annotate test/tools/javac/Paths/Diagnostics.sh @ 3294:9adfb22ff08f

8142968: Module System implementation Summary: Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282 Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, jan.lahoda@oracle.com, vicente.romero@oracle.com, andreas.lundblad@oracle.com, andrey.x.nazarov@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, kumar.x.srinivasan@oracle.com, sundararajan.athijegannathan@oracle.com
author alanb
date Thu, 17 Mar 2016 19:04:28 +0000
parents a28b7f42dae9
children
rev   line source
duke@0 1 #!/bin/sh
duke@0 2
duke@0 3 #
alanb@3294 4 # Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
duke@0 5 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 6 #
duke@0 7 # This code is free software; you can redistribute it and/or modify it
duke@0 8 # under the terms of the GNU General Public License version 2 only, as
duke@0 9 # published by the Free Software Foundation.
duke@0 10 #
duke@0 11 # This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 14 # version 2 for more details (a copy is included in the LICENSE file that
duke@0 15 # accompanied this code).
duke@0 16 #
duke@0 17 # You should have received a copy of the GNU General Public License version
duke@0 18 # 2 along with this work; if not, write to the Free Software Foundation,
duke@0 19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 20 #
ohair@553 21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@553 22 # or visit www.oracle.com if you need additional information or have any
ohair@553 23 # questions.
duke@0 24 #
duke@0 25
duke@0 26 #
duke@0 27 # @test
duke@0 28 # @bug 4884487 6295519 6236704 6429613
duke@0 29 # @summary Test for proper diagnostics during path manipulation operations
duke@0 30 # @author Martin Buchholz
duke@0 31 #
duke@0 32 # @run shell/timeout=180 Diagnostics.sh
duke@0 33
duke@0 34 # To run this test manually, simply do ./Diagnostics.sh
duke@0 35
duke@0 36 . ${TESTSRC-.}/Util.sh
duke@0 37
duke@0 38 set -u
duke@0 39
chegar@2721 40 # BCP=`DefaultBootClassPath`
duke@0 41
duke@0 42 DiagnosticsInEnglishPlease
duke@0 43
chegar@2721 44 No() { NO="no"; "$@"; NO=""; } # No means NO!
duke@0 45
duke@0 46 Warning() {
duke@0 47 HorizontalRule
duke@0 48 echo "$@"
duke@0 49 output=`"$@" 2>&1`; rc="$?"
alanb@3294 50 output2=`echo "$output" | grep -v "bootstrap class path not set in conjunction with -source"`
alanb@3294 51 test -n "$output2" && echo "$output"
duke@0 52 test $rc -eq 0 || Fail "Command \"$*\" failed with exitValue $rc";
alanb@3294 53 case "$output2" in *warning:*) gotwarning="yes";; *) gotwarning="no";; esac
duke@0 54
duke@0 55 if test "$gotwarning" = "yes" -a "$NO" = "no"; then
chegar@2721 56 Fail "Command \"$*\" printed an unexpected warning"
duke@0 57 elif test "$gotwarning" = "no" -a "$NO" != "no"; then
chegar@2721 58 Fail "Command \"$*\" did not generate the expected warning"
duke@0 59 fi
duke@0 60 }
duke@0 61
duke@0 62 Error() {
duke@0 63 HorizontalRule
duke@0 64 echo "$@"
duke@0 65 output=`"$@" 2>&1`; rc="$?"
duke@0 66 test -n "$output" && echo "$output"
duke@0 67 case "$output" in *error:*) goterror="yes";; *) goterror="no";; esac
duke@0 68
duke@0 69 if test "$NO" = "no"; then
chegar@2721 70 test "$rc" -ne 0 && \
chegar@2721 71 Fail "Command \"$*\" failed with return code $rc"
chegar@2721 72 test "$goterror" = "yes" && \
chegar@2721 73 Fail "Command \"$*\" did not generate any error message"
duke@0 74 else
chegar@2721 75 test "$rc" -eq 0 && \
chegar@2721 76 Fail "Command \"$*\" was supposed to Die with fatal error";
chegar@2721 77 test "$goterror" = "no" && \
chegar@2721 78 Fail "Command \"$*\" printed an unexpected error message"
duke@0 79 fi
duke@0 80 }
duke@0 81
duke@0 82 Cleanup() {
chegar@2721 83 Sys rm -rf Main.java Main.class
duke@0 84 Sys rm -rf classes classes.foo classes.jar classes.war classes.zip
duke@0 85 Sys rm -rf MANIFEST.MF classesRef.jar classesRefRef.jar jars
duke@0 86 }
duke@0 87
duke@0 88 Cleanup
duke@0 89 echo "public class Main{public static void main(String[]a){}}" > Main.java
duke@0 90
alanb@3294 91 # We need to set -source 8 -target 8 for those cases where the option is
alanb@3294 92 # not legal in 9 and later. However, that triggers an additional warning
alanb@3294 93 # about not setting bootclasspath, which is filtered out in Warning.
alanb@3294 94 # The alternative would be to extract a minimal rt.jar from JDK and
alanb@3294 95 # specify that with -bootclasspath.
alanb@3294 96 SRCTRG8="-source 8 -target 8"
alanb@3294 97
duke@0 98 #----------------------------------------------------------------
duke@0 99 # No warnings unless -Xlint:path is used
duke@0 100 #----------------------------------------------------------------
duke@0 101 No Warning "$javac" ${TESTTOOLVMOPTS} Main.java
duke@0 102 No Warning "$javac" ${TESTTOOLVMOPTS} -cp ".${PS}classes" Main.java
duke@0 103
duke@0 104 #----------------------------------------------------------------
duke@0 105 # Warn for missing elts in user-specified paths
duke@0 106 #----------------------------------------------------------------
alanb@3294 107 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes" Main.java
alanb@3294 108 Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-Xbootclasspath/p:classes" Main.java
alanb@3294 109 Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint "-Xbootclasspath/a:classes" Main.java
chegar@2721 110
alanb@3294 111 Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-endorseddirs" "classes" Main.java
alanb@3294 112 Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint "-extdirs" "classes" Main.java
alanb@3294 113 #Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-Xbootclasspath:classes${PS}${BCP}" Main.java
duke@0 114
duke@0 115 #----------------------------------------------------------------
duke@0 116 # No warning for missing elts in "system" paths
duke@0 117 #----------------------------------------------------------------
chegar@2721 118 # No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Djava.endorsed.dirs=classes" Main.java
chegar@2721 119 # No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Djava.ext.dirs=classes" Main.java
alanb@3294 120 # No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Xbootclasspath/p:classes" Main.java
alanb@3294 121 # No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Xbootclasspath/a:classes" Main.java
chegar@2721 122 # No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path "-J-Xbootclasspath:classes${PS}${BCP}" Main.java
duke@0 123
duke@0 124 #----------------------------------------------------------------
duke@0 125 # No warning if class path element exists
duke@0 126 #----------------------------------------------------------------
duke@0 127 Sys mkdir classes
alanb@3294 128 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes" Main.java
alanb@3294 129 No Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-endorseddirs" "classes" Main.java
alanb@3294 130 No Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-extdirs" "classes" Main.java
alanb@3294 131 No Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-Xbootclasspath/p:classes" Main.java
alanb@3294 132 No Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-Xbootclasspath/a:classes" Main.java
alanb@3294 133 #No Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint:path "-Xbootclasspath:classes${PS}${BCP}" Main.java
duke@0 134
duke@0 135 Sys "$jar" cf classes.jar Main.class
duke@0 136 Sys cp classes.jar classes.war
duke@0 137 Sys cp classes.war classes.zip
duke@0 138 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes.jar" Main.java
duke@0 139 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes.war" Main.java
duke@0 140 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes.zip" Main.java
duke@0 141
duke@0 142 #----------------------------------------------------------------
chegar@2721 143 # Warn if -Xlint is used and if class path element refers to
duke@0 144 # regular file which doesn't look like a zip file, but is
duke@0 145 #----------------------------------------------------------------
duke@0 146 Sys cp classes.war classes.foo
duke@0 147 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint:path -cp ".${PS}classes.foo" Main.java
duke@0 148
duke@0 149
duke@0 150 #----------------------------------------------------------------
duke@0 151 # No error if class path element refers to regular file which is
duke@0 152 # not a zip file
duke@0 153 #----------------------------------------------------------------
duke@0 154 No Error "$javac" ${TESTTOOLVMOPTS} -cp Main.java Main.java # Main.java is NOT a jar file
duke@0 155 No Error "$javac" ${TESTTOOLVMOPTS} Main.java
duke@0 156
duke@0 157 #----------------------------------------------------------------
chegar@2721 158 # Warn if -Xlint is used and if class path element refers to
duke@0 159 # regular file which is not a zip file
duke@0 160 #----------------------------------------------------------------
duke@0 161 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -cp Main.java Main.java # Main.java is NOT a jar file
duke@0 162
duke@0 163 #----------------------------------------------------------------
duke@0 164 # Test jar file class path reference recursion
duke@0 165 #----------------------------------------------------------------
duke@0 166 MkManifestWithClassPath classesRef.jar
duke@0 167 Sys "$jar" cmf MANIFEST.MF classesRefRef.jar Main.class
duke@0 168
duke@0 169 #----------------------------------------------------------------
duke@0 170 # Non-existent recursive Class-Path reference gives warning
duke@0 171 #----------------------------------------------------------------
alanb@3294 172 No Warning "$javac" ${TESTTOOLVMOPTS} -classpath classesRefRef.jar Main.java
alanb@3294 173 Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -classpath classesRefRef.jar Main.java
alanb@3294 174 No Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint -Xbootclasspath/p:classesRefRef.jar Main.java
duke@0 175
duke@0 176 BadJarFile classesRef.jar
duke@0 177
duke@0 178 #----------------------------------------------------------------
duke@0 179 # Non-jar file recursive Class-Path reference gives error
duke@0 180 #----------------------------------------------------------------
alanb@3294 181 Error "$javac" ${TESTTOOLVMOPTS} -classpath classesRefRef.jar Main.java
alanb@3294 182 No Error "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xbootclasspath/a:classesRefRef.jar Main.java
duke@0 183
duke@0 184 MkManifestWithClassPath classes
duke@0 185 Sys "$jar" cmf MANIFEST.MF classesRef.jar Main.class
duke@0 186
duke@0 187 #----------------------------------------------------------------
duke@0 188 # Jar file recursive Class-Path reference is OK
duke@0 189 #----------------------------------------------------------------
alanb@3294 190 No Warning "$javac" ${TESTTOOLVMOPTS} -Xlint -classpath classesRefRef.jar Main.java
alanb@3294 191 No Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint -Xbootclasspath/p:classesRefRef.jar Main.java
duke@0 192
duke@0 193 #----------------------------------------------------------------
jjg@873 194 # Class-Path attribute followed in extdirs or endorseddirs
duke@0 195 #----------------------------------------------------------------
duke@0 196 Sys mkdir jars
jjg@2902 197 Sys cp classesRefRef.jar jars/.
alanb@3294 198 Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint -extdirs jars Main.java
alanb@3294 199 Warning "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint -endorseddirs jars Main.java
duke@0 200
duke@0 201 #----------------------------------------------------------------
duke@0 202 # Bad Jar file in extdirs and endorseddirs should not be ignored
duke@0 203 #----------------------------------------------------------------
duke@0 204 BadJarFile jars/classesRef.jar
alanb@3294 205 Error "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint -extdirs jars Main.java
alanb@3294 206 Error "$javac" ${TESTTOOLVMOPTS} ${SRCTRG8} -Xlint -endorseddirs jars Main.java
duke@0 207
duke@0 208 Cleanup
duke@0 209
duke@0 210 Bottom Line