53 throw new Exception(errors + " errors occurred."); 54 } 55 56 void javadoc(String pkg, List<String> testOpts, 57 int expectErrs, int expectWarns) { 58 System.err.println("Test " + (++count) + ": " + pkg + " " + testOpts); 59 File testOutDir = new File("test" + count); 60 61 List<String> opts = new ArrayList<String>(); 62 // Force en_US locale in lieu of something like -XDrawDiagnostics. 63 // For some reason, this must be the first option when used. 64 opts.addAll(list("-locale", "en_US")); 65 opts.add("-Xdoclint:none"); 66 opts.addAll(list("-classpath", System.getProperty("test.src"))); 67 opts.addAll(list("-d", testOutDir.getPath())); 68 opts.addAll(testOpts); 69 opts.add(pkg); 70 71 StringWriter errSW = new StringWriter(); 72 PrintWriter errPW = new PrintWriter(errSW); 73 StringWriter warnSW = new StringWriter(); 74 PrintWriter warnPW = new PrintWriter(warnSW); 75 StringWriter noteSW = new StringWriter(); 76 PrintWriter notePW = new PrintWriter(noteSW); 77 78 int rc = com.sun.tools.javadoc.Main.execute("javadoc", 79 errPW, warnPW, notePW, 80 "com.sun.tools.doclets.standard.Standard", 81 getClass().getClassLoader(), 82 opts.toArray(new String[opts.size()])); 83 System.err.println("rc: " + rc); 84 85 errPW.close(); 86 String errOut = errSW.toString(); 87 System.err.println("Errors:\n" + errOut); 88 warnPW.close(); 89 String warnOut = warnSW.toString(); 90 System.err.println("Warnings:\n" + warnOut); 91 notePW.close(); 92 String noteOut = noteSW.toString(); 93 System.err.println("Notes:\n" + noteOut); 94 95 check(errOut, "Errors.java", expectErrs); 96 check(warnOut, " warning ", expectWarns); // requires -locale en_US 97 } 98 99 void check(String text, String expectText, int expectCount) { 100 int foundCount = 0; 101 for (String line: text.split("[\r\n]+")) { 102 if (line.contains(expectText)) 103 foundCount++; 104 } 105 if (foundCount != expectCount) { 106 error("incorrect number of matches found: " + foundCount 107 + ", expected: " + expectCount); 108 } 109 } 110 111 private List<String> list(String... args) { 112 return Arrays.asList(args); 113 } 114 115 void error(String msg) { 116 System.err.println(msg); | 53 throw new Exception(errors + " errors occurred."); 54 } 55 56 void javadoc(String pkg, List<String> testOpts, 57 int expectErrs, int expectWarns) { 58 System.err.println("Test " + (++count) + ": " + pkg + " " + testOpts); 59 File testOutDir = new File("test" + count); 60 61 List<String> opts = new ArrayList<String>(); 62 // Force en_US locale in lieu of something like -XDrawDiagnostics. 63 // For some reason, this must be the first option when used. 64 opts.addAll(list("-locale", "en_US")); 65 opts.add("-Xdoclint:none"); 66 opts.addAll(list("-classpath", System.getProperty("test.src"))); 67 opts.addAll(list("-d", testOutDir.getPath())); 68 opts.addAll(testOpts); 69 opts.add(pkg); 70 71 StringWriter errSW = new StringWriter(); 72 PrintWriter errPW = new PrintWriter(errSW); 73 int rc = jdk.javadoc.internal.tool.Main.execute( 74 opts.toArray(new String[opts.size()]), 75 errPW); 76 System.err.println("rc: " + rc); 77 78 errPW.close(); 79 String errOut = errSW.toString(); 80 System.err.println("Errors:\n" + errOut); 81 82 check(errOut, "Errors.java", expectErrs); 83 check(errOut, " warning ", expectWarns); // requires -locale en_US 84 } 85 86 void check(String text, String expectText, int expectCount) { 87 int foundCount = 0; 88 for (String line: text.split("[\r\n]+")) { 89 if (line.contains(expectText)) 90 foundCount++; 91 } 92 if (foundCount != expectCount) { 93 error("incorrect number of matches found: " + foundCount 94 + ", expected: " + expectCount); 95 } 96 } 97 98 private List<String> list(String... args) { 99 return Arrays.asList(args); 100 } 101 102 void error(String msg) { 103 System.err.println(msg); |