Path: blob/master/test/langtools/tools/javac/6302184/HiddenOptionsShouldUseGivenEncodingTest.java
41152 views
/*1* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 6302184 6350124 635797926* @summary javac hidden options that generate source should use the given27* encoding, if available28* @library /tools/lib29* @modules jdk.compiler/com.sun.tools.javac.api30* jdk.compiler/com.sun.tools.javac.main31* @build toolbox.ToolBox toolbox.JavacTask32* @run main HiddenOptionsShouldUseGivenEncodingTest33*/3435import java.nio.charset.Charset;36import java.nio.file.Files;37import java.nio.file.Path;38import java.nio.file.Paths;39import java.util.Arrays;40import java.util.List;4142import toolbox.JavacTask;43import toolbox.ToolBox;4445// Original test: test/tools/javac/6302184/T6302184.sh46public class HiddenOptionsShouldUseGivenEncodingTest {4748public static void main(String[] args) throws Exception {49String encoding = "iso-8859-1";50Path src = Paths.get("src");51Files.createDirectories(src);52Files.write(src.resolve("T6302184.java"), source, Charset.forName(encoding));53Files.write(src.resolve("T6302184.out"), expect, Charset.forName(encoding));5455Path out = Paths.get("out");56Files.createDirectories(out);5758ToolBox tb = new ToolBox();59new JavacTask(tb)60.outdir("out")61.options("-encoding", encoding, "-XD-printsource")62.files(src.resolve("T6302184.java"))63.run();6465Path path1 = Paths.get("out").resolve("T6302184.java");66List<String> file1 = tb.readAllLines(path1, encoding);67Path path2 = src.resolve("T6302184.out");68List<String> file2 = tb.readAllLines(path2, encoding);69tb.checkEqual(file1, file2);70}7172static List<String> source = Arrays.asList(73"class T6302184 {",74" int \u00c0\u00c1\u00c2\u00c3\u00c4\u00c5 = 1;",75"}"76);7778static List<String> expect = Arrays.asList(79"",80"class T6302184 {",81" ",82" T6302184() {",83" super();",84" }",85" int \u00c0\u00c1\u00c2\u00c3\u00c4\u00c5 = 1;",86"}"87);8889}909192