Skip to content

Commit af8982b

Browse files
committed
[Wasm] fix tests for className wasm (KT-69621)
1 parent 9e970e1 commit af8982b

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

core/commonTest/src/kotlinx/serialization/modules/ModuleBuildersTest.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,22 @@ class ModuleBuildersTest {
227227
subclass(C2::class)
228228
}
229229
}
230-
val classNameMsg = if (currentPlatform == Platform.JS || currentPlatform == Platform.WASM) "class Any" else "class kotlin.Any"
231-
assertFailsWithMessage<IllegalArgumentException>("Multiple polymorphic serializers in a scope of '$classNameMsg' have the same serial name 'C'") { c1 + c2 }
230+
val msgConstructor: (String) -> String = {
231+
classNameMsg -> "Multiple polymorphic serializers in a scope of '$classNameMsg' have the same serial name 'C'"
232+
}
233+
// In WASM the class name may appear as either "class Any" or "class kotlin.Any" due to changing API
234+
if (currentPlatform == Platform.WASM) {
235+
val ex = assertFailsWith<IllegalArgumentException> { c1 + c2 }
236+
val expected1 = msgConstructor("class Any")
237+
val expected2 = msgConstructor("class kotlin.Any")
238+
assertTrue(
239+
ex.message!!.contains(expected1) || ex.message!!.contains(expected2),
240+
"Expected exception message '${ex.message}' to contain either:\n'$expected1' or \n'$expected2'"
241+
)
242+
} else {
243+
val classNameMsg = if (currentPlatform == Platform.JS) "class Any" else "class kotlin.Any"
244+
assertFailsWithMessage<IllegalArgumentException>(msgConstructor(classNameMsg)) { c1 + c2 }
245+
}
232246
val module = c1 overwriteWith c2
233247
// C should not be registered at all, C2 should be registered both under "C" and C2::class
234248
assertEquals(C2.serializer(), module.getPolymorphic(Any::class, serializedClassName = "C"))

0 commit comments

Comments
 (0)