1 #!/bin/sh |
|
2 |
|
3 # |
|
4 # Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved. |
|
5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
6 # |
|
7 # This code is free software; you can redistribute it and/or modify it |
|
8 # under the terms of the GNU General Public License version 2 only, as |
|
9 # published by the Free Software Foundation. |
|
10 # |
|
11 # This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 # version 2 for more details (a copy is included in the LICENSE file that |
|
15 # accompanied this code). |
|
16 # |
|
17 # You should have received a copy of the GNU General Public License version |
|
18 # 2 along with this work; if not, write to the Free Software Foundation, |
|
19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 # |
|
21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 # or visit www.oracle.com if you need additional information or have any |
|
23 # questions. |
|
24 # |
|
25 |
|
26 # @test |
|
27 # @bug 6746458 |
|
28 # @summary Verify correct rejection of illegal quoted identifiers. |
|
29 # @run shell MakeNegTests.sh |
|
30 |
|
31 default_template=QuotedIdent.java |
|
32 # the rest of this file is a generic "//BAD"-line tester |
|
33 |
|
34 : ${TESTSRC=.} ${TESTCLASSES=.} |
|
35 javac="${TESTJAVA+${TESTJAVA}/bin/}javac" |
|
36 |
|
37 verbose=false quiet=false |
|
38 |
|
39 main() { |
|
40 case "${@-}" in |
|
41 *.java*) |
|
42 for template in "$@"; do |
|
43 expand_and_test "$template" |
|
44 done;; |
|
45 *) expand_and_test "${TESTSRC}/$default_template";; |
|
46 esac |
|
47 } |
|
48 |
|
49 expand_and_test() { |
|
50 template=$1 |
|
51 expand "$@" |
|
52 testneg "$@" |
|
53 } |
|
54 |
|
55 expand() { |
|
56 template=$1 |
|
57 badlines=` grep -n < "$template" '//BAD' ` |
|
58 badcount=` echo "$badlines" | wc -l ` |
|
59 [ $badcount -gt 0 ] || { echo "No negative test cases in $template"; exit 1; } |
|
60 $quiet || echo "Expanding $badcount negative test cases from $template:" |
|
61 $quiet || echo "$badlines" |
|
62 badnums=` echo "$badlines" | sed 's/:.*//' ` |
|
63 casestem=` getcasestem "$template" ` |
|
64 tclassname=` basename "$template" .java ` |
|
65 rm "$casestem"*.java |
|
66 for badnum in $badnums; do |
|
67 casefile="$casestem"${badnum}.java |
|
68 cclassname=` basename "$casefile" .java ` |
|
69 sed < "$template" > "$casefile" " |
|
70 s|@compile|@compile/fail| |
|
71 / @[a-z]/s|@|##| |
|
72 ${badnum}s:^ *[/*]*: : |
|
73 s/${tclassname}/${cclassname}/g |
|
74 " |
|
75 $verbose && diff -u "$template" "$casefile" |
|
76 done |
|
77 } |
|
78 |
|
79 getcasestem() { |
|
80 echo `basename $1` | sed 's/.*\///;s/\.java$//;s/_BAD[0-9]*$//;s/$/_BAD/' |
|
81 } |
|
82 |
|
83 testneg() { |
|
84 template=$1 |
|
85 for casefile in ` getcasestem "$template" `*.java; do |
|
86 $quiet || echo -------- $javac "$casefile" |
|
87 $javac "$casefile" > "$casefile".errlog 2>&1 && { |
|
88 echo "*** Compilation unexpectedly succeeded: $casefile" |
|
89 exit 1 |
|
90 } |
|
91 $quiet || echo "Compilation failed as expected" |
|
92 $quiet || head ` $verbose || echo -3 ` < "$casefile".errlog |
|
93 rm "$casefile".errlog |
|
94 done |
|
95 } |
|
96 |
|
97 main "$@" |
|