test/tools/javac/ClassPathTest/ClassPathTest.sh

changeset 1
9a66ca7c79fa
child 390
f0c9fc46990b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/ClassPathTest/ClassPathTest.sh	Sat Dec 01 00:00:00 2007 +0000
     1.3 @@ -0,0 +1,138 @@
     1.4 +#!/bin/sh
     1.5 +
     1.6 +#
     1.7 +# Copyright 1999-2003 Sun Microsystems, Inc.  All Rights Reserved.
     1.8 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.9 +#
    1.10 +# This code is free software; you can redistribute it and/or modify it
    1.11 +# under the terms of the GNU General Public License version 2 only, as
    1.12 +# published by the Free Software Foundation.
    1.13 +#
    1.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 +# version 2 for more details (a copy is included in the LICENSE file that
    1.18 +# accompanied this code).
    1.19 +#
    1.20 +# You should have received a copy of the GNU General Public License version
    1.21 +# 2 along with this work; if not, write to the Free Software Foundation,
    1.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 +#
    1.24 +# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.25 +# CA 95054 USA or visit www.sun.com if you need additional information or
    1.26 +# have any questions.
    1.27 +#
    1.28 +
    1.29 +
    1.30 +# @test
    1.31 +# @bug 4241229 4785453
    1.32 +# @summary Test -classpath option and classpath defaults.
    1.33 +# @author maddox
    1.34 +#
    1.35 +# @run shell/timeout=180 ClassPathTest.sh
    1.36 +
    1.37 +# TODO: Should test sourcepath and classpath separately.
    1.38 +
    1.39 +if [ "${TESTSRC}" = "" ]
    1.40 +then
    1.41 +  echo "TESTSRC not set.  Test cannot execute.  Failed."
    1.42 +  exit 1
    1.43 +fi
    1.44 +echo "TESTSRC=${TESTSRC}"
    1.45 +if [ "${TESTJAVA}" = "" ]
    1.46 +then
    1.47 +  echo "TESTJAVA not set.  Test cannot execute.  Failed."
    1.48 +  exit 1
    1.49 +fi
    1.50 +echo "TESTJAVA=${TESTJAVA}"
    1.51 +if [ "${TESTCLASSES}" = "" ]
    1.52 +then
    1.53 +  echo "TESTCLASSES not set.  Test cannot execute.  Failed."
    1.54 +  exit 1
    1.55 +fi
    1.56 +echo "TESTCLASSES=${TESTCLASSES}"
    1.57 +echo "CLASSPATH=${CLASSPATH}"
    1.58 +
    1.59 +# set platform-dependent variables
    1.60 +OS=`uname -s`
    1.61 +case "$OS" in
    1.62 +  SunOS | Linux )
    1.63 +    NULL=/dev/null
    1.64 +    PS=":"
    1.65 +    FS="/"
    1.66 +    ;;
    1.67 +  Windows* )
    1.68 +    NULL=NUL
    1.69 +    PS=";"
    1.70 +    FS="\\"
    1.71 +    ;;
    1.72 +  * )
    1.73 +    echo "Unrecognized system!"
    1.74 +    exit 1;
    1.75 +    ;;
    1.76 +esac
    1.77 +
    1.78 +javac="${TESTJAVA}${FS}bin${FS}javac"
    1.79 +
    1.80 +cleanup() {
    1.81 +	rm -f *.class pkg${FS}*.class foo${FS}pkg${FS}*.class bar${FS}pkg${FS}*.class
    1.82 +	cp -rf $TESTSRC${FS}* .
    1.83 +}
    1.84 +
    1.85 +fail() {
    1.86 +	echo "FAIL: $1"
    1.87 +	failed="yes"
    1.88 +}
    1.89 +
    1.90 +# report expectedResult $?
    1.91 +report() {
    1.92 +	if   test "$1" = "success" -a "$2" = 0; then
    1.93 +		echo "PASS: succeeded as expected"
    1.94 +	elif test "$1" = "failure" -a "$2" != 0; then
    1.95 +		echo "PASS: failed as expected"
    1.96 +	elif test "$1" = "success" -a "$2" != 0; then
    1.97 +		fail "test failed unexpectedly"
    1.98 +	elif test "$1" = "failure" -a "$2" = 0; then
    1.99 +		fail "test succeeded unexpectedly"
   1.100 +	else
   1.101 +		fail "internal error"
   1.102 +	fi
   1.103 +}
   1.104 +
   1.105 +# testJavac expectedResult javacArgs...
   1.106 +testJavac() {
   1.107 +	expectedResult="$1"; shift
   1.108 +	cleanup
   1.109 +	echo $javac ${TESTTOOLVMOPTS} "$@"
   1.110 +	$javac ${TESTTOOLVMOPTS} "$@"
   1.111 +	report $expectedResult $?
   1.112 +}
   1.113 +
   1.114 +unset CLASSPATH
   1.115 +
   1.116 +# classpath should default to current directory
   1.117 +
   1.118 +testJavac success ClassPathTest3.java
   1.119 +testJavac failure ClassPathTest1.java
   1.120 +
   1.121 +# if CLASSPATH is set, it should be honored
   1.122 +
   1.123 +CLASSPATH=bar; export CLASSPATH
   1.124 +
   1.125 +testJavac success ClassPathTest2.java
   1.126 +testJavac failure ClassPathTest1.java
   1.127 +testJavac failure ClassPathTest3.java
   1.128 +
   1.129 +# -classpath option should override default
   1.130 +
   1.131 +testJavac success -classpath foo ClassPathTest1.java
   1.132 +testJavac failure -classpath foo ClassPathTest2.java
   1.133 +testJavac failure -classpath foo ClassPathTest3.java
   1.134 +
   1.135 +if test -n "$failed"; then
   1.136 +	echo "Some tests failed"
   1.137 +	exit 1
   1.138 +else
   1.139 +	echo PASS: all tests gave expected results
   1.140 +	exit 0
   1.141 +fi

mercurial