test/tools/javac/ClassPathTest/ClassPathTest.sh

changeset 1
9a66ca7c79fa
child 390
f0c9fc46990b
equal deleted inserted replaced
-1:000000000000 1:9a66ca7c79fa
1 #!/bin/sh
2
3 #
4 # Copyright 1999-2003 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 # CA 95054 USA or visit www.sun.com if you need additional information or
23 # have any questions.
24 #
25
26
27 # @test
28 # @bug 4241229 4785453
29 # @summary Test -classpath option and classpath defaults.
30 # @author maddox
31 #
32 # @run shell/timeout=180 ClassPathTest.sh
33
34 # TODO: Should test sourcepath and classpath separately.
35
36 if [ "${TESTSRC}" = "" ]
37 then
38 echo "TESTSRC not set. Test cannot execute. Failed."
39 exit 1
40 fi
41 echo "TESTSRC=${TESTSRC}"
42 if [ "${TESTJAVA}" = "" ]
43 then
44 echo "TESTJAVA not set. Test cannot execute. Failed."
45 exit 1
46 fi
47 echo "TESTJAVA=${TESTJAVA}"
48 if [ "${TESTCLASSES}" = "" ]
49 then
50 echo "TESTCLASSES not set. Test cannot execute. Failed."
51 exit 1
52 fi
53 echo "TESTCLASSES=${TESTCLASSES}"
54 echo "CLASSPATH=${CLASSPATH}"
55
56 # set platform-dependent variables
57 OS=`uname -s`
58 case "$OS" in
59 SunOS | Linux )
60 NULL=/dev/null
61 PS=":"
62 FS="/"
63 ;;
64 Windows* )
65 NULL=NUL
66 PS=";"
67 FS="\\"
68 ;;
69 * )
70 echo "Unrecognized system!"
71 exit 1;
72 ;;
73 esac
74
75 javac="${TESTJAVA}${FS}bin${FS}javac"
76
77 cleanup() {
78 rm -f *.class pkg${FS}*.class foo${FS}pkg${FS}*.class bar${FS}pkg${FS}*.class
79 cp -rf $TESTSRC${FS}* .
80 }
81
82 fail() {
83 echo "FAIL: $1"
84 failed="yes"
85 }
86
87 # report expectedResult $?
88 report() {
89 if test "$1" = "success" -a "$2" = 0; then
90 echo "PASS: succeeded as expected"
91 elif test "$1" = "failure" -a "$2" != 0; then
92 echo "PASS: failed as expected"
93 elif test "$1" = "success" -a "$2" != 0; then
94 fail "test failed unexpectedly"
95 elif test "$1" = "failure" -a "$2" = 0; then
96 fail "test succeeded unexpectedly"
97 else
98 fail "internal error"
99 fi
100 }
101
102 # testJavac expectedResult javacArgs...
103 testJavac() {
104 expectedResult="$1"; shift
105 cleanup
106 echo $javac ${TESTTOOLVMOPTS} "$@"
107 $javac ${TESTTOOLVMOPTS} "$@"
108 report $expectedResult $?
109 }
110
111 unset CLASSPATH
112
113 # classpath should default to current directory
114
115 testJavac success ClassPathTest3.java
116 testJavac failure ClassPathTest1.java
117
118 # if CLASSPATH is set, it should be honored
119
120 CLASSPATH=bar; export CLASSPATH
121
122 testJavac success ClassPathTest2.java
123 testJavac failure ClassPathTest1.java
124 testJavac failure ClassPathTest3.java
125
126 # -classpath option should override default
127
128 testJavac success -classpath foo ClassPathTest1.java
129 testJavac failure -classpath foo ClassPathTest2.java
130 testJavac failure -classpath foo ClassPathTest3.java
131
132 if test -n "$failed"; then
133 echo "Some tests failed"
134 exit 1
135 else
136 echo PASS: all tests gave expected results
137 exit 0
138 fi

mercurial