From b4189d9e85d468235d3044820671c70403450da3 Mon Sep 17 00:00:00 2001 From: Ilmir Usmanov Date: Mon, 6 Aug 2018 17:11:32 +0300 Subject: [PATCH] Minor. Use more granular assertion levels in assertion tests --- .../box/assert/jvm/interfaceAssertionsDisabled.kt | 8 ++++---- .../box/assert/jvm/interfaceAssertionsEnabled.kt | 6 ++++-- .../box/assert/jvm/localAnonymousFunction.kt | 6 ++++-- .../testData/codegen/box/assert/jvm/localClass.kt | 6 ++++-- .../codegen/box/assert/jvm/localFunction.kt | 6 ++++-- .../testData/codegen/box/assert/jvm/localLambda.kt | 6 ++++-- .../testData/codegen/box/assert/jvm/localObject.kt | 6 ++++-- .../codegen/box/assert/jvm/nonLocalReturn.kt | 6 ++++-- .../testData/codegen/box/assert/jvm/ordinary.kt | 6 ++++-- .../box/assert/jvm/superClassInitializer.kt | 6 ++++-- .../assert/jvm/suspendFunctionAssertionDisabled.kt | 6 ++++-- .../assert/jvm/suspendFunctionAssertionsEnabled.kt | 6 ++++-- .../assert/jvm/suspendLambdaAssertionsDisabled.kt | 6 ++++-- .../assert/jvm/suspendLambdaAssertionsEnabled.kt | 6 ++++-- .../jvmAssertInlineFunctionAssertionsDisabled.kt | 14 ++++++++------ .../jvmAssertInlineFunctionAssertionsEnabled.kt | 13 ++++++------- .../boxInline/assert/jvmAssertInlineLambda.kt | 4 ++-- .../boxInline/assert/jvmCrossinlineLambda.kt | 3 ++- 18 files changed, 74 insertions(+), 46 deletions(-) diff --git a/compiler/testData/codegen/box/assert/jvm/interfaceAssertionsDisabled.kt b/compiler/testData/codegen/box/assert/jvm/interfaceAssertionsDisabled.kt index 8d29590f17c..2df13c6a799 100644 --- a/compiler/testData/codegen/box/assert/jvm/interfaceAssertionsDisabled.kt +++ b/compiler/testData/codegen/box/assert/jvm/interfaceAssertionsDisabled.kt @@ -4,6 +4,8 @@ // KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm // WITH_RUNTIME +package interfaceAssertionsDisabled + interface Checker { fun checkTrue(): Boolean { var hit = false @@ -40,9 +42,8 @@ class Dummy fun disableAssertions(): Checker { val loader = Dummy::class.java.classLoader - loader.setDefaultAssertionStatus(false) - val c = loader.loadClass("ShouldBeDisabled") - return c.newInstance() as Checker + loader.setPackageAssertionStatus("interfaceAssertionsDisabled", false) + return loader.loadClass("interfaceAssertionsDisabled.ShouldBeDisabled").newInstance() as Checker } fun box(): String { @@ -51,6 +52,5 @@ fun box(): String { if (c.checkTrueWithMessage()) return "FAIL 1" if (c.checkFalse()) return "FAIL 2" if (c.checkFalseWithMessage()) return "FAIL 3" - return "OK" } diff --git a/compiler/testData/codegen/box/assert/jvm/interfaceAssertionsEnabled.kt b/compiler/testData/codegen/box/assert/jvm/interfaceAssertionsEnabled.kt index a4493034f02..9cd9a6026a2 100644 --- a/compiler/testData/codegen/box/assert/jvm/interfaceAssertionsEnabled.kt +++ b/compiler/testData/codegen/box/assert/jvm/interfaceAssertionsEnabled.kt @@ -3,6 +3,8 @@ // KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm // WITH_RUNTIME +package interfaceAssertionsEnabled + interface Checker { fun checkTrue(): Boolean { var hit = false @@ -39,8 +41,8 @@ class Dummy fun enableAssertions(): Checker { val loader = Dummy::class.java.classLoader - loader.setDefaultAssertionStatus(true) - val c = loader.loadClass("ShouldBeEnabled") + loader.setPackageAssertionStatus("interfaceAssertionsEnabled", true) + val c = loader.loadClass("interfaceAssertionsEnabled.ShouldBeEnabled") return c.newInstance() as Checker } diff --git a/compiler/testData/codegen/box/assert/jvm/localAnonymousFunction.kt b/compiler/testData/codegen/box/assert/jvm/localAnonymousFunction.kt index 689d2526801..ee0f3c96649 100644 --- a/compiler/testData/codegen/box/assert/jvm/localAnonymousFunction.kt +++ b/compiler/testData/codegen/box/assert/jvm/localAnonymousFunction.kt @@ -4,6 +4,8 @@ // KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm // WITH_RUNTIME +package localAnonymousFunction + interface Checker { fun checkTrue(): Boolean fun checkFalse(): Boolean @@ -97,8 +99,8 @@ class ShouldBeEnabled : Checker { fun setDesiredAssertionStatus(v: Boolean): Checker { val loader = Checker::class.java.classLoader - loader.setDefaultAssertionStatus(v) - val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + loader.setPackageAssertionStatus("localAnonymousFunction", v) + val c = loader.loadClass(if (v) "localAnonymousFunction.ShouldBeEnabled" else "localAnonymousFunction.ShouldBeDisabled") return c.newInstance() as Checker } diff --git a/compiler/testData/codegen/box/assert/jvm/localClass.kt b/compiler/testData/codegen/box/assert/jvm/localClass.kt index 7887b489e98..82f5e4e55eb 100644 --- a/compiler/testData/codegen/box/assert/jvm/localClass.kt +++ b/compiler/testData/codegen/box/assert/jvm/localClass.kt @@ -4,6 +4,8 @@ // KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm // WITH_RUNTIME +package localClass + interface Checker { fun checkTrue(): Boolean fun checkFalse(): Boolean @@ -137,8 +139,8 @@ class ShouldBeEnabled : Checker { fun setDesiredAssertionStatus(v: Boolean): Checker { val loader = Checker::class.java.classLoader - loader.setDefaultAssertionStatus(v) - val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + loader.setPackageAssertionStatus("localClass", v) + val c = loader.loadClass(if (v) "localClass.ShouldBeEnabled" else "localClass.ShouldBeDisabled") return c.newInstance() as Checker } diff --git a/compiler/testData/codegen/box/assert/jvm/localFunction.kt b/compiler/testData/codegen/box/assert/jvm/localFunction.kt index bba44f83c75..604daab1e33 100644 --- a/compiler/testData/codegen/box/assert/jvm/localFunction.kt +++ b/compiler/testData/codegen/box/assert/jvm/localFunction.kt @@ -4,6 +4,8 @@ // KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm // WITH_RUNTIME +package localFunction + interface Checker { fun checkTrue(): Boolean fun checkFalse(): Boolean @@ -97,8 +99,8 @@ class ShouldBeEnabled : Checker { fun setDesiredAssertionStatus(v: Boolean): Checker { val loader = Checker::class.java.classLoader - loader.setDefaultAssertionStatus(v) - val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + loader.setPackageAssertionStatus("localFunction", v) + val c = loader.loadClass(if (v) "localFunction.ShouldBeEnabled" else "localFunction.ShouldBeDisabled") return c.newInstance() as Checker } diff --git a/compiler/testData/codegen/box/assert/jvm/localLambda.kt b/compiler/testData/codegen/box/assert/jvm/localLambda.kt index 38bfd53a9bb..771837bc0d5 100644 --- a/compiler/testData/codegen/box/assert/jvm/localLambda.kt +++ b/compiler/testData/codegen/box/assert/jvm/localLambda.kt @@ -4,6 +4,8 @@ // KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm // WITH_RUNTIME +package localLambda + interface Checker { fun checkTrue(): Boolean fun checkFalse(): Boolean @@ -97,8 +99,8 @@ class ShouldBeEnabled : Checker { fun setDesiredAssertionStatus(v: Boolean): Checker { val loader = Checker::class.java.classLoader - loader.setDefaultAssertionStatus(v) - val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + loader.setPackageAssertionStatus("localLambda", v) + val c = loader.loadClass(if (v) "localLambda.ShouldBeEnabled" else "localLambda.ShouldBeDisabled") return c.newInstance() as Checker } diff --git a/compiler/testData/codegen/box/assert/jvm/localObject.kt b/compiler/testData/codegen/box/assert/jvm/localObject.kt index 2e3cc942747..e5358773120 100644 --- a/compiler/testData/codegen/box/assert/jvm/localObject.kt +++ b/compiler/testData/codegen/box/assert/jvm/localObject.kt @@ -4,6 +4,8 @@ // KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm // WITH_RUNTIME +package localObject + interface Checker { fun checkTrue(): Boolean fun checkFalse(): Boolean @@ -129,8 +131,8 @@ class ShouldBeEnabled : Checker { fun setDesiredAssertionStatus(v: Boolean): Checker { val loader = Checker::class.java.classLoader - loader.setDefaultAssertionStatus(v) - val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + loader.setPackageAssertionStatus("localObject", v) + val c = loader.loadClass(if (v) "localObject.ShouldBeEnabled" else "localObject.ShouldBeDisabled") return c.newInstance() as Checker } diff --git a/compiler/testData/codegen/box/assert/jvm/nonLocalReturn.kt b/compiler/testData/codegen/box/assert/jvm/nonLocalReturn.kt index 08e4025b675..5e4d72d5de0 100644 --- a/compiler/testData/codegen/box/assert/jvm/nonLocalReturn.kt +++ b/compiler/testData/codegen/box/assert/jvm/nonLocalReturn.kt @@ -4,6 +4,8 @@ // KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm // WITH_RUNTIME +package nonLocalReturn + interface Checker { fun checkTrueWithMessage(): Boolean fun checkFalseWithMessage(): Boolean @@ -60,8 +62,8 @@ class ShouldBeEnabled : Checker { fun setDesiredAssertionStatus(v: Boolean): Checker { val loader = Checker::class.java.classLoader - loader.setDefaultAssertionStatus(v) - val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + loader.setPackageAssertionStatus("nonLocalReturn", v) + val c = loader.loadClass(if (v) "nonLocalReturn.ShouldBeEnabled" else "nonLocalReturn.ShouldBeDisabled") return c.newInstance() as Checker } diff --git a/compiler/testData/codegen/box/assert/jvm/ordinary.kt b/compiler/testData/codegen/box/assert/jvm/ordinary.kt index 4dbd751d3aa..2ef4a0dba1c 100644 --- a/compiler/testData/codegen/box/assert/jvm/ordinary.kt +++ b/compiler/testData/codegen/box/assert/jvm/ordinary.kt @@ -4,6 +4,8 @@ // KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm // WITH_RUNTIME +package ordinary + interface Checker { fun checkTrue(): Boolean fun checkFalse(): Boolean @@ -73,8 +75,8 @@ class ShouldBeEnabled: Checker { fun setDesiredAssertionStatus(v: Boolean): Checker { val loader = Checker::class.java.classLoader - loader.setDefaultAssertionStatus(v) - val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + loader.setPackageAssertionStatus("ordinary", v) + val c = loader.loadClass(if (v) "ordinary.ShouldBeEnabled" else "ordinary.ShouldBeDisabled") return c.newInstance() as Checker } diff --git a/compiler/testData/codegen/box/assert/jvm/superClassInitializer.kt b/compiler/testData/codegen/box/assert/jvm/superClassInitializer.kt index 08c12be3f95..390aab68c85 100644 --- a/compiler/testData/codegen/box/assert/jvm/superClassInitializer.kt +++ b/compiler/testData/codegen/box/assert/jvm/superClassInitializer.kt @@ -4,6 +4,8 @@ // KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm // WITH_RUNTIME +package superClassInitializer + interface Checker { fun checkTrue(): Boolean fun checkFalse(): Boolean @@ -91,8 +93,8 @@ class ShouldBeEnabled : Checker { fun setDesiredAssertionStatus(v: Boolean): Checker { val loader = Checker::class.java.classLoader - loader.setDefaultAssertionStatus(v) - val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + loader.setPackageAssertionStatus("superClassInitializer", v) + val c = loader.loadClass(if (v) "superClassInitializer.ShouldBeEnabled" else "superClassInitializer.ShouldBeDisabled") return c.newInstance() as Checker } diff --git a/compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt b/compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt index 330509d4041..72e90552488 100644 --- a/compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt +++ b/compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt @@ -5,6 +5,8 @@ // WITH_COROUTINES // COMMON_COROUTINES_TEST +package suspendFunctionAssertionDisabled + import helpers.* import COROUTINES_PACKAGE.* @@ -18,8 +20,8 @@ class Dummy fun disableAssertions(): Checker { val loader = Dummy::class.java.classLoader - loader.setDefaultAssertionStatus(false) - val c = loader.loadClass("Checker") + loader.setPackageAssertionStatus("suspendFunctionAssertionDisabled", false) + val c = loader.loadClass("suspendFunctionAssertionDisabled.Checker") return c.newInstance() as Checker } diff --git a/compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt b/compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt index 7c73f5f1756..5957a0a33c4 100644 --- a/compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt +++ b/compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt @@ -5,6 +5,8 @@ // WITH_COROUTINES // COMMON_COROUTINES_TEST +package suspendFunctionAssertionsEnabled + import helpers.* import COROUTINES_PACKAGE.* @@ -18,8 +20,8 @@ class Dummy fun enableAssertions(): Checker { val loader = Dummy::class.java.classLoader - loader.setDefaultAssertionStatus(true) - val c = loader.loadClass("Checker") + loader.setPackageAssertionStatus("suspendFunctionAssertionsEnabled", true) + val c = loader.loadClass("suspendFunctionAssertionsEnabled.Checker") return c.newInstance() as Checker } diff --git a/compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt b/compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt index 15cbcae646d..0238eb1442d 100644 --- a/compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt +++ b/compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt @@ -5,6 +5,8 @@ // WITH_COROUTINES // COMMON_COROUTINES_TEST +package suspendLambdaAssertionsDisabled + import helpers.* import COROUTINES_PACKAGE.* @@ -18,8 +20,8 @@ class Dummy fun disableAssertions(): Checker { val loader = Dummy::class.java.classLoader - loader.setDefaultAssertionStatus(false) - val c = loader.loadClass("Checker") + loader.setPackageAssertionStatus("suspendLambdaAssertionsDisabled", false) + val c = loader.loadClass("suspendLambdaAssertionsDisabled.Checker") return c.newInstance() as Checker } diff --git a/compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt b/compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt index d3b8b3c27e2..1a32c2814bd 100644 --- a/compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt +++ b/compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt @@ -5,6 +5,8 @@ // WITH_COROUTINES // COMMON_COROUTINES_TEST +package suspendLambdaAssertionsEnabled + import helpers.* import COROUTINES_PACKAGE.* @@ -18,8 +20,8 @@ class Dummy fun enableAssertions(): Checker { val loader = Dummy::class.java.classLoader - loader.setDefaultAssertionStatus(true) - val c = loader.loadClass("Checker") + loader.setPackageAssertionStatus("suspendLambdaAssertionsEnabled", true) + val c = loader.loadClass("suspendLambdaAssertionsEnabled.Checker") return c.newInstance() as Checker } diff --git a/compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsDisabled.kt b/compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsDisabled.kt index 1ba6976e652..bebb1a71f12 100644 --- a/compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsDisabled.kt +++ b/compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsDisabled.kt @@ -1,6 +1,8 @@ // FILE: inline.kt // KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm // WITH_RUNTIME +// FULL_JDK +// IGNORE_BACKEND: JVM_IR inline fun inlineMe() { assert(false) { "FROM INLINED" } @@ -9,7 +11,7 @@ inline fun inlineMe() { // FILE: inlineSite.kt // KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm -class Checker { +class CheckerJvmAssertInlineFunctionAssertionsDisabled { fun check() { inlineMe() assert(false) { "FROM INLINESITE" } @@ -18,16 +20,16 @@ class Checker { class Dummy -fun disableAssertions(): Checker { +fun disableAssertions(): CheckerJvmAssertInlineFunctionAssertionsDisabled { val loader = Dummy::class.java.classLoader - loader.setDefaultAssertionStatus(false) - val c = loader.loadClass("Checker") - return c.newInstance() as Checker + loader.setClassAssertionStatus("CheckerJvmAssertInlineFunctionAssertionsDisabled", false) + loader.setClassAssertionStatus("InlineKt", false) + val c = loader.loadClass("CheckerJvmAssertInlineFunctionAssertionsDisabled") + return c.newInstance() as CheckerJvmAssertInlineFunctionAssertionsDisabled } fun box(): String { var c = disableAssertions() c.check() - return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsEnabled.kt b/compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsEnabled.kt index d5fc1c72a26..b970dd206c4 100644 --- a/compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsEnabled.kt +++ b/compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsEnabled.kt @@ -1,7 +1,7 @@ -// IGNORE_BACKEND: JVM_IR // FILE: inline.kt // KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm // WITH_RUNTIME +// FULL_JDK inline fun inlineMe() { assert(false) { "FROM INLINED" } @@ -10,7 +10,7 @@ inline fun inlineMe() { // FILE: inlineSite.kt // KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm -class Checker { +class CheckerJvmAssertInlineFunctionAssertionsEnabled { fun check() { inlineMe() throw RuntimeException("FAIL 0") @@ -19,11 +19,11 @@ class Checker { class Dummy -fun enableAssertions(): Checker { +fun enableAssertions(): CheckerJvmAssertInlineFunctionAssertionsEnabled { val loader = Dummy::class.java.classLoader - loader.setDefaultAssertionStatus(true) - val c = loader.loadClass("Checker") - return c.newInstance() as Checker + loader.setClassAssertionStatus("CheckerJvmAssertInlineFunctionAssertionsEnabled", true) + val c = loader.loadClass("CheckerJvmAssertInlineFunctionAssertionsEnabled") + return c.newInstance() as CheckerJvmAssertInlineFunctionAssertionsEnabled } fun box(): String { @@ -32,6 +32,5 @@ fun box(): String { c.check() return "FAIL 2" } catch (ignore: AssertionError) {} - return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/assert/jvmAssertInlineLambda.kt b/compiler/testData/codegen/boxInline/assert/jvmAssertInlineLambda.kt index a4ab1360eb1..cd1d18e0ca9 100644 --- a/compiler/testData/codegen/boxInline/assert/jvmAssertInlineLambda.kt +++ b/compiler/testData/codegen/boxInline/assert/jvmAssertInlineLambda.kt @@ -96,7 +96,8 @@ class ShouldBeEnabled : Checker { fun setDesiredAssertionStatus(v: Boolean): Checker { val loader = Checker::class.java.classLoader - loader.setDefaultAssertionStatus(v) + loader.setClassAssertionStatus("ShouldBeEnabled", true) + loader.setClassAssertionStatus("ShouldBeDisabled", false) val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") return c.newInstance() as Checker } @@ -120,6 +121,5 @@ fun box(): String { return "FAIL 7" } catch (ignore: AssertionError) { } - return "OK" } \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/assert/jvmCrossinlineLambda.kt b/compiler/testData/codegen/boxInline/assert/jvmCrossinlineLambda.kt index 30d0e285d92..bc7a1841cba 100644 --- a/compiler/testData/codegen/boxInline/assert/jvmCrossinlineLambda.kt +++ b/compiler/testData/codegen/boxInline/assert/jvmCrossinlineLambda.kt @@ -97,7 +97,8 @@ class ShouldBeEnabled : Checker { fun setDesiredAssertionStatus(v: Boolean): Checker { val loader = Checker::class.java.classLoader - loader.setDefaultAssertionStatus(v) + loader.setClassAssertionStatus("ShouldBeEnabled", true) + loader.setClassAssertionStatus("ShouldBeDisabled", false) val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") return c.newInstance() as Checker }