author | rfield |
Thu, 26 May 2016 07:58:01 -0700 | |
changeset 38608 | 691b607bbcd6 |
parent 37745 | 4b6b59f8e327 |
child 38613 | 2a8e50869b08 |
permissions | -rw-r--r-- |
33362 | 1 |
/* |
36526 | 2 |
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
33362 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/* |
|
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
36993
diff
changeset
|
25 |
* @test 8151754 |
33362 | 26 |
* @summary Testing start-up options. |
35359 | 27 |
* @modules jdk.compiler/com.sun.tools.javac.api |
28 |
* jdk.compiler/com.sun.tools.javac.main |
|
36526 | 29 |
* jdk.jdeps/com.sun.tools.javap |
35359 | 30 |
* jdk.jshell/jdk.internal.jshell.tool |
33362 | 31 |
* @library /tools/lib |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36715
diff
changeset
|
32 |
* @build Compiler toolbox.ToolBox |
33362 | 33 |
* @run testng StartOptionTest |
34 |
*/ |
|
35 |
||
36 |
import java.io.ByteArrayOutputStream; |
|
37 |
import java.io.PrintStream; |
|
38 |
import java.nio.charset.StandardCharsets; |
|
39 |
import java.nio.file.Path; |
|
36990 | 40 |
import java.util.Locale; |
33362 | 41 |
import java.util.function.Consumer; |
42 |
||
43 |
import jdk.internal.jshell.tool.JShellTool; |
|
44 |
import org.testng.annotations.AfterMethod; |
|
45 |
import org.testng.annotations.BeforeMethod; |
|
46 |
import org.testng.annotations.Test; |
|
47 |
||
48 |
import static org.testng.Assert.assertEquals; |
|
49 |
import static org.testng.Assert.assertTrue; |
|
50 |
||
51 |
@Test |
|
52 |
public class StartOptionTest { |
|
53 |
||
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
54 |
private ByteArrayOutputStream cmdout; |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
55 |
private ByteArrayOutputStream cmderr; |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
56 |
private ByteArrayOutputStream console; |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
57 |
private ByteArrayOutputStream userout; |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
58 |
private ByteArrayOutputStream usererr; |
33362 | 59 |
|
60 |
private JShellTool getShellTool() { |
|
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
36993
diff
changeset
|
61 |
return new JShellTool( |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
36993
diff
changeset
|
62 |
new TestingInputStream(), |
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
63 |
new PrintStream(cmdout), |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
64 |
new PrintStream(cmderr), |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
65 |
new PrintStream(console), |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
36993
diff
changeset
|
66 |
new TestingInputStream(), |
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
67 |
new PrintStream(userout), |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
68 |
new PrintStream(usererr), |
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
36993
diff
changeset
|
69 |
new ReplToolTesting.MemoryPreferences(), |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
36993
diff
changeset
|
70 |
Locale.ROOT); |
33362 | 71 |
} |
72 |
||
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
73 |
private void check(ByteArrayOutputStream str, Consumer<String> checkOut, String label) { |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
74 |
byte[] bytes = str.toByteArray(); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
75 |
str.reset(); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
76 |
String out = new String(bytes, StandardCharsets.UTF_8); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
77 |
if (checkOut != null) { |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
78 |
checkOut.accept(out); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
79 |
} else { |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
80 |
assertEquals("", out, label + ": Expected empty -- "); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
81 |
} |
33362 | 82 |
} |
83 |
||
84 |
private void start(Consumer<String> checkOutput, Consumer<String> checkError, String... args) throws Exception { |
|
85 |
JShellTool tool = getShellTool(); |
|
86 |
tool.start(args); |
|
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
87 |
check(cmdout, checkOutput, "cmdout"); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
88 |
check(cmderr, checkError, "cmderr"); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
89 |
check(console, null, "console"); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
90 |
check(userout, null, "userout"); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
91 |
check(usererr, null, "usererr"); |
33362 | 92 |
} |
93 |
||
94 |
private void start(String expectedOutput, String expectedError, String... args) throws Exception { |
|
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
95 |
start(s -> assertEquals(s.trim(), expectedOutput, "cmdout: "), s -> assertEquals(s.trim(), expectedError, "cmderr: "), args); |
33362 | 96 |
} |
97 |
||
98 |
@BeforeMethod |
|
99 |
public void setUp() { |
|
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
100 |
cmdout = new ByteArrayOutputStream(); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
101 |
cmderr = new ByteArrayOutputStream(); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
102 |
console = new ByteArrayOutputStream(); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
103 |
userout = new ByteArrayOutputStream(); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
104 |
usererr = new ByteArrayOutputStream(); |
33362 | 105 |
} |
106 |
||
107 |
@Test |
|
108 |
public void testUsage() throws Exception { |
|
109 |
start(s -> { |
|
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
110 |
assertTrue(s.split("\n").length >= 7, "Not enough usage lines: " + s); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
111 |
assertTrue(s.startsWith("Usage: jshell <options>"), "Unexpect usage start: " + s); |
33362 | 112 |
}, null, "-help"); |
113 |
} |
|
114 |
||
115 |
@Test |
|
116 |
public void testUnknown() throws Exception { |
|
117 |
start(s -> { |
|
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
118 |
assertTrue(s.split("\n").length >= 7, "Not enough usage lines (unknown): " + s); |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
119 |
assertTrue(s.startsWith("Usage: jshell <options>"), "Unexpect usage start (unknown): " + s); |
36993
e00f4be3a47d
8153482: jdk/jshell/StartOptionTest.java fails on Windows after JDK-8147515
rfield
parents:
36990
diff
changeset
|
120 |
}, s -> assertEquals(s.trim(), "Unknown option: -unknown"), "-unknown"); |
33362 | 121 |
} |
122 |
||
123 |
@Test(enabled = false) // TODO 8080883 |
|
124 |
public void testStartup() throws Exception { |
|
125 |
Compiler compiler = new Compiler(); |
|
126 |
Path p = compiler.getPath("file.txt"); |
|
127 |
compiler.writeToFile(p); |
|
36993
e00f4be3a47d
8153482: jdk/jshell/StartOptionTest.java fails on Windows after JDK-8147515
rfield
parents:
36990
diff
changeset
|
128 |
start("", "'-startup' requires a filename argument.", "-startup"); |
e00f4be3a47d
8153482: jdk/jshell/StartOptionTest.java fails on Windows after JDK-8147515
rfield
parents:
36990
diff
changeset
|
129 |
start("", "Conflicting -startup or -nostartup option.", "-startup", p.toString(), "-startup", p.toString()); |
e00f4be3a47d
8153482: jdk/jshell/StartOptionTest.java fails on Windows after JDK-8147515
rfield
parents:
36990
diff
changeset
|
130 |
start("", "Conflicting -startup or -nostartup option.", "-nostartup", "-startup", p.toString()); |
e00f4be3a47d
8153482: jdk/jshell/StartOptionTest.java fails on Windows after JDK-8147515
rfield
parents:
36990
diff
changeset
|
131 |
start("", "Conflicting -startup or -nostartup option.", "-startup", p.toString(), "-nostartup"); |
33362 | 132 |
} |
133 |
||
134 |
@Test |
|
135 |
public void testClasspath() throws Exception { |
|
136 |
for (String cp : new String[] {"-cp", "-classpath"}) { |
|
36993
e00f4be3a47d
8153482: jdk/jshell/StartOptionTest.java fails on Windows after JDK-8147515
rfield
parents:
36990
diff
changeset
|
137 |
start("", "Conflicting -classpath option.", cp, ".", "-classpath", "."); |
e00f4be3a47d
8153482: jdk/jshell/StartOptionTest.java fails on Windows after JDK-8147515
rfield
parents:
36990
diff
changeset
|
138 |
start("", "Argument to -classpath missing.", cp); |
33362 | 139 |
} |
140 |
} |
|
141 |
||
142 |
@Test |
|
37745
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
36993
diff
changeset
|
143 |
public void testNegFeedbackOption() throws Exception { |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
36993
diff
changeset
|
144 |
start("", "Argument to -feedback missing. Mode required.", "-feedback"); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
36993
diff
changeset
|
145 |
start("", "Does not match any current feedback mode: blorp -- -feedback blorp", "-feedback", "blorp"); |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
36993
diff
changeset
|
146 |
} |
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
36993
diff
changeset
|
147 |
|
4b6b59f8e327
8150382: JShell API: Allow setting remote JVM arguments
rfield
parents:
36993
diff
changeset
|
148 |
@Test |
33362 | 149 |
public void testVersion() throws Exception { |
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
150 |
start(s -> assertTrue(s.startsWith("jshell"), "unexpected version: " + s), null, "-version"); |
33362 | 151 |
} |
152 |
||
153 |
@AfterMethod |
|
154 |
public void tearDown() { |
|
38608
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
155 |
cmdout = null; |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
156 |
cmderr = null; |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
157 |
console = null; |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
158 |
userout = null; |
691b607bbcd6
8157917: JShell: shutdown could cause remote JDWP errors to be visible to users
rfield
parents:
37745
diff
changeset
|
159 |
usererr = null; |
33362 | 160 |
} |
161 |
} |