test/langtools/jdk/jshell/ToolBasicTest.java
author rfield
Sat, 01 Jun 2019 14:09:59 -0700
changeset 55143 905b2a416250
parent 53215 299fe76c25c7
permissions -rw-r--r--
8223688: JShell: crash on the instantiation of raw anonymous class 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
/*
50019
e2dc18484400 8202599: Mark intermittently failing jshell tests
darcy
parents: 50017
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    24
/*
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    25
 * @test
55143
905b2a416250 8223688: JShell: crash on the instantiation of raw anonymous class
rfield
parents: 53215
diff changeset
    26
 * @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886 8148316 8148317 8143955 8157953 8080347 8154714 8166649 8167643 8170162 8172102 8165405 8174796 8174797 8175304 8167554 8180508 8166232 8196133 8199912 8211694 8223688
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36718
diff changeset
    27
 * @summary Tests for Basic tests for REPL tool
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javac.api
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    29
 *          jdk.compiler/com.sun.tools.javac.main
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    30
 *          jdk.jdeps/com.sun.tools.javap
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
    31
 *          jdk.jshell/jdk.internal.jshell.tool
34570
8a8f52a733dd 8144095: jshell tool: normalize command parameter handling
rfield
parents: 34481
diff changeset
    32
 * @library /tools/lib
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36718
diff changeset
    33
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36718
diff changeset
    34
 * @build KullaTesting TestingInputStream Compiler
35002
209d72239196 8144906: Fix jshell's ToolBasicTest
jlahoda
parents: 34570
diff changeset
    35
 * @run testng/timeout=600 ToolBasicTest
50019
e2dc18484400 8202599: Mark intermittently failing jshell tests
darcy
parents: 50017
diff changeset
    36
 * @key intermittent
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    37
 */
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    38
43856
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
    39
import java.io.File;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    40
import java.io.IOException;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    41
import java.io.PrintWriter;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    42
import java.io.StringWriter;
50017
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
    43
import java.net.InetAddress;
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
    44
import java.net.InetSocketAddress;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    45
import java.nio.file.Files;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    46
import java.nio.file.Path;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    47
import java.nio.file.Paths;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
import java.util.ArrayList;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    49
import java.util.Arrays;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    50
import java.util.List;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    51
import java.util.Scanner;
34477
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
    52
import java.util.function.BiFunction;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    53
import java.util.function.Consumer;
34477
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
    54
import java.util.function.Function;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    55
import java.util.stream.Collectors;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    56
import java.util.stream.Stream;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    57
50017
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
    58
import com.sun.net.httpserver.HttpServer;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    59
import org.testng.annotations.Test;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    60
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    61
import static org.testng.Assert.assertEquals;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    62
import static org.testng.Assert.assertTrue;
55143
905b2a416250 8223688: JShell: crash on the instantiation of raw anonymous class
rfield
parents: 53215
diff changeset
    63
import static org.testng.Assert.assertFalse;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    64
import static org.testng.Assert.fail;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    65
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    66
@Test
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    67
public class ToolBasicTest extends ReplToolTesting {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    68
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    69
    public void elideStartUpFromList() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    70
        test(
38613
2a8e50869b08 8157953: JShell tests: reenable ToolBasicTest
rfield
parents: 38531
diff changeset
    71
                (a) -> assertCommandOutputContains(a, "123", "==> 123"),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    72
                (a) -> assertCommandCheckOutput(a, "/list", (s) -> {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    73
                    int cnt;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    74
                    try (Scanner scanner = new Scanner(s)) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    75
                        cnt = 0;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    76
                        while (scanner.hasNextLine()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    77
                            String line = scanner.nextLine();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    78
                            if (!line.trim().isEmpty()) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    79
                                ++cnt;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    80
                            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    81
                        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    82
                    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    83
                    assertEquals(cnt, 1, "Expected only one listed line");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    84
                })
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    85
        );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    86
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    87
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    88
    public void elideStartUpFromSave() throws IOException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    89
        Compiler compiler = new Compiler();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    90
        Path path = compiler.getPath("myfile");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    91
        test(
38613
2a8e50869b08 8157953: JShell tests: reenable ToolBasicTest
rfield
parents: 38531
diff changeset
    92
                (a) -> assertCommandOutputContains(a, "123", "==> 123"),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    93
                (a) -> assertCommand(a, "/save " + path.toString(), "")
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    94
        );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    95
        try (Stream<String> lines = Files.lines(path)) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    96
            assertEquals(lines.count(), 1, "Expected only one saved line");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    97
        }
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
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   100
    public void testInterrupt() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   101
        ReplTest interrupt = (a) -> assertCommand(a, "\u0003", "");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   102
        for (String s : new String[] { "", "\u0003" }) {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 40516
diff changeset
   103
            test(false, new String[]{"--no-startup"},
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   104
                    (a) -> assertCommand(a, "int a = 2 +" + s, ""),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   105
                    interrupt,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   106
                    (a) -> assertCommand(a, "int a\u0003", ""),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   107
                    (a) -> assertCommand(a, "int a = 2 + 2\u0003", ""),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   108
                    (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   109
                    (a) -> evaluateExpression(a, "int", "2", "2"),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   110
                    (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   111
                    (a) -> assertCommand(a, "void f() {", ""),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   112
                    (a) -> assertCommand(a, "int q = 10;" + s, ""),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   113
                    interrupt,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   114
                    (a) -> assertCommand(a, "void f() {}\u0003", ""),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   115
                    (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   116
                    (a) -> assertMethod(a, "int f() { return 0; }", "()int", "f"),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   117
                    (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   118
                    (a) -> assertCommand(a, "class A {" + s, ""),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   119
                    interrupt,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   120
                    (a) -> assertCommand(a, "class A {}\u0003", ""),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37389
diff changeset
   121
                    (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   122
                    (a) -> assertClass(a, "interface A {}", "interface", "A"),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37389
diff changeset
   123
                    (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
33714
8064f484590e 8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents: 33362
diff changeset
   124
                    (a) -> assertCommand(a, "import java.util.stream." + s, ""),
8064f484590e 8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents: 33362
diff changeset
   125
                    interrupt,
8064f484590e 8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents: 33362
diff changeset
   126
                    (a) -> assertCommand(a, "import java.util.stream.\u0003", ""),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   127
                    (a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
33714
8064f484590e 8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents: 33362
diff changeset
   128
                    (a) -> assertImport(a, "import java.util.stream.Stream", "", "java.util.stream.Stream"),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   129
                    (a) -> assertCommandCheckOutput(a, "/imports", assertImports())
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   130
            );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   131
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   132
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   133
53215
299fe76c25c7 8215438: jshell tool: Ctrl-D causes EOF
jlahoda
parents: 52282
diff changeset
   134
    public void testCtrlD() {
299fe76c25c7 8215438: jshell tool: Ctrl-D causes EOF
jlahoda
parents: 52282
diff changeset
   135
        test(false, new String[]{"--no-startup"},
299fe76c25c7 8215438: jshell tool: Ctrl-D causes EOF
jlahoda
parents: 52282
diff changeset
   136
                a -> {
299fe76c25c7 8215438: jshell tool: Ctrl-D causes EOF
jlahoda
parents: 52282
diff changeset
   137
                    if (!a) {
299fe76c25c7 8215438: jshell tool: Ctrl-D causes EOF
jlahoda
parents: 52282
diff changeset
   138
                        closeCommandInput();
299fe76c25c7 8215438: jshell tool: Ctrl-D causes EOF
jlahoda
parents: 52282
diff changeset
   139
                    } else {
299fe76c25c7 8215438: jshell tool: Ctrl-D causes EOF
jlahoda
parents: 52282
diff changeset
   140
                        throw new IllegalStateException();
299fe76c25c7 8215438: jshell tool: Ctrl-D causes EOF
jlahoda
parents: 52282
diff changeset
   141
                    }
299fe76c25c7 8215438: jshell tool: Ctrl-D causes EOF
jlahoda
parents: 52282
diff changeset
   142
                }
299fe76c25c7 8215438: jshell tool: Ctrl-D causes EOF
jlahoda
parents: 52282
diff changeset
   143
        );
299fe76c25c7 8215438: jshell tool: Ctrl-D causes EOF
jlahoda
parents: 52282
diff changeset
   144
    }
299fe76c25c7 8215438: jshell tool: Ctrl-D causes EOF
jlahoda
parents: 52282
diff changeset
   145
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   146
    private final Object lock = new Object();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   147
    private PrintWriter out;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   148
    private boolean isStopped;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   149
    private Thread t;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   150
    private void assertStop(boolean after, String cmd, String output) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   151
        if (!after) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   152
            isStopped = false;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   153
            StringWriter writer = new StringWriter();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   154
            out = new PrintWriter(writer);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   155
            setCommandInput(cmd + "\n");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   156
            t = new Thread(() -> {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   157
                try {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   158
                    // no chance to know whether cmd is being evaluated
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   159
                    Thread.sleep(5000);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   160
                } catch (InterruptedException ignored) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   161
                }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   162
                int i = 1;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   163
                int n = 30;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   164
                synchronized (lock) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   165
                    do {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   166
                        setCommandInput("\u0003");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   167
                        if (!isStopped) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   168
                            out.println("Not stopped. Try again: " + i);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   169
                            try {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   170
                                lock.wait(1000);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   171
                            } catch (InterruptedException ignored) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   172
                            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   173
                        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   174
                    } while (i++ < n && !isStopped);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   175
                    if (!isStopped) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   176
                        System.err.println(writer.toString());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   177
                        fail("Evaluation was not stopped: '" + cmd + "'");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   178
                    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   179
                }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   180
            });
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   181
            t.start();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   182
        } else {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   183
            synchronized (lock)  {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   184
                out.println("Evaluation was stopped successfully: '" + cmd + "'");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   185
                isStopped = true;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   186
                lock.notify();
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
            try {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   189
                t.join();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   190
                t = null;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   191
            } catch (InterruptedException ignored) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   192
            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   193
            assertOutput(getCommandOutput(), "", "command");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   194
            assertOutput(getCommandErrorOutput(), "", "command error");
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   195
            assertOutput(getUserOutput().trim(), output, "user");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   196
            assertOutput(getUserErrorOutput(), "", "user error");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   197
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   198
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   199
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   200
    public void testStop() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   201
        test(
38613
2a8e50869b08 8157953: JShell tests: reenable ToolBasicTest
rfield
parents: 38531
diff changeset
   202
                (a) -> assertStop(a, "while (true) {}", ""),
2a8e50869b08 8157953: JShell tests: reenable ToolBasicTest
rfield
parents: 38531
diff changeset
   203
                (a) -> assertStop(a, "while (true) { try { Thread.sleep(100); } catch (InterruptedException ex) { } }", "")
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   204
        );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   205
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   206
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   207
    public void testRerun() {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 40516
diff changeset
   208
        test(false, new String[] {"--no-startup"},
48349
3d4e8f5a2a69 8179858: jshell tool: sync nomenclature from reference to online /help
rfield
parents: 47504
diff changeset
   209
                (a) -> assertCommand(a, "/0", "|  No snippet with ID: 0"),
3d4e8f5a2a69 8179858: jshell tool: sync nomenclature from reference to online /help
rfield
parents: 47504
diff changeset
   210
                (a) -> assertCommand(a, "/5", "|  No snippet with ID: 5")
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   211
        );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   212
        String[] codes = new String[] {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   213
                "int a = 0;", // var
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   214
                "class A {}", // class
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   215
                "void f() {}", // method
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   216
                "bool b;", // active failed
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   217
                "void g() { h(); }", // active corralled
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   218
        };
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   219
        List<ReplTest> tests = new ArrayList<>();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   220
        for (String s : codes) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   221
            tests.add((a) -> assertCommand(a, s, null));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   222
        }
38613
2a8e50869b08 8157953: JShell tests: reenable ToolBasicTest
rfield
parents: 38531
diff changeset
   223
        // Test /1 through /5 -- assure references are correct
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   224
        for (int i = 0; i < codes.length; ++i) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   225
            final int finalI = i;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   226
            Consumer<String> check = (s) -> {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   227
                String[] ss = s.split("\n");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   228
                assertEquals(ss[0], codes[finalI]);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   229
                assertTrue(ss.length > 1, s);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   230
            };
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   231
            tests.add((a) -> assertCommandCheckOutput(a, "/" + (finalI + 1), check));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   232
        }
38613
2a8e50869b08 8157953: JShell tests: reenable ToolBasicTest
rfield
parents: 38531
diff changeset
   233
        // Test /-1 ... note that the snippets added by history must be stepped over
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   234
        for (int i = 0; i < codes.length; ++i) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   235
            final int finalI = i;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   236
            Consumer<String> check = (s) -> {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   237
                String[] ss = s.split("\n");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   238
                assertEquals(ss[0], codes[codes.length - finalI - 1]);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   239
                assertTrue(ss.length > 1, s);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   240
            };
38613
2a8e50869b08 8157953: JShell tests: reenable ToolBasicTest
rfield
parents: 38531
diff changeset
   241
            tests.add((a) -> assertCommandCheckOutput(a, "/-" + (2 * finalI + 1), check));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   242
        }
38613
2a8e50869b08 8157953: JShell tests: reenable ToolBasicTest
rfield
parents: 38531
diff changeset
   243
        tests.add((a) -> assertCommandCheckOutput(a, "/!", assertStartsWith("int a = 0;")));
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 40516
diff changeset
   244
        test(false, new String[]{"--no-startup"},
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   245
                tests.toArray(new ReplTest[tests.size()]));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   246
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   247
34477
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   248
    public void test8142447() {
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   249
        Function<String, BiFunction<String, Integer, ReplTest>> assertRerun = cmd -> (code, assertionCount) ->
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   250
                (a) -> assertCommandCheckOutput(a, cmd, s -> {
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   251
                            String[] ss = s.split("\n");
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   252
                            assertEquals(ss[0], code);
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   253
                            loadVariable(a, "int", "assertionCount", Integer.toString(assertionCount), Integer.toString(assertionCount));
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   254
                        });
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   255
        ReplTest assertVariables = (a) -> assertCommandCheckOutput(a, "/v", assertVariables());
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   256
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   257
        Compiler compiler = new Compiler();
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   258
        Path startup = compiler.getPath("StartupFileOption/startup.txt");
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   259
        compiler.writeToFile(startup, "int assertionCount = 0;\n" + // id: s1
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   260
                "void add(int n) { assertionCount += n; }");
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 40516
diff changeset
   261
        test(new String[]{"--startup", startup.toString()},
34477
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   262
                (a) -> assertCommand(a, "add(1)", ""), // id: 1
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   263
                (a) -> assertCommandCheckOutput(a, "add(ONE)", s -> assertEquals(s.split("\n")[0], "|  Error:")), // id: e1
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   264
                (a) -> assertVariable(a, "int", "ONE", "1", "1"),
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   265
                assertRerun.apply("/1").apply("add(1)", 2), assertVariables,
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   266
                assertRerun.apply("/e1").apply("add(ONE)", 3), assertVariables,
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   267
                assertRerun.apply("/s1").apply("int assertionCount = 0;", 0), assertVariables
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   268
        );
64001b0533a2 8142447: JShell tool: Command change: re-run n-th command should be re-run by id
rfield
parents: 34475
diff changeset
   269
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 40516
diff changeset
   270
        test(false, new String[] {"--no-startup"},
48349
3d4e8f5a2a69 8179858: jshell tool: sync nomenclature from reference to online /help
rfield
parents: 47504
diff changeset
   271
                (a) -> assertCommand(a, "/s1", "|  No snippet with ID: s1"),
3d4e8f5a2a69 8179858: jshell tool: sync nomenclature from reference to online /help
rfield
parents: 47504
diff changeset
   272
                (a) -> assertCommand(a, "/1", "|  No snippet with ID: 1"),
3d4e8f5a2a69 8179858: jshell tool: sync nomenclature from reference to online /help
rfield
parents: 47504
diff changeset
   273
                (a) -> assertCommand(a, "/e1", "|  No snippet with ID: e1")
33714
8064f484590e 8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents: 33362
diff changeset
   274
        );
8064f484590e 8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents: 33362
diff changeset
   275
    }
8064f484590e 8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents: 33362
diff changeset
   276
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   277
    public void testClasspathDirectory() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   278
        Compiler compiler = new Compiler();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   279
        Path outDir = Paths.get("testClasspathDirectory");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   280
        compiler.compile(outDir, "package pkg; public class A { public String toString() { return \"A\"; } }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   281
        Path classpath = compiler.getPath(outDir);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   282
        test(
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   283
                (a) -> assertCommand(a, "/env --class-path " + classpath,
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   284
                        "|  Setting new options and restoring state."),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   285
                (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A")
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   286
        );
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 40516
diff changeset
   287
        test(new String[] { "--class-path", classpath.toString() },
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   288
                (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A")
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   289
        );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   290
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   291
44065
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   292
    public void testEnvInStartUp() {
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   293
        Compiler compiler = new Compiler();
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   294
        Path outDir = Paths.get("testClasspathDirectory");
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   295
        compiler.compile(outDir, "package pkg; public class A { public String toString() { return \"A\"; } }");
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   296
        Path classpath = compiler.getPath(outDir);
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   297
        Path sup = compiler.getPath("startup.jsh");
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   298
        compiler.writeToFile(sup,
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   299
                "int xxx;\n" +
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   300
                "/env -class-path " + classpath + "\n" +
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   301
                "int aaa = 735;\n"
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   302
        );
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   303
        test(
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   304
                (a) -> assertCommand(a, "/set start -retain " + sup, ""),
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   305
                (a) -> assertCommand(a, "/reset",
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   306
                        "|  Resetting state."),
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   307
                (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A"),
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   308
                (a) -> assertCommand(a, "aaa", "aaa ==> 735")
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   309
        );
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   310
        test(
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   311
                (a) -> assertCommandOutputContains(a, "/env", "--class-path"),
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   312
                (a) -> assertCommandOutputContains(a, "xxx", "cannot find symbol", "variable xxx"),
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   313
                (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A"),
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   314
                (a) -> assertCommand(a, "aaa", "aaa ==> 735")
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   315
        );
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   316
    }
d0a8a4c41c85 8175304: JShell tool: The /reset command hangs after setting a startup script
rfield
parents: 43856
diff changeset
   317
43856
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   318
    private String makeSimpleJar() {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   319
        Compiler compiler = new Compiler();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   320
        Path outDir = Paths.get("testClasspathJar");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   321
        compiler.compile(outDir, "package pkg; public class A { public String toString() { return \"A\"; } }");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   322
        String jarName = "test.jar";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   323
        compiler.jar(outDir, jarName, "pkg/A.class");
43856
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   324
        return compiler.getPath(outDir).resolve(jarName).toString();
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   325
    }
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   326
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   327
    public void testClasspathJar() {
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   328
        String jarPath = makeSimpleJar();
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   329
        test(
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   330
                (a) -> assertCommand(a, "/env --class-path " + jarPath,
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42972
diff changeset
   331
                        "|  Setting new options and restoring state."),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   332
                (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A")
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   333
        );
43856
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   334
        test(new String[] { "--class-path", jarPath },
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   335
                (a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A")
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   336
        );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   337
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   338
43856
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   339
    public void testClasspathUserHomeExpansion() {
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   340
        String jarPath = makeSimpleJar();
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   341
        String tilde = "~" + File.separator;
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   342
        test(
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   343
                (a) -> assertCommand(a, "/env --class-path " + tilde + "forblato",
45757
1017cd5d6506 8183021: JShell tests: Fix failing tests on Windows
jlahoda
parents: 45215
diff changeset
   344
                        "|  File '" + Paths.get(System.getProperty("user.home"), "forblato").toString()
1017cd5d6506 8183021: JShell tests: Fix failing tests on Windows
jlahoda
parents: 45215
diff changeset
   345
                                + "' for '--class-path' is not found."),
43856
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   346
                (a) -> assertCommand(a, "/env --class-path " + jarPath + File.pathSeparator
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   347
                                                            + tilde + "forblato",
45757
1017cd5d6506 8183021: JShell tests: Fix failing tests on Windows
jlahoda
parents: 45215
diff changeset
   348
                        "|  File '" + Paths.get(System.getProperty("user.home"), "forblato").toString()
1017cd5d6506 8183021: JShell tests: Fix failing tests on Windows
jlahoda
parents: 45215
diff changeset
   349
                                + "' for '--class-path' is not found.")
43856
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   350
        );
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   351
    }
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   352
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   353
    public void testBadClasspath() {
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   354
        String jarPath = makeSimpleJar();
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   355
        Compiler compiler = new Compiler();
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   356
        Path t1 = compiler.getPath("whatever/thing.zip");
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   357
        compiler.writeToFile(t1, "");
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   358
        Path t2 = compiler.getPath("whatever/thing.jmod");
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   359
        compiler.writeToFile(t2, "");
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   360
        test(
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   361
                (a) -> assertCommand(a, "/env --class-path " + t1.toString(),
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   362
                        "|  Invalid '--class-path' argument: " + t1.toString()),
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   363
                (a) -> assertCommand(a, "/env --class-path " + jarPath + File.pathSeparator + t1.toString(),
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   364
                        "|  Invalid '--class-path' argument: " + t1.toString()),
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   365
                (a) -> assertCommand(a, "/env --class-path " + t2.toString(),
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   366
                        "|  Invalid '--class-path' argument: " + t2.toString())
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   367
        );
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   368
    }
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   369
49092
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   370
    private String makeBadSourceJar() {
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   371
        Compiler compiler = new Compiler();
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   372
        Path outDir = Paths.get("testClasspathJar");
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   373
        Path src = compiler.getPath(outDir.resolve("pkg/A.java"));
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   374
        compiler.writeToFile(src, "package pkg; /** \u0086 */public class A { public String toString() { return \"A\"; } }");
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   375
        String jarName = "test.jar";
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   376
        compiler.jar(outDir, jarName, "pkg/A.java");
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   377
        return compiler.getPath(outDir).resolve(jarName).toString();
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   378
    }
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   379
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   380
    public void testBadSourceJarClasspath() {
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   381
        String jarPath = makeBadSourceJar();
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   382
        test(
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   383
                (a) -> assertCommand(a, "/env --class-path " + jarPath,
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   384
                        "|  Setting new options and restoring state."),
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   385
                (a) -> assertCommandOutputStartsWith(a, "new pkg.A();",
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   386
                        "|  Error:\n"
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   387
                        + "|  cannot find symbol\n"
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   388
                        + "|    symbol:   class A")
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   389
        );
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   390
        test(new String[]{"--class-path", jarPath},
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   391
                (a) -> assertCommandOutputStartsWith(a, "new pkg.A();",
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   392
                        "|  Error:\n"
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   393
                        + "|  cannot find symbol\n"
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   394
                        + "|    symbol:   class A")
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   395
        );
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   396
    }
6dc5e0cdb44c 8196133: JShell crashes when attempting to use bad source file in class path
rfield
parents: 48349
diff changeset
   397
41852
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   398
    public void testModulePath() {
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   399
        Compiler compiler = new Compiler();
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   400
        Path modsDir = Paths.get("mods");
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   401
        Path outDir = Paths.get("mods", "org.astro");
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   402
        compiler.compile(outDir, "package org.astro; public class World { public static String name() { return \"world\"; } }");
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   403
        compiler.compile(outDir, "module org.astro { exports org.astro; }");
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   404
        Path modsPath = compiler.getPath(modsDir);
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   405
        test(new String[] { "--module-path", modsPath.toString(), "--add-modules", "org.astro" },
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   406
                (a) -> assertCommand(a, "import org.astro.World;", ""),
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   407
                (a) -> evaluateExpression(a, "String",
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   408
                        "String.format(\"Greetings %s!\", World.name());",
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   409
                        "\"Greetings world!\"")
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   410
        );
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   411
    }
448273b190ad 8166649: jshell tool: missing --add-modules and --module-path
rfield
parents: 41635
diff changeset
   412
43856
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   413
    public void testModulePathUserHomeExpansion() {
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   414
        String tilde = "~" + File.separatorChar;
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   415
        test(
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   416
                (a) -> assertCommand(a, "/env --module-path " + tilde + "snardugol",
45757
1017cd5d6506 8183021: JShell tests: Fix failing tests on Windows
jlahoda
parents: 45215
diff changeset
   417
                        "|  File '" + Paths.get(System.getProperty("user.home"), "snardugol").toString()
1017cd5d6506 8183021: JShell tests: Fix failing tests on Windows
jlahoda
parents: 45215
diff changeset
   418
                                + "' for '--module-path' is not found.")
43856
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   419
        );
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   420
    }
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   421
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   422
    public void testBadModulePath() {
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   423
        Compiler compiler = new Compiler();
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   424
        Path t1 = compiler.getPath("whatever/thing.zip");
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   425
        compiler.writeToFile(t1, "");
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   426
        test(
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   427
                (a) -> assertCommand(a, "/env --module-path " + t1.toString(),
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   428
                        "|  Invalid '--module-path' argument: " + t1.toString())
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   429
        );
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   430
    }
fcdebb803c62 8174797: jshell tool: invalid module path crashes tool
rfield
parents: 43038
diff changeset
   431
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   432
    public void testStartupFileOption() {
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   433
        Compiler compiler = new Compiler();
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   434
        Path startup = compiler.getPath("StartupFileOption/startup.txt");
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   435
        compiler.writeToFile(startup, "class A { public String toString() { return \"A\"; } }");
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   436
        test(new String[]{"--startup", startup.toString()},
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   437
                (a) -> evaluateExpression(a, "A", "new A()", "A")
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   438
        );
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   439
        test(new String[]{"--no-startup"},
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42843
diff changeset
   440
                (a) -> assertCommandCheckOutput(a, "Pattern.compile(\"x+\")", assertStartsWith("|  Error:\n|  cannot find symbol"))
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   441
        );
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   442
        test(
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42843
diff changeset
   443
                (a) -> assertCommand(a, "Pattern.compile(\"x+\")", "$1 ==> x+", "", null, "", "")
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   444
        );
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   445
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   446
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   447
    public void testLoadingFromArgs() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   448
        Compiler compiler = new Compiler();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   449
        Path path = compiler.getPath("loading.repl");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   450
        compiler.writeToFile(path, "int a = 10; double x = 20; double a = 10;");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   451
        test(new String[] { path.toString() },
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   452
                (a) -> assertCommand(a, "x", "x ==> 20.0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   453
                (a) -> assertCommand(a, "a", "a ==> 10.0")
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   454
        );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   455
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   456
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   457
    public void testReset() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   458
        test(
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   459
                (a) -> assertReset(a, "/res"),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   460
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   461
                (a) -> assertVariable(a, "int", "x"),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   462
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   463
                (a) -> assertMethod(a, "void f() { }", "()void", "f"),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   464
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   465
                (a) -> assertClass(a, "class A { }", "class", "A"),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37389
diff changeset
   466
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
33714
8064f484590e 8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents: 33362
diff changeset
   467
                (a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   468
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports()),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   469
                (a) -> assertReset(a, "/reset"),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   470
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   471
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37389
diff changeset
   472
                (a) -> assertCommandCheckOutput(a, "/types", assertClasses()),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   473
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports())
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   474
        );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   475
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   476
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   477
    public void testOpen() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   478
        Compiler compiler = new Compiler();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   479
        Path path = compiler.getPath("testOpen.repl");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   480
        compiler.writeToFile(path,
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   481
                "int a = 10;\ndouble x = 20;\ndouble a = 10;\n" +
33714
8064f484590e 8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents: 33362
diff changeset
   482
                        "class A { public String toString() { return \"A\"; } }\nimport java.util.stream.*;");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   483
        for (String s : new String[]{"/o", "/open"}) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   484
            test(
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   485
                    (a) -> assertCommand(a, s + " " + path.toString(), ""),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   486
                    (a) -> assertCommand(a, "a", "a ==> 10.0"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   487
                    (a) -> evaluateExpression(a, "A", "new A();", "A"),
33714
8064f484590e 8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents: 33362
diff changeset
   488
                    (a) -> evaluateExpression(a, "long", "Stream.of(\"A\").count();", "1"),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   489
                    (a) -> {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   490
                        loadVariable(a, "double", "x", "20.0", "20.0");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   491
                        loadVariable(a, "double", "a", "10.0", "10.0");
33714
8064f484590e 8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents: 33362
diff changeset
   492
                        loadVariable(a, "A", "$7", "new A();", "A");
8064f484590e 8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents: 33362
diff changeset
   493
                        loadVariable(a, "long", "$8", "Stream.of(\"A\").count();", "1");
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   494
                        loadClass(a, "class A { public String toString() { return \"A\"; } }",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   495
                                "class", "A");
33714
8064f484590e 8142384: JShell tool: New command: /imports, /i which show the list of imported packages or classes, etc...
shinyafox
parents: 33362
diff changeset
   496
                        loadImport(a, "import java.util.stream.*;", "", "java.util.stream.*");
38514
f7df9ab653b0 8153920: jshell tool: allow a parameter on the /vars /methods /classes commands
rfield
parents: 37389
diff changeset
   497
                        assertCommandCheckOutput(a, "/types", assertClasses());
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   498
                    },
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   499
                    (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   500
                    (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   501
                    (a) -> assertCommandCheckOutput(a, "/imports", assertImports())
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   502
            );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   503
            Path unknown = compiler.getPath("UNKNOWN.repl");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   504
            test(
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   505
                    (a) -> assertCommand(a, s + " " + unknown,
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   506
                            "|  File '" + unknown + "' for '/open' is not found.")
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   507
            );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   508
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   509
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   510
50017
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   511
    public void testOpenLocalFileUrl() {
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   512
        Compiler compiler = new Compiler();
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   513
        Path path = compiler.getPath("testOpen.repl");
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   514
        compiler.writeToFile(path, "int a = 10;int b = 20;int c = a + b;\n");
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   515
        for (String s : new String[]{"/o", "/open"}) {
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   516
            test(
50043
2d1952d4d067 8202690: jdk/jshell/ToolBasicTest.java failed in testOpenFileOverHttp() and testOpenLocalFileUrl()
xyin
parents: 50019
diff changeset
   517
                    (a) -> assertCommand(a, s + " " + path.toUri(), ""),
50017
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   518
                    (a) -> assertCommand(a, "a", "a ==> 10"),
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   519
                    (a) -> assertCommand(a, "b", "b ==> 20"),
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   520
                    (a) -> assertCommand(a, "c", "c ==> 30")
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   521
            );
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   522
        }
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   523
    }
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   524
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   525
    public void testOpenFileOverHttp() throws IOException {
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   526
        var script = "int a = 10;int b = 20;int c = a + b;";
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   527
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   528
        var localhostAddress = new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), 0);
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   529
        var httpServer = HttpServer.create(localhostAddress, 0);
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   530
        try {
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   531
            httpServer.createContext("/script", exchange -> {
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   532
                exchange.sendResponseHeaders(200, script.length());
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   533
                try (var output = exchange.getResponseBody()) {
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   534
                    output.write(script.getBytes());
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   535
                }
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   536
            });
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   537
            httpServer.setExecutor(null);
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   538
            httpServer.start();
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   539
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   540
            var urlAddress = "http:/" + httpServer.getAddress().toString() + "/script";
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   541
            for (String s : new String[]{"/o", "/open"}) {
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   542
                test(
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   543
                        (a) -> assertCommand(a, s + " " + urlAddress, ""),
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   544
                        (a) -> assertCommand(a, "a", "a ==> 10"),
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   545
                        (a) -> assertCommand(a, "b", "b ==> 20"),
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   546
                        (a) -> assertCommand(a, "c", "c ==> 30")
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   547
                );
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   548
            }
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   549
        } finally {
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   550
            httpServer.stop(0);
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   551
        }
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   552
    }
88cc95780b6e 8199912: jshell tool: /open from URI
rfield
parents: 49101
diff changeset
   553
42972
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42843
diff changeset
   554
    public void testOpenResource() {
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42843
diff changeset
   555
        test(
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42843
diff changeset
   556
                (a) -> assertCommand(a, "/open PRINTING", ""),
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42843
diff changeset
   557
                (a) -> assertCommandOutputContains(a, "/list",
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42843
diff changeset
   558
                        "void println", "System.out.printf"),
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42843
diff changeset
   559
                (a) -> assertCommand(a, "printf(\"%4.2f\", Math.PI)",
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42843
diff changeset
   560
                        "", "", null, "3.14", "")
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42843
diff changeset
   561
        );
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42843
diff changeset
   562
    }
47ca49eee534 8172102: jshell tool: remove print method forwarding to System.out from default startup
rfield
parents: 42843
diff changeset
   563
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   564
    public void testSave() throws IOException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   565
        Compiler compiler = new Compiler();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   566
        Path path = compiler.getPath("testSave.repl");
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   567
        {
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   568
            List<String> list = Arrays.asList(
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   569
                    "int a;",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   570
                    "class A { public String toString() { return \"A\"; } }"
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   571
            );
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   572
            test(
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   573
                    (a) -> assertVariable(a, "int", "a"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   574
                    (a) -> assertCommand(a, "()", null, null, null, "", ""),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   575
                    (a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   576
                    (a) -> assertCommand(a, "/save " + path.toString(), "")
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   577
            );
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   578
            assertEquals(Files.readAllLines(path), list);
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   579
        }
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   580
        {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   581
            List<String> output = new ArrayList<>();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   582
            test(
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   583
                    (a) -> assertCommand(a, "int a;", null),
34570
8a8f52a733dd 8144095: jshell tool: normalize command parameter handling
rfield
parents: 34481
diff changeset
   584
                    (a) -> assertCommand(a, "()", null, null, null, "", ""),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   585
                    (a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   586
                    (a) -> assertCommandCheckOutput(a, "/list -all", (out) ->
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   587
                                    output.addAll(Stream.of(out.split("\n"))
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   588
                            .filter(str -> !str.isEmpty())
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   589
                            .map(str -> str.substring(str.indexOf(':') + 2))
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   590
                            .filter(str -> !str.startsWith("/"))
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   591
                            .collect(Collectors.toList()))),
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   592
                    (a) -> assertCommand(a, "/save -all " + path.toString(), "")
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   593
            );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   594
            assertEquals(Files.readAllLines(path), output);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   595
        }
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   596
        {
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   597
            List<String> output = new ArrayList<>();
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   598
            test(
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   599
                    (a) -> assertCommand(a, "int a;", null),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   600
                    (a) -> assertCommand(a, "int b;", null),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   601
                    (a) -> assertCommand(a, "int c;", null),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   602
                    (a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   603
                    (a) -> assertCommandCheckOutput(a, "/list b c a A", (out) ->
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   604
                                    output.addAll(Stream.of(out.split("\n"))
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   605
                            .filter(str -> !str.isEmpty())
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   606
                            .map(str -> str.substring(str.indexOf(':') + 2))
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   607
                            .filter(str -> !str.startsWith("/"))
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   608
                            .collect(Collectors.toList()))),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   609
                    (a) -> assertCommand(a, "/save 2-3 1 4 " + path.toString(), "")
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   610
            );
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   611
            assertEquals(Files.readAllLines(path), output);
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   612
        }
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   613
        {
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   614
            List<String> output = new ArrayList<>();
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   615
            test(
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   616
                    (a) -> assertVariable(a, "int", "a"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   617
                    (a) -> assertCommand(a, "()", null, null, null, "", ""),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   618
                    (a) -> assertClass(a, "class A { public String toString() { return \"A\"; } }", "class", "A"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   619
                    (a) -> assertCommandCheckOutput(a, "/history", (out) ->
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   620
                                output.addAll(Stream.of(out.split("\n"))
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   621
                            .filter(str -> !str.isEmpty())
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   622
                            .collect(Collectors.toList()))),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   623
                    (a) -> assertCommand(a, "/save -history " + path.toString(), "")
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   624
            );
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   625
            output.add("/save -history " + path.toString());
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   626
            assertEquals(Files.readAllLines(path), output);
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   627
        }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   628
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   629
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   630
    public void testStartRetain() {
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   631
        Compiler compiler = new Compiler();
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   632
        Path startUpFile = compiler.getPath("startUp.txt");
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   633
        test(
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   634
                (a) -> assertVariable(a, "int", "a"),
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   635
                (a) -> assertVariable(a, "double", "b", "10", "10.0"),
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   636
                (a) -> assertMethod(a, "void f() {}", "()V", "f"),
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   637
                (a) -> assertImport(a, "import java.util.stream.*;", "", "java.util.stream.*"),
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   638
                (a) -> assertCommand(a, "/save " + startUpFile.toString(), null),
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   639
                (a) -> assertCommand(a, "/set start -retain " + startUpFile.toString(), null)
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   640
        );
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   641
        Path unknown = compiler.getPath("UNKNOWN");
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   642
        test(
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   643
                (a) -> assertCommandOutputStartsWith(a, "/set start -retain " + unknown.toString(),
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   644
                        "|  File '" + unknown + "' for '/set start' is not found.")
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   645
        );
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   646
        test(false, new String[0],
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   647
                (a) -> {
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   648
                    loadVariable(a, "int", "a");
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   649
                    loadVariable(a, "double", "b", "10.0", "10.0");
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   650
                    loadMethod(a, "void f() {}", "()void", "f");
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   651
                    loadImport(a, "import java.util.stream.*;", "", "java.util.stream.*");
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   652
                    assertCommandCheckOutput(a, "/types", assertClasses());
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   653
                },
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   654
                (a) -> assertCommandCheckOutput(a, "/vars", assertVariables()),
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   655
                (a) -> assertCommandCheckOutput(a, "/methods", assertMethods()),
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   656
                (a) -> assertCommandCheckOutput(a, "/imports", assertImports())
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 41858
diff changeset
   657
        );
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   658
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   659
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   660
    public void testStartSave() throws IOException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   661
        Compiler compiler = new Compiler();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   662
        Path startSave = compiler.getPath("startSave.txt");
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   663
        test(a -> assertCommand(a, "/save -start " + startSave.toString(), null));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   664
        List<String> lines = Files.lines(startSave)
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   665
                .filter(s -> !s.isEmpty())
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   666
                .collect(Collectors.toList());
34570
8a8f52a733dd 8144095: jshell tool: normalize command parameter handling
rfield
parents: 34481
diff changeset
   667
        assertEquals(lines, START_UP);
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   668
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   669
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   670
    public void testConstrainedUpdates() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   671
        test(
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   672
                a -> assertClass(a, "class XYZZY { }", "class", "XYZZY"),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   673
                a -> assertVariable(a, "XYZZY", "xyzzy"),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   674
                a -> assertCommandCheckOutput(a, "import java.util.stream.*",
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   675
                        (out) -> assertTrue(out.trim().isEmpty(), "Expected no output, got: " + out))
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   676
        );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   677
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   678
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   679
    public void testRemoteExit() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   680
        test(
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   681
                a -> assertVariable(a, "int", "x"),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   682
                a -> assertCommandCheckOutput(a, "/vars", assertVariables()),
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents: 35812
diff changeset
   683
                a -> assertCommandOutputContains(a, "System.exit(5);", "terminated"),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   684
                a -> assertCommandCheckOutput(a, "/vars", s ->
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   685
                        assertTrue(s.trim().isEmpty(), s)),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   686
                a -> assertMethod(a, "void f() { }", "()void", "f"),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   687
                a -> assertCommandCheckOutput(a, "/methods", assertMethods())
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   688
        );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   689
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   690
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   691
    public void testFeedbackNegative() {
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents: 35812
diff changeset
   692
        test(a -> assertCommandCheckOutput(a, "/set feedback aaaa",
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents: 35812
diff changeset
   693
                assertStartsWith("|  Does not match any current feedback mode")));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   694
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   695
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   696
    public void testFeedbackSilent() {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   697
        for (String off : new String[]{"s", "silent"}) {
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   698
            test(
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents: 35812
diff changeset
   699
                    a -> assertCommand(a, "/set feedback " + off, ""),
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   700
                    a -> assertCommand(a, "int a", ""),
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   701
                    a -> assertCommand(a, "void f() {}", ""),
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   702
                    a -> assertCommandCheckOutput(a, "aaaa", assertStartsWith("|  Error:")),
41858
5843b57ce3a6 8167643: JShell: silently ignore access modifiers (as semantically irrelevant)
rfield
parents: 41852
diff changeset
   703
                    a -> assertCommandCheckOutput(a, "static void f() {}", assertStartsWith("|  Warning:"))
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   704
            );
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   705
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   706
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   707
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   708
    public void testFeedbackNormal() {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   709
        Compiler compiler = new Compiler();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   710
        Path testNormalFile = compiler.getPath("testConciseNormal");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   711
        String[] sources = new String[] {"int a", "void f() {}", "class A {}", "a = 10"};
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   712
        String[] sources2 = new String[] {"int a //again", "void f() {int y = 4;}", "class A {} //again", "a = 10"};
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   713
        String[] output = new String[] {
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   714
                "a ==> 0",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   715
                "|  created method f()",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   716
                "|  created class A",
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   717
                "a ==> 10"
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   718
        };
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   719
        compiler.writeToFile(testNormalFile, sources2);
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   720
        for (String feedback : new String[]{"/set fe", "/set feedback"}) {
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   721
            for (String feedbackState : new String[]{"n", "normal"}) {
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   722
                test(
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   723
                        a -> assertCommand(a, feedback + " " + feedbackState, "|  Feedback mode: normal"),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   724
                        a -> assertCommand(a, sources[0], output[0]),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   725
                        a -> assertCommand(a, sources[1], output[1]),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   726
                        a -> assertCommand(a, sources[2], output[2]),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   727
                        a -> assertCommand(a, sources[3], output[3]),
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents: 35812
diff changeset
   728
                        a -> assertCommand(a, "/o " + testNormalFile.toString(), "")
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   729
                );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   730
            }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   731
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   732
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   733
40516
9e0e107c39dd 8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents: 38836
diff changeset
   734
    public void testVarsWithNotActive() {
9e0e107c39dd 8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents: 38836
diff changeset
   735
        test(
9e0e107c39dd 8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents: 38836
diff changeset
   736
                a -> assertVariable(a, "Blath", "x"),
9e0e107c39dd 8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents: 38836
diff changeset
   737
                a -> assertCommandOutputContains(a, "/var -all", "(not-active)")
9e0e107c39dd 8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents: 38836
diff changeset
   738
        );
9e0e107c39dd 8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents: 38836
diff changeset
   739
    }
9e0e107c39dd 8154374: JShell: setContextClassLoader() for remote Snippet class loader
rfield
parents: 38836
diff changeset
   740
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   741
    public void testHistoryReference() {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 40516
diff changeset
   742
        test(false, new String[]{"--no-startup"},
48939
ba545e52b932 8166232: jshell tool: cannot access previous history
rfield
parents: 48349
diff changeset
   743
                a -> assertCommand(a, "System.err.println(99)", "", "", null, "", "99\n"),
ba545e52b932 8166232: jshell tool: cannot access previous history
rfield
parents: 48349
diff changeset
   744
                a -> assertCommand(a, "/exit", "")
ba545e52b932 8166232: jshell tool: cannot access previous history
rfield
parents: 48349
diff changeset
   745
        );
ba545e52b932 8166232: jshell tool: cannot access previous history
rfield
parents: 48349
diff changeset
   746
        test(false, new String[]{"--no-startup"},
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   747
                a -> assertCommand(a, "System.err.println(1)", "", "", null, "", "1\n"),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   748
                a -> assertCommand(a, "System.err.println(2)", "", "", null, "", "2\n"),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   749
                a -> assertCommand(a, "/-2", "System.err.println(1)", "", null, "", "1\n"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   750
                a -> assertCommand(a, "/history",
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   751
                                                    "/debug 0\n" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   752
                                                    "System.err.println(1)\n" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   753
                                                    "System.err.println(2)\n" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   754
                                                    "System.err.println(1)\n" +
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   755
                                                    "/history\n"),
48939
ba545e52b932 8166232: jshell tool: cannot access previous history
rfield
parents: 48349
diff changeset
   756
                a -> assertCommand(a, "/history -all",
ba545e52b932 8166232: jshell tool: cannot access previous history
rfield
parents: 48349
diff changeset
   757
                                                    "/debug 0\n" +
ba545e52b932 8166232: jshell tool: cannot access previous history
rfield
parents: 48349
diff changeset
   758
                                                    "System.err.println(99)\n" +
ba545e52b932 8166232: jshell tool: cannot access previous history
rfield
parents: 48349
diff changeset
   759
                                                    "/exit\n" +
ba545e52b932 8166232: jshell tool: cannot access previous history
rfield
parents: 48349
diff changeset
   760
                                                    "/debug 0\n" +
ba545e52b932 8166232: jshell tool: cannot access previous history
rfield
parents: 48349
diff changeset
   761
                                                    "System.err.println(1)\n" +
ba545e52b932 8166232: jshell tool: cannot access previous history
rfield
parents: 48349
diff changeset
   762
                                                    "System.err.println(2)\n" +
ba545e52b932 8166232: jshell tool: cannot access previous history
rfield
parents: 48349
diff changeset
   763
                                                    "System.err.println(1)\n" +
ba545e52b932 8166232: jshell tool: cannot access previous history
rfield
parents: 48349
diff changeset
   764
                                                    "/history\n" +
ba545e52b932 8166232: jshell tool: cannot access previous history
rfield
parents: 48349
diff changeset
   765
                                                    "/history -all\n"),
37389
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   766
                a -> assertCommand(a, "/-2", "System.err.println(2)", "", null, "", "2\n"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   767
                a -> assertCommand(a, "/!", "System.err.println(2)", "", null, "", "2\n"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   768
                a -> assertCommand(a, "/2", "System.err.println(2)", "", null, "", "2\n"),
9c137b83a8b8 8143955: JShell tool (UX): Output structure
rfield
parents: 37007
diff changeset
   769
                a -> assertCommand(a, "/1", "System.err.println(1)", "", null, "", "1\n")
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   770
        );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   771
    }
34475
7af94fd75ede 8143037: JShell should determine commands by prefix
jlahoda
parents: 33918
diff changeset
   772
45215
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   773
    public void testRerunIdRange() {
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   774
        Compiler compiler = new Compiler();
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   775
        Path startup = compiler.getPath("rangeStartup");
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   776
        String[] startupSources = new String[] {
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   777
            "boolean go = false",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   778
            "void println(String s) { if (go) System.out.println(s); }",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   779
            "void println(int i) { if (go) System.out.println(i); }",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   780
            "println(\"s4\")",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   781
            "println(\"s5\")",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   782
            "println(\"s6\")"
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   783
        };
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   784
        String[] sources = new String[] {
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   785
            "frog",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   786
            "go = true",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   787
            "println(2)",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   788
            "println(3)",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   789
            "println(4)",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   790
            "querty"
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   791
        };
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   792
        compiler.writeToFile(startup, startupSources);
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   793
        test(false, new String[]{"--startup", startup.toString()},
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   794
                a -> assertCommandOutputStartsWith(a, sources[0], "|  Error:"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   795
                a -> assertCommand(a, sources[1], "go ==> true", "", null, "", ""),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   796
                a -> assertCommand(a, sources[2], "", "", null, "2\n", ""),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   797
                a -> assertCommand(a, sources[3], "", "", null, "3\n", ""),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   798
                a -> assertCommand(a, sources[4], "", "", null, "4\n", ""),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   799
                a -> assertCommandOutputStartsWith(a, sources[5], "|  Error:"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   800
                a -> assertCommand(a, "/3", "println(3)", "", null, "3\n", ""),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   801
                a -> assertCommand(a, "/s4", "println(\"s4\")", "", null, "s4\n", ""),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   802
                a -> assertCommandOutputStartsWith(a, "/e1", "frog\n|  Error:"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   803
                a -> assertCommand(a, "/2-4",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   804
                        "println(2)\nprintln(3)\nprintln(4)",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   805
                        "", null, "2\n3\n4\n", ""),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   806
                a -> assertCommand(a, "/s4-s6",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   807
                        startupSources[3] + "\n" +startupSources[4] + "\n" +startupSources[5],
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   808
                        "", null, "s4\ns5\ns6\n", ""),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   809
                a -> assertCommand(a, "/s4-4", null,
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   810
                        "", null, "s4\ns5\ns6\n2\n3\n4\n", ""),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   811
                a -> assertCommandCheckOutput(a, "/e1-e2",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   812
                        s -> {
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   813
                            assertTrue(s.trim().startsWith("frog\n|  Error:"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   814
                                    "Output: \'" + s + "' does not start with: " + "|  Error:");
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   815
                            assertTrue(s.trim().lastIndexOf("|  Error:") > 10,
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   816
                                    "Output: \'" + s + "' does not have second: " + "|  Error:");
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   817
                        }),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   818
                a -> assertCommand(a, "/4  s4 2",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   819
                        "println(4)\nprintln(\"s4\")\nprintln(2)",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   820
                        "", null, "4\ns4\n2\n", ""),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   821
                a -> assertCommand(a, "/s5 2-4 3",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   822
                        "println(\"s5\")\nprintln(2)\nprintln(3)\nprintln(4)\nprintln(3)",
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   823
                        "", null, "s5\n2\n3\n4\n3\n", ""),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   824
                a -> assertCommand(a, "/2 ff", "|  No such snippet: ff"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   825
                a -> assertCommand(a, "/4-2", "|  End of snippet range less than start: 4 - 2"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   826
                a -> assertCommand(a, "/s5-s3", "|  End of snippet range less than start: s5 - s3"),
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   827
                a -> assertCommand(a, "/4-s5", "|  End of snippet range less than start: 4 - s5")
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   828
        );
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   829
    }
c9477e22877f 8167554: jshell tool: re-execute a range and/or sequence of snippets
rfield
parents: 44065
diff changeset
   830
38836
b09d1cfbf28c 8131029: JShell: recover from VMConnection launch failure
rfield
parents: 38613
diff changeset
   831
    @Test(enabled = false) // TODO 8158197
38531
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   832
    public void testHeadlessEditPad() {
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   833
        String prevHeadless = System.getProperty("java.awt.headless");
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   834
        try {
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   835
            System.setProperty("java.awt.headless", "true");
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   836
            test(
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   837
                (a) -> assertCommandOutputStartsWith(a, "/edit printf", "|  Cannot launch editor -- unexpected exception:")
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   838
            );
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   839
        } finally {
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   840
            System.setProperty("java.awt.headless", prevHeadless==null? "false" : prevHeadless);
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   841
        }
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   842
    }
c449daa25b45 8157200: jshell tool: Add /retain command to persist settings
rfield
parents: 38520
diff changeset
   843
41248
2a3e74c5ad8a 8154714: jshell tool: add exports support
shinyafox
parents: 40588
diff changeset
   844
    public void testAddExports() {
2a3e74c5ad8a 8154714: jshell tool: add exports support
shinyafox
parents: 40588
diff changeset
   845
        test(false, new String[]{"--no-startup"},
2a3e74c5ad8a 8154714: jshell tool: add exports support
shinyafox
parents: 40588
diff changeset
   846
                a -> assertCommandOutputStartsWith(a, "import jdk.internal.misc.VM;", "|  Error:")
2a3e74c5ad8a 8154714: jshell tool: add exports support
shinyafox
parents: 40588
diff changeset
   847
        );
2a3e74c5ad8a 8154714: jshell tool: add exports support
shinyafox
parents: 40588
diff changeset
   848
        test(false, new String[]{"--no-startup",
52282
003c062e16ea 8211694: JShell: Redeclared variable should be reset
rfield
parents: 50043
diff changeset
   849
                        "-R--add-exports", "-Rjava.base/jdk.internal.misc=ALL-UNNAMED",
003c062e16ea 8211694: JShell: Redeclared variable should be reset
rfield
parents: 50043
diff changeset
   850
                        "-C--add-exports", "-Cjava.base/jdk.internal.misc=ALL-UNNAMED"},
41248
2a3e74c5ad8a 8154714: jshell tool: add exports support
shinyafox
parents: 40588
diff changeset
   851
                a -> assertImport(a, "import jdk.internal.misc.VM;", "", "jdk.internal.misc.VM"),
2a3e74c5ad8a 8154714: jshell tool: add exports support
shinyafox
parents: 40588
diff changeset
   852
                a -> assertCommand(a, "System.err.println(VM.isBooted())", "", "", null, "", "true\n")
2a3e74c5ad8a 8154714: jshell tool: add exports support
shinyafox
parents: 40588
diff changeset
   853
        );
2a3e74c5ad8a 8154714: jshell tool: add exports support
shinyafox
parents: 40588
diff changeset
   854
        test(false, new String[]{"--no-startup", "--add-exports", "java.base/jdk.internal.misc"},
2a3e74c5ad8a 8154714: jshell tool: add exports support
shinyafox
parents: 40588
diff changeset
   855
                a -> assertImport(a, "import jdk.internal.misc.VM;", "", "jdk.internal.misc.VM"),
2a3e74c5ad8a 8154714: jshell tool: add exports support
shinyafox
parents: 40588
diff changeset
   856
                a -> assertCommand(a, "System.err.println(VM.isBooted())", "", "", null, "", "true\n")
2a3e74c5ad8a 8154714: jshell tool: add exports support
shinyafox
parents: 40588
diff changeset
   857
        );
2a3e74c5ad8a 8154714: jshell tool: add exports support
shinyafox
parents: 40588
diff changeset
   858
    }
2a3e74c5ad8a 8154714: jshell tool: add exports support
shinyafox
parents: 40588
diff changeset
   859
52282
003c062e16ea 8211694: JShell: Redeclared variable should be reset
rfield
parents: 50043
diff changeset
   860
    public void testRedeclareVariableNoInit() {
003c062e16ea 8211694: JShell: Redeclared variable should be reset
rfield
parents: 50043
diff changeset
   861
        test(
003c062e16ea 8211694: JShell: Redeclared variable should be reset
rfield
parents: 50043
diff changeset
   862
                a -> assertCommand(a, "Integer a;", "a ==> null"),
003c062e16ea 8211694: JShell: Redeclared variable should be reset
rfield
parents: 50043
diff changeset
   863
                a -> assertCommand(a, "a instanceof Integer;", "$2 ==> false"),
003c062e16ea 8211694: JShell: Redeclared variable should be reset
rfield
parents: 50043
diff changeset
   864
                a -> assertCommand(a, "a = 1;", "a ==> 1"),
003c062e16ea 8211694: JShell: Redeclared variable should be reset
rfield
parents: 50043
diff changeset
   865
                a -> assertCommand(a, "Integer a;", "a ==> null"),
003c062e16ea 8211694: JShell: Redeclared variable should be reset
rfield
parents: 50043
diff changeset
   866
                a -> assertCommand(a, "a instanceof Integer;", "$5 ==> false"),
003c062e16ea 8211694: JShell: Redeclared variable should be reset
rfield
parents: 50043
diff changeset
   867
                a -> assertCommand(a, "a", "a ==> null")
003c062e16ea 8211694: JShell: Redeclared variable should be reset
rfield
parents: 50043
diff changeset
   868
        );
003c062e16ea 8211694: JShell: Redeclared variable should be reset
rfield
parents: 50043
diff changeset
   869
     }
003c062e16ea 8211694: JShell: Redeclared variable should be reset
rfield
parents: 50043
diff changeset
   870
55143
905b2a416250 8223688: JShell: crash on the instantiation of raw anonymous class
rfield
parents: 53215
diff changeset
   871
    public void testWarningUnchecked() { //8223688
905b2a416250 8223688: JShell: crash on the instantiation of raw anonymous class
rfield
parents: 53215
diff changeset
   872
        test(false, new String[]{"--no-startup"},
905b2a416250 8223688: JShell: crash on the instantiation of raw anonymous class
rfield
parents: 53215
diff changeset
   873
                a -> assertCommand(a, "abstract class A<T> { A(T t){} }", "|  created class A"),
905b2a416250 8223688: JShell: crash on the instantiation of raw anonymous class
rfield
parents: 53215
diff changeset
   874
                a -> assertCommandCheckOutput(a, "new A(\"\") {}", s -> {
905b2a416250 8223688: JShell: crash on the instantiation of raw anonymous class
rfield
parents: 53215
diff changeset
   875
                            assertStartsWith("|  Warning:");
905b2a416250 8223688: JShell: crash on the instantiation of raw anonymous class
rfield
parents: 53215
diff changeset
   876
                            assertTrue(s.contains("unchecked call"));
905b2a416250 8223688: JShell: crash on the instantiation of raw anonymous class
rfield
parents: 53215
diff changeset
   877
                            assertFalse(s.contains("Exception"));
905b2a416250 8223688: JShell: crash on the instantiation of raw anonymous class
rfield
parents: 53215
diff changeset
   878
                        })
905b2a416250 8223688: JShell: crash on the instantiation of raw anonymous class
rfield
parents: 53215
diff changeset
   879
        );
905b2a416250 8223688: JShell: crash on the instantiation of raw anonymous class
rfield
parents: 53215
diff changeset
   880
    }
905b2a416250 8223688: JShell: crash on the instantiation of raw anonymous class
rfield
parents: 53215
diff changeset
   881
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   882
}