From 73e9a3850d3c57380776ebe87faeba375e95ab50 Mon Sep 17 00:00:00 2001 From: duke Date: Tue, 15 Apr 2025 02:37:50 +0000 Subject: [PATCH] Backport 23eb648cae1ccadbca0fd654d4fbc28a1b8375e2 --- .../langtools/jdk/jshell/StartOptionTest.java | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/test/langtools/jdk/jshell/StartOptionTest.java b/test/langtools/jdk/jshell/StartOptionTest.java index b84b454480e..296fb397c4b 100644 --- a/test/langtools/jdk/jshell/StartOptionTest.java +++ b/test/langtools/jdk/jshell/StartOptionTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -89,18 +89,34 @@ protected int runShell(String... args) { } protected void check(ByteArrayOutputStream str, Consumer checkOut, String label) { - byte[] bytes = str.toByteArray(); - str.reset(); - String out = new String(bytes, StandardCharsets.UTF_8); - out = stripAnsi(out); - out = out.replaceAll("[\r\n]+", "\n"); - if (checkOut != null) { - checkOut.accept(out); - } else { - assertEquals(out, "", label + ": Expected empty -- "); + try { + byte[] bytes = str.toByteArray(); + str.reset(); + String out = new String(bytes, StandardCharsets.UTF_8); + out = stripAnsi(out); + out = out.replaceAll("[\r\n]+", "\n"); + if (checkOut != null) { + checkOut.accept(out); + } else { + assertEquals(out, "", label + ": Expected empty -- "); + } + } catch (Throwable t) { + logOutput("cmdout", cmdout); + logOutput("cmderr", cmderr); + logOutput("console", console); + logOutput("userout", userout); + logOutput("usererr", usererr); + + throw t; } } + private void logOutput(String outName, ByteArrayOutputStream out) { + System.err.println(outName + ": " + + new String(out.toByteArray(), + StandardCharsets.UTF_8)); + } + protected void checkExit(int ec, Consumer checkCode) { if (checkCode != null) { checkCode.accept(ec);