/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* @test
* @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 6753938
* 6894719 6968053 7151434 7146424 8007333
* @summary Argument parsing validation.
* @compile -XDignore.symbol.file Arrrghs.java
*/
private Arrrghs(){}
/**
* This class provides various tests for arguments processing.
* A group of tests to ensure that arguments are passed correctly to
* a child java process upon a re-exec, this typically happens when
* a version other than the one being executed is requested by the user.
*
* History: these set of tests were part of Arrrghs.sh. The MKS shell
* implementations were notoriously buggy. Implementing these tests purely
* in Java is not only portable but also robust.
*
*/
// The version string to force a re-exec
// The Cookie or the pattern we match in the debug output.
/*
* SIGH, On Windows all strings are quoted, we need to unwrap it
*/
if (isWindows) {
// Trim the string and remove the enclosed quotes if any.
}
}
return in;
}
/*
* This method detects the cookie in the output stream of the process.
*/
boolean retval = false;
retval = true;
} else {
expectedArguments + "'");
detectedArgument + "'");
}
// Return the value asap if not in debug mode.
if (!debug) {
return retval;
}
}
}
return retval;
}
boolean retval = false;
try {
pb.redirectErrorStream(true);
p.waitFor();
p.destroy();
}
return retval;
}
/**
* 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
*/
}
@Test
void testQuoteParsingThroughReExec() {
/*
* Tests for 6214916
* 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.");
return;
}
// Basic test
// 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
// see 6214916.
// 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.
+ testExitValue + " errors");
}
// 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.
if (m.matches()) {
}
}
throw new RuntimeException("Error: args do not match");
}
}
/*
* 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.
*/
@Test
if (!isWindows)
return;
// no quotes
// single quotes
//double quotes
// triple quotes
// a literal within single quotes
// a literal within double quotes
// a literal quote
// double back-slash
// triple back-slash
// dangling quote
// expansions of white space separators
// MS Windows tests
// triple back-slash
// triple back-slash in quotes
// slashes separating characters
// literals within dangling quotes, etc.
// treatment of back-slashes
// 2 back-slashes
// 3 back-slashes
// 4 back-slashes
// 5 back-slashes
// 6 back-slashes
// more treatment of mixed slashes
}
}
}
}
scratchpad.clear();
}
// now add arbitrary arguments before and after
}
throw new RuntimeException("Error: classpath single entry wildcard entry");
}
}
throw new RuntimeException("Error: args do not match");
}
}
}
/*
* These tests are not expected to work on *nixes, and are ignored.
*/
@Test
if (!isWindows)
return;
// test if javac (the command) can compile *.java
throw new RuntimeException("Error: compiling java wildcards");
}
// use the jar cmd to create jars using the ? wildcard
throw new RuntimeException("Error: creating jar with wildcards");
}
// now the litmus test!, this should work
// test for basic expansion
// basic expansion in quotes
// test for basic expansion
// basic expansion in quotes
// suffix expansion
// suffix expansion in quotes
// check for ? expansion now
// check ? in quotes
// check ? as suffixes
// check ? in a leading role
// check ? prefixed with -
// check * prefixed with -
// check on empty directory
}
if (sindex < 0) {
throw new RuntimeException("Error: no output");
}
sindex++; // skip over the tag
}
throw new RuntimeException("Error: args do not match");
}
}
/*
* These tests are usually run on non-existent targets to check error results
*/
@Test
void testBasicErrorMessages() {
// Tests for 5030233
tr.checkNegative();
if (!tr.testStatus)
tr.checkNegative();
if (!tr.testStatus)
tr.checkNegative();
if (!tr.testStatus)
tr.checkNegative();
if (!tr.testStatus)
// Test for 6356475 "REGRESSION:"java -X" from cmdline fails"
tr.checkPositive();
if (!tr.testStatus)
tr.checkPositive();
if (!tr.testStatus)
// 6753938, test for non-negative exit value for an incorrectly formed
// command line, '% java'
tr.checkNegative();
if (!tr.testStatus)
// 6753938, test for non-negative exit value for an incorrectly formed
// command line, '% java -Xcomp'
tr.checkNegative();
if (!tr.testStatus)
// 7151434, test for non-negative exit value for an incorrectly formed
// command line, '% java -jar -W', note the bogus -W
tr.checkNegative();
if (!tr.testStatus)
}
/*
* Tests various dispositions of the main method, these tests are limited
* to English locales as they check for error messages that are localized.
*/
@Test
if (!isEnglishLocale()) {
return;
}
// a missing class
if (!tr.testStatus)
// use classpath to check
if (!tr.testStatus)
// incorrect method access
"private static void main(String[] args){}");
if (!tr.testStatus)
// use classpath to check
if (!tr.testStatus)
// incorrect return type
"public static int main(String[] args){return 1;}");
if (!tr.testStatus)
// use classpath to check
if (!tr.testStatus)
// incorrect parameter type
"public static void main(Object[] args){}");
if (!tr.testStatus)
// use classpath to check
if (!tr.testStatus)
// incorrect method type - non-static
"public void main(String[] args){}");
if (!tr.testStatus)
// use classpath to check
if (!tr.testStatus)
// 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\");}");
if (!tr.testStatus)
// use classpath to check
if (!tr.testStatus)
// test for extraneous whitespace in the Main-Class attribute
"public static void main(String... args){}");
tr.checkPositive();
if (!tr.testStatus)
}
/*
* 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.
*/
@Test
if (!isEnglishLocale()) { // only english version
return;
}
// a missing class
if (!tr.testStatus)
// use classpath to check
if (!tr.testStatus)
// a missing class on the classpath
if (!tr.testStatus)
}
@Test
static void testJreRestrictSearchFlag() {
// test both arguments to ensure they exist
"-no-jre-restrict-search", "-version");
tr.checkPositive();
if (!tr.testStatus)
"-jre-restrict-search", "-version");
tr.checkPositive();
if (!tr.testStatus)
}
/**
* @param args the command line arguments
* @throws java.io.FileNotFoundException
*/
if (debug) {
}
if (testExitValue > 0) {
} else {
}
}
}