From 87ee373205898b7662adfd0aa4ff6b1ecb71632e Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Fri, 16 Mar 2018 01:38:26 +0300 Subject: [PATCH] Few improvements in test infrastructure: * add the way to specify another compatible target for target backend. It's used to generate a test for X_IR backend even when in a test data is explicitly written a target: "// TARGET_BACKEND: X". * Add the ability to run tests "ignored" with the "IGNORE_BACKEND" directive as regular tests, i.e. w/o catching exceptions. * Print stack trace of caught exception inside tests "ignored" with the "IGNORE_BACKEND" directive. --- .../kotlin/test/InTextDirectivesUtils.java | 2 +- .../kotlin/test/KotlinTestUtils.java | 18 ++++-------- .../jetbrains/kotlin/test/TargetBackend.kt | 7 +++-- .../generator/SimpleTestMethodModel.java | 29 +++++++++---------- 4 files changed, 25 insertions(+), 31 deletions(-) diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/InTextDirectivesUtils.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/InTextDirectivesUtils.java index 36b373b2fb2..3c8198129b2 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/InTextDirectivesUtils.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/InTextDirectivesUtils.java @@ -222,7 +222,7 @@ public final class InTextDirectivesUtils { if (targetBackend == TargetBackend.ANY) return true; List backends = findLinesWithPrefixesRemoved(textWithDirectives(file), "// TARGET_BACKEND: "); - return backends.isEmpty() || backends.contains(targetBackend.name()); + return backends.isEmpty() || backends.contains(targetBackend.name()) || backends.contains(targetBackend.getCompatibleWith().name()); } private static boolean isIgnoredTargetByPrefix(TargetBackend targetBackend, File file, String prefix) { diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java index 4a4cacc4fef..8bfb255c7b5 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -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.test; @@ -107,6 +96,9 @@ public class KotlinTestUtils { public static final String TEST_GENERATOR_NAME = "org.jetbrains.kotlin.generators.tests.TestsPackage"; public static final String PLEASE_REGENERATE_TESTS = "Please regenerate tests (GenerateTests.kt)"; + public static final boolean RUN_IGNORED_TESTS_AS_REGULAR = + Boolean.getBoolean("org.jetbrains.kotlin.run.ignored.tests.as.regular"); + private static final List filesToDelete = new ArrayList<>(); /** diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/test/TargetBackend.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/test/TargetBackend.kt index b47bbf4134b..1eaa77393d0 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/test/TargetBackend.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/test/TargetBackend.kt @@ -8,6 +8,7 @@ package org.jetbrains.kotlin.test import java.io.File enum class TargetBackend( + private val compatibleWithTargetBackend: TargetBackend? = null, // if whitelist === null it will not be used in test generator (will work as usual) // if path to testData file starts with or equals to any entry from whitelist it will be processed as usual // otherwise a testData file will be treated as ignored @@ -15,7 +16,9 @@ enum class TargetBackend( ) { ANY, JVM, - JVM_IR, + JVM_IR(JVM), JS, - JS_IR(JS_IR_BACKEND_TEST_WHITELIST); + JS_IR(JS, JS_IR_BACKEND_TEST_WHITELIST); + + val compatibleWith get() = compatibleWithTargetBackend ?: ANY } diff --git a/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SimpleTestMethodModel.java b/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SimpleTestMethodModel.java index e859409e01e..2ff081d5750 100644 --- a/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SimpleTestMethodModel.java +++ b/generators/test-generator/tests/org/jetbrains/kotlin/generators/tests/generator/SimpleTestMethodModel.java @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 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.generators.tests.generator; @@ -79,18 +68,28 @@ public class SimpleTestMethodModel implements TestMethodModel { String filePath = KotlinTestUtils.getFilePath(file) + (file.isDirectory() ? "/" : ""); p.println("String fileName = KotlinTestUtils.navigationMetadata(\"", filePath, "\");"); - if (isIgnoredTarget(targetBackend, file)) { + boolean ignoredTarget = isIgnoredTarget(targetBackend, file); + + if (ignoredTarget) { + p.println("if (KotlinTestUtils.RUN_IGNORED_TESTS_AS_REGULAR) {"); + p.pushIndent(); + p.println(doTestMethodName, "(fileName);"); + p.println("return;"); + p.popIndent(); + p.println("}"); + p.println("try {"); p.pushIndent(); } p.println(doTestMethodName, "(fileName);"); - if (isIgnoredTarget(targetBackend, file)) { + if (ignoredTarget) { p.popIndent(); p.println("}"); p.println("catch (Throwable ignore) {"); p.pushIndent(); + p.println("ignore.printStackTrace();"); p.println("return;"); p.popIndent(); p.println("}");