From 0be542fd339c21b5bf1487e488453257e1b20927 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Thu, 20 May 2021 17:38:01 +0300 Subject: [PATCH] [Native] Always enable assertions in KonanLocalTest --- kotlin-native/backend.native/tests/build.gradle | 8 +++++++- .../assertions_enabled_for_local_tests.kt | 17 +++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 kotlin-native/backend.native/tests/sanity/assertions_enabled_for_local_tests.kt diff --git a/kotlin-native/backend.native/tests/build.gradle b/kotlin-native/backend.native/tests/build.gradle index dc91b25dd13..c6e648625f6 100644 --- a/kotlin-native/backend.native/tests/build.gradle +++ b/kotlin-native/backend.native/tests/build.gradle @@ -1667,6 +1667,10 @@ task lateinit_innerIsInitialized(type: KonanLocalTest) { source = "codegen/lateinit/innerIsInitialized.kt" } +task sanity_assertions_enabled_for_local_tests(type: KonanLocalTest) { + source = "sanity/assertions_enabled_for_local_tests.kt" +} + task kclass0(type: KonanLocalTest) { source = "codegen/kclass/kclass0.kt" } @@ -5215,7 +5219,7 @@ private void configureStdlibTest(KonanGTest task, boolean inWorker) { * Builds tests into a single binary with TestRunner */ task buildKonanTests { t -> - def compileList = [ "codegen", "datagen", "lower", "runtime", "serialization" ] + def compileList = [ "codegen", "datagen", "lower", "runtime", "serialization", "sanity" ] // These tests should not be built into the TestRunner's test executable def excludeList = [ "codegen/inline/returnLocalClassFromBlock.kt" ] @@ -5236,6 +5240,8 @@ task buildKonanTests { t -> program('localTest', targets: [target.name]) { srcFiles sources baseDir testOutputLocal + extraOpts '-ea' // Without this option assertions would remain inactive. + extraOpts '-g' // To include line numbers in stack trace. extraOpts '-tr' extraOpts '-Xverify-ir' extraOpts project.globalTestArgs diff --git a/kotlin-native/backend.native/tests/sanity/assertions_enabled_for_local_tests.kt b/kotlin-native/backend.native/tests/sanity/assertions_enabled_for_local_tests.kt new file mode 100644 index 00000000000..12620a5fc42 --- /dev/null +++ b/kotlin-native/backend.native/tests/sanity/assertions_enabled_for_local_tests.kt @@ -0,0 +1,17 @@ +package sanity.assertions_enabled + +import kotlin.test.Test + +// Just to make sure that assertions are enabled for `KonanLocalTest`s. +@Test fun runTest() { + main(emptyArray()) +} + +fun main(args: Array) { + try { + assert(false) // Should throw AssertionError. + throw Error("Assertions are disabled. Please make sure the tests were compiled with '-ea' option.") // Normally unreachable line. + } catch (e: AssertionError) { + // That's OK. + } +}