Take coroutinesPackage into account in bunch files

#KT-23362
This commit is contained in:
Ilmir Usmanov
2018-04-24 16:48:14 +03:00
parent 258cba2cf8
commit ce40c3fb21
5 changed files with 53 additions and 34 deletions
+1 -1
View File
@@ -12,7 +12,7 @@ import proguard.gradle.ProGuardTask
buildscript { buildscript {
extra["defaultSnapshotVersion"] = "1.2-SNAPSHOT" extra["defaultSnapshotVersion"] = "1.2-SNAPSHOT"
kotlinBootstrapFrom(BootstrapOption.TeamCity("1.2.50-dev-310", onlySuccessBootstrap = false)) kotlinBootstrapFrom(BootstrapOption.TeamCity("1.2.50-dev-880", onlySuccessBootstrap = false))
val mirrorRepo: String? = findProperty("maven.repository.mirror")?.toString() val mirrorRepo: String? = findProperty("maven.repository.mirror")?.toString()
@@ -1,17 +1,6 @@
/* /*
* Copyright 2010-2017 JetBrains s.r.o. * 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.
* 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.
*/ */
package org.jetbrains.kotlin.checkers package org.jetbrains.kotlin.checkers
@@ -99,7 +88,14 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
val oldModule = modules[testModule]!! val oldModule = modules[testModule]!!
val languageVersionSettings = loadLanguageVersionSettings(testFilesInModule) val languageVersionSettings =
if (coroutinesPackage.isNotEmpty())
CompilerTestLanguageVersionSettings(
DEFAULT_DIAGNOSTIC_TESTS_FEATURES,
if (coroutinesPackage.contains("experimental")) ApiVersion.KOTLIN_1_2 else ApiVersion.KOTLIN_1_3,
if (coroutinesPackage.contains("experimental")) LanguageVersion.KOTLIN_1_2 else LanguageVersion.KOTLIN_1_3
)
else loadLanguageVersionSettings(testFilesInModule)
val moduleContext = context.withProject(project).withModule(oldModule) val moduleContext = context.withProject(project).withModule(oldModule)
val separateModules = groupedByModule.size == 1 && groupedByModule.keys.single() == null val separateModules = groupedByModule.size == 1 && groupedByModule.keys.single() == null
@@ -151,7 +147,7 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
else -> ".txt" else -> ".txt"
} }
val expectedFile = File(FileUtil.getNameWithoutExtension(testDataFile.absolutePath) + postfix) val expectedFile = File(FileUtil.getNameWithoutExtension(testDataFile.absolutePath) + postfix)
validateAndCompareDescriptorWithFile(expectedFile, files, modules) validateAndCompareDescriptorWithFile(expectedFile, files, modules, coroutinesPackage)
} catch (e: Throwable) { } catch (e: Throwable) {
exceptionFromDescriptorValidation = e exceptionFromDescriptorValidation = e
} }
@@ -185,7 +181,9 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
exceptionFromDynamicCallDescriptorsValidation = e exceptionFromDynamicCallDescriptorsValidation = e
} }
KotlinTestUtils.assertEqualsToFile(testDataFile, actualText.toString()) KotlinTestUtils.assertEqualsToFile(getExpectedDiagnosticsFile(testDataFile), actualText.toString()) { s ->
s.replace("COROUTINES_PACKAGE", coroutinesPackage)
}
assertTrue("Diagnostics mismatch. See the output above", ok) assertTrue("Diagnostics mismatch. See the output above", ok)
@@ -385,7 +383,8 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
private fun validateAndCompareDescriptorWithFile( private fun validateAndCompareDescriptorWithFile(
expectedFile: File, expectedFile: File,
testFiles: List<TestFile>, testFiles: List<TestFile>,
modules: Map<TestModule?, ModuleDescriptorImpl> modules: Map<TestModule?, ModuleDescriptorImpl>,
coroutinesPackage: String
) { ) {
if (skipDescriptorsValidation()) return if (skipDescriptorsValidation()) return
if (testFiles.any { file -> InTextDirectivesUtils.isDirectiveDefined(file.expectedText, "// SKIP_TXT") }) { if (testFiles.any { file -> InTextDirectivesUtils.isDirectiveDefined(file.expectedText, "// SKIP_TXT") }) {
@@ -446,7 +445,9 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
"Such tests are hard to maintain, take long time to execute and are subject to sudden unreviewed changes anyway." "Such tests are hard to maintain, take long time to execute and are subject to sudden unreviewed changes anyway."
} }
KotlinTestUtils.assertEqualsToFile(expectedFile, allPackagesText) KotlinTestUtils.assertEqualsToFile(expectedFile, allPackagesText) { s ->
s.replace("COROUTINES_PACKAGE", coroutinesPackage)
}
} }
@@ -568,6 +568,9 @@ public class KotlinTestUtils {
configuration.put(JVMConfigurationKeys.JDK_HOME, new File(System.getProperty("java.home"))); configuration.put(JVMConfigurationKeys.JDK_HOME, new File(System.getProperty("java.home")));
} }
if (configurationKind.getWithCoroutines()) {
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.coroutinesJarForTests());
}
if (configurationKind.getWithRuntime()) { if (configurationKind.getWithRuntime()) {
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.runtimeJarForTests()); JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.runtimeJarForTests());
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.scriptRuntimeJarForTests()); JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.scriptRuntimeJarForTests());
@@ -709,13 +712,13 @@ public class KotlinTestUtils {
} }
@NotNull @NotNull
public static <M, F> List<F> createTestFiles(@Nullable String testFileName, String expectedText, TestFileFactory<M, F> factory) { public static <M, F> List<F> createTestFiles(@Nullable String testFileName, String expectedText, TestFileFactory<M, F> factory, String coroutinesPackage) {
return createTestFiles(testFileName, expectedText, factory, false); return createTestFiles(testFileName, expectedText, factory, false, coroutinesPackage);
} }
@NotNull @NotNull
public static <M, F> List<F> createTestFiles(String testFileName, String expectedText, TestFileFactory<M, F> factory, public static <M, F> List<F> createTestFiles(String testFileName, String expectedText, TestFileFactory<M, F> factory,
boolean preserveLocations) { boolean preserveLocations, String coroutinesPackage) {
Map<String, String> directives = parseDirectives(expectedText); Map<String, String> directives = parseDirectives(expectedText);
List<F> testFiles = Lists.newArrayList(); List<F> testFiles = Lists.newArrayList();
@@ -768,10 +771,13 @@ public class KotlinTestUtils {
if (isDirectiveDefined(expectedText, "WITH_COROUTINES")) { if (isDirectiveDefined(expectedText, "WITH_COROUTINES")) {
M supportModule = hasModules ? factory.createModule("support", Collections.emptyList(), Collections.emptyList()) : null; M supportModule = hasModules ? factory.createModule("support", Collections.emptyList(), Collections.emptyList()) : null;
if (coroutinesPackage.isEmpty()) {
coroutinesPackage = "kotlin.coroutines.experimental";
}
testFiles.add(factory.createFile(supportModule, testFiles.add(factory.createFile(supportModule,
"CoroutineUtil.kt", "CoroutineUtil.kt",
"package helpers\n" + "package helpers\n" +
"import kotlin.coroutines.experimental.*\n" + "import " + coroutinesPackage + ".*\n" +
"fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {\n" + "fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {\n" +
" override val context = EmptyCoroutineContext\n" + " override val context = EmptyCoroutineContext\n" +
" override fun resumeWithException(exception: Throwable) {\n" + " override fun resumeWithException(exception: Throwable) {\n" +
@@ -862,7 +868,7 @@ public class KotlinTestUtils {
int firstLineEnd = text.indexOf('\n'); int firstLineEnd = text.indexOf('\n');
return StringUtil.trimTrailing(text.substring(firstLineEnd + 1)); return StringUtil.trimTrailing(text.substring(firstLineEnd + 1));
} }
}); }, "");
Assert.assertTrue("Exactly two files expected: ", files.size() == 2); Assert.assertTrue("Exactly two files expected: ", files.size() == 2);
@@ -568,6 +568,9 @@ public class KotlinTestUtils {
JvmContentRootsKt.addJvmClasspathRoots(configuration, PathUtil.getJdkClassesRootsFromCurrentJre()); JvmContentRootsKt.addJvmClasspathRoots(configuration, PathUtil.getJdkClassesRootsFromCurrentJre());
} }
if (configurationKind.getWithCoroutines()) {
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.coroutinesJarForTests());
}
if (configurationKind.getWithRuntime()) { if (configurationKind.getWithRuntime()) {
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.runtimeJarForTests()); JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.runtimeJarForTests());
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.scriptRuntimeJarForTests()); JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.scriptRuntimeJarForTests());
@@ -709,13 +712,13 @@ public class KotlinTestUtils {
} }
@NotNull @NotNull
public static <M, F> List<F> createTestFiles(@Nullable String testFileName, String expectedText, TestFileFactory<M, F> factory) { public static <M, F> List<F> createTestFiles(@Nullable String testFileName, String expectedText, TestFileFactory<M, F> factory, String coroutinesPackage) {
return createTestFiles(testFileName, expectedText, factory, false); return createTestFiles(testFileName, expectedText, factory, false, coroutinesPackage);
} }
@NotNull @NotNull
public static <M, F> List<F> createTestFiles(String testFileName, String expectedText, TestFileFactory<M, F> factory, public static <M, F> List<F> createTestFiles(String testFileName, String expectedText, TestFileFactory<M, F> factory,
boolean preserveLocations) { boolean preserveLocations, String coroutinesPackage) {
Map<String, String> directives = parseDirectives(expectedText); Map<String, String> directives = parseDirectives(expectedText);
List<F> testFiles = Lists.newArrayList(); List<F> testFiles = Lists.newArrayList();
@@ -768,10 +771,13 @@ public class KotlinTestUtils {
if (isDirectiveDefined(expectedText, "WITH_COROUTINES")) { if (isDirectiveDefined(expectedText, "WITH_COROUTINES")) {
M supportModule = hasModules ? factory.createModule("support", Collections.emptyList(), Collections.emptyList()) : null; M supportModule = hasModules ? factory.createModule("support", Collections.emptyList(), Collections.emptyList()) : null;
if (coroutinesPackage.isEmpty()) {
coroutinesPackage = "kotlin.coroutines.experimental";
}
testFiles.add(factory.createFile(supportModule, testFiles.add(factory.createFile(supportModule,
"CoroutineUtil.kt", "CoroutineUtil.kt",
"package helpers\n" + "package helpers\n" +
"import kotlin.coroutines.experimental.*\n" + "import " + coroutinesPackage + ".*\n" +
"fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {\n" + "fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {\n" +
" override val context = EmptyCoroutineContext\n" + " override val context = EmptyCoroutineContext\n" +
" override fun resumeWithException(exception: Throwable) {\n" + " override fun resumeWithException(exception: Throwable) {\n" +
@@ -862,7 +868,7 @@ public class KotlinTestUtils {
int firstLineEnd = text.indexOf('\n'); int firstLineEnd = text.indexOf('\n');
return StringUtil.trimTrailing(text.substring(firstLineEnd + 1)); return StringUtil.trimTrailing(text.substring(firstLineEnd + 1));
} }
}); }, "");
Assert.assertTrue("Exactly two files expected: ", files.size() == 2); Assert.assertTrue("Exactly two files expected: ", files.size() == 2);
@@ -568,6 +568,9 @@ public class KotlinTestUtils {
JvmContentRootsKt.addJvmClasspathRoots(configuration, PathUtil.getJdkClassesRootsFromCurrentJre()); JvmContentRootsKt.addJvmClasspathRoots(configuration, PathUtil.getJdkClassesRootsFromCurrentJre());
} }
if (configurationKind.getWithCoroutines()) {
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.coroutinesJarForTests());
}
if (configurationKind.getWithRuntime()) { if (configurationKind.getWithRuntime()) {
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.runtimeJarForTests()); JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.runtimeJarForTests());
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.scriptRuntimeJarForTests()); JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.scriptRuntimeJarForTests());
@@ -709,13 +712,13 @@ public class KotlinTestUtils {
} }
@NotNull @NotNull
public static <M, F> List<F> createTestFiles(@Nullable String testFileName, String expectedText, TestFileFactory<M, F> factory) { public static <M, F> List<F> createTestFiles(@Nullable String testFileName, String expectedText, TestFileFactory<M, F> factory, String coroutinesPackage) {
return createTestFiles(testFileName, expectedText, factory, false); return createTestFiles(testFileName, expectedText, factory, false, coroutinesPackage);
} }
@NotNull @NotNull
public static <M, F> List<F> createTestFiles(String testFileName, String expectedText, TestFileFactory<M, F> factory, public static <M, F> List<F> createTestFiles(String testFileName, String expectedText, TestFileFactory<M, F> factory,
boolean preserveLocations) { boolean preserveLocations, String coroutinesPackage) {
Map<String, String> directives = parseDirectives(expectedText); Map<String, String> directives = parseDirectives(expectedText);
List<F> testFiles = Lists.newArrayList(); List<F> testFiles = Lists.newArrayList();
@@ -768,10 +771,13 @@ public class KotlinTestUtils {
if (isDirectiveDefined(expectedText, "WITH_COROUTINES")) { if (isDirectiveDefined(expectedText, "WITH_COROUTINES")) {
M supportModule = hasModules ? factory.createModule("support", Collections.emptyList(), Collections.emptyList()) : null; M supportModule = hasModules ? factory.createModule("support", Collections.emptyList(), Collections.emptyList()) : null;
if (coroutinesPackage.isEmpty()) {
coroutinesPackage = "kotlin.coroutines.experimental";
}
testFiles.add(factory.createFile(supportModule, testFiles.add(factory.createFile(supportModule,
"CoroutineUtil.kt", "CoroutineUtil.kt",
"package helpers\n" + "package helpers\n" +
"import kotlin.coroutines.experimental.*\n" + "import " + coroutinesPackage + ".*\n" +
"fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {\n" + "fun <T> handleResultContinuation(x: (T) -> Unit): Continuation<T> = object: Continuation<T> {\n" +
" override val context = EmptyCoroutineContext\n" + " override val context = EmptyCoroutineContext\n" +
" override fun resumeWithException(exception: Throwable) {\n" + " override fun resumeWithException(exception: Throwable) {\n" +
@@ -862,7 +868,7 @@ public class KotlinTestUtils {
int firstLineEnd = text.indexOf('\n'); int firstLineEnd = text.indexOf('\n');
return StringUtil.trimTrailing(text.substring(firstLineEnd + 1)); return StringUtil.trimTrailing(text.substring(firstLineEnd + 1));
} }
}); }, "");
Assert.assertTrue("Exactly two files expected: ", files.size() == 2); Assert.assertTrue("Exactly two files expected: ", files.size() == 2);