diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AssertCodegenUtil.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/AssertCodegenUtil.kt new file mode 100644 index 00000000000..d1dc3abe934 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AssertCodegenUtil.kt @@ -0,0 +1,172 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.codegen + +import org.jetbrains.kotlin.codegen.coroutines.createCustomCopy +import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper +import org.jetbrains.kotlin.config.JVMAssertionsMode +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.resolve.BindingTraceContext +import org.jetbrains.kotlin.resolve.DelegatingBindingTrace +import org.jetbrains.kotlin.resolve.calls.model.MutableDataFlowInfoForArguments +import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall +import org.jetbrains.kotlin.resolve.calls.model.ResolvedCallImpl +import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo +import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy +import org.jetbrains.kotlin.resolve.jvm.AsmTypes +import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin +import org.jetbrains.org.objectweb.asm.Label +import org.jetbrains.org.objectweb.asm.Opcodes +import org.jetbrains.org.objectweb.asm.Type +import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter +import org.jetbrains.org.objectweb.asm.tree.MethodNode + +val assertionsDisabledFieldName = "\$assertionsDisabled" +private const val ALWAYS_ENABLED_ASSERT_FUNCTION_NAME = "alwaysEnabledAssert" +private const val LAMBDA_INTERNAL_NAME = "kotlin/jvm/functions/Function0" +private const val ASSERTION_ERROR_INTERNAL_NAME = "java/lang/AssertionError" +private const val THROWABLE_INTERNAL_NAME = "java/lang/Throwable" + +fun isAssertCall(resolvedCall: ResolvedCall<*>) = resolvedCall.resultingDescriptor.isTopLevelInPackage("assert", "kotlin") + +private fun FunctionDescriptor.isBuiltinAlwaysEnabledAssertWithLambda() = + this.isTopLevelInPackage(ALWAYS_ENABLED_ASSERT_FUNCTION_NAME, "kotlin") && this.valueParameters.size == 2 + +private fun FunctionDescriptor.isBuiltinAlwaysEnabledAssertWithoutLambda() = + this.isTopLevelInPackage(ALWAYS_ENABLED_ASSERT_FUNCTION_NAME, "kotlin") && this.valueParameters.size == 1 + +fun FunctionDescriptor.isBuiltinAlwaysEnabledAssert() = + this.isBuiltinAlwaysEnabledAssertWithLambda() || this.isBuiltinAlwaysEnabledAssertWithoutLambda() + +fun createMethodNodeForAlwaysEnabledAssert( + functionDescriptor: FunctionDescriptor, + typeMapper: KotlinTypeMapper +): MethodNode { + assert(functionDescriptor.isBuiltinAlwaysEnabledAssert()) { + "functionDescriptor must be kotlin.alwaysEnabledAssert, but got $functionDescriptor" + } + + val node = + org.jetbrains.org.objectweb.asm.tree.MethodNode( + Opcodes.ASM5, + Opcodes.ACC_STATIC, + "fake", + typeMapper.mapAsmMethod(functionDescriptor).descriptor, null, null + ) + + val v = InstructionAdapter(node) + val returnLabel = Label() + + // if (!condition) + v.load(0, Type.BOOLEAN_TYPE) + v.ifne(returnLabel) + if (functionDescriptor.isBuiltinAlwaysEnabledAssertWithLambda()) { + // val err = AssertionError(lambda()) + v.load(1, Type.getObjectType(LAMBDA_INTERNAL_NAME)) + v.invokeinterface(LAMBDA_INTERNAL_NAME, "invoke", "()Ljava/lang/Object;") + v.store(2, AsmTypes.OBJECT_TYPE) + v.anew(Type.getObjectType(ASSERTION_ERROR_INTERNAL_NAME)) + v.dup() + v.load(2, AsmTypes.OBJECT_TYPE) + v.invokespecial(ASSERTION_ERROR_INTERNAL_NAME, "", "(Ljava/lang/Object;)V", false) + } else { + // val err = AssertionError("Assertion failed") + v.anew(Type.getObjectType(ASSERTION_ERROR_INTERNAL_NAME)) + v.dup() + v.visitLdcInsn("Assertion failed") + v.invokespecial(ASSERTION_ERROR_INTERNAL_NAME, "", "(Ljava/lang/Object;)V", false) + } + // throw err + v.checkcast(Type.getObjectType(THROWABLE_INTERNAL_NAME)) + v.athrow() + // else return + v.mark(returnLabel) + v.areturn(Type.VOID_TYPE) + node.visitMaxs(3, 3) + + return node +} + +fun generateAssert( + assertionsMode: JVMAssertionsMode, + resolvedCall: ResolvedCall<*>, + codegen: ExpressionCodegen, + parentCodegen: MemberCodegen<*> +) { + assert(isAssertCall(resolvedCall)) { "generateAssert expects call of kotlin.assert function" } + when (assertionsMode) { + JVMAssertionsMode.ALWAYS_ENABLE -> inlineAlwaysInlineAssert(resolvedCall, codegen) + JVMAssertionsMode.ALWAYS_DISABLE -> { + // Nothing to do: assertions disabled + } + JVMAssertionsMode.JVM -> generateJvmAssert(resolvedCall, codegen, parentCodegen) + else -> error("legacy assertions mode shall be handled in ExpressionCodegen") + } +} + +private fun generateJvmAssert(resolvedCall: ResolvedCall<*>, codegen: ExpressionCodegen, parentCodegen: MemberCodegen<*>) { + parentCodegen.generateAssertField() + + val label = Label() + with(codegen.v) { + getstatic(parentCodegen.v.thisName, "\$assertionsDisabled", "Z") + ifne(label) + inlineAlwaysInlineAssert(resolvedCall, codegen) + mark(label) + } +} + +@Suppress("UNCHECKED_CAST") +private fun inlineAlwaysInlineAssert(resolvedCall: ResolvedCall<*>, codegen: ExpressionCodegen) { + val replaced = (resolvedCall as ResolvedCall).replaceAssertWithAssertInner() + codegen.invokeMethodWithArguments( + codegen.typeMapper.mapToCallableMethod(replaced.resultingDescriptor, false), + replaced, + StackValue.none() + ) +} + +fun generateAssertionsDisabledFieldInitialization(parentCodegen: MemberCodegen<*>) { + parentCodegen.v.newField( + JvmDeclarationOrigin.NO_ORIGIN, Opcodes.ACC_STATIC or Opcodes.ACC_FINAL or Opcodes.ACC_SYNTHETIC, assertionsDisabledFieldName, + "Z", null, null + ) + val clInitCodegen = parentCodegen.createOrGetClInitCodegen() + MemberCodegen.markLineNumberForElement(parentCodegen.element.psiOrParent, clInitCodegen.v) + val thenLabel = Label() + val elseLabel = Label() + with(clInitCodegen.v) { + aconst(Type.getObjectType(parentCodegen.v.thisName)) + invokevirtual("java/lang/Class", "desiredAssertionStatus", "()Z", false) + ifne(thenLabel) + iconst(1) + goTo(elseLabel) + + mark(thenLabel) + iconst(0) + + mark(elseLabel) + putstatic(parentCodegen.v.thisName, assertionsDisabledFieldName, "Z") + } +} + +private fun ResolvedCall.replaceAssertWithAssertInner(): ResolvedCall { + val newCandidateDescriptor = resultingDescriptor.createCustomCopy { + setName(Name.identifier(ALWAYS_ENABLED_ASSERT_FUNCTION_NAME)) + } + val newResolvedCall = ResolvedCallImpl( + call, + newCandidateDescriptor, + dispatchReceiver, extensionReceiver, explicitReceiverKind, + null, DelegatingBindingTrace(BindingTraceContext().bindingContext, "Temporary trace for assertInner"), + TracingStrategy.EMPTY, MutableDataFlowInfoForArguments.WithoutArgumentsCheck(DataFlowInfo.EMPTY) + ) + valueArguments.forEach { + newResolvedCall.recordValueArgument(newCandidateDescriptor.valueParameters[it.key.index], it.value) + } + return newResolvedCall +} diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index 93feec6e5e4..34e86d1c6d0 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -38,9 +38,9 @@ import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper; import org.jetbrains.kotlin.codegen.when.SwitchCodegen; import org.jetbrains.kotlin.codegen.when.SwitchCodegenProvider; import org.jetbrains.kotlin.config.ApiVersion; +import org.jetbrains.kotlin.config.JVMAssertionsMode; import org.jetbrains.kotlin.config.LanguageFeature; import org.jetbrains.kotlin.descriptors.*; -import org.jetbrains.kotlin.descriptors.impl.AnonymousFunctionDescriptor; import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor; import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor; import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor; @@ -2358,6 +2358,11 @@ public class ExpressionCodegen extends KtVisitor impleme @NotNull CallGenerator callGenerator, @NotNull ArgumentGenerator argumentGenerator ) { + if (AssertCodegenUtilKt.isAssertCall(resolvedCall) && !state.getAssertionsMode().equals(JVMAssertionsMode.LEGACY)) { + AssertCodegenUtilKt.generateAssert(state.getAssertionsMode(), resolvedCall, this, parentCodegen); + return; + } + boolean isSuspendNoInlineCall = CoroutineCodegenUtilKt.isSuspendNoInlineCall(resolvedCall, this, state.getLanguageVersionSettings()); boolean isConstructor = resolvedCall.getResultingDescriptor() instanceof ConstructorDescriptor; diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java index 8b479996bd9..93264ff17b7 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/MemberCodegen.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license * that can be found in the license/LICENSE.txt file. */ @@ -42,6 +42,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall; import org.jetbrains.kotlin.resolve.constants.ConstantValue; import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt; import org.jetbrains.kotlin.resolve.jvm.AsmTypes; +import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin; import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt; import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature; import org.jetbrains.kotlin.resolve.source.KotlinSourceElementKt; @@ -92,6 +93,7 @@ public abstract class MemberCodegen wrapped, T declaration, FieldOwnerContext codegenContext) { @@ -873,4 +876,10 @@ public abstract class MemberCodegen( ), SMAPParser.parseOrCreateDefault(null, null, "fake", -1, -1) ) + functionDescriptor.isBuiltinAlwaysEnabledAssert() -> + return SMAPAndMethodNode( + createMethodNodeForAlwaysEnabledAssert(functionDescriptor, state.typeMapper), + SMAPParser.parseOrCreateDefault(null, null, "fake", -1, -1) + ) } val asmMethod = if (callDefault) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SourceCompilerForInline.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SourceCompilerForInline.kt index afc11ade42d..1d4b2c4f07c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SourceCompilerForInline.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/SourceCompilerForInline.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.codegen.inline @@ -261,6 +250,10 @@ class PsiSourceCompilerForInline(private val codegen: ExpressionCodegen, overrid innerClasses.addAll(parentAsInnerClasses) } } + + override fun generateAssertField() { + delegate.generateAssertField() + } } override fun doCreateMethodNodeFromSource( diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt index f062ccf0fd8..0ada0f3dcbf 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt @@ -209,6 +209,7 @@ class GenerationState private constructor( configuration.getBoolean(JVMConfigurationKeys.DISABLE_RECEIVER_ASSERTIONS) || !languageVersionSettings.supportsFeature(LanguageFeature.NullabilityAssertionOnExtensionReceiver) val isParamAssertionsDisabled: Boolean = configuration.getBoolean(JVMConfigurationKeys.DISABLE_PARAM_ASSERTIONS) + val assertionsMode: JVMAssertionsMode = configuration.get(JVMConfigurationKeys.ASSERTIONS_MODE, JVMAssertionsMode.DEFAULT) val isInlineDisabled: Boolean = configuration.getBoolean(CommonConfigurationKeys.DISABLE_INLINE) val useTypeTableInSerializer: Boolean = configuration.getBoolean(JVMConfigurationKeys.USE_TYPE_TABLE) val inheritMultifileParts: Boolean = configuration.getBoolean(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS) diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index d1e1774475a..7bda4d546af 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -17,10 +17,7 @@ package org.jetbrains.kotlin.cli.common.arguments import org.jetbrains.kotlin.cli.common.messages.MessageCollector -import org.jetbrains.kotlin.config.AnalysisFlag -import org.jetbrains.kotlin.config.JVMConstructorCallNormalizationMode -import org.jetbrains.kotlin.config.JvmTarget -import org.jetbrains.kotlin.config.LanguageFeature +import org.jetbrains.kotlin.config.* class K2JVMCompilerArguments : CommonCompilerArguments() { companion object { @@ -124,6 +121,17 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { ) var constructorCallNormalizationMode: String? by FreezableVar(JVMConstructorCallNormalizationMode.DEFAULT.description) + @Argument( + value = "-Xassertions", valueDescription = "{always-enable|always-disable|jvm|legacy}", + description = "Assert calls behaviour\n" + + "-Xassertions=always-enable: enable, ignore jvm assertion settings;\n" + + "-Xassertions=always-disable: disable, ignore jvm assertion settings;\n" + + "-Xassertions=jvm: enable, depend on jvm assertion settings;\n" + + "-Xassertions=legacy: calculate condition on each call, check depends on jvm assertion settings in the kotlin package;\n" + + "default: legacy" + ) + var assertionsMode: String? by FreezableVar(JVMAssertionsMode.DEFAULT.description) + @Argument( value = "-Xbuild-file", deprecatedName = "-module", diff --git a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt index b69d6835e33..b0388ea452c 100644 --- a/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt +++ b/compiler/cli/src/org/jetbrains/kotlin/cli/jvm/K2JVMCompiler.kt @@ -361,6 +361,20 @@ class K2JVMCompiler : CLICompiler() { constructorCallNormalizationMode ?: JVMConstructorCallNormalizationMode.DEFAULT ) + val assertionsMode = + JVMAssertionsMode.fromStringOrNull(arguments.assertionsMode) + if (assertionsMode == null) { + configuration.getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report( + ERROR, + "Unknown assertions mode: ${arguments.assertionsMode}, " + + "supported modes: ${JVMAssertionsMode.values().map { it.description }}" + ) + } + configuration.put( + JVMConfigurationKeys.ASSERTIONS_MODE, + assertionsMode ?: JVMAssertionsMode.DEFAULT + ) + configuration.put(JVMConfigurationKeys.INHERIT_MULTIFILE_PARTS, arguments.inheritMultifileParts) configuration.put(JVMConfigurationKeys.USE_TYPE_TABLE, arguments.useTypeTable) configuration.put(JVMConfigurationKeys.SKIP_RUNTIME_VERSION_CHECK, arguments.skipRuntimeVersionCheck) diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMAssertionsMode.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMAssertionsMode.kt new file mode 100644 index 00000000000..2dc63d8f740 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMAssertionsMode.kt @@ -0,0 +1,21 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.config + +enum class JVMAssertionsMode(val description: String) { + ALWAYS_ENABLE("always-enable"), + ALWAYS_DISABLE("always-disable"), + JVM("jvm"), + LEGACY("legacy"); + + companion object { + @JvmField + val DEFAULT = LEGACY + + @JvmStatic + fun fromStringOrNull(string: String?) = values().find { it.description == string } + } +} \ No newline at end of file diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java b/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java index 68f7e79f8a4..e6206dae6fa 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/config/JVMConfigurationKeys.java @@ -65,6 +65,8 @@ public class JVMConfigurationKeys { CompilerConfigurationKey.create("disable not-null call receiver assertions"); public static final CompilerConfigurationKey DISABLE_PARAM_ASSERTIONS = CompilerConfigurationKey.create("disable not-null parameter assertions"); + public static final CompilerConfigurationKey ASSERTIONS_MODE = + CompilerConfigurationKey.create("assertions mode"); public static final CompilerConfigurationKey CONSTRUCTOR_CALL_NORMALIZATION_MODE = CompilerConfigurationKey.create("constructor call normalization mode"); public static final CompilerConfigurationKey NO_EXCEPTION_ON_EXPLICIT_EQUALS_FOR_BOXED_NULL = diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 84e33cb7935..a8f6f77df82 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -3,6 +3,13 @@ where advanced options include: -Xadd-compiler-builtins Add definitions of built-in declarations to the compilation classpath (useful with -no-stdlib) -Xadd-modules= Root modules to resolve in addition to the initial modules, or all modules on the module path if is ALL-MODULE-PATH + -Xassertions={always-enable|always-disable|jvm|legacy} + Assert calls behaviour + -Xassertions=always-enable: enable, ignore jvm assertion settings; + -Xassertions=always-disable: disable, ignore jvm assertion settings; + -Xassertions=jvm: enable, depend on jvm assertion settings; + -Xassertions=legacy: calculate condition on each call, check depends on jvm assertion settings in the kotlin package; + default: legacy -Xbuild-file= Path to the .xml build file to compile -Xcompile-java Reuse javac analysis and compile Java source files -Xnormalize-constructor-calls={disable|enable} diff --git a/compiler/testData/codegen/box/assert/alwaysDisable.kt b/compiler/testData/codegen/box/assert/alwaysDisable.kt new file mode 100644 index 00000000000..0bb424cd934 --- /dev/null +++ b/compiler/testData/codegen/box/assert/alwaysDisable.kt @@ -0,0 +1,40 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=always-disable +// WITH_RUNTIME + +fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + assert(l()) + return hit +} + +fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + assert(l()) { "BOOYA!" } + return hit +} + +fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + assert(l()) + return hit +} + +fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + assert(l()) { "BOOYA!" } + return hit +} + +fun box(): String { + if (checkTrue()) return "FAIL 0" + if (checkTrueWithMessage()) return "FAIL 1" + if (checkFalse()) return "FAIL 2" + if (checkFalseWithMessage()) return "FAIL 3" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/alwaysEnable.kt b/compiler/testData/codegen/box/assert/alwaysEnable.kt new file mode 100644 index 00000000000..e40614fec86 --- /dev/null +++ b/compiler/testData/codegen/box/assert/alwaysEnable.kt @@ -0,0 +1,48 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=always-enable +// WITH_RUNTIME + +fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + assert(l()) + return hit +} + +fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + assert(l()) { "BOOYA!" } + return hit +} + +fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + assert(l()) + return hit +} + +fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + assert(l()) { "BOOYA!" } + return hit +} + +fun box(): String { + if (!checkTrue()) return "FAIL 0" + if (!checkTrueWithMessage()) return "FAIL 1" + try { + checkFalse() + return "FAIL 3" + } catch (ignore: AssertionError) { + } + try { + checkFalseWithMessage() + return "FAIL 4" + } catch (ignore: AssertionError) { + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/jvm/interfaceAssertionsDisabled.kt b/compiler/testData/codegen/box/assert/jvm/interfaceAssertionsDisabled.kt new file mode 100644 index 00000000000..ae8fb87967f --- /dev/null +++ b/compiler/testData/codegen/box/assert/jvm/interfaceAssertionsDisabled.kt @@ -0,0 +1,54 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME + +interface Checker { + fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + assert(l()) + return hit + } + + fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + assert(l()) + return hit + } + + fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + assert(l()) { "BOOYA" } + return hit + } + + fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + assert(l()) { "BOOYA" } + return hit + } +} + +class ShouldBeDisabled : Checker {} + +class Dummy + +fun disableAssertions(): Checker { + val loader = Dummy::class.java.classLoader + loader.setDefaultAssertionStatus(false) + val c = loader.loadClass("ShouldBeDisabled") + return c.newInstance() as Checker +} + +fun box(): String { + var c = disableAssertions() + if (c.checkTrue()) return "FAIL 0" + 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 new file mode 100644 index 00000000000..1531b77cd05 --- /dev/null +++ b/compiler/testData/codegen/box/assert/jvm/interfaceAssertionsEnabled.kt @@ -0,0 +1,62 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME + +interface Checker { + fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + assert(l()) + return hit + } + + fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + assert(l()) + return hit + } + + fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + assert(l()) { "BOOYA" } + return hit + } + + fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + assert(l()) { "BOOYA" } + return hit + } +} + +class ShouldBeEnabled : Checker {} + +class Dummy + +fun enableAssertions(): Checker { + val loader = Dummy::class.java.classLoader + loader.setDefaultAssertionStatus(true) + val c = loader.loadClass("ShouldBeEnabled") + return c.newInstance() as Checker +} + +fun box(): String { + var c = enableAssertions() + if (!c.checkTrue()) return "FAIL 0" + if (!c.checkTrueWithMessage()) return "FAIL 1" + try { + c.checkFalse() + return "FAIL 2" + } catch (ignore: AssertionError) { + } + try { + c.checkFalseWithMessage() + return "FAIL 3" + } catch (ignore: AssertionError) { + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/jvm/localAnonymousFunction.kt b/compiler/testData/codegen/box/assert/jvm/localAnonymousFunction.kt new file mode 100644 index 00000000000..08768fce257 --- /dev/null +++ b/compiler/testData/codegen/box/assert/jvm/localAnonymousFunction.kt @@ -0,0 +1,124 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME + +interface Checker { + fun checkTrue(): Boolean + fun checkFalse(): Boolean + fun checkTrueWithMessage(): Boolean + fun checkFalseWithMessage(): Boolean +} + +class ShouldBeDisabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + val local = fun() { + assert(l()) + } + local() + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + val local = fun() { + assert(l()) + } + local() + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + val local = fun() { + assert(l()) { "BOOYA" } + } + local() + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + val local = fun() { + assert(l()) { "BOOYA" } + } + local() + return hit + } +} + +class ShouldBeEnabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + val local = fun() { + assert(l()) + } + local() + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + val local = fun() { + assert(l()) + } + local() + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + val local = fun() { + assert(l()) { "BOOYA" } + } + local() + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + val local = fun() { + assert(l()) { "BOOYA" } + } + local() + return hit + } +} + +fun setDesiredAssertionStatus(v: Boolean): Checker { + val loader = Checker::class.java.classLoader + loader.setDefaultAssertionStatus(v) + val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + return c.newInstance() as Checker +} + +fun box(): String { + var c = setDesiredAssertionStatus(false) + if (c.checkTrue()) return "FAIL 0" + if (c.checkTrueWithMessage()) return "FAIL 1" + if (c.checkFalse()) return "FAIL 2" + if (c.checkFalseWithMessage()) return "FAIL 3" + c = setDesiredAssertionStatus(true) + if (!c.checkTrue()) return "FAIL 4" + if (!c.checkTrueWithMessage()) return "FAIL 5" + try { + c.checkFalse() + return "FAIL 6" + } catch (ignore: AssertionError) { + } + try { + c.checkFalseWithMessage() + return "FAIL 7" + } catch (ignore: AssertionError) { + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/jvm/localClass.kt b/compiler/testData/codegen/box/assert/jvm/localClass.kt new file mode 100644 index 00000000000..4c8f2f5b2ec --- /dev/null +++ b/compiler/testData/codegen/box/assert/jvm/localClass.kt @@ -0,0 +1,164 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME + +interface Checker { + fun checkTrue(): Boolean + fun checkFalse(): Boolean + fun checkTrueWithMessage(): Boolean + fun checkFalseWithMessage(): Boolean +} + +class ShouldBeDisabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + + class Local { + fun run() { + assert(l()) + } + } + + val local = Local() + local.run() + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + + class Local { + fun run() { + assert(l()) + } + } + + val local = Local() + local.run() + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + + class Local { + fun run() { + assert(l()) { "BOOYA" } + } + } + + val local = Local() + local.run() + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + + class Local { + fun run() { + assert(l()) { "BOOYA" } + } + } + + val local = Local() + local.run() + return hit + } +} + +class ShouldBeEnabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + + class Local { + fun run() { + assert(l()) + } + } + + val local = Local() + local.run() + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + + class Local { + fun run() { + assert(l()) + } + } + + val local = Local() + local.run() + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + + class Local { + fun run() { + assert(l()) { "BOOYA" } + } + } + + val local = Local() + local.run() + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + + class Local { + fun run() { + assert(l()) { "BOOYA" } + } + } + + val local = Local() + local.run() + return hit + } +} + +fun setDesiredAssertionStatus(v: Boolean): Checker { + val loader = Checker::class.java.classLoader + loader.setDefaultAssertionStatus(v) + val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + return c.newInstance() as Checker +} + +fun box(): String { + var c = setDesiredAssertionStatus(false) + if (c.checkTrue()) return "FAIL 0" + if (c.checkTrueWithMessage()) return "FAIL 1" + if (c.checkFalse()) return "FAIL 2" + if (c.checkFalseWithMessage()) return "FAIL 3" + c = setDesiredAssertionStatus(true) + if (!c.checkTrue()) return "FAIL 4" + if (!c.checkTrueWithMessage()) return "FAIL 5" + try { + c.checkFalse() + return "FAIL 6" + } catch (ignore: AssertionError) { + } + try { + c.checkFalseWithMessage() + return "FAIL 7" + } catch (ignore: AssertionError) { + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/jvm/localFunction.kt b/compiler/testData/codegen/box/assert/jvm/localFunction.kt new file mode 100644 index 00000000000..432588d5aa9 --- /dev/null +++ b/compiler/testData/codegen/box/assert/jvm/localFunction.kt @@ -0,0 +1,124 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME + +interface Checker { + fun checkTrue(): Boolean + fun checkFalse(): Boolean + fun checkTrueWithMessage(): Boolean + fun checkFalseWithMessage(): Boolean +} + +class ShouldBeDisabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + fun local() { + assert(l()) + } + local() + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + fun local() { + assert(l()) + } + local() + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + fun local() { + assert(l()) { "BOOYA" } + } + local() + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + fun local() { + assert(l()) { "BOOYA" } + } + local() + return hit + } +} + +class ShouldBeEnabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + fun local() { + assert(l()) + } + local() + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + fun local() { + assert(l()) + } + local() + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + fun local() { + assert(l()) { "BOOYA" } + } + local() + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + fun local() { + assert(l()) { "BOOYA" } + } + local() + return hit + } +} + +fun setDesiredAssertionStatus(v: Boolean): Checker { + val loader = Checker::class.java.classLoader + loader.setDefaultAssertionStatus(v) + val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + return c.newInstance() as Checker +} + +fun box(): String { + var c = setDesiredAssertionStatus(false) + if (c.checkTrue()) return "FAIL 0" + if (c.checkTrueWithMessage()) return "FAIL 1" + if (c.checkFalse()) return "FAIL 2" + if (c.checkFalseWithMessage()) return "FAIL 3" + c = setDesiredAssertionStatus(true) + if (!c.checkTrue()) return "FAIL 4" + if (!c.checkTrueWithMessage()) return "FAIL 5" + try { + c.checkFalse() + return "FAIL 6" + } catch (ignore: AssertionError) { + } + try { + c.checkFalseWithMessage() + return "FAIL 7" + } catch (ignore: AssertionError) { + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/jvm/localLambda.kt b/compiler/testData/codegen/box/assert/jvm/localLambda.kt new file mode 100644 index 00000000000..e1ceaff1859 --- /dev/null +++ b/compiler/testData/codegen/box/assert/jvm/localLambda.kt @@ -0,0 +1,124 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME + +interface Checker { + fun checkTrue(): Boolean + fun checkFalse(): Boolean + fun checkTrueWithMessage(): Boolean + fun checkFalseWithMessage(): Boolean +} + +class ShouldBeDisabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + val local = { + assert(l()) + } + local() + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + val local = { + assert(l()) + } + local() + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + val local = { + assert(l()) { "BOOYA" } + } + local() + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + val local = { + assert(l()) { "BOOYA" } + } + local() + return hit + } +} + +class ShouldBeEnabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + val local = { + assert(l()) + } + local() + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + val local = { + assert(l()) + } + local() + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + val local = { + assert(l()) { "BOOYA" } + } + local() + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + val local = { + assert(l()) { "BOOYA" } + } + local() + return hit + } +} + +fun setDesiredAssertionStatus(v: Boolean): Checker { + val loader = Checker::class.java.classLoader + loader.setDefaultAssertionStatus(v) + val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + return c.newInstance() as Checker +} + +fun box(): String { + var c = setDesiredAssertionStatus(false) + if (c.checkTrue()) return "FAIL 0" + if (c.checkTrueWithMessage()) return "FAIL 1" + if (c.checkFalse()) return "FAIL 2" + if (c.checkFalseWithMessage()) return "FAIL 3" + c = setDesiredAssertionStatus(true) + if (!c.checkTrue()) return "FAIL 4" + if (!c.checkTrueWithMessage()) return "FAIL 5" + try { + c.checkFalse() + return "FAIL 6" + } catch (ignore: AssertionError) { + } + try { + c.checkFalseWithMessage() + return "FAIL 7" + } catch (ignore: AssertionError) { + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/jvm/localObject.kt b/compiler/testData/codegen/box/assert/jvm/localObject.kt new file mode 100644 index 00000000000..9de8f711b37 --- /dev/null +++ b/compiler/testData/codegen/box/assert/jvm/localObject.kt @@ -0,0 +1,156 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME + +interface Checker { + fun checkTrue(): Boolean + fun checkFalse(): Boolean + fun checkTrueWithMessage(): Boolean + fun checkFalseWithMessage(): Boolean +} + +class ShouldBeDisabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + + val local = object { + fun run() { + assert(l()) + } + } + + local.run() + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + + val local = object { + fun run() { + assert(l()) + } + } + + local.run() + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + + val local = object { + fun run() { + assert(l()) { "BOOYA" } + } + } + + local.run() + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + + val local = object { + fun run() { + assert(l()) { "BOOYA" } + } + } + + local.run() + return hit + } +} + +class ShouldBeEnabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + + val local = object { + fun run() { + assert(l()) + } + } + + local.run() + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + + val local = object { + fun run() { + assert(l()) + } + } + + local.run() + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + + val local = object { + fun run() { + assert(l()) { "BOOYA" } + } + } + + local.run() + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + + val local = object { + fun run() { + assert(l()) { "BOOYA" } + } + } + + local.run() + return hit + } +} + +fun setDesiredAssertionStatus(v: Boolean): Checker { + val loader = Checker::class.java.classLoader + loader.setDefaultAssertionStatus(v) + val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + return c.newInstance() as Checker +} + +fun box(): String { + var c = setDesiredAssertionStatus(false) + if (c.checkTrue()) return "FAIL 0" + if (c.checkTrueWithMessage()) return "FAIL 1" + if (c.checkFalse()) return "FAIL 2" + if (c.checkFalseWithMessage()) return "FAIL 3" + c = setDesiredAssertionStatus(true) + if (!c.checkTrue()) return "FAIL 4" + if (!c.checkTrueWithMessage()) return "FAIL 5" + try { + c.checkFalse() + return "FAIL 6" + } catch (ignore: AssertionError) { + } + try { + c.checkFalseWithMessage() + return "FAIL 7" + } catch (ignore: AssertionError) { + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/jvm/nonLocalReturn.kt b/compiler/testData/codegen/box/assert/jvm/nonLocalReturn.kt new file mode 100644 index 00000000000..9be1aa94657 --- /dev/null +++ b/compiler/testData/codegen/box/assert/jvm/nonLocalReturn.kt @@ -0,0 +1,75 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME + +interface Checker { + fun checkTrueWithMessage(): Boolean + fun checkFalseWithMessage(): Boolean +} + +class ShouldBeDisabled : Checker { + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + + assert(l()) { + throw RuntimeException("FAIL 1") + } + + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + + assert(l()) { + throw RuntimeException("FAIL 3") + } + + return hit + } +} + +class ShouldBeEnabled : Checker { + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + + assert(l()) { + throw RuntimeException("FAIL 5") + } + + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + + assert(l()) { + return hit + "BOOYA" + } + + throw RuntimeException("FAIL 7") + } +} + +fun setDesiredAssertionStatus(v: Boolean): Checker { + val loader = Checker::class.java.classLoader + loader.setDefaultAssertionStatus(v) + val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + return c.newInstance() as Checker +} + +fun box(): String { + var c = setDesiredAssertionStatus(false) + if (c.checkTrueWithMessage()) return "FAIL 2" + if (c.checkFalseWithMessage()) return "FAIL 4" + c = setDesiredAssertionStatus(true) + if (!c.checkTrueWithMessage()) return "FAIL 6" + if (!c.checkFalseWithMessage()) return "FAIL 8" + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/jvm/ordinary.kt b/compiler/testData/codegen/box/assert/jvm/ordinary.kt new file mode 100644 index 00000000000..91414dd3559 --- /dev/null +++ b/compiler/testData/codegen/box/assert/jvm/ordinary.kt @@ -0,0 +1,100 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME + +interface Checker { + fun checkTrue(): Boolean + fun checkFalse(): Boolean + fun checkTrueWithMessage(): Boolean + fun checkFalseWithMessage(): Boolean +} + +class ShouldBeDisabled: Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + assert(l()) + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + assert(l()) + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + assert(l()) { "BOOYA" } + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + assert(l()) { "BOOYA" } + return hit + } +} + +class ShouldBeEnabled: Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + assert(l()) + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + assert(l()) + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + assert(l()) { "BOOYA" } + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + assert(l()) { "BOOYA" } + return hit + } +} + +fun setDesiredAssertionStatus(v: Boolean): Checker { + val loader = Checker::class.java.classLoader + loader.setDefaultAssertionStatus(v) + val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + return c.newInstance() as Checker +} + +fun box(): String { + var c = setDesiredAssertionStatus(false) + if (c.checkTrue()) return "FAIL 0" + if (c.checkTrueWithMessage()) return "FAIL 1" + if (c.checkFalse()) return "FAIL 2" + if (c.checkFalseWithMessage()) return "FAIL 3" + c = setDesiredAssertionStatus(true) + if (!c.checkTrue()) return "FAIL 4" + if (!c.checkTrueWithMessage()) return "FAIL 5" + try { + c.checkFalse() + return "FAIL 6" + } catch (ignore: AssertionError) { + } + try { + c.checkFalseWithMessage() + return "FAIL 7" + } catch (ignore: AssertionError) { + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/jvm/superClassInitializer.kt b/compiler/testData/codegen/box/assert/jvm/superClassInitializer.kt new file mode 100644 index 00000000000..8095ae34a65 --- /dev/null +++ b/compiler/testData/codegen/box/assert/jvm/superClassInitializer.kt @@ -0,0 +1,118 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME + +interface Checker { + fun checkTrue(): Boolean + fun checkFalse(): Boolean + fun checkTrueWithMessage(): Boolean + fun checkFalseWithMessage(): Boolean +} + +open class IntHolder(i: Int) + +class ShouldBeDisabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + + val local = object : IntHolder(run { assert(l()); 0 }) {} + + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + + val local = object : IntHolder(run { assert(l()); 0 }) {} + + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + + val local = object : IntHolder(run { assert(l()) { "BOOYA!" }; 0 }) {} + + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + + val local = object : IntHolder(run { assert(l()) { "BOOYA!" }; 0 }) {} + + return hit + } +} + +class ShouldBeEnabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + + val local = object : IntHolder(run { assert(l()); 0 }) {} + + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + + val local = object : IntHolder(run { assert(l()); 0 }) {} + + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + + val local = object : IntHolder(run { assert(l()) { "BOOYA!" }; 0 }) {} + + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + + val local = object : IntHolder(run { assert(l()) { "BOOYA!" }; 0 }) {} + + return hit + } +} + +fun setDesiredAssertionStatus(v: Boolean): Checker { + val loader = Checker::class.java.classLoader + loader.setDefaultAssertionStatus(v) + val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + return c.newInstance() as Checker +} + +fun box(): String { + var c = setDesiredAssertionStatus(false) + if (c.checkTrue()) return "FAIL 0" + if (c.checkTrueWithMessage()) return "FAIL 1" + if (c.checkFalse()) return "FAIL 2" + if (c.checkFalseWithMessage()) return "FAIL 3" + c = setDesiredAssertionStatus(true) + if (!c.checkTrue()) return "FAIL 4" + if (!c.checkTrueWithMessage()) return "FAIL 5" + try { + c.checkFalse() + return "FAIL 6" + } catch (ignore: AssertionError) { + } + try { + c.checkFalseWithMessage() + return "FAIL 7" + } catch (ignore: AssertionError) { + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt b/compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt new file mode 100644 index 00000000000..1262f40613a --- /dev/null +++ b/compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt @@ -0,0 +1,34 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME +// WITH_COROUTINES +// COMMON_COROUTINES_TEST + +import helpers.* +import COROUTINES_PACKAGE.* + +class Checker { + suspend fun check() { + assert(false) + } +} + +class Dummy + +fun disableAssertions(): Checker { + val loader = Dummy::class.java.classLoader + loader.setDefaultAssertionStatus(false) + val c = loader.loadClass("Checker") + return c.newInstance() as Checker +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun box(): String { + var c = disableAssertions() + builder { c.check() } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt b/compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt new file mode 100644 index 00000000000..413d5063935 --- /dev/null +++ b/compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt @@ -0,0 +1,38 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME +// WITH_COROUTINES +// COMMON_COROUTINES_TEST + +import helpers.* +import COROUTINES_PACKAGE.* + +class Checker { + suspend fun check() { + assert(false) + } +} + +class Dummy + +fun enableAssertions(): Checker { + val loader = Dummy::class.java.classLoader + loader.setDefaultAssertionStatus(true) + val c = loader.loadClass("Checker") + return c.newInstance() as Checker +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun box(): String { + var c = enableAssertions() + try { + builder { c.check() } + return "FAIL 6" + } catch (ignore: AssertionError) { + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt b/compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt new file mode 100644 index 00000000000..8fbc81478c7 --- /dev/null +++ b/compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt @@ -0,0 +1,34 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME +// WITH_COROUTINES +// COMMON_COROUTINES_TEST + +import helpers.* +import COROUTINES_PACKAGE.* + +class Checker { + fun check() { + builder { assert(false) } + } +} + +class Dummy + +fun disableAssertions(): Checker { + val loader = Dummy::class.java.classLoader + loader.setDefaultAssertionStatus(false) + val c = loader.loadClass("Checker") + return c.newInstance() as Checker +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun box(): String { + var c = disableAssertions() + c.check() + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt b/compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt new file mode 100644 index 00000000000..b776e84e141 --- /dev/null +++ b/compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt @@ -0,0 +1,38 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME +// WITH_COROUTINES +// COMMON_COROUTINES_TEST + +import helpers.* +import COROUTINES_PACKAGE.* + +class Checker { + fun check() { + builder { assert(false) } + } +} + +class Dummy + +fun enableAssertions(): Checker { + val loader = Dummy::class.java.classLoader + loader.setDefaultAssertionStatus(true) + val c = loader.loadClass("Checker") + return c.newInstance() as Checker +} + +fun builder(c: suspend () -> Unit) { + c.startCoroutine(EmptyContinuation) +} + +fun box(): String { + var c = enableAssertions() + try { + c.check() + return "FAIL 6" + } catch (ignore: AssertionError) { + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/assert/legacy.kt b/compiler/testData/codegen/box/assert/legacy.kt new file mode 100644 index 00000000000..a00ea40eaeb --- /dev/null +++ b/compiler/testData/codegen/box/assert/legacy.kt @@ -0,0 +1,76 @@ +// IGNORE_BACKEND: JS +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=legacy +// WITH_RUNTIME +// FULL_JDK + +import java.lang.reflect.Field +import java.lang.reflect.Modifier + +fun setDesiredAssertionStatus(v: Boolean) { + @Suppress("INVISIBLE_REFERENCE") + val field = kotlin._Assertions.javaClass.getField("ENABLED") + val modifiers = Field::class.java.getDeclaredField("modifiers"); + modifiers.isAccessible = true + modifiers.setInt(field, field.modifiers and Modifier.FINAL.inv()) + field.set(null, v) +} + +fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + assert(l()) + return hit +} + +fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + assert(l()) { "BOOYA!" } + return hit +} + +fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + assert(l()) + return hit +} + +fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + assert(l()) { "BOOYA!" } + return hit +} + +fun box(): String { + setDesiredAssertionStatus(false) + if (!checkTrue()) return "FAIL 0" + setDesiredAssertionStatus(true) + if (!checkTrue()) return "FAIL 1" + + setDesiredAssertionStatus(false) + if (!checkTrueWithMessage()) return "FAIL 2" + setDesiredAssertionStatus(true) + if (!checkTrueWithMessage()) return "FAIL 3" + + setDesiredAssertionStatus(false) + if (!checkFalse()) return "FAIL 4" + setDesiredAssertionStatus(true) + try { + checkFalse() + return "FAIL 5" + } catch (ignore: AssertionError) { + } + + setDesiredAssertionStatus(false) + if (!checkFalseWithMessage()) return "FAIL 6" + setDesiredAssertionStatus(true) + try { + checkFalseWithMessage() + return "FAIL 7" + } catch (ignore: AssertionError) { + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsDisabled.kt b/compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsDisabled.kt new file mode 100644 index 00000000000..1ba6976e652 --- /dev/null +++ b/compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsDisabled.kt @@ -0,0 +1,33 @@ +// FILE: inline.kt +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME + +inline fun inlineMe() { + assert(false) { "FROM INLINED" } +} + +// FILE: inlineSite.kt +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm + +class Checker { + fun check() { + inlineMe() + assert(false) { "FROM INLINESITE" } + } +} + +class Dummy + +fun disableAssertions(): Checker { + val loader = Dummy::class.java.classLoader + loader.setDefaultAssertionStatus(false) + val c = loader.loadClass("Checker") + return c.newInstance() as Checker +} + +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 new file mode 100644 index 00000000000..51de71633bb --- /dev/null +++ b/compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsEnabled.kt @@ -0,0 +1,36 @@ +// FILE: inline.kt +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME + +inline fun inlineMe() { + assert(false) { "FROM INLINED" } +} + +// FILE: inlineSite.kt +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm + +class Checker { + fun check() { + inlineMe() + throw RuntimeException("FAIL 0") + } +} + +class Dummy + +fun enableAssertions(): Checker { + val loader = Dummy::class.java.classLoader + loader.setDefaultAssertionStatus(true) + val c = loader.loadClass("Checker") + return c.newInstance() as Checker +} + +fun box(): String { + var c = enableAssertions() + try { + 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 new file mode 100644 index 00000000000..f48f868424a --- /dev/null +++ b/compiler/testData/codegen/boxInline/assert/jvmAssertInlineLambda.kt @@ -0,0 +1,124 @@ +// FILE: inline.kt +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME +// NO_CHECK_LAMBDA_INLINING + +inline fun call(c: () -> Unit) { + c() +} + +// FILE: inlineSite.kt +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm + +interface Checker { + fun checkTrue(): Boolean + fun checkFalse(): Boolean + fun checkTrueWithMessage(): Boolean + fun checkFalseWithMessage(): Boolean +} + +class ShouldBeDisabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + call { + assert(l()) + } + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + call { + assert(l()) + } + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + call { + assert(l()) { "BOOYA" } + } + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + call { + assert(l()) { "BOOYA" } + } + return hit + } +} + +class ShouldBeEnabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + call { + assert(l()) + } + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + call { + assert(l()) + } + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + call { + assert(l()) { "BOOYA" } + } + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + call { + assert(l()) { "BOOYA" } + } + return hit + } +} + +fun setDesiredAssertionStatus(v: Boolean): Checker { + val loader = Checker::class.java.classLoader + loader.setDefaultAssertionStatus(v) + val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + return c.newInstance() as Checker +} + +fun box(): String { + var c = setDesiredAssertionStatus(false) + if (c.checkTrue()) return "FAIL 0" + if (c.checkTrueWithMessage()) return "FAIL 1" + if (c.checkFalse()) return "FAIL 2" + if (c.checkFalseWithMessage()) return "FAIL 3" + c = setDesiredAssertionStatus(true) + if (!c.checkTrue()) return "FAIL 4" + if (!c.checkTrueWithMessage()) return "FAIL 5" + try { + c.checkFalse() + return "FAIL 6" + } catch (ignore: AssertionError) { + } + try { + c.checkFalseWithMessage() + 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 new file mode 100644 index 00000000000..72fb15f5e4c --- /dev/null +++ b/compiler/testData/codegen/boxInline/assert/jvmCrossinlineLambda.kt @@ -0,0 +1,125 @@ +// FILE: inline.kt +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm +// WITH_RUNTIME +// NO_CHECK_LAMBDA_INLINING + +inline fun call(crossinline c: () -> Unit) { + val l = { c() } + l() +} + +// FILE: inlineSite.kt +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=jvm + +interface Checker { + fun checkTrue(): Boolean + fun checkFalse(): Boolean + fun checkTrueWithMessage(): Boolean + fun checkFalseWithMessage(): Boolean +} + +class ShouldBeDisabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + call { + assert(l()) + } + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + call { + assert(l()) + } + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + call { + assert(l()) { "BOOYA" } + } + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + call { + assert(l()) { "BOOYA" } + } + return hit + } +} + +class ShouldBeEnabled : Checker { + override fun checkTrue(): Boolean { + var hit = false + val l = { hit = true; true } + call { + assert(l()) + } + return hit + } + + override fun checkFalse(): Boolean { + var hit = false + val l = { hit = true; false } + call { + assert(l()) + } + return hit + } + + override fun checkTrueWithMessage(): Boolean { + var hit = false + val l = { hit = true; true } + call { + assert(l()) { "BOOYA" } + } + return hit + } + + override fun checkFalseWithMessage(): Boolean { + var hit = false + val l = { hit = true; false } + call { + assert(l()) { "BOOYA" } + } + return hit + } +} + +fun setDesiredAssertionStatus(v: Boolean): Checker { + val loader = Checker::class.java.classLoader + loader.setDefaultAssertionStatus(v) + val c = loader.loadClass(if (v) "ShouldBeEnabled" else "ShouldBeDisabled") + return c.newInstance() as Checker +} + +fun box(): String { + var c = setDesiredAssertionStatus(false) + if (c.checkTrue()) return "FAIL 0" + if (c.checkTrueWithMessage()) return "FAIL 1" + if (c.checkFalse()) return "FAIL 2" + if (c.checkFalseWithMessage()) return "FAIL 3" + c = setDesiredAssertionStatus(true) + if (!c.checkTrue()) return "FAIL 4" + if (!c.checkTrueWithMessage()) return "FAIL 5" + try { + c.checkFalse() + return "FAIL 6" + } catch (ignore: AssertionError) { + } + try { + c.checkFalseWithMessage() + return "FAIL 7" + } catch (ignore: AssertionError) { + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/inlineFromOtherModule.kt b/compiler/testData/codegen/bytecodeText/inlineFromOtherModule.kt index 13ce0d3d697..25e7d2b884e 100644 --- a/compiler/testData/codegen/bytecodeText/inlineFromOtherModule.kt +++ b/compiler/testData/codegen/bytecodeText/inlineFromOtherModule.kt @@ -1,3 +1,4 @@ +// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=legacy fun foo() { assert(1 == 1) { "Hahaha" } } diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractLightAnalysisModeTest.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractLightAnalysisModeTest.kt index a6df8f053e2..c7c009cd7a2 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractLightAnalysisModeTest.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/AbstractLightAnalysisModeTest.kt @@ -113,6 +113,7 @@ abstract class AbstractLightAnalysisModeTest : CodegenTestCase() { } override fun shouldWriteField(access: Int, name: String, desc: String) = when { + name == "\$assertionsDisabled" -> false name == "\$VALUES" && (access and ACC_PRIVATE != 0) && (access and ACC_FINAL != 0) && (access and ACC_SYNTHETIC != 0) -> false name == JvmAbi.DELEGATED_PROPERTIES_ARRAY_NAME && (access and ACC_SYNTHETIC != 0) -> false else -> true diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java index b1cbc9fff50..61a1aad8024 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/codegen/CodegenTestCase.java @@ -236,6 +236,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase { private static final Pattern BOOLEAN_FLAG_PATTERN = Pattern.compile("([+-])(([a-zA-Z_0-9]*)\\.)?([a-zA-Z_0-9]*)"); private static final Pattern CONSTRUCTOR_CALL_NORMALIZATION_MODE_FLAG_PATTERN = Pattern.compile( "CONSTRUCTOR_CALL_NORMALIZATION_MODE=([a-zA-Z_0-9]*)"); + private static final Pattern ASSERTIONS_MODE_FLAG_PATTERN = Pattern.compile("ASSERTIONS_MODE=([a-zA-Z_0-9-]*)"); private static void updateConfigurationWithFlags(@NotNull CompilerConfiguration configuration, @NotNull List flags) { for (String flag : flags) { @@ -256,6 +257,14 @@ public abstract class CodegenTestCase extends KtUsefulTestCase { assert mode != null : "Wrong CONSTRUCTOR_CALL_NORMALIZATION_MODE value: " + flagValueString; configuration.put(JVMConfigurationKeys.CONSTRUCTOR_CALL_NORMALIZATION_MODE, mode); } + + m = ASSERTIONS_MODE_FLAG_PATTERN.matcher(flag); + if (m.matches()) { + String flagValueString = m.group(1); + JVMAssertionsMode mode = JVMAssertionsMode.fromStringOrNull(flagValueString); + assert mode != null : "Wrong ASSERTIONS_MODE value: " + flagValueString; + configuration.put(JVMConfigurationKeys.ASSERTIONS_MODE, mode); + } } } diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 32e7a38680d..08216ff9454 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -700,6 +700,145 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } + @TestMetadata("compiler/testData/codegen/box/assert") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Assert extends AbstractIrBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInAssert() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/assert"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("alwaysDisable.kt") + public void testAlwaysDisable() throws Exception { + runTest("compiler/testData/codegen/box/assert/alwaysDisable.kt"); + } + + @TestMetadata("alwaysEnable.kt") + public void testAlwaysEnable() throws Exception { + runTest("compiler/testData/codegen/box/assert/alwaysEnable.kt"); + } + + @TestMetadata("legacy.kt") + public void testLegacy() throws Exception { + runTest("compiler/testData/codegen/box/assert/legacy.kt"); + } + + @TestMetadata("compiler/testData/codegen/box/assert/jvm") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Jvm extends AbstractIrBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInJvm() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/assert/jvm"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("interfaceAssertionsDisabled.kt") + public void testInterfaceAssertionsDisabled() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/interfaceAssertionsDisabled.kt"); + } + + @TestMetadata("interfaceAssertionsEnabled.kt") + public void testInterfaceAssertionsEnabled() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/interfaceAssertionsEnabled.kt"); + } + + @TestMetadata("localAnonymousFunction.kt") + public void testLocalAnonymousFunction() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localAnonymousFunction.kt"); + } + + @TestMetadata("localClass.kt") + public void testLocalClass() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localClass.kt"); + } + + @TestMetadata("localFunction.kt") + public void testLocalFunction() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localFunction.kt"); + } + + @TestMetadata("localLambda.kt") + public void testLocalLambda() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localLambda.kt"); + } + + @TestMetadata("localObject.kt") + public void testLocalObject() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localObject.kt"); + } + + @TestMetadata("nonLocalReturn.kt") + public void testNonLocalReturn() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/nonLocalReturn.kt"); + } + + @TestMetadata("ordinary.kt") + public void testOrdinary() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/ordinary.kt"); + } + + @TestMetadata("superClassInitializer.kt") + public void testSuperClassInitializer() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/superClassInitializer.kt"); + } + + @TestMetadata("suspendFunctionAssertionDisabled.kt") + public void testSuspendFunctionAssertionDisabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + + @TestMetadata("suspendFunctionAssertionDisabled.kt") + public void testSuspendFunctionAssertionDisabled_1_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines"); + } + + @TestMetadata("suspendFunctionAssertionsEnabled.kt") + public void testSuspendFunctionAssertionsEnabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + + @TestMetadata("suspendFunctionAssertionsEnabled.kt") + public void testSuspendFunctionAssertionsEnabled_1_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines"); + } + + @TestMetadata("suspendLambdaAssertionsDisabled.kt") + public void testSuspendLambdaAssertionsDisabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + + @TestMetadata("suspendLambdaAssertionsDisabled.kt") + public void testSuspendLambdaAssertionsDisabled_1_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines"); + } + + @TestMetadata("suspendLambdaAssertionsEnabled.kt") + public void testSuspendLambdaAssertionsEnabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + + @TestMetadata("suspendLambdaAssertionsEnabled.kt") + public void testSuspendLambdaAssertionsEnabled_1_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines"); + } + } + } + @TestMetadata("compiler/testData/codegen/box/binaryOp") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java index dad266938e2..f5a5b57ea72 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxInlineCodegenTestGenerated.java @@ -603,6 +603,39 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli } } + @TestMetadata("compiler/testData/codegen/boxInline/assert") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Assert extends AbstractIrBlackBoxInlineCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInAssert() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/assert"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("jvmAssertInlineFunctionAssertionsDisabled.kt") + public void testJvmAssertInlineFunctionAssertionsDisabled() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsDisabled.kt"); + } + + @TestMetadata("jvmAssertInlineFunctionAssertionsEnabled.kt") + public void testJvmAssertInlineFunctionAssertionsEnabled() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsEnabled.kt"); + } + + @TestMetadata("jvmAssertInlineLambda.kt") + public void testJvmAssertInlineLambda() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmAssertInlineLambda.kt"); + } + + @TestMetadata("jvmCrossinlineLambda.kt") + public void testJvmCrossinlineLambda() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmCrossinlineLambda.kt"); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/builders") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java index be0bbc95cd3..bbc017d6c05 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrCompileKotlinAgainstInlineKotlinTestGenerated.java @@ -603,6 +603,39 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC } } + @TestMetadata("compiler/testData/codegen/boxInline/assert") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Assert extends AbstractIrCompileKotlinAgainstInlineKotlinTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInAssert() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/assert"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("jvmAssertInlineFunctionAssertionsDisabled.kt") + public void testJvmAssertInlineFunctionAssertionsDisabled() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsDisabled.kt"); + } + + @TestMetadata("jvmAssertInlineFunctionAssertionsEnabled.kt") + public void testJvmAssertInlineFunctionAssertionsEnabled() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsEnabled.kt"); + } + + @TestMetadata("jvmAssertInlineLambda.kt") + public void testJvmAssertInlineLambda() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmAssertInlineLambda.kt"); + } + + @TestMetadata("jvmCrossinlineLambda.kt") + public void testJvmCrossinlineLambda() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmCrossinlineLambda.kt"); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/builders") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index fd1126b388b..1de808e96fe 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -700,6 +700,145 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @TestMetadata("compiler/testData/codegen/box/assert") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Assert extends AbstractBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInAssert() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/assert"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("alwaysDisable.kt") + public void testAlwaysDisable() throws Exception { + runTest("compiler/testData/codegen/box/assert/alwaysDisable.kt"); + } + + @TestMetadata("alwaysEnable.kt") + public void testAlwaysEnable() throws Exception { + runTest("compiler/testData/codegen/box/assert/alwaysEnable.kt"); + } + + @TestMetadata("legacy.kt") + public void testLegacy() throws Exception { + runTest("compiler/testData/codegen/box/assert/legacy.kt"); + } + + @TestMetadata("compiler/testData/codegen/box/assert/jvm") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Jvm extends AbstractBlackBoxCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInJvm() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/assert/jvm"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("interfaceAssertionsDisabled.kt") + public void testInterfaceAssertionsDisabled() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/interfaceAssertionsDisabled.kt"); + } + + @TestMetadata("interfaceAssertionsEnabled.kt") + public void testInterfaceAssertionsEnabled() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/interfaceAssertionsEnabled.kt"); + } + + @TestMetadata("localAnonymousFunction.kt") + public void testLocalAnonymousFunction() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localAnonymousFunction.kt"); + } + + @TestMetadata("localClass.kt") + public void testLocalClass() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localClass.kt"); + } + + @TestMetadata("localFunction.kt") + public void testLocalFunction() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localFunction.kt"); + } + + @TestMetadata("localLambda.kt") + public void testLocalLambda() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localLambda.kt"); + } + + @TestMetadata("localObject.kt") + public void testLocalObject() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localObject.kt"); + } + + @TestMetadata("nonLocalReturn.kt") + public void testNonLocalReturn() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/nonLocalReturn.kt"); + } + + @TestMetadata("ordinary.kt") + public void testOrdinary() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/ordinary.kt"); + } + + @TestMetadata("superClassInitializer.kt") + public void testSuperClassInitializer() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/superClassInitializer.kt"); + } + + @TestMetadata("suspendFunctionAssertionDisabled.kt") + public void testSuspendFunctionAssertionDisabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + + @TestMetadata("suspendFunctionAssertionDisabled.kt") + public void testSuspendFunctionAssertionDisabled_1_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines"); + } + + @TestMetadata("suspendFunctionAssertionsEnabled.kt") + public void testSuspendFunctionAssertionsEnabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + + @TestMetadata("suspendFunctionAssertionsEnabled.kt") + public void testSuspendFunctionAssertionsEnabled_1_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines"); + } + + @TestMetadata("suspendLambdaAssertionsDisabled.kt") + public void testSuspendLambdaAssertionsDisabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + + @TestMetadata("suspendLambdaAssertionsDisabled.kt") + public void testSuspendLambdaAssertionsDisabled_1_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines"); + } + + @TestMetadata("suspendLambdaAssertionsEnabled.kt") + public void testSuspendLambdaAssertionsEnabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + + @TestMetadata("suspendLambdaAssertionsEnabled.kt") + public void testSuspendLambdaAssertionsEnabled_1_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines"); + } + } + } + @TestMetadata("compiler/testData/codegen/box/binaryOp") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index d87ee0d9e18..dba9d993c50 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -603,6 +603,39 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo } } + @TestMetadata("compiler/testData/codegen/boxInline/assert") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Assert extends AbstractBlackBoxInlineCodegenTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInAssert() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/assert"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("jvmAssertInlineFunctionAssertionsDisabled.kt") + public void testJvmAssertInlineFunctionAssertionsDisabled() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsDisabled.kt"); + } + + @TestMetadata("jvmAssertInlineFunctionAssertionsEnabled.kt") + public void testJvmAssertInlineFunctionAssertionsEnabled() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsEnabled.kt"); + } + + @TestMetadata("jvmAssertInlineLambda.kt") + public void testJvmAssertInlineLambda() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmAssertInlineLambda.kt"); + } + + @TestMetadata("jvmCrossinlineLambda.kt") + public void testJvmCrossinlineLambda() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmCrossinlineLambda.kt"); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/builders") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index 524df7b44e6..ec6e5831a7f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -603,6 +603,39 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi } } + @TestMetadata("compiler/testData/codegen/boxInline/assert") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Assert extends AbstractCompileKotlinAgainstInlineKotlinTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath); + } + + public void testAllFilesPresentInAssert() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/assert"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("jvmAssertInlineFunctionAssertionsDisabled.kt") + public void testJvmAssertInlineFunctionAssertionsDisabled() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsDisabled.kt"); + } + + @TestMetadata("jvmAssertInlineFunctionAssertionsEnabled.kt") + public void testJvmAssertInlineFunctionAssertionsEnabled() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmAssertInlineFunctionAssertionsEnabled.kt"); + } + + @TestMetadata("jvmAssertInlineLambda.kt") + public void testJvmAssertInlineLambda() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmAssertInlineLambda.kt"); + } + + @TestMetadata("jvmCrossinlineLambda.kt") + public void testJvmCrossinlineLambda() throws Exception { + runTest("compiler/testData/codegen/boxInline/assert/jvmCrossinlineLambda.kt"); + } + } + @TestMetadata("compiler/testData/codegen/boxInline/builders") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 852fe8c233e..20d495db09f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -700,6 +700,145 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes } } + @TestMetadata("compiler/testData/codegen/box/assert") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Assert extends AbstractLightAnalysisModeTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInAssert() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/assert"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("alwaysDisable.kt") + public void testAlwaysDisable() throws Exception { + runTest("compiler/testData/codegen/box/assert/alwaysDisable.kt"); + } + + @TestMetadata("alwaysEnable.kt") + public void testAlwaysEnable() throws Exception { + runTest("compiler/testData/codegen/box/assert/alwaysEnable.kt"); + } + + @TestMetadata("legacy.kt") + public void testLegacy() throws Exception { + runTest("compiler/testData/codegen/box/assert/legacy.kt"); + } + + @TestMetadata("compiler/testData/codegen/box/assert/jvm") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Jvm extends AbstractLightAnalysisModeTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInJvm() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/assert/jvm"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true); + } + + @TestMetadata("interfaceAssertionsDisabled.kt") + public void testInterfaceAssertionsDisabled() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/interfaceAssertionsDisabled.kt"); + } + + @TestMetadata("interfaceAssertionsEnabled.kt") + public void testInterfaceAssertionsEnabled() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/interfaceAssertionsEnabled.kt"); + } + + @TestMetadata("localAnonymousFunction.kt") + public void testLocalAnonymousFunction() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localAnonymousFunction.kt"); + } + + @TestMetadata("localClass.kt") + public void testLocalClass() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localClass.kt"); + } + + @TestMetadata("localFunction.kt") + public void testLocalFunction() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localFunction.kt"); + } + + @TestMetadata("localLambda.kt") + public void testLocalLambda() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localLambda.kt"); + } + + @TestMetadata("localObject.kt") + public void testLocalObject() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localObject.kt"); + } + + @TestMetadata("nonLocalReturn.kt") + public void testNonLocalReturn() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/nonLocalReturn.kt"); + } + + @TestMetadata("ordinary.kt") + public void testOrdinary() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/ordinary.kt"); + } + + @TestMetadata("superClassInitializer.kt") + public void testSuperClassInitializer() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/superClassInitializer.kt"); + } + + @TestMetadata("suspendFunctionAssertionDisabled.kt") + public void testSuspendFunctionAssertionDisabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + + @TestMetadata("suspendFunctionAssertionDisabled.kt") + public void testSuspendFunctionAssertionDisabled_1_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines"); + } + + @TestMetadata("suspendFunctionAssertionsEnabled.kt") + public void testSuspendFunctionAssertionsEnabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + + @TestMetadata("suspendFunctionAssertionsEnabled.kt") + public void testSuspendFunctionAssertionsEnabled_1_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines"); + } + + @TestMetadata("suspendLambdaAssertionsDisabled.kt") + public void testSuspendLambdaAssertionsDisabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + + @TestMetadata("suspendLambdaAssertionsDisabled.kt") + public void testSuspendLambdaAssertionsDisabled_1_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines"); + } + + @TestMetadata("suspendLambdaAssertionsEnabled.kt") + public void testSuspendLambdaAssertionsEnabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + + @TestMetadata("suspendLambdaAssertionsEnabled.kt") + public void testSuspendLambdaAssertionsEnabled_1_3() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt"); + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines"); + } + } + } + @TestMetadata("compiler/testData/codegen/box/binaryOp") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index dab74ddafe6..5ec2f0dc4a8 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -690,6 +690,145 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } + @TestMetadata("compiler/testData/codegen/box/assert") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Assert extends AbstractJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath); + } + + public void testAllFilesPresentInAssert() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/assert"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("alwaysDisable.kt") + public void testAlwaysDisable() throws Exception { + runTest("compiler/testData/codegen/box/assert/alwaysDisable.kt"); + } + + @TestMetadata("alwaysEnable.kt") + public void testAlwaysEnable() throws Exception { + runTest("compiler/testData/codegen/box/assert/alwaysEnable.kt"); + } + + @TestMetadata("legacy.kt") + public void testLegacy() throws Exception { + runTest("compiler/testData/codegen/box/assert/legacy.kt"); + } + + @TestMetadata("compiler/testData/codegen/box/assert/jvm") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Jvm extends AbstractJsCodegenBoxTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath); + } + + public void testAllFilesPresentInJvm() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/assert/jvm"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true); + } + + @TestMetadata("interfaceAssertionsDisabled.kt") + public void testInterfaceAssertionsDisabled() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/interfaceAssertionsDisabled.kt"); + } + + @TestMetadata("interfaceAssertionsEnabled.kt") + public void testInterfaceAssertionsEnabled() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/interfaceAssertionsEnabled.kt"); + } + + @TestMetadata("localAnonymousFunction.kt") + public void testLocalAnonymousFunction() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localAnonymousFunction.kt"); + } + + @TestMetadata("localClass.kt") + public void testLocalClass() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localClass.kt"); + } + + @TestMetadata("localFunction.kt") + public void testLocalFunction() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localFunction.kt"); + } + + @TestMetadata("localLambda.kt") + public void testLocalLambda() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localLambda.kt"); + } + + @TestMetadata("localObject.kt") + public void testLocalObject() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/localObject.kt"); + } + + @TestMetadata("nonLocalReturn.kt") + public void testNonLocalReturn() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/nonLocalReturn.kt"); + } + + @TestMetadata("ordinary.kt") + public void testOrdinary() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/ordinary.kt"); + } + + @TestMetadata("superClassInitializer.kt") + public void testSuperClassInitializer() throws Exception { + runTest("compiler/testData/codegen/box/assert/jvm/superClassInitializer.kt"); + } + + @TestMetadata("suspendFunctionAssertionDisabled.kt") + public void testSuspendFunctionAssertionDisabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionDisabled.kt"); + try { + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("suspendFunctionAssertionsEnabled.kt") + public void testSuspendFunctionAssertionsEnabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendFunctionAssertionsEnabled.kt"); + try { + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("suspendLambdaAssertionsDisabled.kt") + public void testSuspendLambdaAssertionsDisabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsDisabled.kt"); + try { + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + + @TestMetadata("suspendLambdaAssertionsEnabled.kt") + public void testSuspendLambdaAssertionsEnabled_1_2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/assert/jvm/suspendLambdaAssertionsEnabled.kt"); + try { + doTestWithCoroutinesPackageReplacement(fileName, "kotlin.coroutines.experimental"); + } + catch (Throwable ignore) { + return; + } + throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that."); + } + } + } + @TestMetadata("compiler/testData/codegen/box/binaryOp") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)