langtools/test/jdk/jshell/ToolBasicTest.java
changeset 35812 6a6ca0bd3c14
parent 35002 209d72239196
child 36494 4175f47b2a50
equal deleted inserted replaced
35811:3779fa4164c2 35812:6a6ca0bd3c14
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 8143037 8142447 8144095 8140265 8144906
    26  * @bug 8143037 8142447 8144095 8140265 8144906 8146138 8147887 8147886
    27  * @requires os.family != "solaris"
    27  * @requires os.family != "solaris"
    28  * @summary Tests for Basic tests for REPL tool
    28  * @summary Tests for Basic tests for REPL tool
    29  * @library /tools/lib
    29  * @library /tools/lib
    30  * @ignore 8139873
    30  * @ignore 8139873
    31  * @build KullaTesting TestingInputStream ToolBox Compiler
    31  * @build KullaTesting TestingInputStream ToolBox Compiler
   304                 (a) -> assertCommand(a, "/debug", "|  Debugging on\n"),
   304                 (a) -> assertCommand(a, "/debug", "|  Debugging on\n"),
   305                 (a) -> assertCommand(a, "/deb", "|  Debugging off\n")
   305                 (a) -> assertCommand(a, "/deb", "|  Debugging off\n")
   306         );
   306         );
   307     }
   307     }
   308 
   308 
   309     public void testHelp() {
   309     public void testHelpLength() {
   310         Consumer<String> testOutput = (s) -> {
   310         Consumer<String> testOutput = (s) -> {
   311             List<String> ss = Stream.of(s.split("\n"))
   311             List<String> ss = Stream.of(s.split("\n"))
   312                     .filter(l -> !l.isEmpty())
   312                     .filter(l -> !l.isEmpty())
   313                     .collect(Collectors.toList());
   313                     .collect(Collectors.toList());
   314             assertTrue(ss.size() >= 5, "Help does not print enough lines:\n" + s);
   314             assertTrue(ss.size() >= 10, "Help does not print enough lines:\n" + s);
   315         };
   315         };
   316         test(
   316         test(
   317                 (a) -> assertCommandCheckOutput(a, "/?", testOutput),
   317                 (a) -> assertCommandCheckOutput(a, "/?", testOutput),
   318                 (a) -> assertCommandCheckOutput(a, "/help", testOutput)
   318                 (a) -> assertCommandCheckOutput(a, "/help", testOutput),
   319         );
   319                 (a) -> assertCommandCheckOutput(a, "/help /list", testOutput)
       
   320         );
       
   321     }
       
   322 
       
   323     public void testHelp() {
       
   324         test(
       
   325                 (a) -> assertHelp(a, "/?", "/list", "/help", "/exit", "intro"),
       
   326                 (a) -> assertHelp(a, "/help", "/list", "/help", "/exit", "intro"),
       
   327                 (a) -> assertHelp(a, "/help short", "shortcuts", "<tab>"),
       
   328                 (a) -> assertHelp(a, "/? /li", "/list all", "snippets"),
       
   329                 (a) -> assertHelp(a, "/help /help", "/help <command>")
       
   330         );
       
   331     }
       
   332 
       
   333     private void assertHelp(boolean a, String command, String... find) {
       
   334         assertCommandCheckOutput(a, command, s -> {
       
   335             for (String f : find) {
       
   336                 assertTrue(s.contains(f), "Expected output of " + command + " to contain: " + f);
       
   337             }
       
   338         });
   320     }
   339     }
   321 
   340 
   322     public void oneLineOfError() {
   341     public void oneLineOfError() {
   323         test(
   342         test(
   324                 (a) -> assertCommand(a, "12+", null),
   343                 (a) -> assertCommand(a, "12+", null),
   680                         s -> assertEquals(s, "|  No definition or id named " + arg +
   699                         s -> assertEquals(s, "|  No definition or id named " + arg +
   681                                 " found.  There are no active definitions.\n")),
   700                                 " found.  There are no active definitions.\n")),
   682                 a -> assertVariable(a, "int", "aardvark"),
   701                 a -> assertVariable(a, "int", "aardvark"),
   683                 a -> assertCommandCheckOutput(a, "/list aardvark",
   702                 a -> assertCommandCheckOutput(a, "/list aardvark",
   684                         s -> assertTrue(s.contains("aardvark"))),
   703                         s -> assertTrue(s.contains("aardvark"))),
       
   704                 a -> assertCommandCheckOutput(a, "/list start",
       
   705                         s -> checkLineToList(s, START_UP)),
   685                 a -> assertCommandCheckOutput(a, "/list all",
   706                 a -> assertCommandCheckOutput(a, "/list all",
   686                         s -> checkLineToList(s, startVarList)),
   707                         s -> checkLineToList(s, startVarList)),
   687                 a -> assertCommandCheckOutput(a, "/list history",
   708                 a -> assertCommandCheckOutput(a, "/list printf",
   688                         s -> assertTrue(s.split("\n").length >= 4, s)),
   709                         s -> assertTrue(s.contains("void printf"))),
   689                 a -> assertCommandCheckOutput(a, "/list " + arg,
   710                 a -> assertCommandCheckOutput(a, "/list " + arg,
   690                         s -> assertEquals(s, "|  No definition or id named " + arg +
   711                         s -> assertEquals(s, "|  No definition or id named " + arg +
   691                                 " found.  Try /list without arguments.\n"))
   712                                 " found.  Try /list without arguments.\n"))
   692         );
   713         );
   693     }
   714     }