Mon, 24 Oct 2011 13:00:30 +0100
7098660: Write better overload resolution/inference tests
Summary: Add overload/inference debug diagnostics - added test harness using annotations to check outcome of overload resolution/inference
Reviewed-by: jjg
mcimadamore@100 | 1 | /* |
ohair@554 | 2 | * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. |
mcimadamore@100 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@100 | 4 | * |
mcimadamore@100 | 5 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@100 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@100 | 7 | * published by the Free Software Foundation. |
mcimadamore@100 | 8 | * |
mcimadamore@100 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@100 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@100 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@100 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@100 | 13 | * accompanied this code). |
mcimadamore@100 | 14 | * |
mcimadamore@100 | 15 | * You should have received a copy of the GNU General Public License version |
mcimadamore@100 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@100 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@100 | 18 | * |
ohair@554 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohair@554 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohair@554 | 21 | * questions. |
mcimadamore@100 | 22 | */ |
mcimadamore@100 | 23 | |
mcimadamore@100 | 24 | /* |
mcimadamore@100 | 25 | * @test |
mcimadamore@100 | 26 | * @bug 6733837 |
mcimadamore@100 | 27 | * @summary Compiler API ignores locale settings |
mcimadamore@100 | 28 | * @author Maurizio Cimadamore |
mcimadamore@100 | 29 | * @library ../lib |
mcimadamore@100 | 30 | */ |
mcimadamore@100 | 31 | |
mcimadamore@100 | 32 | import java.io.StringWriter; |
mcimadamore@100 | 33 | import java.io.PrintWriter; |
mcimadamore@100 | 34 | import java.net.URI; |
mcimadamore@100 | 35 | import java.util.Arrays; |
mcimadamore@100 | 36 | import java.util.List; |
mcimadamore@100 | 37 | import javax.tools.JavaFileObject; |
mcimadamore@100 | 38 | import javax.tools.SimpleJavaFileObject; |
mcimadamore@100 | 39 | import static javax.tools.JavaFileObject.Kind; |
mcimadamore@100 | 40 | import com.sun.source.util.JavacTask; |
mcimadamore@100 | 41 | |
mcimadamore@100 | 42 | public class T6733837 extends ToolTester { |
mcimadamore@100 | 43 | |
mcimadamore@100 | 44 | public static void main(String... args) { |
mcimadamore@100 | 45 | new T6733837().exec(); |
mcimadamore@100 | 46 | } |
mcimadamore@100 | 47 | |
mcimadamore@100 | 48 | public void exec() { |
jjg@415 | 49 | JavaFileObject sfo = new SimpleJavaFileObject(URI.create("myfo:/Test.java"),Kind.SOURCE) { |
mcimadamore@100 | 50 | public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
mcimadamore@100 | 51 | return "\tclass ErroneousWithTab"; |
mcimadamore@100 | 52 | } |
mcimadamore@100 | 53 | }; |
mcimadamore@100 | 54 | StringWriter sw = new StringWriter(); |
mcimadamore@100 | 55 | PrintWriter out = new PrintWriter(sw); |
mcimadamore@100 | 56 | List<? extends JavaFileObject> files = Arrays.asList(sfo); |
mcimadamore@100 | 57 | task = tool.getTask(sw, fm, null, null, null, files); |
mcimadamore@100 | 58 | try { |
mcimadamore@100 | 59 | ((JavacTask)task).analyze(); |
mcimadamore@100 | 60 | } |
mcimadamore@100 | 61 | catch (Throwable t) { |
mcimadamore@100 | 62 | throw new Error("Compiler threw an exception"); |
mcimadamore@100 | 63 | } |
mcimadamore@100 | 64 | System.err.println(sw.toString()); |
jjg@415 | 65 | if (!sw.toString().contains("/Test.java")) |
mcimadamore@100 | 66 | throw new Error("Bad source name in diagnostic"); |
mcimadamore@100 | 67 | } |
mcimadamore@100 | 68 | } |