Test.java revision 553
11N/A/*
553N/A * Copyright (c) 2008, 2009, Oracle and/or its affiliates. All rights reserved.
11N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
11N/A *
11N/A * This code is free software; you can redistribute it and/or modify it
11N/A * under the terms of the GNU General Public License version 2 only, as
553N/A * published by the Free Software Foundation. Oracle designates this
11N/A * particular file as subject to the "Classpath" exception as provided
553N/A * by Oracle in the LICENSE file that accompanied this code.
11N/A *
11N/A * This code is distributed in the hope that it will be useful, but WITHOUT
11N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11N/A * version 2 for more details (a copy is included in the LICENSE file that
11N/A * accompanied this code).
11N/A *
11N/A * You should have received a copy of the GNU General Public License version
11N/A * 2 along with this work; if not, write to the Free Software Foundation,
11N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
11N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
11N/A */
11N/A
11N/A/*
11N/A * @test
11N/A * @bug 6668794 6668796
11N/A * @summary javac puts localized text in raw diagnostics
11N/A * bad diagnostic "bad class file" given for source files
11N/A */
11N/A
11N/Aimport java.io.*;
11N/Aimport java.util.*;
11N/Aimport javax.tools.*;
11N/A
11N/Apublic class Test {
11N/A public static void main(String[] args) throws Exception {
11N/A new Test().run();
11N/A }
11N/A
11N/A void run() throws Exception {
11N/A
11N/A // compile q.A then move it to p.A
11N/A compile("A.java");
11N/A
11N/A File p = new File("p");
11N/A p.mkdirs();
11N/A new File("q/A.class").renameTo(new File("p/A.class"));
11N/A
11N/A // compile B against p.A
11N/A String[] out = compile("B.java");
11N/A if (out.length == 0)
11N/A throw new Error("no diagnostics generated");
11N/A
11N/A String expected = "B.java:6:6: compiler.err.cant.access: p.A, " +
220N/A "(compiler.misc.bad.class.file.header: A.class, " +
220N/A "(compiler.misc.class.file.wrong.class: q.A))";
11N/A
11N/A if (!out[0].equals(expected)) {
11N/A System.err.println("expected: " + expected);
11N/A System.err.println(" found: " + out[0]);
11N/A throw new Error("test failed");
11N/A }
11N/A }
11N/A
11N/A String[] compile(String file) {
11N/A String[] options = {
11N/A "-XDrawDiagnostics",
11N/A "-d", ".",
11N/A "-classpath", ".",
11N/A new File(testSrc, file).getPath()
11N/A };
11N/A
11N/A System.err.println("compile: " + Arrays.asList(options));
11N/A StringWriter sw = new StringWriter();
11N/A PrintWriter out = new PrintWriter(sw);
11N/A int rc = com.sun.tools.javac.Main.compile(options, out);
11N/A out.close();
11N/A
11N/A String outText = sw.toString();
11N/A System.err.println(outText);
11N/A
11N/A return sw.toString().split("[\\r\\n]+");
11N/A }
11N/A
11N/A File testSrc = new File(System.getProperty("test.src", "."));
11N/A}