|
1 | 1 | /*
|
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. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
4 | 4 | *
|
5 | 5 | * This code is free software; you can redistribute it and/or modify it
|
@@ -89,18 +89,34 @@ protected int runShell(String... args) {
|
89 | 89 | }
|
90 | 90 |
|
91 | 91 | 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; |
101 | 111 | }
|
102 | 112 | }
|
103 | 113 |
|
| 114 | + private void logOutput(String outName, ByteArrayOutputStream out) { |
| 115 | + System.err.println(outName + ": " + |
| 116 | + new String(out.toByteArray(), |
| 117 | + StandardCharsets.UTF_8)); |
| 118 | + } |
| 119 | + |
104 | 120 | protected void checkExit(int ec, Consumer<Integer> checkCode) {
|
105 | 121 | if (checkCode != null) {
|
106 | 122 | checkCode.accept(ec);
|
|
0 commit comments