author | never |
Mon, 12 Jul 2010 22:27:18 -0700 | |
changeset 5926 | a36f90d986b6 |
parent 5506 | 202f599c92aa |
child 6005 | f9e6c98d4ee3 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2007, 2008, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
24 |
/** |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
25 |
* @test |
1343
ecc86134ee4c
6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents:
1329
diff
changeset
|
26 |
* @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 |
ecc86134ee4c
6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents:
1329
diff
changeset
|
27 |
* @summary Argument parsing validation. |
4340
ec6ba551fa78
6367077: Purge LD_LIBRARY_PATH usage from the launcher
ksrini
parents:
1343
diff
changeset
|
28 |
* @compile -XDignore.symbol.file Arrrghs.java TestHelper.java |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
29 |
* @run main Arrrghs |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
30 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
31 |
|
399 | 32 |
import java.io.BufferedReader; |
33 |
import java.io.File; |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
34 |
import java.io.FileNotFoundException; |
399 | 35 |
import java.io.IOException; |
36 |
import java.io.InputStream; |
|
37 |
import java.io.InputStreamReader; |
|
38 |
import java.util.Map; |
|
2 | 39 |
|
399 | 40 |
public class Arrrghs { |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
41 |
private Arrrghs(){} |
2 | 42 |
/** |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
43 |
* This class provides various tests for arguments processing. |
2 | 44 |
* A group of tests to ensure that arguments are passed correctly to |
45 |
* a child java process upon a re-exec, this typically happens when |
|
46 |
* a version other than the one being executed is requested by the user. |
|
47 |
* |
|
48 |
* History: these set of tests were part of Arrrghs.sh. The MKS shell |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
49 |
* implementations were notoriously buggy. Implementing these tests purely |
2 | 50 |
* in Java is not only portable but also robust. |
51 |
* |
|
52 |
*/ |
|
53 |
||
54 |
// The version string to force a re-exec |
|
55 |
final static String VersionStr = "-version:1.1+"; |
|
56 |
||
57 |
// The Cookie or the pattern we match in the debug output. |
|
58 |
final static String Cookie = "ReExec Args: "; |
|
59 |
||
60 |
/* |
|
61 |
* SIGH, On Windows all strings are quoted, we need to unwrap it |
|
62 |
*/ |
|
63 |
private static String removeExtraQuotes(String in) { |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
64 |
if (TestHelper.isWindows) { |
2 | 65 |
// Trim the string and remove the enclosed quotes if any. |
66 |
in = in.trim(); |
|
67 |
if (in.startsWith("\"") && in.endsWith("\"")) { |
|
68 |
return in.substring(1, in.length()-1); |
|
69 |
} |
|
70 |
} |
|
71 |
return in; |
|
72 |
} |
|
73 |
||
74 |
/* |
|
75 |
* This method detects the cookie in the output stream of the process. |
|
76 |
*/ |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
77 |
private static boolean detectCookie(InputStream istream, |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
78 |
String expectedArguments) throws IOException { |
2 | 79 |
BufferedReader rd = new BufferedReader(new InputStreamReader(istream)); |
80 |
boolean retval = false; |
|
81 |
||
82 |
String in = rd.readLine(); |
|
83 |
while (in != null) { |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
84 |
if (TestHelper.debug) System.out.println(in); |
2 | 85 |
if (in.startsWith(Cookie)) { |
86 |
String detectedArgument = removeExtraQuotes(in.substring(Cookie.length())); |
|
87 |
if (expectedArguments.equals(detectedArgument)) { |
|
88 |
retval = true; |
|
89 |
} else { |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
90 |
System.out.println("Error: Expected Arguments\t:'" + |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
91 |
expectedArguments + "'"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
92 |
System.out.println(" Detected Arguments\t:'" + |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
93 |
detectedArgument + "'"); |
2 | 94 |
} |
95 |
// Return the value asap if not in debug mode. |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
96 |
if (!TestHelper.debug) { |
2 | 97 |
rd.close(); |
98 |
istream.close(); |
|
99 |
return retval; |
|
100 |
} |
|
101 |
} |
|
102 |
in = rd.readLine(); |
|
103 |
} |
|
104 |
return retval; |
|
105 |
} |
|
106 |
||
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
107 |
private static boolean doTest0(ProcessBuilder pb, String expectedArguments) { |
2 | 108 |
boolean retval = false; |
109 |
try { |
|
399 | 110 |
pb.redirectErrorStream(true); |
2 | 111 |
Process p = pb.start(); |
112 |
retval = detectCookie(p.getInputStream(), expectedArguments); |
|
113 |
p.waitFor(); |
|
114 |
p.destroy(); |
|
115 |
} catch (Exception ex) { |
|
116 |
ex.printStackTrace(); |
|
117 |
throw new RuntimeException(ex.getMessage()); |
|
118 |
} |
|
119 |
return retval; |
|
120 |
} |
|
121 |
||
122 |
/** |
|
123 |
* This method return true if the expected and detected arguments are the same. |
|
124 |
* Quoting could cause dissimilar testArguments and expected arguments. |
|
125 |
*/ |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
126 |
static int doTest(String testArguments, String expectedPattern) { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
127 |
ProcessBuilder pb = new ProcessBuilder(TestHelper.javaCmd, |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
128 |
VersionStr, testArguments); |
2 | 129 |
|
130 |
Map<String, String> env = pb.environment(); |
|
131 |
env.put("_JAVA_LAUNCHER_DEBUG", "true"); |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
132 |
return doTest0(pb, testArguments) ? 0 : 1; |
2 | 133 |
} |
134 |
||
135 |
/** |
|
136 |
* A convenience method for identical test pattern and expected arguments |
|
137 |
*/ |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
138 |
static int doTest(String testPattern) { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
139 |
return doTest(testPattern, testPattern); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
140 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
141 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
142 |
static void quoteParsingTests() { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
143 |
/* |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
144 |
* Tests for 6214916 |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
145 |
* These tests require that a JVM (any JVM) be installed in the system registry. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
146 |
* If none is installed, skip this test. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
147 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
148 |
TestHelper.TestResult tr = |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
149 |
TestHelper.doExec(TestHelper.javaCmd, VersionStr, "-version"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
150 |
if (!tr.isOK()) { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
151 |
System.err.println("Warning:Argument Passing Tests were skipped, " + |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
152 |
"no java found in system registry."); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
153 |
return; |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
154 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
155 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
156 |
// Basic test |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
157 |
TestHelper.testExitValue += doTest("-a -b -c -d"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
158 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
159 |
// Basic test with many spaces |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
160 |
TestHelper.testExitValue += doTest("-a -b -c -d"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
161 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
162 |
// Quoted whitespace does matter ? |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
163 |
TestHelper.testExitValue += doTest("-a \"\"-b -c\"\" -d"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
164 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
165 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
166 |
// Escaped quotes outside of quotes as literals |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
167 |
TestHelper.testExitValue += doTest("-a \\\"-b -c\\\" -d"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
168 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
169 |
// Check for escaped quotes inside of quotes as literal |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
170 |
TestHelper.testExitValue += doTest("-a \"-b \\\"stuff\\\"\" -c -d"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
171 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
172 |
// A quote preceeded by an odd number of slashes is a literal quote |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
173 |
TestHelper.testExitValue += doTest("-a -b\\\\\\\" -c -d"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
174 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
175 |
// A quote preceeded by an even number of slashes is a literal quote |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
176 |
// see 6214916. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
177 |
TestHelper.testExitValue += doTest("-a -b\\\\\\\\\" -c -d"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
178 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
179 |
// Make sure that whitespace doesn't interfere with the removal of the |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
180 |
// appropriate tokens. (space-tab-space preceeds -jre-restict-search). |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
181 |
TestHelper.testExitValue += doTest("-a -b \t -jre-restrict-search -c -d","-a -b -c -d"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
182 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
183 |
// Make sure that the mJRE tokens being stripped, aren't stripped if |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
184 |
// they happen to appear as arguments to the main class. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
185 |
TestHelper.testExitValue += doTest("foo -version:1.1+"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
186 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
187 |
System.out.println("Completed arguments quoting tests with " + |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
188 |
TestHelper.testExitValue + " errors"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
189 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
190 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
191 |
/* |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
192 |
* These tests are usually run on non-existent targets to check error results |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
193 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
194 |
static void runBasicErrorMessageTests() { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
195 |
// Tests for 5030233 |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
196 |
TestHelper.TestResult tr = TestHelper.doExec(TestHelper.javaCmd, "-cp"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
197 |
tr.checkNegative(); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
198 |
tr.isNotZeroOutput(); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
199 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
200 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
201 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-classpath"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
202 |
tr.checkNegative(); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
203 |
tr.isNotZeroOutput(); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
204 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
205 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
206 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-jar"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
207 |
tr.checkNegative(); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
208 |
tr.isNotZeroOutput(); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
209 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
210 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
211 |
tr = TestHelper.doExec(TestHelper.javacCmd, "-cp"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
212 |
tr.checkNegative(); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
213 |
tr.isNotZeroOutput(); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
214 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
215 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
216 |
// Test for 6356475 "REGRESSION:"java -X" from cmdline fails" |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
217 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-X"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
218 |
tr.checkPositive(); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
219 |
tr.isNotZeroOutput(); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
220 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
221 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
222 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-help"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
223 |
tr.checkPositive(); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
224 |
tr.isNotZeroOutput(); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
225 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
226 |
} |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
227 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
228 |
/* |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
229 |
* A set of tests which tests various dispositions of the main method. |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
230 |
*/ |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
231 |
static void runMainMethodTests() throws FileNotFoundException { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
232 |
TestHelper.TestResult tr = null; |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
233 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
234 |
// a missing class |
1329
ce13b59a8401
4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents:
1323
diff
changeset
|
235 |
TestHelper.createJar("MIA", new File("some.jar"), new File("Foo"), |
ce13b59a8401
4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents:
1323
diff
changeset
|
236 |
(String[])null); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
237 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar"); |
1343
ecc86134ee4c
6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents:
1329
diff
changeset
|
238 |
tr.contains("Error: Could not find main class MIA"); |
ecc86134ee4c
6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents:
1329
diff
changeset
|
239 |
tr.contains("java.lang.NoClassDefFoundError: MIA"); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
240 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
241 |
// use classpath to check |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
242 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "MIA"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
243 |
tr.contains("Error: Could not find main class MIA"); |
1343
ecc86134ee4c
6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents:
1329
diff
changeset
|
244 |
tr.contains("java.lang.NoClassDefFoundError: MIA"); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
245 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
246 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
247 |
// incorrect method access |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
248 |
TestHelper.createJar(new File("some.jar"), new File("Foo"), |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
249 |
"private static void main(String[] args){}"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
250 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
251 |
tr.contains("Error: Main method not found in class Foo"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
252 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
253 |
// use classpath to check |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
254 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
255 |
tr.contains("Error: Main method not found in class Foo"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
256 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
257 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
258 |
// incorrect return type |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
259 |
TestHelper.createJar(new File("some.jar"), new File("Foo"), |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
260 |
"public static int main(String[] args){return 1;}"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
261 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
262 |
tr.contains("Error: Main method must return a value of type void in class Foo"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
263 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
264 |
// use classpath to check |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
265 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
266 |
tr.contains("Error: Main method must return a value of type void in class Foo"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
267 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
268 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
269 |
// incorrect parameter type |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
270 |
TestHelper.createJar(new File("some.jar"), new File("Foo"), |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
271 |
"public static void main(Object[] args){}"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
272 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
273 |
tr.contains("Error: Main method not found in class Foo"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
274 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
275 |
// use classpath to check |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
276 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
277 |
tr.contains("Error: Main method not found in class Foo"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
278 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
279 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
280 |
// incorrect method type - non-static |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
281 |
TestHelper.createJar(new File("some.jar"), new File("Foo"), |
1329
ce13b59a8401
4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents:
1323
diff
changeset
|
282 |
"public void main(String[] args){}"); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
283 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar"); |
1329
ce13b59a8401
4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents:
1323
diff
changeset
|
284 |
tr.contains("Error: Main method is not static in class Foo"); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
285 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
286 |
// use classpath to check |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
287 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo"); |
1329
ce13b59a8401
4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents:
1323
diff
changeset
|
288 |
tr.contains("Error: Main method is not static in class Foo"); |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
289 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
290 |
|
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
291 |
// amongst a potpourri of kindred main methods, is the right one chosen ? |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
292 |
TestHelper.createJar(new File("some.jar"), new File("Foo"), |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
293 |
"void main(Object[] args){}", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
294 |
"int main(Float[] args){return 1;}", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
295 |
"private void main() {}", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
296 |
"private static void main(int x) {}", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
297 |
"public int main(int argc, String[] argv) {return 1;}", |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
298 |
"public static void main(String[] args) {System.out.println(\"THE_CHOSEN_ONE\");}"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
299 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
300 |
tr.contains("THE_CHOSEN_ONE"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
301 |
System.out.println(tr); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
302 |
// use classpath to check |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
303 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-cp", "some.jar", "Foo"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
304 |
tr.contains("THE_CHOSEN_ONE"); |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
305 |
System.out.println(tr); |
1329
ce13b59a8401
4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents:
1323
diff
changeset
|
306 |
|
ce13b59a8401
4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents:
1323
diff
changeset
|
307 |
// test for extraneous whitespace in the Main-Class attribute |
ce13b59a8401
4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents:
1323
diff
changeset
|
308 |
TestHelper.createJar(" Foo ", new File("some.jar"), new File("Foo"), |
ce13b59a8401
4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents:
1323
diff
changeset
|
309 |
"public static void main(String... args){}"); |
ce13b59a8401
4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents:
1323
diff
changeset
|
310 |
tr = TestHelper.doExec(TestHelper.javaCmd, "-jar", "some.jar"); |
ce13b59a8401
4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents:
1323
diff
changeset
|
311 |
tr.checkPositive(); |
ce13b59a8401
4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents:
1323
diff
changeset
|
312 |
System.out.println(tr); |
2 | 313 |
} |
314 |
||
315 |
/** |
|
316 |
* @param args the command line arguments |
|
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
317 |
* @throws java.io.FileNotFoundException |
2 | 318 |
*/ |
1323
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
319 |
public static void main(String[] args) throws FileNotFoundException { |
e14a3b3536cd
6742159: (launcher) improve the java launching mechanism
ksrini
parents:
399
diff
changeset
|
320 |
if (TestHelper.debug) System.out.println("Starting Arrrghs tests"); |
1343
ecc86134ee4c
6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents:
1329
diff
changeset
|
321 |
quoteParsingTests(); |
ecc86134ee4c
6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents:
1329
diff
changeset
|
322 |
runBasicErrorMessageTests(); |
ecc86134ee4c
6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents:
1329
diff
changeset
|
323 |
runMainMethodTests(); |
ecc86134ee4c
6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents:
1329
diff
changeset
|
324 |
if (TestHelper.testExitValue > 0) { |
ecc86134ee4c
6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents:
1329
diff
changeset
|
325 |
System.out.println("Total of " + TestHelper.testExitValue + " failed"); |
ecc86134ee4c
6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents:
1329
diff
changeset
|
326 |
System.exit(1); |
ecc86134ee4c
6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents:
1329
diff
changeset
|
327 |
} else { |
ecc86134ee4c
6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents:
1329
diff
changeset
|
328 |
System.out.println("All tests pass"); |
ecc86134ee4c
6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents:
1329
diff
changeset
|
329 |
} |
2 | 330 |
} |
331 |
} |