@@ -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)
0 commit comments