Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javadoc/api/basic/RunTest.java
38828 views
1
/*
2
* Copyright (c) 2012, 2013, 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 6493690 8007490
27
* @summary javadoc should have a javax.tools.Tool service provider
28
* @build APITest
29
* @run main RunTest
30
*/
31
32
import java.io.ByteArrayOutputStream;
33
import java.io.File;
34
import java.io.PrintStream;
35
import javax.tools.DocumentationTool;
36
import javax.tools.ToolProvider;
37
38
/**
39
* Tests for DocumentationTool.run method.
40
*/
41
public class RunTest extends APITest {
42
public static void main(String... args) throws Exception {
43
new RunTest().run();
44
}
45
46
/**
47
* Verify that run method can be invoked.
48
*/
49
@Test
50
public void testRunOK() throws Exception {
51
File testSrc = new File(System.getProperty("test.src"));
52
File srcFile = new File(testSrc, "pkg/C.java");
53
File outDir = getOutDir();
54
String[] args = { "-d", outDir.getPath(), srcFile.getPath() };
55
56
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
57
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
58
DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
59
int rc = tool.run(null, stdout, stderr, args);
60
System.err.println("stdout >>" + stdout.toString() + "<<");
61
System.err.println("stderr >>" + stderr.toString() + "<<");
62
63
if (rc == 0) {
64
System.err.println("call succeeded");
65
checkFiles(outDir, standardExpectFiles);
66
String out = stdout.toString();
67
for (String f: standardExpectFiles) {
68
String f1 = f.replace('/', File.separatorChar);
69
if (f1.endsWith(".html") && !out.contains(f1))
70
error("expected string not found: " + f1);
71
}
72
} else {
73
error("call failed");
74
}
75
}
76
77
/**
78
* Verify that run method can be invoked.
79
*/
80
@Test
81
public void testRunFail() throws Exception {
82
File outDir = getOutDir();
83
String badfile = "badfile.java";
84
String[] args = { "-d", outDir.getPath(), badfile };
85
86
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
87
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
88
DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
89
int rc = tool.run(null, stdout, stderr, args);
90
System.err.println("stdout >>" + stdout.toString() + "<<");
91
System.err.println("stderr >>" + stderr.toString() + "<<");
92
93
if (rc == 0) {
94
error("call succeeded unexpectedly");
95
} else {
96
String err = stderr.toString();
97
if (err.contains(badfile))
98
System.err.println("call failed as expected");
99
else
100
error("expected diagnostic not found");
101
}
102
}
103
104
/**
105
* Verify that null args are accepted.
106
*/
107
@Test
108
public void testNullArgs() throws Exception {
109
File testSrc = new File(System.getProperty("test.src"));
110
File srcFile = new File(testSrc, "pkg/C.java");
111
File outDir = getOutDir();
112
String[] args = { "-d", outDir.getPath(), srcFile.getPath() };
113
114
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
115
PrintStream prevStdout = System.out;
116
System.setOut(new PrintStream(stdout));
117
118
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
119
PrintStream prevStderr = System.err;
120
System.setErr(new PrintStream(stderr));
121
122
int rc ;
123
try {
124
DocumentationTool tool = ToolProvider.getSystemDocumentationTool();
125
rc = tool.run(null, null, null, args);
126
} finally {
127
System.setOut(prevStdout);
128
System.setErr(prevStderr);
129
}
130
131
System.err.println("stdout >>" + stdout.toString() + "<<");
132
System.err.println("stderr >>" + stderr.toString() + "<<");
133
134
if (rc == 0) {
135
System.err.println("call succeeded");
136
checkFiles(outDir, standardExpectFiles);
137
String out = stdout.toString();
138
for (String f: standardExpectFiles) {
139
String f1 = f.replace('/', File.separatorChar);
140
if (f1.endsWith(".html") && !out.contains(f1))
141
error("expected string not found: " + f1);
142
}
143
} else {
144
error("call failed");
145
}
146
}
147
}
148
149
150