2013-02-19 17:53:16 +00:00
|
|
|
/*
|
2016-03-31 22:20:50 +00:00
|
|
|
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
|
2013-02-19 17:53:16 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @test
|
|
|
|
* @bug 4846262
|
|
|
|
* @summary check that javac operates correctly in EBCDIC locale
|
2014-08-13 20:20:31 +00:00
|
|
|
* @library /tools/lib
|
2015-05-21 18:41:04 +00:00
|
|
|
* @modules jdk.compiler/com.sun.tools.javac.api
|
|
|
|
* jdk.compiler/com.sun.tools.javac.main
|
8142968: Module System implementation
Initial integration of JEP 200, JEP 260, JEP 261, and JEP 282
Co-authored-by: Alex Buckley <alex.buckley@oracle.com>
Co-authored-by: Jonathan Gibbons <jonathan.gibbons@oracle.com>
Co-authored-by: Karen Kinnear <karen.kinnear@oracle.com>
Co-authored-by: Mandy Chung <mandy.chung@oracle.com>
Co-authored-by: Mark Reinhold <mark.reinhold@oracle.com>
Co-authored-by: Jan Lahoda <jan.lahoda@oracle.com>
Co-authored-by: Vicente Romero <vicente.romero@oracle.com>
Co-authored-by: Andreas Lundblad <andreas.lundblad@oracle.com>
Co-authored-by: Andrey Nazarov <andrey.x.nazarov@oracle.com>
Co-authored-by: Chris Hegarty <chris.hegarty@oracle.com>
Co-authored-by: Erik Joelsson <erik.joelsson@oracle.com>
Co-authored-by: Kumar Srinivasan <kumar.x.srinivasan@oracle.com>
Co-authored-by: Sundararajan Athijegannathan <sundararajan.athijegannathan@oracle.com>
Reviewed-by: jjg, jlahoda, vromero, mcimadamore, bpatel, ksrini, darcy, anazarov, dfuchs
2016-03-17 19:04:28 +00:00
|
|
|
* jdk.jdeps/com.sun.tools.javap
|
2016-03-31 22:20:50 +00:00
|
|
|
* @build toolbox.ToolBox
|
2013-02-19 17:53:16 +00:00
|
|
|
* @run main CheckEBCDICLocaleTest
|
|
|
|
*/
|
|
|
|
|
|
|
|
import java.io.File;
|
2015-05-30 00:15:10 +00:00
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.OutputStreamWriter;
|
2015-05-29 22:50:31 +00:00
|
|
|
import java.io.PrintStream;
|
2015-05-30 00:15:10 +00:00
|
|
|
import java.io.PrintWriter;
|
2015-05-22 23:44:49 +00:00
|
|
|
import java.nio.charset.Charset;
|
2013-02-19 17:53:16 +00:00
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Paths;
|
|
|
|
import java.util.Arrays;
|
2014-08-13 20:20:31 +00:00
|
|
|
import java.util.List;
|
2013-02-19 17:53:16 +00:00
|
|
|
|
2016-03-31 22:20:50 +00:00
|
|
|
import toolbox.ToolBox;
|
|
|
|
|
2013-02-19 17:53:16 +00:00
|
|
|
public class CheckEBCDICLocaleTest {
|
|
|
|
|
|
|
|
private static final String TestSrc =
|
|
|
|
"public class Test {\n" +
|
|
|
|
" public void test() {\n" +
|
|
|
|
" abcdefg\n" +
|
|
|
|
" }\n" +
|
|
|
|
"}";
|
|
|
|
|
2013-03-14 08:30:16 +00:00
|
|
|
private static final String TestOutTemplate =
|
|
|
|
"output%1$sTest.java:3: error: not a statement\n" +
|
2013-02-19 17:53:16 +00:00
|
|
|
" abcdefg\n" +
|
|
|
|
" ^\n" +
|
2013-03-14 08:30:16 +00:00
|
|
|
"output%1$sTest.java:3: error: ';' expected\n" +
|
2013-02-19 17:53:16 +00:00
|
|
|
" abcdefg\n" +
|
|
|
|
" ^\n" +
|
|
|
|
"2 errors\n";
|
|
|
|
|
|
|
|
public static void main(String[] args) throws Exception {
|
|
|
|
new CheckEBCDICLocaleTest().test();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void test() throws Exception {
|
2014-08-13 20:20:31 +00:00
|
|
|
ToolBox tb = new ToolBox();
|
|
|
|
tb.writeFile("Test.java", TestSrc);
|
|
|
|
tb.createDirectories("output");
|
2013-02-19 17:53:16 +00:00
|
|
|
|
2015-05-30 00:15:10 +00:00
|
|
|
Charset ebcdic = Charset.forName("IBM1047");
|
|
|
|
Native2Ascii n2a = new Native2Ascii(ebcdic);
|
2015-05-22 23:44:49 +00:00
|
|
|
n2a.asciiToNative(Paths.get("Test.java"), Paths.get("output", "Test.java"));
|
2013-02-19 17:53:16 +00:00
|
|
|
|
2015-05-30 00:15:10 +00:00
|
|
|
// Use -encoding to specify the encoding with which to read source files
|
|
|
|
// Use a suitable configured output stream for javac diagnostics
|
|
|
|
int rc;
|
|
|
|
try (PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream("Test.tmp"), ebcdic))) {
|
|
|
|
String[] args = { "-encoding", ebcdic.name(), "output/Test.java" };
|
|
|
|
rc = com.sun.tools.javac.Main.compile(args, out);
|
|
|
|
if (rc != 1)
|
|
|
|
throw new Exception("unexpected exit from javac: " + rc);
|
|
|
|
}
|
2013-02-19 17:53:16 +00:00
|
|
|
|
2015-05-22 23:44:49 +00:00
|
|
|
n2a.nativeToAscii(Paths.get("Test.tmp"), Paths.get("Test.out"));
|
2013-02-19 17:53:16 +00:00
|
|
|
|
2014-08-13 20:20:31 +00:00
|
|
|
List<String> expectLines = Arrays.asList(
|
|
|
|
String.format(TestOutTemplate, File.separator).split("\n"));
|
|
|
|
List<String> actualLines = Files.readAllLines(Paths.get("Test.out"));
|
2015-05-28 19:08:54 +00:00
|
|
|
try {
|
|
|
|
tb.checkEqual(expectLines, actualLines);
|
|
|
|
} catch (Throwable tt) {
|
2015-05-29 22:50:31 +00:00
|
|
|
PrintStream out = tb.out;
|
|
|
|
out.println("Output mismatch:");
|
2015-05-28 19:08:54 +00:00
|
|
|
|
2015-05-29 22:50:31 +00:00
|
|
|
out.println("Expected output:");
|
|
|
|
for (String s: expectLines) {
|
|
|
|
out.println(s);
|
|
|
|
}
|
|
|
|
out.println();
|
|
|
|
|
|
|
|
out.println("Actual output:");
|
2015-05-28 19:08:54 +00:00
|
|
|
for (String s : actualLines) {
|
2015-05-29 22:50:31 +00:00
|
|
|
out.println(s);
|
2015-05-28 19:08:54 +00:00
|
|
|
}
|
2015-05-29 22:50:31 +00:00
|
|
|
out.println();
|
|
|
|
|
2015-05-28 19:08:54 +00:00
|
|
|
throw tt;
|
|
|
|
}
|
2013-02-19 17:53:16 +00:00
|
|
|
}
|
|
|
|
}
|