langtools/test/jdk/jshell/StartOptionTest.java
changeset 37745 4b6b59f8e327
parent 36993 e00f4be3a47d
child 38608 691b607bbcd6
equal deleted inserted replaced
37744:bf4fd5e022c5 37745:4b6b59f8e327
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test 8151754
    26  * @summary Testing start-up options.
    26  * @summary Testing start-up options.
    27  * @modules jdk.compiler/com.sun.tools.javac.api
    27  * @modules jdk.compiler/com.sun.tools.javac.api
    28  *          jdk.compiler/com.sun.tools.javac.main
    28  *          jdk.compiler/com.sun.tools.javac.main
    29  *          jdk.jdeps/com.sun.tools.javap
    29  *          jdk.jdeps/com.sun.tools.javap
    30  *          jdk.jshell/jdk.internal.jshell.tool
    30  *          jdk.jshell/jdk.internal.jshell.tool
    32  * @build Compiler toolbox.ToolBox
    32  * @build Compiler toolbox.ToolBox
    33  * @run testng StartOptionTest
    33  * @run testng StartOptionTest
    34  */
    34  */
    35 
    35 
    36 import java.io.ByteArrayOutputStream;
    36 import java.io.ByteArrayOutputStream;
       
    37 import java.io.OutputStream;
    37 import java.io.PrintStream;
    38 import java.io.PrintStream;
    38 import java.nio.charset.StandardCharsets;
    39 import java.nio.charset.StandardCharsets;
    39 import java.nio.file.Path;
    40 import java.nio.file.Path;
    40 import java.util.Locale;
    41 import java.util.Locale;
    41 import java.util.function.Consumer;
    42 import java.util.function.Consumer;
    45 import org.testng.annotations.BeforeMethod;
    46 import org.testng.annotations.BeforeMethod;
    46 import org.testng.annotations.Test;
    47 import org.testng.annotations.Test;
    47 
    48 
    48 import static org.testng.Assert.assertEquals;
    49 import static org.testng.Assert.assertEquals;
    49 import static org.testng.Assert.assertTrue;
    50 import static org.testng.Assert.assertTrue;
       
    51 import static org.testng.Assert.fail;
    50 
    52 
    51 @Test
    53 @Test
    52 public class StartOptionTest {
    54 public class StartOptionTest {
    53 
    55 
    54     private ByteArrayOutputStream out;
    56     private ByteArrayOutputStream out;
    55     private ByteArrayOutputStream err;
    57     private ByteArrayOutputStream err;
    56 
    58 
    57     private JShellTool getShellTool() {
    59     private JShellTool getShellTool() {
    58         return new JShellTool(null, new PrintStream(out), new PrintStream(err), null, null, null,
    60         class NoOutputAllowedStream extends OutputStream {
    59                               null, new ReplToolTesting.MemoryPreferences(),
    61             private final String label;
    60                               Locale.ROOT);
    62             NoOutputAllowedStream(String label) {
       
    63                this.label = label;
       
    64             }
       
    65             @Override
       
    66             public void write(int b) { fail("Unexpected output to: " + label); }
       
    67         }
       
    68         return new JShellTool(
       
    69                 new TestingInputStream(),
       
    70                 new PrintStream(out),
       
    71                 new PrintStream(err),
       
    72                 new PrintStream(new NoOutputAllowedStream("console")),
       
    73                 new TestingInputStream(),
       
    74                 new PrintStream(new NoOutputAllowedStream("userout")),
       
    75                 new PrintStream(new NoOutputAllowedStream("usererr")),
       
    76                 new ReplToolTesting.MemoryPreferences(),
       
    77                 Locale.ROOT);
    61     }
    78     }
    62 
    79 
    63     private String getOutput() {
    80     private String getOutput() {
    64         byte[] bytes = out.toByteArray();
    81         byte[] bytes = out.toByteArray();
    65         out.reset();
    82         out.reset();
   131             start("", "Argument to -classpath missing.", cp);
   148             start("", "Argument to -classpath missing.", cp);
   132         }
   149         }
   133     }
   150     }
   134 
   151 
   135     @Test
   152     @Test
       
   153     public void testNegFeedbackOption() throws Exception {
       
   154         start("", "Argument to -feedback missing. Mode required.", "-feedback");
       
   155         start("", "Does not match any current feedback mode: blorp -- -feedback blorp", "-feedback", "blorp");
       
   156     }
       
   157 
       
   158     @Test
   136     public void testVersion() throws Exception {
   159     public void testVersion() throws Exception {
   137         start(s -> assertTrue(s.startsWith("jshell")), null, "-version");
   160         start(s -> assertTrue(s.startsWith("jshell")), null, "-version");
   138     }
   161     }
   139 
   162 
   140     @AfterMethod
   163     @AfterMethod