Skip to content

Commit 9c74d54

Browse files
committed
8358158: test/jdk/java/io/Console/CharsetTest.java failing with NoClassDefFoundError: jtreg/SkippedException
Reviewed-by: joehw, jlu, iris
1 parent 9397535 commit 9c74d54

File tree

6 files changed

+83
-85
lines changed

6 files changed

+83
-85
lines changed

test/jdk/java/io/Console/CharsetTest.java

Lines changed: 0 additions & 73 deletions
This file was deleted.

test/jdk/java/io/Console/ConsolePromptTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,7 @@ void doRunConsoleTest(String testName) throws Exception {
104104

105105
OutputAnalyzer output = ProcessTools.executeProcess(command.toArray(String[]::new));
106106
output.reportDiagnosticSummary();
107-
var eval = output.getExitValue();
108-
if (eval != 0) {
109-
throw new RuntimeException("Test failed. Exit value from 'expect' command: " + eval);
110-
}
107+
output.shouldHaveExitValue(0);
111108
}
112109

113110
public static class ConsoleTest {

test/jdk/java/io/Console/RestoreEchoTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 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
@@ -32,7 +32,6 @@
3232
import org.junit.jupiter.api.Test;
3333
import org.junit.jupiter.api.condition.EnabledOnOs;
3434
import org.junit.jupiter.api.condition.OS;
35-
import static org.junit.jupiter.api.Assertions.*;
3635

3736

3837
/**
@@ -72,7 +71,7 @@ private static void expectRunner(String initialEcho) throws Throwable {
7271
"-classpath", testClasses,
7372
"RestoreEchoTest");
7473
output.reportDiagnosticSummary();
75-
assertEquals(0, output.getExitValue());
74+
output.shouldHaveExitValue(0);
7675
}
7776

7877
public static void main(String... args) throws Throwable {

test/jdk/java/io/Console/StdinEncodingTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import org.junit.jupiter.api.Assumptions;
3333
import org.junit.jupiter.api.Test;
34-
import static org.junit.jupiter.api.Assertions.assertEquals;
3534

3635
/**
3736
* @test
@@ -64,8 +63,7 @@ public void testStdinEncoding() throws Throwable {
6463
"-Dstdin.encoding=Uppercasing", // <- gist of this test
6564
"StdinEncodingTest");
6665
output.reportDiagnosticSummary();
67-
var eval = output.getExitValue();
68-
assertEquals(0, eval, "Test failed. Exit value from 'expect' command: " + eval);
66+
output.shouldHaveExitValue(0);
6967
}
7068

7169
public static void main(String... args) throws Throwable {
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import java.nio.file.Files;
25+
import java.nio.file.Paths;
26+
27+
import jdk.test.lib.process.OutputAnalyzer;
28+
import jdk.test.lib.process.ProcessTools;
29+
import static jdk.test.lib.Utils.*;
30+
31+
import org.junit.jupiter.api.Assumptions;
32+
import org.junit.jupiter.params.ParameterizedTest;
33+
import org.junit.jupiter.params.provider.CsvSource;
34+
35+
/**
36+
* @test
37+
* @bug 8264208 8265918 8356985 8358158
38+
* @summary Tests if "stdout.encoding" property is reflected in
39+
* Console.charset() method. "expect" command in Windows/Cygwin
40+
* does not work as expected. Ignoring tests on Windows.
41+
* @requires (os.family == "linux") | (os.family == "mac")
42+
* @library /test/lib
43+
* @run junit StdoutEncodingTest
44+
*/
45+
public class StdoutEncodingTest {
46+
47+
@ParameterizedTest
48+
@CsvSource({
49+
"en_US.ISO8859-1, ISO-8859-1",
50+
"en_US.US-ASCII, US-ASCII",
51+
"en_US.UTF-8, UTF-8"
52+
})
53+
void testCharset(String locale, String expectedCharset) throws Exception {
54+
// check "expect" command availability
55+
var expect = Paths.get("/usr/bin/expect");
56+
Assumptions.assumeTrue(Files.exists(expect) && Files.isExecutable(expect),
57+
"'" + expect + "' not found. Test ignored.");
58+
59+
// invoking "expect" command
60+
OutputAnalyzer output = ProcessTools.executeProcess(
61+
"expect",
62+
"-n",
63+
TEST_SRC + "/stdoutEncoding.exp",
64+
TEST_JDK + "/bin/java",
65+
locale,
66+
expectedCharset,
67+
TEST_CLASSES);
68+
output.reportDiagnosticSummary();
69+
output.shouldHaveExitValue(0);
70+
}
71+
72+
public static void main(String... args) {
73+
System.out.println(System.console().charset());
74+
}
75+
}

test/jdk/java/io/Console/script.exp renamed to test/jdk/java/io/Console/stdoutEncoding.exp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@
2121
# questions.
2222
#
2323

24+
# `expect` script for StdoutEncodingTest
25+
2426
set java [lrange $argv 0 0]
2527
set locale [lrange $argv 1 1]
2628
set expected [lrange $argv 2 2]
27-
set args [lrange $argv 3 end]
29+
set classpath [lrange $argv 3 end]
2830
regexp {([a-zA-Z_]*).([a-zA-Z0-9\-]*)} $locale dummy lang_region encoding
2931

30-
eval spawn $java -Dstdout.encoding=$encoding -classpath $args CharsetTest
32+
eval spawn $java -Dstdout.encoding=$encoding -classpath $classpath StdoutEncodingTest
3133
expect $expected
3234
expect eof

0 commit comments

Comments
 (0)