langtools/test/jdk/jshell/CommandCompletionTest.java
author rfield
Wed, 29 Mar 2017 16:07:30 -0700
changeset 44454 74af976d6798
parent 43038 7b8b8750a78e
child 44569 b1accf8b2aed
permissions -rw-r--r--
8177079: jshell tool: usability of /help for commands and sub-commands 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
/*
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents: 35359
diff changeset
     2
 * Copyright (c) 2015, 2016, 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
44454
74af976d6798 8177079: jshell tool: usability of /help for commands and sub-commands
rfield
parents: 43038
diff changeset
    26
 * @bug 8144095 8164825 8169818 8153402 8165405 8177079
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    27
 * @summary Test Command Completion
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 34570
diff changeset
    28
 * @modules jdk.compiler/com.sun.tools.javac.api
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 34570
diff changeset
    29
 *          jdk.compiler/com.sun.tools.javac.main
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36494
diff changeset
    30
 *          jdk.jdeps/com.sun.tools.javap
35359
f04501964016 8148147: Sync up @modules from jigsaw/jake
alanb
parents: 34570
diff changeset
    31
 *          jdk.jshell/jdk.internal.jshell.tool
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    32
 * @library /tools/lib
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    33
 * @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36526
diff changeset
    34
 * @build ReplToolTesting TestingInputStream Compiler
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    35
 * @run testng CommandCompletionTest
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    36
 */
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
import java.io.IOException;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    39
import java.nio.file.FileSystems;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    40
import java.nio.file.Files;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    41
import java.nio.file.Path;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    42
import java.nio.file.Paths;
40765
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
    43
import java.util.Arrays;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    44
import java.util.Collections;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    45
import java.util.List;
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    46
import java.util.Locale;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    47
import java.util.function.Predicate;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    48
import java.util.stream.Collectors;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    49
import java.util.stream.Stream;
42415
85388bae723d 8165564: langtools\test\jdk\jshell\CommandCompletionTest.java fails on some windows
jlahoda
parents: 42265
diff changeset
    50
import java.util.stream.StreamSupport;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    51
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    52
import org.testng.annotations.Test;
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    53
import jdk.internal.jshell.tool.JShellTool;
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    54
import jdk.internal.jshell.tool.JShellToolBuilder;
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    55
import jdk.jshell.SourceCodeAnalysis.Suggestion;
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    56
import static org.testng.Assert.assertEquals;
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    57
import static org.testng.Assert.assertTrue;
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    58
import static org.testng.Assert.fail;
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    59
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    60
public class CommandCompletionTest extends ReplToolTesting {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
    61
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    62
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    63
    private JShellTool repl;
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    64
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    65
    @Override
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    66
    protected void testRawRun(Locale locale, String[] args) {
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    67
        repl = ((JShellToolBuilder) builder(locale))
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    68
                .rawTool();
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    69
        try {
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    70
            repl.start(args);
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    71
        } catch (Exception ex) {
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    72
            fail("Repl tool died with exception", ex);
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    73
        }
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    74
    }
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    75
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    76
    public void assertCompletion(boolean after, String code, boolean isSmart, String... expected) {
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    77
        if (!after) {
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    78
            setCommandInput("\n");
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    79
        } else {
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    80
            assertCompletion(code, isSmart, expected);
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    81
        }
33362
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
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    84
    public void assertCompletion(String code, boolean isSmart, String... expected) {
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    85
        List<String> completions = computeCompletions(code, isSmart);
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    86
        assertEquals(completions, Arrays.asList(expected), "Command: " + code + ", output: " +
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    87
                completions.toString());
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    88
    }
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    89
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    90
    private List<String> computeCompletions(String code, boolean isSmart) {
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    91
        int cursor =  code.indexOf('|');
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    92
        code = code.replace("|", "");
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    93
        assertTrue(cursor > -1, "'|' not found: " + code);
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    94
        List<Suggestion> completions =
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    95
                repl.commandCompletionSuggestions(code, cursor, new int[] {-1}); //XXX: ignoring anchor for now
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    96
        return completions.stream()
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    97
                          .filter(s -> isSmart == s.matchesType())
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    98
                          .map(s -> s.continuation())
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
    99
                          .distinct()
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   100
                          .collect(Collectors.toList());
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   101
    }
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   102
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   103
    @Test
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   104
    public void testCommand() {
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   105
        testNoStartUp(
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   106
                a -> assertCompletion(a, "/deb|", false),
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   107
                a -> assertCompletion(a, "/re|", false, "/reload ", "/reset "),
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   108
                a -> assertCompletion(a, "/h|", false, "/help ", "/history ")
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   109
        );
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   110
    }
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   111
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   112
    @Test
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   113
    public void testList() {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38531
diff changeset
   114
        test(false, new String[] {"--no-startup"},
34570
8a8f52a733dd 8144095: jshell tool: normalize command parameter handling
rfield
parents: 34475
diff changeset
   115
                a -> assertCompletion(a, "/l|", false, "/list "),
42265
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   116
                a -> assertCompletion(a, "/list |", false, "-all", "-history", "-start "),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   117
                a -> assertCompletion(a, "/list -h|", false, "-history"),
34570
8a8f52a733dd 8144095: jshell tool: normalize command parameter handling
rfield
parents: 34475
diff changeset
   118
                a -> assertCompletion(a, "/list q|", false),
8a8f52a733dd 8144095: jshell tool: normalize command parameter handling
rfield
parents: 34475
diff changeset
   119
                a -> assertVariable(a, "int", "xray"),
42265
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   120
                a -> assertCompletion(a, "/list |", false, "-all", "-history", "-start ", "1 ", "xray "),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   121
                a -> assertCompletion(a, "/list x|", false, "xray "),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   122
                a -> assertCompletion(a, "/list xray |", false)
34570
8a8f52a733dd 8144095: jshell tool: normalize command parameter handling
rfield
parents: 34475
diff changeset
   123
        );
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   124
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   125
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   126
    @Test
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   127
    public void testDrop() {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38531
diff changeset
   128
        test(false, new String[] {"--no-startup"},
34570
8a8f52a733dd 8144095: jshell tool: normalize command parameter handling
rfield
parents: 34475
diff changeset
   129
                a -> assertCompletion(a, "/d|", false, "/drop "),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   130
                a -> assertClass(a, "class cTest {}", "class", "cTest"),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   131
                a -> assertMethod(a, "int mTest() { return 0; }", "()I", "mTest"),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   132
                a -> assertVariable(a, "int", "fTest"),
42265
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   133
                a -> assertCompletion(a, "/drop |", false, "1 ", "2 ", "3 ", "cTest ", "fTest ", "mTest "),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   134
                a -> assertCompletion(a, "/drop f|", false, "fTest ")
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   135
        );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   136
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   137
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   138
    @Test
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   139
    public void testEdit() {
40588
b5c32bfa9710 8160089: jshell tool: use new double-dash long-form command-line options
rfield
parents: 38531
diff changeset
   140
        test(false, new String[]{"--no-startup"},
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   141
                a -> assertCompletion(a, "/e|", false, "/edit ", "/env ", "/exit "),
34570
8a8f52a733dd 8144095: jshell tool: normalize command parameter handling
rfield
parents: 34475
diff changeset
   142
                a -> assertCompletion(a, "/ed|", false, "/edit "),
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   143
                a -> assertClass(a, "class cTest {}", "class", "cTest"),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   144
                a -> assertMethod(a, "int mTest() { return 0; }", "()I", "mTest"),
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   145
                a -> assertVariable(a, "int", "fTest"),
42265
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   146
                a -> assertCompletion(a, "/edit |", false,
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   147
                        "-all" , "-start " , "1 ", "2 ", "3 ", "cTest ", "fTest ", "mTest "),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   148
                a -> assertCompletion(a, "/edit cTest |", false,
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   149
                        "2 ", "3 ", "fTest ", "mTest "),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   150
                a -> assertCompletion(a, "/edit 1 fTest |", false,
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   151
                        "2 ", "mTest "),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   152
                a -> assertCompletion(a, "/edit f|", false, "fTest "),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   153
                a -> assertCompletion(a, "/edit mTest f|", false, "fTest ")
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   154
        );
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   155
    }
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   156
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   157
    @Test
42265
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   158
    public void testHelp() {
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   159
        testNoStartUp(
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   160
                a -> assertCompletion(a, "/help |", false,
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   161
                "/! ", "/-<n> ", "/<id> ", "/? ", "/drop ",
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   162
                "/edit ", "/env ", "/exit ",
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   163
                "/help ", "/history ", "/imports ",
42265
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   164
                "/list ", "/methods ", "/open ", "/reload ", "/reset ",
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   165
                "/save ", "/set ", "/types ", "/vars ", "context ", "intro ", "shortcuts "),
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   166
                a -> assertCompletion(a, "/? |", false,
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   167
                "/! ", "/-<n> ", "/<id> ", "/? ", "/drop ",
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   168
                "/edit ", "/env ", "/exit ",
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   169
                "/help ", "/history ", "/imports ",
42265
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   170
                "/list ", "/methods ", "/open ", "/reload ", "/reset ",
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   171
                "/save ", "/set ", "/types ", "/vars ", "context ", "intro ", "shortcuts "),
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   172
                a -> assertCompletion(a, "/help /s|", false,
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   173
                "/save ", "/set "),
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   174
                a -> assertCompletion(a, "/help /set |", false,
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   175
                "editor", "feedback", "format", "mode", "prompt", "start", "truncation"),
44454
74af976d6798 8177079: jshell tool: usability of /help for commands and sub-commands
rfield
parents: 43038
diff changeset
   176
                a -> assertCompletion(a, "/help /edit |", false),
74af976d6798 8177079: jshell tool: usability of /help for commands and sub-commands
rfield
parents: 43038
diff changeset
   177
                a -> assertCompletion(a, "/help dr|", false,
74af976d6798 8177079: jshell tool: usability of /help for commands and sub-commands
rfield
parents: 43038
diff changeset
   178
                "drop ")
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   179
        );
42265
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   180
    }
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   181
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   182
    @Test
42265
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   183
    public void testReload() {
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   184
        String[] ropts = new String[] { "-add-exports ", "-add-modules ",
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   185
            "-class-path ", "-module-path ", "-quiet ", "-restore " };
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   186
        String[] dropts = new String[] { "--add-exports ", "--add-modules ",
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   187
            "--class-path ", "--module-path ", "--quiet ", "--restore " };
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   188
        testNoStartUp(
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   189
                a -> assertCompletion(a, "/reloa |", false, ropts),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   190
                a -> assertCompletion(a, "/relo               |", false, ropts),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   191
                a -> assertCompletion(a, "/reload -|", false, ropts),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   192
                a -> assertCompletion(a, "/reload --|", false, dropts),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   193
                a -> assertCompletion(a, "/reload -restore |", false, ropts),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   194
                a -> assertCompletion(a, "/reload -restore --|", false, dropts),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   195
                a -> assertCompletion(a, "/reload -rest|", false, "-restore "),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   196
                a -> assertCompletion(a, "/reload --r|", false, "--restore "),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   197
                a -> assertCompletion(a, "/reload -q|", false, "-quiet "),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   198
                a -> assertCompletion(a, "/reload -add|", false, "-add-exports ", "-add-modules "),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   199
                a -> assertCompletion(a, "/reload -class-path . -quiet |", false, ropts)
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   200
        );
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   201
    }
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   202
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   203
    @Test
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   204
    public void testEnv() {
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   205
        String[] ropts = new String[] { "-add-exports ", "-add-modules ",
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   206
            "-class-path ", "-module-path " };
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   207
        String[] dropts = new String[] { "--add-exports ", "--add-modules ",
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   208
            "--class-path ", "--module-path " };
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   209
        testNoStartUp(
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   210
                a -> assertCompletion(a, "/env |", false, ropts),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   211
                a -> assertCompletion(a, "/env -|", false, ropts),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   212
                a -> assertCompletion(a, "/env --|", false, dropts),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   213
                a -> assertCompletion(a, "/env --a|", false, "--add-exports ", "--add-modules "),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   214
                a -> assertCompletion(a, "/env -add-|", false, "-add-exports ", "-add-modules "),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   215
                a -> assertCompletion(a, "/env -class-path . |", false, ropts),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   216
                a -> assertCompletion(a, "/env -class-path . --|", false, dropts)
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   217
        );
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   218
    }
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   219
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   220
    @Test
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   221
    public void testReset() {
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   222
        String[] ropts = new String[] { "-add-exports ", "-add-modules ",
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   223
            "-class-path ", "-module-path " };
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   224
        String[] dropts = new String[] { "--add-exports ", "--add-modules ",
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   225
            "--class-path ", "--module-path " };
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   226
        testNoStartUp(
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   227
                a -> assertCompletion(a, "/reset    |", false, ropts),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   228
                a -> assertCompletion(a, "/res -m|", false, "-module-path "),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   229
                a -> assertCompletion(a, "/res -module-|", false, "-module-path "),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   230
                a -> assertCompletion(a, "/res --m|", false, "--module-path "),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   231
                a -> assertCompletion(a, "/res --module-|", false, "--module-path "),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   232
                a -> assertCompletion(a, "/reset -add|", false, "-add-exports ", "-add-modules "),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   233
                a -> assertCompletion(a, "/rese -class-path . |", false, ropts),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   234
                a -> assertCompletion(a, "/rese -class-path . --|", false, dropts)
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   235
        );
42265
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   236
    }
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   237
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   238
    @Test
42265
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   239
    public void testVarsMethodsTypes() {
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   240
        testNoStartUp(
42265
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   241
                a -> assertCompletion(a, "/v|", false, "/vars "),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   242
                a -> assertCompletion(a, "/m|", false, "/methods "),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   243
                a -> assertCompletion(a, "/t|", false, "/types "),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   244
                a -> assertClass(a, "class cTest {}", "class", "cTest"),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   245
                a -> assertMethod(a, "int mTest() { return 0; }", "()I", "mTest"),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   246
                a -> assertVariable(a, "int", "fTest"),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   247
                a -> assertCompletion(a, "/vars |", false, "-all", "-start ", "3 ", "fTest "),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   248
                a -> assertCompletion(a, "/meth |", false, "-all", "-start ", "2 ", "mTest "),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   249
                a -> assertCompletion(a, "/typ |", false, "-all", "-start ", "1 ", "cTest "),
b36ad5a64e75 8153402: jshell tool: completion provider for /help
rfield
parents: 41635
diff changeset
   250
                a -> assertCompletion(a, "/var f|", false, "fTest ")
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   251
        );
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   252
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   253
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   254
    @Test
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   255
    public void testOpen() throws IOException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   256
        Compiler compiler = new Compiler();
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   257
        testNoStartUp(
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   258
                a -> assertCompletion(a, "/o|", false, "/open ")
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   259
        );
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   260
        List<String> p1 = listFiles(Paths.get(""));
42415
85388bae723d 8165564: langtools\test\jdk\jshell\CommandCompletionTest.java fails on some windows
jlahoda
parents: 42265
diff changeset
   261
        getRootDirectories().forEach(s -> p1.add(s.toString()));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   262
        Collections.sort(p1);
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   263
        testNoStartUp(
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   264
                a -> assertCompletion(a, "/open |", false, p1.toArray(new String[p1.size()]))
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   265
        );
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   266
        Path classDir = compiler.getClassDir();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   267
        List<String> p2 = listFiles(classDir);
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   268
        testNoStartUp(
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   269
                a -> assertCompletion(a, "/open " + classDir + "/|", false, p2.toArray(new String[p2.size()]))
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   270
        );
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   271
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   272
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   273
    @Test
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   274
    public void testSave() throws IOException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   275
        Compiler compiler = new Compiler();
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   276
        testNoStartUp(
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   277
                a -> assertCompletion(a, "/s|", false, "/save ", "/set ")
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   278
        );
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   279
        List<String> p1 = listFiles(Paths.get(""));
38520
17e72b872ffd 8157185: jshell tool: ambiguous format -- distinguished arguments should be options
rfield
parents: 38514
diff changeset
   280
        Collections.addAll(p1, "-all ", "-history ", "-start ");
42415
85388bae723d 8165564: langtools\test\jdk\jshell\CommandCompletionTest.java fails on some windows
jlahoda
parents: 42265
diff changeset
   281
        getRootDirectories().forEach(s -> p1.add(s.toString()));
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   282
        Collections.sort(p1);
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   283
        testNoStartUp(
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   284
                a -> assertCompletion(a, "/save |", false, p1.toArray(new String[p1.size()]))
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   285
        );
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   286
        Path classDir = compiler.getClassDir();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   287
        List<String> p2 = listFiles(classDir);
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   288
        testNoStartUp(
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   289
                a -> assertCompletion(a, "/save " + classDir + "/|",
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   290
                false, p2.toArray(new String[p2.size()])),
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   291
                a -> assertCompletion(a, "/save -all " + classDir + "/|",
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   292
                false, p2.toArray(new String[p2.size()]))
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   293
        );
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   294
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   295
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   296
    @Test
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   297
    public void testClassPath() throws IOException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   298
        Compiler compiler = new Compiler();
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   299
        Path outDir = compiler.getPath("testClasspathCompletion");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   300
        Files.createDirectories(outDir);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   301
        Files.createDirectories(outDir.resolve("dir"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   302
        createIfNeeded(outDir.resolve("test.jar"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   303
        createIfNeeded(outDir.resolve("test.zip"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   304
        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
   305
        String jarName = "test.jar";
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   306
        compiler.jar(outDir, jarName, "pkg/A.class");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   307
        compiler.getPath(outDir).resolve(jarName);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   308
        List<String> paths = listFiles(outDir, CLASSPATH_FILTER);
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   309
        String[] pathArray = paths.toArray(new String[paths.size()]);
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   310
        testNoStartUp(
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   311
                a -> assertCompletion(a, "/env -class-path " + outDir + "/|", false, pathArray),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   312
                a -> assertCompletion(a, "/env --class-path " + outDir + "/|", false, pathArray),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   313
                a -> assertCompletion(a, "/env -clas    " + outDir + "/|", false, pathArray),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   314
                a -> assertCompletion(a, "/env --class-p    " + outDir + "/|", false, pathArray),
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   315
                a -> assertCompletion(a, "/env --module-path . --class-p    " + outDir + "/|", false, pathArray)
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   316
        );
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   317
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   318
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   319
    @Test
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   320
    public void testUserHome() throws IOException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   321
        List<String> completions;
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   322
        Path home = Paths.get(System.getProperty("user.home"));
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   323
        try (Stream<Path> content = Files.list(home)) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   324
            completions = content.filter(CLASSPATH_FILTER)
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   325
                                 .map(file -> file.getFileName().toString() + (Files.isDirectory(file) ? "/" : ""))
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   326
                                 .sorted()
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   327
                                 .collect(Collectors.toList());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   328
        }
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   329
        testNoStartUp(
43038
7b8b8750a78e 8165405: jshell tool: /classpath is inconsistent
rfield
parents: 42843
diff changeset
   330
                a -> assertCompletion(a, "/env --class-path ~/|", false, completions.toArray(new String[completions.size()]))
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   331
        );
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   332
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   333
42843
a8d83044a192 8170162: jshell tool: no mechanism to programmatically launch
rfield
parents: 42415
diff changeset
   334
    @Test
40765
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   335
    public void testSet() throws IOException {
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   336
        List<String> p1 = listFiles(Paths.get(""));
42415
85388bae723d 8165564: langtools\test\jdk\jshell\CommandCompletionTest.java fails on some windows
jlahoda
parents: 42265
diff changeset
   337
        getRootDirectories().forEach(s -> p1.add(s.toString()));
40765
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   338
        Collections.sort(p1);
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   339
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   340
        String[] modes = {"concise ", "normal ", "silent ", "verbose "};
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   341
        String[] options = {"-command", "-delete", "-quiet"};
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   342
        String[] modesWithOptions = Stream.concat(Arrays.stream(options), Arrays.stream(modes)).sorted().toArray(String[]::new);
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   343
        test(false, new String[] {"--no-startup"},
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   344
                a -> assertCompletion(a, "/se|", false, "/set "),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   345
                a -> assertCompletion(a, "/set |", false, "editor ", "feedback ", "format ", "mode ", "prompt ", "start ", "truncation "),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   346
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   347
                // /set editor
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   348
                a -> assertCompletion(a, "/set e|", false, "editor "),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   349
                a -> assertCompletion(a, "/set editor |", false, p1.toArray(new String[p1.size()])),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   350
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   351
                // /set feedback
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   352
                a -> assertCompletion(a, "/set fe|", false, "feedback "),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   353
                a -> assertCompletion(a, "/set fe |", false, modes),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   354
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   355
                // /set format
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   356
                a -> assertCompletion(a, "/set fo|", false, "format "),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   357
                a -> assertCompletion(a, "/set fo |", false, modes),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   358
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   359
                // /set mode
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   360
                a -> assertCompletion(a, "/set mo|", false, "mode "),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   361
                a -> assertCompletion(a, "/set mo |", false),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   362
                a -> assertCompletion(a, "/set mo newmode |", false, modesWithOptions),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   363
                a -> assertCompletion(a, "/set mo newmode -|", false, options),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   364
                a -> assertCompletion(a, "/set mo newmode -command |", false),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   365
                a -> assertCompletion(a, "/set mo newmode normal |", false, options),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   366
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   367
                // /set prompt
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   368
                a -> assertCompletion(a, "/set pro|", false, "prompt "),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   369
                a -> assertCompletion(a, "/set pro |", false, modes),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   370
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   371
                // /set start
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   372
                a -> assertCompletion(a, "/set st|", false, "start "),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   373
                a -> assertCompletion(a, "/set st |", false, p1.toArray(new String[p1.size()])),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   374
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   375
                // /set truncation
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   376
                a -> assertCompletion(a, "/set tr|", false, "truncation "),
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   377
                a -> assertCompletion(a, "/set tr |", false, modes)
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   378
        );
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   379
    }
6f9556cf4404 8164825: jshell tool: Completion for subcommand
shinyafox
parents: 40588
diff changeset
   380
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   381
    private void createIfNeeded(Path file) throws IOException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   382
        if (!Files.exists(file))
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   383
            Files.createFile(file);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   384
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   385
    private List<String> listFiles(Path path) throws IOException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   386
        return listFiles(path, ACCEPT_ALL);
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   387
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   388
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   389
    private List<String> listFiles(Path path, Predicate<? super Path> filter) throws IOException {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   390
        try (Stream<Path> stream = Files.list(path)) {
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   391
            return stream.filter(filter)
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   392
                         .map(p -> p.getFileName().toString() + (Files.isDirectory(p) ? "/" : ""))
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   393
                         .sorted()
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   394
                         .collect(Collectors.toList());
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   395
        }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   396
    }
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   397
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   398
    private static final Predicate<? super Path> ACCEPT_ALL =
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   399
            (file) -> !file.endsWith(".") && !file.endsWith("..");
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   400
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   401
    private static final Predicate<? super Path> CLASSPATH_FILTER =
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   402
            (file) -> ACCEPT_ALL.test(file) &&
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   403
                    (Files.isDirectory(file) ||
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   404
                     file.getFileName().toString().endsWith(".jar") ||
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   405
                     file.getFileName().toString().endsWith(".zip"));
42415
85388bae723d 8165564: langtools\test\jdk\jshell\CommandCompletionTest.java fails on some windows
jlahoda
parents: 42265
diff changeset
   406
85388bae723d 8165564: langtools\test\jdk\jshell\CommandCompletionTest.java fails on some windows
jlahoda
parents: 42265
diff changeset
   407
    private static Iterable<? extends Path> getRootDirectories() {
85388bae723d 8165564: langtools\test\jdk\jshell\CommandCompletionTest.java fails on some windows
jlahoda
parents: 42265
diff changeset
   408
        return StreamSupport.stream(FileSystems.getDefault()
85388bae723d 8165564: langtools\test\jdk\jshell\CommandCompletionTest.java fails on some windows
jlahoda
parents: 42265
diff changeset
   409
                                               .getRootDirectories()
85388bae723d 8165564: langtools\test\jdk\jshell\CommandCompletionTest.java fails on some windows
jlahoda
parents: 42265
diff changeset
   410
                                               .spliterator(),
85388bae723d 8165564: langtools\test\jdk\jshell\CommandCompletionTest.java fails on some windows
jlahoda
parents: 42265
diff changeset
   411
                                    false)
85388bae723d 8165564: langtools\test\jdk\jshell\CommandCompletionTest.java fails on some windows
jlahoda
parents: 42265
diff changeset
   412
                            .filter(p -> Files.exists(p))
85388bae723d 8165564: langtools\test\jdk\jshell\CommandCompletionTest.java fails on some windows
jlahoda
parents: 42265
diff changeset
   413
                            .collect(Collectors.toList());
85388bae723d 8165564: langtools\test\jdk\jshell\CommandCompletionTest.java fails on some windows
jlahoda
parents: 42265
diff changeset
   414
    }
33362
65ec6de1d6b4 8134254: JShell API/tool: REPL for Java into JDK9
jlahoda
parents:
diff changeset
   415
}