Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javadoc/api/basic/RunTest.java
38828 views
/*1* Copyright (c) 2012, 2013, 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* @build APITest28* @run main RunTest29*/3031import java.io.ByteArrayOutputStream;32import java.io.File;33import java.io.PrintStream;34import javax.tools.DocumentationTool;35import javax.tools.ToolProvider;3637/**38* Tests for DocumentationTool.run method.39*/40public class RunTest extends APITest {41public static void main(String... args) throws Exception {42new RunTest().run();43}4445/**46* Verify that run method can be invoked.47*/48@Test49public void testRunOK() throws Exception {50File testSrc = new File(System.getProperty("test.src"));51File srcFile = new File(testSrc, "pkg/C.java");52File outDir = getOutDir();53String[] args = { "-d", outDir.getPath(), srcFile.getPath() };5455ByteArrayOutputStream stdout = new ByteArrayOutputStream();56ByteArrayOutputStream stderr = new ByteArrayOutputStream();57DocumentationTool tool = ToolProvider.getSystemDocumentationTool();58int rc = tool.run(null, stdout, stderr, args);59System.err.println("stdout >>" + stdout.toString() + "<<");60System.err.println("stderr >>" + stderr.toString() + "<<");6162if (rc == 0) {63System.err.println("call succeeded");64checkFiles(outDir, standardExpectFiles);65String out = stdout.toString();66for (String f: standardExpectFiles) {67String f1 = f.replace('/', File.separatorChar);68if (f1.endsWith(".html") && !out.contains(f1))69error("expected string not found: " + f1);70}71} else {72error("call failed");73}74}7576/**77* Verify that run method can be invoked.78*/79@Test80public void testRunFail() throws Exception {81File outDir = getOutDir();82String badfile = "badfile.java";83String[] args = { "-d", outDir.getPath(), badfile };8485ByteArrayOutputStream stdout = new ByteArrayOutputStream();86ByteArrayOutputStream stderr = new ByteArrayOutputStream();87DocumentationTool tool = ToolProvider.getSystemDocumentationTool();88int rc = tool.run(null, stdout, stderr, args);89System.err.println("stdout >>" + stdout.toString() + "<<");90System.err.println("stderr >>" + stderr.toString() + "<<");9192if (rc == 0) {93error("call succeeded unexpectedly");94} else {95String err = stderr.toString();96if (err.contains(badfile))97System.err.println("call failed as expected");98else99error("expected diagnostic not found");100}101}102103/**104* Verify that null args are accepted.105*/106@Test107public void testNullArgs() throws Exception {108File testSrc = new File(System.getProperty("test.src"));109File srcFile = new File(testSrc, "pkg/C.java");110File outDir = getOutDir();111String[] args = { "-d", outDir.getPath(), srcFile.getPath() };112113ByteArrayOutputStream stdout = new ByteArrayOutputStream();114PrintStream prevStdout = System.out;115System.setOut(new PrintStream(stdout));116117ByteArrayOutputStream stderr = new ByteArrayOutputStream();118PrintStream prevStderr = System.err;119System.setErr(new PrintStream(stderr));120121int rc ;122try {123DocumentationTool tool = ToolProvider.getSystemDocumentationTool();124rc = tool.run(null, null, null, args);125} finally {126System.setOut(prevStdout);127System.setErr(prevStderr);128}129130System.err.println("stdout >>" + stdout.toString() + "<<");131System.err.println("stderr >>" + stderr.toString() + "<<");132133if (rc == 0) {134System.err.println("call succeeded");135checkFiles(outDir, standardExpectFiles);136String out = stdout.toString();137for (String f: standardExpectFiles) {138String f1 = f.replace('/', File.separatorChar);139if (f1.endsWith(".html") && !out.contains(f1))140error("expected string not found: " + f1);141}142} else {143error("call failed");144}145}146}147148149150