author | coleenp |
Wed, 15 Nov 2017 08:14:31 -0500 | |
changeset 47894 | 352b17f62ff7 |
parent 47216 | 71c04702a3d5 |
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 |
/* |
|
25 |
* @test |
|
26 |
* @summary Tests for EvalState#addToClasspath |
|
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 |
33362 | 30 |
* @library /tools/lib |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
31 |
* @build toolbox.ToolBox toolbox.JarTask toolbox.JavacTask |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
32 |
* @build KullaTesting TestingInputStream Compiler |
33362 | 33 |
* @run testng ClassPathTest |
34 |
*/ |
|
35 |
||
36 |
import java.nio.file.Path; |
|
37 |
import java.nio.file.Paths; |
|
38 |
||
39 |
import org.testng.annotations.Test; |
|
40 |
||
41 |
@Test |
|
42 |
public class ClassPathTest extends KullaTesting { |
|
43 |
||
44 |
private final Compiler compiler = new Compiler(); |
|
45 |
private final Path outDir = Paths.get("class_path_test"); |
|
46 |
||
47 |
public void testDirectory() { |
|
48 |
compiler.compile(outDir, "package pkg; public class TestDirectory { }"); |
|
49 |
assertDeclareFail("import pkg.TestDirectory;", "compiler.err.doesnt.exist"); |
|
50 |
assertDeclareFail("new pkg.TestDirectory();", "compiler.err.doesnt.exist"); |
|
51 |
addToClasspath(compiler.getPath(outDir)); |
|
52 |
assertEval("new pkg.TestDirectory();"); |
|
53 |
} |
|
54 |
||
55 |
public void testJar() { |
|
56 |
compiler.compile(outDir, "package pkg; public class TestJar { }"); |
|
57 |
String jarName = "test.jar"; |
|
58 |
compiler.jar(outDir, jarName, "pkg/TestJar.class"); |
|
59 |
assertDeclareFail("import pkg.TestJar;", "compiler.err.doesnt.exist"); |
|
60 |
assertDeclareFail("new pkg.TestJar();", "compiler.err.doesnt.exist"); |
|
61 |
addToClasspath(compiler.getPath(outDir).resolve(jarName)); |
|
62 |
assertEval("new pkg.TestJar();"); |
|
63 |
} |
|
64 |
||
65 |
public void testAmbiguousDirectory() { |
|
66 |
Path p1 = outDir.resolve("dir1"); |
|
67 |
compiler.compile(p1, |
|
68 |
"package p; public class TestAmbiguous {\n" + |
|
69 |
" public String toString() {\n" + |
|
70 |
" return \"first\";" + |
|
71 |
" }\n" + |
|
72 |
"}"); |
|
73 |
addToClasspath(compiler.getPath(p1)); |
|
74 |
Path p2 = outDir.resolve("dir2"); |
|
75 |
compiler.compile(p2, |
|
76 |
"package p; public class TestAmbiguous {\n" + |
|
77 |
" public String toString() {\n" + |
|
78 |
" return \"second\";" + |
|
79 |
" }\n" + |
|
80 |
"}"); |
|
81 |
addToClasspath(compiler.getPath(p2)); |
|
82 |
assertEval("new p.TestAmbiguous();", "first"); |
|
83 |
} |
|
84 |
||
85 |
public void testAmbiguousJar() { |
|
86 |
Path p1 = outDir.resolve("dir1"); |
|
87 |
compiler.compile(p1, |
|
88 |
"package p; public class TestAmbiguous {\n" + |
|
89 |
" public String toString() {\n" + |
|
90 |
" return \"first\";" + |
|
91 |
" }\n" + |
|
92 |
"}"); |
|
93 |
String jarName = "test.jar"; |
|
94 |
compiler.jar(p1, jarName, "p/TestAmbiguous.class"); |
|
95 |
addToClasspath(compiler.getPath(p1.resolve(jarName))); |
|
96 |
Path p2 = outDir.resolve("dir2"); |
|
97 |
compiler.compile(p2, |
|
98 |
"package p; public class TestAmbiguous {\n" + |
|
99 |
" public String toString() {\n" + |
|
100 |
" return \"second\";" + |
|
101 |
" }\n" + |
|
102 |
"}"); |
|
103 |
addToClasspath(compiler.getPath(p2)); |
|
104 |
assertEval("new p.TestAmbiguous();", "first"); |
|
105 |
} |
|
106 |
||
107 |
public void testEmptyClassPath() { |
|
108 |
addToClasspath(""); |
|
109 |
assertEval("new java.util.ArrayList<String>();"); |
|
110 |
} |
|
111 |
||
112 |
public void testUnknown() { |
|
113 |
addToClasspath(compiler.getPath(outDir.resolve("UNKNOWN"))); |
|
114 |
assertDeclareFail("new Unknown();", "compiler.err.cant.resolve.location"); |
|
115 |
addToClasspath(compiler.getPath(outDir.resolve("UNKNOWN.jar"))); |
|
116 |
assertDeclareFail("new Unknown();", "compiler.err.cant.resolve.location"); |
|
117 |
} |
|
118 |
} |