Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/tools/launcher/Arrrghs.java
38833 views
/*1* Copyright (c) 2007, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 675393826* 6894719 6968053 7151434 7146424 8007333 8077822 814364027* @summary Argument parsing validation.28* @compile -XDignore.symbol.file Arrrghs.java29* @run main/othervm Arrrghs30*/3132import java.io.BufferedReader;33import java.io.File;34import java.io.FileNotFoundException;35import java.io.IOException;36import java.io.InputStream;37import java.io.InputStreamReader;38import java.util.ArrayList;39import java.util.Arrays;40import java.util.HashMap;41import java.util.List;42import java.util.Map;43import java.util.regex.Matcher;44import java.util.regex.Pattern;4546public class Arrrghs extends TestHelper {47private Arrrghs(){}48/**49* This class provides various tests for arguments processing.50* A group of tests to ensure that arguments are passed correctly to51* a child java process upon a re-exec, this typically happens when52* a version other than the one being executed is requested by the user.53*54* History: these set of tests were part of Arrrghs.sh. The MKS shell55* implementations were notoriously buggy. Implementing these tests purely56* in Java is not only portable but also robust.57*58*/5960// The version string to force a re-exec61final static String VersionStr = "-version:1.1+";6263// The Cookie or the pattern we match in the debug output.64final static String Cookie = "ReExec Args: ";6566/*67* SIGH, On Windows all strings are quoted, we need to unwrap it68*/69private static String removeExtraQuotes(String in) {70if (isWindows) {71// Trim the string and remove the enclosed quotes if any.72in = in.trim();73if (in.startsWith("\"") && in.endsWith("\"")) {74return in.substring(1, in.length()-1);75}76}77return in;78}7980/*81* This method detects the cookie in the output stream of the process.82*/83private boolean detectCookie(InputStream istream,84String expectedArguments) throws IOException {85BufferedReader rd = new BufferedReader(new InputStreamReader(istream));86boolean retval = false;8788String in = rd.readLine();89while (in != null) {90if (debug) System.out.println(in);91if (in.startsWith(Cookie)) {92String detectedArgument = removeExtraQuotes(in.substring(Cookie.length()));93if (expectedArguments.equals(detectedArgument)) {94retval = true;95} else {96System.out.println("Error: Expected Arguments\t:'" +97expectedArguments + "'");98System.out.println(" Detected Arguments\t:'" +99detectedArgument + "'");100}101// Return the value asap if not in debug mode.102if (!debug) {103rd.close();104istream.close();105return retval;106}107}108in = rd.readLine();109}110return retval;111}112113private boolean doReExecTest0(ProcessBuilder pb, String expectedArguments) {114boolean retval = false;115try {116pb.redirectErrorStream(true);117Process p = pb.start();118retval = detectCookie(p.getInputStream(), expectedArguments);119p.waitFor();120p.destroy();121} catch (Exception ex) {122ex.printStackTrace();123throw new RuntimeException(ex.getMessage());124}125return retval;126}127128/**129* This method returns true if the expected and detected arguments are the same.130* Quoting could cause dissimilar testArguments and expected arguments.131*/132int doReExecTest(String testArguments, String expectedPattern) {133ProcessBuilder pb = new ProcessBuilder(javaCmd,134VersionStr, testArguments);135136Map<String, String> env = pb.environment();137env.put(JLDEBUG_KEY, "true");138return doReExecTest0(pb, testArguments) ? 0 : 1;139}140141/**142* A convenience method for identical test pattern and expected arguments143*/144int doReExecTest(String testPattern) {145return doReExecTest(testPattern, testPattern);146}147148@Test149void testQuoteParsingThroughReExec() {150/*151* Tests for 6214916152* These tests require that a JVM (any JVM) be installed in the system registry.153* If none is installed, skip this test.154*/155TestResult tr = doExec(javaCmd, VersionStr, "-version");156if (!tr.isOK()) {157System.err.println("Warning:Argument Passing Tests were skipped, " +158"no java found in system registry.");159return;160}161162// Basic test163testExitValue += doReExecTest("-a -b -c -d");164165// Basic test with many spaces166testExitValue += doReExecTest("-a -b -c -d");167168// Quoted whitespace does matter ?169testExitValue += doReExecTest("-a \"\"-b -c\"\" -d");170171172// Escaped quotes outside of quotes as literals173testExitValue += doReExecTest("-a \\\"-b -c\\\" -d");174175// Check for escaped quotes inside of quotes as literal176testExitValue += doReExecTest("-a \"-b \\\"stuff\\\"\" -c -d");177178// A quote preceeded by an odd number of slashes is a literal quote179testExitValue += doReExecTest("-a -b\\\\\\\" -c -d");180181// A quote preceeded by an even number of slashes is a literal quote182// see 6214916.183testExitValue += doReExecTest("-a -b\\\\\\\\\" -c -d");184185// Make sure that whitespace doesn't interfere with the removal of the186// appropriate tokens. (space-tab-space preceeds -jre-restict-search).187testExitValue += doReExecTest("-a -b \t -jre-restrict-search -c -d", "-a -b -c -d");188189// Make sure that the mJRE tokens being stripped, aren't stripped if190// they happen to appear as arguments to the main class.191testExitValue += doReExecTest("foo -version:1.1+");192193System.out.println("Completed arguments quoting tests with "194+ testExitValue + " errors");195}196// the pattern we hope to see in the output197static final Pattern ArgPattern = Pattern.compile("\\s*argv\\[[0-9]*\\].*=.*");198199void checkArgumentParsing(String inArgs, String... expArgs) throws IOException {200List<String> scratchpad = new ArrayList<>();201scratchpad.add("set " + JLDEBUG_KEY + "=true");202// GAK, -version needs to be added so that windows can flush its stderr203// exiting the process prematurely can terminate the stderr.204scratchpad.add(javaCmd + " -version " + inArgs);205File batFile = new File("atest.bat");206createAFile(batFile, scratchpad);207208TestResult tr = doExec(batFile.getName());209210ArrayList<String> expList = new ArrayList<>();211expList.add(javaCmd);212expList.add("-version");213expList.addAll(Arrays.asList(expArgs));214215List<String> gotList = new ArrayList<>();216for (String x : tr.testOutput) {217Matcher m = ArgPattern.matcher(x);218if (m.matches()) {219String a[] = x.split("=");220gotList.add(a[a.length - 1].trim());221}222}223if (!gotList.equals(expList)) {224System.out.println(tr);225System.out.println("Expected args:");226System.out.println(expList);227System.out.println("Obtained args:");228System.out.println(gotList);229throw new RuntimeException("Error: args do not match");230}231System.out.println("\'" + inArgs + "\'" + " - Test passed");232}233234/*235* This tests general quoting and are specific to Windows, *nixes236* need not worry about this, these have been tested with Windows237* implementation and those that are known to work are used against238* the java implementation. Note that the ProcessBuilder gets in the239* way when testing some of these arguments, therefore we need to240* create and execute a .bat file containing the arguments.241*/242@Test243void testArgumentParsing() throws IOException {244if (!isWindows)245return;246// no quotes247checkArgumentParsing("a b c d", "a", "b", "c", "d");248249// single quotes250checkArgumentParsing("\"a b c d\"", "a b c d");251252//double quotes253checkArgumentParsing("\"\"a b c d\"\"", "a", "b", "c", "d");254255// triple quotes256checkArgumentParsing("\"\"\"a b c d\"\"\"", "\"a b c d\"");257258// a literal within single quotes259checkArgumentParsing("\"a\"b c d\"e\"", "ab", "c", "de");260261// a literal within double quotes262checkArgumentParsing("\"\"a\"b c d\"e\"\"", "ab c de");263264// a literal quote265checkArgumentParsing("a\\\"b", "a\"b");266267// double back-slash268checkArgumentParsing("\"a b c d\\\\\"", "a b c d\\");269270// triple back-slash271checkArgumentParsing("a\\\\\\\"b", "a\\\"b");272273// dangling quote274checkArgumentParsing("\"a b c\"\"", "a b c\"");275276// expansions of white space separators277checkArgumentParsing("a b", "a", "b");278checkArgumentParsing("a\tb", "a", "b");279checkArgumentParsing("a \t b", "a", "b");280281checkArgumentParsing("\"C:\\TEST A\\\\\"", "C:\\TEST A\\");282checkArgumentParsing("\"\"C:\\TEST A\\\\\"\"", "C:\\TEST", "A\\");283284// MS Windows tests285// triple back-slash286checkArgumentParsing("a\\\\\\d", "a\\\\\\d");287288// triple back-slash in quotes289checkArgumentParsing("\"a\\\\\\d\"", "a\\\\\\d");290291// slashes separating characters292checkArgumentParsing("X\\Y\\Z", "X\\Y\\Z");293checkArgumentParsing("\\X\\Y\\Z", "\\X\\Y\\Z");294295// literals within dangling quotes, etc.296checkArgumentParsing("\"a b c\" d e", "a b c", "d", "e");297checkArgumentParsing("\"ab\\\"c\" \"\\\\\" d", "ab\"c", "\\", "d");298checkArgumentParsing("a\\\\\\c d\"e f\"g h", "a\\\\\\c", "de fg", "h");299checkArgumentParsing("a\\\\\\\"b c d", "a\\\"b", "c", "d");300checkArgumentParsing("a\\\\\\\\\"g c\" d e", "a\\\\g c", "d", "e");301302// treatment of back-slashes303checkArgumentParsing("*\\", "*\\");304checkArgumentParsing("*/", "*/");305checkArgumentParsing(".\\*", ".\\*");306checkArgumentParsing("./*", "./*");307checkArgumentParsing("..\\..\\*", "..\\..\\*");308checkArgumentParsing("../../*", "../../*");309checkArgumentParsing("..\\..\\", "..\\..\\");310checkArgumentParsing("../../", "../../");311checkArgumentParsing("a b\\ c", "a", "b\\", "c");312// 2 back-slashes313checkArgumentParsing("\\\\?", "\\\\?");314// 3 back-slashes315checkArgumentParsing("\\\\\\?", "\\\\\\?");316// 4 back-slashes317checkArgumentParsing("\\\\\\\\?", "\\\\\\\\?");318// 5 back-slashes319checkArgumentParsing("\\\\\\\\\\?", "\\\\\\\\\\?");320// 6 back-slashes321checkArgumentParsing("\\\\\\\\\\\\?", "\\\\\\\\\\\\?");322323// more treatment of mixed slashes324checkArgumentParsing("f1/ f3\\ f4/", "f1/", "f3\\", "f4/");325checkArgumentParsing("f1/ f2\' ' f3/ f4/", "f1/", "f2\'", "'", "f3/", "f4/");326327checkArgumentParsing("a\\*\\b", "a\\*\\b");328}329330private void initEmptyDir(File emptyDir) throws IOException {331if (emptyDir.exists()) {332recursiveDelete(emptyDir);333}334emptyDir.mkdir();335}336337private void initDirWithJavaFiles(File libDir) throws IOException {338339if (libDir.exists()) {340recursiveDelete(libDir);341}342libDir.mkdirs();343ArrayList<String> scratchpad = new ArrayList<>();344scratchpad.add("package lib;");345scratchpad.add("public class Fbo {");346scratchpad.add("public static void main(String... args){Foo.f();}");347scratchpad.add("public static void f(){}");348scratchpad.add("}");349createFile(new File(libDir, "Fbo.java"), scratchpad);350351scratchpad.clear();352scratchpad.add("package lib;");353scratchpad.add("public class Foo {");354scratchpad.add("public static void main(String... args){");355scratchpad.add("for (String x : args) {");356scratchpad.add("System.out.println(x);");357scratchpad.add("}");358scratchpad.add("Fbo.f();");359scratchpad.add("}");360scratchpad.add("public static void f(){}");361scratchpad.add("}");362createFile(new File(libDir, "Foo.java"), scratchpad);363}364365void checkArgumentWildcard(String inArgs, String... expArgs) throws IOException {366String[] in = {inArgs};367checkArgumentWildcard(in, expArgs);368369// now add arbitrary arguments before and after370String[] outInArgs = { "-Q", inArgs, "-R"};371372String[] outExpArgs = new String[expArgs.length + 2];373outExpArgs[0] = "-Q";374System.arraycopy(expArgs, 0, outExpArgs, 1, expArgs.length);375outExpArgs[expArgs.length + 1] = "-R";376checkArgumentWildcard(outInArgs, outExpArgs);377}378379void checkArgumentWildcard(String[] inArgs, String[] expArgs) throws IOException {380ArrayList<String> argList = new ArrayList<>();381argList.add(javaCmd);382argList.add("-cp");383argList.add("lib" + File.separator + "*");384argList.add("lib.Foo");385argList.addAll(Arrays.asList(inArgs));386String[] cmds = new String[argList.size()];387argList.toArray(cmds);388TestResult tr = doExec(cmds);389if (!tr.isOK()) {390System.out.println(tr);391throw new RuntimeException("Error: classpath single entry wildcard entry");392}393394ArrayList<String> expList = new ArrayList<>();395expList.addAll(Arrays.asList(expArgs));396397List<String> gotList = new ArrayList<>();398for (String x : tr.testOutput) {399gotList.add(x.trim());400}401if (!gotList.equals(expList)) {402System.out.println(tr);403System.out.println("Expected args:");404System.out.println(expList);405System.out.println("Obtained args:");406System.out.println(gotList);407throw new RuntimeException("Error: args do not match");408}409System.out.print("\'");410for (String x : inArgs) {411System.out.print(x + " ");412}413System.out.println("\'" + " - Test passed");414}415416/*417* These tests are not expected to work on *nixes, and are ignored.418*/419@Test420void testWildCardArgumentProcessing() throws IOException {421if (!isWindows)422return;423File cwd = new File(".");424File libDir = new File(cwd, "lib");425initDirWithJavaFiles(libDir);426initEmptyDir(new File(cwd, "empty"));427428// test if javac (the command) can compile *.java429TestResult tr = doExec(javacCmd, libDir.getName() + File.separator + "*.java");430if (!tr.isOK()) {431System.out.println(tr);432throw new RuntimeException("Error: compiling java wildcards");433}434435// test if javac (the command) can compile *.java with a vmoption436tr = doExec(javacCmd, "-cp", ".",437"-J-showversion", "-J-Dsomeproperty=foo",438libDir.getName() + File.separator + "*.java");439if (!tr.isOK()) {440System.out.println(tr);441throw new RuntimeException("Error: compiling java wildcards with vmoptions");442}443444445// use the jar cmd to create jars using the ? wildcard446File jarFoo = new File(libDir, "Foo.jar");447tr = doExec(jarCmd, "cvf", jarFoo.getAbsolutePath(), "lib" + File.separator + "F?o.class");448if (!tr.isOK()) {449System.out.println(tr);450throw new RuntimeException("Error: creating jar with wildcards");451}452453// now the litmus test!, this should work454checkArgumentWildcard("a", "a");455456// test for basic expansion457checkArgumentWildcard("lib\\F*java", "lib\\Fbo.java", "lib\\Foo.java");458459// basic expansion in quotes460checkArgumentWildcard("\"lib\\F*java\"", "lib\\F*java");461462checkArgumentWildcard("lib\\**", "lib\\Fbo.class", "lib\\Fbo.java",463"lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");464465checkArgumentWildcard("lib\\*?", "lib\\Fbo.class", "lib\\Fbo.java",466"lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");467468checkArgumentWildcard("lib\\?*", "lib\\Fbo.class", "lib\\Fbo.java",469"lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");470471checkArgumentWildcard("lib\\?", "lib\\?");472473// test for basic expansion474checkArgumentWildcard("lib\\*java", "lib\\Fbo.java", "lib\\Foo.java");475476// basic expansion in quotes477checkArgumentWildcard("\"lib\\*.java\"", "lib\\*.java");478479// suffix expansion480checkArgumentWildcard("lib\\*.class", "lib\\Fbo.class", "lib\\Foo.class");481482// suffix expansion in quotes483checkArgumentWildcard("\"lib\\*.class\"", "lib\\*.class");484485// check for ? expansion now486checkArgumentWildcard("lib\\F?o.java", "lib\\Fbo.java", "lib\\Foo.java");487488// check ? in quotes489checkArgumentWildcard("\"lib\\F?o.java\"", "lib\\F?o.java");490491// check ? as suffixes492checkArgumentWildcard("lib\\F?o.????", "lib\\Fbo.java", "lib\\Foo.java");493494// check ? in a leading role495checkArgumentWildcard("lib\\???.java", "lib\\Fbo.java", "lib\\Foo.java");496checkArgumentWildcard("\"lib\\???.java\"", "lib\\???.java");497498// check ? prefixed with -499checkArgumentWildcard("-?", "-?");500501// check * prefixed with -502checkArgumentWildcard("-*", "-*");503504// check on empty directory505checkArgumentWildcard("empty\\*", "empty\\*");506checkArgumentWildcard("empty\\**", "empty\\**");507checkArgumentWildcard("empty\\?", "empty\\?");508checkArgumentWildcard("empty\\??", "empty\\??");509checkArgumentWildcard("empty\\*?", "empty\\*?");510checkArgumentWildcard("empty\\?*", "empty\\?*");511512}513514void doArgumentCheck(String inArgs, String... expArgs) {515Map<String, String> env = new HashMap<>();516env.put(JLDEBUG_KEY, "true");517TestResult tr = doExec(env, javaCmd, inArgs);518System.out.println(tr);519int sindex = tr.testOutput.indexOf("Command line args:");520if (sindex < 0) {521System.out.println(tr);522throw new RuntimeException("Error: no output");523}524sindex++; // skip over the tag525List<String> gotList = new ArrayList<>();526for (String x : tr.testOutput.subList(sindex, sindex + expArgs.length)) {527String a[] = x.split("=");528gotList.add(a[a.length - 1].trim());529}530List<String> expList = Arrays.asList(expArgs);531if (!gotList.equals(expList)) {532System.out.println(tr);533System.out.println("Expected args:");534System.out.println(expList);535System.out.println("Obtained args:");536System.out.println(gotList);537throw new RuntimeException("Error: args do not match");538}539}540541542/*543* These tests are usually run on non-existent targets to check error results544*/545@Test546void testBasicErrorMessages() {547// Tests for 5030233548TestResult tr = doExec(javaCmd, "-cp");549tr.checkNegative();550tr.isNotZeroOutput();551if (!tr.testStatus)552System.out.println(tr);553554tr = doExec(javaCmd, "-classpath");555tr.checkNegative();556tr.isNotZeroOutput();557if (!tr.testStatus)558System.out.println(tr);559560tr = doExec(javaCmd, "-jar");561tr.checkNegative();562tr.isNotZeroOutput();563if (!tr.testStatus)564System.out.println(tr);565566tr = doExec(javacCmd, "-cp");567tr.checkNegative();568tr.isNotZeroOutput();569if (!tr.testStatus)570System.out.println(tr);571572// Test for 6356475 "REGRESSION:"java -X" from cmdline fails"573tr = doExec(javaCmd, "-X");574tr.checkPositive();575tr.isNotZeroOutput();576if (!tr.testStatus)577System.out.println(tr);578579tr = doExec(javaCmd, "-help");580tr.checkPositive();581tr.isNotZeroOutput();582if (!tr.testStatus)583System.out.println(tr);584585// 6753938, test for non-negative exit value for an incorrectly formed586// command line, '% java'587tr = doExec(javaCmd);588tr.checkNegative();589tr.isNotZeroOutput();590if (!tr.testStatus)591System.out.println(tr);592593// 6753938, test for non-negative exit value for an incorrectly formed594// command line, '% java -Xcomp'595tr = doExec(javaCmd, "-Xcomp");596tr.checkNegative();597tr.isNotZeroOutput();598if (!tr.testStatus)599System.out.println(tr);600601// 7151434, test for non-negative exit value for an incorrectly formed602// command line, '% java -jar -W', note the bogus -W603tr = doExec(javaCmd, "-jar", "-W");604tr.checkNegative();605tr.contains("Unrecognized option: -W");606if (!tr.testStatus)607System.out.println(tr);608}609610/*611* Tests various dispositions of the main method, these tests are limited612* to English locales as they check for error messages that are localized.613*/614@Test615void testMainMethod() throws FileNotFoundException {616if (!isEnglishLocale()) {617return;618}619620TestResult tr = null;621622// a missing class623createJar("MIA", new File("some.jar"), new File("Foo"),624(String[])null);625tr = doExec(javaCmd, "-jar", "some.jar");626tr.contains("Error: Could not find or load main class MIA");627if (!tr.testStatus)628System.out.println(tr);629// use classpath to check630tr = doExec(javaCmd, "-cp", "some.jar", "MIA");631tr.contains("Error: Could not find or load main class MIA");632if (!tr.testStatus)633System.out.println(tr);634635// incorrect method access636createJar(new File("some.jar"), new File("Foo"),637"private static void main(String[] args){}");638tr = doExec(javaCmd, "-jar", "some.jar");639tr.contains("Error: Main method not found in class Foo");640if (!tr.testStatus)641System.out.println(tr);642// use classpath to check643tr = doExec(javaCmd, "-cp", "some.jar", "Foo");644tr.contains("Error: Main method not found in class Foo");645if (!tr.testStatus)646System.out.println(tr);647648// incorrect return type649createJar(new File("some.jar"), new File("Foo"),650"public static int main(String[] args){return 1;}");651tr = doExec(javaCmd, "-jar", "some.jar");652tr.contains("Error: Main method must return a value of type void in class Foo");653if (!tr.testStatus)654System.out.println(tr);655// use classpath to check656tr = doExec(javaCmd, "-cp", "some.jar", "Foo");657tr.contains("Error: Main method must return a value of type void in class Foo");658if (!tr.testStatus)659System.out.println(tr);660661// incorrect parameter type662createJar(new File("some.jar"), new File("Foo"),663"public static void main(Object[] args){}");664tr = doExec(javaCmd, "-jar", "some.jar");665tr.contains("Error: Main method not found in class Foo");666if (!tr.testStatus)667System.out.println(tr);668// use classpath to check669tr = doExec(javaCmd, "-cp", "some.jar", "Foo");670tr.contains("Error: Main method not found in class Foo");671if (!tr.testStatus)672System.out.println(tr);673674// incorrect method type - non-static675createJar(new File("some.jar"), new File("Foo"),676"public void main(String[] args){}");677tr = doExec(javaCmd, "-jar", "some.jar");678tr.contains("Error: Main method is not static in class Foo");679if (!tr.testStatus)680System.out.println(tr);681// use classpath to check682tr = doExec(javaCmd, "-cp", "some.jar", "Foo");683tr.contains("Error: Main method is not static in class Foo");684if (!tr.testStatus)685System.out.println(tr);686687// amongst a potpourri of kindred main methods, is the right one chosen ?688createJar(new File("some.jar"), new File("Foo"),689"void main(Object[] args){}",690"int main(Float[] args){return 1;}",691"private void main() {}",692"private static void main(int x) {}",693"public int main(int argc, String[] argv) {return 1;}",694"public static void main(String[] args) {System.out.println(\"THE_CHOSEN_ONE\");}");695tr = doExec(javaCmd, "-jar", "some.jar");696tr.contains("THE_CHOSEN_ONE");697if (!tr.testStatus)698System.out.println(tr);699// use classpath to check700tr = doExec(javaCmd, "-cp", "some.jar", "Foo");701tr.contains("THE_CHOSEN_ONE");702if (!tr.testStatus)703System.out.println(tr);704705// test for extraneous whitespace in the Main-Class attribute706createJar(" Foo ", new File("some.jar"), new File("Foo"),707"public static void main(String... args){}");708tr = doExec(javaCmd, "-jar", "some.jar");709tr.checkPositive();710if (!tr.testStatus)711System.out.println(tr);712}713/*714* tests 6968053, ie. we turn on the -Xdiag (for now) flag and check if715* the suppressed stack traces are exposed, ignore these tests for localized716* locales, limiting to English only.717*/718@Test719void testDiagOptions() throws FileNotFoundException {720if (!isEnglishLocale()) { // only english version721return;722}723TestResult tr = null;724// a missing class725createJar("MIA", new File("some.jar"), new File("Foo"),726(String[])null);727tr = doExec(javaCmd, "-Xdiag", "-jar", "some.jar");728tr.contains("Error: Could not find or load main class MIA");729tr.contains("java.lang.ClassNotFoundException: MIA");730if (!tr.testStatus)731System.out.println(tr);732733// use classpath to check734tr = doExec(javaCmd, "-Xdiag", "-cp", "some.jar", "MIA");735tr.contains("Error: Could not find or load main class MIA");736tr.contains("java.lang.ClassNotFoundException: MIA");737if (!tr.testStatus)738System.out.println(tr);739740// a missing class on the classpath741tr = doExec(javaCmd, "-Xdiag", "NonExistentClass");742tr.contains("Error: Could not find or load main class NonExistentClass");743tr.contains("java.lang.ClassNotFoundException: NonExistentClass");744if (!tr.testStatus)745System.out.println(tr);746}747748@Test749static void testJreRestrictSearchFlag() {750// test both arguments to ensure they exist751TestResult tr = null;752tr = doExec(javaCmd,753"-no-jre-restrict-search", "-version");754tr.checkPositive();755if (!tr.testStatus)756System.out.println(tr);757758tr = doExec(javaCmd,759"-jre-restrict-search", "-version");760tr.checkPositive();761if (!tr.testStatus)762System.out.println(tr);763}764765/**766* @param args the command line arguments767* @throws java.io.FileNotFoundException768*/769public static void main(String[] args) throws Exception {770if (debug) {771System.out.println("Starting Arrrghs tests");772}773Arrrghs a = new Arrrghs();774a.run(args);775if (testExitValue > 0) {776System.out.println("Total of " + testExitValue + " failed");777System.exit(1);778} else {779System.out.println("All tests pass");780}781}782}783784785