Skip to content

Commit 23eb648

Browse files
committed
8353545: Improve debug info for StartOptionTest
Reviewed-by: asotona
1 parent 4f97c4c commit 23eb648

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

test/langtools/jdk/jshell/StartOptionTest.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -89,18 +89,34 @@ protected int runShell(String... args) {
8989
}
9090

9191
protected void check(ByteArrayOutputStream str, Consumer<String> checkOut, String label) {
92-
byte[] bytes = str.toByteArray();
93-
str.reset();
94-
String out = new String(bytes, StandardCharsets.UTF_8);
95-
out = stripAnsi(out);
96-
out = out.replaceAll("[\r\n]+", "\n");
97-
if (checkOut != null) {
98-
checkOut.accept(out);
99-
} else {
100-
assertEquals(out, "", label + ": Expected empty -- ");
92+
try {
93+
byte[] bytes = str.toByteArray();
94+
str.reset();
95+
String out = new String(bytes, StandardCharsets.UTF_8);
96+
out = stripAnsi(out);
97+
out = out.replaceAll("[\r\n]+", "\n");
98+
if (checkOut != null) {
99+
checkOut.accept(out);
100+
} else {
101+
assertEquals(out, "", label + ": Expected empty -- ");
102+
}
103+
} catch (Throwable t) {
104+
logOutput("cmdout", cmdout);
105+
logOutput("cmderr", cmderr);
106+
logOutput("console", console);
107+
logOutput("userout", userout);
108+
logOutput("usererr", usererr);
109+
110+
throw t;
101111
}
102112
}
103113

114+
private void logOutput(String outName, ByteArrayOutputStream out) {
115+
System.err.println(outName + ": " +
116+
new String(out.toByteArray(),
117+
StandardCharsets.UTF_8));
118+
}
119+
104120
protected void checkExit(int ec, Consumer<Integer> checkCode) {
105121
if (checkCode != null) {
106122
checkCode.accept(ec);

0 commit comments

Comments
 (0)