1 #!/bin/sh |
|
2 # @test Arrrghs.sh |
|
3 # @bug 5030233 6214916 6356475 6571029 6684582 |
|
4 # @build Arrrghs |
|
5 # @run shell Arrrghs.sh |
|
6 # @summary Argument parsing validation. |
|
7 # @author Joseph E. Kowalski |
|
8 |
|
9 # |
|
10 # Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved. |
|
11 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
12 # |
|
13 # This code is free software; you can redistribute it and/or modify it |
|
14 # under the terms of the GNU General Public License version 2 only, as |
|
15 # published by the Free Software Foundation. |
|
16 # |
|
17 # This code is distributed in the hope that it will be useful, but WITHOUT |
|
18 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
19 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
20 # version 2 for more details (a copy is included in the LICENSE file that |
|
21 # accompanied this code). |
|
22 # |
|
23 # You should have received a copy of the GNU General Public License version |
|
24 # 2 along with this work; if not, write to the Free Software Foundation, |
|
25 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
26 # |
|
27 # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
28 # CA 95054 USA or visit www.sun.com if you need additional information or |
|
29 # have any questions. |
|
30 # |
|
31 |
|
32 # |
|
33 # This test is intended to validate generic argument parsing and |
|
34 # handling. |
|
35 # |
|
36 # Oh yes, since the response to argument parsing errors is often |
|
37 # a visceral one, the name Arrrghs (pronounced "args") seems rather |
|
38 # appropriate. |
|
39 # |
|
40 |
|
41 # Verify directory context variables are set |
|
42 if [ "${TESTJAVA}" = "" ] |
|
43 then |
|
44 echo "TESTJAVA not set. Test cannot execute. Failed." |
|
45 exit 1 |
|
46 fi |
|
47 |
|
48 if [ "${TESTSRC}" = "" ] |
|
49 then |
|
50 echo "TESTSRC not set. Test cannot execute. Failed." |
|
51 exit 1 |
|
52 fi |
|
53 |
|
54 if [ "${TESTCLASSES}" = "" ] |
|
55 then |
|
56 echo "TESTCLASSES not set. Test cannot execute. Failed." |
|
57 exit 1 |
|
58 fi |
|
59 |
|
60 # |
|
61 # Shell routine to test for the proper handling of the cp/classpath |
|
62 # option is correct (see 5030233). This option is unique in that it |
|
63 # is the only option to the java command (and friends) which is |
|
64 # separated from its option argument by a space, rather than an |
|
65 # equals sign. |
|
66 # |
|
67 # Parameters: |
|
68 # $1 cmd utility name to be tested (java, javac, ...) |
|
69 # $2 option either the -cp or -classpath option to be |
|
70 # tested. |
|
71 # |
|
72 TestCP() { |
|
73 mess="`$TESTJAVA/bin/$1 $2 2>&1 1>/dev/null`" |
|
74 if [ $? -eq 0 ]; then |
|
75 echo "Invalid $1 $2 syntax accepted" |
|
76 exit 1 |
|
77 fi |
|
78 if [ -z "$mess" ]; then |
|
79 echo "No Usage message from invalid $1 $2 syntax" |
|
80 exit 1 |
|
81 fi |
|
82 } |
|
83 |
|
84 # |
|
85 # Test for 6356475 "REGRESSION:"java -X" from cmdline fails" |
|
86 # |
|
87 TestXUsage() { |
|
88 $TESTJAVA/bin/java -X > /dev/null 2>&1 |
|
89 if [ $? -ne 0 ]; then |
|
90 echo "-X option failed" |
|
91 exit 1 |
|
92 fi |
|
93 } |
|
94 |
|
95 # |
|
96 # Test if java -help works |
|
97 # |
|
98 TestHelp() { |
|
99 $TESTJAVA/bin/java -help > /dev/null 2>&1 |
|
100 if [ $? -ne 0 ]; then |
|
101 echo "-help option failed" |
|
102 exit 1 |
|
103 fi |
|
104 } |
|
105 |
|
106 # |
|
107 # Test to ensure that a missing main class is indicated in the error message |
|
108 # |
|
109 TestMissingMainClass() { |
|
110 # First create a small jar file with no main |
|
111 printf "public class Foo {}\n" > Foo.java |
|
112 $TESTJAVA/bin/javac Foo.java |
|
113 if [ $? -ne 0 ]; then |
|
114 printf "Error: compilation of Foo.java failed\n" |
|
115 exit 1 |
|
116 fi |
|
117 printf "Main-Class: Bar\n" > manifest |
|
118 $TESTJAVA/bin/jar -cvfm some.jar manifest Foo.class |
|
119 if [ ! -f some.jar ]; then |
|
120 printf "Error: did not find some.jar\n" |
|
121 exit 1 |
|
122 fi |
|
123 |
|
124 # test a non-existence main-class using -jar |
|
125 mess="`$TESTJAVA/bin/java -jar some.jar 2>&1 1>/dev/null`" |
|
126 echo $mess | grep 'Bar' 2>&1 > /dev/null |
|
127 if [ $? -ne 0 ]; then |
|
128 printf "Error: did not find main class missing message\n" |
|
129 exit 1 |
|
130 fi |
|
131 |
|
132 # test a non-existent main-class using classpath |
|
133 mess="`$TESTJAVA/bin/java -cp some.jar Bar 2>&1 1>/dev/null`" |
|
134 echo $mess | grep 'Bar' 2>&1 > /dev/null |
|
135 if [ $? -ne 0 ]; then |
|
136 printf "Error: did not find main class missing message\n" |
|
137 exit 1 |
|
138 fi |
|
139 |
|
140 # cleanup |
|
141 rm -f some.jar Foo.* manifest |
|
142 } |
|
143 |
|
144 # |
|
145 # Main processing: |
|
146 # |
|
147 |
|
148 # |
|
149 # Tests for 5030233 |
|
150 # |
|
151 TestCP java -cp |
|
152 TestCP java -classpath |
|
153 TestCP java -jar |
|
154 TestCP javac -cp |
|
155 TestCP javac -classpath |
|
156 TestXUsage |
|
157 TestHelp |
|
158 TestMissingMainClass |
|
159 |
|
160 # |
|
161 # Tests for 6214916 |
|
162 # |
|
163 # |
|
164 # These tests require that a JVM (any JVM) be installed in the system registry. |
|
165 # If none is installed, skip this test. |
|
166 $TESTJAVA/bin/java -version:1.1+ -version >/dev/null 2>&1 |
|
167 if [ $? -eq 0 ]; then |
|
168 $TESTJAVA/bin/java -classpath $TESTCLASSES Arrrghs $TESTJAVA/bin/java |
|
169 if [ $? -ne 0 ]; then |
|
170 echo "Argument Passing Tests failed" |
|
171 exit 1 |
|
172 fi |
|
173 else |
|
174 printf "Warning:Argument Passing Tests were skipped, no java found in system registry." |
|
175 fi |
|
176 exit 0 |
|