test/tools/javac/meth/MakeNegTests.sh

changeset 685
fd2579b80b83
parent 554
9d9f26857129
equal deleted inserted replaced
653:7ad86852c38a 685:fd2579b80b83
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 6754038
28 # @summary Verify correct rejection of strongly typed return values
29 # @run shell MakeNegTests.sh
30
31 default_template=InvokeMH.java
32 javacflags='-source 7 -target 7'
33 # the rest of this file is a generic "//BAD"-line tester
34
35 : ${TESTSRC=.} ${TESTCLASSES=.}
36 javac="${TESTJAVA+${TESTJAVA}/bin/}javac"
37
38 verbose=false quiet=false
39
40 main() {
41 case "${@-}" in
42 *.java*)
43 for template in "$@"; do
44 expand_and_test "$template"
45 done;;
46 *) expand_and_test "${TESTSRC}/$default_template";;
47 esac
48 }
49
50 expand_and_test() {
51 template=$1
52 expand "$@"
53 testneg "$@"
54 }
55
56 expand() {
57 template=$1
58 badlines=` grep -n < "$template" '//BAD' `
59 badcount=` echo "$badlines" | wc -l `
60 [ $badcount -gt 0 ] || { echo "No negative test cases in $template"; exit 1; }
61 $quiet || echo "Expanding $badcount negative test cases from $template:"
62 $quiet || echo "$badlines"
63 badnums=` echo "$badlines" | sed 's/:.*//' `
64 casestem=` getcasestem "$template" `
65 tclassname=` basename "$template" .java `
66 rm -f "$casestem"*.java
67 for badnum in $badnums; do
68 casefile="$casestem"${badnum}.java
69 cclassname=` basename "$casefile" .java `
70 sed < "$template" > "$casefile" "
71 s|@compile|@compile/fail|
72 / @[a-z]/s|@|##|
73 ${badnum}s:^ *[/*]*: :
74 s/${tclassname}/${cclassname}/g
75 "
76 $verbose && diff -u "$template" "$casefile"
77 done
78 }
79
80 getcasestem() {
81 echo `basename $1` | sed 's/\.java$//;s/_BAD[0-9]*$//;s/$/_BAD/'
82 }
83
84 testneg() {
85 template=$1
86 for casefile in ` getcasestem "$template" `*.java; do
87 $quiet || echo -------- $javac $javacflags "$casefile"
88 $javac $javacflags "$casefile" > "$casefile".errlog 2>&1 && {
89 echo "*** Compilation unexpectedly succeeded: $casefile"
90 exit 1
91 }
92 $quiet || echo "Compilation failed as expected"
93 $quiet || head ` $verbose || echo -3 ` < "$casefile".errlog
94 rm "$casefile".errlog
95 done
96 }
97
98 main "$@"

mercurial