test/tools/javadoc/api/basic/RunTest.java

Tue, 06 Jun 2017 10:03:06 -0700

author
asaha
date
Tue, 06 Jun 2017 10:03:06 -0700
changeset 3395
ec280466843d
parent 1543
1690928dc560
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u141-b12 for changeset b5259d2465fa

jjg@1413 1 /*
jjg@1543 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
jjg@1413 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@1413 4 *
jjg@1413 5 * This code is free software; you can redistribute it and/or modify it
jjg@1413 6 * under the terms of the GNU General Public License version 2 only, as
jjg@1413 7 * published by the Free Software Foundation.
jjg@1413 8 *
jjg@1413 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@1413 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@1413 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@1413 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@1413 13 * accompanied this code).
jjg@1413 14 *
jjg@1413 15 * You should have received a copy of the GNU General Public License version
jjg@1413 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@1413 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@1413 18 *
jjg@1413 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jjg@1413 20 * or visit www.oracle.com if you need additional information or have any
jjg@1413 21 * questions.
jjg@1413 22 */
jjg@1413 23
jjg@1413 24 /*
jjg@1413 25 * @test
jjg@1543 26 * @bug 6493690 8007490
jjg@1413 27 * @summary javadoc should have a javax.tools.Tool service provider
jjg@1413 28 * @build APITest
jjg@1413 29 * @run main RunTest
jjg@1413 30 */
jjg@1413 31
jjg@1413 32 import java.io.ByteArrayOutputStream;
jjg@1413 33 import java.io.File;
jjg@1543 34 import java.io.PrintStream;
jjg@1413 35 import javax.tools.DocumentationTool;
jjg@1413 36 import javax.tools.ToolProvider;
jjg@1413 37
jjg@1413 38 /**
jjg@1413 39 * Tests for DocumentationTool.run method.
jjg@1413 40 */
jjg@1413 41 public class RunTest extends APITest {
jjg@1413 42 public static void main(String... args) throws Exception {
jjg@1413 43 new RunTest().run();
jjg@1413 44 }
jjg@1413 45
jjg@1413 46 /**
jjg@1413 47 * Verify that run method can be invoked.
jjg@1413 48 */
jjg@1413 49 @Test
jjg@1543 50 public void testRunOK() throws Exception {
jjg@1413 51 File testSrc = new File(System.getProperty("test.src"));
jjg@1413 52 File srcFile = new File(testSrc, "pkg/C.java");
jjg@1413 53 File outDir = getOutDir();
jjg@1413 54 String[] args = { "-d", outDir.getPath(), srcFile.getPath() };
jjg@1413 55
jjg@1413 56 ByteArrayOutputStream stdout = new ByteArrayOutputStream();
jjg@1413 57 ByteArrayOutputStream stderr = new ByteArrayOutputStream();
jjg@1413 58 DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
jjg@1413 59 int rc = tool.run(null, stdout, stderr, args);
jjg@1413 60 System.err.println("stdout >>" + stdout.toString() + "<<");
jjg@1413 61 System.err.println("stderr >>" + stderr.toString() + "<<");
jjg@1413 62
jjg@1413 63 if (rc == 0) {
jjg@1413 64 System.err.println("call succeeded");
jjg@1413 65 checkFiles(outDir, standardExpectFiles);
jjg@1413 66 String out = stdout.toString();
jjg@1413 67 for (String f: standardExpectFiles) {
jjg@1420 68 String f1 = f.replace('/', File.separatorChar);
jjg@1420 69 if (f1.endsWith(".html") && !out.contains(f1))
jjg@1420 70 error("expected string not found: " + f1);
jjg@1413 71 }
jjg@1413 72 } else {
jjg@1413 73 error("call failed");
jjg@1413 74 }
jjg@1413 75 }
jjg@1413 76
jjg@1413 77 /**
jjg@1413 78 * Verify that run method can be invoked.
jjg@1413 79 */
jjg@1413 80 @Test
jjg@1543 81 public void testRunFail() throws Exception {
jjg@1413 82 File outDir = getOutDir();
jjg@1413 83 String badfile = "badfile.java";
jjg@1413 84 String[] args = { "-d", outDir.getPath(), badfile };
jjg@1413 85
jjg@1413 86 ByteArrayOutputStream stdout = new ByteArrayOutputStream();
jjg@1413 87 ByteArrayOutputStream stderr = new ByteArrayOutputStream();
jjg@1413 88 DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
jjg@1413 89 int rc = tool.run(null, stdout, stderr, args);
jjg@1413 90 System.err.println("stdout >>" + stdout.toString() + "<<");
jjg@1413 91 System.err.println("stderr >>" + stderr.toString() + "<<");
jjg@1413 92
jjg@1413 93 if (rc == 0) {
jjg@1413 94 error("call succeeded unexpectedly");
jjg@1413 95 } else {
jjg@1413 96 String err = stderr.toString();
jjg@1413 97 if (err.contains(badfile))
jjg@1413 98 System.err.println("call failed as expected");
jjg@1413 99 else
jjg@1413 100 error("expected diagnostic not found");
jjg@1413 101 }
jjg@1413 102 }
jjg@1413 103
jjg@1543 104 /**
jjg@1543 105 * Verify that null args are accepted.
jjg@1543 106 */
jjg@1543 107 @Test
jjg@1543 108 public void testNullArgs() throws Exception {
jjg@1543 109 File testSrc = new File(System.getProperty("test.src"));
jjg@1543 110 File srcFile = new File(testSrc, "pkg/C.java");
jjg@1543 111 File outDir = getOutDir();
jjg@1543 112 String[] args = { "-d", outDir.getPath(), srcFile.getPath() };
jjg@1543 113
jjg@1543 114 ByteArrayOutputStream stdout = new ByteArrayOutputStream();
jjg@1543 115 PrintStream prevStdout = System.out;
jjg@1543 116 System.setOut(new PrintStream(stdout));
jjg@1543 117
jjg@1543 118 ByteArrayOutputStream stderr = new ByteArrayOutputStream();
jjg@1543 119 PrintStream prevStderr = System.err;
jjg@1543 120 System.setErr(new PrintStream(stderr));
jjg@1543 121
jjg@1543 122 int rc ;
jjg@1543 123 try {
jjg@1543 124 DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
jjg@1543 125 rc = tool.run(null, null, null, args);
jjg@1543 126 } finally {
jjg@1543 127 System.setOut(prevStdout);
jjg@1543 128 System.setErr(prevStderr);
jjg@1543 129 }
jjg@1543 130
jjg@1543 131 System.err.println("stdout >>" + stdout.toString() + "<<");
jjg@1543 132 System.err.println("stderr >>" + stderr.toString() + "<<");
jjg@1543 133
jjg@1543 134 if (rc == 0) {
jjg@1543 135 System.err.println("call succeeded");
jjg@1543 136 checkFiles(outDir, standardExpectFiles);
jjg@1543 137 String out = stdout.toString();
jjg@1543 138 for (String f: standardExpectFiles) {
jjg@1543 139 String f1 = f.replace('/', File.separatorChar);
jjg@1543 140 if (f1.endsWith(".html") && !out.contains(f1))
jjg@1543 141 error("expected string not found: " + f1);
jjg@1543 142 }
jjg@1543 143 } else {
jjg@1543 144 error("call failed");
jjg@1543 145 }
jjg@1543 146 }
jjg@1413 147 }
jjg@1413 148

mercurial