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
  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         // use the jar cmd to create jars using the ? wildcard
 308         File jarFoo = new File(libDir, "Foo.jar");
 309         tr = doExec(jarCmd, "cvf", jarFoo.getAbsolutePath(), "lib" + File.separator + "F?o.class");
 310         if (!tr.isOK()) {
 311             System.out.println(tr);
 312             throw new RuntimeException("Error: creating jar with wildcards");
 313         }
 314 
 315         // now the litmus test!, this should work
 316         checkArgumentWildcard("a", "a");
 317 
 318         // test for basic expansion
 319         checkArgumentWildcard("lib\\F*java", "lib\\Fbo.java", "lib\\Foo.java");
 320 
 321         // basic expansion in quotes
 322         checkArgumentWildcard("\"lib\\F*java\"", "lib\\F*java");
 323 
 324         checkArgumentWildcard("lib\\**", "lib\\Fbo.class", "lib\\Fbo.java",
 325                               "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");
 326 
 327         checkArgumentWildcard("lib\\*?", "lib\\Fbo.class", "lib\\Fbo.java",
 328                               "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");
 329 
 330         checkArgumentWildcard("lib\\?*", "lib\\Fbo.class", "lib\\Fbo.java",
 331                 "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");
 332 
 333         checkArgumentWildcard("lib\\?", "lib\\?");
 334 
 335         // test for basic expansion
 336         checkArgumentWildcard("lib\\*java", "lib\\Fbo.java", "lib\\Foo.java");
 337 
 338         // basic expansion in quotes
 339         checkArgumentWildcard("\"lib\\*.java\"", "lib\\*.java");
 340 
 341         // suffix expansion
 342         checkArgumentWildcard("lib\\*.class", "lib\\Fbo.class", "lib\\Foo.class");
 343 
 344         // suffix expansion in quotes
 345         checkArgumentWildcard("\"lib\\*.class\"", "lib\\*.class");
 346 
 347         // check for ? expansion now
 348         checkArgumentWildcard("lib\\F?o.java", "lib\\Fbo.java", "lib\\Foo.java");
 349 
 350         // check ? in quotes
 351         checkArgumentWildcard("\"lib\\F?o.java\"", "lib\\F?o.java");
 352 
 353         // check ? as suffixes
 354         checkArgumentWildcard("lib\\F?o.????", "lib\\Fbo.java", "lib\\Foo.java");
 355 
 356         // check ? in a leading role
 357         checkArgumentWildcard("lib\\???.java", "lib\\Fbo.java", "lib\\Foo.java");
 358         checkArgumentWildcard("\"lib\\???.java\"", "lib\\???.java");
 359 
 360         // check ? prefixed with -
 361         checkArgumentWildcard("-?", "-?");
 362 
 363         // check * prefixed with -
 364         checkArgumentWildcard("-*", "-*");
 365 
 366         // check on empty directory
 367         checkArgumentWildcard("empty\\*", "empty\\*");
 368         checkArgumentWildcard("empty\\**", "empty\\**");
 369         checkArgumentWildcard("empty\\?", "empty\\?");
 370         checkArgumentWildcard("empty\\??", "empty\\??");
 371         checkArgumentWildcard("empty\\*?", "empty\\*?");
 372         checkArgumentWildcard("empty\\?*", "empty\\?*");
 373 
 374     }
 375 
 376     void doArgumentCheck(String inArgs, String... expArgs) {
 377         Map<String, String> env = new HashMap<>();
 378         env.put(JLDEBUG_KEY, "true");
 379         TestResult tr = doExec(env, javaCmd, inArgs);
 380         System.out.println(tr);
 381         int sindex = tr.testOutput.indexOf("Command line args:");
 382         if (sindex < 0) {
 383             System.out.println(tr);
 384             throw new RuntimeException("Error: no output");
 385         }
 386         sindex++; // skip over the tag
 387         List<String> gotList = new ArrayList<>();
 388         for (String x : tr.testOutput.subList(sindex, sindex + expArgs.length)) {
 389             String a[] = x.split("=");
 390             gotList.add(a[a.length - 1].trim());
 391         }
 392         List<String> expList = Arrays.asList(expArgs);
 393         if (!gotList.equals(expList)) {
 394             System.out.println(tr);
 395             System.out.println("Expected args:");
 396             System.out.println(expList);
 397             System.out.println("Obtained args:");
 398             System.out.println(gotList);
 399             throw new RuntimeException("Error: args do not match");
 400         }
 401     }
 402 
 403 
 404     /*
 405      * These tests are usually run on non-existent targets to check error results
 406      */
 407     @Test
 408     void testBasicErrorMessages() {
 409         // Tests for 5030233
 410         TestResult tr = doExec(javaCmd, "-cp");
 411         tr.checkNegative();
 412         tr.isNotZeroOutput();
 413         if (!tr.testStatus)
 414             System.out.println(tr);
 415 
 416         tr = doExec(javaCmd, "-classpath");
 417         tr.checkNegative();
 418         tr.isNotZeroOutput();
 419         if (!tr.testStatus)
 420             System.out.println(tr);
 421 
 422         tr = doExec(javaCmd, "-jar");
 423         tr.checkNegative();
 424         tr.isNotZeroOutput();
 425         if (!tr.testStatus)
 426             System.out.println(tr);
 427 
 428         tr = doExec(javacCmd, "-cp");
 429         tr.checkNegative();
 430         tr.isNotZeroOutput();
 431         if (!tr.testStatus)
 432             System.out.println(tr);
 433 
 434         // Test for 6356475 "REGRESSION:"java -X" from cmdline fails"
 435         tr = doExec(javaCmd, "-X");
 436         tr.checkPositive();
 437         tr.isNotZeroOutput();
 438         if (!tr.testStatus)
 439             System.out.println(tr);
 440 
 441         tr = doExec(javaCmd, "-help");
 442         tr.checkPositive();
 443         tr.isNotZeroOutput();
 444         if (!tr.testStatus)
 445             System.out.println(tr);
 446 
 447         // 6753938, test for non-negative exit value for an incorrectly formed
 448         // command line,  '% java'
 449         tr = doExec(javaCmd);
 450         tr.checkNegative();
 451         tr.isNotZeroOutput();
 452         if (!tr.testStatus)
 453             System.out.println(tr);
 454 
 455         // 6753938, test for non-negative exit value for an incorrectly formed
 456         // command line,  '% java -Xcomp'
 457         tr = doExec(javaCmd, "-Xcomp");
 458         tr.checkNegative();
 459         tr.isNotZeroOutput();
 460         if (!tr.testStatus)
 461             System.out.println(tr);
 462 
 463         // 7151434, test for non-negative exit value for an incorrectly formed
 464         // command line, '% java -jar -W', note the bogus -W
 465         tr = doExec(javaCmd, "-jar", "-W");
 466         tr.checkNegative();
 467         tr.contains("Unrecognized option: -W");
 468         if (!tr.testStatus)
 469             System.out.println(tr);
 470     }
 471 
 472     /*
 473      * Tests various dispositions of the main method, these tests are limited
 474      * to English locales as they check for error messages that are localized.
 475      */
 476     @Test
 477     void testMainMethod() throws FileNotFoundException {
 478         if (!isEnglishLocale()) {
 479             return;
 480         }
 481 
 482         TestResult tr = null;
 483 
 484         // a missing class
 485         createJar("MIA", new File("some.jar"), new File("Foo"),
 486                 (String[])null);
 487         tr = doExec(javaCmd, "-jar", "some.jar");
 488         tr.contains("Error: Could not find or load main class MIA");
 489         if (!tr.testStatus)
 490             System.out.println(tr);
 491         // use classpath to check
 492         tr = doExec(javaCmd, "-cp", "some.jar", "MIA");
 493         tr.contains("Error: Could not find or load main class MIA");
 494         if (!tr.testStatus)
 495             System.out.println(tr);
 496 
 497         // incorrect method access
 498         createJar(new File("some.jar"), new File("Foo"),
 499                 "private static void main(String[] args){}");
 500         tr = doExec(javaCmd, "-jar", "some.jar");
 501         tr.contains("Error: Main method not found in class Foo");
 502         if (!tr.testStatus)
 503             System.out.println(tr);
 504         // use classpath to check
 505         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 506         tr.contains("Error: Main method not found in class Foo");
 507         if (!tr.testStatus)
 508             System.out.println(tr);
 509 
 510         // incorrect return type
 511         createJar(new File("some.jar"), new File("Foo"),
 512                 "public static int main(String[] args){return 1;}");
 513         tr = doExec(javaCmd, "-jar", "some.jar");
 514         tr.contains("Error: Main method must return a value of type void in class Foo");
 515         if (!tr.testStatus)
 516             System.out.println(tr);
 517         // use classpath to check
 518         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 519         tr.contains("Error: Main method must return a value of type void in class Foo");
 520         if (!tr.testStatus)
 521             System.out.println(tr);
 522 
 523         // incorrect parameter type
 524         createJar(new File("some.jar"), new File("Foo"),
 525                 "public static void main(Object[] args){}");
 526         tr = doExec(javaCmd, "-jar", "some.jar");
 527         tr.contains("Error: Main method not found in class Foo");
 528         if (!tr.testStatus)
 529             System.out.println(tr);
 530         // use classpath to check
 531         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 532         tr.contains("Error: Main method not found in class Foo");
 533         if (!tr.testStatus)
 534             System.out.println(tr);
 535 
 536         // incorrect method type - non-static
 537          createJar(new File("some.jar"), new File("Foo"),
 538                 "public void main(String[] args){}");
 539         tr = doExec(javaCmd, "-jar", "some.jar");
 540         tr.contains("Error: Main method is not static in class Foo");
 541         if (!tr.testStatus)
 542             System.out.println(tr);
 543         // use classpath to check
 544         tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
 545         tr.contains("Error: Main method is not static in class Foo");
 546         if (!tr.testStatus)
 547             System.out.println(tr);
 548 
 549         // amongst a potpourri of kindred main methods, is the right one chosen ?
 550         createJar(new File("some.jar"), new File("Foo"),
 551             "void main(Object[] args){}",
 552             "int  main(Float[] args){return 1;}",
 553             "private void main() {}",
 554             "private static void main(int x) {}",
 555             "public int main(int argc, String[] argv) {return 1;}",
 556             "public static void main(String[] args) {System.out.println(\"THE_CHOSEN_ONE\");}");
 557         tr = doExec(javaCmd, "-jar", "some.jar");
 558         tr.contains("THE_CHOSEN_ONE");
 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("THE_CHOSEN_ONE");
 564         if (!tr.testStatus)
 565             System.out.println(tr);
 566 
 567         // test for extraneous whitespace in the Main-Class attribute
 568         createJar(" Foo ", new File("some.jar"), new File("Foo"),
 569                 "public static void main(String... args){}");
 570         tr = doExec(javaCmd, "-jar", "some.jar");
 571         tr.checkPositive();
 572         if (!tr.testStatus)
 573             System.out.println(tr);
 574     }
 575     /*
 576      * tests 6968053, ie. we turn on the -Xdiag (for now) flag and check if
 577      * the suppressed stack traces are exposed, ignore these tests for localized
 578      * locales, limiting to English only.
 579      */
 580     @Test
 581     void testDiagOptions() throws FileNotFoundException {
 582         if (!isEnglishLocale()) { // only english version
 583             return;
 584         }
 585         TestResult tr = null;
 586         // a missing class
 587         createJar("MIA", new File("some.jar"), new File("Foo"),
 588                 (String[])null);
 589         tr = doExec(javaCmd, "-Xdiag", "-jar", "some.jar");
 590         tr.contains("Error: Could not find or load main class MIA");
 591         tr.contains("java.lang.ClassNotFoundException: MIA");
 592         if (!tr.testStatus)
 593             System.out.println(tr);
 594 
 595         // use classpath to check
 596         tr = doExec(javaCmd,  "-Xdiag", "-cp", "some.jar", "MIA");
 597         tr.contains("Error: Could not find or load main class MIA");
 598         tr.contains("java.lang.ClassNotFoundException: MIA");
 599         if (!tr.testStatus)
 600             System.out.println(tr);
 601 
 602         // a missing class on the classpath
 603         tr = doExec(javaCmd, "-Xdiag", "NonExistentClass");
 604         tr.contains("Error: Could not find or load main class NonExistentClass");
 605         tr.contains("java.lang.ClassNotFoundException: NonExistentClass");
 606         if (!tr.testStatus)
 607             System.out.println(tr);
 608     }
 609 
 610     /**
 611      * @param args the command line arguments
 612      * @throws java.io.FileNotFoundException
 613      */
 614     public static void main(String[] args) throws Exception {
 615         if (debug) {
 616             System.out.println("Starting Arrrghs tests");
 617         }
 618         Arrrghs a = new Arrrghs();
 619         a.run(args);
 620         if (testExitValue > 0) {
 621             System.out.println("Total of " + testExitValue + " failed");
 622             System.exit(1);
 623         } else {
 624             System.out.println("All tests pass");
 625         }
 626     }
 627 }