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:
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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.asJava
|
||||
@@ -28,7 +17,6 @@ import java.util.regex.Pattern
|
||||
object LightClassTestCommon {
|
||||
private val SUBJECT_FQ_NAME_PATTERN = Pattern.compile("^//\\s*(.*)$", Pattern.MULTILINE)
|
||||
|
||||
@JvmOverloads
|
||||
fun testLightClass(
|
||||
expectedFile: File,
|
||||
testDataFile: File,
|
||||
|
||||
+19
-18
@@ -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.checkers
|
||||
@@ -99,7 +88,14 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
|
||||
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 separateModules = groupedByModule.size == 1 && groupedByModule.keys.single() == null
|
||||
@@ -141,7 +137,7 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
var exceptionFromDescriptorValidation: Throwable? = null
|
||||
try {
|
||||
val expectedFile = getExpectedDescriptorFile(testDataFile, files)
|
||||
validateAndCompareDescriptorWithFile(expectedFile, files, modules)
|
||||
validateAndCompareDescriptorWithFile(expectedFile, files, modules, coroutinesPackage)
|
||||
} catch (e: Throwable) {
|
||||
exceptionFromDescriptorValidation = e
|
||||
}
|
||||
@@ -175,7 +171,9 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
exceptionFromDynamicCallDescriptorsValidation = e
|
||||
}
|
||||
|
||||
KotlinTestUtils.assertEqualsToFile(getExpectedDiagnosticsFile(testDataFile), actualText.toString())
|
||||
KotlinTestUtils.assertEqualsToFile(getExpectedDiagnosticsFile(testDataFile), actualText.toString()) { s ->
|
||||
s.replace("COROUTINES_PACKAGE", coroutinesPackage)
|
||||
}
|
||||
|
||||
assertTrue("Diagnostics mismatch. See the output above", ok)
|
||||
|
||||
@@ -395,7 +393,8 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
private fun validateAndCompareDescriptorWithFile(
|
||||
expectedFile: File,
|
||||
testFiles: List<TestFile>,
|
||||
modules: Map<TestModule?, ModuleDescriptorImpl>
|
||||
modules: Map<TestModule?, ModuleDescriptorImpl>,
|
||||
coroutinesPackage: String
|
||||
) {
|
||||
if (skipDescriptorsValidation()) return
|
||||
if (testFiles.any { file -> InTextDirectivesUtils.isDirectiveDefined(file.expectedText, "// SKIP_TXT") }) {
|
||||
@@ -456,7 +455,9 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
"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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+16
-14
@@ -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.checkers;
|
||||
@@ -41,6 +30,7 @@ import java.util.*;
|
||||
public abstract class KotlinMultiFileTestWithJava<M, F> extends KtUsefulTestCase {
|
||||
protected File javaFilesDir;
|
||||
private File kotlinSourceRoot;
|
||||
protected String coroutinesPackage;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
@@ -50,6 +40,7 @@ public abstract class KotlinMultiFileTestWithJava<M, F> extends KtUsefulTestCase
|
||||
if (isKotlinSourceRootNeeded()) {
|
||||
kotlinSourceRoot = KotlinTestUtils.tmpDir("kotlin-src");
|
||||
}
|
||||
coroutinesPackage = "";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -147,6 +138,17 @@ public abstract class KotlinMultiFileTestWithJava<M, F> extends KtUsefulTestCase
|
||||
doMultiFileTest(file, modules, testFiles);
|
||||
}
|
||||
|
||||
protected void doTestWithCoroutinesPackageReplacement(String filePath, String coroutinesPackage) throws Exception {
|
||||
File file = new File(filePath);
|
||||
String expectedText = KotlinTestUtils.doLoadFile(file);
|
||||
expectedText = expectedText.replace("COROUTINES_PACKAGE", coroutinesPackage);
|
||||
this.coroutinesPackage = coroutinesPackage;
|
||||
Map<String, ModuleAndDependencies> modules = new HashMap<>();
|
||||
List<F> testFiles = createTestFiles(file, expectedText, modules);
|
||||
|
||||
doMultiFileTest(file, modules, testFiles);
|
||||
}
|
||||
|
||||
protected abstract M createTestModule(@NotNull String name);
|
||||
|
||||
protected abstract F createTestFile(M module, String fileName, String text, Map<String, String> directives);
|
||||
@@ -187,7 +189,7 @@ public abstract class KotlinMultiFileTestWithJava<M, F> extends KtUsefulTestCase
|
||||
KotlinTestUtils.mkdirs(file.getParentFile());
|
||||
FilesKt.writeText(file, content, Charsets.UTF_8);
|
||||
}
|
||||
});
|
||||
}, coroutinesPackage);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+8
-15
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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.codegen;
|
||||
@@ -38,7 +27,11 @@ import static org.jetbrains.kotlin.test.clientserver.TestProcessServerKt.getGene
|
||||
public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
||||
|
||||
@Override
|
||||
protected void doMultiFileTest(@NotNull File wholeFile, @NotNull List<TestFile> files, @Nullable File javaFilesDir) throws Exception {
|
||||
protected void doMultiFileTest(
|
||||
@NotNull File wholeFile,
|
||||
@NotNull List<TestFile> files,
|
||||
@Nullable File javaFilesDir
|
||||
) throws Exception {
|
||||
try {
|
||||
compile(files, javaFilesDir);
|
||||
blackBox();
|
||||
@@ -87,7 +80,7 @@ public abstract class AbstractBlackBoxCodegenTest extends CodegenTestCase {
|
||||
}
|
||||
);
|
||||
|
||||
assertEqualsToFile(expectedFile, text);
|
||||
assertEqualsToFile(expectedFile, text, s -> s.replace("COROUTINES_PACKAGE", coroutinesPackage));
|
||||
}
|
||||
|
||||
protected void blackBox() {
|
||||
|
||||
+5
-14
@@ -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.codegen
|
||||
@@ -26,7 +15,9 @@ abstract class AbstractBytecodeListingTest : CodegenTestCase() {
|
||||
val txtFile = File(wholeFile.parentFile, wholeFile.nameWithoutExtension + ".txt")
|
||||
compile(files, javaFilesDir)
|
||||
val actualTxt = BytecodeListingTextCollectingVisitor.getText(classFileFactory, withSignatures = isWithSignatures(wholeFile))
|
||||
KotlinTestUtils.assertEqualsToFile(txtFile, actualTxt)
|
||||
KotlinTestUtils.assertEqualsToFile(txtFile, actualTxt) {
|
||||
it.replace("COROUTINES_PACKAGE", coroutinesPackage)
|
||||
}
|
||||
}
|
||||
|
||||
private fun isWithSignatures(wholeFile: File): Boolean =
|
||||
|
||||
+3
-14
@@ -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.codegen
|
||||
@@ -31,7 +20,7 @@ abstract class AbstractBytecodeTextTest : CodegenTestCase() {
|
||||
|
||||
@Throws(Exception::class)
|
||||
override fun doMultiFileTest(wholeFile: File, files: List<CodegenTestCase.TestFile>, javaFilesDir: File?) {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL, files, javaFilesDir)
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.ALL, files, coroutinesPackage, javaFilesDir)
|
||||
loadMultiFiles(files)
|
||||
|
||||
if (isMultiFileTest(files) && !InTextDirectivesUtils.isDirectiveDefined(wholeFile.readText(), "TREAT_AS_ONE_FILE")) {
|
||||
|
||||
+2
-13
@@ -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.codegen;
|
||||
|
||||
+5
-14
@@ -1,17 +1,6 @@
|
||||
/*
|
||||
* Copyright 2010-2016 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.codegen
|
||||
@@ -31,7 +20,9 @@ abstract class AbstractDumpDeclarationsTest : CodegenTestCase() {
|
||||
dumpToFile = KotlinTestUtils.tmpDirForTest(this).resolve(name + ".json")
|
||||
compile(files, null)
|
||||
classFileFactory.generationState.destroy()
|
||||
KotlinTestUtils.assertEqualsToFile(expectedResult, dumpToFile.readText())
|
||||
KotlinTestUtils.assertEqualsToFile(expectedResult, dumpToFile.readText()) {
|
||||
it.replace("COROUTINES_PACKAGE", coroutinesPackage)
|
||||
}
|
||||
}
|
||||
|
||||
override fun updateConfiguration(configuration: CompilerConfiguration) {
|
||||
|
||||
+2
-13
@@ -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.codegen
|
||||
|
||||
@@ -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.codegen;
|
||||
@@ -99,6 +88,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
protected GeneratedClassLoader initializedClassLoader;
|
||||
protected File javaClassesOutputDirectory = null;
|
||||
protected List<File> additionalDependencies = null;
|
||||
protected String coroutinesPackage;
|
||||
|
||||
protected ConfigurationKind configurationKind = ConfigurationKind.JDK_ONLY;
|
||||
private final String defaultJvmTarget = System.getProperty(DEFAULT_JVM_TARGET_FOR_TEST);
|
||||
@@ -109,7 +99,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
@NotNull ConfigurationKind configurationKind,
|
||||
@Nullable File... javaSourceRoots
|
||||
) {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(configurationKind, Collections.emptyList(), javaSourceRoots);
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(configurationKind, Collections.emptyList(), "" , javaSourceRoots);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -125,6 +115,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
protected final void createEnvironmentWithMockJdkAndIdeaAnnotations(
|
||||
@NotNull ConfigurationKind configurationKind,
|
||||
@NotNull List<TestFile> testFilesWithConfigurationDirectives,
|
||||
@NotNull String coroutinesPackage,
|
||||
@Nullable File... javaSourceRoots
|
||||
) {
|
||||
if (myEnvironment != null) {
|
||||
@@ -154,7 +145,7 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
) {
|
||||
CompilerConfiguration configuration = KotlinTestUtils.newConfiguration(kind, jdkKind, classpath, javaSource);
|
||||
|
||||
updateConfigurationByDirectivesInTestFiles(testFilesWithConfigurationDirectives, configuration);
|
||||
updateConfigurationByDirectivesInTestFiles(testFilesWithConfigurationDirectives, configuration, coroutinesPackage);
|
||||
updateConfiguration(configuration);
|
||||
setCustomDefaultJvmTarget(configuration);
|
||||
|
||||
@@ -163,7 +154,8 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
|
||||
protected static void updateConfigurationByDirectivesInTestFiles(
|
||||
@NotNull List<TestFile> testFilesWithConfigurationDirectives,
|
||||
@NotNull CompilerConfiguration configuration
|
||||
@NotNull CompilerConfiguration configuration,
|
||||
@NotNull String coroutinesPackage
|
||||
) {
|
||||
LanguageVersionSettings explicitLanguageVersionSettings = null;
|
||||
LanguageVersion explicitLanguageVersion = null;
|
||||
@@ -185,6 +177,16 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
assertDirectivesToNull(explicitLanguageVersionSettings, explicitLanguageVersion);
|
||||
explicitLanguageVersion = LanguageVersion.fromVersionString(version);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Map<String, String> directives = KotlinTestUtils.parseDirectives(testFile.content);
|
||||
LanguageVersionSettings fileLanguageVersionSettings = parseLanguageVersionSettings(directives);
|
||||
@@ -291,6 +293,12 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
coroutinesPackage = "";
|
||||
super.setUp();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
myFiles = null;
|
||||
@@ -388,8 +396,11 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
protected GeneratedClassLoader createClassLoader() {
|
||||
return new GeneratedClassLoader(
|
||||
generateClassesInFile(),
|
||||
configurationKind.getWithReflection() ? ForTestCompileRuntime.runtimeAndReflectJarClassLoader()
|
||||
: ForTestCompileRuntime.runtimeJarClassLoader(),
|
||||
configurationKind.getWithReflection()
|
||||
? ForTestCompileRuntime.runtimeAndReflectJarClassLoader()
|
||||
: configurationKind.getWithCoroutines()
|
||||
? ForTestCompileRuntime.runtimeAndCoroutinesJarClassLoader()
|
||||
: ForTestCompileRuntime.runtimeJarClassLoader(),
|
||||
getClassPathURLs()
|
||||
);
|
||||
}
|
||||
@@ -641,6 +652,9 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
if (loadAndroidAnnotations) {
|
||||
javaClasspath.add(ForTestCompileRuntime.androidAnnotationsForTests().getPath());
|
||||
}
|
||||
if (configurationKind.getWithCoroutines()) {
|
||||
javaClasspath.add(ForTestCompileRuntime.coroutinesJarForTests().getPath());
|
||||
}
|
||||
|
||||
javaClassesOutputDirectory = CodegenTestUtil.compileJava(
|
||||
findJavaSourcesInDirectory(javaSourceDir), javaClasspath, javacOptions
|
||||
@@ -652,7 +666,11 @@ 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")) {
|
||||
addCoroutines = true;
|
||||
}
|
||||
if (InTextDirectivesUtils.isDirectiveDefined(file.content, "WITH_RUNTIME")) {
|
||||
addRuntime = true;
|
||||
}
|
||||
@@ -661,7 +679,9 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
return addReflect ? ConfigurationKind.ALL :
|
||||
return (addReflect && addCoroutines) ? ConfigurationKind.ALL :
|
||||
addReflect ? ConfigurationKind.WITH_REFLECT :
|
||||
addCoroutines ? ConfigurationKind.WITH_COROUTINES :
|
||||
addRuntime ? ConfigurationKind.NO_KOTLIN_REFLECT :
|
||||
ConfigurationKind.JDK_ONLY;
|
||||
}
|
||||
@@ -720,13 +740,25 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
String expectedText = KotlinTestUtils.doLoadFile(file);
|
||||
Ref<File> javaFilesDir = Ref.create();
|
||||
|
||||
List<TestFile> testFiles = createTestFiles(file, expectedText, javaFilesDir);
|
||||
List<TestFile> testFiles = createTestFiles(file, expectedText, javaFilesDir, "");
|
||||
|
||||
doMultiFileTest(file, testFiles, javaFilesDir.get());
|
||||
}
|
||||
|
||||
protected void doTestWithCoroutinesPackageReplacement(String filePath, String packageName) throws Exception {
|
||||
File file = new File(filePath);
|
||||
String expectedText = KotlinTestUtils.doLoadFile(file);
|
||||
expectedText = expectedText.replace("COROUTINES_PACKAGE", packageName);
|
||||
this.coroutinesPackage = packageName;
|
||||
Ref<File> javaFilesDir = Ref.create();
|
||||
|
||||
List<TestFile> testFiles = createTestFiles(file, expectedText, javaFilesDir, coroutinesPackage);
|
||||
|
||||
doMultiFileTest(file, testFiles, javaFilesDir.get());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<TestFile> createTestFiles(File file, String expectedText, Ref<File> javaFilesDir) {
|
||||
private static List<TestFile> createTestFiles(File file, String expectedText, Ref<File> javaFilesDir, String coroutinesPackage) {
|
||||
return KotlinTestUtils.createTestFiles(file.getName(), expectedText, new KotlinTestUtils.TestFileFactoryNoModules<TestFile>() {
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -751,10 +783,14 @@ public abstract class CodegenTestCase extends KtUsefulTestCase {
|
||||
KotlinTestUtils.mkdirs(file.getParentFile());
|
||||
FilesKt.writeText(file, content, Charsets.UTF_8);
|
||||
}
|
||||
});
|
||||
}, coroutinesPackage);
|
||||
}
|
||||
|
||||
protected void doMultiFileTest(@NotNull File wholeFile, @NotNull List<TestFile> files, @Nullable File javaFilesDir) throws Exception {
|
||||
protected void doMultiFileTest(
|
||||
@NotNull File wholeFile,
|
||||
@NotNull List<TestFile> files,
|
||||
@Nullable File javaFilesDir
|
||||
) throws Exception {
|
||||
throw new UnsupportedOperationException("Multi-file test cases are not supported in this test");
|
||||
}
|
||||
|
||||
|
||||
+20
-14
@@ -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.codegen.forTestCompile;
|
||||
@@ -30,12 +19,18 @@ import java.util.List;
|
||||
public class ForTestCompileRuntime {
|
||||
private static volatile SoftReference<ClassLoader> reflectJarClassLoader = new SoftReference<>(null);
|
||||
private static volatile SoftReference<ClassLoader> runtimeJarClassLoader = new SoftReference<>(null);
|
||||
private static volatile SoftReference<ClassLoader> coroutinesJarClassLoader = new SoftReference<>(null);
|
||||
|
||||
@NotNull
|
||||
public static File runtimeJarForTests() {
|
||||
return assertExists(new File("dist/kotlinc/lib/kotlin-stdlib.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File coroutinesJarForTests() {
|
||||
return assertExists(new File("dist/kotlin-stdlib-coroutines.jar"));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static File minimalRuntimeJarForTests() {
|
||||
return assertExists(new File("dist/kotlin-stdlib-minimal-for-test.jar"));
|
||||
@@ -93,12 +88,23 @@ public class ForTestCompileRuntime {
|
||||
public static synchronized ClassLoader runtimeAndReflectJarClassLoader() {
|
||||
ClassLoader loader = reflectJarClassLoader.get();
|
||||
if (loader == null) {
|
||||
loader = createClassLoader(runtimeJarForTests(), reflectJarForTests(), scriptRuntimeJarForTests(), kotlinTestJarForTests());
|
||||
loader = createClassLoader(runtimeJarForTests(), coroutinesJarForTests(), reflectJarForTests(), scriptRuntimeJarForTests(),
|
||||
kotlinTestJarForTests());
|
||||
reflectJarClassLoader = new SoftReference<>(loader);
|
||||
}
|
||||
return loader;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static synchronized ClassLoader runtimeAndCoroutinesJarClassLoader() {
|
||||
ClassLoader loader = coroutinesJarClassLoader.get();
|
||||
if (loader == null) {
|
||||
loader = createClassLoader(runtimeJarForTests(), coroutinesJarForTests(), scriptRuntimeJarForTests(), kotlinTestJarForTests());
|
||||
coroutinesJarClassLoader = new SoftReference<>(loader);
|
||||
}
|
||||
return loader;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static synchronized ClassLoader runtimeJarClassLoader() {
|
||||
ClassLoader loader = runtimeJarClassLoader.get();
|
||||
|
||||
+3
-14
@@ -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.jvm.compiler;
|
||||
@@ -280,7 +269,7 @@ public abstract class AbstractLoadJavaTest extends TestCaseWithTmpdir {
|
||||
}
|
||||
return targetFile;
|
||||
}
|
||||
});
|
||||
}, "");
|
||||
|
||||
Pair<PackageViewDescriptor, BindingContext> javaPackageAndContext = compileJavaAndLoadTestPackageAndBindingContextFromBinary(
|
||||
srcFiles, compiledDir, ConfigurationKind.ALL
|
||||
|
||||
+3
-14
@@ -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.resolve;
|
||||
@@ -59,7 +48,7 @@ public abstract class ExtensibleResolveTestCase extends KotlinTestWithEnvironmen
|
||||
public KtFile create(@NotNull String fileName, @NotNull String text, @NotNull Map<String, String> directives) {
|
||||
return expectedResolveData.createFileFromMarkedUpText(fileName, text);
|
||||
}
|
||||
});
|
||||
}, "");
|
||||
expectedResolveData.checkResult(ExpectedResolveData.analyze(files, getEnvironment()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.test
|
||||
@@ -19,7 +8,8 @@ package org.jetbrains.kotlin.test
|
||||
enum class ConfigurationKind(
|
||||
val withRuntime: Boolean = false,
|
||||
val withMockRuntime: Boolean = false,
|
||||
val withReflection: Boolean = false
|
||||
val withReflection: Boolean = false,
|
||||
val withCoroutines: Boolean = false
|
||||
) {
|
||||
/** JDK without any kotlin runtime */
|
||||
JDK_NO_RUNTIME(),
|
||||
@@ -27,6 +17,10 @@ enum class ConfigurationKind(
|
||||
JDK_ONLY(withMockRuntime = true),
|
||||
/** JDK + kotlin runtime but without reflection */
|
||||
NO_KOTLIN_REFLECT(withRuntime = true),
|
||||
/** JDK + kotlin runtime + coroutines */
|
||||
WITH_COROUTINES(withCoroutines = true, withRuntime = true),
|
||||
/** JDK + kotlin runtime + kotlin reflection */
|
||||
ALL(withRuntime = true, withReflection = true),
|
||||
WITH_REFLECT(withRuntime = true, withReflection = true),
|
||||
/** JDK + kotlin runtime + kotlin reflection + coroutines*/
|
||||
ALL(withRuntime = true, withReflection = true, withCoroutines = true)
|
||||
}
|
||||
|
||||
@@ -568,6 +568,9 @@ public class KotlinTestUtils {
|
||||
configuration.put(JVMConfigurationKeys.JDK_HOME, new File(System.getProperty("java.home")));
|
||||
}
|
||||
|
||||
if (configurationKind.getWithCoroutines()) {
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.coroutinesJarForTests());
|
||||
}
|
||||
if (configurationKind.getWithRuntime()) {
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.runtimeJarForTests());
|
||||
JvmContentRootsKt.addJvmClasspathRoot(configuration, ForTestCompileRuntime.scriptRuntimeJarForTests());
|
||||
@@ -709,13 +712,13 @@ public class KotlinTestUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <M, F> List<F> createTestFiles(@Nullable String testFileName, String expectedText, TestFileFactory<M, F> factory) {
|
||||
return createTestFiles(testFileName, expectedText, factory, false);
|
||||
public static <M, F> List<F> createTestFiles(@Nullable String testFileName, String expectedText, TestFileFactory<M, F> factory, String coroutinesPackage) {
|
||||
return createTestFiles(testFileName, expectedText, factory, false, coroutinesPackage);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
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);
|
||||
|
||||
List<F> testFiles = Lists.newArrayList();
|
||||
@@ -768,10 +771,13 @@ 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";
|
||||
}
|
||||
testFiles.add(factory.createFile(supportModule,
|
||||
"CoroutineUtil.kt",
|
||||
"package helpers\n" +
|
||||
"import kotlin.coroutines.experimental.*\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" +
|
||||
@@ -862,7 +868,7 @@ public class KotlinTestUtils {
|
||||
int firstLineEnd = text.indexOf('\n');
|
||||
return StringUtil.trimTrailing(text.substring(firstLineEnd + 1));
|
||||
}
|
||||
});
|
||||
}, "");
|
||||
|
||||
Assert.assertTrue("Exactly two files expected: ", files.size() == 2);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user