Move coroutines to kotlin.coroutines package: tests
Introduce COMMON_COROUTINES_TEST directive. Every test with this directive is run twice: one time with language version 1.2 and kotlin.coroutines.experimental package and the other time with language version 1.3 and kotlin.coroutines package. Each run is a separate method: with suffixes _1_2 and _1_3 respectively. However, since codegen of release coroutines is not supported in JS backend, we generate only one method: with suffix _1_2. #KT-23362
This commit is contained in:
+23
-20
@@ -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;
|
||||
@@ -20,6 +9,7 @@ import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.generators.util.CoroutinesKt;
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TargetBackend;
|
||||
import org.jetbrains.kotlin.utils.Printer;
|
||||
@@ -146,10 +136,16 @@ public class SimpleTestClassModel implements TestClassModel {
|
||||
public Collection<MethodModel> getMethods() {
|
||||
if (testMethods == null) {
|
||||
if (!rootFile.isDirectory()) {
|
||||
testMethods = Collections.singletonList(new SimpleTestMethodModel(
|
||||
rootFile, rootFile, filenamePattern,
|
||||
checkFilenameStartsLowerCase, targetBackend, skipIgnored
|
||||
));
|
||||
if (CoroutinesKt.isCommonCoroutineTest(rootFile)) {
|
||||
testMethods = CoroutinesKt.createCommonCoroutinesTestMethodModels(rootFile, rootFile, doTestMethodName, filenamePattern,
|
||||
checkFilenameStartsLowerCase, targetBackend,
|
||||
skipIgnored);
|
||||
}
|
||||
else {
|
||||
testMethods = Collections.singletonList(new SimpleTestMethodModel(
|
||||
rootFile, rootFile, filenamePattern, checkFilenameStartsLowerCase, targetBackend, skipIgnored
|
||||
));
|
||||
}
|
||||
}
|
||||
else {
|
||||
List<MethodModel> result = new ArrayList<>();
|
||||
@@ -167,9 +163,16 @@ public class SimpleTestClassModel implements TestClassModel {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.add(new SimpleTestMethodModel(
|
||||
rootFile, file, filenamePattern,
|
||||
checkFilenameStartsLowerCase, targetBackend, skipIgnored));
|
||||
if (!file.isDirectory() && CoroutinesKt.isCommonCoroutineTest(file)) {
|
||||
result.addAll(CoroutinesKt.createCommonCoroutinesTestMethodModels(rootFile, file, doTestMethodName,
|
||||
filenamePattern,
|
||||
checkFilenameStartsLowerCase,
|
||||
targetBackend, skipIgnored));
|
||||
}
|
||||
else {
|
||||
result.add(new SimpleTestMethodModel(rootFile, file, filenamePattern,
|
||||
checkFilenameStartsLowerCase, targetBackend, skipIgnored));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -25,11 +25,11 @@ public class SimpleTestMethodModel implements TestMethodModel {
|
||||
@NotNull
|
||||
private final File rootDir;
|
||||
@NotNull
|
||||
private final File file;
|
||||
protected final File file;
|
||||
@NotNull
|
||||
private final Pattern filenamePattern;
|
||||
@NotNull
|
||||
private final TargetBackend targetBackend;
|
||||
protected final TargetBackend targetBackend;
|
||||
|
||||
private final boolean skipIgnored;
|
||||
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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.util
|
||||
|
||||
import org.jetbrains.kotlin.generators.tests.generator.MethodModel
|
||||
import org.jetbrains.kotlin.generators.tests.generator.SimpleTestMethodModel
|
||||
import org.jetbrains.kotlin.test.InTextDirectivesUtils.isIgnoredTarget
|
||||
import org.jetbrains.kotlin.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.test.TargetBackend
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import java.io.File
|
||||
import java.util.regex.Pattern
|
||||
|
||||
class CoroutinesTestModel(
|
||||
rootDir: File,
|
||||
file: File,
|
||||
private val doTestMethodName: String,
|
||||
filenamePattern: Pattern,
|
||||
checkFilenameStartsLowerCase: Boolean?,
|
||||
targetBackend: TargetBackend,
|
||||
skipIgnored: Boolean,
|
||||
private val isLanguageVersion1_3: Boolean
|
||||
) : SimpleTestMethodModel(
|
||||
rootDir,
|
||||
file,
|
||||
filenamePattern,
|
||||
checkFilenameStartsLowerCase,
|
||||
targetBackend,
|
||||
skipIgnored
|
||||
) {
|
||||
override val name: String
|
||||
get() = super.name + if (isLanguageVersion1_3) "_1_3" else "_1_2"
|
||||
|
||||
override fun generateBody(p: Printer) {
|
||||
val filePath = KotlinTestUtils.getFilePath(file) + if (file.isDirectory) "/" else ""
|
||||
p.println("String fileName = KotlinTestUtils.navigationMetadata(\"", filePath, "\");")
|
||||
|
||||
if (isIgnoredTarget(targetBackend, file)) {
|
||||
p.println("try {")
|
||||
p.pushIndent()
|
||||
}
|
||||
|
||||
val packageName = if (isLanguageVersion1_3) "kotlin.coroutines" else "kotlin.coroutines.experimental"
|
||||
p.println(doTestMethodName + "WithCoroutinesPackageReplacement", "(fileName, \"$packageName\");")
|
||||
|
||||
if (isIgnoredTarget(targetBackend, file)) {
|
||||
p.popIndent()
|
||||
p.println("}")
|
||||
p.println("catch (Throwable ignore) {")
|
||||
p.pushIndent()
|
||||
p.println("return;")
|
||||
p.popIndent()
|
||||
p.println("}")
|
||||
p.println("throw new AssertionError(\"Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.\");")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun isCommonCoroutineTest(file: File): Boolean {
|
||||
return file.readLines().any { it.startsWith("// COMMON_COROUTINES_TEST") }
|
||||
}
|
||||
|
||||
fun createCommonCoroutinesTestMethodModels(
|
||||
rootDir: File,
|
||||
file: File,
|
||||
doTestMethodName: String,
|
||||
filenamePattern: Pattern,
|
||||
checkFilenameStartsLowerCase: Boolean?,
|
||||
targetBackend: TargetBackend,
|
||||
skipIgnored: Boolean
|
||||
): Collection<MethodModel> {
|
||||
return if (targetBackend == TargetBackend.JS)
|
||||
listOf(
|
||||
CoroutinesTestModel(
|
||||
rootDir,
|
||||
file,
|
||||
doTestMethodName,
|
||||
filenamePattern,
|
||||
checkFilenameStartsLowerCase,
|
||||
targetBackend,
|
||||
skipIgnored,
|
||||
false
|
||||
)
|
||||
)
|
||||
else
|
||||
listOf(
|
||||
CoroutinesTestModel(
|
||||
rootDir,
|
||||
file,
|
||||
doTestMethodName,
|
||||
filenamePattern,
|
||||
checkFilenameStartsLowerCase,
|
||||
targetBackend,
|
||||
skipIgnored,
|
||||
true
|
||||
),
|
||||
CoroutinesTestModel(
|
||||
rootDir,
|
||||
file,
|
||||
doTestMethodName,
|
||||
filenamePattern,
|
||||
checkFilenameStartsLowerCase,
|
||||
targetBackend,
|
||||
skipIgnored,
|
||||
false
|
||||
)
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user