duke@1: # ohair@554: # Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved. duke@1: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: # duke@1: # This code is free software; you can redistribute it and/or modify it duke@1: # under the terms of the GNU General Public License version 2 only, as duke@1: # published by the Free Software Foundation. duke@1: # duke@1: # This code is distributed in the hope that it will be useful, but WITHOUT duke@1: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: # version 2 for more details (a copy is included in the LICENSE file that duke@1: # accompanied this code). duke@1: # duke@1: # You should have received a copy of the GNU General Public License version duke@1: # 2 along with this work; if not, write to the Free Software Foundation, duke@1: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: # ohair@554: # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: # or visit www.oracle.com if you need additional information or have any ohair@554: # questions. duke@1: # duke@1: duke@1: # Utilities for shell tests duke@1: duke@1: : ${TESTSRC=.} ${TESTCLASSES=.} duke@1: java="${TESTJAVA+${TESTJAVA}/bin/}java" duke@1: javac="${TESTJAVA+${TESTJAVA}/bin/}javac" duke@1: jar="${TESTJAVA+${TESTJAVA}/bin/}jar" duke@1: duke@1: case `uname -s` in duke@1: Windows*|CYGWIN*) duke@1: WindowsOnly() { "$@"; } duke@1: UnixOnly() { :; } duke@1: PS=";" ;; duke@1: *) duke@1: UnixOnly() { "$@"; } duke@1: WindowsOnly() { :; } duke@1: PS=":";; duke@1: esac duke@1: duke@1: failed="" duke@1: Fail() { echo "FAIL: $1"; failed="${failed}."; } duke@1: duke@1: Die() { printf "%s\n" "$*"; exit 1; } duke@1: duke@1: Sys() { duke@1: printf "%s\n" "$*"; "$@"; rc="$?"; duke@1: test "$rc" -eq 0 || Die "Command \"$*\" failed with exitValue $rc"; duke@1: } duke@1: duke@1: CheckFiles() { duke@1: for f in "$@"; do test -r "$f" || Die "File $f not found"; done duke@1: } duke@1: duke@1: Report() { duke@1: test "$#" != 2 && Die "Usage: Report success|failure rc" duke@1: duke@1: if test "$1" = "success" -a "$2" = 0; then duke@1: echo "PASS: succeeded as expected" duke@1: elif test "$1" = "failure" -a "$2" != 0; then duke@1: echo "PASS: failed as expected" duke@1: elif test "$1" = "success" -a "$2" != 0; then duke@1: Fail "test failed unexpectedly" duke@1: elif test "$1" = "failure" -a "$2" = 0; then duke@1: Fail "test succeeded unexpectedly" duke@1: else duke@1: Die "Usage: Report success|failure rc" duke@1: fi duke@1: } duke@1: duke@1: MkManifestWithClassPath() { duke@1: (echo "Manifest-Version: 1.0"; echo "Class-Path: $*") > MANIFEST.MF duke@1: } duke@1: duke@1: HorizontalRule() { duke@1: echo "-----------------------------------------------------------------" duke@1: } duke@1: duke@1: Test() { duke@1: HorizontalRule duke@1: expectedResult="$1"; shift duke@1: printf "%s\n" "$*" duke@1: "$@" duke@1: Report "$expectedResult" "$?" duke@1: } duke@1: duke@1: Failure() { Test failure "$@"; } duke@1: Success() { Test success "$@"; } duke@1: duke@1: Bottom() { duke@1: test "$#" = 1 -a "$1" = "Line" || Die "Usage: Bottom Line" duke@1: duke@1: if test -n "$failed"; then duke@1: count=`printf "%s" "$failed" | wc -c | tr -d ' '` duke@1: echo "FAIL: $count tests failed" duke@1: exit 1 duke@1: else duke@1: echo "PASS: all tests gave expected results" duke@1: exit 0 duke@1: fi duke@1: } duke@1: duke@1: BadJarFile() { duke@1: for jarfilename in "$@"; do pwd > "$jarfilename"; done duke@1: } duke@1: duke@1: #---------------------------------------------------------------- duke@1: # Usage: BCP=`DefaultBootClassPath` duke@1: # Returns default bootclasspath, discarding non-existent entries duke@1: #---------------------------------------------------------------- duke@1: DefaultBootClassPath() { duke@1: echo 'public class B {public static void main(String[] a) { duke@1: System.out.println(System.getProperty("sun.boot.class.path"));}}' > B.java duke@1: "$javac" ${TESTTOOLVMOPTS} B.java duke@1: _BCP_="" duke@1: for elt in `"$java" ${TESTVMOPTS} B | tr "${PS}" " "`; do duke@1: test -r "$elt" -a -n "$elt" && _BCP_="${_BCP_:+${_BCP_}${PS}}${elt}" duke@1: done duke@1: rm -f B.java B.class duke@1: printf "%s" "$_BCP_" # Don't use echo -- unsafe on Windows duke@1: } duke@1: duke@1: #---------------------------------------------------------------- duke@1: # Foil message localization duke@1: #---------------------------------------------------------------- duke@1: DiagnosticsInEnglishPlease() { duke@1: LANG="C" LC_ALL="C" LC_MESSAGES="C"; export LANG LC_ALL LC_MESSAGES duke@1: }