Fri, 02 Nov 2012 14:35:57 -0700
7169362: JDK8: Write compiler tests for repeating annotations for JDK8
Reviewed-by: darcy, jjg
Contributed-by: sonali.goel@oracle.com
mcimadamore@137 | 1 | /* |
ohair@798 | 2 | * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. |
mcimadamore@137 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mcimadamore@137 | 4 | * |
mcimadamore@137 | 5 | * This code is free software; you can redistribute it and/or modify it |
mcimadamore@137 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mcimadamore@137 | 7 | * published by the Free Software Foundation. |
mcimadamore@137 | 8 | * |
mcimadamore@137 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mcimadamore@137 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mcimadamore@137 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mcimadamore@137 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
mcimadamore@137 | 13 | * accompanied this code). |
mcimadamore@137 | 14 | * |
mcimadamore@137 | 15 | * You should have received a copy of the GNU General Public License version |
mcimadamore@137 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
mcimadamore@137 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mcimadamore@137 | 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@137 | 22 | */ |
mcimadamore@137 | 23 | |
mcimadamore@137 | 24 | /* |
mcimadamore@137 | 25 | * @test |
mcimadamore@137 | 26 | * @bug 6731573 |
mcimadamore@137 | 27 | * @summary diagnostic output should optionally include source line |
mcimadamore@137 | 28 | * @author Maurizio Cimadamore |
mcimadamore@137 | 29 | * @library ../lib |
mcimadamore@137 | 30 | */ |
mcimadamore@137 | 31 | |
mcimadamore@137 | 32 | import java.io.*; |
mcimadamore@137 | 33 | import java.util.*; |
mcimadamore@137 | 34 | import javax.tools.*; |
mcimadamore@137 | 35 | |
mcimadamore@137 | 36 | public class T6731573 extends ToolTester { |
mcimadamore@137 | 37 | |
mcimadamore@137 | 38 | enum DiagnosticType { |
mcimadamore@137 | 39 | BASIC(null) { |
mcimadamore@137 | 40 | boolean shouldDisplaySource(SourceLine sourceLine) { |
mcimadamore@137 | 41 | return sourceLine != SourceLine.DISABLED; |
mcimadamore@137 | 42 | } |
mcimadamore@137 | 43 | }, |
mcimadamore@137 | 44 | RAW("-XDrawDiagnostics") { |
mcimadamore@137 | 45 | boolean shouldDisplaySource(SourceLine sourceLine) { |
mcimadamore@137 | 46 | return sourceLine == SourceLine.ENABLED; |
mcimadamore@137 | 47 | } |
mcimadamore@137 | 48 | }; |
mcimadamore@137 | 49 | |
mcimadamore@137 | 50 | String optValue; |
mcimadamore@137 | 51 | |
mcimadamore@137 | 52 | DiagnosticType(String optValue) { |
mcimadamore@137 | 53 | this.optValue = optValue; |
mcimadamore@137 | 54 | } |
mcimadamore@137 | 55 | |
mcimadamore@137 | 56 | abstract boolean shouldDisplaySource(SourceLine sourceLine); |
mcimadamore@137 | 57 | } |
mcimadamore@137 | 58 | |
mcimadamore@137 | 59 | enum SourceLine { |
mcimadamore@137 | 60 | STANDARD(null), |
mcimadamore@137 | 61 | ENABLED("-XDshowSource=true"), |
mcimadamore@137 | 62 | DISABLED("-XDshowSource=false"); |
mcimadamore@137 | 63 | |
mcimadamore@137 | 64 | String optValue; |
mcimadamore@137 | 65 | |
mcimadamore@137 | 66 | SourceLine(String optValue) { |
mcimadamore@137 | 67 | this.optValue = optValue; |
mcimadamore@137 | 68 | } |
mcimadamore@137 | 69 | } |
mcimadamore@137 | 70 | |
mcimadamore@137 | 71 | void checkErrorLine(String output, boolean expected, List<String> options) { |
mcimadamore@137 | 72 | System.err.println("\noptions = "+options); |
mcimadamore@137 | 73 | System.err.println(output); |
mcimadamore@137 | 74 | boolean errLinePresent = output.contains("^"); |
mcimadamore@137 | 75 | if (errLinePresent != expected) { |
mcimadamore@137 | 76 | throw new AssertionError("Error in diagnostic: error line" + |
mcimadamore@137 | 77 | (expected ? "" : " not") + " expected but" + |
mcimadamore@137 | 78 | (errLinePresent ? "" : " not") + " found"); |
mcimadamore@137 | 79 | } |
mcimadamore@137 | 80 | } |
mcimadamore@137 | 81 | |
mcimadamore@137 | 82 | void exec(DiagnosticType diagType, SourceLine sourceLine) { |
mcimadamore@137 | 83 | final Iterable<? extends JavaFileObject> compilationUnits = |
mcimadamore@137 | 84 | fm.getJavaFileObjects(new File(test_src, "Erroneous.java")); |
mcimadamore@137 | 85 | StringWriter pw = new StringWriter(); |
mcimadamore@137 | 86 | ArrayList<String> options = new ArrayList<String>(); |
mcimadamore@137 | 87 | if (diagType.optValue != null) |
mcimadamore@137 | 88 | options.add(diagType.optValue); |
mcimadamore@137 | 89 | if (sourceLine.optValue != null) |
mcimadamore@137 | 90 | options.add(sourceLine.optValue); |
mcimadamore@137 | 91 | task = tool.getTask(pw, fm, null, options, null, compilationUnits); |
mcimadamore@137 | 92 | task.call(); |
mcimadamore@137 | 93 | checkErrorLine(pw.toString(), |
mcimadamore@137 | 94 | diagType.shouldDisplaySource(sourceLine), |
mcimadamore@137 | 95 | options); |
mcimadamore@137 | 96 | } |
mcimadamore@137 | 97 | |
mcimadamore@137 | 98 | void test() { |
mcimadamore@137 | 99 | for (DiagnosticType dt : DiagnosticType.values()) { |
mcimadamore@137 | 100 | for (SourceLine sl : SourceLine.values()) { |
mcimadamore@137 | 101 | exec(dt, sl); |
mcimadamore@137 | 102 | } |
mcimadamore@137 | 103 | } |
mcimadamore@137 | 104 | } |
mcimadamore@137 | 105 | |
mcimadamore@137 | 106 | public static void main(String... args) throws Exception { |
mcimadamore@137 | 107 | new T6731573().test(); |
mcimadamore@137 | 108 | } |
jjg@525 | 109 | } |