Path: blob/master/test/langtools/jdk/javadoc/tool/api/basic/RunTest.java
40983 views
/*1* Copyright (c) 2012, 2015, 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 6493690 800749026* @summary javadoc should have a javax.tools.Tool service provider27* @modules java.compiler28* jdk.compiler29* @build APITest30* @run main RunTest31*/3233import java.io.ByteArrayOutputStream;34import java.io.File;35import java.io.PrintStream;36import javax.tools.DocumentationTool;37import javax.tools.ToolProvider;3839/**40* Tests for DocumentationTool.run method.41*/42public class RunTest extends APITest {43public static void main(String... args) throws Exception {44new RunTest().run();45}4647/**48* Verify that run method can be invoked.49*/50// @Test51public void testRunOK() throws Exception {52File testSrc = new File(System.getProperty("test.src"));53File srcFile = new File(testSrc, "pkg/C.java");54File outDir = getOutDir();55String[] args = { "-d", outDir.getPath(), srcFile.getPath() };5657ByteArrayOutputStream stdout = new ByteArrayOutputStream();58ByteArrayOutputStream stderr = new ByteArrayOutputStream();59DocumentationTool tool = ToolProvider.getSystemDocumentationTool();60int rc = tool.run(null, stdout, stderr, args);61System.err.println("stdout >>" + stdout.toString() + "<<");62System.err.println("stderr >>" + stderr.toString() + "<<");6364if (rc == 0) {65System.err.println("call succeeded");66checkFiles(outDir, standardExpectFiles);67String out = stdout.toString();68for (String f: standardExpectFiles) {69String f1 = f.replace('/', File.separatorChar);70if (f1.endsWith(".html") && !out.contains(f1))71error("expected string not found: " + f1);72}73} else {74error("call failed");75}76}7778/**79* Verify that run method can be invoked.80*/81@Test82public void testRunFail() throws Exception {83File outDir = getOutDir();84String badfile = "badfile.java";85String[] args = { "-d", outDir.getPath(), badfile };8687ByteArrayOutputStream stdout = new ByteArrayOutputStream();88ByteArrayOutputStream stderr = new ByteArrayOutputStream();89DocumentationTool tool = ToolProvider.getSystemDocumentationTool();90int rc = tool.run(null, stdout, stderr, args);91System.err.println("stdout >>" + stdout.toString() + "<<");92System.err.println("stderr >>" + stderr.toString() + "<<");9394if (rc == 0) {95error("call succeeded unexpectedly");96} else {97String err = stderr.toString();98if (err.contains(badfile))99System.err.println("call failed as expected");100else101error("expected diagnostic not found");102}103}104105/**106* Verify that null args are accepted.107*/108// @Test109public void testNullArgs() throws Exception {110File testSrc = new File(System.getProperty("test.src"));111File srcFile = new File(testSrc, "pkg/C.java");112File outDir = getOutDir();113String[] args = { "-d", outDir.getPath(), srcFile.getPath() };114115ByteArrayOutputStream stdout = new ByteArrayOutputStream();116PrintStream prevStdout = System.out;117System.setOut(new PrintStream(stdout));118119ByteArrayOutputStream stderr = new ByteArrayOutputStream();120PrintStream prevStderr = System.err;121System.setErr(new PrintStream(stderr));122123int rc ;124try {125DocumentationTool tool = ToolProvider.getSystemDocumentationTool();126rc = tool.run(null, null, null, args);127} finally {128System.setOut(prevStdout);129System.setErr(prevStderr);130}131132System.err.println("stdout >>" + stdout.toString() + "<<");133System.err.println("stderr >>" + stderr.toString() + "<<");134135if (rc == 0) {136System.err.println("call succeeded");137checkFiles(outDir, standardExpectFiles);138String out = stdout.toString();139for (String f: standardExpectFiles) {140String f1 = f.replace('/', File.separatorChar);141if (f1.endsWith(".html") && !out.contains(f1))142error("expected string not found: " + f1);143}144} else {145error("call failed");146}147}148}149150151152