Skip to content

Commit fdad11c

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

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,21 @@ 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 classNameMsg = if (currentPlatform == Platform.JS) "class Any" else "class kotlin.Any"
231+
// In WASM the class name may appear as either "class Any" or "class kotlin.Any" due to changing API
232+
if (currentPlatform == Platform.WASM) {
233+
val ex = assertFailsWith<IllegalArgumentException> { c1 + c2 }
234+
val expected1 = "Multiple polymorphic serializers in a scope of 'class Any' have the same serial name 'C'"
235+
val expected2 = "Multiple polymorphic serializers in a scope of 'class kotlin.Any' have the same serial name 'C'"
236+
assertTrue(
237+
ex.message == expected1 || ex.message == expected2,
238+
"Expected exception message to be either:\n'$expected1' or '\n'$expected2' but was: '${ex.message}'"
239+
)
240+
} else {
241+
assertFailsWithMessage<IllegalArgumentException>(
242+
"Multiple polymorphic serializers in a scope of '$classNameMsg' have the same serial name 'C'"
243+
) { c1 + c2 }
244+
}
232245
val module = c1 overwriteWith c2
233246
// C should not be registered at all, C2 should be registered both under "C" and C2::class
234247
assertEquals(C2.serializer(), module.getPolymorphic(Any::class, serializedClassName = "C"))

0 commit comments

Comments
 (0)