jdk/test/tools/launcher/Arrrghs.java
author chegar
Thu, 03 Jan 2013 10:00:55 +0000
changeset 14998 b9a99aac309e
parent 14763 c16fa130fa23
child 15523 cc0ee864bfb5
permissions -rw-r--r--
8005634: tools/launcher/VersionCheck.java fails version check on jdeps Summary: add jdeps to the list of tools that do not support '-version' Reviewed-by: mchung
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
13416
9732a77088fe 7189944: (launcher) test/tools/launcher/Arrrrghs.java needs a couple of minor fixes
ksrini
parents: 13411
diff changeset
    27
 *      6894719 6968053 7151434 7146424
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
14763
c16fa130fa23 8004042: Arrrghs.java test failed on windows with access error.
ksrini
parents: 13416
diff changeset
    30
 * @run main/othervm Arrrghs
1323
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;
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
    39
import java.util.ArrayList;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
    40
import java.util.Arrays;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
    41
import java.util.HashMap;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
    42
import java.util.List;
399
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
    43
import java.util.Map;
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
    44
import java.util.regex.Matcher;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
    45
import java.util.regex.Pattern;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
    47
public class Arrrghs extends TestHelper {
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    48
    private Arrrghs(){}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    50
     * This class provides various tests for arguments processing.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * A group of tests to ensure that arguments are passed correctly to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     * a child java process upon a re-exec, this typically happens when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * a version other than the one being executed is requested by the user.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * 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
    56
     * implementations were notoriously buggy. Implementing these tests purely
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * in Java is not only portable but also robust.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    // The version string to force a re-exec
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    final static String VersionStr = "-version:1.1+";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    // The Cookie or the pattern we match in the debug output.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    final static String Cookie = "ReExec Args: ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * SIGH, On Windows all strings are quoted, we need to unwrap it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private static String removeExtraQuotes(String in) {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
    71
        if (isWindows) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            // Trim the string and remove the enclosed quotes if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            in = in.trim();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            if (in.startsWith("\"") && in.endsWith("\"")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
                return in.substring(1, in.length()-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        return in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * This method detects the cookie in the output stream of the process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
    84
    private boolean detectCookie(InputStream istream,
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    85
            String expectedArguments) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        BufferedReader rd = new BufferedReader(new InputStreamReader(istream));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        boolean retval = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        String in = rd.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        while (in != null) {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
    91
            if (debug) System.out.println(in);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if (in.startsWith(Cookie)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                String detectedArgument = removeExtraQuotes(in.substring(Cookie.length()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                if (expectedArguments.equals(detectedArgument)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                    retval = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                } else {
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    97
                    System.out.println("Error: Expected Arguments\t:'" +
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    98
                            expectedArguments + "'");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
    99
                    System.out.println(" Detected Arguments\t:'" +
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   100
                            detectedArgument + "'");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                // 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
   103
                if (!debug) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                    rd.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                    istream.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                    return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            in = rd.readLine();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   114
    private boolean doReExecTest0(ProcessBuilder pb, String expectedArguments) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        boolean retval = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        try {
399
bcc2354430ff 6684582: Launcher needs improved error reporting
ksrini
parents: 2
diff changeset
   117
            pb.redirectErrorStream(true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            Process p = pb.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            retval = detectCookie(p.getInputStream(), expectedArguments);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            p.waitFor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            p.destroy();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            ex.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            throw new RuntimeException(ex.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        return retval;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    /**
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   130
     * This method returns true  if the expected and detected arguments are the same.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Quoting could cause dissimilar testArguments and expected arguments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   133
    int doReExecTest(String testArguments, String expectedPattern) {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   134
        ProcessBuilder pb = new ProcessBuilder(javaCmd,
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   135
                VersionStr, testArguments);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        Map<String, String> env = pb.environment();
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   138
        env.put(JLDEBUG_KEY, "true");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   139
        return doReExecTest0(pb, testArguments) ? 0 : 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * A convenience method for identical test pattern and expected arguments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   145
    int doReExecTest(String testPattern) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   146
        return doReExecTest(testPattern, testPattern);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   147
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   148
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   149
    @Test
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   150
    void testQuoteParsingThroughReExec() {
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   151
        /*
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   152
         * Tests for 6214916
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   153
         * 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
   154
         * If none is installed, skip this test.
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   155
         */
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   156
        TestResult tr = doExec(javaCmd, VersionStr, "-version");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   157
        if (!tr.isOK()) {
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   158
            System.err.println("Warning:Argument Passing Tests were skipped, " +
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   159
                    "no java found in system registry.");
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   160
            return;
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
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   163
        // Basic test
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   164
        testExitValue += doReExecTest("-a -b -c -d");
1323
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
        // Basic test with many spaces
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   167
        testExitValue += doReExecTest("-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
        // Quoted whitespace does matter ?
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   170
        testExitValue += doReExecTest("-a \"\"-b      -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
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   173
        // Escaped quotes outside of quotes as literals
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   174
        testExitValue += doReExecTest("-a \\\"-b -c\\\" -d");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   175
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   176
        // Check for escaped quotes inside of quotes as literal
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   177
        testExitValue += doReExecTest("-a \"-b \\\"stuff\\\"\" -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
        // A quote preceeded by an odd number of slashes is a literal quote
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   180
        testExitValue += doReExecTest("-a -b\\\\\\\" -c -d");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   181
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   182
        // 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
   183
        // see 6214916.
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   184
        testExitValue += doReExecTest("-a -b\\\\\\\\\" -c -d");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   185
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   186
        // 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
   187
        // appropriate tokens. (space-tab-space preceeds -jre-restict-search).
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   188
        testExitValue += doReExecTest("-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
   189
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   190
        // 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
   191
        // they happen to appear as arguments to the main class.
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   192
        testExitValue += doReExecTest("foo -version:1.1+");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   193
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   194
        System.out.println("Completed arguments quoting tests with "
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   195
                + testExitValue + " errors");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   196
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   197
    // the pattern we hope to see in the output
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   198
    static final Pattern ArgPattern = Pattern.compile("\\s*argv\\[[0-9]*\\].*=.*");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   199
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   200
    void checkArgumentParsing(String inArgs, String... expArgs) throws IOException {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   201
        List<String> scratchpad = new ArrayList<>();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   202
        scratchpad.add("set " + JLDEBUG_KEY + "=true");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   203
        // GAK, -version needs to be added so that windows can flush its stderr
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   204
        // exiting the process prematurely can terminate the stderr.
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   205
        scratchpad.add(javaCmd + " -version " + inArgs);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   206
        File batFile = new File("atest.bat");
14763
c16fa130fa23 8004042: Arrrghs.java test failed on windows with access error.
ksrini
parents: 13416
diff changeset
   207
        createAFile(batFile, scratchpad);
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   208
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   209
        TestResult tr = doExec(batFile.getName());
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   210
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   211
        ArrayList<String> expList = new ArrayList<>();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   212
        expList.add(javaCmd);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   213
        expList.add("-version");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   214
        expList.addAll(Arrays.asList(expArgs));
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   215
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   216
        List<String> gotList = new ArrayList<>();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   217
        for (String x : tr.testOutput) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   218
            Matcher m = ArgPattern.matcher(x);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   219
            if (m.matches()) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   220
                String a[] = x.split("=");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   221
                gotList.add(a[a.length - 1].trim());
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   222
            }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   223
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   224
        if (!gotList.equals(expList)) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   225
            System.out.println(tr);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   226
            System.out.println("Expected args:");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   227
            System.out.println(expList);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   228
            System.out.println("Obtained args:");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   229
            System.out.println(gotList);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   230
            throw new RuntimeException("Error: args do not match");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   231
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   232
        System.out.println("\'" + inArgs + "\'" + " - Test passed");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   233
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   234
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   235
    /*
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   236
     * This tests general quoting and are specific to Windows, *nixes
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   237
     * need not worry about this, these have been tested with Windows
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   238
     * implementation and those that are known to work are used against
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   239
     * the java implementation. Note that the ProcessBuilder gets in the
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   240
     * way when testing some of these arguments, therefore we need to
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   241
     * create and execute a .bat file containing the arguments.
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   242
     */
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   243
    @Test
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   244
    void testArgumentParsing() throws IOException {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   245
        if (!isWindows)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   246
            return;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   247
        // no quotes
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   248
        checkArgumentParsing("a b c d", "a", "b", "c", "d");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   249
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   250
        // single quotes
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   251
        checkArgumentParsing("\"a b c d\"", "a b c d");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   252
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   253
        //double quotes
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   254
        checkArgumentParsing("\"\"a b c d\"\"", "a", "b", "c", "d");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   255
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   256
        // triple quotes
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   257
        checkArgumentParsing("\"\"\"a b c d\"\"\"", "\"a b c d\"");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   258
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   259
        // a literal within single quotes
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   260
        checkArgumentParsing("\"a\"b c d\"e\"", "ab", "c", "de");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   261
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   262
        // a literal within double quotes
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   263
        checkArgumentParsing("\"\"a\"b c d\"e\"\"", "ab c de");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   264
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   265
        // a literal quote
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   266
        checkArgumentParsing("a\\\"b", "a\"b");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   267
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   268
        // double back-slash
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   269
        checkArgumentParsing("\"a b c d\\\\\"", "a b c d\\");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   270
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   271
        // triple back-slash
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   272
        checkArgumentParsing("a\\\\\\\"b", "a\\\"b");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   273
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   274
        // dangling quote
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   275
        checkArgumentParsing("\"a b c\"\"", "a b c\"");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   276
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   277
        // expansions of white space separators
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   278
        checkArgumentParsing("a b", "a", "b");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   279
        checkArgumentParsing("a\tb", "a", "b");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   280
        checkArgumentParsing("a \t b", "a", "b");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   281
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   282
        checkArgumentParsing("\"C:\\TEST A\\\\\"", "C:\\TEST A\\");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   283
        checkArgumentParsing("\"\"C:\\TEST A\\\\\"\"", "C:\\TEST", "A\\");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   284
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   285
        // MS Windows tests
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   286
        // triple back-slash
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   287
        checkArgumentParsing("a\\\\\\d", "a\\\\\\d");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   288
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   289
        // triple back-slash in quotes
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   290
        checkArgumentParsing("\"a\\\\\\d\"", "a\\\\\\d");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   291
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   292
        // slashes separating characters
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   293
        checkArgumentParsing("X\\Y\\Z", "X\\Y\\Z");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   294
        checkArgumentParsing("\\X\\Y\\Z", "\\X\\Y\\Z");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   295
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   296
        // literals within dangling quotes, etc.
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   297
        checkArgumentParsing("\"a b c\" d e", "a b c", "d", "e");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   298
        checkArgumentParsing("\"ab\\\"c\"  \"\\\\\"  d", "ab\"c", "\\", "d");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   299
        checkArgumentParsing("a\\\\\\c d\"e f\"g h", "a\\\\\\c", "de fg", "h");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   300
        checkArgumentParsing("a\\\\\\\"b c d", "a\\\"b", "c", "d");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   301
        checkArgumentParsing("a\\\\\\\\\"g c\" d e", "a\\\\g c", "d", "e");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   302
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   303
        // treatment of back-slashes
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   304
        checkArgumentParsing("*\\", "*\\");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   305
        checkArgumentParsing("*/", "*/");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   306
        checkArgumentParsing(".\\*", ".\\*");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   307
        checkArgumentParsing("./*", "./*");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   308
        checkArgumentParsing("..\\..\\*", "..\\..\\*");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   309
        checkArgumentParsing("../../*", "../../*");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   310
        checkArgumentParsing("..\\..\\", "..\\..\\");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   311
        checkArgumentParsing("../../", "../../");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   312
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   313
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   314
    private void initEmptyDir(File emptyDir) throws IOException {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   315
        if (emptyDir.exists()) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   316
            recursiveDelete(emptyDir);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   317
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   318
        emptyDir.mkdir();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   319
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   320
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   321
    private void initDirWithJavaFiles(File libDir) throws IOException {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   322
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   323
        if (libDir.exists()) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   324
            recursiveDelete(libDir);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   325
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   326
        libDir.mkdirs();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   327
        ArrayList<String> scratchpad = new ArrayList<>();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   328
        scratchpad.add("package lib;");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   329
        scratchpad.add("public class Fbo {");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   330
        scratchpad.add("public static void main(String... args){Foo.f();}");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   331
        scratchpad.add("public static void f(){}");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   332
        scratchpad.add("}");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   333
        createFile(new File(libDir, "Fbo.java"), scratchpad);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   334
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   335
        scratchpad.clear();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   336
        scratchpad.add("package lib;");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   337
        scratchpad.add("public class Foo {");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   338
        scratchpad.add("public static void main(String... args){");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   339
        scratchpad.add("for (String x : args) {");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   340
        scratchpad.add("System.out.println(x);");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   341
        scratchpad.add("}");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   342
        scratchpad.add("Fbo.f();");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   343
        scratchpad.add("}");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   344
        scratchpad.add("public static void f(){}");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   345
        scratchpad.add("}");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   346
        createFile(new File(libDir, "Foo.java"), scratchpad);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   347
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   348
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   349
    void checkArgumentWildcard(String inArgs, String... expArgs) throws IOException {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   350
        String[] in = {inArgs};
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   351
        checkArgumentWildcard(in, expArgs);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   352
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   353
        // now add arbitrary arguments before and after
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   354
        String[] outInArgs = { "-Q", inArgs, "-R"};
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   355
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   356
        String[] outExpArgs = new String[expArgs.length + 2];
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   357
        outExpArgs[0] = "-Q";
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   358
        System.arraycopy(expArgs, 0, outExpArgs, 1, expArgs.length);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   359
        outExpArgs[expArgs.length + 1] = "-R";
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   360
        checkArgumentWildcard(outInArgs, outExpArgs);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   361
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   362
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   363
    void checkArgumentWildcard(String[] inArgs, String[] expArgs) throws IOException {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   364
        ArrayList<String> argList = new ArrayList<>();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   365
        argList.add(javaCmd);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   366
        argList.add("-cp");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   367
        argList.add("lib" + File.separator + "*");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   368
        argList.add("lib.Foo");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   369
        argList.addAll(Arrays.asList(inArgs));
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   370
        String[] cmds = new String[argList.size()];
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   371
        argList.toArray(cmds);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   372
        TestResult tr = doExec(cmds);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   373
        if (!tr.isOK()) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   374
            System.out.println(tr);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   375
            throw new RuntimeException("Error: classpath single entry wildcard entry");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   376
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   377
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   378
        ArrayList<String> expList = new ArrayList<>();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   379
        expList.addAll(Arrays.asList(expArgs));
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   380
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   381
        List<String> gotList = new ArrayList<>();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   382
        for (String x : tr.testOutput) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   383
            gotList.add(x.trim());
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   384
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   385
        if (!gotList.equals(expList)) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   386
            System.out.println(tr);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   387
            System.out.println("Expected args:");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   388
            System.out.println(expList);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   389
            System.out.println("Obtained args:");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   390
            System.out.println(gotList);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   391
            throw new RuntimeException("Error: args do not match");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   392
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   393
        System.out.print("\'");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   394
        for (String x : inArgs) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   395
            System.out.print(x + " ");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   396
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   397
        System.out.println("\'" + " - Test passed");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   398
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   399
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   400
    /*
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   401
     * These tests are not expected to work on *nixes, and are ignored.
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   402
     */
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   403
    @Test
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   404
    void testWildCardArgumentProcessing() throws IOException {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   405
        if (!isWindows)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   406
            return;
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   407
        File cwd = new File(".");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   408
        File libDir = new File(cwd, "lib");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   409
        initDirWithJavaFiles(libDir);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   410
        initEmptyDir(new File(cwd, "empty"));
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   412
        // test if javac (the command) can compile *.java
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   413
        TestResult tr = doExec(javacCmd, libDir.getName() + File.separator + "*.java");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   414
        if (!tr.isOK()) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   415
            System.out.println(tr);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   416
            throw new RuntimeException("Error: compiling java wildcards");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   417
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   418
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   419
        // use the jar cmd to create jars using the ? wildcard
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   420
        File jarFoo = new File(libDir, "Foo.jar");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   421
        tr = doExec(jarCmd, "cvf", jarFoo.getAbsolutePath(), "lib" + File.separator + "F?o.class");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   422
        if (!tr.isOK()) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   423
            System.out.println(tr);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   424
            throw new RuntimeException("Error: creating jar with wildcards");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   425
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   426
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   427
        // now the litmus test!, this should work
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   428
        checkArgumentWildcard("a", "a");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   429
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   430
        // test for basic expansion
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   431
        checkArgumentWildcard("lib\\F*java", "lib\\Fbo.java", "lib\\Foo.java");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   432
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   433
        // basic expansion in quotes
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   434
        checkArgumentWildcard("\"lib\\F*java\"", "lib\\F*java");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   435
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   436
        checkArgumentWildcard("lib\\**", "lib\\Fbo.class", "lib\\Fbo.java",
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   437
                              "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   438
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   439
        checkArgumentWildcard("lib\\*?", "lib\\Fbo.class", "lib\\Fbo.java",
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   440
                              "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   441
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   442
        checkArgumentWildcard("lib\\?*", "lib\\Fbo.class", "lib\\Fbo.java",
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   443
                "lib\\Foo.class", "lib\\Foo.jar", "lib\\Foo.java");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   444
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   445
        checkArgumentWildcard("lib\\?", "lib\\?");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   446
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   447
        // test for basic expansion
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   448
        checkArgumentWildcard("lib\\*java", "lib\\Fbo.java", "lib\\Foo.java");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   449
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   450
        // basic expansion in quotes
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   451
        checkArgumentWildcard("\"lib\\*.java\"", "lib\\*.java");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   452
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   453
        // suffix expansion
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   454
        checkArgumentWildcard("lib\\*.class", "lib\\Fbo.class", "lib\\Foo.class");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   455
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   456
        // suffix expansion in quotes
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   457
        checkArgumentWildcard("\"lib\\*.class\"", "lib\\*.class");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   458
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   459
        // check for ? expansion now
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   460
        checkArgumentWildcard("lib\\F?o.java", "lib\\Fbo.java", "lib\\Foo.java");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   461
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   462
        // check ? in quotes
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   463
        checkArgumentWildcard("\"lib\\F?o.java\"", "lib\\F?o.java");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   464
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   465
        // check ? as suffixes
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   466
        checkArgumentWildcard("lib\\F?o.????", "lib\\Fbo.java", "lib\\Foo.java");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   467
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   468
        // check ? in a leading role
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   469
        checkArgumentWildcard("lib\\???.java", "lib\\Fbo.java", "lib\\Foo.java");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   470
        checkArgumentWildcard("\"lib\\???.java\"", "lib\\???.java");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   471
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   472
        // check ? prefixed with -
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   473
        checkArgumentWildcard("-?", "-?");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   474
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   475
        // check * prefixed with -
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   476
        checkArgumentWildcard("-*", "-*");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   477
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   478
        // check on empty directory
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   479
        checkArgumentWildcard("empty\\*", "empty\\*");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   480
        checkArgumentWildcard("empty\\**", "empty\\**");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   481
        checkArgumentWildcard("empty\\?", "empty\\?");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   482
        checkArgumentWildcard("empty\\??", "empty\\??");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   483
        checkArgumentWildcard("empty\\*?", "empty\\*?");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   484
        checkArgumentWildcard("empty\\?*", "empty\\?*");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   485
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   486
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   487
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   488
    void doArgumentCheck(String inArgs, String... expArgs) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   489
        Map<String, String> env = new HashMap<>();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   490
        env.put(JLDEBUG_KEY, "true");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   491
        TestResult tr = doExec(env, javaCmd, inArgs);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   492
        System.out.println(tr);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   493
        int sindex = tr.testOutput.indexOf("Command line args:");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   494
        if (sindex < 0) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   495
            System.out.println(tr);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   496
            throw new RuntimeException("Error: no output");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   497
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   498
        sindex++; // skip over the tag
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   499
        List<String> gotList = new ArrayList<>();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   500
        for (String x : tr.testOutput.subList(sindex, sindex + expArgs.length)) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   501
            String a[] = x.split("=");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   502
            gotList.add(a[a.length - 1].trim());
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   503
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   504
        List<String> expList = Arrays.asList(expArgs);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   505
        if (!gotList.equals(expList)) {
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   506
            System.out.println(tr);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   507
            System.out.println("Expected args:");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   508
            System.out.println(expList);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   509
            System.out.println("Obtained args:");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   510
            System.out.println(gotList);
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   511
            throw new RuntimeException("Error: args do not match");
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   512
        }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   513
    }
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   514
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   515
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   516
    /*
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   517
     * 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
   518
     */
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   519
    @Test
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   520
    void testBasicErrorMessages() {
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   521
        // Tests for 5030233
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   522
        TestResult tr = doExec(javaCmd, "-cp");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   523
        tr.checkNegative();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   524
        tr.isNotZeroOutput();
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   525
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   526
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   527
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   528
        tr = doExec(javaCmd, "-classpath");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   529
        tr.checkNegative();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   530
        tr.isNotZeroOutput();
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   531
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   532
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   533
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   534
        tr = doExec(javaCmd, "-jar");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   535
        tr.checkNegative();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   536
        tr.isNotZeroOutput();
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   537
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   538
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   539
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   540
        tr = doExec(javacCmd, "-cp");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   541
        tr.checkNegative();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   542
        tr.isNotZeroOutput();
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   543
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   544
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   545
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   546
        // 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
   547
        tr = doExec(javaCmd, "-X");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   548
        tr.checkPositive();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   549
        tr.isNotZeroOutput();
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   550
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   551
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   552
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   553
        tr = doExec(javaCmd, "-help");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   554
        tr.checkPositive();
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   555
        tr.isNotZeroOutput();
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   556
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   557
            System.out.println(tr);
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   558
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   559
        // 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
   560
        // command line,  '% java'
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   561
        tr = doExec(javaCmd);
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   562
        tr.checkNegative();
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   563
        tr.isNotZeroOutput();
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   564
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   565
            System.out.println(tr);
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   566
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   567
        // 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
   568
        // command line,  '% java -Xcomp'
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   569
        tr = doExec(javaCmd, "-Xcomp");
6005
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   570
        tr.checkNegative();
f9e6c98d4ee3 6921472: RFE: java launcher code needs clean up
ksrini
parents: 5506
diff changeset
   571
        tr.isNotZeroOutput();
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   572
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   573
            System.out.println(tr);
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 11822
diff changeset
   574
12703
c5ebefaa2f9f 7170087: tools/launcher/Arrghs.java test has wrong bugID for 7151434
ksrini
parents: 12550
diff changeset
   575
        // 7151434, test for non-negative exit value for an incorrectly formed
12550
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 11822
diff changeset
   576
        // command line, '% java -jar -W', note the bogus -W
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 11822
diff changeset
   577
        tr = doExec(javaCmd, "-jar", "-W");
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 11822
diff changeset
   578
        tr.checkNegative();
482c64a6f825 7151434: java -jar -XX crashes java launcher
ksrini
parents: 11822
diff changeset
   579
        tr.contains("Unrecognized option: -W");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   580
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   581
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   582
    }
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   583
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   584
    /*
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   585
     * 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
   586
     * 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
   587
     */
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   588
    @Test
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   589
    void testMainMethod() throws FileNotFoundException {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   590
        if (!isEnglishLocale()) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   591
            return;
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   592
        }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   593
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   594
        TestResult tr = null;
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   595
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   596
        // a missing class
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   597
        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
   598
                (String[])null);
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   599
        tr = doExec(javaCmd, "-jar", "some.jar");
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   600
        tr.contains("Error: Could not find or load main class MIA");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   601
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   602
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   603
        // use classpath to check
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   604
        tr = doExec(javaCmd, "-cp", "some.jar", "MIA");
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   605
        tr.contains("Error: Could not find or load main class MIA");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   606
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   607
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   608
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   609
        // incorrect method access
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   610
        createJar(new File("some.jar"), new File("Foo"),
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   611
                "private static void main(String[] args){}");
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   612
        tr = doExec(javaCmd, "-jar", "some.jar");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   613
        tr.contains("Error: Main method not found in class Foo");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   614
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   615
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   616
        // use classpath to check
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   617
        tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   618
        tr.contains("Error: Main method not found in class Foo");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   619
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   620
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   621
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   622
        // incorrect return type
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   623
        createJar(new File("some.jar"), new File("Foo"),
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   624
                "public static int main(String[] args){return 1;}");
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   625
        tr = doExec(javaCmd, "-jar", "some.jar");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   626
        tr.contains("Error: Main method must return a value of type void in class Foo");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   627
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   628
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   629
        // use classpath to check
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   630
        tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   631
        tr.contains("Error: Main method must return a value of type void in class Foo");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   632
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   633
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   634
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   635
        // incorrect parameter type
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   636
        createJar(new File("some.jar"), new File("Foo"),
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   637
                "public static void main(Object[] args){}");
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   638
        tr = doExec(javaCmd, "-jar", "some.jar");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   639
        tr.contains("Error: Main method not found in class Foo");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   640
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   641
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   642
        // use classpath to check
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   643
        tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   644
        tr.contains("Error: Main method not found in class Foo");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   645
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   646
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   647
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   648
        // incorrect method type - non-static
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   649
         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
   650
                "public void main(String[] args){}");
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   651
        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
   652
        tr.contains("Error: Main method is not static in class Foo");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   653
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   654
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   655
        // use classpath to check
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   656
        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
   657
        tr.contains("Error: Main method is not static in class Foo");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   658
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   659
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   660
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   661
        // 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
   662
        createJar(new File("some.jar"), new File("Foo"),
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   663
            "void main(Object[] args){}",
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   664
            "int  main(Float[] args){return 1;}",
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   665
            "private void main() {}",
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   666
            "private static void main(int x) {}",
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   667
            "public int main(int argc, String[] argv) {return 1;}",
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   668
            "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
   669
        tr = doExec(javaCmd, "-jar", "some.jar");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   670
        tr.contains("THE_CHOSEN_ONE");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   671
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   672
            System.out.println(tr);
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   673
        // use classpath to check
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   674
        tr = doExec(javaCmd, "-cp", "some.jar", "Foo");
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   675
        tr.contains("THE_CHOSEN_ONE");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   676
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   677
            System.out.println(tr);
1329
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   678
ce13b59a8401 4459600: java -jar fails to run Main-Class if classname followed by whitespace.
ksrini
parents: 1323
diff changeset
   679
        // 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
   680
        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
   681
                "public static void main(String... args){}");
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   682
        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
   683
        tr.checkPositive();
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   684
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   685
            System.out.println(tr);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   687
    /*
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   688
     * 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
   689
     * 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
   690
     * locales, limiting to English only.
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   691
     */
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   692
    @Test
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   693
    void testDiagOptions() throws FileNotFoundException {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   694
        if (!isEnglishLocale()) { // only english version
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   695
            return;
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   696
        }
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   697
        TestResult tr = null;
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   698
        // a missing class
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   699
        createJar("MIA", new File("some.jar"), new File("Foo"),
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   700
                (String[])null);
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   701
        tr = doExec(javaCmd, "-Xdiag", "-jar", "some.jar");
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   702
        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
   703
        tr.contains("java.lang.ClassNotFoundException: MIA");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   704
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   705
            System.out.println(tr);
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   706
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   707
        // use classpath to check
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   708
        tr = doExec(javaCmd,  "-Xdiag", "-cp", "some.jar", "MIA");
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   709
        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
   710
        tr.contains("java.lang.ClassNotFoundException: MIA");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   711
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   712
            System.out.println(tr);
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   713
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   714
        // a missing class on the classpath
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   715
        tr = doExec(javaCmd, "-Xdiag", "NonExistentClass");
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   716
        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
   717
        tr.contains("java.lang.ClassNotFoundException: NonExistentClass");
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   718
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   719
            System.out.println(tr);
8174
89e3a22d4cd7 6968053: (launcher) hide exceptions under certain launcher failures
ksrini
parents: 6888
diff changeset
   720
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   722
    @Test
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   723
    static void testJreRestrictSearchFlag() {
6888
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   724
        // test both arguments to ensure they exist
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   725
        TestResult tr = null;
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   726
        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
   727
                "-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
   728
        tr.checkPositive();
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   729
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   730
            System.out.println(tr);
6888
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   731
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   732
        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
   733
                "-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
   734
        tr.checkPositive();
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   735
        if (!tr.testStatus)
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   736
            System.out.println(tr);
6888
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   737
    }
10126
a375b8714147 7067922: (launcher) java -jar throws NPE if JAR file does not contain Main-Class attribute
ksrini
parents: 9035
diff changeset
   738
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * @param args the command line arguments
1323
e14a3b3536cd 6742159: (launcher) improve the java launching mechanism
ksrini
parents: 399
diff changeset
   741
     * @throws java.io.FileNotFoundException
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     */
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   743
    public static void main(String[] args) throws Exception {
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   744
        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
   745
            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
   746
        }
13411
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   747
        Arrrghs a = new Arrrghs();
224a28370893 7146424: Wildcard expansion for single entry classpath
ksrini
parents: 12703
diff changeset
   748
        a.run(args);
11687
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   749
        if (testExitValue > 0) {
f13cadbb0bb5 7127906: (launcher) convert the launcher regression tests to java
ksrini
parents: 10126
diff changeset
   750
            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
   751
            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
   752
        } else {
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   753
            System.out.println("All tests pass");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
    }
6888
83b7b1e3301c 6894719: (launcher)The option -no-jre-restrict-search is expected when -jre-no-restrict-search is documented.
ksrini
parents: 6005
diff changeset
   756
}