author | vromero |
Tue, 03 Apr 2018 23:58:52 -0400 | |
changeset 49518 | d0ff431a596e |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
8843
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
1 |
/* |
49518
d0ff431a596e
8198314: javac hidden options violate standard syntax for options
vromero
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved. |
8843
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
4 |
* |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
8 |
* |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
14 |
* |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
18 |
* |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
21 |
* questions. |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
22 |
*/ |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
23 |
|
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
24 |
/* |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
25 |
* @test |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
26 |
* @bug 7010608 |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
27 |
* @summary the string 'error' should appear in error messages |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
8843
diff
changeset
|
28 |
* @modules java.compiler |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
8843
diff
changeset
|
29 |
* jdk.compiler |
8843
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
30 |
*/ |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
31 |
|
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
32 |
import java.io.*; |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
33 |
import java.net.URI; |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
34 |
import java.util.*; |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
35 |
import javax.tools.*; |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
36 |
import javax.tools.JavaCompiler.CompilationTask; |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
37 |
|
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
38 |
public class Test { |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
39 |
public static void main(String... args) throws Exception { |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
40 |
new Test().run(); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
41 |
} |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
42 |
|
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
43 |
void run() throws Exception { |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
44 |
Locale prev = Locale.getDefault(); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
45 |
Locale.setDefault(Locale.ENGLISH); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
46 |
try { |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
47 |
test(Arrays.<String>asList(), |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
48 |
"myfo://test:1: error: cannot find symbol"); |
49518
d0ff431a596e
8198314: javac hidden options violate standard syntax for options
vromero
parents:
47216
diff
changeset
|
49 |
test(Arrays.asList("--diags=layout=OLD"), |
8843
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
50 |
"myfo://test:1: cannot find symbol"); |
49518
d0ff431a596e
8198314: javac hidden options violate standard syntax for options
vromero
parents:
47216
diff
changeset
|
51 |
test(Arrays.asList("--diags=legacy"), |
8843
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
52 |
"myfo://test:1: cannot find symbol"); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
53 |
} finally { |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
54 |
Locale.setDefault(prev); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
55 |
} |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
56 |
} |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
57 |
|
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
58 |
void test(List<String> options, String expect) throws Exception { |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
59 |
System.err.println("test: " + options); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
60 |
JavaCompiler javac = ToolProvider.getSystemJavaCompiler(); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
61 |
StringWriter sw = new StringWriter(); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
62 |
PrintWriter pw = new PrintWriter(sw); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
63 |
JavaFileObject f = new MyFileObject("myfo://test", "class Bad { Missing x; }"); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
64 |
List<? extends JavaFileObject> files = Arrays.asList(f); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
65 |
CompilationTask task = javac.getTask(pw, null, null, options, null, files); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
66 |
boolean ok = task.call(); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
67 |
pw.close(); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
68 |
String out = sw.toString(); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
69 |
if (!out.isEmpty()) |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
70 |
System.err.println(out); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
71 |
if (ok) |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
72 |
throw new Exception("Compilation succeeded unexpectedly"); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
73 |
if (!out.contains(expect)) |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
74 |
throw new Exception("expected text not found: " + expect); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
75 |
} |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
76 |
|
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
77 |
class MyFileObject extends SimpleJavaFileObject { |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
78 |
MyFileObject(String uri, String text) { |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
79 |
super(URI.create(uri), JavaFileObject.Kind.SOURCE); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
80 |
this.text = text; |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
81 |
} |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
82 |
@Override |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
83 |
public String getName() { |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
84 |
return uri.toString(); |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
85 |
} |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
86 |
@Override |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
87 |
public String getCharContent(boolean ignoreEncodingErrors) { |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
88 |
return text; |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
89 |
} |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
90 |
final String text; |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
91 |
} |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
92 |
} |
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
93 |
|
2602bd5c9c5f
7010608: the string 'error' should appear in error messages
jjg
parents:
diff
changeset
|
94 |