Path: blob/master/test/langtools/jdk/javadoc/tool/example/Tester.java
40974 views
/*1* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 816431626* @summary tests the example used in package-info.java and doclet options.27* @modules28* jdk.javadoc/jdk.javadoc.internal.api29* jdk.javadoc/jdk.javadoc.internal.tool30* jdk.compiler/com.sun.tools.javac.api31* jdk.compiler/com.sun.tools.javac.main32* @library /tools/lib33* @build toolbox.ToolBox toolbox.TestRunner Example34* @run main Tester35*/3637import java.io.File;38import java.util.Arrays;39import java.util.ArrayList;40import java.util.List;4142import toolbox.*;43import toolbox.Task.Expect;4445import static toolbox.Task.OutputKind.*;4647public class Tester extends TestRunner {48final ToolBox tb;49final File testFile;50final File testSrc;51final Class<?> docletClass;52final static String OV_FN = "overview.html";5354Tester() {55super(System.err);56testSrc = new File(System.getProperty("test.src"));57testFile = new File(testSrc, "Example.java");58tb = new ToolBox();59ClassLoader cl = Tester.class.getClassLoader();60try {61docletClass = cl.loadClass("Example");62} catch (ClassNotFoundException cfe) {63throw new Error(cfe);64}65}6667public static void main(String... args) throws Exception {68new Tester().runTests();69}7071private Task.Result execTask(String... extraArgs) {72return execTask(false, extraArgs);73}7475private Task.Result execTask(boolean isNegative, String... extraArgs) {76JavadocTask et = new JavadocTask(tb, Task.Mode.API);77et.docletClass(docletClass);78List<String> args = new ArrayList<>();79args.add("-sourcepath");80args.add(testSrc.getAbsolutePath());81args.add(testFile.getAbsolutePath());82args.addAll(Arrays.asList(extraArgs));83//args.forEach((a -> System.err.println("arg: " + a)));84System.err.println(Arrays.asList(extraArgs));85Task.Result result = isNegative86? et.options(args).run(Expect.FAIL)87: et.options(args).run();88return result;89}9091void assertPresence(String regex, List<String> output) throws Exception {92List<String> foundList = tb.grep(regex, output);93if (foundList.isEmpty()) {94throw new Exception("Not found, expected: " + regex);95}96}9798@Test99public void testOption() throws Exception {100Task.Result result = execTask("-overviewfile", OV_FN);101assertPresence("overviewfile: " + OV_FN, result.getOutputLines(DIRECT));102}103104@Test105public void testOptionAlias() throws Exception {106Task.Result result = execTask("-overview-file", OV_FN);107assertPresence("overviewfile: " + OV_FN, result.getOutputLines(DIRECT));108}109110@Test111public void testOptionAliasDoubleDash() throws Exception {112Task.Result result = execTask("--over-view-file", OV_FN);113assertPresence("overviewfile: " + OV_FN, result.getOutputLines(DIRECT));114}115}116117118