langtools/test/jdk/jshell/ToolFormatTest.java
changeset 41635 cb3d04878117
parent 38615 9221159d84fb
child 41937 1313399705e9
equal deleted inserted replaced
41634:3f9c491b05aa 41635:cb3d04878117
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 8148316 8148317 8151755 8152246 8153551 8154812 8157261
    26  * @bug 8148316 8148317 8151755 8152246 8153551 8154812 8157261 8163840
    27  * @summary Tests for output customization
    27  * @summary Tests for output customization
    28  * @library /tools/lib
    28  * @library /tools/lib
    29  * @modules jdk.compiler/com.sun.tools.javac.api
    29  * @modules jdk.compiler/com.sun.tools.javac.api
    30  *          jdk.compiler/com.sun.tools.javac.main
    30  *          jdk.compiler/com.sun.tools.javac.main
    31  *          jdk.jdeps/com.sun.tools.javap
    31  *          jdk.jdeps/com.sun.tools.javap
    32  *          jdk.jshell/jdk.internal.jshell.tool
    32  *          jdk.jshell/jdk.internal.jshell.tool
    33  * @build KullaTesting TestingInputStream toolbox.ToolBox Compiler
    33  * @build KullaTesting TestingInputStream toolbox.ToolBox Compiler
    34  * @run testng ToolFormatTest
    34  * @run testng ToolFormatTest
    35  */
    35  */
       
    36 import java.io.BufferedReader;
       
    37 import java.io.IOException;
       
    38 import java.io.StringReader;
    36 import java.util.ArrayList;
    39 import java.util.ArrayList;
    37 import java.util.List;
    40 import java.util.List;
       
    41 import java.util.logging.Level;
       
    42 import java.util.logging.Logger;
    38 import org.testng.annotations.Test;
    43 import org.testng.annotations.Test;
       
    44 import static org.testng.Assert.assertEquals;
    39 import static org.testng.Assert.assertTrue;
    45 import static org.testng.Assert.assertTrue;
       
    46 import static org.testng.Assert.fail;
    40 
    47 
    41 @Test
    48 @Test
    42 public class ToolFormatTest extends ReplToolTesting {
    49 public class ToolFormatTest extends ReplToolTesting {
    43 
    50 
    44     public void testSetFormat() {
    51     public void testSetFormat() {
    77             );
    84             );
    78         } finally {
    85         } finally {
    79             assertCommandCheckOutput(false, "/set feedback normal", s -> {
    86             assertCommandCheckOutput(false, "/set feedback normal", s -> {
    80             });
    87             });
    81         }
    88         }
       
    89     }
       
    90 
       
    91     public void testSetFormatOverride() {
       
    92         test(
       
    93                 (a) -> assertCommand(a, "/set mode tm -c", "|  Created new feedback mode: tm"),
       
    94                 (a) -> assertCommand(a, "/se fo tm x \"aaa\"", ""),
       
    95                 (a) -> assertCommand(a, "/se fo tm x \"bbb\" class,method-added", ""),
       
    96                 (a) -> assertCommand(a, "/se fo tm x",
       
    97                         "|  /set format tm x \"aaa\" \n" +
       
    98                         "|  /set format tm x \"bbb\" class,method-added"),
       
    99                 (a) -> assertCommand(a, "/se fo tm x \"ccc\" class,method-added,modified", ""),
       
   100                 (a) -> assertCommand(a, "/se fo tm x \"ddd\" class,method-added", ""),
       
   101                 (a) -> assertCommand(a, "/se fo tm x \"eee\" method-added", ""),
       
   102                 (a) -> assertCommand(a, "/se fo tm x",
       
   103                         "|  /set format tm x \"aaa\" \n" +
       
   104                         "|  /set format tm x \"ccc\" class,method-added,modified\n" +
       
   105                         "|  /set format tm x \"ddd\" class,method-added\n" +
       
   106                         "|  /set format tm x \"eee\" method-added"),
       
   107                 (a) -> assertCommand(a, "/se fo tm x \"EEE\" method-added,replaced", ""),
       
   108                 (a) -> assertCommand(a, "/se fo tm x",
       
   109                         "|  /set format tm x \"aaa\" \n" +
       
   110                         "|  /set format tm x \"ccc\" class,method-added,modified\n" +
       
   111                         "|  /set format tm x \"ddd\" class,method-added\n" +
       
   112                         "|  /set format tm x \"EEE\" method-added,replaced"),
       
   113                 (a) -> assertCommand(a, "/se fo tm x \"fff\" method-added,replaced-ok", ""),
       
   114                 (a) -> assertCommand(a, "/se fo tm x",
       
   115                         "|  /set format tm x \"aaa\" \n" +
       
   116                         "|  /set format tm x \"ccc\" class,method-added,modified\n" +
       
   117                         "|  /set format tm x \"ddd\" class,method-added\n" +
       
   118                         "|  /set format tm x \"EEE\" method-added,replaced\n" +
       
   119                         "|  /set format tm x \"fff\" method-added,replaced-ok"),
       
   120                 (a) -> assertCommand(a, "/se fo tm x \"ggg\" method-ok", ""),
       
   121                 (a) -> assertCommand(a, "/se fo tm x",
       
   122                         "|  /set format tm x \"aaa\" \n" +
       
   123                         "|  /set format tm x \"ccc\" class,method-added,modified\n" +
       
   124                         "|  /set format tm x \"ddd\" class,method-added\n" +
       
   125                         "|  /set format tm x \"EEE\" method-added,replaced\n" +
       
   126                         "|  /set format tm x \"ggg\" method-ok"),
       
   127                 (a) -> assertCommand(a, "/se fo tm x \"hhh\" method", ""),
       
   128                 (a) -> assertCommand(a, "/se fo tm x",
       
   129                         "|  /set format tm x \"aaa\" \n" +
       
   130                         "|  /set format tm x \"ccc\" class,method-added,modified\n" +
       
   131                         "|  /set format tm x \"ddd\" class,method-added\n" +
       
   132                         "|  /set format tm x \"hhh\" method"),
       
   133                 (a) -> assertCommand(a, "/se fo tm x \"iii\" method,class", ""),
       
   134                 (a) -> assertCommand(a, "/se fo tm x",
       
   135                         "|  /set format tm x \"aaa\" \n" +
       
   136                         "|  /set format tm x \"iii\" class,method"),
       
   137                 (a) -> assertCommand(a, "/se fo tm x \"jjj\"", ""),
       
   138                 (a) -> assertCommand(a, "/se fo tm x",
       
   139                         "|  /set format tm x \"jjj\"")
       
   140         );
    82     }
   141     }
    83 
   142 
    84     public void testSetFormatSelector() {
   143     public void testSetFormatSelector() {
    85         List<ReplTest> tests = new ArrayList<>();
   144         List<ReplTest> tests = new ArrayList<>();
    86         tests.add((a) -> assertCommandOutputStartsWith(a, "/set mode ate -quiet",
   145         tests.add((a) -> assertCommandOutputStartsWith(a, "/set mode ate -quiet",
   165                             "s ==> \"ABACABADABACABAEABACABADABACABAFABACABADABACABAEABACABADABACABAGABACABADABA ..."),
   224                             "s ==> \"ABACABADABACABAEABACABADABACABAFABACABADABACABAEABACABADABACABAGABACABADABA ..."),
   166                     (a) -> assertCommandOutputStartsWith(a, "/set mode test -quiet", ""),
   225                     (a) -> assertCommandOutputStartsWith(a, "/set mode test -quiet", ""),
   167                     (a) -> assertCommandOutputStartsWith(a, "/set feedback test", ""),
   226                     (a) -> assertCommandOutputStartsWith(a, "/set feedback test", ""),
   168                     (a) -> assertCommand(a, "/set format test display '{type}:{value}' primary", ""),
   227                     (a) -> assertCommand(a, "/set format test display '{type}:{value}' primary", ""),
   169                     (a) -> assertCommand(a, "/set truncation test 20", ""),
   228                     (a) -> assertCommand(a, "/set truncation test 20", ""),
       
   229                     (a) -> assertCommand(a, "/set truncation test", "|  /set truncation test 20"),
       
   230                     (a) -> assertCommandOutputContains(a, "/set truncation", "/set truncation test 20"),
   170                     (a) -> assertCommand(a, "/set trunc test 10 varvalue", ""),
   231                     (a) -> assertCommand(a, "/set trunc test 10 varvalue", ""),
   171                     (a) -> assertCommand(a, "/set trunc test 3 assignment", ""),
   232                     (a) -> assertCommand(a, "/set trunc test 3 assignment", ""),
       
   233                     (a) -> assertCommandOutputContains(a, "/set truncation",
       
   234                             "/set truncation test 10 varvalue"),
       
   235                     (a) -> assertCommandOutputContains(a, "/set truncation test",
       
   236                             "/set truncation test 10 varvalue"),
   172                     (a) -> assertCommand(a, "String r = s", "String:\"ABACABADABACABA ..."),
   237                     (a) -> assertCommand(a, "String r = s", "String:\"ABACABADABACABA ..."),
   173                     (a) -> assertCommand(a, "r", "String:\"ABACA ..."),
   238                     (a) -> assertCommand(a, "r", "String:\"ABACA ..."),
   174                     (a) -> assertCommand(a, "r=s", "String:\"AB")
   239                     (a) -> assertCommand(a, "r=s", "String:\"AB")
   175             );
   240             );
   176         } finally {
   241         } finally {
   199                                 assertTrue(s.contains("XAAAAAAAAAAAAAAAAAA"), "Bad value: " + s);
   264                                 assertTrue(s.contains("XAAAAAAAAAAAAAAAAAA"), "Bad value: " + s);
   200                             })
   265                             })
   201         );
   266         );
   202     }
   267     }
   203 
   268 
       
   269     public void testPrompt() {
       
   270         test(
       
   271                 (a) -> assertCommand(a, "/set mode tp -quiet", "|  Created new feedback mode: tp"),
       
   272                 (a) -> assertCommand(a, "/set prompt tp 'aaa' 'bbb'", ""),
       
   273                 (a) -> assertCommand(a, "/set prompt tp",
       
   274                         "|  /set prompt tp \"aaa\" \"bbb\""),
       
   275                 (a) -> assertCommandOutputContains(a, "/set prompt",
       
   276                         "|  /set prompt tp \"aaa\" \"bbb\""),
       
   277                 (a) -> assertCommand(a, "/set mode -retain tp", ""),
       
   278                 (a) -> assertCommand(a, "/set prompt tp 'ccc' 'ddd'", ""),
       
   279                 (a) -> assertCommand(a, "/set prompt tp",
       
   280                         "|  /set prompt tp \"ccc\" \"ddd\""),
       
   281                 (a) -> assertCommandCheckOutput(a, "/set mode tp",
       
   282                         (s) -> {
       
   283                             try {
       
   284                                 BufferedReader rdr = new BufferedReader(new StringReader(s));
       
   285                                 assertEquals(rdr.readLine(), "|  /set mode tp -quiet",
       
   286                                         "|  /set mode tp -quiet");
       
   287                                 assertEquals(rdr.readLine(), "|  /set prompt tp \"aaa\" \"bbb\"",
       
   288                                         "|  /set prompt tp \"aaa\" \"bbb\"");
       
   289                                 String l = rdr.readLine();
       
   290                                 while (l.startsWith("|  /set format tp ")) {
       
   291                                     l = rdr.readLine();
       
   292                                 }
       
   293                                 assertEquals(l, "|  /set mode -retain tp",
       
   294                                         "|  /set mode -retain tp");
       
   295                                 assertEquals(rdr.readLine(), "|  ",
       
   296                                         "|  ");
       
   297                                 assertEquals(rdr.readLine(), "|  /set mode tp -quiet",
       
   298                                         "|  /set mode tp -quiet");
       
   299                                 assertEquals(rdr.readLine(), "|  /set prompt tp \"ccc\" \"ddd\"",
       
   300                                         "|  /set prompt tp \"ccc\" \"ddd\"");
       
   301                             } catch (IOException ex) {
       
   302                                 fail("threw " + ex);
       
   303                             }
       
   304                         })
       
   305         );
       
   306     }
       
   307 
   204     public void testShowFeedbackModes() {
   308     public void testShowFeedbackModes() {
   205         test(
   309         test(
   206                 (a) -> assertCommandOutputContains(a, "/set feedback", "normal")
   310                 (a) -> assertCommandOutputContains(a, "/set feedback", "normal")
   207         );
   311         );
   208     }
   312     }
   214                     (a) -> assertCommand(a, "/set feedback nmq", ""),
   318                     (a) -> assertCommand(a, "/set feedback nmq", ""),
   215                     (a) -> assertCommand(a, "/se mo nmq2 -q nor", ""),
   319                     (a) -> assertCommand(a, "/se mo nmq2 -q nor", ""),
   216                     (a) -> assertCommand(a, "/se fee nmq2", ""),
   320                     (a) -> assertCommand(a, "/se fee nmq2", ""),
   217                     (a) -> assertCommand(a, "/set mode nmc -command normal", ""),
   321                     (a) -> assertCommand(a, "/set mode nmc -command normal", ""),
   218                     (a) -> assertCommandOutputStartsWith(a, "/set feedback nmc", "|  Feedback mode: nmc"),
   322                     (a) -> assertCommandOutputStartsWith(a, "/set feedback nmc", "|  Feedback mode: nmc"),
   219                     (a) -> assertCommandOutputStartsWith(a, "/set mode nm", "|  Created new feedback mode: nm"),
   323                     (a) -> assertCommandOutputStartsWith(a, "/set mode nm -command",
       
   324                             "|  Created new feedback mode: nm"),
   220                     (a) -> assertCommandOutputStartsWith(a, "/set feedback nm", "|  Feedback mode: nm"),
   325                     (a) -> assertCommandOutputStartsWith(a, "/set feedback nm", "|  Feedback mode: nm"),
   221                     (a) -> assertCommandOutputStartsWith(a, "/set feedback normal", "|  Feedback mode: normal")
   326                     (a) -> assertCommandOutputStartsWith(a, "/set feedback normal", "|  Feedback mode: normal")
   222             );
   327             );
   223         } finally {
   328         } finally {
   224             assertCommandCheckOutput(false, "/set feedback normal", s -> {
   329             assertCommandCheckOutput(false, "/set feedback normal", s -> {
   229     public void testSetError() {
   334     public void testSetError() {
   230         try {
   335         try {
   231             test(
   336             test(
   232                     (a) -> assertCommandOutputStartsWith(a, "/set mode tee -command foo",
   337                     (a) -> assertCommandOutputStartsWith(a, "/set mode tee -command foo",
   233                             "|  Does not match any current feedback mode: foo"),
   338                             "|  Does not match any current feedback mode: foo"),
   234                     (a) -> assertCommandOutputStartsWith(a, "/set mode tee flurb",
   339                     (a) -> assertCommandOutputStartsWith(a, "/set mode tee -quiet flurb",
   235                             "|  Does not match any current feedback mode: flurb"),
   340                             "|  Does not match any current feedback mode: flurb"),
   236                     (a) -> assertCommandOutputStartsWith(a, "/set mode tee",
   341                     (a) -> assertCommandOutputStartsWith(a, "/set mode -command tee",
   237                             "|  Created new feedback mode: tee"),
   342                             "|  Created new feedback mode: tee"),
   238                     (a) -> assertCommandOutputStartsWith(a, "/set mode verbose",
   343                     (a) -> assertCommandOutputStartsWith(a, "/set mode verbose -command",
   239                             "|  Not valid with a predefined mode: verbose"),
   344                             "|  Mode to be created already exists: verbose"),
   240                     (a) -> assertCommandOutputStartsWith(a, "/set mode te -command normal",
   345                     (a) -> assertCommandOutputStartsWith(a, "/set mode te -command normal",
   241                             "|  Created new feedback mode: te"),
   346                             "|  Created new feedback mode: te"),
   242                     (a) -> assertCommand(a, "/set format te errorpre 'ERROR: '", ""),
   347                     (a) -> assertCommand(a, "/set format te errorpre 'ERROR: '", ""),
   243                     (a) -> assertCommandOutputStartsWith(a, "/set feedback te",
   348                     (a) -> assertCommandOutputStartsWith(a, "/set feedback te",
   244                             ""),
   349                             ""),
   245                     (a) -> assertCommandOutputStartsWith(a, "/set ",
       
   246                             "ERROR: The '/set' command requires a sub-command"),
       
   247                     (a) -> assertCommandOutputStartsWith(a, "/set xyz",
   350                     (a) -> assertCommandOutputStartsWith(a, "/set xyz",
   248                             "ERROR: Invalid '/set' argument: xyz"),
   351                             "ERROR: Invalid '/set' argument: xyz"),
   249                     (a) -> assertCommandOutputStartsWith(a, "/set f",
   352                     (a) -> assertCommandOutputStartsWith(a, "/set f",
   250                             "ERROR: Ambiguous sub-command argument to '/set': f"),
   353                             "ERROR: Ambiguous sub-command argument to '/set': f"),
   251                     (a) -> assertCommandOutputStartsWith(a, "/set feedback",
   354                     (a) -> assertCommandOutputStartsWith(a, "/set feedback",
   252                             "ERROR: Missing the feedback mode"),
   355                             "|  /set feedback te"),
   253                     (a) -> assertCommandOutputStartsWith(a, "/set feedback xyz",
   356                     (a) -> assertCommandOutputStartsWith(a, "/set feedback xyz",
   254                             "ERROR: Does not match any current feedback mode"),
   357                             "ERROR: Does not match any current feedback mode"),
   255                     (a) -> assertCommandOutputStartsWith(a, "/set format",
   358                     (a) -> assertCommandOutputStartsWith(a, "/set feed",
   256                             "ERROR: Missing the feedback mode"),
   359                             "|  /set feedback te"),
   257                     (a) -> assertCommandOutputStartsWith(a, "/set format xyz",
   360                     (a) -> assertCommandOutputStartsWith(a, "/set format xyz",
   258                             "ERROR: Does not match any current feedback mode"),
   361                             "ERROR: Does not match any current feedback mode"),
   259                     (a) -> assertCommandOutputStartsWith(a, "/set format t",
   362                     (a) -> assertCommandOutputStartsWith(a, "/set format t",
   260                             "ERROR: Matches more then one current feedback mode: t"),
   363                             "ERROR: Matches more then one current feedback mode: t"),
   261                     (a) -> assertCommandOutputStartsWith(a, "/set format te",
   364                     (a) -> assertCommandOutputStartsWith(a, "/set format qqq",
   262                             "ERROR: Missing the field name"),
   365                             "ERROR: Does not match any current feedback mode: qqq"),
   263                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld",
   366                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld",
   264                             "ERROR: Expected format missing"),
   367                             "ERROR: Expected a field name:"),
   265                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld aaa",
   368                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld aaa",
   266                             "ERROR: Format 'aaa' must be quoted"),
   369                             "ERROR: Format 'aaa' must be quoted"),
   267                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld 'aaa' frog",
   370                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld 'aaa' frog",
   268                             "ERROR: Not a valid selector"),
   371                             "ERROR: Not a valid selector"),
   269                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld 'aaa' import-frog",
   372                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld 'aaa' import-frog",
   272                             "ERROR: Selector kind in multiple sections of"),
   375                             "ERROR: Selector kind in multiple sections of"),
   273                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld 'aaa' import,added",
   376                     (a) -> assertCommandOutputStartsWith(a, "/set format te fld 'aaa' import,added",
   274                             "ERROR: Different selector kinds in same sections of"),
   377                             "ERROR: Different selector kinds in same sections of"),
   275                     (a) -> assertCommandOutputStartsWith(a, "/set trunc te 20x",
   378                     (a) -> assertCommandOutputStartsWith(a, "/set trunc te 20x",
   276                             "ERROR: Truncation length must be an integer: 20x"),
   379                             "ERROR: Truncation length must be an integer: 20x"),
   277                     (a) -> assertCommandOutputStartsWith(a, "/set trunc te",
   380                     (a) -> assertCommandOutputStartsWith(a, "/set trunc qaz",
   278                             "ERROR: Expected truncation length"),
   381                             "ERROR: Does not match any current feedback mode: qaz -- /set trunc qaz"),
   279                     (a) -> assertCommandOutputStartsWith(a, "/set truncation te 111 import,added",
   382                     (a) -> assertCommandOutputStartsWith(a, "/set truncation te 111 import,added",
   280                             "ERROR: Different selector kinds in same sections of"),
   383                             "ERROR: Different selector kinds in same sections of"),
   281                     (a) -> assertCommandOutputStartsWith(a, "/set mode",
   384                     (a) -> assertCommandOutputContains(a, "/set mode",
       
   385                             "|  /set truncation verbose"),
       
   386                     (a) -> assertCommandOutputStartsWith(a, "/set mode -command",
   282                             "ERROR: Missing the feedback mode"),
   387                             "ERROR: Missing the feedback mode"),
   283                     (a) -> assertCommandOutputStartsWith(a, "/set mode x -quiet y",
   388                     (a) -> assertCommandOutputStartsWith(a, "/set mode x -quiet y",
   284                             "ERROR: Does not match any current feedback mode"),
   389                             "ERROR: Does not match any current feedback mode"),
   285                     (a) -> assertCommandOutputStartsWith(a, "/set prompt",
   390                     (a) -> assertCommandOutputStartsWith(a, "/set prompt",
   286                             "ERROR: Missing the feedback mode"),
   391                             "|  /set prompt"),
   287                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te",
   392                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te",
   288                             "ERROR: Expected format missing"),
   393                             "|  /set prompt te "),
   289                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te aaa xyz",
   394                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te aaa xyz",
   290                             "ERROR: Format 'aaa' must be quoted"),
   395                             "ERROR: Format 'aaa' must be quoted"),
   291                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te 'aaa' xyz",
   396                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te 'aaa' xyz",
   292                             "ERROR: Format 'xyz' must be quoted"),
   397                             "ERROR: Format 'xyz' must be quoted"),
   293                     (a) -> assertCommandOutputStartsWith(a, "/set prompt",
       
   294                             "ERROR: Missing the feedback mode"),
       
   295                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te",
       
   296                             "ERROR: Expected format missing"),
       
   297                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te aaa",
   398                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te aaa",
   298                             "ERROR: Format 'aaa' must be quoted"),
   399                             "ERROR: Format 'aaa' must be quoted"),
   299                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te 'aaa'",
   400                     (a) -> assertCommandOutputStartsWith(a, "/set prompt te 'aaa'",
   300                             "ERROR: Expected format missing"),
   401                             "ERROR: Continuation prompt required"),
   301                     (a) -> assertCommandOutputStartsWith(a, "/set feedback normal",
   402                     (a) -> assertCommandOutputStartsWith(a, "/set feedback normal",
   302                             "|  Feedback mode: normal")
   403                             "|  Feedback mode: normal")
   303             );
   404             );
   304         } finally {
   405         } finally {
   305             assertCommandCheckOutput(false, "/set feedback normal", s -> {
   406             assertCommandCheckOutput(false, "/set feedback normal", s -> {