jdk/test/tools/launcher/Arrrghs.java
author ksrini
Tue, 24 Apr 2012 10:37:01 -0700
changeset 12550 482c64a6f825
parent 11822 475ac0b35c06
child 12703 c5ebefaa2f9f
permissions -rw-r--r--
7151434: java -jar -XX crashes java launcher Reviewed-by: mchung, darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
     2
 * Copyright (c) 2007, 2012, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4340
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4340
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4340
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    24
/**
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    25
 * @test
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
    26
 * @bug 5030233 6214916 6356475 6571029 6684582 6742159 4459600 6758881 6753938
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 11822
diff changeset
    27
 *      6894719 6968053 7151314
1343
ecc86134ee4c 6758881: (launcher) needs to throw NoClassDefFoundError instead of JavaRuntimeException
ksrini
parents: 1329
diff changeset
    28
 * @summary Argument parsing validation.
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
    29
 * @compile -XDignore.symbol.file Arrrghs.java
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    30
 * @run main Arrrghs
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    31
 */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    32
399
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
    33
import java.io.BufferedReader;
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
    34
import java.io.File;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    35
import java.io.FileNotFoundException;
399
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
    36
import java.io.IOException;
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
    37
import java.io.InputStream;
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
    38
import java.io.InputStreamReader;
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
    39
import java.util.Map;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
    41
public class Arrrghs extends TestHelper {
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    42
    private Arrrghs(){}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    /**
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    44
     * This class provides various tests for arguments processing.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * A group of tests to ensure that arguments are passed correctly to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * a child java process upon a re-exec, this typically happens when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * a version other than the one being executed is requested by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * History: these set of tests  were part of Arrrghs.sh. The MKS shell
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    50
     * implementations were notoriously buggy. Implementing these tests purely
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * in Java is not only portable but also robust.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    // The version string to force a re-exec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    final static String VersionStr = "-version:1.1+";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // The Cookie or the pattern we match in the debug output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    final static String Cookie = "ReExec Args: ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * SIGH, On Windows all strings are quoted, we need to unwrap it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    private static String removeExtraQuotes(String in) {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
    65
        if (isWindows) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            // Trim the string and remove the enclosed quotes if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            in = in.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            if (in.startsWith("\"") && in.endsWith("\"")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
                return in.substring(1, in.length()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        return in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * This method detects the cookie in the output stream of the process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    78
    private static boolean detectCookie(InputStream istream,
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    79
            String expectedArguments) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        BufferedReader rd = new BufferedReader(new InputStreamReader(istream));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        boolean retval = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        String in = rd.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        while (in != null) {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
    85
            if (debug) System.out.println(in);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            if (in.startsWith(Cookie)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                String detectedArgument = removeExtraQuotes(in.substring(Cookie.length()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                if (expectedArguments.equals(detectedArgument)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    retval = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                } else {
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    91
                    System.out.println("Error: Expected Arguments\t:'" +
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    92
                            expectedArguments + "'");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    93
                    System.out.println(" Detected Arguments\t:'" +
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    94
                            detectedArgument + "'");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                // Return the value asap if not in debug mode.
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
    97
                if (!debug) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    rd.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    istream.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            in = rd.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   108
    private static boolean doTest0(ProcessBuilder pb, String expectedArguments) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        boolean retval = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        try {
399
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
   111
            pb.redirectErrorStream(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            Process p = pb.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            retval = detectCookie(p.getInputStream(), expectedArguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            p.waitFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            p.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            throw new RuntimeException(ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * This method return true  if the expected and detected arguments are the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Quoting could cause dissimilar testArguments and expected arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   127
    static int doTest(String testArguments, String expectedPattern) {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   128
        ProcessBuilder pb = new ProcessBuilder(javaCmd,
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   129
                VersionStr, testArguments);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        Map<String, String> env = pb.environment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        env.put("_JAVA_LAUNCHER_DEBUG", "true");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   133
        return doTest0(pb, testArguments) ? 0 : 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * A convenience method for identical test pattern and expected arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   139
    static int doTest(String testPattern) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   140
        return doTest(testPattern, testPattern);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   141
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   142
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   143
    static void quoteParsingTests() {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   144
        /*
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   145
         * Tests for 6214916
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   146
         * These tests require that a JVM (any JVM) be installed in the system registry.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   147
         * If none is installed, skip this test.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   148
         */
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   149
        TestResult tr = doExec(javaCmd, VersionStr, "-version");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   150
        if (!tr.isOK()) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   151
            System.err.println("Warning:Argument Passing Tests were skipped, " +
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   152
                    "no java found in system registry.");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   153
            return;
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   154
        }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   155
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   156
        // Basic test
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   157
        testExitValue += doTest("-a -b -c -d");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   158
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   159
        // Basic test with many spaces
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   160
        testExitValue += doTest("-a    -b      -c       -d");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   161
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   162
        // Quoted whitespace does matter ?
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   163
        testExitValue += doTest("-a \"\"-b      -c\"\" -d");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   164
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   165
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   166
        // Escaped quotes outside of quotes as literals
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   167
        testExitValue += doTest("-a \\\"-b -c\\\" -d");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   168
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   169
        // Check for escaped quotes inside of quotes as literal
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   170
        testExitValue += doTest("-a \"-b \\\"stuff\\\"\" -c -d");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   171
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   172
        // A quote preceeded by an odd number of slashes is a literal quote
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   173
        testExitValue += doTest("-a -b\\\\\\\" -c -d");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   174
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   175
        // A quote preceeded by an even number of slashes is a literal quote
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   176
        // see 6214916.
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   177
        testExitValue += doTest("-a -b\\\\\\\\\" -c -d");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   178
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   179
        // Make sure that whitespace doesn't interfere with the removal of the
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   180
        // appropriate tokens. (space-tab-space preceeds -jre-restict-search).
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   181
        testExitValue += doTest("-a -b  \t -jre-restrict-search -c -d","-a -b -c -d");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   182
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   183
        // Make sure that the mJRE tokens being stripped, aren't stripped if
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   184
        // they happen to appear as arguments to the main class.
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   185
        testExitValue += doTest("foo -version:1.1+");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   186
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   187
        System.out.println("Completed arguments quoting tests with " +
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   188
                testExitValue + " errors");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   189
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   190
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   191
    /*
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   192
     * These tests are usually run on non-existent targets to check error results
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   193
     */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   194
    static void runBasicErrorMessageTests() {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   195
        // Tests for 5030233
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   196
        TestResult tr = doExec(javaCmd, "-cp");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   197
        tr.checkNegative();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   198
        tr.isNotZeroOutput();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   199
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   200
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   201
        tr = doExec(javaCmd, "-classpath");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   202
        tr.checkNegative();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   203
        tr.isNotZeroOutput();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   204
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   205
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   206
        tr = doExec(javaCmd, "-jar");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   207
        tr.checkNegative();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   208
        tr.isNotZeroOutput();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   209
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   210
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   211
        tr = doExec(javacCmd, "-cp");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   212
        tr.checkNegative();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   213
        tr.isNotZeroOutput();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   214
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   215
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   216
        // Test for 6356475 "REGRESSION:"java -X" from cmdline fails"
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   217
        tr = doExec(javaCmd, "-X");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   218
        tr.checkPositive();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   219
        tr.isNotZeroOutput();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   220
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   221
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   222
        tr = doExec(javaCmd, "-help");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   223
        tr.checkPositive();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   224
        tr.isNotZeroOutput();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   225
        System.out.println(tr);
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   226
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   227
        // 6753938, test for non-negative exit value for an incorrectly formed
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   228
        // command line,  '% java'
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   229
        tr = doExec(javaCmd);
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   230
        tr.checkNegative();
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   231
        tr.isNotZeroOutput();
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   232
        System.out.println(tr);
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   233
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   234
        // 6753938, test for non-negative exit value for an incorrectly formed
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   235
        // command line,  '% java -Xcomp'
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   236
        tr = doExec(javaCmd, "-Xcomp");
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   237
        tr.checkNegative();
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   238
        tr.isNotZeroOutput();
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   239
        System.out.println(tr);
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 11822
diff changeset
   240
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 11822
diff changeset
   241
        // 7151314, test for non-negative exit value for an incorrectly formed
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 11822
diff changeset
   242
        // command line, '% java -jar -W', note the bogus -W
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 11822
diff changeset
   243
        tr = doExec(javaCmd, "-jar", "-W");
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 11822
diff changeset
   244
        tr.checkNegative();
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 11822
diff changeset
   245
        tr.contains("Unrecognized option: -W");
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 11822
diff changeset
   246
        System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   247
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   248
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   249
    /*
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   250
     * Tests various dispositions of the main method, these tests are limited
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   251
     * to English locales as they check for error messages that are localized.
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   252
     */
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   253
    static void runMainMethodTests() throws FileNotFoundException {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   254
        if (!isEnglishLocale()) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   255
            return;
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   256
        }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   257
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   258
        TestResult tr = null;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   259
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   260
        // a missing class
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   261
        createJar("MIA", new File("some.jar"), new File("Foo"),
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   262
                (String[])null);
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   263
        tr = doExec(javaCmd, "-jar", "some.jar");
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   264
        tr.contains("Error: Could not find or load main class MIA");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   265
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   266
        // use classpath to check
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   267
        tr = doExec(javaCmd, "-cp", "some.jar", "MIA");
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   268
        tr.contains("Error: Could not find or load main class MIA");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   269
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   270
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   271
        // incorrect method access
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   272
        createJar(new File("some.jar"), new File("Foo"),
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   273
                "private static void main(String[] args){}");
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   274
        tr = doExec(javaCmd, "-jar", "some.jar");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   275
        tr.contains("Error: Main method not found in class Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   276
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   277
        // use classpath to check
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   278
        tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   279
        tr.contains("Error: Main method not found in class Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   280
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   281
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   282
        // incorrect return type
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   283
        createJar(new File("some.jar"), new File("Foo"),
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   284
                "public static int main(String[] args){return 1;}");
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   285
        tr = doExec(javaCmd, "-jar", "some.jar");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   286
        tr.contains("Error: Main method must return a value of type void in class Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   287
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   288
        // use classpath to check
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   289
        tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   290
        tr.contains("Error: Main method must return a value of type void in class Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   291
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   292
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   293
        // incorrect parameter type
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   294
        createJar(new File("some.jar"), new File("Foo"),
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   295
                "public static void main(Object[] args){}");
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   296
        tr = doExec(javaCmd, "-jar", "some.jar");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   297
        tr.contains("Error: Main method not found in class Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   298
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   299
        // use classpath to check
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   300
        tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   301
        tr.contains("Error: Main method not found in class Foo");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   302
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   303
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   304
        // incorrect method type - non-static
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   305
         createJar(new File("some.jar"), new File("Foo"),
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   306
                "public void main(String[] args){}");
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   307
        tr = doExec(javaCmd, "-jar", "some.jar");
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   308
        tr.contains("Error: Main method is not static in class Foo");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   309
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   310
        // use classpath to check
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   311
        tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   312
        tr.contains("Error: Main method is not static in class Foo");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   313
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   314
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   315
        // amongst a potpourri of kindred main methods, is the right one chosen ?
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   316
        createJar(new File("some.jar"), new File("Foo"),
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   317
            "void main(Object[] args){}",
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   318
            "int  main(Float[] args){return 1;}",
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   319
            "private void main() {}",
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   320
            "private static void main(int x) {}",
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   321
            "public int main(int argc, String[] argv) {return 1;}",
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   322
            "public static void main(String[] args) {System.out.println(\"THE_CHOSEN_ONE\");}");
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   323
        tr = doExec(javaCmd, "-jar", "some.jar");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   324
        tr.contains("THE_CHOSEN_ONE");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   325
        System.out.println(tr);
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   326
        // use classpath to check
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   327
        tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   328
        tr.contains("THE_CHOSEN_ONE");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   329
        System.out.println(tr);
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   330
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   331
        // test for extraneous whitespace in the Main-Class attribute
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   332
        createJar(" Foo ", new File("some.jar"), new File("Foo"),
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   333
                "public static void main(String... args){}");
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   334
        tr = doExec(javaCmd, "-jar", "some.jar");
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   335
        tr.checkPositive();
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   336
        System.out.println(tr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    }
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   338
    /*
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   339
     * tests 6968053, ie. we turn on the -Xdiag (for now) flag and check if
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   340
     * the suppressed stack traces are exposed, ignore these tests for localized
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   341
     * locales, limiting to English only.
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   342
     */
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   343
    static void runDiagOptionTests() throws FileNotFoundException {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   344
        if (!isEnglishLocale()) { // only english version
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   345
            return;
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   346
        }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   347
        TestResult tr = null;
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   348
        // a missing class
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   349
        createJar("MIA", new File("some.jar"), new File("Foo"),
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   350
                (String[])null);
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   351
        tr = doExec(javaCmd, "-Xdiag", "-jar", "some.jar");
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   352
        tr.contains("Error: Could not find or load main class MIA");
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   353
        tr.contains("java.lang.ClassNotFoundException: MIA");
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   354
        System.out.println(tr);
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   355
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   356
        // use classpath to check
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   357
        tr = doExec(javaCmd,  "-Xdiag", "-cp", "some.jar", "MIA");
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   358
        tr.contains("Error: Could not find or load main class MIA");
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   359
        tr.contains("java.lang.ClassNotFoundException: MIA");
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   360
        System.out.println(tr);
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   361
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   362
        // a missing class on the classpath
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   363
        tr = doExec(javaCmd, "-Xdiag", "NonExistentClass");
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   364
        tr.contains("Error: Could not find or load main class NonExistentClass");
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   365
        tr.contains("java.lang.ClassNotFoundException: NonExistentClass");
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   366
        System.out.println(tr);
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   367
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
6888
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   369
    static void test6894719() {
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   370
        // test both arguments to ensure they exist
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   371
        TestResult tr = null;
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   372
        tr = doExec(javaCmd,
6888
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   373
                "-no-jre-restrict-search", "-version");
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   374
        tr.checkPositive();
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   375
        System.out.println(tr);
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   376
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   377
        tr = doExec(javaCmd,
6888
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   378
                "-jre-restrict-search", "-version");
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   379
        tr.checkPositive();
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   380
        System.out.println(tr);
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   381
    }
10126
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9035
diff changeset
   382
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @param args the command line arguments
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   385
     * @throws java.io.FileNotFoundException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     */
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   387
    public static void main(String[] args) throws FileNotFoundException {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   388
        if (debug) {
6888
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   389
            System.out.println("Starting Arrrghs tests");
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   390
        }
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   391
        quoteParsingTests();
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   392
        runBasicErrorMessageTests();
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   393
        runMainMethodTests();
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   394
        test6894719();
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   395
        runDiagOptionTests();
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   396
        if (testExitValue > 0) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   397
            System.out.println("Total of " + testExitValue + " failed");
6888
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   398
            System.exit(1);
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   399
        } else {
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   400
            System.out.println("All tests pass");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
6888
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   403
}