Skip to content

Commit c70e554

Browse files
ddolovovSpace Team
authored andcommitted
[JS, Wasm] Simplify and unify stdlib/kotlin-test version checker tests
^KT-82208
1 parent 1a5ef3e commit c70e554

File tree

3 files changed

+68
-135
lines changed

3 files changed

+68
-135
lines changed

js/js.tests/testFixtures/org/jetbrains/kotlin/js/testOld/klib/LibrarySpecialCompatibilityChecksTest.kt

Lines changed: 64 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -39,49 +39,30 @@ abstract class LibrarySpecialCompatibilityChecksTest : TestCaseWithTmpdir() {
3939
}
4040
}
4141

42-
fun testJsNewerCompilerVersion() {
42+
fun testNewerCompilerVersion() {
4343
testCurrentAndNextBasicVersions { currentVersion, nextVersion ->
44-
compileDummyLibrary(
45-
libraryVersion = currentVersion,
46-
compilerVersion = nextVersion,
47-
isWasm = false,
48-
expectedWarningStatus = WarningStatus.JS_OLD_LIBRARY_WARNING
49-
)
50-
}
51-
}
52-
53-
fun testJsOlderCompilerVersion() {
54-
testCurrentAndNextBasicVersions { currentVersion, nextVersion ->
55-
val sameLanguageVersion = haveSameLanguageVersion(currentVersion, nextVersion)
56-
compileDummyLibrary(
57-
libraryVersion = nextVersion,
58-
compilerVersion = currentVersion,
59-
isWasm = false,
60-
expectedWarningStatus = if (sameLanguageVersion) WarningStatus.NO_WARNINGS else WarningStatus.JS_TOO_NEW_LIBRARY_WARNING
61-
)
62-
}
63-
}
64-
65-
fun testWasmNewerCompilerVersion() {
66-
testCurrentAndNextBasicVersions { currentVersion, nextVersion ->
67-
compileDummyLibrary(
68-
libraryVersion = currentVersion,
69-
compilerVersion = nextVersion,
70-
isWasm = true,
71-
expectedWarningStatus = WarningStatus.WASM_OLD_LIBRARY_WARNING
72-
)
44+
for (isWasm in listOf(false, true)) {
45+
compileDummyLibrary(
46+
libraryVersion = currentVersion,
47+
compilerVersion = nextVersion,
48+
isWasm = isWasm,
49+
expectedWarningStatus = WarningStatus.OLD_LIBRARY_WARNING
50+
)
51+
}
7352
}
7453
}
7554

76-
fun testWasmOlderCompilerVersion() {
55+
fun testOlderCompilerVersion() {
7756
testCurrentAndNextBasicVersions { currentVersion, nextVersion ->
7857
val sameLanguageVersion = haveSameLanguageVersion(currentVersion, nextVersion)
79-
compileDummyLibrary(
80-
libraryVersion = nextVersion,
81-
compilerVersion = currentVersion,
82-
isWasm = true,
83-
expectedWarningStatus = if (sameLanguageVersion) WarningStatus.NO_WARNINGS else WarningStatus.WASM_TOO_NEW_LIBRARY_WARNING
84-
)
58+
for (isWasm in listOf(false, true)) {
59+
compileDummyLibrary(
60+
libraryVersion = nextVersion,
61+
compilerVersion = currentVersion,
62+
isWasm = isWasm,
63+
expectedWarningStatus = if (sameLanguageVersion) WarningStatus.NO_WARNINGS else WarningStatus.TOO_NEW_LIBRARY_WARNING
64+
)
65+
}
8566
}
8667
}
8768

@@ -98,31 +79,19 @@ abstract class LibrarySpecialCompatibilityChecksTest : TestCaseWithTmpdir() {
9879
}
9980
}
10081

101-
fun testJsEitherVersionIsMissing() {
82+
fun testEitherVersionIsMissing() {
10283
listOf(
10384
TestVersion(2, 0, 0) to null,
10485
null to TestVersion(2, 0, 0),
10586
).forEach { (libraryVersion, compilerVersion) ->
106-
compileDummyLibrary(
107-
libraryVersion = libraryVersion,
108-
compilerVersion = compilerVersion,
109-
isWasm = false,
110-
expectedWarningStatus = WarningStatus.NO_WARNINGS
111-
)
112-
}
113-
}
114-
115-
fun testWasmEitherVersionIsMissing() {
116-
listOf(
117-
TestVersion(2, 0, 0) to null,
118-
null to TestVersion(2, 0, 0),
119-
).forEach { (libraryVersion, compilerVersion) ->
120-
compileDummyLibrary(
121-
libraryVersion = libraryVersion,
122-
compilerVersion = compilerVersion,
123-
isWasm = true,
124-
expectedWarningStatus = WarningStatus.NO_WARNINGS
125-
)
87+
for (isWasm in listOf(false, true)) {
88+
compileDummyLibrary(
89+
libraryVersion = libraryVersion,
90+
compilerVersion = compilerVersion,
91+
isWasm = isWasm,
92+
expectedWarningStatus = WarningStatus.NO_WARNINGS
93+
)
94+
}
12695
}
12796
}
12897

@@ -136,22 +105,48 @@ abstract class LibrarySpecialCompatibilityChecksTest : TestCaseWithTmpdir() {
136105
compileDummyLibrary(libraryVersion, compilerVersion, isWasm, isZipped = true, expectedWarningStatus)
137106
}
138107

139-
protected abstract fun MessageCollectorImpl.hasJsOldLibraryError(specificVersions: Pair<TestVersion, TestVersion>? = null): Boolean
140-
protected abstract fun MessageCollectorImpl.hasJsTooNewLibraryError(specificVersions: Pair<TestVersion, TestVersion>? = null): Boolean
141-
protected abstract fun MessageCollectorImpl.hasWasmOldLibraryError(specificVersions: Pair<TestVersion, TestVersion>? = null): Boolean
142-
protected abstract fun MessageCollectorImpl.hasWasmTooNewLibraryError(specificVersions: Pair<TestVersion, TestVersion>? = null): Boolean
108+
protected abstract val libraryDisplayName: String
109+
110+
private fun MessageCollectorImpl.hasOldLibraryError(
111+
isWasm: Boolean,
112+
specificVersions: Pair<TestVersion, TestVersion>? = null,
113+
): Boolean {
114+
val platformDisplayName = if (isWasm) "Kotlin/Wasm" else "Kotlin/JS"
115+
116+
val stdlibMessagePart = "$platformDisplayName $libraryDisplayName library has an older version" +
117+
specificVersions?.first?.let { " ($it)" }.orEmpty()
118+
val compilerMessagePart = "than the compiler" + specificVersions?.second?.let { " ($it)" }.orEmpty()
119+
120+
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
121+
}
122+
123+
private fun MessageCollectorImpl.hasTooNewLibraryError(
124+
isWasm: Boolean,
125+
specificVersions: Pair<TestVersion, TestVersion>? = null,
126+
): Boolean {
127+
val platformDisplayName = if (isWasm) "Kotlin/Wasm" else "Kotlin/JS"
128+
129+
val stdlibMessagePart = "The $platformDisplayName $libraryDisplayName library has a more recent version" +
130+
specificVersions?.first?.let { " ($it)" }.orEmpty()
131+
val compilerMessagePart = "The compiler version is " + specificVersions?.second?.toString().orEmpty()
132+
133+
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
134+
135+
}
143136

144137
private fun MessageCollectorImpl.checkMessage(
138+
isWasm: Boolean,
145139
expectedWarningStatus: WarningStatus,
146140
libraryVersion: TestVersion?,
147141
compilerVersion: TestVersion?,
148142
) {
149143
val success = when (expectedWarningStatus) {
150-
WarningStatus.NO_WARNINGS -> !hasJsOldLibraryError() && !hasJsTooNewLibraryError() && !hasWasmOldLibraryError() && !hasWasmTooNewLibraryError()
151-
WarningStatus.JS_OLD_LIBRARY_WARNING -> hasJsOldLibraryError(libraryVersion!! to compilerVersion!!)
152-
WarningStatus.JS_TOO_NEW_LIBRARY_WARNING -> hasJsTooNewLibraryError(libraryVersion!! to compilerVersion!!)
153-
WarningStatus.WASM_OLD_LIBRARY_WARNING -> hasWasmOldLibraryError(libraryVersion!! to compilerVersion!!)
154-
WarningStatus.WASM_TOO_NEW_LIBRARY_WARNING -> hasWasmTooNewLibraryError(libraryVersion!! to compilerVersion!!)
144+
WarningStatus.NO_WARNINGS -> !hasOldLibraryError(isWasm = false) &&
145+
!hasTooNewLibraryError(isWasm = false) &&
146+
!hasOldLibraryError(isWasm = true) &&
147+
!hasTooNewLibraryError(isWasm = true)
148+
WarningStatus.OLD_LIBRARY_WARNING -> hasOldLibraryError(isWasm, libraryVersion!! to compilerVersion!!)
149+
WarningStatus.TOO_NEW_LIBRARY_WARNING -> hasTooNewLibraryError(isWasm, libraryVersion!! to compilerVersion!!)
155150
}
156151
if (!success) fail(
157152
buildString {
@@ -195,7 +190,7 @@ abstract class LibrarySpecialCompatibilityChecksTest : TestCaseWithTmpdir() {
195190
}
196191
}
197192

198-
messageCollector.checkMessage(expectedWarningStatus, libraryVersion, compilerVersion)
193+
messageCollector.checkMessage(isWasm, expectedWarningStatus, libraryVersion, compilerVersion)
199194
}
200195

201196
private fun haveSameLanguageVersion(a: TestVersion, b: TestVersion): Boolean =
@@ -261,7 +256,7 @@ abstract class LibrarySpecialCompatibilityChecksTest : TestCaseWithTmpdir() {
261256
protected fun createDir(name: String): File = tmpdir.resolve(name).apply { mkdirs() }
262257
protected fun createFile(name: String): File = tmpdir.resolve(name).apply { parentFile.mkdirs() }
263258

264-
protected enum class WarningStatus { NO_WARNINGS, JS_OLD_LIBRARY_WARNING, JS_TOO_NEW_LIBRARY_WARNING, WASM_OLD_LIBRARY_WARNING, WASM_TOO_NEW_LIBRARY_WARNING }
259+
protected enum class WarningStatus { NO_WARNINGS, OLD_LIBRARY_WARNING, TOO_NEW_LIBRARY_WARNING }
265260

266261
protected class TestVersion(val basicVersion: KotlinVersion, val postfix: String) : Comparable<TestVersion> {
267262
constructor(major: Int, minor: Int, patch: Int, postfix: String = "") : this(KotlinVersion(major, minor, patch), postfix)

js/js.tests/tests/org/jetbrains/kotlin/js/testOld/klib/JsWasmStdlibSpecialCompatibilityChecksTest.kt

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,11 @@
55

66
package org.jetbrains.kotlin.js.testOld.klib
77

8-
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorImpl
9-
import kotlin.collections.any
10-
118
@Suppress("JUnitTestCaseWithNoTests")
129
class JsWasmStdlibSpecialCompatibilityChecksTest : LibrarySpecialCompatibilityChecksTest() {
1310
override val originalLibraryPath: String
1411
get() = System.getProperty("kotlin.js.full.stdlib.path")
1512

16-
override fun MessageCollectorImpl.hasJsOldLibraryError(specificVersions: Pair<TestVersion, TestVersion>?): Boolean {
17-
val stdlibMessagePart = "Kotlin/JS standard library has an older version" + specificVersions?.first?.let { " ($it)" }.orEmpty()
18-
val compilerMessagePart = "than the compiler" + specificVersions?.second?.let { " ($it)" }.orEmpty()
19-
20-
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
21-
}
22-
23-
override fun MessageCollectorImpl.hasJsTooNewLibraryError(specificVersions: Pair<TestVersion, TestVersion>?): Boolean {
24-
val stdlibMessagePart =
25-
"The Kotlin/JS standard library has a more recent version" + specificVersions?.first?.let { " ($it)" }.orEmpty()
26-
val compilerMessagePart = "The compiler version is " + specificVersions?.second?.toString().orEmpty()
27-
28-
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
29-
}
30-
31-
override fun MessageCollectorImpl.hasWasmOldLibraryError(specificVersions: Pair<TestVersion, TestVersion>?): Boolean {
32-
val stdlibMessagePart = "Kotlin/Wasm standard library has an older version" + specificVersions?.first?.let { " ($it)" }.orEmpty()
33-
val compilerMessagePart = "than the compiler" + specificVersions?.second?.let { " ($it)" }.orEmpty()
34-
35-
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
36-
}
37-
38-
override fun MessageCollectorImpl.hasWasmTooNewLibraryError(specificVersions: Pair<TestVersion, TestVersion>?): Boolean {
39-
val stdlibMessagePart =
40-
"The Kotlin/Wasm standard library has a more recent version" + specificVersions?.first?.let { " ($it)" }.orEmpty()
41-
val compilerMessagePart = "The compiler version is " + specificVersions?.second?.toString().orEmpty()
42-
43-
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
44-
}
13+
override val libraryDisplayName: String
14+
get() = "standard"
4515
}

js/js.tests/tests/org/jetbrains/kotlin/js/testOld/klib/JsWasmTestLibSpecialCompatibilityChecksTest.kt

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55

66
package org.jetbrains.kotlin.js.testOld.klib
77

8-
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorImpl
9-
import kotlin.collections.any
10-
118
@Suppress("JUnitTestCaseWithNoTests")
129
class JsWasmTestLibSpecialCompatibilityChecksTest : LibrarySpecialCompatibilityChecksTest() {
1310
override val originalLibraryPath: String
@@ -16,35 +13,6 @@ class JsWasmTestLibSpecialCompatibilityChecksTest : LibrarySpecialCompatibilityC
1613
override fun additionalLibraries(isWasm: Boolean): List<String> =
1714
if (!isWasm) listOf(System.getProperty("kotlin.js.full.stdlib.path")) else listOf(System.getProperty("kotlin.wasm.full.stdlib.path"))
1815

19-
override fun MessageCollectorImpl.hasJsOldLibraryError(
20-
specificVersions: Pair<TestVersion, TestVersion>?,
21-
): Boolean {
22-
val stdlibMessagePart = "Kotlin/JS kotlin-test library has an older version" + specificVersions?.first?.let { " ($it)" }.orEmpty()
23-
val compilerMessagePart = "than the compiler" + specificVersions?.second?.let { " ($it)" }.orEmpty()
24-
25-
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
26-
}
27-
28-
override fun MessageCollectorImpl.hasJsTooNewLibraryError(specificVersions: Pair<TestVersion, TestVersion>?): Boolean {
29-
val stdlibMessagePart =
30-
"The Kotlin/JS kotlin-test library has a more recent version" + specificVersions?.first?.let { " ($it)" }.orEmpty()
31-
val compilerMessagePart = "The compiler version is " + specificVersions?.second?.toString().orEmpty()
32-
33-
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
34-
}
35-
36-
override fun MessageCollectorImpl.hasWasmOldLibraryError(specificVersions: Pair<TestVersion, TestVersion>?): Boolean {
37-
val stdlibMessagePart = "Kotlin/Wasm kotlin-test library has an older version" + specificVersions?.first?.let { " ($it)" }.orEmpty()
38-
val compilerMessagePart = "than the compiler" + specificVersions?.second?.let { " ($it)" }.orEmpty()
39-
40-
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
41-
}
42-
43-
override fun MessageCollectorImpl.hasWasmTooNewLibraryError(specificVersions: Pair<TestVersion, TestVersion>?): Boolean {
44-
val stdlibMessagePart =
45-
"The Kotlin/Wasm kotlin-test library has a more recent version" + specificVersions?.first?.let { " ($it)" }.orEmpty()
46-
val compilerMessagePart = "The compiler version is " + specificVersions?.second?.toString().orEmpty()
47-
48-
return messages.any { stdlibMessagePart in it.message && compilerMessagePart in it.message }
49-
}
16+
override val libraryDisplayName: String
17+
get() = "kotlin-test"
5018
}

0 commit comments

Comments
 (0)