Tue, 10 Sep 2013 13:47:51 +0200
8005222: Fixed bugs should have tests with bugid in @bug tag
Reviewed-by: jfranck, jjg
Contributed-by: Andreas Lundblad <andreas.lundblad@oracle.com>
mcimadamore@1415 | 1 | /* |
mcimadamore@1415 | 2 | * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
mcimadamore@1415 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@1415 | 4 | * |
mcimadamore@1415 | 5 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@1415 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@1415 | 7 | * published by the Free Software Foundation. |
mcimadamore@1415 | 8 | * |
mcimadamore@1415 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@1415 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@1415 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@1415 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@1415 | 13 | * accompanied this code). |
mcimadamore@1415 | 14 | * |
mcimadamore@1415 | 15 | * You should have received a copy of the GNU General Public License version |
mcimadamore@1415 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@1415 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@1415 | 18 | * |
mcimadamore@1415 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
mcimadamore@1415 | 20 | * or visit www.oracle.com if you need additional information or have any |
mcimadamore@1415 | 21 | * questions. |
mcimadamore@1415 | 22 | */ |
mcimadamore@1415 | 23 | |
mcimadamore@1415 | 24 | /* |
mcimadamore@1415 | 25 | * @test |
mcimadamore@1415 | 26 | * @bug 8003280 |
mcimadamore@1415 | 27 | * @summary Add lambda tests |
mcimadamore@1415 | 28 | * check that all diagnostics are dumped to output when compiler exits abruptly |
mcimadamore@1415 | 29 | */ |
mcimadamore@1415 | 30 | |
mcimadamore@1415 | 31 | import com.sun.source.util.JavacTask; |
mcimadamore@1415 | 32 | import java.io.BufferedWriter; |
mcimadamore@1415 | 33 | import java.io.IOException; |
mcimadamore@1415 | 34 | import java.io.StringWriter; |
mcimadamore@1415 | 35 | import java.net.URI; |
mcimadamore@1415 | 36 | import java.net.URL; |
mcimadamore@1415 | 37 | import java.util.Arrays; |
mcimadamore@1415 | 38 | import javax.tools.Diagnostic; |
mcimadamore@1415 | 39 | import javax.tools.JavaCompiler; |
mcimadamore@1415 | 40 | import javax.tools.JavaFileObject; |
mcimadamore@1415 | 41 | import javax.tools.SimpleJavaFileObject; |
mcimadamore@1415 | 42 | import javax.tools.StandardJavaFileManager; |
mcimadamore@1415 | 43 | import javax.tools.ToolProvider; |
mcimadamore@1415 | 44 | |
mcimadamore@1415 | 45 | public class Abort { |
mcimadamore@1415 | 46 | |
mcimadamore@1415 | 47 | public static void main(String... args) throws Exception { |
mcimadamore@1415 | 48 | |
mcimadamore@1415 | 49 | String SCRATCH_DIR = System.getProperty("user.dir"); |
mcimadamore@1415 | 50 | JavaCompiler javacTool = ToolProvider.getSystemJavaCompiler(); |
mcimadamore@1415 | 51 | java.io.File testDir = new java.io.File(SCRATCH_DIR); |
mcimadamore@1415 | 52 | |
mcimadamore@1415 | 53 | sourceA.dumpTo(testDir); |
mcimadamore@1415 | 54 | sourceB.dumpTo(testDir); |
mcimadamore@1415 | 55 | |
mcimadamore@1415 | 56 | DiagnosticChecker diagChecker = new DiagnosticChecker(); |
mcimadamore@1415 | 57 | JavacTask ct = (JavacTask)javacTool.getTask(null, null, diagChecker, |
mcimadamore@1415 | 58 | Arrays.asList("-XDrawDiagnostics", "-cp", testDir.getAbsolutePath()), |
mcimadamore@1415 | 59 | null, Arrays.asList(sourceA.asJFO(testDir))); |
mcimadamore@1415 | 60 | try { |
mcimadamore@1415 | 61 | ct.analyze(); |
mcimadamore@1415 | 62 | } catch (Throwable ex) { |
mcimadamore@1415 | 63 | //ignore abort exception thrown by javac |
mcimadamore@1415 | 64 | } |
mcimadamore@1415 | 65 | |
mcimadamore@1415 | 66 | if (!diagChecker.errorFound) { |
mcimadamore@1415 | 67 | throw new AssertionError("Missing diagnostic"); |
mcimadamore@1415 | 68 | } |
mcimadamore@1415 | 69 | } |
mcimadamore@1415 | 70 | |
mcimadamore@1415 | 71 | static class JavaSource { |
mcimadamore@1415 | 72 | String contents; |
mcimadamore@1415 | 73 | String filename; |
mcimadamore@1415 | 74 | |
mcimadamore@1415 | 75 | public JavaSource(String filename, String contents) { |
mcimadamore@1415 | 76 | this.filename = filename; |
mcimadamore@1415 | 77 | this.contents = contents; |
mcimadamore@1415 | 78 | } |
mcimadamore@1415 | 79 | |
mcimadamore@1415 | 80 | void dumpTo(java.io.File loc) throws Exception { |
mcimadamore@1415 | 81 | java.io.File file = new java.io.File(loc, filename); |
mcimadamore@1415 | 82 | java.io.BufferedWriter bw = new java.io.BufferedWriter(new java.io.FileWriter(file)); |
mcimadamore@1415 | 83 | bw.append(contents); |
mcimadamore@1415 | 84 | bw.close(); |
mcimadamore@1415 | 85 | } |
mcimadamore@1415 | 86 | |
mcimadamore@1415 | 87 | SimpleJavaFileObject asJFO(java.io.File dir) { |
mcimadamore@1421 | 88 | return new SimpleJavaFileObject(new java.io.File(dir, filename).toURI(), JavaFileObject.Kind.SOURCE) { |
mcimadamore@1415 | 89 | @Override |
mcimadamore@1415 | 90 | public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException { |
mcimadamore@1415 | 91 | return contents; |
mcimadamore@1415 | 92 | } |
mcimadamore@1415 | 93 | }; |
mcimadamore@1415 | 94 | } |
mcimadamore@1415 | 95 | } |
mcimadamore@1415 | 96 | |
mcimadamore@1415 | 97 | static JavaSource sourceA = new JavaSource("Abort.java", "public class Abort {\n" + |
mcimadamore@1415 | 98 | " public static void main(String[] args) {\n" + |
mcimadamore@1415 | 99 | " System.out.println(C.m());\n" + |
mcimadamore@1415 | 100 | " }\n" + |
mcimadamore@1415 | 101 | "}"); |
mcimadamore@1415 | 102 | |
mcimadamore@1415 | 103 | static JavaSource sourceB = new JavaSource("C.java", "package com.example;\n" + |
mcimadamore@1415 | 104 | "public class C {\n" + |
mcimadamore@1415 | 105 | " public static String m() { return null; }\n" + |
mcimadamore@1415 | 106 | "}"); |
mcimadamore@1415 | 107 | |
mcimadamore@1415 | 108 | static class DiagnosticChecker implements javax.tools.DiagnosticListener<JavaFileObject> { |
mcimadamore@1415 | 109 | |
mcimadamore@1415 | 110 | boolean errorFound; |
mcimadamore@1415 | 111 | |
mcimadamore@1415 | 112 | public void report(Diagnostic<? extends JavaFileObject> diagnostic) { |
mcimadamore@1415 | 113 | if (diagnostic.getKind() == Diagnostic.Kind.ERROR && |
mcimadamore@1415 | 114 | diagnostic.getCode().contains("compiler.err.cant.access")) { |
mcimadamore@1415 | 115 | errorFound = true; |
mcimadamore@1415 | 116 | } |
mcimadamore@1415 | 117 | } |
mcimadamore@1415 | 118 | } |
mcimadamore@1415 | 119 | } |