test/tools/doclint/RunTest.java

Mon, 31 Aug 2015 13:37:01 -0700

author
asaha
date
Mon, 31 Aug 2015 13:37:01 -0700
changeset 2971
153d0309e698
parent 1774
37295244f534
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u65-b12 for changeset 54e958a3719e

jjg@1455 1 /*
vromero@1774 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
jjg@1455 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jjg@1455 4 *
jjg@1455 5 * This code is free software; you can redistribute it and/or modify it
jjg@1455 6 * under the terms of the GNU General Public License version 2 only, as
jjg@1455 7 * published by the Free Software Foundation.
jjg@1455 8 *
jjg@1455 9 * This code is distributed in the hope that it will be useful, but WITHOUT
jjg@1455 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jjg@1455 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
jjg@1455 12 * version 2 for more details (a copy is included in the LICENSE file that
jjg@1455 13 * accompanied this code).
jjg@1455 14 *
jjg@1455 15 * You should have received a copy of the GNU General Public License version
jjg@1455 16 * 2 along with this work; if not, write to the Free Software Foundation,
jjg@1455 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jjg@1455 18 *
jjg@1455 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jjg@1455 20 * or visit www.oracle.com if you need additional information or have any
jjg@1455 21 * questions.
jjg@1455 22 */
jjg@1455 23
jjg@1455 24 /* @test
vromero@1774 25 * @bug 8004832 8000103
jjg@1465 26 * @summary Add new doclint package
jjg@1455 27 * @summary Create doclint utility
jjg@1455 28 */
jjg@1455 29
jjg@1455 30 import java.io.File;
jjg@1455 31 import java.io.IOException;
jjg@1455 32 import java.io.PrintWriter;
jjg@1455 33 import java.io.StringWriter;
jjg@1455 34 import java.lang.annotation.Annotation;
jjg@1455 35 import java.lang.annotation.Retention;
jjg@1455 36 import java.lang.annotation.RetentionPolicy;
jjg@1455 37 import java.lang.reflect.InvocationTargetException;
jjg@1455 38 import java.lang.reflect.Method;
jjg@1455 39
vromero@1774 40 import com.sun.tools.doclint.DocLint;
vromero@1774 41 import com.sun.tools.doclint.DocLint.BadArgs;
vromero@1774 42
jjg@1455 43 /** javadoc error on toplevel: a & b. */
jjg@1455 44 public class RunTest {
jjg@1455 45 /** javadoc error on member: a < b */
jjg@1455 46 public static void main(String... args) throws Exception {
jjg@1455 47 new RunTest().run();
jjg@1455 48 }
jjg@1455 49
jjg@1455 50
jjg@1455 51 File testSrc = new File(System.getProperty("test.src"));
jjg@1455 52 File thisFile = new File(testSrc, RunTest.class.getSimpleName() + ".java");
jjg@1455 53
jjg@1455 54 void run() throws Exception {
jjg@1455 55 for (Method m: getClass().getDeclaredMethods()) {
jjg@1455 56 Annotation a = m.getAnnotation(Test.class);
jjg@1455 57 if (a != null) {
jjg@1455 58 System.err.println("test: " + m.getName());
jjg@1455 59 try {
jjg@1455 60 StringWriter sw = new StringWriter();
jjg@1455 61 PrintWriter pw = new PrintWriter(sw);;
jjg@1455 62 m.invoke(this, new Object[] { pw });
jjg@1455 63 String out = sw.toString();
jjg@1455 64 System.err.println(">>> " + out.replace("\n", "\n>>> "));
jjg@1455 65 if (!out.contains("a < b"))
jjg@1455 66 error("\"a < b\" not found");
jjg@1455 67 if (!out.contains("a & b"))
jjg@1455 68 error("\"a & b\" not found");
jjg@1455 69 } catch (InvocationTargetException e) {
jjg@1455 70 Throwable cause = e.getCause();
jjg@1455 71 throw (cause instanceof Exception) ? ((Exception) cause) : e;
jjg@1455 72 }
jjg@1455 73 System.err.println();
jjg@1455 74 }
jjg@1455 75 }
jjg@1455 76
jjg@1455 77 if (errors > 0)
jjg@1455 78 throw new Exception(errors + " errors occurred");
jjg@1455 79 }
jjg@1455 80
jjg@1455 81
jjg@1455 82 void error(String msg) {
jjg@1455 83 System.err.println("Error: " + msg);
jjg@1455 84 errors++;
jjg@1455 85 }
jjg@1455 86
jjg@1455 87 int errors;
jjg@1455 88
jjg@1455 89 /** Marker annotation for test cases. */
jjg@1455 90 @Retention(RetentionPolicy.RUNTIME)
jjg@1455 91 @interface Test { }
jjg@1455 92
jjg@1455 93 @Test
jjg@1455 94 void testMain(PrintWriter pw) throws BadArgs, IOException {
jjg@1455 95 String[] args = { "-Xmsgs", thisFile.getPath() };
jjg@1455 96 DocLint d = new DocLint();
jjg@1455 97 d.run(pw, args);
jjg@1455 98 }
jjg@1455 99 }
jjg@1455 100
jjg@1455 101

mercurial