langtools/test/jdk/jshell/ToolFormatTest.java
author rfield
Thu, 20 Oct 2016 12:53:11 -0700
changeset 41635 cb3d04878117
parent 38615 9221159d84fb
child 41937 1313399705e9
permissions -rw-r--r--
8163840: jshell tool: provide way to display configuration settings Reviewed-by: jlahoda
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
     1
/*
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
     4
 *
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
     7
 * published by the Free Software Foundation.
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
     8
 *
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    13
 * accompanied this code).
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    14
 *
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    18
 *
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    21
 * questions.
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    22
 */
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    23
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    24
/*
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    25
 * @test
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    26
 * @bug 8148316 8148317 8151755 8152246 8153551 8154812 8157261 8163840
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    27
 * @summary Tests for output customization
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    28
 * @library /tools/lib
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36494
diff changeset
    29
 * @modules jdk.compiler/com.sun.tools.javac.api
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36494
diff changeset
    30
 *          jdk.compiler/com.sun.tools.javac.main
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36494
diff changeset
    31
 *          jdk.jdeps/com.sun.tools.javap
3b41f1c69604 8142968: Module System implementation
alanb
parents: 36494
diff changeset
    32
 *          jdk.jshell/jdk.internal.jshell.tool
36778
e04318f39f92 8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents: 36718
diff changeset
    33
 * @build KullaTesting TestingInputStream toolbox.ToolBox Compiler
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    34
 * @run testng ToolFormatTest
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    35
 */
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    36
import java.io.BufferedReader;
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    37
import java.io.IOException;
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    38
import java.io.StringReader;
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    39
import java.util.ArrayList;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    40
import java.util.List;
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    41
import java.util.logging.Level;
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    42
import java.util.logging.Logger;
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    43
import org.testng.annotations.Test;
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    44
import static org.testng.Assert.assertEquals;
38615
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
    45
import static org.testng.Assert.assertTrue;
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    46
import static org.testng.Assert.fail;
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    47
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    48
@Test
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    49
public class ToolFormatTest extends ReplToolTesting {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    50
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    51
    public void testSetFormat() {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    52
        try {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    53
            test(
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
    54
                    (a) -> assertCommandOutputStartsWith(a, "/set mode test -command", "|  Created new feedback mode: test"),
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    55
                    (a) -> assertCommand(a, "/set format test pre '$ '", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    56
                    (a) -> assertCommand(a, "/set format test post ''", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    57
                    (a) -> assertCommand(a, "/set format test act 'ADD' added", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    58
                    (a) -> assertCommand(a, "/set format test act 'MOD' modified", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    59
                    (a) -> assertCommand(a, "/set format test act 'REP' replaced", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    60
                    (a) -> assertCommand(a, "/set format test act 'OVR' overwrote", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    61
                    (a) -> assertCommand(a, "/set format test act 'USE' used", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    62
                    (a) -> assertCommand(a, "/set format test act 'DRP' dropped", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    63
                    (a) -> assertCommand(a, "/set format test up 'UP-' update", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    64
                    (a) -> assertCommand(a, "/set format test action '{up}{act} '", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    65
                    (a) -> assertCommand(a, "/set format test resolve 'OK' ok", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    66
                    (a) -> assertCommand(a, "/set format test resolve 'DEF' defined", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    67
                    (a) -> assertCommand(a, "/set format test resolve 'NODEF' notdefined", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    68
                    (a) -> assertCommand(a, "/set format test fname ':{name} ' ", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    69
                    (a) -> assertCommand(a, "/set format test ftype '[{type}]' method,expression", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    70
                    (a) -> assertCommand(a, "/set format test result '={value} ' expression", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    71
                    (a) -> assertCommand(a, "/set format test display '{pre}{action}{ftype}{fname}{result}{resolve}'", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    72
                    (a) -> assertCommand(a, "/set format test display '{pre}HI this is enum' enum", ""),
36990
ec0b843a7af5 8147515: JShell: Internationalize
rfield
parents: 36778
diff changeset
    73
                    (a) -> assertCommandOutputStartsWith(a, "/set feedback test", "$ Feedback mode: test"),
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    74
                    (a) -> assertCommand(a, "class D {}", "$ ADD :D OK"),
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    75
                    (a) -> assertCommand(a, "void m() {}", "$ ADD []:m OK"),
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    76
                    (a) -> assertCommand(a, "interface EX extends EEX {}", "$ ADD :EX NODEF"),
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    77
                    (a) -> assertCommand(a, "56", "$ ADD [int]:$4 =56 OK"),
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    78
                    (a) -> assertCommand(a, "class D { int hh; }", "$ REP :D OK$ UP-OVR :D OK"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    79
                    (a) -> assertCommand(a, "enum E {A,B}", "$ HI this is enum"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    80
                    (a) -> assertCommand(a, "int z() { return f(); }", "$ ADD []:z DEF"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    81
                    (a) -> assertCommand(a, "z()", "$ UP-USE []:z DEF"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
    82
                    (a) -> assertCommand(a, "/drop z", "$ DRP []:z OK"),
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    83
                    (a) -> assertCommandOutputStartsWith(a, "/set feedback normal", "|  Feedback mode: normal")
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    84
            );
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    85
        } finally {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    86
            assertCommandCheckOutput(false, "/set feedback normal", s -> {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    87
            });
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    88
        }
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    89
    }
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
    90
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    91
    public void testSetFormatOverride() {
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    92
        test(
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    93
                (a) -> assertCommand(a, "/set mode tm -c", "|  Created new feedback mode: tm"),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    94
                (a) -> assertCommand(a, "/se fo tm x \"aaa\"", ""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    95
                (a) -> assertCommand(a, "/se fo tm x \"bbb\" class,method-added", ""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    96
                (a) -> assertCommand(a, "/se fo tm x",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    97
                        "|  /set format tm x \"aaa\" \n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    98
                        "|  /set format tm x \"bbb\" class,method-added"),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
    99
                (a) -> assertCommand(a, "/se fo tm x \"ccc\" class,method-added,modified", ""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   100
                (a) -> assertCommand(a, "/se fo tm x \"ddd\" class,method-added", ""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   101
                (a) -> assertCommand(a, "/se fo tm x \"eee\" method-added", ""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   102
                (a) -> assertCommand(a, "/se fo tm x",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   103
                        "|  /set format tm x \"aaa\" \n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   104
                        "|  /set format tm x \"ccc\" class,method-added,modified\n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   105
                        "|  /set format tm x \"ddd\" class,method-added\n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   106
                        "|  /set format tm x \"eee\" method-added"),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   107
                (a) -> assertCommand(a, "/se fo tm x \"EEE\" method-added,replaced", ""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   108
                (a) -> assertCommand(a, "/se fo tm x",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   109
                        "|  /set format tm x \"aaa\" \n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   110
                        "|  /set format tm x \"ccc\" class,method-added,modified\n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   111
                        "|  /set format tm x \"ddd\" class,method-added\n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   112
                        "|  /set format tm x \"EEE\" method-added,replaced"),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   113
                (a) -> assertCommand(a, "/se fo tm x \"fff\" method-added,replaced-ok", ""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   114
                (a) -> assertCommand(a, "/se fo tm x",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   115
                        "|  /set format tm x \"aaa\" \n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   116
                        "|  /set format tm x \"ccc\" class,method-added,modified\n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   117
                        "|  /set format tm x \"ddd\" class,method-added\n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   118
                        "|  /set format tm x \"EEE\" method-added,replaced\n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   119
                        "|  /set format tm x \"fff\" method-added,replaced-ok"),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   120
                (a) -> assertCommand(a, "/se fo tm x \"ggg\" method-ok", ""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   121
                (a) -> assertCommand(a, "/se fo tm x",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   122
                        "|  /set format tm x \"aaa\" \n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   123
                        "|  /set format tm x \"ccc\" class,method-added,modified\n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   124
                        "|  /set format tm x \"ddd\" class,method-added\n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   125
                        "|  /set format tm x \"EEE\" method-added,replaced\n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   126
                        "|  /set format tm x \"ggg\" method-ok"),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   127
                (a) -> assertCommand(a, "/se fo tm x \"hhh\" method", ""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   128
                (a) -> assertCommand(a, "/se fo tm x",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   129
                        "|  /set format tm x \"aaa\" \n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   130
                        "|  /set format tm x \"ccc\" class,method-added,modified\n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   131
                        "|  /set format tm x \"ddd\" class,method-added\n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   132
                        "|  /set format tm x \"hhh\" method"),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   133
                (a) -> assertCommand(a, "/se fo tm x \"iii\" method,class", ""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   134
                (a) -> assertCommand(a, "/se fo tm x",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   135
                        "|  /set format tm x \"aaa\" \n" +
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   136
                        "|  /set format tm x \"iii\" class,method"),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   137
                (a) -> assertCommand(a, "/se fo tm x \"jjj\"", ""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   138
                (a) -> assertCommand(a, "/se fo tm x",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   139
                        "|  /set format tm x \"jjj\"")
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   140
        );
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   141
    }
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   142
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   143
    public void testSetFormatSelector() {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   144
        List<ReplTest> tests = new ArrayList<>();
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   145
        tests.add((a) -> assertCommandOutputStartsWith(a, "/set mode ate -quiet",
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   146
                            "|  Created new feedback mode: ate"));
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   147
        tests.add((a) -> assertCommand(a, "/set feedback ate", ""));
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   148
        StringBuilder sb = new StringBuilder();
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   149
        class KindList {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   150
            final String[] values;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   151
            final int matchIndex;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   152
            int current;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   153
            boolean match;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   154
            KindList(String[] values, int matchIndex) {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   155
                this.values = values;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   156
                this.matchIndex = matchIndex;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   157
                this.current = 1 << values.length;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   158
            }
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   159
            boolean next() {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   160
                if (current <= 0) {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   161
                    return false;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   162
                }
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   163
                --current;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   164
                return true;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   165
            }
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   166
            boolean append(boolean ahead) {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   167
                boolean any = false;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   168
                match = false;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   169
                for (int i = values.length - 1; i >= 0 ; --i) {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   170
                    if ((current & (1 << i)) != 0) {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   171
                        match |= i == matchIndex;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   172
                        if (any) {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   173
                            sb.append(",");
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   174
                        } else {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   175
                            if (ahead) {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   176
                                sb.append("-");
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   177
                            }
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   178
                        }
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   179
                        sb.append(values[i]);
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   180
                        any = true;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   181
                    }
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   182
                }
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   183
                match |= !any;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   184
                return ahead || any;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   185
            }
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   186
        }
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   187
        KindList klcase = new KindList(new String[] {"class", "method", "expression", "vardecl"}, 2);
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   188
        while (klcase.next()) {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   189
            KindList klact  = new KindList(new String[] {"added", "modified", "replaced"}, 0);
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   190
            while (klact.next()) {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   191
                KindList klwhen = new KindList(new String[] {"update", "primary"}, 1);
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   192
                while (klwhen.next()) {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   193
                    sb.setLength(0);
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   194
                    klwhen.append(
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   195
                        klact.append(
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   196
                            klcase.append(false)));
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   197
                    boolean match = klcase.match && klact.match && klwhen.match;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   198
                    String select = sb.toString();
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   199
                    String yes = "+++" + select + "+++";
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   200
                    String no  = "---" + select + "---";
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   201
                    String expect = match? yes : no;
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   202
                    tests.add((a) -> assertCommand(a, "/set format ate display '" + no  + "'", ""));
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   203
                    tests.add((a) -> assertCommand(a, "/set format ate display '" + yes + "' " + select, ""));
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   204
                    tests.add((a) -> assertCommand(a, "\"" + select + "\"", expect));
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   205
                }
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   206
            }
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   207
        }
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   208
        tests.add((a) -> assertCommandOutputStartsWith(a, "/set feedback normal", "|  Feedback mode: normal"));
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   209
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   210
        try {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   211
            test(tests.toArray(new ReplTest[tests.size()]));
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   212
        } finally {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   213
            assertCommandCheckOutput(false, "/set feedback normal", s -> {
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   214
            });
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   215
        }
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   216
    }
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   217
38513
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   218
    public void testSetTruncation() {
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   219
        try {
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   220
            test(
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   221
                    (a) -> assertCommandOutputStartsWith(a, "/set feedback normal", ""),
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   222
                    (a) -> assertCommand(a, "String s = java.util.stream.IntStream.range(65, 74)"+
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   223
                            ".mapToObj(i -> \"\"+(char)i).reduce((a,b) -> a + b + a).get()",
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   224
                            "s ==> \"ABACABADABACABAEABACABADABACABAFABACABADABACABAEABACABADABACABAGABACABADABA ..."),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   225
                    (a) -> assertCommandOutputStartsWith(a, "/set mode test -quiet", ""),
38513
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   226
                    (a) -> assertCommandOutputStartsWith(a, "/set feedback test", ""),
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   227
                    (a) -> assertCommand(a, "/set format test display '{type}:{value}' primary", ""),
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   228
                    (a) -> assertCommand(a, "/set truncation test 20", ""),
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   229
                    (a) -> assertCommand(a, "/set truncation test", "|  /set truncation test 20"),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   230
                    (a) -> assertCommandOutputContains(a, "/set truncation", "/set truncation test 20"),
38513
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   231
                    (a) -> assertCommand(a, "/set trunc test 10 varvalue", ""),
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   232
                    (a) -> assertCommand(a, "/set trunc test 3 assignment", ""),
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   233
                    (a) -> assertCommandOutputContains(a, "/set truncation",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   234
                            "/set truncation test 10 varvalue"),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   235
                    (a) -> assertCommandOutputContains(a, "/set truncation test",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   236
                            "/set truncation test 10 varvalue"),
38513
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   237
                    (a) -> assertCommand(a, "String r = s", "String:\"ABACABADABACABA ..."),
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   238
                    (a) -> assertCommand(a, "r", "String:\"ABACA ..."),
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   239
                    (a) -> assertCommand(a, "r=s", "String:\"AB")
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   240
            );
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   241
        } finally {
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   242
            assertCommandCheckOutput(false, "/set feedback normal", s -> {
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   243
            });
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   244
        }
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   245
    }
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   246
38615
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   247
    public void testDefaultTruncation() {
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   248
        test(
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   249
                    (a) -> assertCommand(a, "char[] cs = new char[2000];", null),
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   250
                    (a) -> assertCommand(a, "Arrays.fill(cs, 'A');", ""),
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   251
                    (a) -> assertCommandCheckOutput(a, "String s = new String(cs)",
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   252
                            (s) -> {
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   253
                                assertTrue(s.length() < 120, "Result too long (" + s.length() + ") -- " + s);
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   254
                                assertTrue(s.contains("AAAAAAAAAAAAAAAAAA"), "Bad value: " + s);
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   255
                            }),
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   256
                    (a) -> assertCommandCheckOutput(a, "s",
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   257
                            (s) -> {
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   258
                                assertTrue(s.length() > 300, "Result too short (" + s.length() + ") -- " + s);
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   259
                                assertTrue(s.contains("AAAAAAAAAAAAAAAAAA"), "Bad value: " + s);
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   260
                            }),
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   261
                    (a) -> assertCommandCheckOutput(a, "\"X\" + s",
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   262
                            (s) -> {
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   263
                                assertTrue(s.length() > 300, "Result too short (" + s.length() + ") -- " + s);
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   264
                                assertTrue(s.contains("XAAAAAAAAAAAAAAAAAA"), "Bad value: " + s);
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   265
                            })
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   266
        );
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   267
    }
9221159d84fb 8157261: jshell tool: truncation for expressions is not consistent
rfield
parents: 38539
diff changeset
   268
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   269
    public void testPrompt() {
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   270
        test(
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   271
                (a) -> assertCommand(a, "/set mode tp -quiet", "|  Created new feedback mode: tp"),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   272
                (a) -> assertCommand(a, "/set prompt tp 'aaa' 'bbb'", ""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   273
                (a) -> assertCommand(a, "/set prompt tp",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   274
                        "|  /set prompt tp \"aaa\" \"bbb\""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   275
                (a) -> assertCommandOutputContains(a, "/set prompt",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   276
                        "|  /set prompt tp \"aaa\" \"bbb\""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   277
                (a) -> assertCommand(a, "/set mode -retain tp", ""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   278
                (a) -> assertCommand(a, "/set prompt tp 'ccc' 'ddd'", ""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   279
                (a) -> assertCommand(a, "/set prompt tp",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   280
                        "|  /set prompt tp \"ccc\" \"ddd\""),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   281
                (a) -> assertCommandCheckOutput(a, "/set mode tp",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   282
                        (s) -> {
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   283
                            try {
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   284
                                BufferedReader rdr = new BufferedReader(new StringReader(s));
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   285
                                assertEquals(rdr.readLine(), "|  /set mode tp -quiet",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   286
                                        "|  /set mode tp -quiet");
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   287
                                assertEquals(rdr.readLine(), "|  /set prompt tp \"aaa\" \"bbb\"",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   288
                                        "|  /set prompt tp \"aaa\" \"bbb\"");
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   289
                                String l = rdr.readLine();
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   290
                                while (l.startsWith("|  /set format tp ")) {
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   291
                                    l = rdr.readLine();
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   292
                                }
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   293
                                assertEquals(l, "|  /set mode -retain tp",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   294
                                        "|  /set mode -retain tp");
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   295
                                assertEquals(rdr.readLine(), "|  ",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   296
                                        "|  ");
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   297
                                assertEquals(rdr.readLine(), "|  /set mode tp -quiet",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   298
                                        "|  /set mode tp -quiet");
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   299
                                assertEquals(rdr.readLine(), "|  /set prompt tp \"ccc\" \"ddd\"",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   300
                                        "|  /set prompt tp \"ccc\" \"ddd\"");
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   301
                            } catch (IOException ex) {
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   302
                                fail("threw " + ex);
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   303
                            }
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   304
                        })
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   305
        );
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   306
    }
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   307
37640
42e5136a367c 8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents: 36990
diff changeset
   308
    public void testShowFeedbackModes() {
42e5136a367c 8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents: 36990
diff changeset
   309
        test(
42e5136a367c 8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents: 36990
diff changeset
   310
                (a) -> assertCommandOutputContains(a, "/set feedback", "normal")
42e5136a367c 8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents: 36990
diff changeset
   311
        );
42e5136a367c 8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents: 36990
diff changeset
   312
    }
42e5136a367c 8153551: jshell tool: no longer a mechanism to see current feedback modes
rfield
parents: 36990
diff changeset
   313
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   314
    public void testSetNewModeQuiet() {
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   315
        try {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   316
            test(
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   317
                    (a) -> assertCommandOutputStartsWith(a, "/set mode nmq -quiet normal", "|  Created new feedback mode: nmq"),
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   318
                    (a) -> assertCommand(a, "/set feedback nmq", ""),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   319
                    (a) -> assertCommand(a, "/se mo nmq2 -q nor", ""),
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   320
                    (a) -> assertCommand(a, "/se fee nmq2", ""),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   321
                    (a) -> assertCommand(a, "/set mode nmc -command normal", ""),
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   322
                    (a) -> assertCommandOutputStartsWith(a, "/set feedback nmc", "|  Feedback mode: nmc"),
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   323
                    (a) -> assertCommandOutputStartsWith(a, "/set mode nm -command",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   324
                            "|  Created new feedback mode: nm"),
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   325
                    (a) -> assertCommandOutputStartsWith(a, "/set feedback nm", "|  Feedback mode: nm"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   326
                    (a) -> assertCommandOutputStartsWith(a, "/set feedback normal", "|  Feedback mode: normal")
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   327
            );
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   328
        } finally {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   329
            assertCommandCheckOutput(false, "/set feedback normal", s -> {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   330
            });
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   331
        }
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   332
    }
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   333
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   334
    public void testSetError() {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   335
        try {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   336
            test(
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   337
                    (a) -> assertCommandOutputStartsWith(a, "/set mode tee -command foo",
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   338
                            "|  Does not match any current feedback mode: foo"),
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   339
                    (a) -> assertCommandOutputStartsWith(a, "/set mode tee -quiet flurb",
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   340
                            "|  Does not match any current feedback mode: flurb"),
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   341
                    (a) -> assertCommandOutputStartsWith(a, "/set mode -command tee",
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   342
                            "|  Created new feedback mode: tee"),
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   343
                    (a) -> assertCommandOutputStartsWith(a, "/set mode verbose -command",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   344
                            "|  Mode to be created already exists: verbose"),
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   345
                    (a) -> assertCommandOutputStartsWith(a, "/set mode te -command normal",
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   346
                            "|  Created new feedback mode: te"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   347
                    (a) -> assertCommand(a, "/set format te errorpre 'ERROR: '", ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   348
                    (a) -> assertCommandOutputStartsWith(a, "/set feedback te",
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   349
                            ""),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   350
                    (a) -> assertCommandOutputStartsWith(a, "/set xyz",
36990
ec0b843a7af5 8147515: JShell: Internationalize
rfield
parents: 36778
diff changeset
   351
                            "ERROR: Invalid '/set' argument: xyz"),
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   352
                    (a) -> assertCommandOutputStartsWith(a, "/set f",
36990
ec0b843a7af5 8147515: JShell: Internationalize
rfield
parents: 36778
diff changeset
   353
                            "ERROR: Ambiguous sub-command argument to '/set': f"),
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   354
                    (a) -> assertCommandOutputStartsWith(a, "/set feedback",
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   355
                            "|  /set feedback te"),
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   356
                    (a) -> assertCommandOutputStartsWith(a, "/set feedback xyz",
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   357
                            "ERROR: Does not match any current feedback mode"),
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   358
                    (a) -> assertCommandOutputStartsWith(a, "/set feed",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   359
                            "|  /set feedback te"),
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   360
                    (a) -> assertCommandOutputStartsWith(a, "/set format xyz",
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   361
                            "ERROR: Does not match any current feedback mode"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   362
                    (a) -> assertCommandOutputStartsWith(a, "/set format t",
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   363
                            "ERROR: Matches more then one current feedback mode: t"),
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   364
                    (a) -> assertCommandOutputStartsWith(a, "/set format qqq",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   365
                            "ERROR: Does not match any current feedback mode: qqq"),
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   366
                    (a) -> assertCommandOutputStartsWith(a, "/set format te fld",
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   367
                            "ERROR: Expected a field name:"),
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   368
                    (a) -> assertCommandOutputStartsWith(a, "/set format te fld aaa",
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   369
                            "ERROR: Format 'aaa' must be quoted"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   370
                    (a) -> assertCommandOutputStartsWith(a, "/set format te fld 'aaa' frog",
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   371
                            "ERROR: Not a valid selector"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   372
                    (a) -> assertCommandOutputStartsWith(a, "/set format te fld 'aaa' import-frog",
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   373
                            "ERROR: Not a valid selector"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   374
                    (a) -> assertCommandOutputStartsWith(a, "/set format te fld 'aaa' import-import",
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   375
                            "ERROR: Selector kind in multiple sections of"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   376
                    (a) -> assertCommandOutputStartsWith(a, "/set format te fld 'aaa' import,added",
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   377
                            "ERROR: Different selector kinds in same sections of"),
38513
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   378
                    (a) -> assertCommandOutputStartsWith(a, "/set trunc te 20x",
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   379
                            "ERROR: Truncation length must be an integer: 20x"),
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   380
                    (a) -> assertCommandOutputStartsWith(a, "/set trunc qaz",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   381
                            "ERROR: Does not match any current feedback mode: qaz -- /set trunc qaz"),
38513
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   382
                    (a) -> assertCommandOutputStartsWith(a, "/set truncation te 111 import,added",
0ae85633d035 8154812: jshell tool: value printing truncation
rfield
parents: 37640
diff changeset
   383
                            "ERROR: Different selector kinds in same sections of"),
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   384
                    (a) -> assertCommandOutputContains(a, "/set mode",
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   385
                            "|  /set truncation verbose"),
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   386
                    (a) -> assertCommandOutputStartsWith(a, "/set mode -command",
38539
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   387
                            "ERROR: Missing the feedback mode"),
71874886920f 8157517: jshell tool: allow undoing operations
rfield
parents: 38531
diff changeset
   388
                    (a) -> assertCommandOutputStartsWith(a, "/set mode x -quiet y",
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   389
                            "ERROR: Does not match any current feedback mode"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   390
                    (a) -> assertCommandOutputStartsWith(a, "/set prompt",
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   391
                            "|  /set prompt"),
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   392
                    (a) -> assertCommandOutputStartsWith(a, "/set prompt te",
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   393
                            "|  /set prompt te "),
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   394
                    (a) -> assertCommandOutputStartsWith(a, "/set prompt te aaa xyz",
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   395
                            "ERROR: Format 'aaa' must be quoted"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   396
                    (a) -> assertCommandOutputStartsWith(a, "/set prompt te 'aaa' xyz",
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   397
                            "ERROR: Format 'xyz' must be quoted"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   398
                    (a) -> assertCommandOutputStartsWith(a, "/set prompt te aaa",
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   399
                            "ERROR: Format 'aaa' must be quoted"),
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   400
                    (a) -> assertCommandOutputStartsWith(a, "/set prompt te 'aaa'",
41635
cb3d04878117 8163840: jshell tool: provide way to display configuration settings
rfield
parents: 38615
diff changeset
   401
                            "ERROR: Continuation prompt required"),
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   402
                    (a) -> assertCommandOutputStartsWith(a, "/set feedback normal",
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   403
                            "|  Feedback mode: normal")
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   404
            );
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   405
        } finally {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   406
            assertCommandCheckOutput(false, "/set feedback normal", s -> {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   407
            });
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   408
        }
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   409
    }
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   410
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   411
    public void testSetHelp() {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   412
        try {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   413
            test(
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   414
                    (a) -> assertCommandOutputContains(a, "/help /set", "command to launch"),
36718
bf40906bf49d 8151755: jshell tool: properly cover resolution issues in output configuration
rfield
parents: 36526
diff changeset
   415
                    (a) -> assertCommandOutputContains(a, "/help /set format", "display"),
36494
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   416
                    (a) -> assertCommandOutputContains(a, "/hel /se for", "vardecl"),
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   417
                    (a) -> assertCommandOutputContains(a, "/help /set editor", "temporary file")
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   418
            );
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   419
        } finally {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   420
            assertCommandCheckOutput(false, "/set feedback normal", s -> {
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   421
            });
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   422
        }
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   423
    }
4175f47b2a50 8148316: jshell tool: Configurable output format
rfield
parents:
diff changeset
   424
}