mcimadamore@137: /* ohair@798: * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. mcimadamore@137: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. mcimadamore@137: * mcimadamore@137: * This code is free software; you can redistribute it and/or modify it mcimadamore@137: * under the terms of the GNU General Public License version 2 only, as mcimadamore@137: * published by the Free Software Foundation. mcimadamore@137: * mcimadamore@137: * This code is distributed in the hope that it will be useful, but WITHOUT mcimadamore@137: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or mcimadamore@137: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License mcimadamore@137: * version 2 for more details (a copy is included in the LICENSE file that mcimadamore@137: * accompanied this code). mcimadamore@137: * mcimadamore@137: * You should have received a copy of the GNU General Public License version mcimadamore@137: * 2 along with this work; if not, write to the Free Software Foundation, mcimadamore@137: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. mcimadamore@137: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. mcimadamore@137: */ mcimadamore@137: mcimadamore@137: /* mcimadamore@137: * @test mcimadamore@137: * @bug 6731573 mcimadamore@137: * @summary diagnostic output should optionally include source line mcimadamore@137: * @author Maurizio Cimadamore mcimadamore@137: * @library ../lib mcimadamore@137: */ mcimadamore@137: mcimadamore@137: import java.io.*; mcimadamore@137: import java.util.*; mcimadamore@137: import javax.tools.*; mcimadamore@137: mcimadamore@137: public class T6731573 extends ToolTester { mcimadamore@137: mcimadamore@137: enum DiagnosticType { mcimadamore@137: BASIC(null) { mcimadamore@137: boolean shouldDisplaySource(SourceLine sourceLine) { mcimadamore@137: return sourceLine != SourceLine.DISABLED; mcimadamore@137: } mcimadamore@137: }, mcimadamore@137: RAW("-XDrawDiagnostics") { mcimadamore@137: boolean shouldDisplaySource(SourceLine sourceLine) { mcimadamore@137: return sourceLine == SourceLine.ENABLED; mcimadamore@137: } mcimadamore@137: }; mcimadamore@137: mcimadamore@137: String optValue; mcimadamore@137: mcimadamore@137: DiagnosticType(String optValue) { mcimadamore@137: this.optValue = optValue; mcimadamore@137: } mcimadamore@137: mcimadamore@137: abstract boolean shouldDisplaySource(SourceLine sourceLine); mcimadamore@137: } mcimadamore@137: mcimadamore@137: enum SourceLine { mcimadamore@137: STANDARD(null), mcimadamore@137: ENABLED("-XDshowSource=true"), mcimadamore@137: DISABLED("-XDshowSource=false"); mcimadamore@137: mcimadamore@137: String optValue; mcimadamore@137: mcimadamore@137: SourceLine(String optValue) { mcimadamore@137: this.optValue = optValue; mcimadamore@137: } mcimadamore@137: } mcimadamore@137: mcimadamore@137: void checkErrorLine(String output, boolean expected, List options) { mcimadamore@137: System.err.println("\noptions = "+options); mcimadamore@137: System.err.println(output); mcimadamore@137: boolean errLinePresent = output.contains("^"); mcimadamore@137: if (errLinePresent != expected) { mcimadamore@137: throw new AssertionError("Error in diagnostic: error line" + mcimadamore@137: (expected ? "" : " not") + " expected but" + mcimadamore@137: (errLinePresent ? "" : " not") + " found"); mcimadamore@137: } mcimadamore@137: } mcimadamore@137: mcimadamore@137: void exec(DiagnosticType diagType, SourceLine sourceLine) { mcimadamore@137: final Iterable compilationUnits = mcimadamore@137: fm.getJavaFileObjects(new File(test_src, "Erroneous.java")); mcimadamore@137: StringWriter pw = new StringWriter(); mcimadamore@137: ArrayList options = new ArrayList(); mcimadamore@137: if (diagType.optValue != null) mcimadamore@137: options.add(diagType.optValue); mcimadamore@137: if (sourceLine.optValue != null) mcimadamore@137: options.add(sourceLine.optValue); mcimadamore@137: task = tool.getTask(pw, fm, null, options, null, compilationUnits); mcimadamore@137: task.call(); mcimadamore@137: checkErrorLine(pw.toString(), mcimadamore@137: diagType.shouldDisplaySource(sourceLine), mcimadamore@137: options); mcimadamore@137: } mcimadamore@137: mcimadamore@137: void test() { mcimadamore@137: for (DiagnosticType dt : DiagnosticType.values()) { mcimadamore@137: for (SourceLine sl : SourceLine.values()) { mcimadamore@137: exec(dt, sl); mcimadamore@137: } mcimadamore@137: } mcimadamore@137: } mcimadamore@137: mcimadamore@137: public static void main(String... args) throws Exception { mcimadamore@137: new T6731573().test(); mcimadamore@137: } jjg@525: }