author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 5520 | 86e4b9a9da40 |
child 32337 | c9d3ab9f601c |
permissions | -rw-r--r-- |
169 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
5520
diff
changeset
|
2 |
* Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved. |
169 | 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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
169 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
169 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
169 | 24 |
*/ |
25 |
||
26 |
/* |
|
27 |
* @test |
|
28 |
* @bug 6668794 6668796 |
|
29 |
* @summary javac puts localized text in raw diagnostics |
|
30 |
* bad diagnostic "bad class file" given for source files |
|
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
5520
diff
changeset
|
31 |
* @modules jdk.compiler |
169 | 32 |
*/ |
33 |
||
34 |
import java.io.*; |
|
35 |
import java.util.*; |
|
36 |
import javax.tools.*; |
|
37 |
||
38 |
public class Test { |
|
39 |
public static void main(String[] args) throws Exception { |
|
40 |
new Test().run(); |
|
41 |
} |
|
42 |
||
43 |
void run() throws Exception { |
|
44 |
||
45 |
// compile q.A then move it to p.A |
|
46 |
compile("A.java"); |
|
47 |
||
48 |
File p = new File("p"); |
|
49 |
p.mkdirs(); |
|
50 |
new File("q/A.class").renameTo(new File("p/A.class")); |
|
51 |
||
52 |
// compile B against p.A |
|
53 |
String[] out = compile("B.java"); |
|
54 |
if (out.length == 0) |
|
55 |
throw new Error("no diagnostics generated"); |
|
56 |
||
57 |
String expected = "B.java:6:6: compiler.err.cant.access: p.A, " + |
|
2085
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
169
diff
changeset
|
58 |
"(compiler.misc.bad.class.file.header: A.class, " + |
4792e12a8ca2
6769027: Source line should be displayed immediately after the first diagnostic line
mcimadamore
parents:
169
diff
changeset
|
59 |
"(compiler.misc.class.file.wrong.class: q.A))"; |
169 | 60 |
|
61 |
if (!out[0].equals(expected)) { |
|
62 |
System.err.println("expected: " + expected); |
|
63 |
System.err.println(" found: " + out[0]); |
|
64 |
throw new Error("test failed"); |
|
65 |
} |
|
66 |
} |
|
67 |
||
68 |
String[] compile(String file) { |
|
69 |
String[] options = { |
|
70 |
"-XDrawDiagnostics", |
|
71 |
"-d", ".", |
|
72 |
"-classpath", ".", |
|
73 |
new File(testSrc, file).getPath() |
|
74 |
}; |
|
75 |
||
76 |
System.err.println("compile: " + Arrays.asList(options)); |
|
77 |
StringWriter sw = new StringWriter(); |
|
78 |
PrintWriter out = new PrintWriter(sw); |
|
79 |
int rc = com.sun.tools.javac.Main.compile(options, out); |
|
80 |
out.close(); |
|
81 |
||
82 |
String outText = sw.toString(); |
|
83 |
System.err.println(outText); |
|
84 |
||
85 |
return sw.toString().split("[\\r\\n]+"); |
|
86 |
} |
|
87 |
||
88 |
File testSrc = new File(System.getProperty("test.src", ".")); |
|
89 |
} |