test/tools/javac/6668794/badClass/Test.java

Wed, 12 Mar 2008 13:06:00 -0700

author
jjg
date
Wed, 12 Mar 2008 13:06:00 -0700
changeset 12
7366066839bb
child 221
6ada6122dd4f
permissions
-rw-r--r--

6668794: javac puts localized text in raw diagnostics
6668796: bad diagnostic "bad class file" given for source files
Summary: Replace internal use of localized text with JCDiagnostic fragments; fix diagnostic for bad source file
Reviewed-by: mcimadamore

jjg@12 1 /*
jjg@12 2 * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
jjg@12 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@12 4 *
jjg@12 5 * This code is free software; you can redistribute it and/or modify it
jjg@12 6 * under the terms of the GNU General Public License version 2 only, as
jjg@12 7 * published by the Free Software Foundation. Sun designates this
jjg@12 8 * particular file as subject to the "Classpath" exception as provided
jjg@12 9 * by Sun in the LICENSE file that accompanied this code.
jjg@12 10 *
jjg@12 11 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@12 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@12 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@12 14 * version 2 for more details (a copy is included in the LICENSE file that
jjg@12 15 * accompanied this code).
jjg@12 16 *
jjg@12 17 * You should have received a copy of the GNU General Public License version
jjg@12 18 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@12 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@12 20 *
jjg@12 21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
jjg@12 22 * CA 95054 USA or visit www.sun.com if you need additional information or
jjg@12 23 * have any questions.
jjg@12 24 */
jjg@12 25
jjg@12 26 /*
jjg@12 27 * @test
jjg@12 28 * @bug 6668794 6668796
jjg@12 29 * @summary javac puts localized text in raw diagnostics
jjg@12 30 * bad diagnostic "bad class file" given for source files
jjg@12 31 */
jjg@12 32
jjg@12 33 import java.io.*;
jjg@12 34 import java.util.*;
jjg@12 35 import javax.tools.*;
jjg@12 36
jjg@12 37 public class Test {
jjg@12 38 public static void main(String[] args) throws Exception {
jjg@12 39 new Test().run();
jjg@12 40 }
jjg@12 41
jjg@12 42 void run() throws Exception {
jjg@12 43
jjg@12 44 // compile q.A then move it to p.A
jjg@12 45 compile("A.java");
jjg@12 46
jjg@12 47 File p = new File("p");
jjg@12 48 p.mkdirs();
jjg@12 49 new File("q/A.class").renameTo(new File("p/A.class"));
jjg@12 50
jjg@12 51 // compile B against p.A
jjg@12 52 String[] out = compile("B.java");
jjg@12 53 if (out.length == 0)
jjg@12 54 throw new Error("no diagnostics generated");
jjg@12 55
jjg@12 56 String expected = "B.java:6:6: compiler.err.cant.access: p.A, " +
jjg@12 57 "(- compiler.misc.bad.class.file.header: A.class, " +
jjg@12 58 "(- compiler.misc.class.file.wrong.class: q.A))";
jjg@12 59
jjg@12 60 if (!out[0].equals(expected)) {
jjg@12 61 System.err.println("expected: " + expected);
jjg@12 62 System.err.println(" found: " + out[0]);
jjg@12 63 throw new Error("test failed");
jjg@12 64 }
jjg@12 65 }
jjg@12 66
jjg@12 67 String[] compile(String file) {
jjg@12 68 String[] options = {
jjg@12 69 "-XDrawDiagnostics",
jjg@12 70 "-d", ".",
jjg@12 71 "-classpath", ".",
jjg@12 72 new File(testSrc, file).getPath()
jjg@12 73 };
jjg@12 74
jjg@12 75 System.err.println("compile: " + Arrays.asList(options));
jjg@12 76 StringWriter sw = new StringWriter();
jjg@12 77 PrintWriter out = new PrintWriter(sw);
jjg@12 78 int rc = com.sun.tools.javac.Main.compile(options, out);
jjg@12 79 out.close();
jjg@12 80
jjg@12 81 String outText = sw.toString();
jjg@12 82 System.err.println(outText);
jjg@12 83
jjg@12 84 return sw.toString().split("[\\r\\n]+");
jjg@12 85 }
jjg@12 86
jjg@12 87 File testSrc = new File(System.getProperty("test.src", "."));
jjg@12 88 }

mercurial