Skip to content

Commit 1737cd3

Browse files
robertpatrickjeff5
authored andcommitted
Correct test expectations of _localeTest for Java 25
The currency symbol in the Chinese mainland locale has changed. We also bring in the Java 25 changes to build.gradle at this point, since it runs the Java tests. This change is cherry-picked from PR 424 with improvements.
1 parent 84c404b commit 1737cd3

2 files changed

Lines changed: 43 additions & 6 deletions

File tree

build.gradle

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,34 @@ ext {
9191
}
9292

9393

94+
// Collect extra arguments for the JVM in the test task
95+
ext.jythonTestJvmArgs = []
96+
97+
// Explicitly provided in a property
98+
def extraJythonTestJavaOpts = findProperty('jython.test.java.opts')
99+
if (extraJythonTestJavaOpts) {
100+
ext.jythonTestJvmArgs.addAll(
101+
extraJythonTestJavaOpts.toString().trim().split(/\s+/).findAll { it })
102+
}
103+
104+
// JVM aguments necessitated by later versions of Java
105+
// FIXME: Gradle 7.4.2 returns at most 21 here even on Java 25.
106+
// (Fix by updating Gradle: the code is correct and the warnings harmless.)
107+
def currentJavaMajor = JavaVersion.current().majorVersion as int
108+
if (currentJavaMajor >= 9) {
109+
ext.jythonTestJvmArgs.addAll([
110+
'--add-opens=java.base/java.io=ALL-UNNAMED',
111+
'--add-opens=java.base/sun.nio.ch=ALL-UNNAMED'
112+
])
113+
}
114+
if (currentJavaMajor >= 25) {
115+
ext.jythonTestJvmArgs.addAll([
116+
'--enable-native-access=ALL-UNNAMED',
117+
'--sun-misc-unsafe-memory-access=allow'
118+
])
119+
}
120+
121+
94122
repositories {
95123
// Jython is distributed through Maven Central. Get our dependencies there too.
96124
mavenCentral()
@@ -651,7 +679,8 @@ jar {
651679
'Main-Class': 'org.python.util.jython',
652680
'Built-By': 'build.gradle',
653681
'Automatic-Module-Name': 'org.python.jython2',
654-
'Enable-Native-Access': 'ALL-UNNAMED'
682+
'Enable-Native-Access': 'ALL-UNNAMED',
683+
'Add-Opens': 'java.base/java.io java.base/sun.nio.ch'
655684
])
656685

657686
attributes( [ // Build-Info section
@@ -684,6 +713,8 @@ task testJar(type: Jar) {
684713
attributes ([
685714
//'Main-Class': 'org.python.util.jython',
686715
'Built-By': 'build.gradle',
716+
'Enable-Native-Access': 'ALL-UNNAMED',
717+
'Add-Opens': 'java.base/java.io java.base/sun.nio.ch'
687718
])
688719

689720
attributes( [ // Build-Info section
@@ -864,6 +895,7 @@ test {
864895
systemProperty 'python.cachedir', "${project.buildDir}/cachedir"
865896
// Logging level: default is message=INFO
866897
//systemProperty 'python.verbose', 'CONFIG'
898+
jvmArgs project.ext.jythonTestJvmArgs
867899

868900
include '**/*Test*'
869901

@@ -890,7 +922,10 @@ test {
890922
exclude 'org/python/util/InterpreterTest.class'
891923

892924
doFirst {
893-
println "systemProperties = $systemProperties"
925+
println " systemProperties = $systemProperties"
926+
println " JavaVersion = ${JavaVersion.current()}"
927+
println "jythonTestJvmArgs = ${project.ext.jythonTestJvmArgs}"
928+
println " allJvmArgs = ${allJvmArgs}"
894929
}
895930

896931
}

tests/java/org/python/modules/_locale/_localeTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public void moduleImportDefault() {
116116

117117
private static int javaMajorVersion() {
118118
String versionString = System.getProperty("java.runtime.version");
119-
String[] javaVersionElements = versionString.split("\\.|_|-b");
119+
String[] javaVersionElements = versionString.split("\\.|_|-b|-|\\+");
120120
int major = Integer.valueOf(javaVersionElements[0]);
121121
int minor = Integer.valueOf(javaVersionElements[1]);
122122
if (major == 1) {
@@ -281,9 +281,11 @@ public void setLocaleGerman() {
281281
public void setLocaleChinaMainland() {
282282
settableInit();
283283
/*
284-
* Java has ¥ \uffe5 rather than 元 \u5143 for zh-CN Java has negative sign preceding, Python
285-
* following.
284+
* Java has ¥ rather than 元 \u5143 for zh-CN. Java has negative sign preceding, Python
285+
* following. JDK 17+ returns the regular yen sign \u00a5, while older JDKs returned the
286+
* full-width yen sign \uffe5.
286287
*/
288+
String currencySymbol = javaMajorVersion() >= 17 ? "\\xc2\\xa5" : "\\xef\\xbf\\xa5";
287289
// @formatter:off
288290
String script =
289291
"from _locale import setlocale, localeconv\n"
@@ -295,7 +297,7 @@ public void setLocaleChinaMainland() {
295297
+ "'decimal_point': '.', 'int_curr_symbol': 'CNY', "
296298
+ "'n_cs_precedes': 1, 'p_sign_posn': 3, "
297299
+ "'mon_thousands_sep': ',', 'negative_sign': '-', "
298-
+ "'currency_symbol': '\\xef\\xbf\\xa5' , "
300+
+ "'currency_symbol': '" + currencySymbol + "' , "
299301
+ "'n_sep_by_space': 0, "
300302
+ "'p_cs_precedes': 1, 'positive_sign': ''} \n"
301303
+ "actual = localeconv() \n"

0 commit comments

Comments
 (0)