Fri, 17 Feb 2012 15:24:40 -0800
7143910: test/tools/apt/Basics/apt.sh fails with 'real' sh
Reviewed-by: darcy
Contributed-by: sonali.goel@oracle.com
duke@1 | 1 | #!/bin/sh |
duke@1 | 2 | |
duke@1 | 3 | # |
ohair@962 | 4 | # Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 5 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 6 | # |
duke@1 | 7 | # This code is free software; you can redistribute it and/or modify it |
duke@1 | 8 | # under the terms of the GNU General Public License version 2 only, as |
duke@1 | 9 | # published by the Free Software Foundation. |
duke@1 | 10 | # |
duke@1 | 11 | # This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | # version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | # accompanied this code). |
duke@1 | 16 | # |
duke@1 | 17 | # You should have received a copy of the GNU General Public License version |
duke@1 | 18 | # 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 20 | # |
ohair@554 | 21 | # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 22 | # or visit www.oracle.com if you need additional information or have any |
ohair@554 | 23 | # questions. |
duke@1 | 24 | # |
duke@1 | 25 | |
duke@1 | 26 | |
duke@1 | 27 | # @test |
duke@1 | 28 | # @bug 4241229 4785453 |
duke@1 | 29 | # @summary Test -classpath option and classpath defaults. |
duke@1 | 30 | # @author maddox |
duke@1 | 31 | # |
duke@1 | 32 | # @run shell/timeout=180 ClassPathTest.sh |
duke@1 | 33 | |
duke@1 | 34 | # TODO: Should test sourcepath and classpath separately. |
duke@1 | 35 | |
duke@1 | 36 | if [ "${TESTSRC}" = "" ] |
duke@1 | 37 | then |
duke@1 | 38 | echo "TESTSRC not set. Test cannot execute. Failed." |
duke@1 | 39 | exit 1 |
duke@1 | 40 | fi |
duke@1 | 41 | echo "TESTSRC=${TESTSRC}" |
duke@1 | 42 | if [ "${TESTJAVA}" = "" ] |
duke@1 | 43 | then |
duke@1 | 44 | echo "TESTJAVA not set. Test cannot execute. Failed." |
duke@1 | 45 | exit 1 |
duke@1 | 46 | fi |
duke@1 | 47 | echo "TESTJAVA=${TESTJAVA}" |
duke@1 | 48 | if [ "${TESTCLASSES}" = "" ] |
duke@1 | 49 | then |
duke@1 | 50 | echo "TESTCLASSES not set. Test cannot execute. Failed." |
duke@1 | 51 | exit 1 |
duke@1 | 52 | fi |
duke@1 | 53 | echo "TESTCLASSES=${TESTCLASSES}" |
duke@1 | 54 | echo "CLASSPATH=${CLASSPATH}" |
duke@1 | 55 | |
duke@1 | 56 | # set platform-dependent variables |
duke@1 | 57 | OS=`uname -s` |
duke@1 | 58 | case "$OS" in |
jjg@390 | 59 | SunOS | Linux | CYGWIN* ) |
duke@1 | 60 | FS="/" |
duke@1 | 61 | ;; |
duke@1 | 62 | Windows* ) |
duke@1 | 63 | FS="\\" |
duke@1 | 64 | ;; |
duke@1 | 65 | * ) |
duke@1 | 66 | echo "Unrecognized system!" |
duke@1 | 67 | exit 1; |
duke@1 | 68 | ;; |
duke@1 | 69 | esac |
duke@1 | 70 | |
duke@1 | 71 | javac="${TESTJAVA}${FS}bin${FS}javac" |
duke@1 | 72 | |
duke@1 | 73 | cleanup() { |
duke@1 | 74 | rm -f *.class pkg${FS}*.class foo${FS}pkg${FS}*.class bar${FS}pkg${FS}*.class |
duke@1 | 75 | cp -rf $TESTSRC${FS}* . |
duke@1 | 76 | } |
duke@1 | 77 | |
duke@1 | 78 | fail() { |
duke@1 | 79 | echo "FAIL: $1" |
duke@1 | 80 | failed="yes" |
duke@1 | 81 | } |
duke@1 | 82 | |
duke@1 | 83 | # report expectedResult $? |
duke@1 | 84 | report() { |
duke@1 | 85 | if test "$1" = "success" -a "$2" = 0; then |
duke@1 | 86 | echo "PASS: succeeded as expected" |
duke@1 | 87 | elif test "$1" = "failure" -a "$2" != 0; then |
duke@1 | 88 | echo "PASS: failed as expected" |
duke@1 | 89 | elif test "$1" = "success" -a "$2" != 0; then |
duke@1 | 90 | fail "test failed unexpectedly" |
duke@1 | 91 | elif test "$1" = "failure" -a "$2" = 0; then |
duke@1 | 92 | fail "test succeeded unexpectedly" |
duke@1 | 93 | else |
duke@1 | 94 | fail "internal error" |
duke@1 | 95 | fi |
duke@1 | 96 | } |
duke@1 | 97 | |
duke@1 | 98 | # testJavac expectedResult javacArgs... |
duke@1 | 99 | testJavac() { |
duke@1 | 100 | expectedResult="$1"; shift |
duke@1 | 101 | cleanup |
duke@1 | 102 | echo $javac ${TESTTOOLVMOPTS} "$@" |
jjg@838 | 103 | "$javac" ${TESTTOOLVMOPTS} "$@" |
duke@1 | 104 | report $expectedResult $? |
duke@1 | 105 | } |
duke@1 | 106 | |
duke@1 | 107 | unset CLASSPATH |
duke@1 | 108 | |
duke@1 | 109 | # classpath should default to current directory |
duke@1 | 110 | |
duke@1 | 111 | testJavac success ClassPathTest3.java |
duke@1 | 112 | testJavac failure ClassPathTest1.java |
duke@1 | 113 | |
duke@1 | 114 | # if CLASSPATH is set, it should be honored |
duke@1 | 115 | |
duke@1 | 116 | CLASSPATH=bar; export CLASSPATH |
duke@1 | 117 | |
duke@1 | 118 | testJavac success ClassPathTest2.java |
duke@1 | 119 | testJavac failure ClassPathTest1.java |
duke@1 | 120 | testJavac failure ClassPathTest3.java |
duke@1 | 121 | |
duke@1 | 122 | # -classpath option should override default |
duke@1 | 123 | |
duke@1 | 124 | testJavac success -classpath foo ClassPathTest1.java |
duke@1 | 125 | testJavac failure -classpath foo ClassPathTest2.java |
duke@1 | 126 | testJavac failure -classpath foo ClassPathTest3.java |
duke@1 | 127 | |
duke@1 | 128 | if test -n "$failed"; then |
duke@1 | 129 | echo "Some tests failed" |
duke@1 | 130 | exit 1 |
duke@1 | 131 | else |
duke@1 | 132 | echo PASS: all tests gave expected results |
duke@1 | 133 | exit 0 |
duke@1 | 134 | fi |