|
1 # |
|
2 # Copyright 2004-2006 Sun Microsystems, Inc. All Rights Reserved. |
|
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 # |
|
5 # This code is free software; you can redistribute it and/or modify it |
|
6 # under the terms of the GNU General Public License version 2 only, as |
|
7 # published by the Free Software Foundation. |
|
8 # |
|
9 # This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 # version 2 for more details (a copy is included in the LICENSE file that |
|
13 # accompanied this code). |
|
14 # |
|
15 # You should have received a copy of the GNU General Public License version |
|
16 # 2 along with this work; if not, write to the Free Software Foundation, |
|
17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 # |
|
19 # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
20 # CA 95054 USA or visit www.sun.com if you need additional information or |
|
21 # have any questions. |
|
22 # |
|
23 |
|
24 # @test |
|
25 # @bug 4981566 5028634 5094412 6304984 |
|
26 # @summary Check interpretation of -target and -source options |
|
27 # |
|
28 # @build CheckClassFileVersion |
|
29 # @run shell check.sh |
|
30 |
|
31 TESTJAVA=${TESTJAVA:?} |
|
32 TC=${TESTCLASSES-.} |
|
33 |
|
34 J="$TESTJAVA/bin/java" |
|
35 JC="$TESTJAVA/bin/javac" |
|
36 CFV="$J ${TESTVMOPTS} -cp $TC CheckClassFileVersion" |
|
37 |
|
38 rm -f $TC/X.java $TC/X.java |
|
39 echo 'public class X { }' > $TC/X.java |
|
40 echo 'public enum Y { }' > $TC/Y.java |
|
41 |
|
42 |
|
43 # Check class-file versions |
|
44 |
|
45 check() { |
|
46 V=$1; shift |
|
47 echo "+ javac $* [$V]" |
|
48 $JC ${TESTTOOLVMOPTS} -d $TC $* $TC/X.java && $CFV $TC/X.class $V || exit 2 |
|
49 } |
|
50 |
|
51 check 50.0 |
|
52 check 48.0 -source 1.4 |
|
53 check 49.0 -source 1.4 -target 1.5 |
|
54 check 49.0 -target 1.5 |
|
55 check 50.0 -source 1.5 |
|
56 check 50.0 -target 1.6 |
|
57 check 50.0 -target 6 |
|
58 check 50.0 -source 1.6 |
|
59 check 50.0 -source 6 |
|
60 check 51.0 -target 1.7 |
|
61 check 51.0 -target 7 |
|
62 check 51.0 -source 1.7 |
|
63 check 51.0 -source 7 |
|
64 |
|
65 |
|
66 # Check source versions |
|
67 |
|
68 fail() { |
|
69 echo "+ javac $*" |
|
70 if $JC ${TESTTOOLVMOPTS} -d $TC $*; then |
|
71 echo "-- did not fail as expected" |
|
72 exit 3 |
|
73 else |
|
74 echo "-- failed as expected" |
|
75 fi |
|
76 } |
|
77 |
|
78 pass() { |
|
79 echo "+ javac $*" |
|
80 if $JC ${TESTTOOLVMOPTS} -d $TC $*; then |
|
81 echo "-- passed" |
|
82 else |
|
83 echo "-- failed" |
|
84 exit 4 |
|
85 fi |
|
86 } |
|
87 |
|
88 checksrc14() { pass $* $TC/X.java; fail $* $TC/Y.java; } |
|
89 checksrc15() { pass $* $TC/X.java; pass $* $TC/Y.java; } |
|
90 checksrc16() { checksrc15 $* ; } |
|
91 |
|
92 checksrc14 -source 1.4 |
|
93 checksrc14 -source 1.4 -target 1.5 |
|
94 |
|
95 checksrc15 |
|
96 checksrc15 -target 1.5 |
|
97 checksrc15 -source 1.5 |
|
98 |
|
99 checksrc16 -target 1.6 |
|
100 checksrc16 -target 6 |
|
101 checksrc16 -source 1.6 |
|
102 checksrc16 -source 6 |
|
103 |
|
104 fail -source 1.5 -target 1.4 $TC/X.java |
|
105 fail -source 1.6 -target 1.4 $TC/X.java |
|
106 fail -source 6 -target 1.4 $TC/X.java |
|
107 fail -source 1.6 -target 1.5 $TC/X.java |
|
108 fail -source 6 -target 1.5 $TC/X.java |