Test.java revision 3233:b5d08bc0d224
1234353Sdim/*
2193323Sed * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
3193323Sed * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4193323Sed *
5193323Sed * This code is free software; you can redistribute it and/or modify it
6193323Sed * under the terms of the GNU General Public License version 2 only, as
7193323Sed * published by the Free Software Foundation.
8193323Sed *
9193323Sed * This code is distributed in the hope that it will be useful, but WITHOUT
10224145Sdim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11193323Sed * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12193323Sed * version 2 for more details (a copy is included in the LICENSE file that
13193323Sed * accompanied this code).
14193323Sed *
15193323Sed * You should have received a copy of the GNU General Public License version
16193323Sed * 2 along with this work; if not, write to the Free Software Foundation,
17210299Sed * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18249423Sdim *
19224145Sdim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20193323Sed * or visit www.oracle.com if you need additional information or have any
21193323Sed * questions.
22224145Sdim */
23224145Sdim
24224145Sdim/*
25193323Sed * @test
26193323Sed * @bug 6964914
27224145Sdim * @summary javadoc does not output number of warnings using user written doclet
28193323Sed * @modules jdk.javadoc/com.sun.tools.doclets.standard
29204642Srdivacky */
30198090Srdivacky
31204642Srdivackyimport java.io.*;
32193323Sed
33193323Sedpublic class Test {
34198090Srdivacky    public static void main(String... args) throws Exception {
35198090Srdivacky        new Test().run();
36198090Srdivacky    }
37198090Srdivacky
38198090Srdivacky    public void run() throws Exception {
39193323Sed        javadoc("Error.java", "1 error");
40193323Sed        javadoc("JavacWarning.java", "1 warning");
41193323Sed        javadoc("JavadocWarning.java", "1 warning");
42224145Sdim        if (errors > 0)
43193323Sed            throw new Exception(errors + " errors found");
44193323Sed    }
45263508Sdim
46193323Sed    void javadoc(String path, String expect) {
47193323Sed        File testSrc = new File(System.getProperty("test.src"));
48193323Sed        String[] args = {
49193323Sed            "-Xdoclint:none",
50193323Sed            "-source", "8",
51193323Sed            "-bootclasspath", System.getProperty("sun.boot.class.path"),
52234353Sdim            "-classpath", ".",
53263508Sdim            "-package",
54234353Sdim            new File(testSrc, path).getPath()
55234353Sdim        };
56234353Sdim
57234353Sdim        StringWriter sw = new StringWriter();
58239462Sdim        PrintWriter pw = new PrintWriter(sw);
59193323Sed        int rc = jdk.javadoc.internal.tool.Main.execute(args, pw);
60193323Sed        pw.close();
61193323Sed        String out = sw.toString();
62204642Srdivacky        if (!out.isEmpty())
63193323Sed            System.err.println(out);
64193323Sed        System.err.println("javadoc exit: rc=" + rc);
65193323Sed
66193323Sed        if (!out.contains(expect))
67193323Sed            error("expected text not found: " + expect);
68193323Sed    }
69193323Sed
70193323Sed    void error(String msg) {
71198090Srdivacky        System.err.println("Error: " + msg);
72198090Srdivacky        errors++;
73198090Srdivacky    }
74204642Srdivacky
75193323Sed    int errors;
76193323Sed}
77193323Sed