Convert KotlinMultiFileTestWithJava.java to Kotlin
This commit is contained in:
+1
-1
@@ -13,7 +13,7 @@ abstract class AbstractFirDiagnosticsWithStdlibTest : AbstractFirDiagnosticsTest
|
|||||||
return ConfigurationKind.ALL
|
return ConfigurationKind.ALL
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTestJdkKind(testFiles: MutableList<TestFile>): TestJdkKind {
|
override fun getTestJdkKind(files: List<TestFile>): TestJdkKind {
|
||||||
return TestJdkKind.FULL_JDK
|
return TestJdkKind.FULL_JDK
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+2
-2
@@ -50,8 +50,8 @@ abstract class AbstractCompilerLightClassTest : KotlinMultiFileTestWithJava<Kotl
|
|||||||
|
|
||||||
override fun createTestModule(
|
override fun createTestModule(
|
||||||
name: String,
|
name: String,
|
||||||
dependencies: MutableList<String>,
|
dependencies: List<String>,
|
||||||
friends: MutableList<String>
|
friends: List<String>
|
||||||
): TestModule? = null
|
): TestModule? = null
|
||||||
|
|
||||||
override fun createTestFile(
|
override fun createTestFile(
|
||||||
|
|||||||
+10
-18
@@ -13,26 +13,18 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
package org.jetbrains.kotlin.cfg
|
||||||
|
|
||||||
package org.jetbrains.kotlin.cfg;
|
import org.jetbrains.kotlin.checkers.AbstractDiagnosticsTest
|
||||||
|
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||||
|
import org.jetbrains.kotlin.test.TestJdkKind
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
abstract class AbstractDiagnosticsWithModifiedMockJdkTest : AbstractDiagnosticsTest() {
|
||||||
import org.jetbrains.kotlin.checkers.AbstractDiagnosticsTest;
|
override fun getConfigurationKind(): ConfigurationKind {
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
return ConfigurationKind.ALL
|
||||||
import org.jetbrains.kotlin.test.TestJdkKind;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public abstract class AbstractDiagnosticsWithModifiedMockJdkTest extends AbstractDiagnosticsTest {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
protected ConfigurationKind getConfigurationKind() {
|
|
||||||
return ConfigurationKind.ALL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
override fun getTestJdkKind(files: List<TestFile>): TestJdkKind {
|
||||||
@Override
|
return TestJdkKind.MODIFIED_MOCK_JDK
|
||||||
protected TestJdkKind getTestJdkKind(@NotNull List<TestFile> testFiles) {
|
|
||||||
return TestJdkKind.MODIFIED_MOCK_JDK;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+1
-1
@@ -30,7 +30,7 @@ abstract class AbstractDiagnosticsTestWithStdLibUsingJavac : AbstractDiagnostics
|
|||||||
return isJavacSkipTest(wholeFile, files)
|
return isJavacSkipTest(wholeFile, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setupEnvironment(environment: KotlinCoreEnvironment, testDataFile: File, files: MutableList<TestFile>) {
|
override fun setupEnvironment(environment: KotlinCoreEnvironment, testDataFile: File, files: List<TestFile>) {
|
||||||
val testDataFileText = testDataFile.readText()
|
val testDataFileText = testDataFile.readText()
|
||||||
|
|
||||||
val groupedByModule = files.groupBy(TestFile::module)
|
val groupedByModule = files.groupBy(TestFile::module)
|
||||||
|
|||||||
+1
-1
@@ -23,7 +23,7 @@ import java.io.File
|
|||||||
|
|
||||||
abstract class AbstractJavacForeignAnnotationsTest : AbstractForeignAnnotationsTest() {
|
abstract class AbstractJavacForeignAnnotationsTest : AbstractForeignAnnotationsTest() {
|
||||||
|
|
||||||
override fun setupEnvironment(environment: KotlinCoreEnvironment, testDataFile: File, files: MutableList<TestFile>) {
|
override fun setupEnvironment(environment: KotlinCoreEnvironment, testDataFile: File, files: List<TestFile>) {
|
||||||
val groupedByModule = files.groupBy(TestFile::module)
|
val groupedByModule = files.groupBy(TestFile::module)
|
||||||
val allKtFiles = groupedByModule.values.flatMap { getKtFiles(it, true) }
|
val allKtFiles = groupedByModule.values.flatMap { getKtFiles(it, true) }
|
||||||
environment.registerJavac(kotlinFiles = allKtFiles)
|
environment.registerJavac(kotlinFiles = allKtFiles)
|
||||||
|
|||||||
+1
-1
@@ -28,7 +28,7 @@ abstract class AbstractJavacForeignJava8AnnotationsTest : AbstractForeignJava8An
|
|||||||
return isSkipJavacTest(wholeFile, files)
|
return isSkipJavacTest(wholeFile, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setupEnvironment(environment: KotlinCoreEnvironment, testDataFile: File, files: MutableList<TestFile>) {
|
override fun setupEnvironment(environment: KotlinCoreEnvironment, testDataFile: File, files: List<TestFile>) {
|
||||||
val groupedByModule = files.groupBy(TestFile::module)
|
val groupedByModule = files.groupBy(TestFile::module)
|
||||||
val allKtFiles = groupedByModule.values.flatMap { getKtFiles(it, true) }
|
val allKtFiles = groupedByModule.values.flatMap { getKtFiles(it, true) }
|
||||||
environment.registerJavac(kotlinFiles = allKtFiles)
|
environment.registerJavac(kotlinFiles = allKtFiles)
|
||||||
|
|||||||
+8
-18
@@ -13,25 +13,15 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
package org.jetbrains.kotlin.checkers
|
||||||
|
|
||||||
package org.jetbrains.kotlin.checkers;
|
import org.jetbrains.kotlin.test.ConfigurationKind
|
||||||
|
import org.jetbrains.kotlin.test.TestJdkKind
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
abstract class AbstractDiagnosticsWithJdk9Test : AbstractDiagnosticsTest() {
|
||||||
import org.jetbrains.kotlin.test.ConfigurationKind;
|
override fun getConfigurationKind(): ConfigurationKind = ConfigurationKind.ALL
|
||||||
import org.jetbrains.kotlin.test.TestJdkKind;
|
|
||||||
|
|
||||||
import java.util.List;
|
override fun getTestJdkKind(files: List<TestFile>): TestJdkKind {
|
||||||
|
return TestJdkKind.FULL_JDK_9
|
||||||
public abstract class AbstractDiagnosticsWithJdk9Test extends AbstractDiagnosticsTest {
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
protected ConfigurationKind getConfigurationKind() {
|
|
||||||
return ConfigurationKind.ALL;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
protected TestJdkKind getTestJdkKind(@NotNull List<TestFile> testFiles) {
|
|
||||||
return TestJdkKind.FULL_JDK_9;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
-1
@@ -54,7 +54,7 @@ abstract class AbstractForeignAnnotationsTest : AbstractDiagnosticsTest() {
|
|||||||
|
|
||||||
override fun getConfigurationKind(): ConfigurationKind = ConfigurationKind.ALL
|
override fun getConfigurationKind(): ConfigurationKind = ConfigurationKind.ALL
|
||||||
|
|
||||||
override fun getTestJdkKind(testFiles: MutableList<TestFile>): TestJdkKind = TestJdkKind.FULL_JDK
|
override fun getTestJdkKind(testFiles: List<TestFile>): TestJdkKind = TestJdkKind.FULL_JDK
|
||||||
|
|
||||||
open protected val annotationsPath: String
|
open protected val annotationsPath: String
|
||||||
get() = FOREIGN_ANNOTATIONS_SOURCES_PATH
|
get() = FOREIGN_ANNOTATIONS_SOURCES_PATH
|
||||||
|
|||||||
+114
-151
@@ -2,203 +2,166 @@
|
|||||||
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
* 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
|
||||||
|
|
||||||
package org.jetbrains.kotlin.checkers;
|
import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||||
|
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment.Companion.createForTests
|
||||||
|
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||||
|
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||||
|
import org.jetbrains.kotlin.config.JVMConfigurationKeys
|
||||||
|
import org.jetbrains.kotlin.parsing.KotlinParserDefinition
|
||||||
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
|
import org.jetbrains.kotlin.script.loadScriptingPlugin
|
||||||
|
import org.jetbrains.kotlin.test.*
|
||||||
|
import org.jetbrains.kotlin.test.TestFiles.TestFileFactory
|
||||||
|
import java.io.File
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
import kotlin.io.FilesKt;
|
abstract class KotlinMultiFileTestWithJava<M : KotlinBaseTest.TestModule, F : KotlinBaseTest.TestFile> :
|
||||||
import kotlin.text.Charsets;
|
KotlinBaseTest<F>() {
|
||||||
import org.jetbrains.annotations.NotNull;
|
protected lateinit var javaFilesDir: File
|
||||||
import org.jetbrains.annotations.Nullable;
|
private var kotlinSourceRoot: File? = null
|
||||||
import org.jetbrains.kotlin.cli.common.config.ContentRootsKt;
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles;
|
|
||||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
|
|
||||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime;
|
|
||||||
import org.jetbrains.kotlin.config.CompilerConfiguration;
|
|
||||||
import org.jetbrains.kotlin.config.JVMConfigurationKeys;
|
|
||||||
import org.jetbrains.kotlin.parsing.KotlinParserDefinition;
|
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
|
||||||
import org.jetbrains.kotlin.test.*;
|
|
||||||
import org.jetbrains.kotlin.test.KotlinBaseTest;
|
|
||||||
|
|
||||||
import java.io.File;
|
@Throws(Exception::class)
|
||||||
import java.util.*;
|
public override fun setUp() {
|
||||||
|
super.setUp()
|
||||||
import static org.jetbrains.kotlin.script.ScriptTestUtilKt.loadScriptingPlugin;
|
|
||||||
|
|
||||||
public abstract class KotlinMultiFileTestWithJava<M extends KotlinBaseTest.TestModule, F extends KotlinBaseTest.TestFile> extends KotlinBaseTest<F> {
|
|
||||||
protected File javaFilesDir;
|
|
||||||
private File kotlinSourceRoot;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
super.setUp();
|
|
||||||
// TODO: do not create temporary directory for tests without Java sources
|
// TODO: do not create temporary directory for tests without Java sources
|
||||||
javaFilesDir = KotlinTestUtils.tmpDir("java-files");
|
javaFilesDir = KotlinTestUtils.tmpDir("java-files")
|
||||||
if (isKotlinSourceRootNeeded()) {
|
if (isKotlinSourceRootNeeded()) {
|
||||||
kotlinSourceRoot = KotlinTestUtils.tmpDir("kotlin-src");
|
kotlinSourceRoot = KotlinTestUtils.tmpDir("kotlin-src")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ModuleAndDependencies {
|
inner class ModuleAndDependencies internal constructor(val module: M?, val dependencies: List<String>, val friends: List<String>)
|
||||||
final M module;
|
|
||||||
final List<String> dependencies;
|
|
||||||
final List<String> friends;
|
|
||||||
|
|
||||||
ModuleAndDependencies(M module, List<String> dependencies, List<String> friends) {
|
override fun createTestFilesFromFile(file: File, expectedText: String): List<F> {
|
||||||
this.module = module;
|
return createTestFiles(file, expectedText, HashMap())
|
||||||
this.dependencies = dependencies;
|
|
||||||
this.friends = friends;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
protected fun createEnvironment(
|
||||||
private static Boolean isScriptingNeeded(@NotNull File file) {
|
file: File,
|
||||||
return file.getName().endsWith(KotlinParserDefinition.STD_SCRIPT_EXT);
|
files: List<F>
|
||||||
}
|
): KotlinCoreEnvironment {
|
||||||
|
val configuration = KotlinTestUtils.newConfiguration(
|
||||||
@Override
|
getConfigurationKind(),
|
||||||
@NotNull
|
getTestJdkKind(files),
|
||||||
public List<F> createTestFilesFromFile(@NotNull File file, String expectedText) {
|
getClasspath(file),
|
||||||
return createTestFiles(file, expectedText, new HashMap<>());
|
if (isJavaSourceRootNeeded()) listOf(javaFilesDir) else emptyList()
|
||||||
}
|
)
|
||||||
|
|
||||||
@NotNull
|
|
||||||
protected KotlinCoreEnvironment createEnvironment(
|
|
||||||
@NotNull File file,
|
|
||||||
@NotNull List<TestFile> files
|
|
||||||
) {
|
|
||||||
CompilerConfiguration configuration = KotlinTestUtils.newConfiguration(
|
|
||||||
getConfigurationKind(),
|
|
||||||
getTestJdkKind(files),
|
|
||||||
getClasspath(file),
|
|
||||||
isJavaSourceRootNeeded() ? Collections.singletonList(javaFilesDir) : Collections.emptyList()
|
|
||||||
);
|
|
||||||
if (isScriptingNeeded(file)) {
|
if (isScriptingNeeded(file)) {
|
||||||
loadScriptingPlugin(configuration);
|
loadScriptingPlugin(configuration)
|
||||||
}
|
}
|
||||||
if (isKotlinSourceRootNeeded()) {
|
if (isKotlinSourceRootNeeded()) {
|
||||||
ContentRootsKt.addKotlinSourceRoot(configuration, kotlinSourceRoot.getPath());
|
configuration.addKotlinSourceRoot(kotlinSourceRoot!!.path)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Currently, we're testing IDE behavior when generating the .txt files for comparison, but this can be changed.
|
// Currently, we're testing IDE behavior when generating the .txt files for comparison, but this can be changed.
|
||||||
// The main difference is the fact that the new class file reading implementation doesn't load parameter names from JDK classes.
|
// The main difference is the fact that the new class file reading implementation doesn't load parameter names from JDK classes.
|
||||||
configuration.put(JVMConfigurationKeys.USE_PSI_CLASS_FILES_READING, true);
|
configuration.put(JVMConfigurationKeys.USE_PSI_CLASS_FILES_READING, true)
|
||||||
|
|
||||||
performCustomConfiguration(configuration);
|
performCustomConfiguration(configuration)
|
||||||
return KotlinCoreEnvironment.createForTests(getTestRootDisposable(), configuration, getEnvironmentConfigFiles());
|
return createForTests(testRootDisposable, configuration, getEnvironmentConfigFiles())
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isJavaSourceRootNeeded() {
|
protected open fun isJavaSourceRootNeeded(): Boolean = true
|
||||||
return true;
|
|
||||||
|
protected open fun performCustomConfiguration(configuration: CompilerConfiguration) {}
|
||||||
|
|
||||||
|
protected open fun setupEnvironment(environment: KotlinCoreEnvironment) {}
|
||||||
|
|
||||||
|
protected open fun setupEnvironment(
|
||||||
|
environment: KotlinCoreEnvironment,
|
||||||
|
testDataFile: File,
|
||||||
|
files: List<BaseDiagnosticsTest.TestFile>
|
||||||
|
) {
|
||||||
|
setupEnvironment(environment)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void performCustomConfiguration(@NotNull CompilerConfiguration configuration) {
|
protected open fun getConfigurationKind() = ConfigurationKind.JDK_ONLY
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setupEnvironment(@NotNull KotlinCoreEnvironment environment) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setupEnvironment(@NotNull KotlinCoreEnvironment environment,@NotNull File testDataFile, @NotNull List<BaseDiagnosticsTest.TestFile> files) {
|
|
||||||
setupEnvironment(environment);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
protected ConfigurationKind getConfigurationKind() {
|
|
||||||
return ConfigurationKind.JDK_ONLY;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<File> getClasspath(File file) {
|
|
||||||
List<File> result = new ArrayList<>();
|
|
||||||
result.add(KotlinTestUtils.getAnnotationsJar());
|
|
||||||
result.addAll(getExtraClasspath());
|
|
||||||
|
|
||||||
String fileText = FilesKt.readText(file, Charsets.UTF_8);
|
|
||||||
|
|
||||||
|
private fun getClasspath(file: File): List<File> {
|
||||||
|
val result: MutableList<File> = ArrayList()
|
||||||
|
result.add(KotlinTestUtils.getAnnotationsJar())
|
||||||
|
result.addAll(getExtraClasspath())
|
||||||
|
val fileText = file.readText(Charsets.UTF_8)
|
||||||
if (InTextDirectivesUtils.isDirectiveDefined(fileText, "ANDROID_ANNOTATIONS")) {
|
if (InTextDirectivesUtils.isDirectiveDefined(fileText, "ANDROID_ANNOTATIONS")) {
|
||||||
result.add(ForTestCompileRuntime.androidAnnotationsForTests());
|
result.add(ForTestCompileRuntime.androidAnnotationsForTests())
|
||||||
}
|
}
|
||||||
if (InTextDirectivesUtils.isDirectiveDefined(fileText, "STDLIB_JDK8")) {
|
if (InTextDirectivesUtils.isDirectiveDefined(fileText, "STDLIB_JDK8")) {
|
||||||
result.add(ForTestCompileRuntime.runtimeJarForTestsWithJdk8());
|
result.add(ForTestCompileRuntime.runtimeJarForTestsWithJdk8())
|
||||||
}
|
}
|
||||||
|
if (DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_EXPERIMENTAL.asString() == coroutinesPackage ||
|
||||||
if (DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_EXPERIMENTAL.asString().equals(coroutinesPackage) ||
|
fileText.contains(DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_EXPERIMENTAL.asString())
|
||||||
fileText.contains(DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_EXPERIMENTAL.asString())) {
|
) {
|
||||||
result.add(ForTestCompileRuntime.coroutinesCompatForTests());
|
result.add(ForTestCompileRuntime.coroutinesCompatForTests())
|
||||||
}
|
}
|
||||||
|
return result
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
protected open fun getExtraClasspath(): List<File> = emptyList()
|
||||||
protected List<File> getExtraClasspath() {
|
|
||||||
return Collections.emptyList();
|
protected open fun getEnvironmentConfigFiles(): EnvironmentConfigFiles = EnvironmentConfigFiles.JVM_CONFIG_FILES
|
||||||
|
|
||||||
|
protected open fun isKotlinSourceRootNeeded(): Boolean = false
|
||||||
|
|
||||||
|
protected open fun createTestFileFromPath(filePath: String): File {
|
||||||
|
return File(filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@Throws(Exception::class)
|
||||||
protected EnvironmentConfigFiles getEnvironmentConfigFiles() {
|
public override fun doTest(filePath: String) {
|
||||||
return EnvironmentConfigFiles.JVM_CONFIG_FILES;
|
val file = createTestFileFromPath(filePath)
|
||||||
}
|
val expectedText = KotlinTestUtils.doLoadFile(file)
|
||||||
|
|
||||||
protected boolean isKotlinSourceRootNeeded() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
protected File createTestFileFromPath(@NotNull String filePath) {
|
|
||||||
return new File(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doTest(@NotNull String filePath) throws Exception {
|
|
||||||
File file = createTestFileFromPath(filePath);
|
|
||||||
String expectedText = KotlinTestUtils.doLoadFile(file);
|
|
||||||
//TODO: move to proper tests
|
//TODO: move to proper tests
|
||||||
if (InTextDirectivesUtils.isDirectiveDefined(expectedText, "// SKIP_JAVAC")) return;
|
if (InTextDirectivesUtils.isDirectiveDefined(expectedText, "// SKIP_JAVAC")) return
|
||||||
|
super.doTest(file.path)
|
||||||
super.doTest(file.getPath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract M createTestModule(@NotNull String name, List<String> dependencies, List<String> friends);
|
protected abstract fun createTestModule(name: String, dependencies: List<String>, friends: List<String>): M?
|
||||||
|
|
||||||
protected abstract F createTestFile(M module, String fileName, String text, Map<String, String> directives);
|
protected abstract fun createTestFile(module: M?, fileName: String, text: String, directives: Map<String, String>): F?
|
||||||
|
|
||||||
protected List<F> createTestFiles(File file, String expectedText, Map<String, ModuleAndDependencies> modules) {
|
protected open fun createTestFiles(
|
||||||
return TestFiles.createTestFiles(file.getName(), expectedText, new TestFiles.TestFileFactory<M, F>() {
|
file: File,
|
||||||
@Override
|
expectedText: String,
|
||||||
public F createFile(
|
modules: MutableMap<String?, ModuleAndDependencies>
|
||||||
@Nullable M module,
|
): List<F> {
|
||||||
@NotNull String fileName,
|
return TestFiles.createTestFiles(file.name, expectedText, object : TestFileFactory<M, F> {
|
||||||
@NotNull String text,
|
override fun createFile(
|
||||||
@NotNull Map<String, String> directives
|
module: M?,
|
||||||
) {
|
fileName: String,
|
||||||
|
text: String,
|
||||||
|
directives: Map<String, String>
|
||||||
|
): F? {
|
||||||
if (fileName.endsWith(".java")) {
|
if (fileName.endsWith(".java")) {
|
||||||
writeSourceFile(fileName, text, javaFilesDir);
|
writeSourceFile(fileName, text, javaFilesDir!!)
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fileName.endsWith(".kt") || fileName.endsWith(".kts")) && kotlinSourceRoot != null) {
|
if ((fileName.endsWith(".kt") || fileName.endsWith(".kts")) && kotlinSourceRoot != null) {
|
||||||
writeSourceFile(fileName, text, kotlinSourceRoot);
|
writeSourceFile(fileName, text, kotlinSourceRoot!!)
|
||||||
}
|
}
|
||||||
|
return createTestFile(module, fileName, text, directives)
|
||||||
return createTestFile(module, fileName, text, directives);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun createModule(name: String, dependencies: List<String>, friends: List<String>): M? {
|
||||||
public M createModule(@NotNull String name, @NotNull List<String> dependencies, @NotNull List<String> friends) {
|
val module = createTestModule(name, dependencies, friends)
|
||||||
M module = createTestModule(name, dependencies, friends);
|
val oldValue = modules.put(name, ModuleAndDependencies(module, dependencies, friends))
|
||||||
ModuleAndDependencies oldValue = modules.put(name, new ModuleAndDependencies(module, dependencies, friends));
|
assert(oldValue == null) { "Module $name declared more than once" }
|
||||||
assert oldValue == null : "Module " + name + " declared more than once";
|
return module
|
||||||
|
|
||||||
return module;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeSourceFile(@NotNull String fileName, @NotNull String content, @NotNull File targetDir) {
|
private fun writeSourceFile(fileName: String, content: String, targetDir: File) {
|
||||||
File file = new File(targetDir, fileName);
|
val file = File(targetDir, fileName)
|
||||||
KotlinTestUtils.mkdirs(file.getParentFile());
|
KotlinTestUtils.mkdirs(file.parentFile)
|
||||||
FilesKt.writeText(file, content, Charsets.UTF_8);
|
file.writeText(content, Charsets.UTF_8)
|
||||||
}
|
}
|
||||||
}, coroutinesPackage);
|
}, coroutinesPackage)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
companion object {
|
||||||
|
private fun isScriptingNeeded(file: File): Boolean {
|
||||||
|
return file.name.endsWith(KotlinParserDefinition.STD_SCRIPT_EXT)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -29,7 +29,7 @@ abstract class AbstractDiagnosticsUsingJavacTest : AbstractDiagnosticsTest() {
|
|||||||
return isJavacSkipTest(wholeFile, files)
|
return isJavacSkipTest(wholeFile, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setupEnvironment(environment: KotlinCoreEnvironment, testDataFile: File, files: MutableList<TestFile>) {
|
override fun setupEnvironment(environment: KotlinCoreEnvironment, testDataFile: File, files: List<TestFile>) {
|
||||||
val testDataFileText = testDataFile.readText()
|
val testDataFileText = testDataFile.readText()
|
||||||
val groupedByModule = files.groupBy(TestFile::module)
|
val groupedByModule = files.groupBy(TestFile::module)
|
||||||
val allKtFiles = groupedByModule.values.flatMap { getKtFiles(it, true) }
|
val allKtFiles = groupedByModule.values.flatMap { getKtFiles(it, true) }
|
||||||
|
|||||||
+2
-2
@@ -26,7 +26,7 @@ abstract class AbstractJavacDiagnosticsTest : AbstractDiagnosticsTest() {
|
|||||||
|
|
||||||
private var useJavac = true
|
private var useJavac = true
|
||||||
|
|
||||||
override fun setupEnvironment(environment: KotlinCoreEnvironment, testDataFile: File, files: MutableList<TestFile>) {
|
override fun setupEnvironment(environment: KotlinCoreEnvironment, testDataFile: File, files: List<TestFile>) {
|
||||||
if (useJavac) {
|
if (useJavac) {
|
||||||
val groupedByModule = files.groupBy(TestFile::module)
|
val groupedByModule = files.groupBy(TestFile::module)
|
||||||
val allKtFiles = groupedByModule.values.flatMap { getKtFiles(it, true) }
|
val allKtFiles = groupedByModule.values.flatMap { getKtFiles(it, true) }
|
||||||
@@ -46,7 +46,7 @@ abstract class AbstractJavacDiagnosticsTest : AbstractDiagnosticsTest() {
|
|||||||
return specialFile.takeIf { it.exists() } ?: super.getExpectedDiagnosticsFile(testDataFile)
|
return specialFile.takeIf { it.exists() } ?: super.getExpectedDiagnosticsFile(testDataFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createTestFiles(file: File, expectedText: String, modules: MutableMap<String, ModuleAndDependencies>?): List<TestFile> {
|
override fun createTestFiles(file: File, expectedText: String, modules: MutableMap<String?, ModuleAndDependencies>): List<TestFile> {
|
||||||
val specialFile = getExpectedDiagnosticsFile(file)
|
val specialFile = getExpectedDiagnosticsFile(file)
|
||||||
if (file.path == specialFile.path) {
|
if (file.path == specialFile.path) {
|
||||||
return super.createTestFiles(file, expectedText, modules)
|
return super.createTestFiles(file, expectedText, modules)
|
||||||
|
|||||||
+1
-1
@@ -25,7 +25,7 @@ abstract class AbstractJavacFieldResolutionTest : AbstractDiagnosticsTest() {
|
|||||||
|
|
||||||
private var useJavac = true
|
private var useJavac = true
|
||||||
|
|
||||||
override fun setupEnvironment(environment: KotlinCoreEnvironment, testDataFile: File, files: MutableList<TestFile>) {
|
override fun setupEnvironment(environment: KotlinCoreEnvironment, testDataFile: File, files: List<TestFile>) {
|
||||||
if (useJavac) {
|
if (useJavac) {
|
||||||
val groupedByModule = files.groupBy(TestFile::module)
|
val groupedByModule = files.groupBy(TestFile::module)
|
||||||
val allKtFiles = groupedByModule.values.flatMap { getKtFiles(it, true) }
|
val allKtFiles = groupedByModule.values.flatMap { getKtFiles(it, true) }
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ abstract class KotlinBaseTest<F : KotlinBaseTest.TestFile> : KtUsefulTestCase()
|
|||||||
doMultiFileTest(file, createTestFilesFromFile(file, expectedText))
|
doMultiFileTest(file, createTestFilesFromFile(file, expectedText))
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract fun createTestFilesFromFile(file: File, expectedText: String?): List<F>
|
protected abstract fun createTestFilesFromFile(file: File, expectedText: String): List<F>
|
||||||
|
|
||||||
@Throws(java.lang.Exception::class)
|
@Throws(java.lang.Exception::class)
|
||||||
protected open fun doMultiFileTest(
|
protected open fun doMultiFileTest(
|
||||||
|
|||||||
@@ -12,23 +12,23 @@ import org.jetbrains.kotlin.test.ConfigurationKind
|
|||||||
import org.jetbrains.kotlin.test.TestJdkKind
|
import org.jetbrains.kotlin.test.TestJdkKind
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
abstract class AbstractVisualizer : KotlinMultiFileTestWithJava<KotlinBaseTest.TestModule?, KotlinBaseTest.TestFile>() {
|
abstract class AbstractVisualizer : KotlinMultiFileTestWithJava<KotlinBaseTest.TestModule, KotlinBaseTest.TestFile>() {
|
||||||
lateinit var replacement: Pair<String, String>
|
lateinit var replacement: Pair<String, String>
|
||||||
|
|
||||||
override fun createTestModule(
|
override fun createTestModule(
|
||||||
name: String,
|
name: String,
|
||||||
dependencies: MutableList<String>,
|
dependencies: List<String>,
|
||||||
friends: MutableList<String>
|
friends: List<String>
|
||||||
): TestModule? = null
|
): TestModule? = null
|
||||||
|
|
||||||
|
|
||||||
override fun createTestFile(module: TestModule?, fileName: String?, text: String?, directives: MutableMap<String, String>?): TestFile? =
|
override fun createTestFile(module: TestModule?, fileName: String, text: String, directives: Map<String, String>): TestFile? =
|
||||||
null
|
null
|
||||||
|
|
||||||
|
|
||||||
override fun doMultiFileTest(file: File, files: List<TestFile>) {
|
override fun doMultiFileTest(wholeFile: File, files: List<TestFile>) {
|
||||||
val environment = createEnvironment(file, files)
|
val environment = createEnvironment(wholeFile, files)
|
||||||
doVisualizerTest(file, environment)
|
doVisualizerTest(wholeFile, environment)
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract fun doVisualizerTest(file: File, environment: KotlinCoreEnvironment)
|
abstract fun doVisualizerTest(file: File, environment: KotlinCoreEnvironment)
|
||||||
@@ -37,7 +37,7 @@ abstract class AbstractVisualizer : KotlinMultiFileTestWithJava<KotlinBaseTest.T
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getTestJdkKind(testFiles: MutableList<TestFile>): TestJdkKind {
|
override fun getTestJdkKind(files: List<TestFile>): TestJdkKind {
|
||||||
return TestJdkKind.FULL_JDK
|
return TestJdkKind.FULL_JDK
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user