1 /*
   2  * Copyright (c) 2007, 2015, Oracle and/or its affiliates. All rights reserved.
   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  *
  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.
  22  */
  23 
  24 /**
  25  * @test
  26  * @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 6753938
  27  *      6894719 6968053 7151434 7146424 8007333 8077822 8143640 8132379
  28  * @summary Argument parsing validation.
  29  * @compile -XDignore.symbol.file Arrrghs.java
  30  * @run main/othervm Arrrghs
  31  */
  32 
  33 
  34 import java.io.File;
  35 import java.io.FileNotFoundException;
  36 import java.io.IOException;
  37 import java.util.ArrayList;
  38 import java.util.Arrays;
  39 import java.util.HashMap;
  40 import java.util.List;
  41 import java.util.Map;
  42 import java.util.regex.Matcher;
  43 import java.util.regex.Pattern;
  44 
  45 public class Arrrghs extends TestHelper {
  46     private Arrrghs(){}
  47     /**
  48      * This class provides various tests for arguments processing.
  49      *
  50      * History: these set of tests  were part of Arrrghs.sh. The MKS shell
  51      * implementations were notoriously buggy. Implementing these tests purely
  52      * in Java is not only portable but also robust.
  53      *
  54      */
  55 
  56     /*
  57      * SIGH, On Windows all strings are quoted, we need to unwrap it
  58      */
  59     private static String removeExtraQuotes(String in) {
  60         if (isWindows) {
  61             // Trim the string and remove the enclosed quotes if any.
  62             in = in.trim();
  63             if (in.startsWith("\"") && in.endsWith("\"")) {
  64                 return in.substring(1, in.length()-1);
  65             }
  66         }
  67         return in;
  68     }
  69 
  70     // the pattern we hope to see in the output
  71     static final Pattern ArgPattern = Pattern.compile("\\s*argv\\[[0-9]*\\].*=.*");
  72 
  73     void checkArgumentParsing(String inArgs, String... expArgs) throws IOException {
  74         List<String> scratchpad = new ArrayList<>();
  75         scratchpad.add("set " + JLDEBUG_KEY + "=true");
  76         // GAK, -version needs to be added so that windows can flush its stderr
  77         // exiting the process prematurely can terminate the stderr.
  78         scratchpad.add(javaCmd + " -version " + inArgs);
  79         File batFile = new File("atest.bat");
  80         createAFile(batFile, scratchpad);
  81 
  82         TestResult tr = doExec(batFile.getName());
  83 
  84         ArrayList<String> expList = new ArrayList<>();
  85         expList.add(javaCmd);
  86         expList.add("-version");
  87         expList.addAll(Arrays.asList(expArgs));
  88 
  89         List<String> gotList = new ArrayList<>();
  90         for (String x : tr.testOutput) {
  91             Matcher m = ArgPattern.matcher(x);
  92             if (m.matches()) {
  93                 String a[] = x.split("=");
  94                 gotList.add(a[a.length - 1].trim());
  95             }
  96         }
  97         if (!gotList.equals(expList)) {
  98             System.out.println(tr);
  99             System.out.println("Expected args:");
 100             System.out.println(expList);
 101             System.out.println("Obtained args:");
 102             System.out.println(gotList);
 103             throw new RuntimeException("Error: args do not match");
 104         }
 105         System.out.println("\'" + inArgs + "\'" + " - Test passed");
 106     }
 107 
 108     /*
 109      * This tests general quoting and are specific to Windows, *nixes
 110      * need not worry about this, these have been tested with Windows
 111      * implementation and those that are known to work are used against
 112      * the java implementation. Note that the ProcessBuilder gets in the
 113      * way when testing some of these arguments, therefore we need to
 114      * create and execute a .bat file containing the arguments.
 115      */
 116     @Test
 117     void testArgumentParsing() throws IOException {
 118         if (!isWindows)
 119             return;
 120         // no quotes
 121         checkArgumentParsing("a b c d", "a", "b", "c", "d");
 122 
 123         // single quotes
 124         checkArgumentParsing("\"a b c d\"", "a b c d");
 125 
 126         //double quotes
 127         checkArgumentParsing("\"\"a b c d\"\"", "a", "b", "c", "d");
 128 
 129         // triple quotes
 130         checkArgumentParsing("\"\"\"a b c d\"\"\"", "\"a b c d\"");
 131 
 132         // a literal within single quotes
 133         checkArgumentParsing("\"a\"b c d\"e\"", "ab", "c", "de");
 134 
 135         // a literal within double quotes
 136         checkArgumentParsing("\"\"a\"b c d\"e\"\"", "ab c de");
 137 
 138         // a literal quote
 139         checkArgumentParsing("a\\\"b", "a\"b");
 140 
 141         // double back-slash
 142         checkArgumentParsing("\"a b c d\\\\\"", "a b c d\\");
 143 
 144         // triple back-slash
 145         checkArgumentParsing("a\\\\\\\"b", "a\\\"b");
 146 
 147         // dangling quote
 148         checkArgumentParsing("\"a b c\"\"", "a b c\"");
 149 
 150         // expansions of white space separators
 151         checkArgumentParsing("a b", "a", "b");
 152         checkArgumentParsing("a\tb", "a", "b");
 153         checkArgumentParsing("a \t b", "a", "b");
 154 
 155         checkArgumentParsing("\"C:\\TEST A\\\\\"", "C:\\TEST A\\");
 156         checkArgumentParsing("\"\"C:\\TEST A\\\\\"\"", "C:\\TEST", "A\\");
 157 
 158         // MS Windows tests
 159         // triple back-slash
 160         checkArgumentParsing("a\\\\\\d", "a\\\\\\d");
 161 
 162         // triple back-slash in quotes
 163         checkArgumentParsing("\"a\\\\\\d\"", "a\\\\\\d");
 164 
 165         // slashes separating characters
 166         checkArgumentParsing("X\\Y\\Z", "X\\Y\\Z");
 167         checkArgumentParsing("\\X\\Y\\Z", "\\X\\Y\\Z");
 168 
 169         // literals within dangling quotes, etc.
 170         checkArgumentParsing("\"a b c\" d e", "a b c", "d", "e");
 171         checkArgumentParsing("\"ab\\\"c\"  \"\\\\\"  d", "ab\"c", "\\", "d");
 172         checkArgumentParsing("a\\\\\\c d\"e f\"g h", "a\\\\\\c", "de fg", "h");
 173         checkArgumentParsing("a\\\\\\\"b c d", "a\\\"b", "c", "d");
 174         checkArgumentParsing("a\\\\\\\\\"g c\" d e", "a\\\\g c", "d", "e");
 175 
 176         // treatment of back-slashes
 177         checkArgumentParsing("*\\", "*\\");
 178         checkArgumentParsing("*/", "*/");
 179         checkArgumentParsing(".\\*", ".\\*");
 180         checkArgumentParsing("./*", "./*");
 181         checkArgumentParsing("..\\..\\*", "..\\..\\*");
 182         checkArgumentParsing("../../*", "../../*");
 183         checkArgumentParsing("..\\..\\", "..\\..\\");
 184         checkArgumentParsing("../../", "../../");
 185         checkArgumentParsing("a b\\ c", "a", "b\\", "c");
 186         // 2 back-slashes
 187         checkArgumentParsing("\\\\?", "\\\\?");
 188         // 3 back-slashes
 189         checkArgumentParsing("\\\\\\?", "\\\\\\?");
 190         // 4 back-slashes
 191         checkArgumentParsing("\\\\\\\\?", "\\\\\\\\?");
 192         // 5 back-slashes
 193         checkArgumentParsing("\\\\\\\\\\?", "\\\\\\\\\\?");
 194         // 6 back-slashes
 195         checkArgumentParsing("\\\\\\\\\\\\?", "\\\\\\\\\\\\?");
 196 
 197         // more treatment of  mixed slashes
 198         checkArgumentParsing("f1/ f3\\ f4/", "f1/", "f3\\", "f4/");
 199         checkArgumentParsing("f1/ f2\' ' f3/ f4/", "f1/", "f2\'", "'", "f3/", "f4/");
 200 
 201         checkArgumentParsing("a\\*\\b", "a\\*\\b");
 202     }
 203 
 204     private void initEmptyDir(File emptyDir) throws IOException {
 205         if (emptyDir.exists()) {
 206             recursiveDelete(emptyDir);
 207         }
 208         emptyDir.mkdir();
 209     }
 210 
 211     private void initDirWithJavaFiles(File libDir) throws IOException {
 212 
 213         if (libDir.exists()) {
 214             recursiveDelete(libDir);
 215         }
 216         libDir.mkdirs();
 217         ArrayList<String> scratchpad = new ArrayList<>();
 218         scratchpad.add("package lib;");
 219         scratchpad.add("public class Fbo {");
 220         scratchpad.add("public static void main(String... args){Foo.f();}");
 221         scratchpad.add("public static void f(){}");
 222         scratchpad.add("}");
 223         createFile(new File(libDir, "Fbo.java"), scratchpad);
 224 
 225         scratchpad.clear();
 226         scratchpad.add("package lib;");
 227         scratchpad.add("public class Foo {");
 228         scratchpad.add("public static void main(String... args){");
 229         scratchpad.add("for (String x : args) {");
 230         scratchpad.add("System.out.println(x);");
 231         scratchpad.add("}");
 232         scratchpad.add("Fbo.f();");
 233         scratchpad.add("}");
 234         scratchpad.add("public static void f(){}");
 235         scratchpad.add("}");
 236         createFile(new File(libDir, "Foo.java"), scratchpad);
 237     }
 238 
 239     void checkArgumentWildcard(String inArgs, String... expArgs) throws IOException {
 240         String[] in = {inArgs};
 241         checkArgumentWildcard(in, expArgs);
 242 
 243         // now add arbitrary arguments before and after
 244         String[] outInArgs = { "-Q", inArgs, "-R"};
 245 
 246         String[] outExpArgs = new String[expArgs.length + 2];
 247         outExpArgs[0] = "-Q";
 248         System.arraycopy(expArgs, 0, outExpArgs, 1, expArgs.length);
 249         outExpArgs[expArgs.length + 1] = "-R";
 250         checkArgumentWildcard(outInArgs, outExpArgs);
 251     }
 252 
 253     void checkArgumentWildcard(String[] inArgs, String[] expArgs) throws IOException {
 254         ArrayList<String> argList = new ArrayList<>();
 255         argList.add(javaCmd);
 256         argList.add("-cp");
 257         argList.add("lib" + File.separator + "*");
 258         argList.add("lib.Foo");
 259         argList.addAll(Arrays.asList(inArgs));
 260         String[] cmds = new String[argList.size()];
 261         argList.toArray(cmds);
 262         TestResult tr = doExec(cmds);
 263         if (!tr.isOK()) {
 264             System.out.println(tr);
 265             throw new RuntimeException("Error: classpath single entry wildcard entry");
 266         }
 267 
 268         ArrayList<String> expList = new ArrayList<>();
 269         expList.addAll(Arrays.asList(expArgs));
 270 
 271         List<String> gotList = new ArrayList<>();
 272         for (String x : tr.testOutput) {
 273             gotList.add(x.trim());
 274         }
 275         if (!gotList.equals(expList)) {
 276             System.out.println(tr);
 277             System.out.println("Expected args:");
 278             System.out.println(expList);
 279             System.out.println("Obtained args:");
 280             System.out.println(gotList);
 281             throw new RuntimeException("Error: args do not match");
 282         }
 283         System.out.print("\'");
 284         for (String x : inArgs) {
 285             System.out.print(x + " ");
 286         }
 287         System.out.println("\'" + " - Test passed");
 288     }
 289 
 290     /*
 291      * These tests are not expected to work on *nixes, and are ignored.
 292      */
 293     @Test
 294     void testWildCardArgumentProcessing() throws IOException {
 295         if (!isWindows)
 296             return;
 297         File cwd = new File(".");
 298         File libDir = new File(cwd, "lib");
 299         initDirWithJavaFiles(libDir);
 300         initEmptyDir(new File(cwd, "empty"));
 301 
 302         // test if javac (the command) can compile *.java
 303         TestResult tr = doExec(javacCmd, libDir.getName() + File.separator + "*.java");
 304         if (!tr.isOK()) {
 305             System.out.println(tr);
 306             throw new RuntimeException("Error: compiling java wildcards");
 307         }
 308 
 309         // test if javac (the command) can compile *.java with a vmoption
 310         tr = doExec(javacCmd, "-cp", ".",
 311                     "-J-showversion", "-J-Dsomeproperty=foo",
 312                     libDir.getName() + File.separator + "*.java");
 313         if (!tr.isOK()) {
 314             System.out.println(tr);
 315             throw new RuntimeException("Error: compiling java wildcards with vmoptions");
 316         }
 317 
 318 
 319         // use the jar cmd to create jars using the ? wildcard
 320         File jarFoo = new File(libDir, "Foo.jar");
 321         tr = doExec(jarCmd, "cvf", jarFoo.getAbsolutePath(), "lib" + File.separator + "F?o.class");
 322         if (!tr.isOK()) {
 323             System.out.println(tr);
 324             throw new RuntimeException("Error: creating jar with wildcards");
 325         }
 326 
 327         // now the litmus test!, this should work
 328         checkArgumentWildcard("a", "a");
 329 
 330         // test for basic expansion
 331         checkArgumentWildcard("lib\\F*java", "lib\\Fbo.java", "lib\\Foo.java");
 332 
 333         // basic expansion in quotes
 334         checkArgumentWildcard("\"lib\\F*java\"", "lib\\F*java");
 335 
 336         checkArgumentWildcard("lib\\**", "lib\\Fbo.class", "lib\\Fbo.java",
 337                               "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");
 338 
 339         checkArgumentWildcard("lib\\*?", "lib\\Fbo.class", "lib\\Fbo.java",
 340                               "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");
 341 
 342         checkArgumentWildcard("lib\\?*", "lib\\Fbo.class", "lib\\Fbo.java",
 343                 "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");
 344 
 345         checkArgumentWildcard("lib\\?", "lib\\?");
 346 
 347         // test for basic expansion
 348         checkArgumentWildcard("lib\\*java", "lib\\Fbo.java", "lib\\Foo.java");
 349 
 350         // basic expansion in quotes
 351         checkArgumentWildcard("\"lib\\*.java\"", "lib\\*.java");
 352 
 353         // suffix expansion
 354         checkArgumentWildcard("lib\\*.class", "lib\\Fbo.class", "lib\\Foo.class");
 355 
 356         // suffix expansion in quotes
 357         checkArgumentWildcard("\"lib\\*.class\"", "lib\\*.class");
 358 
 359         // check for ? expansion now
 360         checkArgumentWildcard("lib\\F?o.java", "lib\\Fbo.java", "lib\\Foo.java");
 361 
 362         // check ? in quotes
 363         checkArgumentWildcard("\"lib\\F?o.java\"", "lib\\F?o.java");
 364 
 365         // check ? as suffixes
 366         checkArgumentWildcard("lib\\F?o.????", "lib\\Fbo.java", "lib\\Foo.java");
 367 
 368         // check ? in a leading role
 369         checkArgumentWildcard("lib\\???.java", "lib\\Fbo.java", "lib\\Foo.java");
 370         checkArgumentWildcard("\"lib\\???.java\"", "lib\\???.java");
 371 
 372         // check ? prefixed with -
 373         checkArgumentWildcard("-?", "-?");
 374 
 375         // check * prefixed with -
 376         checkArgumentWildcard("-*", "-*");
 377 
 378         // check on empty directory
 379         checkArgumentWildcard("empty\\*", "empty\\*");
 380         checkArgumentWildcard("empty\\**", "empty\\**");
 381         checkArgumentWildcard("empty\\?", "empty\\?");
 382         checkArgumentWildcard("empty\\??", "empty\\??");
 383         checkArgumentWildcard("empty\\*?", "empty\\*?");
 384         checkArgumentWildcard("empty\\?*", "empty\\?*");
 385 
 386         // 8132379: java should not filter out -J options for application
 387         String[] args = { "-J-one", "-Jtwo", "lib\\???.java", "-J-Dsomething",
 388            "a", "-J-Dlast.arg" };
 389         String[] expected = { "-J-one", "-Jtwo", "lib\\Fbo.java",
 390            "lib\\Foo.java", "-J-Dsomething", "a", "-J-Dlast.arg" };
 391         checkArgumentWildcard(args, expected);
 392     }
 393 
 394     void doArgumentCheck(String inArgs, String... expArgs) {
 395         Map<String, String> env = new HashMap<>();
 396         env.put(JLDEBUG_KEY, "true");
 397         TestResult tr = doExec(env, javaCmd, inArgs);
 398         System.out.println(tr);
 399         int sindex = tr.testOutput.indexOf("Command line args:");
 400         if (sindex < 0) {
 401             System.out.println(tr);
 402             throw new RuntimeException("Error: no output");
 403         }
 404         sindex++; // skip over the tag
 405         List<String> gotList = new ArrayList<>();
 406         for (String x : tr.testOutput.subList(sindex, sindex + expArgs.length)) {
 407             String a[] = x.split("=");
 408             gotList.add(a[a.length - 1].trim());
 409         }
 410         List<String> expList = Arrays.asList(expArgs);
 411         if (!gotList.equals(expList)) {
 412             System.out.println(tr);
 413             System.out.println("Expected args:");
 414             System.out.println(expList);
 415             System.out.println("Obtained args:");
 416             System.out.println(gotList);
 417             throw new RuntimeException("Error: args do not match");
 418         }
 419     }
 420 
 421 
 422     /*
 423      * These tests are usually run on non-existent targets to check error results
 424      */
 425     @Test
 426     void testBasicErrorMessages() {
 427         // Tests for 5030233
 428         TestResult tr = doExec(javaCmd, "-cp");
 429         tr.checkNegative();
 430         tr.isNotZeroOutput();
 431         if (!tr.testStatus)
 432             System.out.println(tr);
 433 
 434         tr = doExec(javaCmd, "-classpath");
 435         tr.checkNegative();
 436         tr.isNotZeroOutput();
 437         if (!tr.testStatus)
 438             System.out.println(tr);
 439 
 440         tr = doExec(javaCmd, "-jar");
 441         tr.checkNegative();
 442         tr.isNotZeroOutput();
 443         if (!tr.testStatus)
 444             System.out.println(tr);
 445 
 446         tr = doExec(javacCmd, "-cp");
 447         tr.checkNegative();
 448         tr.isNotZeroOutput();
 449         if (!tr.testStatus)
 450             System.out.println(tr);
 451 
 452         // Test for 6356475 "REGRESSION:"java -X" from cmdline fails"
 453         tr = doExec(javaCmd, "-X");
 454         tr.checkPositive();
 455         tr.isNotZeroOutput();
 456         if (!tr.testStatus)
 457             System.out.println(tr);
 458 
 459         tr = doExec(javaCmd, "-help");
 460         tr.checkPositive();
 461         tr.isNotZeroOutput();
 462         if (!tr.testStatus)
 463             System.out.println(tr);
 464 
 465         // 6753938, test for non-negative exit value for an incorrectly formed
 466         // command line,  '% java'
 467         tr = doExec(javaCmd);
 468         tr.checkNegative();
 469         tr.isNotZeroOutput();
 470         if (!tr.testStatus)
 471             System.out.println(tr);
 472 
 473         // 6753938, test for non-negative exit value for an incorrectly formed
 474         // command line,  '% java -Xcomp'
 475         tr = doExec(javaCmd, "-Xcomp");
 476         tr.checkNegative();
 477         tr.isNotZeroOutput();
 478         if (!tr.testStatus)
 479             System.out.println(tr);
 480 
 481         // 7151434, test for non-negative exit value for an incorrectly formed
 482         // command line, '% java -jar -W', note the bogus -W
 483         tr = doExec(javaCmd, "-jar", "-W");
 484         tr.checkNegative();
 485         tr.contains("Unrecognized option: -W");
 486         if (!tr.testStatus)
 487             System.out.println(tr);
 488     }
 489 
 490     /*
 491      * Tests various dispositions of the main method, these tests are limited
 492      * to English locales as they check for error messages that are localized.
 493      */
 494     @Test
 495     void testMainMethod() throws FileNotFoundException {
 496         if (!isEnglishLocale()) {
 497             return;
 498         }
 499 
 500         TestResult tr;
 501 
 502         // a missing class
 503         createJar("MIA", new File("some.jar"), new File("Foo"),
 504                 (String[])null);
 505         tr = doExec(javaCmd, "-jar", "some.jar");
 506         tr.contains("Error: Could not find or load main class MIA");
 507         if (!tr.testStatus)
 508             System.out.println(tr);
 509         // use classpath to check
 510         tr = doExec(javaCmd, "-cp", "some.jar", "MIA");
 511         tr.contains("Error: Could not find or load main class MIA");
 512         if (!tr.testStatus)
 513             System.out.println(tr);
 514 
 515         // incorrect method access
 516         createJar(new File("some.jar"), new File("Foo"),
 517                 "private static void main(String[] args){}");
 518         tr = doExec(javaCmd, "-jar", "some.jar");
 519         tr.contains("Error: Main method not found in class Foo");
 520         if (!tr.testStatus)
 521             System.out.println(tr);
 522         // use classpath to check
 523         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 524         tr.contains("Error: Main method not found in class Foo");
 525         if (!tr.testStatus)
 526             System.out.println(tr);
 527 
 528         // incorrect return type
 529         createJar(new File("some.jar"), new File("Foo"),
 530                 "public static int main(String[] args){return 1;}");
 531         tr = doExec(javaCmd, "-jar", "some.jar");
 532         tr.contains("Error: Main method must return a value of type void in class Foo");
 533         if (!tr.testStatus)
 534             System.out.println(tr);
 535         // use classpath to check
 536         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 537         tr.contains("Error: Main method must return a value of type void in class Foo");
 538         if (!tr.testStatus)
 539             System.out.println(tr);
 540 
 541         // incorrect parameter type
 542         createJar(new File("some.jar"), new File("Foo"),
 543                 "public static void main(Object[] args){}");
 544         tr = doExec(javaCmd, "-jar", "some.jar");
 545         tr.contains("Error: Main method not found in class Foo");
 546         if (!tr.testStatus)
 547             System.out.println(tr);
 548         // use classpath to check
 549         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 550         tr.contains("Error: Main method not found in class Foo");
 551         if (!tr.testStatus)
 552             System.out.println(tr);
 553 
 554         // incorrect method type - non-static
 555          createJar(new File("some.jar"), new File("Foo"),
 556                 "public void main(String[] args){}");
 557         tr = doExec(javaCmd, "-jar", "some.jar");
 558         tr.contains("Error: Main method is not static in class Foo");
 559         if (!tr.testStatus)
 560             System.out.println(tr);
 561         // use classpath to check
 562         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 563         tr.contains("Error: Main method is not static in class Foo");
 564         if (!tr.testStatus)
 565             System.out.println(tr);
 566 
 567         // amongst a potpourri of kindred main methods, is the right one chosen ?
 568         createJar(new File("some.jar"), new File("Foo"),
 569             "void main(Object[] args){}",
 570             "int  main(Float[] args){return 1;}",
 571             "private void main() {}",
 572             "private static void main(int x) {}",
 573             "public int main(int argc, String[] argv) {return 1;}",
 574             "public static void main(String[] args) {System.out.println(\"THE_CHOSEN_ONE\");}");
 575         tr = doExec(javaCmd, "-jar", "some.jar");
 576         tr.contains("THE_CHOSEN_ONE");
 577         if (!tr.testStatus)
 578             System.out.println(tr);
 579         // use classpath to check
 580         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 581         tr.contains("THE_CHOSEN_ONE");
 582         if (!tr.testStatus)
 583             System.out.println(tr);
 584 
 585         // test for extraneous whitespace in the Main-Class attribute
 586         createJar(" Foo ", new File("some.jar"), new File("Foo"),
 587                 "public static void main(String... args){}");
 588         tr = doExec(javaCmd, "-jar", "some.jar");
 589         tr.checkPositive();
 590         if (!tr.testStatus)
 591             System.out.println(tr);
 592     }
 593     /*
 594      * tests 6968053, ie. we turn on the -Xdiag (for now) flag and check if
 595      * the suppressed stack traces are exposed, ignore these tests for localized
 596      * locales, limiting to English only.
 597      */
 598     @Test
 599     void testDiagOptions() throws FileNotFoundException {
 600         if (!isEnglishLocale()) { // only english version
 601             return;
 602         }
 603         TestResult tr;
 604         // a missing class
 605         createJar("MIA", new File("some.jar"), new File("Foo"),
 606                 (String[])null);
 607         tr = doExec(javaCmd, "-Xdiag", "-jar", "some.jar");
 608         tr.contains("Error: Could not find or load main class MIA");
 609         tr.contains("java.lang.ClassNotFoundException: MIA");
 610         if (!tr.testStatus)
 611             System.out.println(tr);
 612 
 613         // use classpath to check
 614         tr = doExec(javaCmd,  "-Xdiag", "-cp", "some.jar", "MIA");
 615         tr.contains("Error: Could not find or load main class MIA");
 616         tr.contains("java.lang.ClassNotFoundException: MIA");
 617         if (!tr.testStatus)
 618             System.out.println(tr);
 619 
 620         // a missing class on the classpath
 621         tr = doExec(javaCmd, "-Xdiag", "NonExistentClass");
 622         tr.contains("Error: Could not find or load main class NonExistentClass");
 623         tr.contains("java.lang.ClassNotFoundException: NonExistentClass");
 624         if (!tr.testStatus)
 625             System.out.println(tr);
 626     }
 627 
 628     /**
 629      * @param args the command line arguments
 630      * @throws java.io.FileNotFoundException
 631      */
 632     public static void main(String[] args) throws Exception {
 633         if (debug) {
 634             System.out.println("Starting Arrrghs tests");
 635         }
 636         Arrrghs a = new Arrrghs();
 637         a.run(args);
 638         if (testExitValue > 0) {
 639             System.out.println("Total of " + testExitValue + " failed");
 640             System.exit(1);
 641         } else {
 642             System.out.println("All tests pass");
 643         }
 644     }
 645 }