From 24d8ac97cd06824814a4965dc60a7c8e9572c5ad Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Tue, 23 Aug 2022 15:00:26 +0200 Subject: [PATCH] [IR][tests] Make ABI compatibility tests less verbose, part 2 --- .../changeFunctionVisibility/main/m.kt | 137 +-------- .../changePropertyVisibility/main/m.kt | 259 ++---------------- .../main/m.kt | 81 +----- .../main/m.kt | 59 +--- .../main/m.kt | 132 +-------- .../main/m.kt | 59 +--- .../main/m.kt | 24 +- .../main/m.kt | 24 +- .../main/m.kt | 24 +- .../main/m.kt | 24 +- .../removeClassAsConstructorCall/main/m.kt | 23 +- .../removeClassAsParameterType/main/m.kt | 36 +-- .../klibABI/removeClassAsReturnType/main/m.kt | 109 +------- .../removeClassAsSuperTypeArgument/main/m.kt | 36 +-- .../removeClassAsTypeArgument/main/m.kt | 36 +-- .../removeClassAsVariableType/main/m.kt | 71 +---- .../testData/klibABI/removeFunction/main/m.kt | 45 +-- .../klibABI/removeInlinedClass/main/m.kt | 91 +----- .../klibABI/removeInlinedFunction/main/m.kt | 22 +- .../klibABI/removeInlinedProperty/main/m.kt | 22 +- .../klibABI/removeOpenFunction/main/m.kt | 6 +- .../klibABI/removeOpenProperty/main/m.kt | 6 +- .../testData/klibABI/removeProperty/main/m.kt | 57 +--- .../klibABI/typeAliasRHSTypeChange/main/m.kt | 32 +-- 24 files changed, 173 insertions(+), 1242 deletions(-) diff --git a/compiler/testData/klibABI/changeFunctionVisibility/main/m.kt b/compiler/testData/klibABI/changeFunctionVisibility/main/m.kt index 9d5a55deffd..e53ac863a77 100644 --- a/compiler/testData/klibABI/changeFunctionVisibility/main/m.kt +++ b/compiler/testData/klibABI/changeFunctionVisibility/main/m.kt @@ -1,127 +1,16 @@ -fun test1(): String { - return try { - publicToInternalFunction() - "OK" - } catch(e: Throwable) { - e.message.orEmpty().ifBlank { "FAIL1" } - } -} +import abitestutils.abiTest -fun test2(): String { - return try { - publicToPrivateFunction() - "FAIL2" - } catch(e: Throwable) { - e.checkLinkageError("function publicToPrivateFunction can not be called") - } -} - -fun test3(): String { +fun box() = abiTest { val c = ContainerImpl() - return try { - c.publicToProtectedFunction() - "OK" - } catch(e: Throwable) { - e.message.orEmpty().ifBlank { "FAIL3" } - } -} - -fun test4(): String { - val c = ContainerImpl() - return try { - c.publicToInternalFunction() - "FAIL4" - } catch(e: Throwable) { - e.checkLinkageError("function publicToInternalFunction can not be called") - } -} - -fun test5(): String { - val c = ContainerImpl() - return try { - c.publicToPrivateFunction() - "FAIL5" - } catch(e: Throwable) { - e.checkLinkageError("function publicToPrivateFunction can not be called") - } -} - -fun test6(): String { - val c = ContainerImpl() - return try { - c.publicToProtectedFunctionAccess() - "OK" - } catch(e: Throwable) { - e.message.orEmpty().ifBlank { "FAIL6" } - } -} - -fun test7(): String { - val c = ContainerImpl() - return try { - c.publicToInternalFunctionAccess() - "FAIL7" - } catch(e: Throwable) { - e.checkLinkageError("function publicToInternalFunction can not be called") - } -} - -fun test8(): String { - val c = ContainerImpl() - return try { - c.publicToPrivateFunctionAccess() - "FAIL8" - } catch(e: Throwable) { - e.checkLinkageError("function publicToPrivateFunction can not be called") - } -} - -fun test9(): String { - val c = ContainerImpl() - return try { - c.protectedToPublicFunctionAccess() - "OK" - } catch(e: Throwable) { - e.message.orEmpty().ifBlank { "FAIL9" } - } -} - -fun test10(): String { - val c = ContainerImpl() - return try { - c.protectedToInternalFunctionAccess() - "FAIL10" - } catch(e: Throwable) { - e.checkLinkageError("function protectedToInternalFunction can not be called") - } -} - -fun test11(): String { - val c = ContainerImpl() - return try { - c.protectedToPrivateFunctionAccess() - "FAIL11" - } catch(e: Throwable) { - e.checkLinkageError("function protectedToPrivateFunction can not be called") - } -} - -fun box() = checkResults(test1(), test2(), test3(), test4(), test5(), test6(), test7(), test8(), test9(), test10(), test11()) - -private fun Throwable.checkLinkageError(prefix: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessagePrefix = "$prefix because it uses unlinked symbols" - val actualMessage = message.orEmpty() - - return if (actualMessage.startsWith(expectedMessagePrefix)) - "OK" - else - "EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") + expectSuccess(42) { publicToInternalFunction() } + expectFailure(prefixed("function publicToPrivateFunction can not be called")) { publicToPrivateFunction() } + expectSuccess(42) { c.publicToProtectedFunction() } + expectFailure(prefixed("function publicToInternalFunction can not be called")) { c.publicToInternalFunction() } + expectFailure(prefixed("function publicToPrivateFunction can not be called")) { c.publicToPrivateFunction() } + expectSuccess(42) { c.publicToProtectedFunctionAccess() } + expectFailure(prefixed("function publicToInternalFunction can not be called")) { c.publicToInternalFunctionAccess() } + expectFailure(prefixed("function publicToPrivateFunction can not be called")) { c.publicToPrivateFunctionAccess() } + expectSuccess(42) { c.protectedToPublicFunctionAccess() } + expectFailure(prefixed("function protectedToInternalFunction can not be called")) { c.protectedToInternalFunctionAccess() } + expectFailure(prefixed("function protectedToPrivateFunction can not be called")) { c.protectedToPrivateFunctionAccess() } } diff --git a/compiler/testData/klibABI/changePropertyVisibility/main/m.kt b/compiler/testData/klibABI/changePropertyVisibility/main/m.kt index 52adee4cb6e..9f9e52468cc 100644 --- a/compiler/testData/klibABI/changePropertyVisibility/main/m.kt +++ b/compiler/testData/klibABI/changePropertyVisibility/main/m.kt @@ -1,238 +1,27 @@ -fun test1(): String { - return try { - publicToInternalProperty1 - "OK" - } catch(e: Throwable) { - e.message.orEmpty().ifBlank { "FAIL1" } - } -} +import abitestutils.abiTest -fun test2(): String { - return try { - publicToInternalProperty2 - "OK" - } catch(e: Throwable) { - e.message.orEmpty().ifBlank { "FAIL2" } - } -} - -fun test3(): String { - return try { - publicToPrivateProperty1 - "FAIL3" - } catch(e: Throwable) { - e.checkLinkageError("property accessor publicToPrivateProperty1. can not be called") - } -} - -fun test4(): String { - return try { - publicToPrivateProperty2 - "FAIL4" - } catch(e: Throwable) { - e.checkLinkageError("property accessor publicToPrivateProperty2. can not be called") - } -} - -fun test5(): String { +fun box() = abiTest { val c = ContainerImpl() - return try { - c.publicToProtectedProperty1 - "OK" - } catch(e: Throwable) { - e.message.orEmpty().ifBlank { "FAIL5" } - } -} - -fun test6(): String { - val c = ContainerImpl() - return try { - c.publicToProtectedProperty2 - "OK" - } catch(e: Throwable) { - e.message.orEmpty().ifBlank { "FAIL6" } - } -} - -fun test7(): String { - val c = ContainerImpl() - return try { - c.publicToInternalProperty1 - "FAIL7" - } catch(e: Throwable) { - e.checkLinkageError("property accessor publicToInternalProperty1. can not be called") - } -} - -fun test8(): String { - val c = ContainerImpl() - return try { - c.publicToInternalProperty2 - "FAIL8" - } catch(e: Throwable) { - e.checkLinkageError("property accessor publicToInternalProperty2. can not be called") - } -} - -fun test9(): String { - val c = ContainerImpl() - return try { - c.publicToPrivateProperty1 - "FAIL9" - } catch(e: Throwable) { - e.checkLinkageError("property accessor publicToPrivateProperty1. can not be called") - } -} - -fun test10(): String { - val c = ContainerImpl() - return try { - c.publicToPrivateProperty2 - "FAIL10" - } catch(e: Throwable) { - e.checkLinkageError("property accessor publicToPrivateProperty2. can not be called") - } -} - -fun test11(): String { - val c = ContainerImpl() - return try { - c.publicToProtectedProperty1Access() - "OK" - } catch(e: Throwable) { - e.message.orEmpty().ifBlank { "FAIL11" } - } -} - -fun test12(): String { - val c = ContainerImpl() - return try { - c.publicToProtectedProperty2Access() - "OK" - } catch(e: Throwable) { - e.message.orEmpty().ifBlank { "FAIL12" } - } -} - -fun test13(): String { - val c = ContainerImpl() - return try { - c.publicToInternalProperty1Access() - "FAIL13" - } catch(e: Throwable) { - e.checkLinkageError("property accessor publicToInternalProperty1. can not be called") - } -} - -fun test14(): String { - val c = ContainerImpl() - return try { - c.publicToInternalProperty2Access() - "FAIL14" - } catch(e: Throwable) { - e.checkLinkageError("property accessor publicToInternalProperty2. can not be called") - } -} - -fun test15(): String { - val c = ContainerImpl() - return try { - c.publicToPrivateProperty1Access() - "FAIL15" - } catch(e: Throwable) { - e.checkLinkageError("property accessor publicToPrivateProperty1. can not be called") - } -} - -fun test16(): String { - val c = ContainerImpl() - return try { - c.publicToPrivateProperty2Access() - "FAIL16" - } catch(e: Throwable) { - e.checkLinkageError("property accessor publicToPrivateProperty2. can not be called") - } -} - -fun test17(): String { - val c = ContainerImpl() - return try { - c.protectedToPublicProperty1Access() - "OK" - } catch(e: Throwable) { - e.message.orEmpty().ifBlank { "FAIL17" } - } -} - -fun test18(): String { - val c = ContainerImpl() - return try { - c.protectedToPublicProperty2Access() - "OK" - } catch(e: Throwable) { - e.message.orEmpty().ifBlank { "FAIL18" } - } -} - -fun test19(): String { - val c = ContainerImpl() - return try { - c.protectedToInternalProperty1Access() - "FAIL19" - } catch(e: Throwable) { - e.checkLinkageError("property accessor protectedToInternalProperty1. can not be called") - } -} - -fun test20(): String { - val c = ContainerImpl() - return try { - c.protectedToInternalProperty2Access() - "FAIL20" - } catch(e: Throwable) { - e.checkLinkageError("property accessor protectedToInternalProperty2. can not be called") - } -} - -fun test21(): String { - val c = ContainerImpl() - return try { - c.protectedToPrivateProperty1Access() - "FAIL21" - } catch(e: Throwable) { - e.checkLinkageError("property accessor protectedToPrivateProperty1. can not be called") - } -} - -fun test22(): String { - val c = ContainerImpl() - return try { - c.protectedToPrivateProperty2Access() - "FAIL22" - } catch(e: Throwable) { - e.checkLinkageError("property accessor protectedToPrivateProperty2. can not be called") - } -} - -fun box() = checkResults( - test1(), test2(), test3(), test4(), test5(), test6(), test7(), test8(), test9(), test10(), - test11(), test12(), test13(), test14(), test15(), test16(), test17(), test18(), test19(), test20(), - test21(), test22()) - -private fun Throwable.checkLinkageError(prefix: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessagePrefix = "$prefix because it uses unlinked symbols" - val actualMessage = message.orEmpty() - - return if (actualMessage.startsWith(expectedMessagePrefix)) - "OK" - else - "EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") + expectSuccess(42) { publicToInternalProperty1 } + expectSuccess(42) { publicToInternalProperty2 } + expectFailure(prefixed("property accessor publicToPrivateProperty1. can not be called")) { publicToPrivateProperty1 } + expectFailure(prefixed("property accessor publicToPrivateProperty2. can not be called")) { publicToPrivateProperty2 } + expectSuccess(42) { c.publicToProtectedProperty1 } + expectSuccess(42) { c.publicToProtectedProperty2 } + expectFailure(prefixed("property accessor publicToInternalProperty1. can not be called")) { c.publicToInternalProperty1 } + expectFailure(prefixed("property accessor publicToInternalProperty2. can not be called")) { c.publicToInternalProperty2 } + expectFailure(prefixed("property accessor publicToPrivateProperty1. can not be called")) { c.publicToPrivateProperty1 } + expectFailure(prefixed("property accessor publicToPrivateProperty2. can not be called")) { c.publicToPrivateProperty2 } + expectSuccess(42) { c.publicToProtectedProperty1Access() } + expectSuccess(42) { c.publicToProtectedProperty2Access() } + expectFailure(prefixed("property accessor publicToInternalProperty1. can not be called")) { c.publicToInternalProperty1Access() } + expectFailure(prefixed("property accessor publicToInternalProperty2. can not be called")) { c.publicToInternalProperty2Access() } + expectFailure(prefixed("property accessor publicToPrivateProperty1. can not be called")) { c.publicToPrivateProperty1Access() } + expectFailure(prefixed("property accessor publicToPrivateProperty2. can not be called")) { c.publicToPrivateProperty2Access() } + expectSuccess(42) { c.protectedToPublicProperty1Access() } + expectSuccess(42) { c.protectedToPublicProperty2Access() } + expectFailure(prefixed("property accessor protectedToInternalProperty1. can not be called")) { c.protectedToInternalProperty1Access() } + expectFailure(prefixed("property accessor protectedToInternalProperty2. can not be called")) { c.protectedToInternalProperty2Access() } + expectFailure(prefixed("property accessor protectedToPrivateProperty1. can not be called")) { c.protectedToPrivateProperty1Access() } + expectFailure(prefixed("property accessor protectedToPrivateProperty2. can not be called")) { c.protectedToPrivateProperty2Access() } } diff --git a/compiler/testData/klibABI/nonAbstractFunctionInAbstractClassBecomesAbstract/main/m.kt b/compiler/testData/klibABI/nonAbstractFunctionInAbstractClassBecomesAbstract/main/m.kt index a97d0bc3a76..d41c6bf963f 100644 --- a/compiler/testData/klibABI/nonAbstractFunctionInAbstractClassBecomesAbstract/main/m.kt +++ b/compiler/testData/klibABI/nonAbstractFunctionInAbstractClassBecomesAbstract/main/m.kt @@ -1,81 +1,16 @@ +import abitestutils.abiTest import lib1.A import lib2.B import lib2.B1 import lib2.B2 -fun test1(): String { +fun box() = abiTest { val a: A = B() - return try { - val answer: Int = a.foo() // <-- should throw linkage error here - println(answer) - "FAIL1" - } catch (e: Throwable) { - e.checkLinkageError("foo", "B") - } -} - -fun test2(): String { - val a: A = B() - return try { - val answer: Int = a.bar() // <-- should throw linkage error here - println(answer) - "FAIL2" - } catch (e: Throwable) { - e.checkLinkageError("bar", "B") - } -} - -fun test3(): String { - val a: A = B() - val baz = a.baz() - return if (baz == -42) "OK" else "baz=$baz" -} - -fun test4(): String { val b = B() - return try { - val answer: Int = b.unlinkedFunctionUsage // <-- should throw linkage error here - println(answer) - "FAIL3" - } catch (e: Throwable) { - e.checkLinkageError("foo", "B") - } -} - -fun test5(): String { - return try { - B1() - "FAIL4" - } catch (e: Throwable) { - e.checkLinkageError("foo", "B1") - } -} - -fun test6(): String { - return try { - B2() - "FAIL5" - } catch (e: Throwable) { - e.checkLinkageError("bar", "B2") - } -} - -fun box(): String = checkResults(test1(), test2(), test3(), test4(), test5(), test6()) - -private fun Throwable.checkLinkageError(symbolName: String, className: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessage = "Abstract function $symbolName is not implemented in non-abstract class $className" - val actualMessage = message.orEmpty() - - return if (expectedMessage == actualMessage) - "OK" - else - "EXPECTED: $expectedMessage, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") + expectFailure(nonImplementedCallable("function foo", "class B")) { a.foo() } + expectFailure(nonImplementedCallable("function bar", "class B")) { a.bar() } + expectSuccess(-42) { a.baz() } + expectFailure(nonImplementedCallable("function foo", "class B")) { b.unlinkedFunctionUsage } + expectFailure(nonImplementedCallable("function foo", "class B1")) { B1() } + expectFailure(nonImplementedCallable("function bar", "class B2")) { B2() } } diff --git a/compiler/testData/klibABI/nonAbstractFunctionInInterfaceBecomesAbstract/main/m.kt b/compiler/testData/klibABI/nonAbstractFunctionInInterfaceBecomesAbstract/main/m.kt index e7891e14279..0c48d857a6e 100644 --- a/compiler/testData/klibABI/nonAbstractFunctionInInterfaceBecomesAbstract/main/m.kt +++ b/compiler/testData/klibABI/nonAbstractFunctionInInterfaceBecomesAbstract/main/m.kt @@ -1,60 +1,13 @@ +import abitestutils.abiTest import lib1.A import lib2.B import lib2.B1 -fun test1(): String { +fun box() = abiTest { val a: A = B() - return try { - val answer: Int = a.foo() // <-- should throw linkage error here - println(answer) - "FAIL1" - } catch(e: Throwable) { - e.checkLinkageError("foo", "B") - } -} - -fun test2(): String { - val a: A = B() - val bar = a.bar() - return if (bar == -42) "OK" else "bar=$bar" -} - -fun test3(): String { val b = B() - return try { - val answer: Int = b.unlinkedFunctionUsage // <-- should throw linkage error here - println(answer) - "FAIL2" - } catch (e: Throwable) { - e.checkLinkageError("foo", "B") - } -} - -fun test4(): String { - return try { - B1() - "FAIL3" - } catch (e: Throwable) { - e.checkLinkageError("foo", "B1") - } -} - -fun box(): String = checkResults(test1(), test2(), test3(), test4()) - -private fun Throwable.checkLinkageError(symbolName: String, className: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessage = "Abstract function $symbolName is not implemented in non-abstract class $className" - val actualMessage = message.orEmpty() - - return if (expectedMessage == actualMessage) - "OK" - else - "EXPECTED: $expectedMessage, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") + expectFailure(nonImplementedCallable("function foo", "class B")) { a.foo() } + expectSuccess(-42) { a.bar() } + expectFailure(nonImplementedCallable("function foo", "class B")) { b.unlinkedFunctionUsage } + expectFailure(nonImplementedCallable("function foo", "class B1")) { B1() } } diff --git a/compiler/testData/klibABI/nonAbstractPropertyInAbstractClassBecomesAbstract/main/m.kt b/compiler/testData/klibABI/nonAbstractPropertyInAbstractClassBecomesAbstract/main/m.kt index 0190f87058b..4f6d2f2d9da 100644 --- a/compiler/testData/klibABI/nonAbstractPropertyInAbstractClassBecomesAbstract/main/m.kt +++ b/compiler/testData/klibABI/nonAbstractPropertyInAbstractClassBecomesAbstract/main/m.kt @@ -1,3 +1,4 @@ +import abitestutils.abiTest import lib1.A import lib2.B import lib2.B1 @@ -5,125 +6,18 @@ import lib2.B2 import lib2.B3 import lib2.B4 -fun test1(): String { +fun box() = abiTest { val a: A = B() - return try { - val answer: Int = a.foo1 // <-- should throw linkage error here - println(answer) - "FAIL1" - } catch(e: Throwable) { - e.checkLinkageError("foo1.", "B") - } -} - -fun test2(): String { - val a: A = B() - return try { - val answer: Int = a.foo2 // <-- should throw linkage error here - println(answer) - "FAIL2" - } catch(e: Throwable) { - e.checkLinkageError("foo2.", "B") - } -} - -fun test3(): String { - val a: A = B() - return try { - val answer: Int = a.bar1 // <-- should throw linkage error here - println(answer) - "FAIL1" - } catch(e: Throwable) { - e.checkLinkageError("bar1.", "B") - } -} - -fun test4(): String { - val a: A = B() - return try { - val answer: Int = a.bar2 // <-- should throw linkage error here - println(answer) - "FAIL2" - } catch(e: Throwable) { - e.checkLinkageError("bar2.", "B") - } -} - -fun test5(): String { - val a: A = B() - val baz1 = a.baz1 - return if (baz1 == -42) "OK" else "baz1=$baz1" -} - -fun test6(): String { - val a: A = B() - val baz2 = a.baz2 - return if (baz2 == -42) "OK" else "baz2=$baz2" -} - -fun test7(): String { val b = B() - return try { - val answer: Int = b.unlinkedPropertyUsage // <-- should throw linkage error here - println(answer) - "FAIL3" - } catch (e: Throwable) { - e.checkLinkageError("foo1.", "B") - } -} - -fun test8(): String { - return try { - B1() - "FAIL4" - } catch (e: Throwable) { - e.checkLinkageError("foo1.", "B1") - } -} - -fun test9(): String { - return try { - B2() - "FAIL5" - } catch (e: Throwable) { - e.checkLinkageError("foo2.", "B2") - } -} - -fun test10(): String { - return try { - B3() - "FAIL6" - } catch (e: Throwable) { - e.checkLinkageError("bar1.", "B3") - } -} - -fun test11(): String { - return try { - B4() - "FAIL7" - } catch (e: Throwable) { - e.checkLinkageError("bar2.", "B4") - } -} - -fun box(): String = checkResults(test1(), test2(), test3(), test4(), test5(), test6(), test7(), test8(), test9(), test10(), test11()) - -private fun Throwable.checkLinkageError(symbolName: String, className: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessage = "Abstract property accessor $symbolName is not implemented in non-abstract class $className" - val actualMessage = message.orEmpty() - - return if (expectedMessage == actualMessage) - "OK" - else - "EXPECTED: $expectedMessage, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") + expectFailure(nonImplementedCallable("property accessor foo1.", "class B")) { a.foo1 } + expectFailure(nonImplementedCallable("property accessor foo2.", "class B")) { a.foo2 } + expectFailure(nonImplementedCallable("property accessor bar1.", "class B")) { a.bar1 } + expectFailure(nonImplementedCallable("property accessor bar2.", "class B")) { a.bar2 } + expectSuccess(-42) { a.baz1 } + expectSuccess(-42) { a.baz2 } + expectFailure(nonImplementedCallable("property accessor foo1.", "class B")) { b.unlinkedPropertyUsage } + expectFailure(nonImplementedCallable("property accessor foo1.", "class B1")) { B1() } + expectFailure(nonImplementedCallable("property accessor foo2.", "class B2")) { B2() } + expectFailure(nonImplementedCallable("property accessor bar1.", "class B3")) { B3() } + expectFailure(nonImplementedCallable("property accessor bar2.", "class B4")) { B4() } } diff --git a/compiler/testData/klibABI/nonAbstractPropertyInInterfaceBecomesAbstract/main/m.kt b/compiler/testData/klibABI/nonAbstractPropertyInInterfaceBecomesAbstract/main/m.kt index 1ae0d0fcd75..fdc20d90b47 100644 --- a/compiler/testData/klibABI/nonAbstractPropertyInInterfaceBecomesAbstract/main/m.kt +++ b/compiler/testData/klibABI/nonAbstractPropertyInInterfaceBecomesAbstract/main/m.kt @@ -1,60 +1,13 @@ +import abitestutils.abiTest import lib1.A import lib2.B import lib2.B1 -fun test1(): String { +fun box() = abiTest { val a: A = B() - return try { - val answer: Int = a.foo // <-- should throw linkage error here - println(answer) - "FAIL" - } catch(e: Throwable) { - e.checkLinkageError("foo.", "B") - } -} - -fun test2(): String { - val a: A = B() - val bar = a.bar - return if (bar == -42) "OK" else "bar=$bar" -} - -fun test3(): String { val b = B() - return try { - val answer: Int = b.unlinkedPropertyUsage // <-- should throw linkage error here - println(answer) - "FAIL2" - } catch (e: Throwable) { - e.checkLinkageError("foo.", "B") - } -} - -fun test4(): String { - return try { - B1() - "FAIL3" - } catch (e: Throwable) { - e.checkLinkageError("foo.", "B1") - } -} - -fun box(): String = checkResults(test1(), test2(), test3(), test4()) - -private fun Throwable.checkLinkageError(symbolName: String, className: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessage = "Abstract property accessor $symbolName is not implemented in non-abstract class $className" - val actualMessage = message.orEmpty() - - return if (expectedMessage == actualMessage) - "OK" - else - "EXPECTED: $expectedMessage, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") + expectFailure(nonImplementedCallable("property accessor foo.", "class B")) { a.foo } + expectSuccess(-42) { a.bar } + expectFailure(nonImplementedCallable("property accessor foo.", "class B")) { b.unlinkedPropertyUsage } + expectFailure(nonImplementedCallable("property accessor foo.", "class B1")) { B1() } } diff --git a/compiler/testData/klibABI/removeAbstractFunctionFromAbstractClass/main/m.kt b/compiler/testData/klibABI/removeAbstractFunctionFromAbstractClass/main/m.kt index 7149c21628b..f500a7be4d8 100644 --- a/compiler/testData/klibABI/removeAbstractFunctionFromAbstractClass/main/m.kt +++ b/compiler/testData/klibABI/removeAbstractFunctionFromAbstractClass/main/m.kt @@ -1,26 +1,8 @@ +import abitestutils.abiTest import lib1.A import lib2.B -fun box(): String { +fun box() = abiTest { val a: A = B() - - return try { - val answer: Int = a.foo() // <-- should throw linkage error here - println(answer) - "FAIL" - } catch (e: Throwable) { - e.checkLinkageError("foo", "B") - } -} - -private fun Throwable.checkLinkageError(symbolName: String, className: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessage = "Abstract function $symbolName is not implemented in non-abstract class $className" - val actualMessage = message.orEmpty() - - return if (expectedMessage == actualMessage) - "OK" - else - "EXPECTED: $expectedMessage, ACTUAL: $actualMessage" + expectFailure(nonImplementedCallable("function foo", "class B")) { a.foo() } } diff --git a/compiler/testData/klibABI/removeAbstractFunctionFromInterface/main/m.kt b/compiler/testData/klibABI/removeAbstractFunctionFromInterface/main/m.kt index 7149c21628b..f500a7be4d8 100644 --- a/compiler/testData/klibABI/removeAbstractFunctionFromInterface/main/m.kt +++ b/compiler/testData/klibABI/removeAbstractFunctionFromInterface/main/m.kt @@ -1,26 +1,8 @@ +import abitestutils.abiTest import lib1.A import lib2.B -fun box(): String { +fun box() = abiTest { val a: A = B() - - return try { - val answer: Int = a.foo() // <-- should throw linkage error here - println(answer) - "FAIL" - } catch (e: Throwable) { - e.checkLinkageError("foo", "B") - } -} - -private fun Throwable.checkLinkageError(symbolName: String, className: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessage = "Abstract function $symbolName is not implemented in non-abstract class $className" - val actualMessage = message.orEmpty() - - return if (expectedMessage == actualMessage) - "OK" - else - "EXPECTED: $expectedMessage, ACTUAL: $actualMessage" + expectFailure(nonImplementedCallable("function foo", "class B")) { a.foo() } } diff --git a/compiler/testData/klibABI/removeAbstractPropertyFromAbstractClass/main/m.kt b/compiler/testData/klibABI/removeAbstractPropertyFromAbstractClass/main/m.kt index e54d2e705ae..812710794ca 100644 --- a/compiler/testData/klibABI/removeAbstractPropertyFromAbstractClass/main/m.kt +++ b/compiler/testData/klibABI/removeAbstractPropertyFromAbstractClass/main/m.kt @@ -1,26 +1,8 @@ +import abitestutils.abiTest import lib1.A import lib2.B -fun box(): String { +fun box() = abiTest { val a: A = B() - - return try { - val answer: Int = a.foo // <-- should throw linkage error here - println(answer) - "FAIL" - } catch (e: Throwable) { - e.checkLinkageError("foo.", "B") - } -} - -private fun Throwable.checkLinkageError(symbolName: String, className: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessage = "Abstract property accessor $symbolName is not implemented in non-abstract class $className" - val actualMessage = message.orEmpty() - - return if (expectedMessage == actualMessage) - "OK" - else - "EXPECTED: $expectedMessage, ACTUAL: $actualMessage" + expectFailure(nonImplementedCallable("property accessor foo.", "class B")) { a.foo } } diff --git a/compiler/testData/klibABI/removeAbstractPropertyFromInterface/main/m.kt b/compiler/testData/klibABI/removeAbstractPropertyFromInterface/main/m.kt index e54d2e705ae..812710794ca 100644 --- a/compiler/testData/klibABI/removeAbstractPropertyFromInterface/main/m.kt +++ b/compiler/testData/klibABI/removeAbstractPropertyFromInterface/main/m.kt @@ -1,26 +1,8 @@ +import abitestutils.abiTest import lib1.A import lib2.B -fun box(): String { +fun box() = abiTest { val a: A = B() - - return try { - val answer: Int = a.foo // <-- should throw linkage error here - println(answer) - "FAIL" - } catch (e: Throwable) { - e.checkLinkageError("foo.", "B") - } -} - -private fun Throwable.checkLinkageError(symbolName: String, className: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessage = "Abstract property accessor $symbolName is not implemented in non-abstract class $className" - val actualMessage = message.orEmpty() - - return if (expectedMessage == actualMessage) - "OK" - else - "EXPECTED: $expectedMessage, ACTUAL: $actualMessage" + expectFailure(nonImplementedCallable("property accessor foo.", "class B")) { a.foo } } diff --git a/compiler/testData/klibABI/removeClassAsConstructorCall/main/m.kt b/compiler/testData/klibABI/removeClassAsConstructorCall/main/m.kt index d4843fbf6eb..a1248590c17 100644 --- a/compiler/testData/klibABI/removeClassAsConstructorCall/main/m.kt +++ b/compiler/testData/klibABI/removeClassAsConstructorCall/main/m.kt @@ -1,20 +1,5 @@ -fun box(): String { - return try { - bar() - "FAIL" - } catch (e: Throwable) { - e.checkLinkageError("constructor Foo. can not be called") - } -} - -private fun Throwable.checkLinkageError(prefix: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessagePrefix = "$prefix because it uses unlinked symbols" - val actualMessage = message.orEmpty() - - return if (actualMessage.startsWith(expectedMessagePrefix)) - "OK" - else - "EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage" +import abitestutils.abiTest + +fun box() = abiTest { + expectFailure(prefixed("constructor Foo. can not be called")) { bar() } } diff --git a/compiler/testData/klibABI/removeClassAsParameterType/main/m.kt b/compiler/testData/klibABI/removeClassAsParameterType/main/m.kt index c97ad7a3651..6966870e118 100644 --- a/compiler/testData/klibABI/removeClassAsParameterType/main/m.kt +++ b/compiler/testData/klibABI/removeClassAsParameterType/main/m.kt @@ -1,31 +1,7 @@ -fun test1(d: D): String { - return try { - d.bar() - } catch(e: Throwable) { - e.checkLinkageError("constructor E. can not be called") - } -} - -fun test2(d: D): String { - return d.foo() -} - -fun box(): String =checkResults(test1(D()), test2(D())) - -private fun Throwable.checkLinkageError(prefix: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessagePrefix = "$prefix because it uses unlinked symbols" - val actualMessage = message.orEmpty() - - return if (actualMessage.startsWith(expectedMessagePrefix)) - "OK" - else - "EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") +import abitestutils.abiTest + +fun box() = abiTest { + val d = D() + expectFailure(prefixed("constructor E. can not be called")) { d.bar() } + expectSuccess { d.foo() } } diff --git a/compiler/testData/klibABI/removeClassAsReturnType/main/m.kt b/compiler/testData/klibABI/removeClassAsReturnType/main/m.kt index c4eafde4e69..cd080c3b30f 100644 --- a/compiler/testData/klibABI/removeClassAsReturnType/main/m.kt +++ b/compiler/testData/klibABI/removeClassAsReturnType/main/m.kt @@ -1,96 +1,15 @@ -fun test1(d: D): String { - return try { - d.barF() - } catch(e: Throwable) { - e.checkLinkageError("function expF can not be called") - } -} - -fun test2(d: D): String { - return d.fooF() -} - -fun test3(d: D): String { - return try { - d.barP1 - } catch(e: Throwable) { - e.checkLinkageError("property accessor expP1. can not be called") - } -} - -fun test4(d: D): String { - return d.fooP1 -} - -fun test5(): String { - return try { - D2().barP2 - } catch(e: Throwable) { - e.checkLinkageError("property accessor expP2. can not be called") - } -} - -fun test6(): String { - return try { - bar() - return "FAIL6" - } catch (e: Throwable) { - e.checkLinkageError("function foo can not be called") - } -} - -fun test7(): String { - return try { - baz() - return "FAIL7" - } catch (e: Throwable) { - e.checkLinkageError("function foo can not be called") - } -} - -fun test8(): String { - return try { - quux() - return "FAIL8" - } catch (e: Throwable) { - e.checkLinkageError("function foo can not be called") - } -} - -fun test9(): String { - return try { - grault() - return "FAIL9" - } catch (e: Throwable) { - e.checkLinkageError("function foo can not be called") - } -} - -fun test10(): String { - return try { - waldo() - return "FAIL10" - } catch (e: Throwable) { - e.checkLinkageError("function foo can not be called") - } -} - -fun box(): String = checkResults(test1(D()), test2(D()), test3(D()), test4(D()), test5(), test6(), test7(), test8(), test9(), test10()) - -private fun Throwable.checkLinkageError(prefix: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessagePrefix = "$prefix because it uses unlinked symbols" - val actualMessage = message.orEmpty() - - return if (actualMessage.startsWith(expectedMessagePrefix)) - "OK" - else - "EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") +import abitestutils.abiTest + +fun box() = abiTest { + val d = D() + expectFailure(prefixed("function expF can not be called")) { d.barF() } + expectSuccess { d.fooF() } + expectFailure(prefixed("property accessor expP1. can not be called")) { d.barP1 } + expectSuccess { d.fooP1 } + expectFailure(prefixed("property accessor expP2. can not be called")) { D2().barP2 } + expectFailure(prefixed("function foo can not be called")) { bar() } + expectFailure(prefixed("function foo can not be called")) { baz() } + expectFailure(prefixed("function foo can not be called")) { quux() } + expectFailure(prefixed("function foo can not be called")) { grault() } + expectFailure(prefixed("function foo can not be called")) { waldo() } } diff --git a/compiler/testData/klibABI/removeClassAsSuperTypeArgument/main/m.kt b/compiler/testData/klibABI/removeClassAsSuperTypeArgument/main/m.kt index d22dc056f30..1d76540b190 100644 --- a/compiler/testData/klibABI/removeClassAsSuperTypeArgument/main/m.kt +++ b/compiler/testData/klibABI/removeClassAsSuperTypeArgument/main/m.kt @@ -1,31 +1,7 @@ -fun test1(d: D): String { - return try { - d.bar() - } catch(e: Throwable) { - e.checkLinkageError("function exp can not be called") - } -} - -fun test2(d: D): String { - return d.foo() -} - -fun box(): String = checkResults(test1(D()), test2(D())) - -private fun Throwable.checkLinkageError(prefix: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessagePrefix = "$prefix because it uses unlinked symbols" - val actualMessage = message.orEmpty() - - return if (actualMessage.startsWith(expectedMessagePrefix)) - "OK" - else - "EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") +import abitestutils.abiTest + +fun box() = abiTest { + val d = D() + expectFailure(prefixed("function exp can not be called")) { d.bar() } + expectSuccess { d.foo() } } diff --git a/compiler/testData/klibABI/removeClassAsTypeArgument/main/m.kt b/compiler/testData/klibABI/removeClassAsTypeArgument/main/m.kt index ec83319d88b..1d76540b190 100644 --- a/compiler/testData/klibABI/removeClassAsTypeArgument/main/m.kt +++ b/compiler/testData/klibABI/removeClassAsTypeArgument/main/m.kt @@ -1,31 +1,7 @@ -fun test1(d: D): String { - return try { - d.bar() - } catch(e: Throwable) { - e.checkLinkageError("function exp can not be called") - } -} - -fun test2(d: D): String { - return d.foo() -} - -fun box(): String =checkResults(test1(D()), test2(D())) - -private fun Throwable.checkLinkageError(prefix: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessagePrefix = "$prefix because it uses unlinked symbols" - val actualMessage = message.orEmpty() - - return if (actualMessage.startsWith(expectedMessagePrefix)) - "OK" - else - "EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") +import abitestutils.abiTest + +fun box() = abiTest { + val d = D() + expectFailure(prefixed("function exp can not be called")) { d.bar() } + expectSuccess { d.foo() } } diff --git a/compiler/testData/klibABI/removeClassAsVariableType/main/m.kt b/compiler/testData/klibABI/removeClassAsVariableType/main/m.kt index 4d03851e69a..2adee529beb 100644 --- a/compiler/testData/klibABI/removeClassAsVariableType/main/m.kt +++ b/compiler/testData/klibABI/removeClassAsVariableType/main/m.kt @@ -1,64 +1,9 @@ -fun test1(): String { - return try { - bar() - return "FAIL1" - } catch (e: Throwable) { - e.checkLinkageError("var foo can not be read") - } -} - -fun test2(): String { - return try { - baz() - return "FAIL2" - } catch (e: Throwable) { - e.checkLinkageError("var foo can not be read") - } -} - -fun test3(): String { - return try { - quux() - return "FAIL3" - } catch (e: Throwable) { - e.checkLinkageError("var foo can not be read") - } -} - -fun test4(): String { - return try { - grault() - return "FAIL4" - } catch (e: Throwable) { - e.checkLinkageError("var foo can not be read") - } -} - -fun test5(): String { - return try { - waldo() - return "FAIL5" - } catch (e: Throwable) { - e.checkLinkageError("var foo can not be read") - } -} - -fun box() = checkResults(test1(), test2(), test3(), test4(), test5()) - -private fun Throwable.checkLinkageError(prefix: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessagePrefix = "$prefix because it uses unlinked symbols" - val actualMessage = message.orEmpty() - - return if (actualMessage.startsWith(expectedMessagePrefix)) - "OK" - else - "EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") +import abitestutils.abiTest + +fun box() = abiTest { + expectFailure(prefixed("var foo can not be read")) { bar() } + expectFailure(prefixed("var foo can not be read")) { baz() } + expectFailure(prefixed("var foo can not be read")) { quux() } + expectFailure(prefixed("var foo can not be read")) { grault() } + expectFailure(prefixed("var foo can not be read")) { waldo() } } diff --git a/compiler/testData/klibABI/removeFunction/main/m.kt b/compiler/testData/klibABI/removeFunction/main/m.kt index ebf2c7a65a2..389aaf93e52 100644 --- a/compiler/testData/klibABI/removeFunction/main/m.kt +++ b/compiler/testData/klibABI/removeFunction/main/m.kt @@ -1,39 +1,8 @@ -fun test1(): String { - return try { - qux(true) - } catch(e: Throwable) { - e.checkLinkageError("function exp_foo can not be called") - } -} - -fun test2(): String = qux(false) - -fun test3(): String { - return try { - qux2(true) - } catch(e: Throwable) { - e.checkLinkageError("function exp_foo can not be called") - } -} - -fun test4(): String = qux2(false) - -fun box() = checkResults(test1(), test2(), test3(), test4()) - -private fun Throwable.checkLinkageError(prefix: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessagePrefix = "$prefix because it uses unlinked symbols" - val actualMessage = message.orEmpty() - - return if (actualMessage.startsWith(expectedMessagePrefix)) - "OK" - else - "EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") +import abitestutils.abiTest + +fun box() = abiTest { + expectFailure(prefixed("function exp_foo can not be called")) { qux(true) } + expectSuccess { qux(false) } + expectFailure(prefixed("function exp_foo can not be called")) { qux2(true) } + expectSuccess { qux2(false) } } diff --git a/compiler/testData/klibABI/removeInlinedClass/main/m.kt b/compiler/testData/klibABI/removeInlinedClass/main/m.kt index a23556907f1..3137e4bbb30 100644 --- a/compiler/testData/klibABI/removeInlinedClass/main/m.kt +++ b/compiler/testData/klibABI/removeInlinedClass/main/m.kt @@ -1,82 +1,11 @@ -fun test1(): String { - return try { - fooVariableType() - "FAIL1" - } catch (e: Throwable) { - e.checkLinkageError("val foo can not be read") - } -} - -fun test2(): String { - return try { - barVariableType() - "FAIL2" - } catch (e: Throwable) { - e.checkLinkageError("val bar can not be read") - } -} - -fun test3(): String { - return try { - fooInstance() - "FAIL3" - } catch (e: Throwable) { - e.checkLinkageError("constructor Foo. can not be called") - } -} - -fun test4(): String { - return try { - barInstance() - "FAIL4" - } catch (e: Throwable) { - e.checkLinkageError("constructor Bar. can not be called") - } -} - -fun test5(): String { - return try { - fooInstance2() - "FAIL5" - } catch (e: Throwable) { - e.checkLinkageError("reference to constructor Foo. can not be evaluated") - } -} - -fun test6(): String { - return try { - barInstance2() - "FAIL6" - } catch (e: Throwable) { - e.checkLinkageError("reference to constructor Bar. can not be evaluated") - } -} - -fun test7(): String { - return try { - fooAnonymousObject() - "FAIL7" - } catch (e: Throwable) { - e.checkLinkageError("val foo can not be read") - } -} - -fun box(): String = checkResults(test1(), test2(), test3(), test4(), test5(), test6(), test7()) - -private fun Throwable.checkLinkageError(prefix: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessagePrefix = "$prefix because it uses unlinked symbols" - val actualMessage = message.orEmpty() - - return if (actualMessage.startsWith(expectedMessagePrefix)) - "OK" - else - "EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") +import abitestutils.abiTest + +fun box() = abiTest { + expectFailure(prefixed("val foo can not be read")) { fooVariableType() } + expectFailure(prefixed("val bar can not be read")) { barVariableType() } + expectFailure(prefixed("constructor Foo. can not be called")) { fooInstance() } + expectFailure(prefixed("constructor Bar. can not be called")) { barInstance() } + expectFailure(prefixed("reference to constructor Foo. can not be evaluated")) { fooInstance2() } + expectFailure(prefixed("reference to constructor Bar. can not be evaluated")) { barInstance2() } + expectFailure(prefixed("val foo can not be read")) { fooAnonymousObject() } } diff --git a/compiler/testData/klibABI/removeInlinedFunction/main/m.kt b/compiler/testData/klibABI/removeInlinedFunction/main/m.kt index be5aa01a8a7..ae98e974808 100644 --- a/compiler/testData/klibABI/removeInlinedFunction/main/m.kt +++ b/compiler/testData/klibABI/removeInlinedFunction/main/m.kt @@ -1,19 +1,5 @@ -fun box(): String { - return try { - bar() - } catch(e: Throwable) { - e.checkLinkageError("function foo can not be called") - } -} - -private fun Throwable.checkLinkageError(prefix: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessagePrefix = "$prefix because it uses unlinked symbols" - val actualMessage = message.orEmpty() - - return if (actualMessage.startsWith(expectedMessagePrefix)) - "OK" - else - "EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage" +import abitestutils.abiTest + +fun box() = abiTest { + expectFailure(prefixed("function foo can not be called")) { bar() } } diff --git a/compiler/testData/klibABI/removeInlinedProperty/main/m.kt b/compiler/testData/klibABI/removeInlinedProperty/main/m.kt index 5f139e7bc9f..8f0b4b03e77 100644 --- a/compiler/testData/klibABI/removeInlinedProperty/main/m.kt +++ b/compiler/testData/klibABI/removeInlinedProperty/main/m.kt @@ -1,19 +1,5 @@ -fun box(): String { - return try { - bar() - } catch(e: Throwable) { - e.checkLinkageError("property accessor foo. can not be called") - } -} - -private fun Throwable.checkLinkageError(prefix: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessagePrefix = "$prefix because it uses unlinked symbols" - val actualMessage = message.orEmpty() - - return if (actualMessage.startsWith(expectedMessagePrefix)) - "OK" - else - "EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage" +import abitestutils.abiTest + +fun box() = abiTest { + expectFailure(prefixed("property accessor foo. can not be called")) { bar() } } diff --git a/compiler/testData/klibABI/removeOpenFunction/main/m.kt b/compiler/testData/klibABI/removeOpenFunction/main/m.kt index b26094fba69..4471e1e6869 100644 --- a/compiler/testData/klibABI/removeOpenFunction/main/m.kt +++ b/compiler/testData/klibABI/removeOpenFunction/main/m.kt @@ -1,3 +1,5 @@ -fun box(): String { - return C2().foo() + I2().foo() +import abitestutils.abiTest + +fun box() = abiTest { + expectSuccess { C2().foo() + I2().foo() } } diff --git a/compiler/testData/klibABI/removeOpenProperty/main/m.kt b/compiler/testData/klibABI/removeOpenProperty/main/m.kt index a45c1e03295..4f5bd8cbb4b 100644 --- a/compiler/testData/klibABI/removeOpenProperty/main/m.kt +++ b/compiler/testData/klibABI/removeOpenProperty/main/m.kt @@ -1,3 +1,5 @@ -fun box(): String { - return C2().foo + I2().foo +import abitestutils.abiTest + +fun box() = abiTest { + expectSuccess { C2().foo + I2().foo } } diff --git a/compiler/testData/klibABI/removeProperty/main/m.kt b/compiler/testData/klibABI/removeProperty/main/m.kt index 3fd5af0dc54..357a498f53f 100644 --- a/compiler/testData/klibABI/removeProperty/main/m.kt +++ b/compiler/testData/klibABI/removeProperty/main/m.kt @@ -1,49 +1,10 @@ -fun test1(): String { - return try { - qux(true) - } catch(e: Throwable) { - e.checkLinkageError("property accessor exp_foo. can not be called") - } -} - -fun test2(): String = qux(false) - -fun test3(): String { - return try { - qux2(true) - } catch(e: Throwable) { - e.checkLinkageError("property accessor exp_foo. can not be called") - } -} - -fun test4(): String = qux2(false) - -fun test5(): String { - return try { - return qux3(true) - } catch(e: Throwable) { - e.checkLinkageError("property accessor exp_foo. can not be called") - } -} - -fun test6(): String = qux3(false) - -fun box(): String = checkResults(test1(), test2(), test3(), test4(), test5(), test6()) - -private fun Throwable.checkLinkageError(prefix: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessagePrefix = "$prefix because it uses unlinked symbols" - val actualMessage = message.orEmpty() - - return if (actualMessage.startsWith(expectedMessagePrefix)) - "OK" - else - "EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") +import abitestutils.abiTest + +fun box() = abiTest { + expectFailure(prefixed("property accessor exp_foo. can not be called")) { qux(true) } + expectSuccess { qux(false) } + expectFailure(prefixed("property accessor exp_foo. can not be called")) { qux2(true) } + expectSuccess { qux2(false) } + expectFailure(prefixed("property accessor exp_foo. can not be called")) { qux3(true) } + expectSuccess { qux3(false) } } diff --git a/compiler/testData/klibABI/typeAliasRHSTypeChange/main/m.kt b/compiler/testData/klibABI/typeAliasRHSTypeChange/main/m.kt index c13c748bbc8..aaeb19b5e3d 100644 --- a/compiler/testData/klibABI/typeAliasRHSTypeChange/main/m.kt +++ b/compiler/testData/klibABI/typeAliasRHSTypeChange/main/m.kt @@ -1,28 +1,6 @@ -fun test1() = try { - callFoo() - "FAIL" -} catch (e: Throwable) { - e.checkLinkageError("function foo can not be called") -} - -fun test2() = bar() - -fun box(): String = checkResults(test1(), test2()) - -private fun Throwable.checkLinkageError(prefix: String): String { - if (this::class.simpleName != "IrLinkageError") return "Unexpected throwable: ${this::class}" - - val expectedMessagePrefix = "$prefix because it uses unlinked symbols" - val actualMessage = message.orEmpty() - - return if (actualMessage.startsWith(expectedMessagePrefix)) - "OK" - else - "EXPECTED: $expectedMessagePrefix, ACTUAL: $actualMessage" -} - -private fun checkResults(vararg results: String): String = when { - results.isEmpty() -> "no results to check" - results.all { it == "OK" } -> "OK" - else -> results.joinToString("\n") +import abitestutils.abiTest + +fun box() = abiTest { + expectFailure(prefixed("function foo can not be called")) { callFoo() } + expectSuccess { bar() } }