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