Skip to content

Commit 3660a90

Browse files
8319139: Improve diagnosability of JavadocTester output
Reviewed-by: hannesw
1 parent 7f47c51 commit 3660a90

File tree

3 files changed

+78
-55
lines changed

3 files changed

+78
-55
lines changed

test/langtools/jdk/javadoc/lib/javadoc/tester/JavadocTester.java

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -827,9 +827,9 @@ public void checkFiles(boolean expectedFound, Collection<String> paths) {
827827
Path file = outputDir.resolve(path);
828828
boolean isFound = Files.exists(file);
829829
if (isFound == expectedFound) {
830-
passed(file, "file " + (isFound ? "found:" : "not found:") + "\n");
830+
passed(file, "file " + (isFound ? "found:" : "not found:"));
831831
} else {
832-
failed(file, "file " + (isFound ? "found:" : "not found:") + "\n");
832+
failed(file, "file " + (isFound ? "found:" : "not found:"));
833833
}
834834
}
835835
}
@@ -946,9 +946,10 @@ protected void checking(String message) {
946946
*
947947
* @param file the file that was the focus of the check
948948
* @param message a short description of the outcome
949+
* @param details optional additional details
949950
*/
950-
protected void passed(Path file, String message) {
951-
passed(file + ": " + message);
951+
protected void passed(Path file, String message, String... details) {
952+
passed(file + ": " + message, details);
952953
}
953954

954955
/**
@@ -957,10 +958,14 @@ protected void passed(Path file, String message) {
957958
* <p>This method should be called after previously calling {@code checking(...)}.
958959
*
959960
* @param message a short description of the outcome
961+
* @param details optional additional details
960962
*/
961-
protected void passed(String message) {
963+
protected void passed(String message, String... details) {
962964
numTestsPassed++;
963965
print("Passed", message);
966+
for (var detail: details) {
967+
detail.lines().forEachOrdered(out::println);
968+
}
964969
out.println();
965970
}
966971

@@ -971,9 +976,10 @@ protected void passed(String message) {
971976
*
972977
* @param file the file that was the focus of the check
973978
* @param message a short description of the outcome
979+
* @param details optional additional details
974980
*/
975-
protected void failed(Path file, String message) {
976-
failed(file + ": " + message);
981+
protected void failed(Path file, String message, String... details) {
982+
failed(file + ": " + message, details);
977983
}
978984

979985
/**
@@ -982,8 +988,9 @@ protected void failed(Path file, String message) {
982988
* <p>This method should be called after previously calling {@code checking(...)}.
983989
*
984990
* @param message a short description of the outcome
991+
* @param details optional additional details
985992
*/
986-
protected void failed(String message) {
993+
protected void failed(String message, String... details) {
987994
print("FAILED", message);
988995
StackWalker.getInstance().walk(s -> {
989996
s.dropWhile(f -> f.getMethodName().equals("failed"))
@@ -993,6 +1000,9 @@ protected void failed(String message) {
9931000
+ "(" + f.getFileName() + ":" + f.getLineNumber() + ")"));
9941001
return null;
9951002
});
1003+
for (var detail: details) {
1004+
detail.lines().forEachOrdered(out::println);
1005+
}
9961006
out.println();
9971007
}
9981008

@@ -1002,10 +1012,7 @@ private void print(String prefix, String message) {
10021012
else {
10031013
out.print(prefix);
10041014
out.print(": ");
1005-
out.print(message.replace("\n", NL));
1006-
if (!(message.endsWith("\n") || message.endsWith(NL))) {
1007-
out.println();
1008-
}
1015+
message.lines().forEachOrdered(out::println);
10091016
}
10101017
}
10111018

@@ -1219,25 +1226,28 @@ private void check(Function<Integer, Range> finder, SearchKind kind, String s) {
12191226
boolean isFound = r != null;
12201227
if (isFound == expectFound) {
12211228
matches.add(lastMatch = r);
1222-
passed(name + ": following " + kind + " " + (isFound ? "found:" : "not found:") + "\n"
1223-
+ s);
1229+
passed(name + ": the following " + kind + " was " + (isFound ? "found:" : "not found:"),
1230+
s);
12241231
} else {
12251232
// item not found in order, so check if the item is found out of order, to determine the best message
12261233
if (expectFound && expectOrdered && start > 0) {
12271234
Range r2 = finder.apply(0);
12281235
if (r2 != null) {
1229-
failed(name + ": following " + kind + " was found on line "
1236+
failed(name + ": output not as expected",
1237+
">> the following " + kind + " was found on line "
12301238
+ getLineNumber(r2.start)
12311239
+ ", but not in order as expected, on or after line "
1232-
+ getLineNumber(start)
1233-
+ ":\n"
1234-
+ s);
1240+
+ getLineNumber(start),
1241+
">> " + kind + ":",
1242+
s);
12351243
return;
12361244
}
12371245
}
1238-
failed(name + ": following " + kind + " "
1239-
+ (isFound ? "found:" : "not found:") + "\n"
1240-
+ s + '\n' + "found \n" + content);
1246+
failed(name + ": output not as expected",
1247+
">> the following " + kind + " was " + (isFound ? "found:" : "not found:"),
1248+
s,
1249+
">> found",
1250+
content);
12411251
}
12421252

12431253
}
@@ -1374,8 +1384,9 @@ public OutputChecker checkComplete() {
13741384
if (uncovered.isEmpty()) {
13751385
passed("All output matched");
13761386
} else {
1377-
failed("The following output was not matched: "
1378-
+ uncovered.stream()
1387+
failed("Output not as expected",
1388+
">> The following output was not matched",
1389+
uncovered.stream()
13791390
.map(Range::toIntervalString)
13801391
.collect(Collectors.joining(", ")));
13811392
}
@@ -1395,8 +1406,9 @@ public OutputChecker checkEmpty() {
13951406
if (content == null || content.isEmpty()) {
13961407
passed(name + " is empty, as expected");
13971408
} else {
1398-
failed(name + " is not empty; contains:\n"
1399-
+ content);
1409+
failed(name + " is not empty",
1410+
">> found:",
1411+
content);
14001412
}
14011413
return this;
14021414
}
@@ -1444,7 +1456,8 @@ private <T> OutputChecker checkAnyOf(SearchKind kind, List<T> items, BiFunction<
14441456
if (count == 0) {
14451457
failed("no match found for any " + kind);
14461458
} else {
1447-
passed(count + " matches found; earliest is " + earliest.toIntervalString());
1459+
passed(count + " matches found",
1460+
">> the earliest is: " + earliest.toIntervalString());
14481461
}
14491462
return this;
14501463
}

test/langtools/jdk/javadoc/testJavadocTester/TestJavadocTester.java

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ public static void main(String... args) throws Exception {
7373
* @param message a short description of the outcome
7474
*/
7575
@Override
76-
public void passed(String message) {
77-
super.passed(message);
78-
messages.add("Passed: " + message);
76+
public void passed(String message, String... details) {
77+
super.passed(message, details);
78+
messages.add("Passed: " + join(message, details));
7979
}
8080

8181
/**
@@ -85,9 +85,13 @@ public void passed(String message) {
8585
* @param message a short description of the outcome
8686
*/
8787
@Override
88-
public void failed(String message) {
89-
super.failed(message);
90-
messages.add("FAILED: " + message);
88+
public void failed(String message, String... details) {
89+
super.failed(message, details);
90+
messages.add("FAILED: " + join(message, details));
91+
}
92+
93+
private String join(String message, String... details) {
94+
return details.length == 0 ? message : message + "\n" + String.join("\n", details);
9195
}
9296

9397
/**
@@ -138,6 +142,8 @@ void checkMessages(String... expect) {
138142
testErrors++;
139143
}
140144
}
145+
146+
messages.forEach(m -> out.println("MESSAGES: " + m));
141147
}
142148

143149
/**
@@ -153,7 +159,7 @@ void checkMessages(String... expect) {
153159
* @param message the message to be reported.
154160
*/
155161
private void report(String message) {
156-
message.lines().forEachOrdered(l -> out.println(">>> " + l));
162+
message.lines().forEachOrdered(l -> out.println(">>>> " + l));
157163
}
158164

159165
//-------------------------------------------------
@@ -202,13 +208,13 @@ public void testSimpleStringCheck() {
202208
messages.forEach(this::report);
203209
checkMessages(
204210
"""
205-
Passed: out/p/C.html: following text found:
211+
Passed: out/p/C.html: the following text was found:
206212
Second sentence""",
207213
"""
208-
Passed: out/p/C.html: following text found:
214+
Passed: out/p/C.html: the following text was found:
209215
abc123""",
210216
"""
211-
Passed: out/p/C.html: following text found:
217+
Passed: out/p/C.html: the following text was found:
212218
def456""");
213219
}
214220

@@ -220,7 +226,7 @@ public void testSimpleNegativeStringCheck_expected() {
220226
.check("Third sentence.");
221227
checkMessages(
222228
"""
223-
Passed: out/p/C.html: following text not found:
229+
Passed: out/p/C.html: the following text was not found:
224230
Third sentence""");
225231
}
226232

@@ -231,7 +237,8 @@ public void testSimpleNegativeStringCheck_unexpected() {
231237
.check("Third sentence.");
232238
checkMessages(
233239
"""
234-
FAILED: out/p/C.html: following text not found:
240+
FAILED: out/p/C.html: output not as expected
241+
>> the following text was not found:
235242
Third sentence""");
236243
}
237244

@@ -244,13 +251,13 @@ public void testSimpleRegexCheck() {
244251
Pattern.compile("d.f4.6"));
245252
checkMessages(
246253
"""
247-
Passed: out/p/C.html: following pattern found:
254+
Passed: out/p/C.html: the following pattern was found:
248255
S.cond s.nt.nc.""",
249256
"""
250-
Passed: out/p/C.html: following pattern found:
257+
Passed: out/p/C.html: the following pattern was found:
251258
[abc]{3}[123]{3}""",
252259
"""
253-
Passed: out/p/C.html: following pattern found:
260+
Passed: out/p/C.html: the following pattern was found:
254261
d.f4.6""");
255262
}
256263

@@ -271,28 +278,28 @@ public void testOrdered() {
271278

272279
checkMessages(
273280
"""
274-
Passed: out/p/C.html: following text found:
281+
Passed: out/p/C.html: the following text was found:
275282
<h2>Method Summary</h2>""",
276283
"""
277-
Passed: out/p/C.html: following text found:
284+
Passed: out/p/C.html: the following text was found:
278285
<a href="#m1()" class="member-name-link">m1</a>""",
279286
"""
280-
Passed: out/p/C.html: following text found:
287+
Passed: out/p/C.html: the following text was found:
281288
<a href="#m2()" class="member-name-link">m2</a>""",
282289
"""
283-
Passed: out/p/C.html: following text found:
290+
Passed: out/p/C.html: the following text was found:
284291
<a href="#m3()" class="member-name-link">m3</a>""",
285292
"""
286-
Passed: out/p/C.html: following text found:
293+
Passed: out/p/C.html: the following text was found:
287294
<h2>Method Details</h2>""",
288295
"""
289-
Passed: out/p/C.html: following text found:
296+
Passed: out/p/C.html: the following text was found:
290297
<section class="detail" id="m3()">""",
291298
"""
292-
Passed: out/p/C.html: following text found:
299+
Passed: out/p/C.html: the following text was found:
293300
<section class="detail" id="m2()">""",
294301
"""
295-
Passed: out/p/C.html: following text found:
302+
Passed: out/p/C.html: the following text was found:
296303
<section class="detail" id="m1()">"""
297304
);
298305
}
@@ -306,10 +313,10 @@ public void testUnordered_expected() {
306313
"First sentence");
307314
checkMessages(
308315
"""
309-
Passed: out/p/C.html: following text found:
316+
Passed: out/p/C.html: the following text was found:
310317
Second sentence""",
311318
"""
312-
Passed: out/p/C.html: following text found:
319+
Passed: out/p/C.html: the following text was found:
313320
First sentence""");
314321
}
315322

@@ -321,10 +328,11 @@ public void testUnordered_unexpected() {
321328
"First sentence");
322329
checkMessages(
323330
"""
324-
Passed: out/p/C.html: following text found:
331+
Passed: out/p/C.html: the following text was found:
325332
Second sentence""",
326333
"""
327-
FAILED: out/p/C.html: following text was found on line""");
334+
FAILED: out/p/C.html: output not as expected
335+
>> the following text was found on line""");
328336
}
329337

330338
@Test

test/langtools/jdk/javadoc/testJavadocTester/TestJavadocTesterCrash.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public String toString(List<? extends DocTree> tags, Element element) {
8686
String s = tags.toString();
8787
if (s.contains("test")) {
8888
throw new Error("demo error");
89-
};
89+
}
9090
return s;
9191
}
9292
}
@@ -118,6 +118,8 @@ public class C { }""");
118118
"1 error");
119119

120120
// verify that JavadocTester detected the crash
121-
checkMessages("FAILED: STDERR: following text found:");
121+
checkMessages("""
122+
FAILED: STDERR: output not as expected
123+
>> the following text was found:""");
122124
}
123125
}

0 commit comments

Comments
 (0)