1/* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 8175219 27 * @summary test --ignore-errors works correctly 28 * @modules 29 * jdk.javadoc/jdk.javadoc.internal.api 30 * jdk.javadoc/jdk.javadoc.internal.tool 31 * jdk.compiler/com.sun.tools.javac.api 32 * jdk.compiler/com.sun.tools.javac.main 33 * @library /tools/lib 34 * @build toolbox.ToolBox toolbox.TestRunner 35 * @run main IgnoreSourceErrors 36 */ 37 38import java.io.IOException; 39import java.nio.file.Files; 40import java.nio.file.Path; 41import java.nio.file.Paths; 42import java.nio.file.StandardOpenOption; 43import java.util.Arrays; 44 45import toolbox.*; 46import toolbox.Task.*; 47 48/** 49 * Dummy javadoc comment. 50 */ 51public class IgnoreSourceErrors extends TestRunner { 52 53 final ToolBox tb; 54 final Path testSrc; 55 56 public IgnoreSourceErrors() throws IOException { 57 super(System.err); 58 tb = new ToolBox(); 59 testSrc = Paths.get("Foo.java"); 60 emitSample(testSrc); 61 } 62 63 public static void main(String... args) throws Exception { 64 new IgnoreSourceErrors().runTests(); 65 } 66 67 @Test 68 public void runIgnoreErrorsOffByDefault() throws Exception { 69 JavadocTask task = new JavadocTask(tb, Task.Mode.CMDLINE); 70 task.options(testSrc.toString()); 71 Task.Result result = task.run(Expect.FAIL); 72 String out = result.getOutput(OutputKind.DIRECT); 73 if (!out.contains("modifier static not allowed here")) { 74 throw new Exception("expected string not found \'modifier static not allowed here\'"); 75 } 76 } 77 78 @Test 79 public void runIgnoreErrorsOn() throws Exception { 80 JavadocTask task = new JavadocTask(tb, Task.Mode.CMDLINE); 81 task.options("--ignore-source-errors", testSrc.toString()); 82 Task.Result result = task.run(Expect.SUCCESS); 83 String out = result.getOutput(OutputKind.DIRECT); 84 if (!out.contains("modifier static not allowed here")) { 85 throw new Exception("expected string not found \'modifier static not allowed here\'"); 86 } 87 } 88 89 void emitSample(Path file) throws IOException { 90 String[] contents = { 91 "/** A java file with errors */", 92 "public static class Foo {}" 93 }; 94 Files.write(file, Arrays.asList(contents), StandardOpenOption.CREATE); 95 } 96} 97