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
  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 
 202     private void initEmptyDir(File emptyDir) throws IOException {
 203         if (emptyDir.exists()) {
 204             recursiveDelete(emptyDir);
 205         }
 206         emptyDir.mkdir();
 207     }
 208 
 209     private void initDirWithJavaFiles(File libDir) throws IOException {
 210 
 211         if (libDir.exists()) {
 212             recursiveDelete(libDir);
 213         }
 214         libDir.mkdirs();
 215         ArrayList<String> scratchpad = new ArrayList<>();
 216         scratchpad.add("package lib;");
 217         scratchpad.add("public class Fbo {");
 218         scratchpad.add("public static void main(String... args){Foo.f();}");
 219         scratchpad.add("public static void f(){}");
 220         scratchpad.add("}");
 221         createFile(new File(libDir, "Fbo.java"), scratchpad);
 222 
 223         scratchpad.clear();
 224         scratchpad.add("package lib;");
 225         scratchpad.add("public class Foo {");
 226         scratchpad.add("public static void main(String... args){");
 227         scratchpad.add("for (String x : args) {");
 228         scratchpad.add("System.out.println(x);");
 229         scratchpad.add("}");
 230         scratchpad.add("Fbo.f();");
 231         scratchpad.add("}");
 232         scratchpad.add("public static void f(){}");
 233         scratchpad.add("}");
 234         createFile(new File(libDir, "Foo.java"), scratchpad);
 235     }
 236 
 237     void checkArgumentWildcard(String inArgs, String... expArgs) throws IOException {
 238         String[] in = {inArgs};
 239         checkArgumentWildcard(in, expArgs);
 240 
 241         // now add arbitrary arguments before and after
 242         String[] outInArgs = { "-Q", inArgs, "-R"};
 243 
 244         String[] outExpArgs = new String[expArgs.length + 2];
 245         outExpArgs[0] = "-Q";
 246         System.arraycopy(expArgs, 0, outExpArgs, 1, expArgs.length);
 247         outExpArgs[expArgs.length + 1] = "-R";
 248         checkArgumentWildcard(outInArgs, outExpArgs);
 249     }
 250 
 251     void checkArgumentWildcard(String[] inArgs, String[] expArgs) throws IOException {
 252         ArrayList<String> argList = new ArrayList<>();
 253         argList.add(javaCmd);
 254         argList.add("-cp");
 255         argList.add("lib" + File.separator + "*");
 256         argList.add("lib.Foo");
 257         argList.addAll(Arrays.asList(inArgs));
 258         String[] cmds = new String[argList.size()];
 259         argList.toArray(cmds);
 260         TestResult tr = doExec(cmds);
 261         if (!tr.isOK()) {
 262             System.out.println(tr);
 263             throw new RuntimeException("Error: classpath single entry wildcard entry");
 264         }
 265 
 266         ArrayList<String> expList = new ArrayList<>();
 267         expList.addAll(Arrays.asList(expArgs));
 268 
 269         List<String> gotList = new ArrayList<>();
 270         for (String x : tr.testOutput) {
 271             gotList.add(x.trim());
 272         }
 273         if (!gotList.equals(expList)) {
 274             System.out.println(tr);
 275             System.out.println("Expected args:");
 276             System.out.println(expList);
 277             System.out.println("Obtained args:");
 278             System.out.println(gotList);
 279             throw new RuntimeException("Error: args do not match");
 280         }
 281         System.out.print("\'");
 282         for (String x : inArgs) {
 283             System.out.print(x + " ");
 284         }
 285         System.out.println("\'" + " - Test passed");
 286     }
 287 
 288     /*
 289      * These tests are not expected to work on *nixes, and are ignored.
 290      */
 291     @Test
 292     void testWildCardArgumentProcessing() throws IOException {
 293         if (!isWindows)
 294             return;
 295         File cwd = new File(".");
 296         File libDir = new File(cwd, "lib");
 297         initDirWithJavaFiles(libDir);
 298         initEmptyDir(new File(cwd, "empty"));
 299 
 300         // test if javac (the command) can compile *.java
 301         TestResult tr = doExec(javacCmd, libDir.getName() + File.separator + "*.java");
 302         if (!tr.isOK()) {
 303             System.out.println(tr);
 304             throw new RuntimeException("Error: compiling java wildcards");
 305         }
 306 
 307         // test if javac (the command) can compile *.java with a vmoption
 308         tr = doExec(javacCmd, "-cp", ".",
 309                     "-J-showversion", "-J-Dsomeproperty=foo",
 310                     libDir.getName() + File.separator + "*.java");
 311         if (!tr.isOK()) {
 312             System.out.println(tr);
 313             throw new RuntimeException("Error: compiling java wildcards with vmoptions");
 314         }
 315 
 316 
 317         // use the jar cmd to create jars using the ? wildcard
 318         File jarFoo = new File(libDir, "Foo.jar");
 319         tr = doExec(jarCmd, "cvf", jarFoo.getAbsolutePath(), "lib" + File.separator + "F?o.class");
 320         if (!tr.isOK()) {
 321             System.out.println(tr);
 322             throw new RuntimeException("Error: creating jar with wildcards");
 323         }
 324 
 325         // now the litmus test!, this should work
 326         checkArgumentWildcard("a", "a");
 327 
 328         // test for basic expansion
 329         checkArgumentWildcard("lib\\F*java", "lib\\Fbo.java", "lib\\Foo.java");
 330 
 331         // basic expansion in quotes
 332         checkArgumentWildcard("\"lib\\F*java\"", "lib\\F*java");
 333 
 334         checkArgumentWildcard("lib\\**", "lib\\Fbo.class", "lib\\Fbo.java",
 335                               "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");
 336 
 337         checkArgumentWildcard("lib\\*?", "lib\\Fbo.class", "lib\\Fbo.java",
 338                               "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");
 339 
 340         checkArgumentWildcard("lib\\?*", "lib\\Fbo.class", "lib\\Fbo.java",
 341                 "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");
 342 
 343         checkArgumentWildcard("lib\\?", "lib\\?");
 344 
 345         // test for basic expansion
 346         checkArgumentWildcard("lib\\*java", "lib\\Fbo.java", "lib\\Foo.java");
 347 
 348         // basic expansion in quotes
 349         checkArgumentWildcard("\"lib\\*.java\"", "lib\\*.java");
 350 
 351         // suffix expansion
 352         checkArgumentWildcard("lib\\*.class", "lib\\Fbo.class", "lib\\Foo.class");
 353 
 354         // suffix expansion in quotes
 355         checkArgumentWildcard("\"lib\\*.class\"", "lib\\*.class");
 356 
 357         // check for ? expansion now
 358         checkArgumentWildcard("lib\\F?o.java", "lib\\Fbo.java", "lib\\Foo.java");
 359 
 360         // check ? in quotes
 361         checkArgumentWildcard("\"lib\\F?o.java\"", "lib\\F?o.java");
 362 
 363         // check ? as suffixes
 364         checkArgumentWildcard("lib\\F?o.????", "lib\\Fbo.java", "lib\\Foo.java");
 365 
 366         // check ? in a leading role
 367         checkArgumentWildcard("lib\\???.java", "lib\\Fbo.java", "lib\\Foo.java");
 368         checkArgumentWildcard("\"lib\\???.java\"", "lib\\???.java");
 369 
 370         // check ? prefixed with -
 371         checkArgumentWildcard("-?", "-?");
 372 
 373         // check * prefixed with -
 374         checkArgumentWildcard("-*", "-*");
 375 
 376         // check on empty directory
 377         checkArgumentWildcard("empty\\*", "empty\\*");
 378         checkArgumentWildcard("empty\\**", "empty\\**");
 379         checkArgumentWildcard("empty\\?", "empty\\?");
 380         checkArgumentWildcard("empty\\??", "empty\\??");
 381         checkArgumentWildcard("empty\\*?", "empty\\*?");
 382         checkArgumentWildcard("empty\\?*", "empty\\?*");
 383 
 384     }
 385 
 386     void doArgumentCheck(String inArgs, String... expArgs) {
 387         Map<String, String> env = new HashMap<>();
 388         env.put(JLDEBUG_KEY, "true");
 389         TestResult tr = doExec(env, javaCmd, inArgs);
 390         System.out.println(tr);
 391         int sindex = tr.testOutput.indexOf("Command line args:");
 392         if (sindex < 0) {
 393             System.out.println(tr);
 394             throw new RuntimeException("Error: no output");
 395         }
 396         sindex++; // skip over the tag
 397         List<String> gotList = new ArrayList<>();
 398         for (String x : tr.testOutput.subList(sindex, sindex + expArgs.length)) {
 399             String a[] = x.split("=");
 400             gotList.add(a[a.length - 1].trim());
 401         }
 402         List<String> expList = Arrays.asList(expArgs);
 403         if (!gotList.equals(expList)) {
 404             System.out.println(tr);
 405             System.out.println("Expected args:");
 406             System.out.println(expList);
 407             System.out.println("Obtained args:");
 408             System.out.println(gotList);
 409             throw new RuntimeException("Error: args do not match");
 410         }
 411     }
 412 
 413 
 414     /*
 415      * These tests are usually run on non-existent targets to check error results
 416      */
 417     @Test
 418     void testBasicErrorMessages() {
 419         // Tests for 5030233
 420         TestResult tr = doExec(javaCmd, "-cp");
 421         tr.checkNegative();
 422         tr.isNotZeroOutput();
 423         if (!tr.testStatus)
 424             System.out.println(tr);
 425 
 426         tr = doExec(javaCmd, "-classpath");
 427         tr.checkNegative();
 428         tr.isNotZeroOutput();
 429         if (!tr.testStatus)
 430             System.out.println(tr);
 431 
 432         tr = doExec(javaCmd, "-jar");
 433         tr.checkNegative();
 434         tr.isNotZeroOutput();
 435         if (!tr.testStatus)
 436             System.out.println(tr);
 437 
 438         tr = doExec(javacCmd, "-cp");
 439         tr.checkNegative();
 440         tr.isNotZeroOutput();
 441         if (!tr.testStatus)
 442             System.out.println(tr);
 443 
 444         // Test for 6356475 "REGRESSION:"java -X" from cmdline fails"
 445         tr = doExec(javaCmd, "-X");
 446         tr.checkPositive();
 447         tr.isNotZeroOutput();
 448         if (!tr.testStatus)
 449             System.out.println(tr);
 450 
 451         tr = doExec(javaCmd, "-help");
 452         tr.checkPositive();
 453         tr.isNotZeroOutput();
 454         if (!tr.testStatus)
 455             System.out.println(tr);
 456 
 457         // 6753938, test for non-negative exit value for an incorrectly formed
 458         // command line,  '% java'
 459         tr = doExec(javaCmd);
 460         tr.checkNegative();
 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 -Xcomp'
 467         tr = doExec(javaCmd, "-Xcomp");
 468         tr.checkNegative();
 469         tr.isNotZeroOutput();
 470         if (!tr.testStatus)
 471             System.out.println(tr);
 472 
 473         // 7151434, test for non-negative exit value for an incorrectly formed
 474         // command line, '% java -jar -W', note the bogus -W
 475         tr = doExec(javaCmd, "-jar", "-W");
 476         tr.checkNegative();
 477         tr.contains("Unrecognized option: -W");
 478         if (!tr.testStatus)
 479             System.out.println(tr);
 480     }
 481 
 482     /*
 483      * Tests various dispositions of the main method, these tests are limited
 484      * to English locales as they check for error messages that are localized.
 485      */
 486     @Test
 487     void testMainMethod() throws FileNotFoundException {
 488         if (!isEnglishLocale()) {
 489             return;
 490         }
 491 
 492         TestResult tr = null;
 493 
 494         // a missing class
 495         createJar("MIA", new File("some.jar"), new File("Foo"),
 496                 (String[])null);
 497         tr = doExec(javaCmd, "-jar", "some.jar");
 498         tr.contains("Error: Could not find or load main class MIA");
 499         if (!tr.testStatus)
 500             System.out.println(tr);
 501         // use classpath to check
 502         tr = doExec(javaCmd, "-cp", "some.jar", "MIA");
 503         tr.contains("Error: Could not find or load main class MIA");
 504         if (!tr.testStatus)
 505             System.out.println(tr);
 506 
 507         // incorrect method access
 508         createJar(new File("some.jar"), new File("Foo"),
 509                 "private static void main(String[] args){}");
 510         tr = doExec(javaCmd, "-jar", "some.jar");
 511         tr.contains("Error: Main method not found in class Foo");
 512         if (!tr.testStatus)
 513             System.out.println(tr);
 514         // use classpath to check
 515         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 516         tr.contains("Error: Main method not found in class Foo");
 517         if (!tr.testStatus)
 518             System.out.println(tr);
 519 
 520         // incorrect return type
 521         createJar(new File("some.jar"), new File("Foo"),
 522                 "public static int main(String[] args){return 1;}");
 523         tr = doExec(javaCmd, "-jar", "some.jar");
 524         tr.contains("Error: Main method must return a value of type void in class Foo");
 525         if (!tr.testStatus)
 526             System.out.println(tr);
 527         // use classpath to check
 528         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 529         tr.contains("Error: Main method must return a value of type void in class Foo");
 530         if (!tr.testStatus)
 531             System.out.println(tr);
 532 
 533         // incorrect parameter type
 534         createJar(new File("some.jar"), new File("Foo"),
 535                 "public static void main(Object[] args){}");
 536         tr = doExec(javaCmd, "-jar", "some.jar");
 537         tr.contains("Error: Main method not found in class Foo");
 538         if (!tr.testStatus)
 539             System.out.println(tr);
 540         // use classpath to check
 541         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 542         tr.contains("Error: Main method not found in class Foo");
 543         if (!tr.testStatus)
 544             System.out.println(tr);
 545 
 546         // incorrect method type - non-static
 547          createJar(new File("some.jar"), new File("Foo"),
 548                 "public void main(String[] args){}");
 549         tr = doExec(javaCmd, "-jar", "some.jar");
 550         tr.contains("Error: Main method is not static in class Foo");
 551         if (!tr.testStatus)
 552             System.out.println(tr);
 553         // use classpath to check
 554         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 555         tr.contains("Error: Main method is not static in class Foo");
 556         if (!tr.testStatus)
 557             System.out.println(tr);
 558 
 559         // amongst a potpourri of kindred main methods, is the right one chosen ?
 560         createJar(new File("some.jar"), new File("Foo"),
 561             "void main(Object[] args){}",
 562             "int  main(Float[] args){return 1;}",
 563             "private void main() {}",
 564             "private static void main(int x) {}",
 565             "public int main(int argc, String[] argv) {return 1;}",
 566             "public static void main(String[] args) {System.out.println(\"THE_CHOSEN_ONE\");}");
 567         tr = doExec(javaCmd, "-jar", "some.jar");
 568         tr.contains("THE_CHOSEN_ONE");
 569         if (!tr.testStatus)
 570             System.out.println(tr);
 571         // use classpath to check
 572         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 573         tr.contains("THE_CHOSEN_ONE");
 574         if (!tr.testStatus)
 575             System.out.println(tr);
 576 
 577         // test for extraneous whitespace in the Main-Class attribute
 578         createJar(" Foo ", new File("some.jar"), new File("Foo"),
 579                 "public static void main(String... args){}");
 580         tr = doExec(javaCmd, "-jar", "some.jar");
 581         tr.checkPositive();
 582         if (!tr.testStatus)
 583             System.out.println(tr);
 584     }
 585     /*
 586      * tests 6968053, ie. we turn on the -Xdiag (for now) flag and check if
 587      * the suppressed stack traces are exposed, ignore these tests for localized
 588      * locales, limiting to English only.
 589      */
 590     @Test
 591     void testDiagOptions() throws FileNotFoundException {
 592         if (!isEnglishLocale()) { // only english version
 593             return;
 594         }
 595         TestResult tr = null;
 596         // a missing class
 597         createJar("MIA", new File("some.jar"), new File("Foo"),
 598                 (String[])null);
 599         tr = doExec(javaCmd, "-Xdiag", "-jar", "some.jar");
 600         tr.contains("Error: Could not find or load main class MIA");
 601         tr.contains("java.lang.ClassNotFoundException: MIA");
 602         if (!tr.testStatus)
 603             System.out.println(tr);
 604 
 605         // use classpath to check
 606         tr = doExec(javaCmd,  "-Xdiag", "-cp", "some.jar", "MIA");
 607         tr.contains("Error: Could not find or load main class MIA");
 608         tr.contains("java.lang.ClassNotFoundException: MIA");
 609         if (!tr.testStatus)
 610             System.out.println(tr);
 611 
 612         // a missing class on the classpath
 613         tr = doExec(javaCmd, "-Xdiag", "NonExistentClass");
 614         tr.contains("Error: Could not find or load main class NonExistentClass");
 615         tr.contains("java.lang.ClassNotFoundException: NonExistentClass");
 616         if (!tr.testStatus)
 617             System.out.println(tr);
 618     }
 619 
 620     /**
 621      * @param args the command line arguments
 622      * @throws java.io.FileNotFoundException
 623      */
 624     public static void main(String[] args) throws Exception {
 625         if (debug) {
 626             System.out.println("Starting Arrrghs tests");
 627         }
 628         Arrrghs a = new Arrrghs();
 629         a.run(args);
 630         if (testExitValue > 0) {
 631             System.out.println("Total of " + testExitValue + " failed");
 632             System.exit(1);
 633         } else {
 634             System.out.println("All tests pass");
 635         }
 636     }
 637 }