diff --git a/test/langtools/jdk/javadoc/lib/javadoc/tester/JavadocTester.java b/test/langtools/jdk/javadoc/lib/javadoc/tester/JavadocTester.java index a409dd2cedb65..b4bb8a319df7f 100644 --- a/test/langtools/jdk/javadoc/lib/javadoc/tester/JavadocTester.java +++ b/test/langtools/jdk/javadoc/lib/javadoc/tester/JavadocTester.java @@ -827,9 +827,9 @@ public void checkFiles(boolean expectedFound, Collection paths) { Path file = outputDir.resolve(path); boolean isFound = Files.exists(file); if (isFound == expectedFound) { - passed(file, "file " + (isFound ? "found:" : "not found:") + "\n"); + passed(file, "file " + (isFound ? "found:" : "not found:")); } else { - failed(file, "file " + (isFound ? "found:" : "not found:") + "\n"); + failed(file, "file " + (isFound ? "found:" : "not found:")); } } } @@ -946,9 +946,10 @@ protected void checking(String message) { * * @param file the file that was the focus of the check * @param message a short description of the outcome + * @param details optional additional details */ - protected void passed(Path file, String message) { - passed(file + ": " + message); + protected void passed(Path file, String message, String... details) { + passed(file + ": " + message, details); } /** @@ -957,10 +958,14 @@ protected void passed(Path file, String message) { *

This method should be called after previously calling {@code checking(...)}. * * @param message a short description of the outcome + * @param details optional additional details */ - protected void passed(String message) { + protected void passed(String message, String... details) { numTestsPassed++; print("Passed", message); + for (var detail: details) { + detail.lines().forEachOrdered(out::println); + } out.println(); } @@ -971,9 +976,10 @@ protected void passed(String message) { * * @param file the file that was the focus of the check * @param message a short description of the outcome + * @param details optional additional details */ - protected void failed(Path file, String message) { - failed(file + ": " + message); + protected void failed(Path file, String message, String... details) { + failed(file + ": " + message, details); } /** @@ -982,8 +988,9 @@ protected void failed(Path file, String message) { *

This method should be called after previously calling {@code checking(...)}. * * @param message a short description of the outcome + * @param details optional additional details */ - protected void failed(String message) { + protected void failed(String message, String... details) { print("FAILED", message); StackWalker.getInstance().walk(s -> { s.dropWhile(f -> f.getMethodName().equals("failed")) @@ -993,6 +1000,9 @@ protected void failed(String message) { + "(" + f.getFileName() + ":" + f.getLineNumber() + ")")); return null; }); + for (var detail: details) { + detail.lines().forEachOrdered(out::println); + } out.println(); } @@ -1002,10 +1012,7 @@ private void print(String prefix, String message) { else { out.print(prefix); out.print(": "); - out.print(message.replace("\n", NL)); - if (!(message.endsWith("\n") || message.endsWith(NL))) { - out.println(); - } + message.lines().forEachOrdered(out::println); } } @@ -1219,25 +1226,28 @@ private void check(Function finder, SearchKind kind, String s) { boolean isFound = r != null; if (isFound == expectFound) { matches.add(lastMatch = r); - passed(name + ": following " + kind + " " + (isFound ? "found:" : "not found:") + "\n" - + s); + passed(name + ": the following " + kind + " was " + (isFound ? "found:" : "not found:"), + s); } else { // item not found in order, so check if the item is found out of order, to determine the best message if (expectFound && expectOrdered && start > 0) { Range r2 = finder.apply(0); if (r2 != null) { - failed(name + ": following " + kind + " was found on line " + failed(name + ": output not as expected", + ">> the following " + kind + " was found on line " + getLineNumber(r2.start) + ", but not in order as expected, on or after line " - + getLineNumber(start) - + ":\n" - + s); + + getLineNumber(start), + ">> " + kind + ":", + s); return; } } - failed(name + ": following " + kind + " " - + (isFound ? "found:" : "not found:") + "\n" - + s + '\n' + "found \n" + content); + failed(name + ": output not as expected", + ">> the following " + kind + " was " + (isFound ? "found:" : "not found:"), + s, + ">> found", + content); } } @@ -1374,8 +1384,9 @@ public OutputChecker checkComplete() { if (uncovered.isEmpty()) { passed("All output matched"); } else { - failed("The following output was not matched: " - + uncovered.stream() + failed("Output not as expected", + ">> The following output was not matched", + uncovered.stream() .map(Range::toIntervalString) .collect(Collectors.joining(", "))); } @@ -1395,8 +1406,9 @@ public OutputChecker checkEmpty() { if (content == null || content.isEmpty()) { passed(name + " is empty, as expected"); } else { - failed(name + " is not empty; contains:\n" - + content); + failed(name + " is not empty", + ">> found:", + content); } return this; } @@ -1444,7 +1456,8 @@ private OutputChecker checkAnyOf(SearchKind kind, List items, BiFunction< if (count == 0) { failed("no match found for any " + kind); } else { - passed(count + " matches found; earliest is " + earliest.toIntervalString()); + passed(count + " matches found", + ">> the earliest is: " + earliest.toIntervalString()); } return this; } diff --git a/test/langtools/jdk/javadoc/testJavadocTester/TestJavadocTester.java b/test/langtools/jdk/javadoc/testJavadocTester/TestJavadocTester.java index 2fcb0c9a958bc..abebf6fb3ba08 100644 --- a/test/langtools/jdk/javadoc/testJavadocTester/TestJavadocTester.java +++ b/test/langtools/jdk/javadoc/testJavadocTester/TestJavadocTester.java @@ -73,9 +73,9 @@ public static void main(String... args) throws Exception { * @param message a short description of the outcome */ @Override - public void passed(String message) { - super.passed(message); - messages.add("Passed: " + message); + public void passed(String message, String... details) { + super.passed(message, details); + messages.add("Passed: " + join(message, details)); } /** @@ -85,9 +85,13 @@ public void passed(String message) { * @param message a short description of the outcome */ @Override - public void failed(String message) { - super.failed(message); - messages.add("FAILED: " + message); + public void failed(String message, String... details) { + super.failed(message, details); + messages.add("FAILED: " + join(message, details)); + } + + private String join(String message, String... details) { + return details.length == 0 ? message : message + "\n" + String.join("\n", details); } /** @@ -138,6 +142,8 @@ void checkMessages(String... expect) { testErrors++; } } + + messages.forEach(m -> out.println("MESSAGES: " + m)); } /** @@ -153,7 +159,7 @@ void checkMessages(String... expect) { * @param message the message to be reported. */ private void report(String message) { - message.lines().forEachOrdered(l -> out.println(">>> " + l)); + message.lines().forEachOrdered(l -> out.println(">>>> " + l)); } //------------------------------------------------- @@ -202,13 +208,13 @@ public void testSimpleStringCheck() { messages.forEach(this::report); checkMessages( """ - Passed: out/p/C.html: following text found: + Passed: out/p/C.html: the following text was found: Second sentence""", """ - Passed: out/p/C.html: following text found: + Passed: out/p/C.html: the following text was found: abc123""", """ - Passed: out/p/C.html: following text found: + Passed: out/p/C.html: the following text was found: def456"""); } @@ -220,7 +226,7 @@ public void testSimpleNegativeStringCheck_expected() { .check("Third sentence."); checkMessages( """ - Passed: out/p/C.html: following text not found: + Passed: out/p/C.html: the following text was not found: Third sentence"""); } @@ -231,7 +237,8 @@ public void testSimpleNegativeStringCheck_unexpected() { .check("Third sentence."); checkMessages( """ - FAILED: out/p/C.html: following text not found: + FAILED: out/p/C.html: output not as expected + >> the following text was not found: Third sentence"""); } @@ -244,13 +251,13 @@ public void testSimpleRegexCheck() { Pattern.compile("d.f4.6")); checkMessages( """ - Passed: out/p/C.html: following pattern found: + Passed: out/p/C.html: the following pattern was found: S.cond s.nt.nc.""", """ - Passed: out/p/C.html: following pattern found: + Passed: out/p/C.html: the following pattern was found: [abc]{3}[123]{3}""", """ - Passed: out/p/C.html: following pattern found: + Passed: out/p/C.html: the following pattern was found: d.f4.6"""); } @@ -271,28 +278,28 @@ public void testOrdered() { checkMessages( """ - Passed: out/p/C.html: following text found: + Passed: out/p/C.html: the following text was found:

Method Summary

""", """ - Passed: out/p/C.html: following text found: + Passed: out/p/C.html: the following text was found: m1""", """ - Passed: out/p/C.html: following text found: + Passed: out/p/C.html: the following text was found: m2""", """ - Passed: out/p/C.html: following text found: + Passed: out/p/C.html: the following text was found: m3""", """ - Passed: out/p/C.html: following text found: + Passed: out/p/C.html: the following text was found:

Method Details

""", """ - Passed: out/p/C.html: following text found: + Passed: out/p/C.html: the following text was found:
""", """ - Passed: out/p/C.html: following text found: + Passed: out/p/C.html: the following text was found:
""", """ - Passed: out/p/C.html: following text found: + Passed: out/p/C.html: the following text was found:
""" ); } @@ -306,10 +313,10 @@ public void testUnordered_expected() { "First sentence"); checkMessages( """ - Passed: out/p/C.html: following text found: + Passed: out/p/C.html: the following text was found: Second sentence""", """ - Passed: out/p/C.html: following text found: + Passed: out/p/C.html: the following text was found: First sentence"""); } @@ -321,10 +328,11 @@ public void testUnordered_unexpected() { "First sentence"); checkMessages( """ - Passed: out/p/C.html: following text found: + Passed: out/p/C.html: the following text was found: Second sentence""", """ - FAILED: out/p/C.html: following text was found on line"""); + FAILED: out/p/C.html: output not as expected + >> the following text was found on line"""); } @Test diff --git a/test/langtools/jdk/javadoc/testJavadocTester/TestJavadocTesterCrash.java b/test/langtools/jdk/javadoc/testJavadocTester/TestJavadocTesterCrash.java index f0a6b0e98eb64..bd50902389560 100644 --- a/test/langtools/jdk/javadoc/testJavadocTester/TestJavadocTesterCrash.java +++ b/test/langtools/jdk/javadoc/testJavadocTester/TestJavadocTesterCrash.java @@ -86,7 +86,7 @@ public String toString(List tags, Element element) { String s = tags.toString(); if (s.contains("test")) { throw new Error("demo error"); - }; + } return s; } } @@ -118,6 +118,8 @@ public class C { }"""); "1 error"); // verify that JavadocTester detected the crash - checkMessages("FAILED: STDERR: following text found:"); + checkMessages(""" + FAILED: STDERR: output not as expected + >> the following text was found:"""); } }