test/tools/javac/Paths/Util.sh

changeset 1
9a66ca7c79fa
child 554
9d9f26857129
equal deleted inserted replaced
-1:000000000000 1:9a66ca7c79fa
1 #
2 # Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # This code is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License version 2 only, as
7 # published by the Free Software Foundation.
8 #
9 # This code is distributed in the hope that it will be useful, but WITHOUT
10 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 # version 2 for more details (a copy is included in the LICENSE file that
13 # accompanied this code).
14 #
15 # You should have received a copy of the GNU General Public License version
16 # 2 along with this work; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 #
19 # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 # CA 95054 USA or visit www.sun.com if you need additional information or
21 # have any questions.
22 #
23
24 # Utilities for shell tests
25
26 : ${TESTSRC=.} ${TESTCLASSES=.}
27 java="${TESTJAVA+${TESTJAVA}/bin/}java"
28 javac="${TESTJAVA+${TESTJAVA}/bin/}javac"
29 jar="${TESTJAVA+${TESTJAVA}/bin/}jar"
30
31 case `uname -s` in
32 Windows*|CYGWIN*)
33 WindowsOnly() { "$@"; }
34 UnixOnly() { :; }
35 PS=";" ;;
36 *)
37 UnixOnly() { "$@"; }
38 WindowsOnly() { :; }
39 PS=":";;
40 esac
41
42 failed=""
43 Fail() { echo "FAIL: $1"; failed="${failed}."; }
44
45 Die() { printf "%s\n" "$*"; exit 1; }
46
47 Sys() {
48 printf "%s\n" "$*"; "$@"; rc="$?";
49 test "$rc" -eq 0 || Die "Command \"$*\" failed with exitValue $rc";
50 }
51
52 CheckFiles() {
53 for f in "$@"; do test -r "$f" || Die "File $f not found"; done
54 }
55
56 Report() {
57 test "$#" != 2 && Die "Usage: Report success|failure rc"
58
59 if test "$1" = "success" -a "$2" = 0; then
60 echo "PASS: succeeded as expected"
61 elif test "$1" = "failure" -a "$2" != 0; then
62 echo "PASS: failed as expected"
63 elif test "$1" = "success" -a "$2" != 0; then
64 Fail "test failed unexpectedly"
65 elif test "$1" = "failure" -a "$2" = 0; then
66 Fail "test succeeded unexpectedly"
67 else
68 Die "Usage: Report success|failure rc"
69 fi
70 }
71
72 MkManifestWithClassPath() {
73 (echo "Manifest-Version: 1.0"; echo "Class-Path: $*") > MANIFEST.MF
74 }
75
76 HorizontalRule() {
77 echo "-----------------------------------------------------------------"
78 }
79
80 Test() {
81 HorizontalRule
82 expectedResult="$1"; shift
83 printf "%s\n" "$*"
84 "$@"
85 Report "$expectedResult" "$?"
86 }
87
88 Failure() { Test failure "$@"; }
89 Success() { Test success "$@"; }
90
91 Bottom() {
92 test "$#" = 1 -a "$1" = "Line" || Die "Usage: Bottom Line"
93
94 if test -n "$failed"; then
95 count=`printf "%s" "$failed" | wc -c | tr -d ' '`
96 echo "FAIL: $count tests failed"
97 exit 1
98 else
99 echo "PASS: all tests gave expected results"
100 exit 0
101 fi
102 }
103
104 BadJarFile() {
105 for jarfilename in "$@"; do pwd > "$jarfilename"; done
106 }
107
108 #----------------------------------------------------------------
109 # Usage: BCP=`DefaultBootClassPath`
110 # Returns default bootclasspath, discarding non-existent entries
111 #----------------------------------------------------------------
112 DefaultBootClassPath() {
113 echo 'public class B {public static void main(String[] a) {
114 System.out.println(System.getProperty("sun.boot.class.path"));}}' > B.java
115 "$javac" ${TESTTOOLVMOPTS} B.java
116 _BCP_=""
117 for elt in `"$java" ${TESTVMOPTS} B | tr "${PS}" " "`; do
118 test -r "$elt" -a -n "$elt" && _BCP_="${_BCP_:+${_BCP_}${PS}}${elt}"
119 done
120 rm -f B.java B.class
121 printf "%s" "$_BCP_" # Don't use echo -- unsafe on Windows
122 }
123
124 #----------------------------------------------------------------
125 # Foil message localization
126 #----------------------------------------------------------------
127 DiagnosticsInEnglishPlease() {
128 LANG="C" LC_ALL="C" LC_MESSAGES="C"; export LANG LC_ALL LC_MESSAGES
129 }

mercurial