1+ /*
2+ * Copyright (c) 2021, 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 8268774
27+ * @summary Residual logging output written to STDOUT, not STDERR
28+ * @library /tools/lib ../../lib
29+ * @modules jdk.javadoc/jdk.javadoc.internal.tool
30+ * @build toolbox.ToolBox javadoc.tester.*
31+ * @run main TestToolStreams
32+ */
33+
34+ import java .io .IOException ;
35+ import java .nio .file .Path ;
36+
37+ import javadoc .tester .JavadocTester ;
38+ import toolbox .ToolBox ;
39+
40+ // See also TestReporterStreams for testing doclet/reporter use of streams
41+ public class TestToolStreams extends JavadocTester {
42+
43+ public static void main (String ... args ) throws Exception {
44+ TestToolStreams tester = new TestToolStreams ();
45+ tester .runTests (m -> new Object []{Path .of (m .getName ())});
46+ }
47+
48+ ToolBox tb = new ToolBox ();
49+
50+ TestToolStreams () throws IOException {
51+ tb .writeJavaFiles (Path .of ("src" ),
52+ """
53+ package p1;
54+ /** Comment 1. */
55+ public class C1 { }""" ,
56+ """
57+ package p2;
58+ /** Comment 2. */
59+ public class C2 { }""" );
60+ }
61+
62+ /**
63+ * Tests the entry point used by the DocumentationTool API and JavadocTester, in which
64+ * all output is written to a single specified writer.
65+ */
66+ @ Test
67+ public void testSingleStream (Path base ) {
68+ test (base , false , Output .OUT , Output .OUT );
69+ }
70+
71+ /**
72+ * Tests the entry point used by the launcher, in which output is written to
73+ * writers that wrap {@code System.out} and {@code System.err}.
74+ */
75+ @ Test
76+ public void testStandardStreams (Path base ) {
77+ test (base , true , Output .STDOUT , Output .STDERR );
78+ }
79+
80+ void test (Path base , boolean useStdStreams , Output stdOut , Output stdErr ) {
81+ setOutputDirectoryCheck (DirectoryCheck .NONE );
82+ setUseStandardStreams (useStdStreams );
83+
84+ javadoc ("--help" );
85+ checkExit (Exit .OK );
86+
87+ if (stdOut != stdErr ) {
88+ checkIsEmpty (stdErr );
89+ }
90+
91+ checkOutput (stdOut , true ,
92+ "Usage:" );
93+
94+ javadoc ("-d" , base .resolve ("out" ).toString (),
95+ "-sourcepath" , "src" ,
96+ "-verbose" , // Note: triggers lots of javac messages as well as the javadoc time-taken message
97+ "p1" ,
98+ Path .of ("src" ).resolve ("p2" ).resolve ("C2.java" ).toString ());
99+ checkExit (Exit .OK );
100+
101+ if (stdOut != stdErr ) {
102+ checkIsEmpty (stdOut );
103+ }
104+
105+ checkOutput (stdErr , true ,
106+ "Loading source file src/p2/C2.java..." .replace ("/" , FS ),
107+ "Loading source files for package p1..." ,
108+ "Constructing Javadoc information" ,
109+ "[done in " , " ms]"
110+ );
111+ }
112+
113+ void checkIsEmpty (Output out ) {
114+ checking ("no output to " + out );
115+ String s = getOutput (out );
116+ if (s .isEmpty ()) {
117+ passed ("no output written to " + out );
118+ } else {
119+ failed (out + " is not empty" );
120+ }
121+ }
122+ }
0 commit comments