author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 44683 | langtools/test/jdk/jshell/ToolProviderTest.java@610dc2b48954 |
child 47504 | 58ce36f43f1a |
permissions | -rw-r--r-- |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
1 |
/* |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
4 |
* |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
8 |
* |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
13 |
* accompanied this code). |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
14 |
* |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
18 |
* |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
21 |
* questions. |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
22 |
*/ |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
23 |
|
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
24 |
import java.io.ByteArrayInputStream; |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
25 |
import java.io.ByteArrayOutputStream; |
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
26 |
import java.io.InputStream; |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
27 |
import java.util.ServiceLoader; |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
28 |
import java.util.function.Consumer; |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
29 |
import javax.tools.Tool; |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
30 |
import org.testng.annotations.BeforeMethod; |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
31 |
import org.testng.annotations.Test; |
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
32 |
import static org.testng.Assert.assertTrue; |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
33 |
import static org.testng.Assert.fail; |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
34 |
|
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
35 |
/* |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
36 |
* @test |
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
37 |
* @bug 8170044 8171343 |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
38 |
* @summary Test ServiceLoader launching of jshell tool |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
39 |
* @modules jdk.compiler/com.sun.tools.javac.api |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
40 |
* jdk.compiler/com.sun.tools.javac.main |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
41 |
* jdk.jdeps/com.sun.tools.javap |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
42 |
* jdk.jshell/jdk.internal.jshell.tool |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
43 |
* @library /tools/lib |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
44 |
* @build Compiler toolbox.ToolBox |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
45 |
* @run testng ToolProviderTest |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
46 |
*/ |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
47 |
@Test |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
48 |
public class ToolProviderTest extends StartOptionTest { |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
49 |
|
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
50 |
private ByteArrayOutputStream cmdout; |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
51 |
private ByteArrayOutputStream cmderr; |
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
52 |
private InputStream cmdInStream; |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
53 |
|
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
54 |
@BeforeMethod |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
55 |
@Override |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
56 |
public void setUp() { |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
57 |
cmdout = new ByteArrayOutputStream(); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
58 |
cmderr = new ByteArrayOutputStream(); |
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
59 |
cmdInStream = new ByteArrayInputStream("/exit\n".getBytes()); |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
60 |
} |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
61 |
|
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
62 |
@Override |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
63 |
protected void start(Consumer<String> checkCmdOutput, |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
64 |
Consumer<String> checkUserOutput, Consumer<String> checkError, |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
65 |
String... args) throws Exception { |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
66 |
if (runShellServiceLoader(args) != 0) { |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
67 |
fail("Repl tool failed"); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
68 |
} |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
69 |
check(cmdout, checkCmdOutput, "cmdout"); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
70 |
check(cmderr, checkError, "cmderr"); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
71 |
} |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
72 |
|
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
73 |
private int runShellServiceLoader(String... args) { |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
74 |
ServiceLoader<Tool> sl = ServiceLoader.load(Tool.class); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
75 |
for (Tool provider : sl) { |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
76 |
if (provider.name().equals("jshell")) { |
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
77 |
return provider.run(cmdInStream, cmdout, cmderr, args); |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
78 |
} |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
79 |
} |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
80 |
throw new AssertionError("Repl tool not found by ServiceLoader: " + sl); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
81 |
} |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
82 |
|
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
83 |
@Override |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
84 |
public void testCommandFile() throws Exception { |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
85 |
String fn = writeToFile("String str = \"Hello \"\n/list\nSystem.out.println(str + str)\n/exit\n"); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
86 |
start("1 : String str = \"Hello \";" + "\n" + "Hello Hello", "", "--no-startup", fn, "-s"); |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
87 |
} |
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
88 |
|
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
89 |
@Override |
43367
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
90 |
public void testShowVersion() throws Exception { |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
91 |
start( |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
92 |
s -> { |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
93 |
assertTrue(s.startsWith("jshell "), "unexpected version: " + s); |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
94 |
assertTrue(s.contains("Welcome"), "Expected start (but got no welcome): " + s); |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
95 |
assertTrue(s.trim().contains("jshell>"), "Expected prompt, got: " + s); |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
96 |
}, |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
97 |
null, null, |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
98 |
"--show-version"); |
7797472a9ed5
8171343: jshell tool: missing options: --help-extra --show-version
rfield
parents:
42843
diff
changeset
|
99 |
} |
42843
a8d83044a192
8170162: jshell tool: no mechanism to programmatically launch
rfield
parents:
diff
changeset
|
100 |
} |