author | shade |
Tue, 02 Feb 2016 18:15:15 +0300 | |
changeset 35639 | f34e7e8b4eac |
parent 31002 | b99fa15b3717 |
child 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
16304
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
26100
diff
changeset
|
2 |
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. |
16304
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
4 |
* |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
8 |
* |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
13 |
* accompanied this code). |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
14 |
* |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
18 |
* |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
21 |
* questions. |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
22 |
*/ |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
23 |
|
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
24 |
/* |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
25 |
* @test |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
26 |
* @bug 4846262 |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
27 |
* @summary check that javac operates correctly in EBCDIC locale |
26100 | 28 |
* @library /tools/lib |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
26100
diff
changeset
|
29 |
* @modules jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
26100
diff
changeset
|
30 |
* jdk.compiler/com.sun.tools.javac.file |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
26100
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.main |
16304
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
32 |
* @build ToolBox |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
33 |
* @run main CheckEBCDICLocaleTest |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
34 |
*/ |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
35 |
|
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
36 |
import java.io.File; |
31002 | 37 |
import java.io.FileOutputStream; |
38 |
import java.io.OutputStreamWriter; |
|
31001 | 39 |
import java.io.PrintStream; |
31002 | 40 |
import java.io.PrintWriter; |
30844 | 41 |
import java.nio.charset.Charset; |
16304
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
42 |
import java.nio.file.Files; |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
43 |
import java.nio.file.Paths; |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
44 |
import java.util.Arrays; |
26100 | 45 |
import java.util.List; |
16304
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
46 |
|
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
47 |
public class CheckEBCDICLocaleTest { |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
48 |
|
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
49 |
private static final String TestSrc = |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
50 |
"public class Test {\n" + |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
51 |
" public void test() {\n" + |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
52 |
" abcdefg\n" + |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
53 |
" }\n" + |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
54 |
"}"; |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
55 |
|
16549
1bdeedb5446c
8008582: jtreg failures after conversion of shell tests to Java
vromero
parents:
16304
diff
changeset
|
56 |
private static final String TestOutTemplate = |
1bdeedb5446c
8008582: jtreg failures after conversion of shell tests to Java
vromero
parents:
16304
diff
changeset
|
57 |
"output%1$sTest.java:3: error: not a statement\n" + |
16304
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
58 |
" abcdefg\n" + |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
59 |
" ^\n" + |
16549
1bdeedb5446c
8008582: jtreg failures after conversion of shell tests to Java
vromero
parents:
16304
diff
changeset
|
60 |
"output%1$sTest.java:3: error: ';' expected\n" + |
16304
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
61 |
" abcdefg\n" + |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
62 |
" ^\n" + |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
63 |
"2 errors\n"; |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
64 |
|
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
65 |
public static void main(String[] args) throws Exception { |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
66 |
new CheckEBCDICLocaleTest().test(); |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
67 |
} |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
68 |
|
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
69 |
public void test() throws Exception { |
26100 | 70 |
ToolBox tb = new ToolBox(); |
71 |
tb.writeFile("Test.java", TestSrc); |
|
72 |
tb.createDirectories("output"); |
|
73 |
||
31002 | 74 |
Charset ebcdic = Charset.forName("IBM1047"); |
75 |
Native2Ascii n2a = new Native2Ascii(ebcdic); |
|
30844 | 76 |
n2a.asciiToNative(Paths.get("Test.java"), Paths.get("output", "Test.java")); |
16304
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
77 |
|
31002 | 78 |
// Use -encoding to specify the encoding with which to read source files |
79 |
// Use a suitable configured output stream for javac diagnostics |
|
80 |
int rc; |
|
81 |
try (PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream("Test.tmp"), ebcdic))) { |
|
82 |
String[] args = { "-encoding", ebcdic.name(), "output/Test.java" }; |
|
83 |
rc = com.sun.tools.javac.Main.compile(args, out); |
|
84 |
if (rc != 1) |
|
85 |
throw new Exception("unexpected exit from javac: " + rc); |
|
86 |
} |
|
16304
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
87 |
|
30844 | 88 |
n2a.nativeToAscii(Paths.get("Test.tmp"), Paths.get("Test.out")); |
16304
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
89 |
|
26100 | 90 |
List<String> expectLines = Arrays.asList( |
91 |
String.format(TestOutTemplate, File.separator).split("\n")); |
|
92 |
List<String> actualLines = Files.readAllLines(Paths.get("Test.out")); |
|
30847
9385b9c8506b
8081417: test CheckEBCDICLocaleTest.java is failing intermittently
vromero
parents:
30844
diff
changeset
|
93 |
try { |
9385b9c8506b
8081417: test CheckEBCDICLocaleTest.java is failing intermittently
vromero
parents:
30844
diff
changeset
|
94 |
tb.checkEqual(expectLines, actualLines); |
9385b9c8506b
8081417: test CheckEBCDICLocaleTest.java is failing intermittently
vromero
parents:
30844
diff
changeset
|
95 |
} catch (Throwable tt) { |
31001 | 96 |
PrintStream out = tb.out; |
97 |
out.println("Output mismatch:"); |
|
30847
9385b9c8506b
8081417: test CheckEBCDICLocaleTest.java is failing intermittently
vromero
parents:
30844
diff
changeset
|
98 |
|
31001 | 99 |
out.println("Expected output:"); |
100 |
for (String s: expectLines) { |
|
101 |
out.println(s); |
|
102 |
} |
|
103 |
out.println(); |
|
104 |
||
105 |
out.println("Actual output:"); |
|
30847
9385b9c8506b
8081417: test CheckEBCDICLocaleTest.java is failing intermittently
vromero
parents:
30844
diff
changeset
|
106 |
for (String s : actualLines) { |
31001 | 107 |
out.println(s); |
30847
9385b9c8506b
8081417: test CheckEBCDICLocaleTest.java is failing intermittently
vromero
parents:
30844
diff
changeset
|
108 |
} |
31001 | 109 |
out.println(); |
110 |
||
30847
9385b9c8506b
8081417: test CheckEBCDICLocaleTest.java is failing intermittently
vromero
parents:
30844
diff
changeset
|
111 |
throw tt; |
9385b9c8506b
8081417: test CheckEBCDICLocaleTest.java is failing intermittently
vromero
parents:
30844
diff
changeset
|
112 |
} |
16304
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
113 |
} |
475504933a2d
8006212: javac, convert jtreg tests from shell script to java
vromero
parents:
diff
changeset
|
114 |
} |