Do not support LANGUAGE_VERSION directive in codegen tests

Test data of crossinline_1_2.txt has changed because now we do not
automatically enable 1.2 (with _all_ of its features) when we're
executing a common coroutines test with old coroutines; and so the
NewCapturedReceiverFieldNamingConvention language feature (which is
introduced in 1.3) is now enabled in this test
This commit is contained in:
Alexander Udalov
2018-12-17 17:56:11 +01:00
parent 77c87fa6c9
commit 00caa23307
2 changed files with 23 additions and 29 deletions
@@ -167,7 +167,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
@NotNull String coroutinesPackage
) {
LanguageVersionSettings explicitLanguageVersionSettings = null;
LanguageVersion explicitLanguageVersion = null;
boolean disableReleaseCoroutines = false;
List<String> kotlinConfigurationFlags = new ArrayList<>(0);
for (TestFile testFile : testFilesWithConfigurationDirectives) {
@@ -183,17 +183,18 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
String version = InTextDirectivesUtils.findStringWithPrefixes(testFile.content, "// LANGUAGE_VERSION:");
if (version != null) {
assertDirectivesToNull(explicitLanguageVersionSettings, explicitLanguageVersion);
explicitLanguageVersion = LanguageVersion.fromVersionString(version);
throw new AssertionError(
"Do not use LANGUAGE_VERSION directive in compiler tests because it's prone to limiting the test\n" +
"to a specific language version, which will become obsolete at some point and the test won't check\n" +
"things like feature intersection with newer releases. Use `// !LANGUAGE: [+-]FeatureName` directive instead,\n" +
"where FeatureName is an entry of the enum `LanguageFeature`\n"
);
}
if (!InTextDirectivesUtils.findLinesWithPrefixesRemoved(testFile.content, "// COMMON_COROUTINES_TEST").isEmpty()) {
assert(!testFile.content.contains("COROUTINES_PACKAGE")) : "Must replace COROUTINES_PACKAGE prior to tests compilation";
if (!coroutinesPackage.isEmpty()) {
if (coroutinesPackage.equals("kotlin.coroutines.experimental")) {
explicitLanguageVersion = LanguageVersion.KOTLIN_1_2;
} else {
explicitLanguageVersion = LanguageVersion.KOTLIN_1_3;
}
assert !testFile.content.contains("COROUTINES_PACKAGE") : "Must replace COROUTINES_PACKAGE prior to tests compilation";
if (coroutinesPackage.equals("kotlin.coroutines.experimental")) {
disableReleaseCoroutines = true;
}
}
@@ -201,7 +202,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
LanguageVersionSettings fileLanguageVersionSettings = parseLanguageVersionSettings(directives);
if (fileLanguageVersionSettings != null) {
assertDirectivesToNull(explicitLanguageVersionSettings, null);
assert explicitLanguageVersionSettings == null : "Should not specify !LANGUAGE directive twice";
explicitLanguageVersionSettings = fileLanguageVersionSettings;
}
}
@@ -209,26 +210,19 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
if (explicitLanguageVersionSettings != null) {
CommonConfigurationKeysKt.setLanguageVersionSettings(configuration, explicitLanguageVersionSettings);
}
else if (explicitLanguageVersion != null) {
else if (disableReleaseCoroutines) {
CompilerTestLanguageVersionSettings compilerLanguageVersionSettings = new CompilerTestLanguageVersionSettings(
Collections.emptyMap(),
ApiVersion.createByLanguageVersion(explicitLanguageVersion),
explicitLanguageVersion,
Collections.singletonMap(LanguageFeature.ReleaseCoroutines, LanguageFeature.State.DISABLED),
ApiVersion.LATEST_STABLE,
LanguageVersion.LATEST_STABLE,
Collections.emptyMap()
);
CommonConfigurationKeysKt.setLanguageVersionSettings(
configuration,
compilerLanguageVersionSettings
);
CommonConfigurationKeysKt.setLanguageVersionSettings(configuration, compilerLanguageVersionSettings);
}
updateConfigurationWithFlags(configuration, kotlinConfigurationFlags);
}
private static void assertDirectivesToNull(@Nullable LanguageVersionSettings settings, @Nullable LanguageVersion version) {
assert settings == null && version == null : "Should not specify LANGUAGE_VERSION twice or together with !LANGUAGE directive";
}
private static final Map<String, Class<?>> FLAG_NAMESPACE_TO_CLASS = ImmutableMap.of(
"CLI", CLIConfigurationKeys.class,
"JVM", JVMConfigurationKeys.class