Implement new assert semantics in back-end

Previously, assert was just a regular function and its argument used to
be computed on each call (even if assertions are disabled on JVM).
This change adds support for 3 new behaviours of assert:
* always-enable (independently from -ea on JVM)
* always-disable (independently from -ea JVM)
* runtime/jvm (compile the calls like javac generates assert-operator)
* legacy (leave current eager semantics) - this already existed

Default behaviour is legacy for now.

The behavior is changed based on -Xassertions flag.
 #KT-7540: Fixed
This commit is contained in:
Ilmir Usmanov
2018-04-28 22:15:29 +03:00
parent 3f5a2c6427
commit f568149863
44 changed files with 2685 additions and 33 deletions
@@ -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, "<init>", "(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, "<init>", "(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<FunctionDescriptor>).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 <D : FunctionDescriptor> ResolvedCall<D>.replaceAssertWithAssertInner(): ResolvedCall<D> {
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
}
@@ -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<StackValue, StackValue> 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;
@@ -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<T extends KtPureElement/* TODO: & KtDeclarat
private ExpressionCodegen clInit;
private NameGenerator inlineNameGenerator;
private boolean jvmAssertFieldGenerated;
private DefaultSourceMapper sourceMapper;
@@ -111,6 +113,7 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
this.functionCodegen = new FunctionCodegen(context, v, state, this);
this.propertyCodegen = new PropertyCodegen(context, v, functionCodegen, this);
this.parentCodegen = parentCodegen;
this.jvmAssertFieldGenerated = false;
}
protected MemberCodegen(@NotNull MemberCodegen<T> wrapped, T declaration, FieldOwnerContext codegenContext) {
@@ -873,4 +876,10 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
return Unit.INSTANCE;
});
}
public void generateAssertField() {
if (jvmAssertFieldGenerated) return;
AssertCodegenUtilKt.generateAssertionsDisabledFieldInitialization(this);
jvmAssertFieldGenerated = true;
}
}
@@ -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
@@ -235,7 +224,7 @@ fun getClosedFloatingPointRangeElementType(rangeType: KotlinType): KotlinType? {
return rangeType.arguments.singleOrNull()?.type
}
private fun DeclarationDescriptor.isTopLevelInPackage(name: String, packageName: String): Boolean {
fun DeclarationDescriptor.isTopLevelInPackage(name: String, packageName: String): Boolean {
if (name != this.name.asString()) return false
val containingDeclaration = containingDeclaration as? PackageFragmentDescriptor ?: return false
@@ -493,6 +493,11 @@ abstract class InlineCodegen<out T : BaseExpressionCodegen>(
),
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)
@@ -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(
@@ -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)
@@ -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",
@@ -361,6 +361,20 @@ class K2JVMCompiler : CLICompiler<K2JVMCompilerArguments>() {
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)
@@ -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 }
}
}
@@ -65,6 +65,8 @@ public class JVMConfigurationKeys {
CompilerConfigurationKey.create("disable not-null call receiver assertions");
public static final CompilerConfigurationKey<Boolean> DISABLE_PARAM_ASSERTIONS =
CompilerConfigurationKey.create("disable not-null parameter assertions");
public static final CompilerConfigurationKey<JVMAssertionsMode> ASSERTIONS_MODE =
CompilerConfigurationKey.create("assertions mode");
public static final CompilerConfigurationKey<JVMConstructorCallNormalizationMode> CONSTRUCTOR_CALL_NORMALIZATION_MODE =
CompilerConfigurationKey.create("constructor call normalization mode");
public static final CompilerConfigurationKey<Boolean> NO_EXCEPTION_ON_EXPLICIT_EQUALS_FOR_BOXED_NULL =
+7
View File
@@ -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=<module[,]> Root modules to resolve in addition to the initial modules,
or all modules on the module path if <module> 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> Path to the .xml build file to compile
-Xcompile-java Reuse javac analysis and compile Java source files
-Xnormalize-constructor-calls={disable|enable}
+40
View File
@@ -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"
}
+48
View File
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
+164
View File
@@ -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"
}
@@ -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"
}
+124
View File
@@ -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"
}
+156
View File
@@ -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"
}
@@ -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"
}
+100
View File
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
+76
View File
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -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"
}
@@ -1,3 +1,4 @@
// KOTLIN_CONFIGURATION_FLAGS: ASSERTIONS_MODE=legacy
fun foo() {
assert(1 == 1) { "Hahaha" }
}
@@ -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
@@ -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<String> 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);
}
}
}
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)
@@ -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)