mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-07 12:14:55 +00:00
8171343: jshell tool: missing options: --help-extra --show-version
Reviewed-by: jlahoda
This commit is contained in:
parent
8fd1027a6b
commit
01b7f9ed5e
@ -426,7 +426,8 @@ public class JShellTool implements MessageHandler {
|
||||
private final OptionSpecBuilder argHelp = parser.acceptsAll(asList("h", "help"));
|
||||
private final OptionSpecBuilder argVersion = parser.accepts("version");
|
||||
private final OptionSpecBuilder argFullVersion = parser.accepts("full-version");
|
||||
private final OptionSpecBuilder argX = parser.accepts("X");
|
||||
private final OptionSpecBuilder argShowVersion = parser.accepts("show-version");
|
||||
private final OptionSpecBuilder argHelpExtra = parser.acceptsAll(asList("X", "help-extra"));
|
||||
|
||||
private String feedbackMode = null;
|
||||
private Startup initialStartup = null;
|
||||
@ -450,7 +451,7 @@ public class JShellTool implements MessageHandler {
|
||||
printUsage();
|
||||
return null;
|
||||
}
|
||||
if (options.has(argX)) {
|
||||
if (options.has(argHelpExtra)) {
|
||||
printUsageX();
|
||||
return null;
|
||||
}
|
||||
@ -462,6 +463,9 @@ public class JShellTool implements MessageHandler {
|
||||
cmdout.printf("jshell %s\n", fullVersion());
|
||||
return null;
|
||||
}
|
||||
if (options.has(argShowVersion)) {
|
||||
cmdout.printf("jshell %s\n", version());
|
||||
}
|
||||
if ((options.valuesOf(argFeedback).size() +
|
||||
(options.has(argQ) ? 1 : 0) +
|
||||
(options.has(argS) ? 1 : 0) +
|
||||
|
||||
@ -187,9 +187,10 @@ where possible options include:\n\
|
||||
\ Use one -R for each remote flag or flag argument\n\
|
||||
\ -C<flag> Pass <flag> to the compiler.\n\
|
||||
\ Use one -C for each compiler flag or flag argument\n\
|
||||
\ --help Print this synopsis of standard options\n\
|
||||
\ --version Version information\n\
|
||||
\ -X Print help on non-standard options\n
|
||||
\ --version Print version information and exit\n\
|
||||
\ --show-version Print version information and continue\n\
|
||||
\ --help Print this synopsis of standard options and exit\n\
|
||||
\ --help-extra, -X Print help on non-standard options and exit\n
|
||||
help.usage.x = \
|
||||
\ --add-exports <module>/<package> Export specified module-private package to snippets\n\
|
||||
\ --execution <spec> Specify an alternate execution engine.\n\
|
||||
|
||||
@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test 8151754 8080883 8160089 8170162 8166581 8172102
|
||||
* @test 8151754 8080883 8160089 8170162 8166581 8172102 8171343
|
||||
* @summary Testing start-up options.
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.main
|
||||
@ -33,7 +33,9 @@
|
||||
* @run testng StartOptionTest
|
||||
*/
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Path;
|
||||
@ -46,6 +48,7 @@ import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import jdk.jshell.tool.JavaShellToolBuilder;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
@ -57,12 +60,14 @@ public class StartOptionTest {
|
||||
private ByteArrayOutputStream console;
|
||||
private ByteArrayOutputStream userout;
|
||||
private ByteArrayOutputStream usererr;
|
||||
private InputStream cmdInStream;
|
||||
|
||||
private JavaShellToolBuilder builder() {
|
||||
return JavaShellToolBuilder
|
||||
.builder()
|
||||
.out(new PrintStream(cmdout), new PrintStream(console), new PrintStream(userout))
|
||||
.err(new PrintStream(cmderr), new PrintStream(usererr))
|
||||
.in(cmdInStream, null)
|
||||
.persistence(new HashMap<>())
|
||||
.env(new HashMap<>())
|
||||
.locale(Locale.ROOT);
|
||||
@ -119,6 +124,7 @@ public class StartOptionTest {
|
||||
console = new ByteArrayOutputStream();
|
||||
userout = new ByteArrayOutputStream();
|
||||
usererr = new ByteArrayOutputStream();
|
||||
cmdInStream = new ByteArrayInputStream("/exit\n".getBytes());
|
||||
}
|
||||
|
||||
protected String writeToFile(String stuff) throws Exception {
|
||||
@ -138,6 +144,19 @@ public class StartOptionTest {
|
||||
start(s -> {
|
||||
assertTrue(s.split("\n").length >= 7, "Not enough usage lines: " + s);
|
||||
assertTrue(s.startsWith("Usage: jshell <options>"), "Unexpect usage start: " + s);
|
||||
assertTrue(s.contains("--show-version"), "Expected help: " + s);
|
||||
assertFalse(s.contains("Welcome"), "Unexpected start: " + s);
|
||||
}, null, null, opt);
|
||||
}
|
||||
}
|
||||
|
||||
public void testHelpExtra() throws Exception {
|
||||
for (String opt : new String[]{"-X", "--help-extra"}) {
|
||||
start(s -> {
|
||||
assertTrue(s.split("\n").length >= 5, "Not enough help-extra lines: " + s);
|
||||
assertTrue(s.contains("--add-exports"), "Expected --add-exports: " + s);
|
||||
assertTrue(s.contains("--execution"), "Expected --add-exports: " + s);
|
||||
assertFalse(s.contains("Welcome"), "Unexpected start: " + s);
|
||||
}, null, null, opt);
|
||||
}
|
||||
}
|
||||
@ -201,7 +220,29 @@ public class StartOptionTest {
|
||||
}
|
||||
|
||||
public void testVersion() throws Exception {
|
||||
start(s -> assertTrue(s.startsWith("jshell"), "unexpected version: " + s), null, null, "--version");
|
||||
start(
|
||||
s -> {
|
||||
assertTrue(s.startsWith("jshell"), "unexpected version: " + s);
|
||||
assertFalse(s.contains("Welcome"), "Unexpected start: " + s);
|
||||
},
|
||||
null, null,
|
||||
"--version");
|
||||
}
|
||||
|
||||
public void testShowVersion() throws Exception {
|
||||
runShell("--show-version");
|
||||
check(cmdout,
|
||||
s -> {
|
||||
assertTrue(s.startsWith("jshell"), "unexpected version: " + s);
|
||||
assertTrue(s.contains("Welcome"), "Expected start (but got no welcome): " + s);
|
||||
},
|
||||
"cmdout");
|
||||
check(cmderr, null, "cmderr");
|
||||
check(console,
|
||||
s -> assertTrue(s.trim().startsWith("jshell>"), "Expected prompt, got: " + s),
|
||||
"console");
|
||||
check(userout, null, "userout");
|
||||
check(usererr, null, "usererr");
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
@ -211,5 +252,6 @@ public class StartOptionTest {
|
||||
console = null;
|
||||
userout = null;
|
||||
usererr = null;
|
||||
cmdInStream = null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,16 +23,18 @@
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.function.Consumer;
|
||||
import javax.tools.Tool;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8170044
|
||||
* @bug 8170044 8171343
|
||||
* @summary Test ServiceLoader launching of jshell tool
|
||||
* @modules jdk.compiler/com.sun.tools.javac.api
|
||||
* jdk.compiler/com.sun.tools.javac.main
|
||||
@ -47,12 +49,14 @@ public class ToolProviderTest extends StartOptionTest {
|
||||
|
||||
private ByteArrayOutputStream cmdout;
|
||||
private ByteArrayOutputStream cmderr;
|
||||
private InputStream cmdInStream;
|
||||
|
||||
@BeforeMethod
|
||||
@Override
|
||||
public void setUp() {
|
||||
cmdout = new ByteArrayOutputStream();
|
||||
cmderr = new ByteArrayOutputStream();
|
||||
cmdInStream = new ByteArrayInputStream("/exit\n".getBytes());
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -70,7 +74,7 @@ public class ToolProviderTest extends StartOptionTest {
|
||||
ServiceLoader<Tool> sl = ServiceLoader.load(Tool.class);
|
||||
for (Tool provider : sl) {
|
||||
if (provider.name().equals("jshell")) {
|
||||
return provider.run(new ByteArrayInputStream(new byte[0]), cmdout, cmderr, args);
|
||||
return provider.run(cmdInStream, cmdout, cmderr, args);
|
||||
}
|
||||
}
|
||||
throw new AssertionError("Repl tool not found by ServiceLoader: " + sl);
|
||||
@ -90,4 +94,16 @@ public class ToolProviderTest extends StartOptionTest {
|
||||
check(cmderr, s -> s.startsWith("Launching JShell execution engine threw: Failed remote"), "cmderr");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void testShowVersion() throws Exception {
|
||||
start(
|
||||
s -> {
|
||||
assertTrue(s.startsWith("jshell "), "unexpected version: " + s);
|
||||
assertTrue(s.contains("Welcome"), "Expected start (but got no welcome): " + s);
|
||||
assertTrue(s.trim().contains("jshell>"), "Expected prompt, got: " + s);
|
||||
},
|
||||
null, null,
|
||||
"--show-version");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user