Arrrghs.java revision 5271
911N/A * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved. 767N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 98N/A * This code is free software; you can redistribute it and/or modify it 919N/A * under the terms of the GNU General Public License version 2 only, as 919N/A * published by the Free Software Foundation. 919N/A * This code is distributed in the hope that it will be useful, but WITHOUT 919N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 919N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 919N/A * version 2 for more details (a copy is included in the LICENSE file that 919N/A * accompanied this code). 919N/A * You should have received a copy of the GNU General Public License version 919N/A * 2 along with this work; if not, write to the Free Software Foundation, 919N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 919N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 919N/A * or visit www.oracle.com if you need additional information or have any 98N/A * @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 6753938 493N/A * 6894719 6968053 7151434 98N/A * @summary Argument parsing validation. 98N/A * This class provides various tests for arguments processing. 606N/A * A group of tests to ensure that arguments are passed correctly to 606N/A * a child java process upon a re-exec, this typically happens when 606N/A * a version other than the one being executed is requested by the user. 493N/A * History: these set of tests were part of Arrrghs.sh. The MKS shell 493N/A * implementations were notoriously buggy. Implementing these tests purely 493N/A * in Java is not only portable but also robust. 705N/A // The version string to force a re-exec 493N/A // The Cookie or the pattern we match in the debug output. * SIGH, On Windows all strings are quoted, we need to unwrap it // Trim the string and remove the enclosed quotes if any. * This method detects the cookie in the output stream of the process. // Return the value asap if not in debug mode. * This method returns true if the expected and detected arguments are the same. * Quoting could cause dissimilar testArguments and expected arguments. * A convenience method for identical test pattern and expected arguments * These tests require that a JVM (any JVM) be installed in the system registry. * If none is installed, skip this test. "no java found in system registry.");
// Basic test with many spaces // Quoted whitespace does matter ? // Escaped quotes outside of quotes as literals // Check for escaped quotes inside of quotes as literal // A quote preceeded by an odd number of slashes is a literal quote // A quote preceeded by an even number of slashes is a literal quote // Make sure that whitespace doesn't interfere with the removal of the // appropriate tokens. (space-tab-space preceeds -jre-restict-search). // Make sure that the mJRE tokens being stripped, aren't stripped if // they happen to appear as arguments to the main class. // the pattern we hope to see in the output // GAK, -version needs to be added so that windows can flush its stderr // exiting the process prematurely can terminate the stderr. * This tests general quoting and are specific to Windows, *nixes * need not worry about this, these have been tested with Windows * implementation and those that are known to work are used against * the java implementation. Note that the ProcessBuilder gets in the * way when testing some of these arguments, therefore we need to * create and execute a .bat file containing the arguments. // a literal within single quotes // a literal within double quotes // expansions of white space separators // triple back-slash in quotes // slashes separating characters // literals within dangling quotes, etc. // treatment of back-slashes scratchpad.
add(
"public static void main(String... args){Foo.f();}");
// now add arbitrary arguments before and after * These tests are not expected to work on *nixes, and are ignored. // test if javac (the command) can compile *.java // use the jar cmd to create jars using the ? wildcard // now the litmus test!, this should work // test for basic expansion // basic expansion in quotes "lib\\Foo.class",
"lib\\Foo.jar",
"lib\\Foo.java");
"lib\\Foo.class",
"lib\\Foo.jar",
"lib\\Foo.java");
"lib\\Foo.class",
"lib\\Foo.jar",
"lib\\Foo.java");
// test for basic expansion // basic expansion in quotes // suffix expansion in quotes // check for ? expansion now // check ? in a leading role // check ? prefixed with - // check * prefixed with - // check on empty directory sindex++;
// skip over the tag * These tests are usually run on non-existent targets to check error results // Test for 6356475 "REGRESSION:"java -X" from cmdline fails" // 6753938, test for non-negative exit value for an incorrectly formed // command line, '% java' // 6753938, test for non-negative exit value for an incorrectly formed // command line, '% java -Xcomp' // 7151434, test for non-negative exit value for an incorrectly formed // command line, '% java -jar -W', note the bogus -W * Tests various dispositions of the main method, these tests are limited * to English locales as they check for error messages that are localized. tr.
contains(
"Error: Could not find or load main class MIA");
// use classpath to check tr.
contains(
"Error: Could not find or load main class MIA");
// incorrect method access "private static void main(String[] args){}");
tr.
contains(
"Error: Main method not found in class Foo");
// use classpath to check tr.
contains(
"Error: Main method not found in class Foo");
"public static int main(String[] args){return 1;}");
tr.
contains(
"Error: Main method must return a value of type void in class Foo");
// use classpath to check tr.
contains(
"Error: Main method must return a value of type void in class Foo");
// incorrect parameter type "public static void main(Object[] args){}");
tr.
contains(
"Error: Main method not found in class Foo");
// use classpath to check tr.
contains(
"Error: Main method not found in class Foo");
// incorrect method type - non-static "public void main(String[] args){}");
tr.
contains(
"Error: Main method is not static in class Foo");
// use classpath to check tr.
contains(
"Error: Main method is not static in class Foo");
// amongst a potpourri of kindred main methods, is the right one chosen ? "void main(Object[] args){}",
"int main(Float[] args){return 1;}",
"private void main() {}",
"private static void main(int x) {}",
"public int main(int argc, String[] argv) {return 1;}",
"public static void main(String[] args) {System.out.println(\"THE_CHOSEN_ONE\");}");
// use classpath to check // test for extraneous whitespace in the Main-Class attribute "public static void main(String... args){}");
* tests 6968053, ie. we turn on the -Xdiag (for now) flag and check if * the suppressed stack traces are exposed, ignore these tests for localized * locales, limiting to English only. tr.
contains(
"Error: Could not find or load main class MIA");
tr.
contains(
"java.lang.ClassNotFoundException: MIA");
// use classpath to check tr.
contains(
"Error: Could not find or load main class MIA");
tr.
contains(
"java.lang.ClassNotFoundException: MIA");
// a missing class on the classpath tr.
contains(
"Error: Could not find or load main class NonExistentClass");
tr.
contains(
"java.lang.ClassNotFoundException: NonExistentClass");
// test both arguments to ensure they exist "-no-jre-restrict-search",
"-version");
"-jre-restrict-search",
"-version");
* @param args the command line arguments * @throws java.io.FileNotFoundException