test/tools/javac/api/6731573/T6731573.java

Fri, 27 Sep 2013 11:34:32 -0700

author
mduigou
date
Fri, 27 Sep 2013 11:34:32 -0700
changeset 2073
4ed8565fa536
parent 1733
e39669aea0bd
child 2525
2eb010b6cb22
permissions
-rw-r--r--

8024842: Define ABS_TEST_OUTPUT_DIR via TEST_OUTPUT_DIR
Reviewed-by: ihse, erikj, vromero

mcimadamore@137 1 /*
jjg@1733 2 * Copyright (c) 2008, 2013, 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
jjg@1733 30 * @build ToolTester
jjg@1733 31 * @run main T6731573
mcimadamore@137 32 */
mcimadamore@137 33
mcimadamore@137 34 import java.io.*;
mcimadamore@137 35 import java.util.*;
mcimadamore@137 36 import javax.tools.*;
mcimadamore@137 37
mcimadamore@137 38 public class T6731573 extends ToolTester {
mcimadamore@137 39
mcimadamore@137 40 enum DiagnosticType {
mcimadamore@137 41 BASIC(null) {
mcimadamore@137 42 boolean shouldDisplaySource(SourceLine sourceLine) {
mcimadamore@137 43 return sourceLine != SourceLine.DISABLED;
mcimadamore@137 44 }
mcimadamore@137 45 },
mcimadamore@137 46 RAW("-XDrawDiagnostics") {
mcimadamore@137 47 boolean shouldDisplaySource(SourceLine sourceLine) {
mcimadamore@137 48 return sourceLine == SourceLine.ENABLED;
mcimadamore@137 49 }
mcimadamore@137 50 };
mcimadamore@137 51
mcimadamore@137 52 String optValue;
mcimadamore@137 53
mcimadamore@137 54 DiagnosticType(String optValue) {
mcimadamore@137 55 this.optValue = optValue;
mcimadamore@137 56 }
mcimadamore@137 57
mcimadamore@137 58 abstract boolean shouldDisplaySource(SourceLine sourceLine);
mcimadamore@137 59 }
mcimadamore@137 60
mcimadamore@137 61 enum SourceLine {
mcimadamore@137 62 STANDARD(null),
mcimadamore@137 63 ENABLED("-XDshowSource=true"),
mcimadamore@137 64 DISABLED("-XDshowSource=false");
mcimadamore@137 65
mcimadamore@137 66 String optValue;
mcimadamore@137 67
mcimadamore@137 68 SourceLine(String optValue) {
mcimadamore@137 69 this.optValue = optValue;
mcimadamore@137 70 }
mcimadamore@137 71 }
mcimadamore@137 72
mcimadamore@137 73 void checkErrorLine(String output, boolean expected, List<String> options) {
mcimadamore@137 74 System.err.println("\noptions = "+options);
mcimadamore@137 75 System.err.println(output);
mcimadamore@137 76 boolean errLinePresent = output.contains("^");
mcimadamore@137 77 if (errLinePresent != expected) {
mcimadamore@137 78 throw new AssertionError("Error in diagnostic: error line" +
mcimadamore@137 79 (expected ? "" : " not") + " expected but" +
mcimadamore@137 80 (errLinePresent ? "" : " not") + " found");
mcimadamore@137 81 }
mcimadamore@137 82 }
mcimadamore@137 83
mcimadamore@137 84 void exec(DiagnosticType diagType, SourceLine sourceLine) {
mcimadamore@137 85 final Iterable<? extends JavaFileObject> compilationUnits =
mcimadamore@137 86 fm.getJavaFileObjects(new File(test_src, "Erroneous.java"));
mcimadamore@137 87 StringWriter pw = new StringWriter();
mcimadamore@137 88 ArrayList<String> options = new ArrayList<String>();
mcimadamore@137 89 if (diagType.optValue != null)
mcimadamore@137 90 options.add(diagType.optValue);
mcimadamore@137 91 if (sourceLine.optValue != null)
mcimadamore@137 92 options.add(sourceLine.optValue);
mcimadamore@137 93 task = tool.getTask(pw, fm, null, options, null, compilationUnits);
mcimadamore@137 94 task.call();
mcimadamore@137 95 checkErrorLine(pw.toString(),
mcimadamore@137 96 diagType.shouldDisplaySource(sourceLine),
mcimadamore@137 97 options);
mcimadamore@137 98 }
mcimadamore@137 99
mcimadamore@137 100 void test() {
mcimadamore@137 101 for (DiagnosticType dt : DiagnosticType.values()) {
mcimadamore@137 102 for (SourceLine sl : SourceLine.values()) {
mcimadamore@137 103 exec(dt, sl);
mcimadamore@137 104 }
mcimadamore@137 105 }
mcimadamore@137 106 }
mcimadamore@137 107
mcimadamore@137 108 public static void main(String... args) throws Exception {
mcimadamore@137 109 new T6731573().test();
mcimadamore@137 110 }
jjg@525 111 }

mercurial