author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 27319 | 030080f03e4f |
permissions | -rw-r--r-- |
10 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
2 |
* Copyright (c) 2006, 2015, Oracle and/or its affiliates. All rights reserved. |
10 | 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 |
* |
|
5520 | 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. |
|
10 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6441871 |
|
27 |
* @summary javac crashes at com.sun.tools.javac.jvm.ClassReader$BadClassFile |
|
14963
974d4423c999
8005282: Use @library tag with non-relative path for javac tests
darcy
parents:
13634
diff
changeset
|
28 |
* @library /tools/javac/lib |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
29 |
* @modules jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.file |
6720 | 31 |
* @build JavacTestingAbstractProcessor A |
10 | 32 |
* @run main T6348499 |
33 |
*/ |
|
34 |
||
35 |
// Note that 6441871 is an interim partial fix for 6348499 that just removes the javac |
|
36 |
// crash message and stacktrace |
|
37 |
||
38 |
import java.io.*; |
|
39 |
import java.util.*; |
|
40 |
import javax.annotation.processing.*; |
|
41 |
import javax.lang.model.*; |
|
42 |
import javax.lang.model.element.*; |
|
43 |
import javax.tools.*; |
|
44 |
import com.sun.source.util.*; |
|
45 |
import com.sun.tools.javac.api.*; |
|
46 |
||
47 |
||
48 |
public class T6348499 { |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
49 |
public static void main(String... args) throws IOException { |
10 | 50 |
String testSrc = System.getProperty("test.src", "."); |
51 |
String testClasses = System.getProperty("test.classes"); |
|
13634
91f0b2d4d816
7192744: fix up tests to accommodate jtreg spec change
jjg
parents:
6720
diff
changeset
|
52 |
String testClassPath = System.getProperty("test.class.path", testClasses); |
10 | 53 |
String A_java = new File(testSrc, "A.java").getPath(); |
54 |
JavacTool tool = JavacTool.create(); |
|
55 |
MyDiagListener dl = new MyDiagListener(); |
|
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
56 |
try (StandardJavaFileManager fm = tool.getStandardFileManager(dl, null, null)) { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
57 |
Iterable<? extends JavaFileObject> files = |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
58 |
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(testSrc, "A.java"))); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
59 |
Iterable<String> opts = Arrays.asList("-proc:only", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
60 |
"-processor", "A", |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
61 |
"-processorpath", testClassPath); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
62 |
StringWriter out = new StringWriter(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
63 |
JavacTask task = tool.getTask(out, fm, dl, opts, null, files); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
64 |
task.call(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
65 |
String s = out.toString(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
66 |
System.err.print(s); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
67 |
// Expect the following 1 multi-line diagnostic, and no output to log |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
68 |
// error: cannot access A_0 |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
69 |
// bad class file: A_0.class |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
70 |
// illegal start of class file |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
71 |
// Please remove or make sure it appears in the correct subdirectory of the classpath. |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
72 |
System.err.println(dl.count + " diagnostics; " + s.length() + " characters"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
73 |
if (dl.count != 1 || s.length() != 0) |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
74 |
throw new AssertionError("unexpected output from compiler"); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
14963
diff
changeset
|
75 |
} |
10 | 76 |
} |
77 |
||
78 |
static class MyDiagListener implements DiagnosticListener<JavaFileObject> { |
|
79 |
public void report(Diagnostic d) { |
|
80 |
System.err.println(d); |
|
81 |
count++; |
|
82 |
} |
|
83 |
||
84 |
public int count; |
|
85 |
} |
|
86 |
||
87 |
private static String self = T6348499.class.getName(); |
|
88 |
} |