2015-10-19 17:15:16 +00:00
|
|
|
/*
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: Vicente Romero <vicente.romero@oracle.com>
Co-authored-by: Andreas Lundblad <andreas.lundblad@oracle.com>
Co-authored-by: Andrey Nazarov <andrey.x.nazarov@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Kumar Srinivasan <kumar.x.srinivasan@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs
2016-03-17 19:04:28 +00:00
|
|
|
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
|
2015-10-19 17:15:16 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2016-05-26 19:38:21 +00:00
|
|
|
* @test 8151754 8080883
|
2015-10-19 17:15:16 +00:00
|
|
|
* @summary Testing start-up options.
|
2016-01-25 19:01:32 +00:00
|
|
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
|
|
|
* jdk.compiler/com.sun.tools.javac.main
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: Vicente Romero <vicente.romero@oracle.com>
Co-authored-by: Andreas Lundblad <andreas.lundblad@oracle.com>
Co-authored-by: Andrey Nazarov <andrey.x.nazarov@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Kumar Srinivasan <kumar.x.srinivasan@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs
2016-03-17 19:04:28 +00:00
|
|
|
* jdk.jdeps/com.sun.tools.javap
|
2016-01-25 19:01:32 +00:00
|
|
|
* jdk.jshell/jdk.internal.jshell.tool
|
2015-10-19 17:15:16 +00:00
|
|
|
* @library /tools/lib
|
2016-03-31 22:20:50 +00:00
|
|
|
* @build Compiler toolbox.ToolBox
|
2015-10-19 17:15:16 +00:00
|
|
|
* @run testng StartOptionTest
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
|
|
import java.io.PrintStream;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.nio.file.Path;
|
2016-04-04 17:31:20 +00:00
|
|
|
import java.util.Locale;
|
2015-10-19 17:15:16 +00:00
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
|
|
|
import jdk.internal.jshell.tool.JShellTool;
|
|
|
|
import org.testng.annotations.AfterMethod;
|
|
|
|
import org.testng.annotations.BeforeMethod;
|
|
|
|
import org.testng.annotations.Test;
|
|
|
|
|
|
|
|
import static org.testng.Assert.assertEquals;
|
|
|
|
import static org.testng.Assert.assertTrue;
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public class StartOptionTest {
|
|
|
|
|
2016-05-26 14:58:01 +00:00
|
|
|
private ByteArrayOutputStream cmdout;
|
|
|
|
private ByteArrayOutputStream cmderr;
|
|
|
|
private ByteArrayOutputStream console;
|
|
|
|
private ByteArrayOutputStream userout;
|
|
|
|
private ByteArrayOutputStream usererr;
|
2015-10-19 17:15:16 +00:00
|
|
|
|
|
|
|
private JShellTool getShellTool() {
|
2016-04-28 01:13:19 +00:00
|
|
|
return new JShellTool(
|
|
|
|
new TestingInputStream(),
|
2016-05-26 14:58:01 +00:00
|
|
|
new PrintStream(cmdout),
|
|
|
|
new PrintStream(cmderr),
|
|
|
|
new PrintStream(console),
|
2016-04-28 01:13:19 +00:00
|
|
|
new TestingInputStream(),
|
2016-05-26 14:58:01 +00:00
|
|
|
new PrintStream(userout),
|
|
|
|
new PrintStream(usererr),
|
2016-04-28 01:13:19 +00:00
|
|
|
new ReplToolTesting.MemoryPreferences(),
|
|
|
|
Locale.ROOT);
|
2015-10-19 17:15:16 +00:00
|
|
|
}
|
|
|
|
|
2016-05-26 14:58:01 +00:00
|
|
|
private void check(ByteArrayOutputStream str, Consumer<String> checkOut, String label) {
|
|
|
|
byte[] bytes = str.toByteArray();
|
|
|
|
str.reset();
|
|
|
|
String out = new String(bytes, StandardCharsets.UTF_8);
|
|
|
|
if (checkOut != null) {
|
|
|
|
checkOut.accept(out);
|
|
|
|
} else {
|
|
|
|
assertEquals("", out, label + ": Expected empty -- ");
|
|
|
|
}
|
2015-10-19 17:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void start(Consumer<String> checkOutput, Consumer<String> checkError, String... args) throws Exception {
|
|
|
|
JShellTool tool = getShellTool();
|
|
|
|
tool.start(args);
|
2016-05-26 14:58:01 +00:00
|
|
|
check(cmdout, checkOutput, "cmdout");
|
|
|
|
check(cmderr, checkError, "cmderr");
|
|
|
|
check(console, null, "console");
|
|
|
|
check(userout, null, "userout");
|
|
|
|
check(usererr, null, "usererr");
|
2015-10-19 17:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void start(String expectedOutput, String expectedError, String... args) throws Exception {
|
2016-05-26 14:58:01 +00:00
|
|
|
start(s -> assertEquals(s.trim(), expectedOutput, "cmdout: "), s -> assertEquals(s.trim(), expectedError, "cmderr: "), args);
|
2015-10-19 17:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@BeforeMethod
|
|
|
|
public void setUp() {
|
2016-05-26 14:58:01 +00:00
|
|
|
cmdout = new ByteArrayOutputStream();
|
|
|
|
cmderr = new ByteArrayOutputStream();
|
|
|
|
console = new ByteArrayOutputStream();
|
|
|
|
userout = new ByteArrayOutputStream();
|
|
|
|
usererr = new ByteArrayOutputStream();
|
2015-10-19 17:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testUsage() throws Exception {
|
|
|
|
start(s -> {
|
2016-05-26 14:58:01 +00:00
|
|
|
assertTrue(s.split("\n").length >= 7, "Not enough usage lines: " + s);
|
|
|
|
assertTrue(s.startsWith("Usage: jshell <options>"), "Unexpect usage start: " + s);
|
2015-10-19 17:15:16 +00:00
|
|
|
}, null, "-help");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testUnknown() throws Exception {
|
|
|
|
start(s -> {
|
2016-05-26 14:58:01 +00:00
|
|
|
assertTrue(s.split("\n").length >= 7, "Not enough usage lines (unknown): " + s);
|
|
|
|
assertTrue(s.startsWith("Usage: jshell <options>"), "Unexpect usage start (unknown): " + s);
|
2016-04-05 07:46:51 +00:00
|
|
|
}, s -> assertEquals(s.trim(), "Unknown option: -unknown"), "-unknown");
|
2015-10-19 17:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void testStartup() throws Exception {
|
|
|
|
Compiler compiler = new Compiler();
|
|
|
|
Path p = compiler.getPath("file.txt");
|
|
|
|
compiler.writeToFile(p);
|
2016-04-05 07:46:51 +00:00
|
|
|
start("", "'-startup' requires a filename argument.", "-startup");
|
2016-05-26 19:38:21 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void testStartupUnknown() throws Exception {
|
|
|
|
start("", "File 'UNKNOWN' for '-startup' is not found.", "-startup", "UNKNOWN");
|
2015-10-19 17:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testClasspath() throws Exception {
|
|
|
|
for (String cp : new String[] {"-cp", "-classpath"}) {
|
2016-04-05 07:46:51 +00:00
|
|
|
start("", "Conflicting -classpath option.", cp, ".", "-classpath", ".");
|
|
|
|
start("", "Argument to -classpath missing.", cp);
|
2015-10-19 17:15:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-28 01:13:19 +00:00
|
|
|
@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");
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:15:16 +00:00
|
|
|
@Test
|
|
|
|
public void testVersion() throws Exception {
|
2016-05-26 14:58:01 +00:00
|
|
|
start(s -> assertTrue(s.startsWith("jshell"), "unexpected version: " + s), null, "-version");
|
2015-10-19 17:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@AfterMethod
|
|
|
|
public void tearDown() {
|
2016-05-26 14:58:01 +00:00
|
|
|
cmdout = null;
|
|
|
|
cmderr = null;
|
|
|
|
console = null;
|
|
|
|
userout = null;
|
|
|
|
usererr = null;
|
2015-10-19 17:15:16 +00:00
|
|
|
}
|
|
|
|
}
|