test/tools/doclint/RunTest.java

Mon, 21 Jan 2013 20:13:56 +0000

author
mcimadamore
date
Mon, 21 Jan 2013 20:13:56 +0000
changeset 1510
7873d37f5b37
parent 1465
a22f23fb7abf
child 1774
37295244f534
permissions
-rw-r--r--

8005244: Implement overload resolution as per latest spec EDR
Summary: Add support for stuck expressions and provisional applicability
Reviewed-by: jjg

jjg@1455 1 /*
jjg@1455 2 * Copyright (c) 2012, 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
jjg@1465 25 * @bug 8004832
jjg@1465 26 * @summary Add new doclint package
jjg@1455 27 * @bug 8000103
jjg@1455 28 * @summary Create doclint utility
jjg@1455 29 */
jjg@1455 30
jjg@1455 31 import com.sun.tools.doclint.DocLint;
jjg@1455 32 import com.sun.tools.doclint.DocLint.BadArgs;
jjg@1455 33 import java.io.ByteArrayOutputStream;
jjg@1455 34 import java.io.File;
jjg@1455 35 import java.io.FilterOutputStream;
jjg@1455 36 import java.io.IOException;
jjg@1455 37 import java.io.OutputStream;
jjg@1455 38 import java.io.PrintStream;
jjg@1455 39 import java.io.PrintWriter;
jjg@1455 40 import java.io.StringWriter;
jjg@1455 41 import java.lang.annotation.Annotation;
jjg@1455 42 import java.lang.annotation.Retention;
jjg@1455 43 import java.lang.annotation.RetentionPolicy;
jjg@1455 44 import java.lang.reflect.InvocationTargetException;
jjg@1455 45 import java.lang.reflect.Method;
jjg@1455 46
jjg@1455 47 /** javadoc error on toplevel: a & b. */
jjg@1455 48 public class RunTest {
jjg@1455 49 /** javadoc error on member: a < b */
jjg@1455 50 public static void main(String... args) throws Exception {
jjg@1455 51 new RunTest().run();
jjg@1455 52 }
jjg@1455 53
jjg@1455 54
jjg@1455 55 File testSrc = new File(System.getProperty("test.src"));
jjg@1455 56 File thisFile = new File(testSrc, RunTest.class.getSimpleName() + ".java");
jjg@1455 57
jjg@1455 58 void run() throws Exception {
jjg@1455 59 for (Method m: getClass().getDeclaredMethods()) {
jjg@1455 60 Annotation a = m.getAnnotation(Test.class);
jjg@1455 61 if (a != null) {
jjg@1455 62 System.err.println("test: " + m.getName());
jjg@1455 63 try {
jjg@1455 64 StringWriter sw = new StringWriter();
jjg@1455 65 PrintWriter pw = new PrintWriter(sw);;
jjg@1455 66 m.invoke(this, new Object[] { pw });
jjg@1455 67 String out = sw.toString();
jjg@1455 68 System.err.println(">>> " + out.replace("\n", "\n>>> "));
jjg@1455 69 if (!out.contains("a < b"))
jjg@1455 70 error("\"a < b\" not found");
jjg@1455 71 if (!out.contains("a & b"))
jjg@1455 72 error("\"a & b\" not found");
jjg@1455 73 } catch (InvocationTargetException e) {
jjg@1455 74 Throwable cause = e.getCause();
jjg@1455 75 throw (cause instanceof Exception) ? ((Exception) cause) : e;
jjg@1455 76 }
jjg@1455 77 System.err.println();
jjg@1455 78 }
jjg@1455 79 }
jjg@1455 80
jjg@1455 81 if (errors > 0)
jjg@1455 82 throw new Exception(errors + " errors occurred");
jjg@1455 83 }
jjg@1455 84
jjg@1455 85
jjg@1455 86 void error(String msg) {
jjg@1455 87 System.err.println("Error: " + msg);
jjg@1455 88 errors++;
jjg@1455 89 }
jjg@1455 90
jjg@1455 91 int errors;
jjg@1455 92
jjg@1455 93 /** Marker annotation for test cases. */
jjg@1455 94 @Retention(RetentionPolicy.RUNTIME)
jjg@1455 95 @interface Test { }
jjg@1455 96
jjg@1455 97 @Test
jjg@1455 98 void testMain(PrintWriter pw) throws BadArgs, IOException {
jjg@1455 99 String[] args = { "-Xmsgs", thisFile.getPath() };
jjg@1455 100 DocLint d = new DocLint();
jjg@1455 101 d.run(pw, args);
jjg@1455 102 }
jjg@1455 103 }
jjg@1455 104
jjg@1455 105

mercurial