Remove LANGUAGE_VERSION from codegen tests on coroutines

Use `// !LANGUAGE: -ReleaseCoroutines` instead in tests which require
old (1.2) coroutines, and nothing in tests which require new coroutines
because master is already 1.3. Also remove superfluous API_VERSION and
other directives which have no effect anymore. Do not include runtime
automatically with `WITH_COROUTINES`/`COMMON_COROUTINES_TEST` in box
tests; require `WITH_RUNTIME` for that (majority of tests already had it
anyway), but remove it from bytecode text tests where runtime is always
added automatically. Fix the coroutine package selection code in
KotlinTestUtils and update the bunch files correspondingly.

Disable tests in `box/coroutines/noStdLib` on JVM: despite the name,
these tests were launched with stdlib because of the code in
CodegenTestCase, and they do not work without it because at least
CoroutineUtil.kt requires stdlib to compile correctly
This commit is contained in:
Alexander Udalov
2018-12-17 17:35:08 +01:00
parent 5b58eb8491
commit ec2dd58165
75 changed files with 173 additions and 324 deletions
@@ -18,8 +18,8 @@ import kotlin.script.experimental.dependencies.ScriptDependencies;
import kotlin.text.Charsets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.TestsCompiletimeError;
import org.jetbrains.kotlin.TestsCompilerError;
import org.jetbrains.kotlin.TestsCompiletimeError;
import org.jetbrains.kotlin.backend.common.output.OutputFile;
import org.jetbrains.kotlin.backend.common.output.SimpleOutputFileCollection;
import org.jetbrains.kotlin.checkers.CheckerTestUtil;
@@ -70,7 +70,6 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.jetbrains.kotlin.checkers.CompilerTestLanguageVersionSettingsKt.API_VERSION_DIRECTIVE;
import static org.jetbrains.kotlin.checkers.CompilerTestLanguageVersionSettingsKt.parseLanguageVersionSettings;
import static org.jetbrains.kotlin.cli.common.output.OutputUtilsKt.writeAllTo;
import static org.jetbrains.kotlin.codegen.CodegenTestUtil.*;
@@ -724,13 +723,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
protected ConfigurationKind extractConfigurationKind(@NotNull List<TestFile> files) {
boolean addRuntime = false;
boolean addReflect = false;
boolean addCoroutines = false;
for (TestFile file : files) {
if (InTextDirectivesUtils.isDirectiveDefined(file.content, "COMMON_COROUTINES_TEST") ||
InTextDirectivesUtils.isDirectiveDefined(file.content, "!LANGUAGE: +ReleaseCoroutines") ||
InTextDirectivesUtils.isDirectiveDefined(file.content, "LANGUAGE_VERSION: 1.3")) {
addCoroutines = true;
}
if (InTextDirectivesUtils.isDirectiveDefined(file.content, "WITH_RUNTIME")) {
addRuntime = true;
}
@@ -740,7 +733,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
}
return addReflect ? ConfigurationKind.ALL :
(addRuntime || addCoroutines) ? ConfigurationKind.NO_KOTLIN_REFLECT :
addRuntime ? ConfigurationKind.NO_KOTLIN_REFLECT :
ConfigurationKind.JDK_ONLY;
}
@@ -798,14 +798,10 @@ public class KotlinTestUtils {
if (isDirectiveDefined(expectedText, "WITH_COROUTINES")) {
M supportModule = hasModules ? factory.createModule("support", Collections.emptyList(), Collections.emptyList()) : null;
if (coroutinesPackage.isEmpty()) {
coroutinesPackage = "kotlin.coroutines.experimental";
}
boolean isReleaseCoroutines =
!coroutinesPackage.contains("experimental") ||
isDirectiveDefined(expectedText, "LANGUAGE_VERSION: 1.3") ||
isDirectiveDefined(expectedText, "!LANGUAGE: +ReleaseCoroutines");
!coroutinesPackage.contains("experimental") &&
!isDirectiveDefined(expectedText, "!LANGUAGE: -ReleaseCoroutines");
testFiles.add(factory.createFile(supportModule,
"CoroutineUtil.kt",
@@ -36,6 +36,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.kotlin.CoroutineTestUtilKt;
import org.jetbrains.kotlin.analyzer.AnalysisResult;
import org.jetbrains.kotlin.builtins.DefaultBuiltIns;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
@@ -793,36 +794,14 @@ public class KotlinTestUtils {
if (isDirectiveDefined(expectedText, "WITH_COROUTINES")) {
M supportModule = hasModules ? factory.createModule("support", Collections.emptyList(), Collections.emptyList()) : null;
if (coroutinesPackage.isEmpty()) {
coroutinesPackage = "kotlin.coroutines.experimental";
}
boolean isReleaseCoroutines =
!coroutinesPackage.contains("experimental") &&
!isDirectiveDefined(expectedText, "!LANGUAGE: -ReleaseCoroutines");
testFiles.add(factory.createFile(supportModule,
"CoroutineUtil.kt",
"package helpers\n" +
"import " + coroutinesPackage + ".*\n" +
"fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {\n" +
" override val context = EmptyCoroutineContext\n" +
" override fun resumeWithException(exception: Throwable) {\n" +
" throw exception\n" +
" }\n" +
"\n" +
" override fun resume(data: T) = x(data)\n" +
"}\n" +
"\n" +
"fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation<Any?> = object: Continuation<Any?> {\n" +
" override val context = EmptyCoroutineContext\n" +
" override fun resumeWithException(exception: Throwable) {\n" +
" x(exception)\n" +
" }\n" +
"\n" +
" override fun resume(data: Any?) { }\n" +
"}\n" +
"\n" +
"open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {\n" +
" companion object : EmptyContinuation()\n" +
" override fun resume(data: Any?) {}\n" +
" override fun resumeWithException(exception: Throwable) { throw exception }\n" +
"}",
CoroutineTestUtilKt.createTextForHelpers(isReleaseCoroutines),
directives
));
}
@@ -35,6 +35,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.kotlin.CoroutineTestUtilKt;
import org.jetbrains.kotlin.analyzer.AnalysisResult;
import org.jetbrains.kotlin.builtins.DefaultBuiltIns;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
@@ -793,36 +794,14 @@ public class KotlinTestUtils {
if (isDirectiveDefined(expectedText, "WITH_COROUTINES")) {
M supportModule = hasModules ? factory.createModule("support", Collections.emptyList(), Collections.emptyList()) : null;
if (coroutinesPackage.isEmpty()) {
coroutinesPackage = "kotlin.coroutines.experimental";
}
boolean isReleaseCoroutines =
!coroutinesPackage.contains("experimental") &&
!isDirectiveDefined(expectedText, "!LANGUAGE: -ReleaseCoroutines");
testFiles.add(factory.createFile(supportModule,
"CoroutineUtil.kt",
"package helpers\n" +
"import " + coroutinesPackage + ".*\n" +
"fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {\n" +
" override val context = EmptyCoroutineContext\n" +
" override fun resumeWithException(exception: Throwable) {\n" +
" throw exception\n" +
" }\n" +
"\n" +
" override fun resume(data: T) = x(data)\n" +
"}\n" +
"\n" +
"fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation<Any?> = object: Continuation<Any?> {\n" +
" override val context = EmptyCoroutineContext\n" +
" override fun resumeWithException(exception: Throwable) {\n" +
" x(exception)\n" +
" }\n" +
"\n" +
" override fun resume(data: Any?) { }\n" +
"}\n" +
"\n" +
"open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {\n" +
" companion object : EmptyContinuation()\n" +
" override fun resume(data: Any?) {}\n" +
" override fun resumeWithException(exception: Throwable) { throw exception }\n" +
"}",
CoroutineTestUtilKt.createTextForHelpers(isReleaseCoroutines),
directives
));
}
@@ -35,6 +35,7 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
import org.jetbrains.kotlin.CoroutineTestUtilKt;
import org.jetbrains.kotlin.analyzer.AnalysisResult;
import org.jetbrains.kotlin.builtins.DefaultBuiltIns;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
@@ -793,36 +794,14 @@ public class KotlinTestUtils {
if (isDirectiveDefined(expectedText, "WITH_COROUTINES")) {
M supportModule = hasModules ? factory.createModule("support", Collections.emptyList(), Collections.emptyList()) : null;
if (coroutinesPackage.isEmpty()) {
coroutinesPackage = "kotlin.coroutines.experimental";
}
boolean isReleaseCoroutines =
!coroutinesPackage.contains("experimental") &&
!isDirectiveDefined(expectedText, "!LANGUAGE: -ReleaseCoroutines");
testFiles.add(factory.createFile(supportModule,
"CoroutineUtil.kt",
"package helpers\n" +
"import " + coroutinesPackage + ".*\n" +
"fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {\n" +
" override val context = EmptyCoroutineContext\n" +
" override fun resumeWithException(exception: Throwable) {\n" +
" throw exception\n" +
" }\n" +
"\n" +
" override fun resume(data: T) = x(data)\n" +
"}\n" +
"\n" +
"fun handleExceptionContinuation(x: (Throwable) -> Unit): Continuation<Any?> = object: Continuation<Any?> {\n" +
" override val context = EmptyCoroutineContext\n" +
" override fun resumeWithException(exception: Throwable) {\n" +
" x(exception)\n" +
" }\n" +
"\n" +
" override fun resume(data: Any?) { }\n" +
"}\n" +
"\n" +
"open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {\n" +
" companion object : EmptyContinuation()\n" +
" override fun resume(data: Any?) {}\n" +
" override fun resumeWithException(exception: Throwable) { throw exception }\n" +
"}",
CoroutineTestUtilKt.createTextForHelpers(isReleaseCoroutines),
directives
));
}