10000 Merge pull request #5076 from sjrd/simplify-platform-test-api · scala-js/scala-js@344b0db · GitHub
[go: up one dir, main page]

Skip to content

Commit 344b0db

Browse files
authored
Merge pull request #5076 from sjrd/simplify-platform-test-api
Simplify the test API we use to identify specific JDKs.
2 parents da2554d + 7ae4a05 commit 344b0db

File tree

10 files changed

+20
-40
lines changed

10 files changed

+20
-40
lines changed

test-suite-ex/shared/src/test/scala/org/scalajs/testsuite/javalib/util/FormatterTestEx.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class FormatterTestEx {
7676
* locale uses U+202F NARROW NO-BREAK SPACE as grouping
7777
* separator, instead of U+00A0 NO-BREAK SPACE.
7878
*/
79-
if (!executingInJVMOnLowerThanJDK13) {
79+
if (!executingInJVMOnLowerThanJDK(13)) {
8080
// U+202F NARROW NO-BREAK SPACE
8181
assertF(French, "1\u202F234\u202F567", "%,d", 1234567)
8282
assertF(French, "1\u202F234\u202F567,89", "%,.2f", 1234567.89)
@@ -119,7 +119,7 @@ class FormatterTestEx {
119119

120120
@Test def testFormatTurkish(): Unit = {
121121
assumeFalse("Affected by https://bugs.openjdk.java.net/browse/JDK-8060094",
122-
executingInJVMOnJDK8OrLower)
122+
executingInJVMOnLowerThanJDK(9))
123123

124124
// U+0130 LATIN CAPITAL LETTER I WITH DOT ABOVE
125125
assertF(Turkish, "TİTLE", "%S", "title")

test-suite/js/src/main/scala/org/scalajs/testsuite/utils/Platform.scala

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,10 @@ object Platform {
2424
*/
2525
final val executingInJVM = false
2626

27-
final val executingInJVMOnJDK8OrLower = false
28-
29-
final val executingInJVMOnLowerThanJDK10 = false
30-
31-
final val executingInJVMOnLowerThanJDK13 = false
32-
33-
final val executingInJVMOnLowerThanJDK15 = false
34-
35-
final val executingInJVMOnLowerThanJDK16 = false
36-
37-
final val executingInJVMOnLowerThanJDK17 = false
38-
3927
def executingInJVMOnLowerThanJDK(version: Int): Boolean = false
4028

29+
def executingInJVMWithJDKIn(range: Range): Boolean = false
30+
4131
def executingInWebAssembly: Boolean = BuildInfo.isWebAssembly
4232

4333
def executingInNodeJS: Boolean = {

test-suite/jvm/src/main/scala/org/scalajs/testsuite/utils/Platform.scala

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,10 @@ object Platform {
2222
*/
2323
final val executingInJVM = true
2424

25-
def executingInJVMOnJDK8OrLower: Boolean = jdkVersion <= 8
26-
27-
def executingInJVMOnLowerThanJDK10: Boolean = jdkVersion < 10
28-
29-
def executingInJVMOnLowerThanJDK13: Boolean = jdkVersion < 13
30-
31-
def executingInJVMOnLowerThanJDK15: Boolean = jdkVersion < 15
32-
33-
def executingInJVMOnLowerThanJDK16: Boolean = jdkVersion < 16
34-
35-
def executingInJVMOnLowerThanJDK17: Boolean = jdkVersion < 17
36-
3725
def executingInJVMOnLowerThanJDK(version: Int): Boolean = jdkVersion < version
3826

27+
def executingInJVMWithJDKIn(range: Range): Boolean = range.contains(jdkVersion)
28+
3929
private lazy val jdkVersion = {
4030
val v = System.getProperty("java.version")
4131
if (v.startsWith("1.")) Integer.parseInt(v.drop(2).takeWhile(_.isDigit))

test-suite/shared/src/test/scala/org/scalajs/testsuite/javalib/net/URITest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import org.junit.Assert._
1818
import org.junit.Test
1919

2020
import org.scalajs.testsuite.utils.AssertThrows.assertThrows
21-
import org.scalajs.testsuite.utils.Platform.executingInJVMOnLowerThanJDK15
21+
import org.scalajs.testsuite.utils.Platform._
2222

2323
class URITest {
2424

@@ -170,7 +170,7 @@ class URITest {
170170
val rel3 = new URI("/foo/ccc")
171171

172172
// https://bugs.openjdk.java.net/browse/JDK-5064980
173-
if (!executingInJVMOnLowerThanJDK15)
173+
if (!executingInJVMOnLowerThanJDK(15))
174174
assertTrue(x.compareTo(y) == 0)
175175

176176
assertTrue(x.compareTo(z) < 0)

test-suite/shared/src/test/scala/org/scalajs/testsuite/javalib/net/URLDecoderTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class URLDecoderTest {
9999
* the implementation. So in all likelihood, it will not be coming back.
100100
* It is still throwing as of JDK 17.
101101
*/
102-
if (!executingInJVMOnLowerThanJDK10) {
102+
if (!executingInJVMOnLowerThanJDK(10)) {
103103
unsupportedEncoding("abc", enc = "dummy")
104104
unsupportedEncoding("a+b+c", enc = "dummy")
105105
}

test-suite/shared/src/test/scala/org/scalajs/testsuite/javalib/util/FormatterTest.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ class FormatterTest {
16941694

16951695
@Test def indexNotInRangeThrows(): Unit = {
16961696
assumeFalse("https://bugs.openjdk.java.net/browse/JDK-8253875",
1697-
executingInJVMOnLowerThanJDK16)
1697+
executingInJVMOnLowerThanJDK(16))
16981698

16991699
/* The public JavaDoc says that these situations throw an
17001700
* IllegalFormatException, without being more specific. However, the bug
@@ -1716,7 +1716,7 @@ class FormatterTest {
17161716

17171717
@Test def widthOrPrecisionTooLargeThrows(): Unit = {
17181718
assumeFalse("https://bugs.openjdk.java.net/browse/JDK-8253875",
1719-
executingInJVMOnLowerThanJDK16)
1719+
executingInJVMOnLowerThanJDK(16))
17201720

17211721
expectFormatterThrows(classOf[IllegalFormatWidthException], "%d %9876543210d", 56, 78)
17221722
expectFormatterThrows(classOf[IllegalFormatPrecisionException], "%d %.9876543210f", 56, 78.5)

test-suite/shared/src/test/scala/org/scalajs/testsuite/javalib/util/MapTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1391,7 +1391,7 @@ trait MapTest {
13911391
* https://bugs.openjdk.org/browse/JDK-8259622
13921392
*/
13931393
assumeFalse("affected by JDK-8259622",
1394-
executingInJVMOnLowerThanJDK17 && !executingInJVMOnLowerThanJDK15 &&
1394+
executingInJVMWithJDKIn(15 to 16) &&
13951395
mp.isInstanceOf[ju.TreeMap[_, _]])
13961396

13971397
mp.put("nullable", null)

test-suite/shared/src/test/scala/org/scalajs/testsuite/javalib/util/concurrent/ThreadLocalRandomTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ class ThreadLocalRandomTest {
508508
@Test def nextDoubleDoubleDouble(): Unit = {
509509
implicit val tlr = ThreadLocalRandom.current()
510510

511-
if (!executingInJVMOnLowerThanJDK(19) || executingInJVMOnLowerThanJDK(17)) {
511+
if (!executingInJVMWithJDKIn(17 to 18)) {
512512
/* For some reason, JDK 17-18 throw an IllegalArgumentException for this one.
513513
* Older and more recent versions of the JDK succeed.
514514
*/

test-suite/shared/src/test/scala/org/scalajs/testsuite/javalib/util/regex/RegexEngineTest.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ class RegexEngineTest {
10341034
assertNotMatches(lower, "É")
10351035

10361036
// https://bugs.openjdk.java.net/browse/JDK-8214245
1037-
if (!executingInJVMOnLowerThanJDK15) {
1037+
if (!executingInJVMOnLowerThanJDK(15)) {
10381038
val lowerCI = compile("\\p{Lower}", CaseInsensitive)
10391039
assertMatches(lowerCI, "a")
10401040
assertMatches(lowerCI, "f")
@@ -1223,7 +1223,7 @@ class RegexEngineTest {
12231223
assertNotMatches(lower, "É")
12241224

12251225
// https://bugs.openjdk.java.net/browse/JDK-8214245
1226-
if (!executingInJVMOnLowerThanJDK15) {
1226+
if (!executingInJVMOnLowerThanJDK(15)) {
12271227
val lowerCI = compile("\\p{Lower}", CaseInsensitive | UnicodeCharacterClass)
12281228
assertMatches(lowerCI, "a")
12291229
assertMatches(lowerCI, "f")
@@ -1389,7 +1389,7 @@ class RegexEngineTest {
13891389
checkConsistency("javaIdentifierIgnorable", "[\u0000-\u0008\u000E-\u001B\u007F-\u009F\\p{Cf}]")
13901390
checkConsistency("javaIdeographic", "\\p{IsIdeographic}")
13911391
checkConsistency("javaISOControl", "[\u0000-\u001F\u007F-\u009F]")
1392-
if (!executingInJVMOnJDK8OrLower) {
1392+
if (!executingInJVMOnLowerThanJDK(9)) {
13931393
checkConsistency("javaJavaIdentifierPart",
13941394
"[\\p{L}\\p{Sc}\\p{Pc}\\p{Nd}\\p{Nl}\\p{Mn}\\p{Mc}\u0000-\u0008\u000E-\u001B\u007F-\u009F\\p{Cf}]")
13951395
checkConsistency("javaJavaIdentifierStart", "[\\p{L}\\p{Sc}\\p{Pc}\\p{Nl}]")
@@ -1459,7 +1459,7 @@ class RegexEngineTest {
14591459
/* SignWriting is special because of its canonical name, which is not Sign_Writing.
14601460
* It's from Unicode 8.0.0, so it requires JDK 9+.
14611461
*/
1462-
if (!executingInJVMOnJDK8OrLower) {
1462+
if (!executingInJVMOnLowerThanJDK(9)) {
14631463
val signWriting = compile("\\p{script=signwrItIng}")
14641464
assertMatches(signWriting, "\uD836\uDC36") // U+1D836 SIGNWRITING HAND-FIST MIDDLE THUMB CUPPED INDEX UP
14651465
assertNotMatches(signWriting, "A")
@@ -1846,7 +1846,7 @@ class RegexEngineTest {
18461846
assertNotMatches(complexUnionsAndIntersections, "z")
18471847

18481848
// https://bugs.openjdk.java.net/browse/JDK-8216391
1849-
if (!executingInJVMOnJDK8OrLower) {
1849+
if (!executingInJVMOnLowerThanJDK(9)) {
18501850
val not_ad_or_mp = compile("[^a-d[m-p]]")
18511851
assertNotMatches(not_ad_or_mp, "a")
18521852
assertNotMatches(not_ad_or_mp, "c")
@@ -2572,7 +2572,7 @@ class RegexEngineTest {
25722572
}
25732573

25742574
// JDK 9+ features
2575-
if (!executingInJVMOnJDK8OrLower) {
2575+
if (!executingInJVMOnLowerThanJDK(9)) {
25762576
assertSyntaxErrorInJS("\\N{DIGIT TWO}", "\\N is not supported", 1)
25772577
assertSyntaxErrorInJS("foo\\b{g}.", "\\b{g} is not supported", 4)
25782578
assertSyntaxErrorInJS("foo\\X", "\\X is not supported", 4)

test-suite/shared/src/test/scala/org/scalajs/testsuite/niobuffer/BaseBufferTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ abstract class BaseBufferTest {
313313

314314
@Test def compact(): Unit = {
315315
assumeFalse("Affected by a bug in the JDK.",
316-
executingInJVMOnJDK8OrLower &&
316+
executingInJVMOnLowerThanJDK(9) &&
317317
factory.isInstanceOf[BufferFactory.ByteBufferViewFactory])
318318

319319
if (!createsReadOnly) {

0 commit comments

Comments
 (0)
0