langtools/test/tools/javac/versions/check.sh
changeset 25448 40c5263b551f
parent 25447 90222e25bb57
child 25449 3c14a2e16bd6
equal deleted inserted replaced
25447:90222e25bb57 25448:40c5263b551f
     1 #
       
     2 # Copyright (c) 2004, 2014, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20 # or visit www.oracle.com if you need additional information or have any
       
    21 # questions.
       
    22 #
       
    23 
       
    24 # @test
       
    25 # @bug 4981566 5028634 5094412 6304984 7025786 7025789 8001112 8028545 8000961
       
    26 # @summary Check interpretation of -target and -source options
       
    27 # @build CheckClassFileVersion
       
    28 # @run shell check.sh
       
    29 
       
    30 TESTJAVA=${TESTJAVA:?}
       
    31 TC=${TESTCLASSES-.}
       
    32 
       
    33 J="$TESTJAVA/bin/java"
       
    34 JC="$TESTJAVA/bin/javac"
       
    35 CFV="${TESTVMOPTS} -cp $TC CheckClassFileVersion"
       
    36 
       
    37 rm -f $TC/X.java $TC/X.java
       
    38 echo 'public class X { }' > $TC/X.java
       
    39 echo 'public enum Y { }' > $TC/Y.java
       
    40 
       
    41 
       
    42 # Check class-file versions
       
    43 
       
    44 check() {
       
    45   V=$1; shift
       
    46   echo "+ javac $* [$V]"
       
    47   "$JC" ${TESTTOOLVMOPTS} -Xlint:-options -d $TC $* $TC/X.java && "$J" $CFV $TC/X.class $V || exit 2
       
    48 }
       
    49 
       
    50 # check for all combinations of target values
       
    51 check_target() {
       
    52   check $1 -source $2 -target $3
       
    53   check $1 -source $2 -target 1.${3}
       
    54 }
       
    55 # check for all combinations of source and target values
       
    56 check_source_target() {
       
    57   check_target $1 $2     $3
       
    58   check_target $1 1.${2} $3
       
    59 }
       
    60 
       
    61 
       
    62 check_source_target 50.0 6   6
       
    63 
       
    64 check_source_target 51.0 6   7
       
    65 check_source_target 51.0 7   7
       
    66 
       
    67 check_source_target 52.0 6   8
       
    68 check_source_target 52.0 7   8
       
    69 check_source_target 52.0 8   8
       
    70 
       
    71 check_source_target 52.0 8   9
       
    72 check_source_target 52.0 9   9
       
    73 
       
    74 # and finally the default with no options
       
    75 check 52.0
       
    76 
       
    77 # Check source versions
       
    78 
       
    79 fail() {
       
    80   echo "+ javac $*"
       
    81   if "$JC" ${TESTTOOLVMOPTS} -Xlint:-options -d $TC $*; then
       
    82     echo "-- did not fail as expected"
       
    83     exit 3
       
    84   else
       
    85     echo "-- failed as expected"
       
    86   fi
       
    87 }
       
    88 
       
    89 pass() {
       
    90   echo "+ javac $*"
       
    91   if "$JC" ${TESTTOOLVMOPTS} -Xlint:options -d $TC $*; then
       
    92     echo "-- passed"
       
    93   else
       
    94     echo "-- failed"
       
    95     exit 4
       
    96   fi
       
    97 }
       
    98 
       
    99 # the following need to be updated when -source 7 features are available
       
   100 checksrc14() { pass $* $TC/X.java; fail $* $TC/Y.java; }
       
   101 checksrc15() { pass $* $TC/X.java; pass $* $TC/Y.java; }
       
   102 checksrc16() { checksrc15 $* ; }
       
   103 checksrc17() { checksrc15 $* ; }
       
   104 checksrc18() { checksrc15 $* ; }
       
   105 checksrc19() { checksrc15 $* ; }
       
   106 
       
   107 
       
   108 
       
   109 checksrc16 -source 1.6
       
   110 checksrc16 -source 6
       
   111 checksrc16 -source 1.6 -target 1.6
       
   112 checksrc16 -source 6 -target 6
       
   113 
       
   114 checksrc17 -source 1.7
       
   115 checksrc17 -source 7
       
   116 checksrc17 -source 1.7 -target 1.7
       
   117 checksrc17 -source 7 -target 7
       
   118 
       
   119 checksrc18 -source 1.8
       
   120 checksrc18 -source 8
       
   121 checksrc18 -source 1.8 -target 1.8
       
   122 checksrc18 -source 8 -target 8
       
   123 
       
   124 checksrc19
       
   125 checksrc19 -source 1.9
       
   126 checksrc19 -source 9
       
   127 checksrc19 -source 1.9 -target 1.9
       
   128 checksrc19 -source 9 -target 9
       
   129 checksrc19 -target 1.9
       
   130 checksrc19 -target 9
       
   131 
       
   132 fail -source 1.6 -target 1.5 $TC/X.java
       
   133 fail -source 6   -target 1.5 $TC/X.java
       
   134 fail -source 7   -target 1.6 $TC/X.java
       
   135 fail -source 8   -target 1.6 $TC/X.java
       
   136 fail -source 8   -target 1.7 $TC/X.java
       
   137 fail -source 9   -target 1.7 $TC/X.java
       
   138 fail -source 9   -target 1.8 $TC/X.java