test/langtools/jdk/jshell/StartOptionTest.java
author rfield
Fri, 23 Feb 2018 10:49:56 -0800
changeset 48940 ca22f8cb0c9b
parent 48543 7067fe4e054e
child 52938 5ff7480c9e28
permissions -rw-r--r--
8198573: JShell: class replace loses instances Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     1
/*
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 48272
diff changeset
     2
 * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     4
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     7
 * published by the Free Software Foundation.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     8
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    13
 * accompanied this code).
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    14
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    18
 *
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    21
 * questions.
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    22
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    23
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    24
 /*
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    25
 * @test 8151754 8080883 8160089 8170162 8166581 8172102 8171343 8178023 8186708 8179856 8185840 8190383
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    26
 * @summary Testing startExCe-up options.
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 33362
diff changeset
    27
 * @modules jdk.compiler/com.sun.tools.javac.api
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 33362
diff changeset
    28
 *          jdk.compiler/com.sun.tools.javac.main
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 35359
diff changeset
    29
 *          jdk.jdeps/com.sun.tools.javap
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 33362
diff changeset
    30
 *          jdk.jshell/jdk.internal.jshell.tool
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    31
 * @library /tools/lib
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36715
diff changeset
    32
 * @build Compiler toolbox.ToolBox
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    33
 * @run testng StartOptionTest
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    34
 */
43367
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
    35
import java.io.ByteArrayInputStream;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
import java.io.ByteArrayOutputStream;
43367
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
    37
import java.io.InputStream;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    38
import java.io.PrintStream;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    39
import java.nio.charset.StandardCharsets;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    40
import java.nio.file.Path;
41641
a628785b9dd9 8167637: jshell tool: /edit should use EDITOR setting
rfield
parents: 40767
diff changeset
    41
import java.util.HashMap;
36990
ec0b843a7af5 8147515: JShell: Internationalize
rfield
parents: 36778
diff changeset
    42
import java.util.Locale;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    43
import java.util.function.Consumer;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    44
44683
610dc2b48954 8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents: 43367
diff changeset
    45
import java.util.logging.Level;
610dc2b48954 8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents: 43367
diff changeset
    46
import java.util.logging.Logger;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    47
import org.testng.annotations.AfterMethod;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
import org.testng.annotations.BeforeMethod;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    49
import org.testng.annotations.Test;
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
    50
import jdk.jshell.tool.JavaShellToolBuilder;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    51
import static org.testng.Assert.assertEquals;
43367
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
    52
import static org.testng.Assert.assertFalse;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    53
import static org.testng.Assert.assertTrue;
42272
82e273c4f2b3 8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents: 41641
diff changeset
    54
import static org.testng.Assert.fail;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    55
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    56
@Test
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    57
public class StartOptionTest {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    58
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    59
    protected ByteArrayOutputStream cmdout;
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    60
    protected ByteArrayOutputStream cmderr;
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    61
    protected ByteArrayOutputStream console;
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    62
    protected ByteArrayOutputStream userout;
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    63
    protected ByteArrayOutputStream usererr;
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    64
    protected InputStream cmdInStream;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    65
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
    66
    private JavaShellToolBuilder builder() {
44683
610dc2b48954 8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents: 43367
diff changeset
    67
        // turn on logging of launch failures
610dc2b48954 8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents: 43367
diff changeset
    68
        Logger.getLogger("jdk.jshell.execution").setLevel(Level.ALL);
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
    69
        return JavaShellToolBuilder
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    70
                .builder()
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    71
                .out(new PrintStream(cmdout), new PrintStream(console), new PrintStream(userout))
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    72
                .err(new PrintStream(cmderr), new PrintStream(usererr))
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    73
                .in(cmdInStream, null)
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    74
                .persistence(new HashMap<>())
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    75
                .env(new HashMap<>())
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    76
                .locale(Locale.ROOT);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    79
    protected int runShell(String... args) {
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
    80
        try {
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    81
            return builder()
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    82
                    .start(args);
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
    83
        } catch (Exception ex) {
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
    84
            fail("Repl tool died with exception", ex);
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
    85
        }
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    86
        return -1; // for compiler
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
    87
    }
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
    88
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
    89
    protected void check(ByteArrayOutputStream str, Consumer<String> checkOut, String label) {
38608
691b607bbcd6 8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents: 37745
diff changeset
    90
        byte[] bytes = str.toByteArray();
691b607bbcd6 8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents: 37745
diff changeset
    91
        str.reset();
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    92
        String out = new String(bytes, StandardCharsets.UTF_8);
38608
691b607bbcd6 8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents: 37745
diff changeset
    93
        if (checkOut != null) {
691b607bbcd6 8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents: 37745
diff changeset
    94
            checkOut.accept(out);
691b607bbcd6 8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents: 37745
diff changeset
    95
        } else {
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
    96
            assertEquals(out, "", label + ": Expected empty -- ");
38608
691b607bbcd6 8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents: 37745
diff changeset
    97
        }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    98
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    99
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   100
    protected void checkExit(int ec, Consumer<Integer> checkCode) {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   101
        if (checkCode != null) {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   102
            checkCode.accept(ec);
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   103
        } else {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   104
            assertEquals(ec, 0, "Expected standard exit code (0), but found: " + ec);
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   105
        }
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   106
    }
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   107
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   108
    // Start and check the resultant: exit code (Ex), command output (Co),
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   109
    // user output (Uo), command error (Ce), and console output (Cn)
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   110
    protected void startExCoUoCeCn(Consumer<Integer> checkExitCode,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   111
            Consumer<String> checkCmdOutput,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   112
            Consumer<String> checkUserOutput,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   113
            Consumer<String> checkError,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   114
            Consumer<String> checkConsole,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   115
            String... args) {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   116
        int ec = runShell(args);
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   117
        checkExit(ec, checkExitCode);
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
   118
        check(cmdout, checkCmdOutput, "cmdout");
38608
691b607bbcd6 8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents: 37745
diff changeset
   119
        check(cmderr, checkError, "cmderr");
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   120
        check(console, checkConsole, "console");
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
   121
        check(userout, checkUserOutput, "userout");
38608
691b607bbcd6 8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents: 37745
diff changeset
   122
        check(usererr, null, "usererr");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   123
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   124
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   125
    // Start with an exit code and command error check
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   126
    protected void startExCe(int eec, Consumer<String> checkError, String... args) {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   127
        StartOptionTest.this.startExCoUoCeCn(
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   128
                (Integer ec) -> assertEquals((int) ec, eec,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   129
                        "Expected error exit code (" + eec + "), but found: " + ec),
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   130
                null, null, checkError, null, args);
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   131
    }
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   132
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   133
    // Start with a command output check
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   134
    protected void startCo(Consumer<String> checkCmdOutput, String... args) {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   135
        StartOptionTest.this.startExCoUoCeCn(null, checkCmdOutput, null, null, null, args);
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   136
    }
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   137
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   138
    private Consumer<String> assertOrNull(String expected, String label) {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   139
        return expected == null
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   140
                ? null
48272
128de6a38f8e 8191455: jdk/jshell/StartOptionTest.java and jdk/jshell/ToolProviderTest.java failed after changeset e0f08a
rfield
parents: 47840
diff changeset
   141
                : s -> assertEquals(s.replaceAll("\\r\\n?", "\n").trim(), expected.trim(), label);
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
   142
    }
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
   143
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   144
    // Start and check the resultant: exit code (Ex), command output (Co),
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   145
    // user output (Uo), command error (Ce), and console output (Cn)
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   146
    protected void startExCoUoCeCn(int expectedExitCode,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   147
            String expectedCmdOutput,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   148
            String expectedUserOutput,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   149
            String expectedError,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   150
            String expectedConsole,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   151
            String... args) {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   152
        startExCoUoCeCn(
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   153
                expectedExitCode == 0
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   154
                        ? null
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   155
                        : (Integer i) -> assertEquals((int) i, expectedExitCode,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   156
                        "Expected exit code (" + expectedExitCode + "), but found: " + i),
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   157
                assertOrNull(expectedCmdOutput, "cmdout: "),
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   158
                assertOrNull(expectedUserOutput, "userout: "),
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   159
                assertOrNull(expectedError, "cmderr: "),
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   160
                assertOrNull(expectedConsole, "console: "),
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
   161
                args);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   162
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   163
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   164
    // Start with an expected exit code and command error
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   165
    protected void startExCe(int ec, String expectedError, String... args) {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   166
        startExCoUoCeCn(ec, null, null, expectedError, null, args);
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   167
    }
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   168
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   169
    // Start with an expected command output
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   170
    protected void startCo(String expectedCmdOutput, String... args) {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   171
        startExCoUoCeCn(0, expectedCmdOutput, null, null, null, args);
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   172
    }
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   173
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   174
    // Start with an expected user output
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   175
    protected void startUo(String expectedUserOutput, String... args) {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   176
        startExCoUoCeCn(0, null, expectedUserOutput, null, null, args);
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   177
    }
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   178
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   179
    @BeforeMethod
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   180
    public void setUp() {
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   181
        cmdout = new ByteArrayOutputStream();
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   182
        cmderr = new ByteArrayOutputStream();
38608
691b607bbcd6 8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents: 37745
diff changeset
   183
        console = new ByteArrayOutputStream();
691b607bbcd6 8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents: 37745
diff changeset
   184
        userout = new ByteArrayOutputStream();
691b607bbcd6 8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents: 37745
diff changeset
   185
        usererr = new ByteArrayOutputStream();
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   186
        setIn("/exit\n");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   187
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   188
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   189
    protected String writeToFile(String stuff) {
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
   190
        Compiler compiler = new Compiler();
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
   191
        Path p = compiler.getPath("doit.repl");
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
   192
        compiler.writeToFile(p, stuff);
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
   193
        return p.toString();
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
   194
    }
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
   195
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   196
    // Set the input from a String
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   197
    protected void setIn(String s) {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   198
        cmdInStream = new ByteArrayInputStream(s.getBytes());
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
   199
    }
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42272
diff changeset
   200
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   201
    // Test load files
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   202
    public void testCommandFile() {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   203
        String fn = writeToFile("String str = \"Hello \"\n" +
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   204
                "/list\n" +
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   205
                "System.out.println(str + str)\n" +
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   206
                "/exit\n");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   207
        startExCoUoCeCn(0,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   208
                "1 : String str = \"Hello \";\n",
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   209
                "Hello Hello",
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   210
                null,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   211
                null,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   212
                "--no-startup", fn, "-s");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   213
    }
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   214
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   215
    // Test that the usage message is printed
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   216
    public void testUsage() {
48543
7067fe4e054e 8189102: All tools should support -?, -h and --help
goetz
parents: 48272
diff changeset
   217
        for (String opt : new String[]{"-?", "-h", "--help"}) {
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   218
            startCo(s -> {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38613
diff changeset
   219
                assertTrue(s.split("\n").length >= 7, "Not enough usage lines: " + s);
47504
58ce36f43f1a 8179856: jshell tool: not suitable for pipeline use
rfield
parents: 47216
diff changeset
   220
                assertTrue(s.startsWith("Usage:   jshell <option>..."), "Unexpect usage start: " + s);
43367
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   221
                assertTrue(s.contains("--show-version"), "Expected help: " + s);
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   222
                assertFalse(s.contains("Welcome"), "Unexpected start: " + s);
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   223
            }, opt);
43367
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   224
        }
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   225
    }
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   226
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   227
    // Test the --help-extra message
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   228
    public void testHelpExtra() {
43367
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   229
        for (String opt : new String[]{"-X", "--help-extra"}) {
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   230
            startCo(s -> {
43367
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   231
                assertTrue(s.split("\n").length >= 5, "Not enough help-extra lines: " + s);
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   232
                assertTrue(s.contains("--add-exports"), "Expected --add-exports: " + s);
48940
ca22f8cb0c9b 8198573: JShell: class replace loses instances
rfield
parents: 48543
diff changeset
   233
                assertTrue(s.contains("--execution"), "Expected --execution: " + s);
43367
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   234
                assertFalse(s.contains("Welcome"), "Unexpected start: " + s);
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   235
            }, opt);
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38613
diff changeset
   236
        }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   237
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   238
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   239
    // Test handling of bogus options
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   240
    public void testUnknown() {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   241
        startExCe(1, "Unknown option: u", "-unknown");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   242
        startExCe(1, "Unknown option: unknown", "--unknown");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   243
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   244
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   245
    // Test that input is read with "-" and there is no extra output.
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   246
    public void testHypenFile() {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   247
        setIn("System.out.print(\"Hello\");\n");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   248
        startUo("Hello", "-");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   249
        setIn("System.out.print(\"Hello\");\n");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   250
        startUo("Hello", "-", "-");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   251
        String fn = writeToFile("System.out.print(\"===\");");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   252
        setIn("System.out.print(\"Hello\");\n");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   253
        startUo("===Hello===", fn, "-", fn);
47504
58ce36f43f1a 8179856: jshell tool: not suitable for pipeline use
rfield
parents: 47216
diff changeset
   254
        // check that errors go to standard error
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   255
        setIn(") Foobar");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   256
        startExCe(0, s -> assertTrue(s.contains("illegal start of expression"),
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   257
                "cmderr: illegal start of expression"),
47504
58ce36f43f1a 8179856: jshell tool: not suitable for pipeline use
rfield
parents: 47216
diff changeset
   258
                "-");
58ce36f43f1a 8179856: jshell tool: not suitable for pipeline use
rfield
parents: 47216
diff changeset
   259
    }
58ce36f43f1a 8179856: jshell tool: not suitable for pipeline use
rfield
parents: 47216
diff changeset
   260
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   261
    // Test that user specified exit codes are propagated
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   262
    public void testExitCode() {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   263
        setIn("/exit 57\n");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   264
        startExCoUoCeCn(57, null, null, null, "-> /exit 57", "-s");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   265
        setIn("int eight = 8\n" +
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   266
                "/exit eight + \n" +
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   267
                " eight\n");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   268
        startExCoUoCeCn(16, null, null, null,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   269
                "-> int eight = 8\n" +
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   270
                "-> /exit eight + \n" +
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   271
                ">>  eight",
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   272
                "-s");
47504
58ce36f43f1a 8179856: jshell tool: not suitable for pipeline use
rfield
parents: 47216
diff changeset
   273
    }
58ce36f43f1a 8179856: jshell tool: not suitable for pipeline use
rfield
parents: 47216
diff changeset
   274
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   275
    // Test that non-existent load file sends output to stderr and does not startExCe (no welcome).
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   276
    public void testUnknownLoadFile() {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   277
        startExCe(1, "File 'UNKNOWN' for 'jshell' is not found.", "UNKNOWN");
38613
2a8e50869b08 8157953: JShell tests: reenable ToolBasicTest
rfield
parents: 38608
diff changeset
   278
    }
2a8e50869b08 8157953: JShell tests: reenable ToolBasicTest
rfield
parents: 38608
diff changeset
   279
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   280
    // Test bad usage of the --startup option
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   281
    public void testStartup() {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   282
        String fn = writeToFile("");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   283
        startExCe(1, "Argument to startup missing.", "--startup");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   284
        startExCe(1, "Conflicting options: both --startup and --no-startup were used.", "--no-startup", "--startup", fn);
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   285
        startExCe(1, "Conflicting options: both --startup and --no-startup were used.", "--startup", fn, "--no-startup");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   286
        startExCe(1, "Argument to startup missing.", "--no-startup", "--startup");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   287
    }
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   288
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   289
    // Test an option that causes the back-end to fail is propagated
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   290
    public void testStartupFailedOption() {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   291
        startExCe(1, s -> assertTrue(s.contains("Unrecognized option: -hoge-foo-bar"), "cmderr: " + s),
44683
610dc2b48954 8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents: 43367
diff changeset
   292
                "-R-hoge-foo-bar");
42272
82e273c4f2b3 8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents: 41641
diff changeset
   293
    }
82e273c4f2b3 8169519: JShell: Handle start-up failures and hangs gracefully
rfield
parents: 41641
diff changeset
   294
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   295
    // Test the use of non-existant files with the --startup option
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   296
    public void testStartupUnknown() {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   297
        startExCe(1, "File 'UNKNOWN' for '--startup' is not found.", "--startup", "UNKNOWN");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   298
        startExCe(1, "File 'UNKNOWN' for '--startup' is not found.", "--startup", "DEFAULT", "--startup", "UNKNOWN");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   299
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   300
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   301
    // Test bad usage of --class-path option
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   302
    public void testClasspath() {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   303
        for (String cp : new String[]{"--class-path"}) {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   304
            startExCe(1, "Only one --class-path option may be used.", cp, ".", "--class-path", ".");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   305
            startExCe(1, "Argument to class-path missing.", cp);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   306
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   307
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   308
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   309
    // Test bogus module on --add-modules option
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   310
    public void testUnknownModule() {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   311
        startExCe(1, s -> assertTrue(s.contains("rror") && s.contains("unKnown"), "cmderr: " + s),
44683
610dc2b48954 8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents: 43367
diff changeset
   312
                "--add-modules", "unKnown");
610dc2b48954 8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents: 43367
diff changeset
   313
    }
610dc2b48954 8178023: jshell tool: crash with ugly message on attempt to add non-existant module path
rfield
parents: 43367
diff changeset
   314
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   315
    // Test that muliple feedback options fail
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   316
    public void testFeedbackOptionConflict() {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   317
        startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.",
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38613
diff changeset
   318
                "--feedback", "concise", "--feedback", "verbose");
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   319
        startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "--feedback", "concise", "-s");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   320
        startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "--feedback", "verbose", "-q");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   321
        startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "--feedback", "concise", "-v");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   322
        startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-v", "--feedback", "concise");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   323
        startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-q", "-v");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   324
        startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-s", "-v");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   325
        startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-v", "-q");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   326
        startExCe(1, "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-q", "-s");
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38613
diff changeset
   327
    }
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38613
diff changeset
   328
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   329
    // Test bogus arguments to the --feedback option
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   330
    public void testNegFeedbackOption() {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   331
        startExCe(1, "Argument to feedback missing.", "--feedback");
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   332
        startExCe(1, "Does not match any current feedback mode: blorp -- --feedback blorp", "--feedback", "blorp");
37745
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 36993
diff changeset
   333
    }
4b6b59f8e327 8150382: JShell API: Allow setting remote JVM arguments
rfield
parents: 36993
diff changeset
   334
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   335
    // Test --version
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   336
    public void testVersion() {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   337
        startCo(s -> {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   338
            assertTrue(s.startsWith("jshell"), "unexpected version: " + s);
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   339
            assertFalse(s.contains("Welcome"), "Unexpected start: " + s);
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   340
        },
43367
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   341
                "--version");
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   342
    }
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   343
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   344
    // Test --show-version
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   345
    public void testShowVersion() {
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   346
        startExCoUoCeCn(null,
43367
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   347
                s -> {
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   348
                    assertTrue(s.startsWith("jshell"), "unexpected version: " + s);
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   349
                    assertTrue(s.contains("Welcome"), "Expected start (but got no welcome): " + s);
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   350
                },
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   351
                null,
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   352
                null,
43367
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   353
                s -> assertTrue(s.trim().startsWith("jshell>"), "Expected prompt, got: " + s),
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   354
                "--show-version");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   355
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   356
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   357
    @AfterMethod
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   358
    public void tearDown() {
47840
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   359
        cmdout = null;
e0f08a49f3e3 8177076: jshell tool: allow non-zero /exit
rfield
parents: 47504
diff changeset
   360
        cmderr = null;
38608
691b607bbcd6 8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents: 37745
diff changeset
   361
        console = null;
691b607bbcd6 8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents: 37745
diff changeset
   362
        userout = null;
691b607bbcd6 8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents: 37745
diff changeset
   363
        usererr = null;
43367
7797472a9ed5 8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents: 42972
diff changeset
   364
        cmdInStream = null;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   365
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   366
}