8160089: jshell tool: use new double-dash long-form command-line options

Reviewed-by: jlahoda
This commit is contained in:
Robert Field 2016-08-22 19:31:37 -07:00
parent 20e0d40bc1
commit f39e912857
12 changed files with 201 additions and 156 deletions

View File

@ -94,12 +94,16 @@ import java.util.ResourceBundle;
import java.util.Spliterators;
import java.util.function.Function;
import java.util.function.Supplier;
import jdk.internal.joptsimple.*;
import jdk.internal.jshell.tool.Feedback.FormatAction;
import jdk.internal.jshell.tool.Feedback.FormatCase;
import jdk.internal.jshell.tool.Feedback.FormatErrors;
import jdk.internal.jshell.tool.Feedback.FormatResolve;
import jdk.internal.jshell.tool.Feedback.FormatUnresolved;
import jdk.internal.jshell.tool.Feedback.FormatWhen;
import static java.util.Arrays.asList;
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toList;
import static jdk.jshell.Snippet.SubKind.VAR_VALUE_SUBKIND;
import static java.util.stream.Collectors.toMap;
@ -515,82 +519,91 @@ public class JShellTool implements MessageHandler {
* @return the list of files to be loaded
*/
private List<String> processCommandArgs(String[] args) {
List<String> loadList = new ArrayList<>();
Iterator<String> ai = Arrays.asList(args).iterator();
while (ai.hasNext()) {
String arg = ai.next();
if (arg.startsWith("-")) {
switch (arg) {
case "-classpath":
case "-cp":
if (cmdlineClasspath != null) {
startmsg("jshell.err.opt.classpath.conflict");
return null;
}
if (ai.hasNext()) {
cmdlineClasspath = ai.next();
} else {
startmsg("jshell.err.opt.classpath.arg");
return null;
}
break;
case "-help":
printUsage();
return null;
case "-version":
cmdout.printf("jshell %s\n", version());
return null;
case "-fullversion":
cmdout.printf("jshell %s\n", fullVersion());
return null;
case "-feedback":
if (ai.hasNext()) {
commandLineFeedbackMode = ai.next();
} else {
startmsg("jshell.err.opt.feedback.arg");
return null;
}
break;
case "-q":
commandLineFeedbackMode = "concise";
break;
case "-qq":
commandLineFeedbackMode = "silent";
break;
case "-v":
commandLineFeedbackMode = "verbose";
break;
case "-startup":
if (startup != null) {
startmsg("jshell.err.opt.startup.one");
return null;
}
startup = readFile(ai.hasNext()? ai.next() : null, "-startup");
if (startup == null) {
return null;
}
break;
case "-nostartup":
if (startup != null) {
startmsg("jshell.err.opt.startup.one");
return null;
}
startup = "";
break;
default:
if (arg.startsWith("-R")) {
remoteVMOptions.add(arg.substring(2));
break;
}
startmsg("jshell.err.opt.unknown", arg);
printUsage();
return null;
}
OptionParser parser = new OptionParser();
OptionSpec<String> cp = parser.accepts("class-path").withRequiredArg();
OptionSpec<String> st = parser.accepts("startup").withRequiredArg();
parser.acceptsAll(asList("n", "no-startup"));
OptionSpec<String> fb = parser.accepts("feedback").withRequiredArg();
parser.accepts("q");
parser.accepts("s");
parser.accepts("v");
OptionSpec<String> r = parser.accepts("R").withRequiredArg();
parser.acceptsAll(asList("h", "help"));
parser.accepts("version");
parser.accepts("full-version");
NonOptionArgumentSpec<String> loadFileSpec = parser.nonOptions();
OptionSet options;
try {
options = parser.parse(args);
} catch (OptionException ex) {
if (ex.options().isEmpty()) {
startmsg("jshell.err.opt.invalid", stream(args).collect(joining(", ")));
} else {
loadList.add(arg);
boolean isKnown = parser.recognizedOptions().containsKey(ex.options().iterator().next());
startmsg(isKnown
? "jshell.err.opt.arg"
: "jshell.err.opt.unknown",
ex.options()
.stream()
.collect(joining(", ")));
}
return null;
}
return loadList;
if (options.has("help")) {
printUsage();
return null;
}
if (options.has("version")) {
cmdout.printf("jshell %s\n", version());
return null;
}
if (options.has("full-version")) {
cmdout.printf("jshell %s\n", fullVersion());
return null;
}
if (options.has(cp)) {
List<String> cps = options.valuesOf(cp);
if (cps.size() > 1) {
startmsg("jshell.err.opt.one", "--class-path");
return null;
}
cmdlineClasspath = cps.get(0);
}
if (options.has(st)) {
List<String> sts = options.valuesOf(st);
if (sts.size() != 1 || options.has("no-startup")) {
startmsg("jshell.err.opt.startup.one");
return null;
}
startup = readFile(sts.get(0), "--startup");
if (startup == null) {
return null;
}
} else if (options.has("no-startup")) {
startup = "";
}
if ((options.valuesOf(fb).size() +
(options.has("q") ? 1 : 0) +
(options.has("s") ? 1 : 0) +
(options.has("v") ? 1 : 0)) > 1) {
startmsg("jshell.err.opt.feedback.one");
return null;
} else if (options.has(fb)) {
commandLineFeedbackMode = options.valueOf(fb);
} else if (options.has("q")) {
commandLineFeedbackMode = "concise";
} else if (options.has("s")) {
commandLineFeedbackMode = "silent";
} else if (options.has("v")) {
commandLineFeedbackMode = "verbose";
}
if (options.has(r)) {
remoteVMOptions = options.valuesOf(r);
}
return options.valuesOf(loadFileSpec);
}
private void printUsage() {
@ -686,7 +699,7 @@ public class JShellTool implements MessageHandler {
}
if (commandLineFeedbackMode != null) {
// The feedback mode to use was specified on the command line, use it
if (!feedback.setFeedback(initmh, new ArgTokenizer("-feedback", commandLineFeedbackMode))) {
if (!feedback.setFeedback(initmh, new ArgTokenizer("--feedback", commandLineFeedbackMode))) {
regenerateOnDeath = false;
}
commandLineFeedbackMode = null;

View File

@ -26,10 +26,11 @@
jshell.msg.welcome =\
Welcome to JShell -- Version {0}\n\
For an introduction type: /help intro\n
jshell.err.opt.classpath.conflict = Conflicting -classpath option.
jshell.err.opt.classpath.arg = Argument to -classpath missing.
jshell.err.opt.feedback.arg = Argument to -feedback missing. Mode required.
jshell.err.opt.startup.one = Only one -startup or -nostartup option may be used.
jshell.err.opt.arg = Argument to {0} missing.
jshell.err.opt.invalid = Invalid options: {0}.
jshell.err.opt.one = Only one {0} option may be used.
jshell.err.opt.startup.one = Only one --startup or --no-startup option may be used.
jshell.err.opt.feedback.one = Only one feedback option (--feedback, -q, -s, or -v) may be used.
jshell.err.opt.unknown = Unknown option: {0}
jshell.msg.terminated =\
@ -148,22 +149,21 @@ jshell.console.incomplete = \nResults may be incomplete; try again later for com
help.usage = \
Usage: jshell <options> <load files>\n\
where possible options include:\n\
\ -classpath <path> Specify where to find user class files\n\
\ -cp <path> Specify where to find user class files\n\
\ -startup <file> One run replacement for the start-up definitions\n\
\ -nostartup Do not run the start-up definitions\n\
\ -feedback <mode> Specify the initial feedback mode. The mode may be\n\
\ predefined (silent, concise, normal, or verbose) or\n\
\ previously user-defined\n\
\ -q Quiet feedback. Same as: -feedback concise\n\
\ -qq Really quiet feedback. Same as: -feedback silent\n\
\ -v Verbose feedback. Same as: -feedback verbose\n\
\ -J<flag> Pass <flag> directly to the runtime system.\n\
\ Use one -J for each runtime flag or flag argument\n\
\ -R<flag> Pass <flag> to the remote runtime system.\n\
\ Use one -R for each remote flag or flag argument\n\
\ -help Print this synopsis of standard options\n\
\ -version Version information\n
\ --class-path <path> Specify where to find user class files\n\
\ --startup <file> One run replacement for the start-up definitions\n\
\ --no-startup Do not run the start-up definitions\n\
\ --feedback <mode> Specify the initial feedback mode. The mode may be\n\
\ predefined (silent, concise, normal, or verbose) or\n\
\ previously user-defined\n\
\ -q Quiet feedback. Same as: --feedback concise\n\
\ -s Really quiet feedback. Same as: --feedback silent\n\
\ -v Verbose feedback. Same as: --feedback verbose\n\
\ -J<flag> Pass <flag> directly to the runtime system.\n\
\ Use one -J for each runtime flag or flag argument\n\
\ -R<flag> Pass <flag> to the remote runtime system.\n\
\ Use one -R for each remote flag or flag argument\n\
\ --help Print this synopsis of standard options\n\
\ --version Version information\n
help.list.summary = list the source you have typed
help.list.args = [<name or id>|-all|-start]

View File

@ -34,6 +34,7 @@ module jdk.jshell {
requires java.prefs;
requires jdk.compiler;
requires jdk.internal.le;
requires jdk.internal.opt;
requires jdk.jdi;
exports jdk.jshell;

View File

@ -58,7 +58,7 @@ public class CommandCompletionTest extends ReplToolTesting {
}
public void testList() {
test(false, new String[] {"-nostartup"},
test(false, new String[] {"--no-startup"},
a -> assertCompletion(a, "/l|", false, "/list "),
a -> assertCompletion(a, "/list |", false, "-all ", "-history ", "-start "),
a -> assertCompletion(a, "/list -h|", false, "-history "),
@ -70,7 +70,7 @@ public class CommandCompletionTest extends ReplToolTesting {
}
public void testDrop() {
test(false, new String[] {"-nostartup"},
test(false, new String[] {"--no-startup"},
a -> assertCompletion(a, "/d|", false, "/drop "),
a -> assertClass(a, "class cTest {}", "class", "cTest"),
a -> assertMethod(a, "int mTest() { return 0; }", "()I", "mTest"),
@ -81,7 +81,7 @@ public class CommandCompletionTest extends ReplToolTesting {
}
public void testEdit() {
test(false, new String[]{"-nostartup"},
test(false, new String[]{"--no-startup"},
a -> assertCompletion(a, "/e|", false, "/edit ", "/exit "),
a -> assertCompletion(a, "/ed|", false, "/edit "),
a -> assertClass(a, "class cTest {}", "class", "cTest"),

View File

@ -42,7 +42,7 @@ public abstract class EditorTestBase extends ReplToolTesting {
public abstract void shutdownEditor();
public void testEditor(ReplTest... tests) {
testEditor(false, new String[]{"-nostartup"}, tests);
testEditor(false, new String[]{"--no-startup"}, tests);
}
public void testEditor(boolean defaultStartup, String[] args, ReplTest... tests) {
@ -71,7 +71,7 @@ public abstract class EditorTestBase extends ReplToolTesting {
@Test
public void testEditNegative() {
for (String edit : new String[] {"/ed", "/edit"}) {
test(new String[]{"-nostartup"},
test(new String[]{"--no-startup"},
a -> assertCommandOutputStartsWith(a, edit + " 1",
"| No such snippet: 1"),
a -> assertCommandOutputStartsWith(a, edit + " unknown",

View File

@ -203,7 +203,7 @@ public class ExternalEditorTest extends EditorTestBase {
@Test(enabled = false) // TODO 8159229
public void testRemoveTempFile() {
test(new String[]{"-nostartup"},
test(new String[]{"--no-startup"},
a -> assertCommandCheckOutput(a, "/set editor " + executionScript,
assertStartsWith("| Editor set to: " + executionScript)),
a -> assertVariable(a, "int", "a", "0", "0"),

View File

@ -22,7 +22,7 @@
*/
/*
* @test 8151754 8080883
* @test 8151754 8080883 8160089
* @summary Testing start-up options.
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
@ -106,53 +106,68 @@ public class StartOptionTest {
@Test
public void testUsage() throws Exception {
start(s -> {
assertTrue(s.split("\n").length >= 7, "Not enough usage lines: " + s);
assertTrue(s.startsWith("Usage: jshell <options>"), "Unexpect usage start: " + s);
}, null, "-help");
for (String opt : new String[]{"-h", "--help"}) {
start(s -> {
assertTrue(s.split("\n").length >= 7, "Not enough usage lines: " + s);
assertTrue(s.startsWith("Usage: jshell <options>"), "Unexpect usage start: " + s);
}, null, opt);
}
}
@Test
public void testUnknown() throws Exception {
start(s -> {
assertTrue(s.split("\n").length >= 7, "Not enough usage lines (unknown): " + s);
assertTrue(s.startsWith("Usage: jshell <options>"), "Unexpect usage start (unknown): " + s);
}, s -> assertEquals(s.trim(), "Unknown option: -unknown"), "-unknown");
start(s -> { },
s -> assertEquals(s.trim(), "Unknown option: u"), "-unknown");
start(s -> { },
s -> assertEquals(s.trim(), "Unknown option: unknown"), "--unknown");
}
public void testStartup() throws Exception {
Compiler compiler = new Compiler();
Path p = compiler.getPath("file.txt");
compiler.writeToFile(p);
start("", "'-startup' requires a filename argument.", "-startup");
start("", "Only one -startup or -nostartup option may be used.", "-startup", p.toString(), "-startup", p.toString());
start("", "Only one -startup or -nostartup option may be used.", "-nostartup", "-startup", p.toString());
start("", "Only one -startup or -nostartup option may be used.", "-startup", p.toString(), "-nostartup");
start("", "Only one -startup or -nostartup option may be used.", "-nostartup", "-nostartup");
start("", "Only one -startup or -nostartup option may be used.", "-nostartup", "-startup");
start("", "Argument to startup missing.", "--startup");
start("", "Only one --startup or --no-startup option may be used.", "--startup", p.toString(), "--startup", p.toString());
start("", "Only one --startup or --no-startup option may be used.", "--no-startup", "--startup", p.toString());
start("", "Only one --startup or --no-startup option may be used.", "--startup", p.toString(), "--no-startup");
start("", "Argument to startup missing.", "--no-startup", "--startup");
}
public void testStartupUnknown() throws Exception {
start("", "File 'UNKNOWN' for '-startup' is not found.", "-startup", "UNKNOWN");
start("", "File 'UNKNOWN' for '--startup' is not found.", "--startup", "UNKNOWN");
}
@Test
public void testClasspath() throws Exception {
for (String cp : new String[] {"-cp", "-classpath"}) {
start("", "Conflicting -classpath option.", cp, ".", "-classpath", ".");
start("", "Argument to -classpath missing.", cp);
for (String cp : new String[] {"--class-path"}) {
start("", "Only one --class-path option may be used.", cp, ".", "--class-path", ".");
start("", "Argument to class-path missing.", cp);
}
}
@Test
public void testFeedbackOptionConflict() throws Exception {
start("", "Only one feedback option (--feedback, -q, -s, or -v) may be used.",
"--feedback", "concise", "--feedback", "verbose");
start("", "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "--feedback", "concise", "-s");
start("", "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "--feedback", "verbose", "-q");
start("", "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "--feedback", "concise", "-v");
start("", "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-v", "--feedback", "concise");
start("", "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-q", "-v");
start("", "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-s", "-v");
start("", "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-v", "-q");
start("", "Only one feedback option (--feedback, -q, -s, or -v) may be used.", "-q", "-s");
}
@Test
public void testNegFeedbackOption() throws Exception {
start("", "Argument to -feedback missing. Mode required.", "-feedback");
start("", "Does not match any current feedback mode: blorp -- -feedback blorp", "-feedback", "blorp");
start("", "Argument to feedback missing.", "--feedback");
start("", "Does not match any current feedback mode: blorp -- --feedback blorp", "--feedback", "blorp");
}
@Test
public void testVersion() throws Exception {
start(s -> assertTrue(s.startsWith("jshell"), "unexpected version: " + s), null, "-version");
start(s -> assertTrue(s.startsWith("jshell"), "unexpected version: " + s), null, "--version");
}
@AfterMethod

View File

@ -97,7 +97,7 @@ public class ToolBasicTest extends ReplToolTesting {
public void testInterrupt() {
ReplTest interrupt = (a) -> assertCommand(a, "\u0003", "");
for (String s : new String[] { "", "\u0003" }) {
test(false, new String[]{"-nostartup"},
test(false, new String[]{"--no-startup"},
(a) -> assertCommand(a, "int a = 2 +" + s, ""),
interrupt,
(a) -> assertCommand(a, "int a\u0003", ""),
@ -190,7 +190,7 @@ public class ToolBasicTest extends ReplToolTesting {
}
public void testRerun() {
test(false, new String[] {"-nostartup"},
test(false, new String[] {"--no-startup"},
(a) -> assertCommand(a, "/0", "| No such command or snippet id: /0\n| Type /help for help."),
(a) -> assertCommand(a, "/5", "| No such command or snippet id: /5\n| Type /help for help.")
);
@ -226,7 +226,7 @@ public class ToolBasicTest extends ReplToolTesting {
tests.add((a) -> assertCommandCheckOutput(a, "/-" + (2 * finalI + 1), check));
}
tests.add((a) -> assertCommandCheckOutput(a, "/!", assertStartsWith("int a = 0;")));
test(false, new String[]{"-nostartup"},
test(false, new String[]{"--no-startup"},
tests.toArray(new ReplTest[tests.size()]));
}
@ -243,7 +243,7 @@ public class ToolBasicTest extends ReplToolTesting {
Path startup = compiler.getPath("StartupFileOption/startup.txt");
compiler.writeToFile(startup, "int assertionCount = 0;\n" + // id: s1
"void add(int n) { assertionCount += n; }");
test(new String[]{"-startup", startup.toString()},
test(new String[]{"--startup", startup.toString()},
(a) -> assertCommand(a, "add(1)", ""), // id: 1
(a) -> assertCommandCheckOutput(a, "add(ONE)", s -> assertEquals(s.split("\n")[0], "| Error:")), // id: e1
(a) -> assertVariable(a, "int", "ONE", "1", "1"),
@ -252,7 +252,7 @@ public class ToolBasicTest extends ReplToolTesting {
assertRerun.apply("/s1").apply("int assertionCount = 0;", 0), assertVariables
);
test(false, new String[] {"-nostartup"},
test(false, new String[] {"--no-startup"},
(a) -> assertCommand(a, "/s1", "| No such command or snippet id: /s1\n| Type /help for help."),
(a) -> assertCommand(a, "/1", "| No such command or snippet id: /1\n| Type /help for help."),
(a) -> assertCommand(a, "/e1", "| No such command or snippet id: /e1\n| Type /help for help.")
@ -268,10 +268,7 @@ public class ToolBasicTest extends ReplToolTesting {
(a) -> assertCommand(a, "/classpath " + classpath, String.format("| Path '%s' added to classpath", classpath)),
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A")
);
test(new String[] { "-cp", classpath.toString() },
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A")
);
test(new String[] { "-classpath", classpath.toString() },
test(new String[] { "--class-path", classpath.toString() },
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A")
);
}
@ -287,10 +284,7 @@ public class ToolBasicTest extends ReplToolTesting {
(a) -> assertCommand(a, "/classpath " + jarPath, String.format("| Path '%s' added to classpath", jarPath)),
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A")
);
test(new String[] { "-cp", jarPath.toString() },
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A")
);
test(new String[] { "-classpath", jarPath.toString() },
test(new String[] { "--class-path", jarPath.toString() },
(a) -> evaluateExpression(a, "pkg.A", "new pkg.A();", "A")
);
}
@ -300,10 +294,10 @@ public class ToolBasicTest extends ReplToolTesting {
Compiler compiler = new Compiler();
Path startup = compiler.getPath("StartupFileOption/startup.txt");
compiler.writeToFile(startup, "class A { public String toString() { return \"A\"; } }");
test(new String[]{"-startup", startup.toString()},
test(new String[]{"--startup", startup.toString()},
(a) -> evaluateExpression(a, "A", "new A()", "A")
);
test(new String[]{"-nostartup"},
test(new String[]{"--no-startup"},
(a) -> assertCommandCheckOutput(a, "printf(\"\")", assertStartsWith("| Error:\n| cannot find symbol"))
);
test(
@ -550,7 +544,7 @@ public class ToolBasicTest extends ReplToolTesting {
}
public void testHistoryReference() {
test(false, new String[]{"-nostartup"},
test(false, new String[]{"--no-startup"},
a -> assertCommand(a, "System.err.println(1)", "", "", null, "", "1\n"),
a -> assertCommand(a, "System.err.println(2)", "", "", null, "", "2\n"),
a -> assertCommand(a, "/-2", "System.err.println(1)", "", null, "", "1\n"),

View File

@ -88,7 +88,7 @@ public class ToolCommandOptionTest extends ReplToolTesting {
}
public void dropTest() {
test(false, new String[]{"-nostartup"},
test(false, new String[]{"--no-startup"},
(a) -> assertCommand(a, "int x = 5;",
"x ==> 5"),
(a) -> assertCommand(a, "x",

View File

@ -44,7 +44,7 @@ import static org.testng.Assert.assertTrue;
public class ToolLocaleMessageTest extends ReplToolTesting {
void testLocale(ReplTest... tests) {
test(Locale.getDefault(), false, new String[]{"-nostartup"}, "", tests);
test(Locale.getDefault(), false, new String[]{"--no-startup"}, "", tests);
}
void assertCommandOK(boolean after, String cmd, String... contains) {

View File

@ -90,7 +90,7 @@ public class ToolReloadTest extends ReplToolTesting {
}
public void testReloadDrop() {
test(false, new String[]{"-nostartup"},
test(false, new String[]{"--no-startup"},
a -> assertVariable(a, "int", "a"),
a -> dropVariable(a, "/dr 1", "int a = 0", "| dropped variable a"),
a -> assertMethod(a, "int b() { return 0; }", "()I", "b"),
@ -113,7 +113,7 @@ public class ToolReloadTest extends ReplToolTesting {
}
public void testReloadQuiet() {
test(false, new String[]{"-nostartup"},
test(false, new String[]{"--no-startup"},
a -> assertVariable(a, "int", "a"),
a -> dropVariable(a, "/dr 1", "int a = 0", "| dropped variable a"),
a -> assertMethod(a, "int b() { return 0; }", "()I", "b"),
@ -130,7 +130,7 @@ public class ToolReloadTest extends ReplToolTesting {
}
public void testReloadRepeat() {
test(false, new String[]{"-nostartup"},
test(false, new String[]{"--no-startup"},
(a) -> assertVariable(a, "int", "c", "7", "7"),
(a) -> assertCommand(a, "++c", null),
(a) -> assertCommand(a, "/!", null),
@ -150,7 +150,7 @@ public class ToolReloadTest extends ReplToolTesting {
}
public void testReloadIgnore() {
test(false, new String[]{"-nostartup"},
test(false, new String[]{"--no-startup"},
(a) -> assertCommand(a, "(-)", null),
(a) -> assertCommand(a, "/list", null),
(a) -> assertCommand(a, "/history", null),
@ -201,13 +201,13 @@ public class ToolReloadTest extends ReplToolTesting {
}
public void testReloadExitRestore() {
test(false, new String[]{"-nostartup"},
test(false, new String[]{"--no-startup"},
(a) -> assertVariable(a, "int", "x", "5", "5"),
(a) -> assertMethod(a, "int m(int z) { return z * z; }",
"(int)int", "m"),
(a) -> evaluateExpression(a, "int", "m(x)", "25")
);
test(false, new String[]{"-nostartup"},
test(false, new String[]{"--no-startup"},
(a) -> assertCommand(a, "/reload -restore",
"| Restarting and restoring from previous state.\n" +
"-: int x = 5;\n" +

View File

@ -23,7 +23,7 @@
/*
* @test
* @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024
* @bug 8153716 8143955 8151754 8150382 8153920 8156910 8131024 8160089
* @summary Simple jshell tool tests
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.main
@ -209,7 +209,7 @@ public class ToolSimpleTest extends ReplToolTesting {
}
public void testDrop() {
test(false, new String[]{"-nostartup"},
test(false, new String[]{"--no-startup"},
a -> assertVariable(a, "int", "a"),
a -> dropVariable(a, "/drop 1", "int a = 0", "| dropped variable a"),
a -> assertMethod(a, "int b() { return 0; }", "()I", "b"),
@ -223,7 +223,7 @@ public class ToolSimpleTest extends ReplToolTesting {
a -> assertCommandCheckOutput(a, "/types", assertClasses()),
a -> assertCommandCheckOutput(a, "/imports", assertImports())
);
test(false, new String[]{"-nostartup"},
test(false, new String[]{"--no-startup"},
a -> assertVariable(a, "int", "a"),
a -> dropVariable(a, "/drop a", "int a = 0", "| dropped variable a"),
a -> assertMethod(a, "int b() { return 0; }", "()I", "b"),
@ -238,7 +238,7 @@ public class ToolSimpleTest extends ReplToolTesting {
}
public void testDropNegative() {
test(false, new String[]{"-nostartup"},
test(false, new String[]{"--no-startup"},
a -> assertCommandOutputStartsWith(a, "/drop 0", "| No such snippet: 0"),
a -> assertCommandOutputStartsWith(a, "/drop a", "| No such snippet: a"),
a -> assertCommandCheckOutput(a, "/drop",
@ -462,20 +462,20 @@ public class ToolSimpleTest extends ReplToolTesting {
}
public void testOptionQ() {
test(new String[]{"-q", "-nostartup"},
test(new String[]{"-q", "--no-startup"},
(a) -> assertCommand(a, "1+1", "$1 ==> 2"),
(a) -> assertCommand(a, "int x = 5", "")
);
}
public void testOptionQq() {
test(new String[]{"-qq", "-nostartup"},
public void testOptionS() {
test(new String[]{"-s", "--no-startup"},
(a) -> assertCommand(a, "1+1", "")
);
}
public void testOptionV() {
test(new String[]{"-v", "-nostartup"},
test(new String[]{"-v", "--no-startup"},
(a) -> assertCommand(a, "1+1",
"$1 ==> 2\n" +
"| created scratch variable $1 : int")
@ -483,14 +483,36 @@ public class ToolSimpleTest extends ReplToolTesting {
}
public void testOptionFeedback() {
test(new String[]{"-feedback", "concise", "-nostartup"},
test(new String[]{"--feedback", "concise", "--no-startup"},
(a) -> assertCommand(a, "1+1", "$1 ==> 2"),
(a) -> assertCommand(a, "int x = 5", "")
);
}
public void testCompoundOptions() {
Consumer<String> confirmNoStartup = s -> {
assertEquals(0, Stream.of(s.split("\n"))
.filter(l -> !l.isEmpty())
.count(), "Expected no lines: " + s);
};
test(new String[]{"-nq"},
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup),
(a) -> assertCommand(a, "1+1", "$1 ==> 2"),
(a) -> assertCommand(a, "int x = 5", "")
);
test(new String[]{"-qn"},
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup),
(a) -> assertCommand(a, "1+1", "$1 ==> 2"),
(a) -> assertCommand(a, "int x = 5", "")
);
test(new String[]{"-ns"},
(a) -> assertCommandCheckOutput(a, "/list -all", confirmNoStartup),
(a) -> assertCommand(a, "1+1", "")
);
}
public void testOptionR() {
test(new String[]{"-R-Dthe.sound=blorp", "-nostartup"},
test(new String[]{"-R-Dthe.sound=blorp", "--no-startup"},
(a) -> assertCommand(a, "System.getProperty(\"the.sound\")",
"$1 ==> \"blorp\"")
);