author | amurillo |
Mon, 11 Apr 2016 20:38:38 -0700 (2016-04-12) | |
changeset 37298 | 8df0cc9da41e |
parent 30730 | d3ce7619db2c |
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) 2005, 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 6306137 |
|
27 |
* @summary JSR 199: encoding option doesn't affect standard file manager |
|
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
28 |
* @modules java.compiler |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27319
diff
changeset
|
29 |
* jdk.compiler |
15708
fbf749010eba
8007698: jtreg test T6306137.java won't compile with ASCII encoding
jjh
parents:
15569
diff
changeset
|
30 |
* @compile -encoding utf-8 T6306137.java |
fbf749010eba
8007698: jtreg test T6306137.java won't compile with ASCII encoding
jjh
parents:
15569
diff
changeset
|
31 |
* @run main T6306137 |
18390 | 32 |
* @author Peter von der Ah\u00e9 |
10 | 33 |
*/ |
34 |
||
35 |
import java.io.File; |
|
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
36 |
import java.io.IOException; |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
37 |
import java.nio.charset.Charset; |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
38 |
import java.nio.file.Files; |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
39 |
import java.util.ArrayList; |
10 | 40 |
import java.util.Arrays; |
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
41 |
import java.util.List; |
10 | 42 |
import javax.tools.*; |
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
43 |
import static java.nio.file.StandardOpenOption.*; |
10 | 44 |
|
45 |
public class T6306137 { |
|
46 |
boolean error; |
|
47 |
final StandardJavaFileManager fm; |
|
48 |
final JavaCompiler compiler; |
|
49 |
Iterable<? extends JavaFileObject> files; |
|
50 |
DiagnosticListener<JavaFileObject> dl; |
|
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
51 |
final File testFile = new File("Utf8.java"); |
10 | 52 |
|
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
53 |
T6306137() throws IOException { |
10 | 54 |
dl = new DiagnosticListener<JavaFileObject>() { |
55 |
public void report(Diagnostic<? extends JavaFileObject> message) { |
|
56 |
if (message.getKind() == Diagnostic.Kind.ERROR) |
|
57 |
error = true; |
|
58 |
System.out.println(message.getSource() |
|
59 |
+":"+message.getStartPosition()+":" |
|
60 |
+message.getStartPosition()+":"+message.getPosition()); |
|
61 |
System.out.println(message.toString()); |
|
62 |
System.out.format("Found problem: %s%n", message.getCode()); |
|
63 |
System.out.flush(); |
|
64 |
} |
|
65 |
}; |
|
66 |
compiler = ToolProvider.getSystemJavaCompiler(); |
|
67 |
fm = compiler.getStandardFileManager(dl, null, null); |
|
68 |
files = |
|
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
69 |
fm.getJavaFileObjectsFromFiles(Arrays.asList(testFile)); |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
70 |
createTestFile(); |
10 | 71 |
} |
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
72 |
final void createTestFile() throws IOException { |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
73 |
List<String> scratch = new ArrayList<>(); |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
74 |
scratch.add("// @author Peter von der Ah" + (char)0xe9); |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
75 |
scratch.add("class Utf8{}"); |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
76 |
Files.write(testFile.toPath(), scratch, Charset.forName("UTF-8"), |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
77 |
CREATE, TRUNCATE_EXISTING); |
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
78 |
} |
10 | 79 |
void test(String encoding, boolean good) { |
80 |
error = false; |
|
22444
c79ee1e6742f
8031745: Remove unneeded/obsolete -source/-target options in javac tests, part 1
darcy
parents:
18648
diff
changeset
|
81 |
Iterable<String> args = Arrays.asList("-encoding", encoding, "-d", "."); |
10 | 82 |
compiler.getTask(null, fm, dl, args, null, files).call(); |
83 |
if (error == good) { |
|
84 |
if (error) { |
|
85 |
throw new AssertionError("Error reported"); |
|
86 |
} else { |
|
87 |
throw new AssertionError("No error reported"); |
|
88 |
} |
|
89 |
} |
|
90 |
} |
|
91 |
||
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
92 |
void close() throws IOException { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
93 |
fm.close(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
94 |
} |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
95 |
|
18648
38447fa68349
8016908: TEST_BUG: removing non-ascii characters causes tests to fail
ksrini
parents:
18390
diff
changeset
|
96 |
public static void main(String[] args) throws IOException { |
10 | 97 |
T6306137 self = new T6306137(); |
27319
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
98 |
try { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
99 |
self.test("utf-8", true); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
100 |
self.test("ascii", false); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
101 |
self.test("utf-8", true); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
102 |
} finally { |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
103 |
self.close(); |
030080f03e4f
8062348: langtools tests should close file manager (group 1)
jjg
parents:
22444
diff
changeset
|
104 |
} |
10 | 105 |
} |
106 |
} |