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
  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     }
 387 
 388     void doArgumentCheck(String inArgs, String... expArgs) {
 389         Map<String, String> env = new HashMap<>();
 390         env.put(JLDEBUG_KEY, "true");
 391         TestResult tr = doExec(env, javaCmd, inArgs);
 392         System.out.println(tr);
 393         int sindex = tr.testOutput.indexOf("Command line args:");
 394         if (sindex < 0) {
 395             System.out.println(tr);
 396             throw new RuntimeException("Error: no output");
 397         }
 398         sindex++; // skip over the tag
 399         List<String> gotList = new ArrayList<>();
 400         for (String x : tr.testOutput.subList(sindex, sindex + expArgs.length)) {
 401             String a[] = x.split("=");
 402             gotList.add(a[a.length - 1].trim());
 403         }
 404         List<String> expList = Arrays.asList(expArgs);
 405         if (!gotList.equals(expList)) {
 406             System.out.println(tr);
 407             System.out.println("Expected args:");
 408             System.out.println(expList);
 409             System.out.println("Obtained args:");
 410             System.out.println(gotList);
 411             throw new RuntimeException("Error: args do not match");
 412         }
 413     }
 414 
 415 
 416     /*
 417      * These tests are usually run on non-existent targets to check error results
 418      */
 419     @Test
 420     void testBasicErrorMessages() {
 421         // Tests for 5030233
 422         TestResult tr = doExec(javaCmd, "-cp");
 423         tr.checkNegative();
 424         tr.isNotZeroOutput();
 425         if (!tr.testStatus)
 426             System.out.println(tr);
 427 
 428         tr = doExec(javaCmd, "-classpath");
 429         tr.checkNegative();
 430         tr.isNotZeroOutput();
 431         if (!tr.testStatus)
 432             System.out.println(tr);
 433 
 434         tr = doExec(javaCmd, "-jar");
 435         tr.checkNegative();
 436         tr.isNotZeroOutput();
 437         if (!tr.testStatus)
 438             System.out.println(tr);
 439 
 440         tr = doExec(javacCmd, "-cp");
 441         tr.checkNegative();
 442         tr.isNotZeroOutput();
 443         if (!tr.testStatus)
 444             System.out.println(tr);
 445 
 446         // Test for 6356475 "REGRESSION:"java -X" from cmdline fails"
 447         tr = doExec(javaCmd, "-X");
 448         tr.checkPositive();
 449         tr.isNotZeroOutput();
 450         if (!tr.testStatus)
 451             System.out.println(tr);
 452 
 453         tr = doExec(javaCmd, "-help");
 454         tr.checkPositive();
 455         tr.isNotZeroOutput();
 456         if (!tr.testStatus)
 457             System.out.println(tr);
 458 
 459         // 6753938, test for non-negative exit value for an incorrectly formed
 460         // command line,  '% java'
 461         tr = doExec(javaCmd);
 462         tr.checkNegative();
 463         tr.isNotZeroOutput();
 464         if (!tr.testStatus)
 465             System.out.println(tr);
 466 
 467         // 6753938, test for non-negative exit value for an incorrectly formed
 468         // command line,  '% java -Xcomp'
 469         tr = doExec(javaCmd, "-Xcomp");
 470         tr.checkNegative();
 471         tr.isNotZeroOutput();
 472         if (!tr.testStatus)
 473             System.out.println(tr);
 474 
 475         // 7151434, test for non-negative exit value for an incorrectly formed
 476         // command line, '% java -jar -W', note the bogus -W
 477         tr = doExec(javaCmd, "-jar", "-W");
 478         tr.checkNegative();
 479         tr.contains("Unrecognized option: -W");
 480         if (!tr.testStatus)
 481             System.out.println(tr);
 482     }
 483 
 484     /*
 485      * Tests various dispositions of the main method, these tests are limited
 486      * to English locales as they check for error messages that are localized.
 487      */
 488     @Test
 489     void testMainMethod() throws FileNotFoundException {
 490         if (!isEnglishLocale()) {
 491             return;
 492         }
 493 
 494         TestResult tr;
 495 
 496         // a missing class
 497         createJar("MIA", new File("some.jar"), new File("Foo"),
 498                 (String[])null);
 499         tr = doExec(javaCmd, "-jar", "some.jar");
 500         tr.contains("Error: Could not find or load main class MIA");
 501         if (!tr.testStatus)
 502             System.out.println(tr);
 503         // use classpath to check
 504         tr = doExec(javaCmd, "-cp", "some.jar", "MIA");
 505         tr.contains("Error: Could not find or load main class MIA");
 506         if (!tr.testStatus)
 507             System.out.println(tr);
 508 
 509         // incorrect method access
 510         createJar(new File("some.jar"), new File("Foo"),
 511                 "private static void main(String[] args){}");
 512         tr = doExec(javaCmd, "-jar", "some.jar");
 513         tr.contains("Error: Main method not found in class Foo");
 514         if (!tr.testStatus)
 515             System.out.println(tr);
 516         // use classpath to check
 517         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 518         tr.contains("Error: Main method not found in class Foo");
 519         if (!tr.testStatus)
 520             System.out.println(tr);
 521 
 522         // incorrect return type
 523         createJar(new File("some.jar"), new File("Foo"),
 524                 "public static int main(String[] args){return 1;}");
 525         tr = doExec(javaCmd, "-jar", "some.jar");
 526         tr.contains("Error: Main method must return a value of type void in class Foo");
 527         if (!tr.testStatus)
 528             System.out.println(tr);
 529         // use classpath to check
 530         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 531         tr.contains("Error: Main method must return a value of type void in class Foo");
 532         if (!tr.testStatus)
 533             System.out.println(tr);
 534 
 535         // incorrect parameter type
 536         createJar(new File("some.jar"), new File("Foo"),
 537                 "public static void main(Object[] args){}");
 538         tr = doExec(javaCmd, "-jar", "some.jar");
 539         tr.contains("Error: Main method not found in class Foo");
 540         if (!tr.testStatus)
 541             System.out.println(tr);
 542         // use classpath to check
 543         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 544         tr.contains("Error: Main method not found in class Foo");
 545         if (!tr.testStatus)
 546             System.out.println(tr);
 547 
 548         // incorrect method type - non-static
 549          createJar(new File("some.jar"), new File("Foo"),
 550                 "public void main(String[] args){}");
 551         tr = doExec(javaCmd, "-jar", "some.jar");
 552         tr.contains("Error: Main method is not static in class Foo");
 553         if (!tr.testStatus)
 554             System.out.println(tr);
 555         // use classpath to check
 556         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 557         tr.contains("Error: Main method is not static in class Foo");
 558         if (!tr.testStatus)
 559             System.out.println(tr);
 560 
 561         // amongst a potpourri of kindred main methods, is the right one chosen ?
 562         createJar(new File("some.jar"), new File("Foo"),
 563             "void main(Object[] args){}",
 564             "int  main(Float[] args){return 1;}",
 565             "private void main() {}",
 566             "private static void main(int x) {}",
 567             "public int main(int argc, String[] argv) {return 1;}",
 568             "public static void main(String[] args) {System.out.println(\"THE_CHOSEN_ONE\");}");
 569         tr = doExec(javaCmd, "-jar", "some.jar");
 570         tr.contains("THE_CHOSEN_ONE");
 571         if (!tr.testStatus)
 572             System.out.println(tr);
 573         // use classpath to check
 574         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 575         tr.contains("THE_CHOSEN_ONE");
 576         if (!tr.testStatus)
 577             System.out.println(tr);
 578 
 579         // test for extraneous whitespace in the Main-Class attribute
 580         createJar(" Foo ", new File("some.jar"), new File("Foo"),
 581                 "public static void main(String... args){}");
 582         tr = doExec(javaCmd, "-jar", "some.jar");
 583         tr.checkPositive();
 584         if (!tr.testStatus)
 585             System.out.println(tr);
 586     }
 587     /*
 588      * tests 6968053, ie. we turn on the -Xdiag (for now) flag and check if
 589      * the suppressed stack traces are exposed, ignore these tests for localized
 590      * locales, limiting to English only.
 591      */
 592     @Test
 593     void testDiagOptions() throws FileNotFoundException {
 594         if (!isEnglishLocale()) { // only english version
 595             return;
 596         }
 597         TestResult tr;
 598         // a missing class
 599         createJar("MIA", new File("some.jar"), new File("Foo"),
 600                 (String[])null);
 601         tr = doExec(javaCmd, "-Xdiag", "-jar", "some.jar");
 602         tr.contains("Error: Could not find or load main class MIA");
 603         tr.contains("java.lang.ClassNotFoundException: MIA");
 604         if (!tr.testStatus)
 605             System.out.println(tr);
 606 
 607         // use classpath to check
 608         tr = doExec(javaCmd,  "-Xdiag", "-cp", "some.jar", "MIA");
 609         tr.contains("Error: Could not find or load main class MIA");
 610         tr.contains("java.lang.ClassNotFoundException: MIA");
 611         if (!tr.testStatus)
 612             System.out.println(tr);
 613 
 614         // a missing class on the classpath
 615         tr = doExec(javaCmd, "-Xdiag", "NonExistentClass");
 616         tr.contains("Error: Could not find or load main class NonExistentClass");
 617         tr.contains("java.lang.ClassNotFoundException: NonExistentClass");
 618         if (!tr.testStatus)
 619             System.out.println(tr);
 620     }
 621 
 622     /**
 623      * @param args the command line arguments
 624      * @throws java.io.FileNotFoundException
 625      */
 626     public static void main(String[] args) throws Exception {
 627         if (debug) {
 628             System.out.println("Starting Arrrghs tests");
 629         }
 630         Arrrghs a = new Arrrghs();
 631         a.run(args);
 632         if (testExitValue > 0) {
 633             System.out.println("Total of " + testExitValue + " failed");
 634             System.exit(1);
 635         } else {
 636             System.out.println("All tests pass");
 637         }
 638     }
 639 }