From 02cffbd146d771dd66a77e0b4d8bd3211ee1ff15 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Thu, 16 Jul 2020 20:27:49 +0900 Subject: [PATCH] Remove remaining parts of "all files present" checking GitOrigin-RevId: 280ae5dabed1d52d9137d63ba3e58dffdd071255 --- .../level/api/AbstractFirLazyResolveTest.kt | 1 - ...radleConfigureProjectByChangingFileTest.kt | 17 +- .../resolve/AbstractIdeLightClassTest.kt | 1 - .../AbstractMultiFileLocalInspectionTest.kt | 1 - .../AbstractMultiFileIntentionTest.kt | 1 - .../AbstractMultifileRefactoringTest.kt | 2 - .../refactoring/rename/AbstractRenameTest.kt | 2 - ...tNewJavaToKotlinConverterSingleFileTest.kt | 3 +- .../AbstractMutabilityInferenceTest.kt | 3 +- .../AbstractNullabilityInferenceTest.kt | 3 +- .../org/jetbrains/kotlin/nj2k/testUtils.kt | 6 +- .../debugger/test/KotlinDescriptorTestCase.kt | 4 - ...MavenConfigureProjectByChangingFileTest.kt | 18 +- .../KotlinLightCodeInsightFixtureTestCase.kt | 6 - .../kotlin/idea/test/PluginTestCaseBase.java | 4 - .../kotlin/test/KotlinTestUtils.java | 165 +----------------- 16 files changed, 29 insertions(+), 208 deletions(-) diff --git a/plugins/kotlin/fir-low-level-api/test/org/jetbrains/kotlin/idea/fir/low/level/api/AbstractFirLazyResolveTest.kt b/plugins/kotlin/fir-low-level-api/test/org/jetbrains/kotlin/idea/fir/low/level/api/AbstractFirLazyResolveTest.kt index 8f56377e5272..ace046aed6aa 100644 --- a/plugins/kotlin/fir-low-level-api/test/org/jetbrains/kotlin/idea/fir/low/level/api/AbstractFirLazyResolveTest.kt +++ b/plugins/kotlin/fir-low-level-api/test/org/jetbrains/kotlin/idea/fir/low/level/api/AbstractFirLazyResolveTest.kt @@ -32,7 +32,6 @@ abstract class AbstractFirLazyResolveTest : KotlinLightCodeInsightFixtureTestCas override fun isFirPlugin(): Boolean = true override fun getProjectDescriptor(): LightProjectDescriptor { - if (KotlinTestUtils.isAllFilesPresentTest(getTestName(false))) return super.getProjectDescriptor() val testFile = File(testDataPath, fileName()) val config = JsonParser().parse(FileUtil.loadFile(testFile, true)) as JsonObject val withRuntime = config["withRuntime"]?.asBoolean ?: false diff --git a/plugins/kotlin/gradle/gradle-idea/test/org/jetbrains/kotlin/idea/configuration/AbstractGradleConfigureProjectByChangingFileTest.kt b/plugins/kotlin/gradle/gradle-idea/test/org/jetbrains/kotlin/idea/configuration/AbstractGradleConfigureProjectByChangingFileTest.kt index 6d4948a906b1..3a668d400c65 100644 --- a/plugins/kotlin/gradle/gradle-idea/test/org/jetbrains/kotlin/idea/configuration/AbstractGradleConfigureProjectByChangingFileTest.kt +++ b/plugins/kotlin/gradle/gradle-idea/test/org/jetbrains/kotlin/idea/configuration/AbstractGradleConfigureProjectByChangingFileTest.kt @@ -70,15 +70,14 @@ abstract class AbstractGradleConfigureProjectByChangingFileTest : } override fun getProjectJDK(): Sdk { - if (!isAllFilesPresentTest(getTestName(false))) { - val beforeAfterFiles = beforeAfterFiles() - val (before, _) = beforeAfterFiles - val gradleFile = File(testDataPath, before) - if (gradleFile.readText().contains("1.9")) { - return PluginTestCaseBase.mockJdk9() - } - } + val beforeAfterFiles = beforeAfterFiles() + val (before, _) = beforeAfterFiles + val gradleFile = File(testDataPath, before) - return super.getProjectJDK() + if (gradleFile.readText().contains("1.9")) { + return PluginTestCaseBase.mockJdk9() + } else { + return super.getProjectJDK() + } } } diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/caches/resolve/AbstractIdeLightClassTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/caches/resolve/AbstractIdeLightClassTest.kt index 78d037c63238..44f71ed2b619 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/caches/resolve/AbstractIdeLightClassTest.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/caches/resolve/AbstractIdeLightClassTest.kt @@ -97,7 +97,6 @@ abstract class AbstractIdeCompiledLightClassTest : KotlinDaemonAnalyzerTestCase( super.setUp() val testName = getTestName(false) - if (KotlinTestUtils.isAllFilesPresentTest(testName)) return val testDataDir = TestMetadataUtil.getTestData(this::class.java) val testFile = listOf(File(testDataDir, "$testName.kt"), File(testDataDir, "$testName.kts")).first { it.exists() } diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/inspections/AbstractMultiFileLocalInspectionTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/inspections/AbstractMultiFileLocalInspectionTest.kt index 20e1a945a34b..65b2a2eb34c3 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/inspections/AbstractMultiFileLocalInspectionTest.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/inspections/AbstractMultiFileLocalInspectionTest.kt @@ -26,7 +26,6 @@ import java.io.File abstract class AbstractMultiFileLocalInspectionTest : AbstractLocalInspectionTest() { override fun getProjectDescriptor(): LightProjectDescriptor { - if (KotlinTestUtils.isAllFilesPresentTest(getTestName(false))) return super.getProjectDescriptor() val testFile = File(testDataPath, fileName()) val config = JsonParser().parse(FileUtil.loadFile(testFile, true)) as JsonObject val withRuntime = config["withRuntime"]?.asBoolean ?: false diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/intentions/AbstractMultiFileIntentionTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/intentions/AbstractMultiFileIntentionTest.kt index 181215197c6e..41e9a478b99e 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/intentions/AbstractMultiFileIntentionTest.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/intentions/AbstractMultiFileIntentionTest.kt @@ -31,7 +31,6 @@ import java.io.File abstract class AbstractMultiFileIntentionTest : KotlinLightCodeInsightFixtureTestCase() { override fun getProjectDescriptor(): LightProjectDescriptor { - if (KotlinTestUtils.isAllFilesPresentTest(getTestName(false))) return super.getProjectDescriptor() val testFile = File(testDataPath, fileName()) val config = JsonParser().parse(FileUtil.loadFile(testFile, true)) as JsonObject val withRuntime = config["withRuntime"]?.asBoolean ?: false diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/AbstractMultifileRefactoringTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/AbstractMultifileRefactoringTest.kt index 5b598dd1e044..3ccddb23ecbc 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/AbstractMultifileRefactoringTest.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/AbstractMultifileRefactoringTest.kt @@ -38,8 +38,6 @@ abstract class AbstractMultifileRefactoringTest : KotlinLightCodeInsightFixtureT } override fun getProjectDescriptor(): LightProjectDescriptor { - if (KotlinTestUtils.isAllFilesPresentTest(getTestName(false))) return super.getProjectDescriptor() - val testConfigurationFile = File(super.getTestDataPath(), fileName()) val config = loadTestConfiguration(testConfigurationFile) val withRuntime = config["withRuntime"]?.asBoolean ?: false diff --git a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/rename/AbstractRenameTest.kt b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/rename/AbstractRenameTest.kt index 321db52ee715..9d78f017fe46 100644 --- a/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/rename/AbstractRenameTest.kt +++ b/plugins/kotlin/idea/tests/test/org/jetbrains/kotlin/idea/refactoring/rename/AbstractRenameTest.kt @@ -82,8 +82,6 @@ abstract class AbstractRenameTest : KotlinLightCodeInsightFixtureTestCase() { ) override fun getProjectDescriptor(): LightProjectDescriptor { - if (KotlinTestUtils.isAllFilesPresentTest(getTestName(false))) return super.getProjectDescriptor() - val testConfigurationFile = File(testDataPath, fileName()) val renameObject = loadTestConfiguration(testConfigurationFile) val withRuntime = renameObject.getNullableString("withRuntime") diff --git a/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/AbstractNewJavaToKotlinConverterSingleFileTest.kt b/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/AbstractNewJavaToKotlinConverterSingleFileTest.kt index 24adfedf54f6..cc51edd2f8b0 100644 --- a/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/AbstractNewJavaToKotlinConverterSingleFileTest.kt +++ b/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/AbstractNewJavaToKotlinConverterSingleFileTest.kt @@ -55,6 +55,5 @@ abstract class AbstractNewJavaToKotlinConverterSingleFileTest : AbstractJavaToKo File(javaPath.replace(".java", ".new.kt")).takeIf { it.exists() } ?: super.provideExpectedFile(javaPath) - override fun getProjectDescriptor() = - descriptorByFileDirective(File(testDataPath, fileName()), isAllFilesPresentInTest()) + override fun getProjectDescriptor() = descriptorByFileDirective(File(testDataPath, fileName())) } diff --git a/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/inference/mutability/AbstractMutabilityInferenceTest.kt b/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/inference/mutability/AbstractMutabilityInferenceTest.kt index d9d89435aafd..4e8499c01a3d 100644 --- a/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/inference/mutability/AbstractMutabilityInferenceTest.kt +++ b/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/inference/mutability/AbstractMutabilityInferenceTest.kt @@ -77,6 +77,5 @@ abstract class AbstractMutabilityInferenceTest : AbstractConstraintCollectorTest deleteComments() } - override fun getProjectDescriptor() = - descriptorByFileDirective(File(testDataPath, fileName()), isAllFilesPresentInTest()) + override fun getProjectDescriptor() = descriptorByFileDirective(File(testDataPath, fileName())) } \ No newline at end of file diff --git a/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/inference/nullability/AbstractNullabilityInferenceTest.kt b/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/inference/nullability/AbstractNullabilityInferenceTest.kt index fa9487876f48..9da6a97682c9 100644 --- a/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/inference/nullability/AbstractNullabilityInferenceTest.kt +++ b/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/inference/nullability/AbstractNullabilityInferenceTest.kt @@ -70,6 +70,5 @@ abstract class AbstractNullabilityInferenceTest : AbstractConstraintCollectorTes super.tearDown() } - override fun getProjectDescriptor() = - descriptorByFileDirective(File(testDataPath, fileName()), isAllFilesPresentInTest()) + override fun getProjectDescriptor() = descriptorByFileDirective(File(testDataPath, fileName())) } \ No newline at end of file diff --git a/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/testUtils.kt b/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/testUtils.kt index d6c8522856d8..91b58a87eb8f 100644 --- a/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/testUtils.kt +++ b/plugins/kotlin/j2k/new/tests/test/org/jetbrains/kotlin/nj2k/testUtils.kt @@ -19,10 +19,9 @@ import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescrip import org.jetbrains.kotlin.test.InTextDirectivesUtils import java.io.File -fun descriptorByFileDirective(testDataFile: File, isAllFilesPresentInTest: Boolean) = - object : KotlinWithJdkAndRuntimeLightProjectDescriptor() { +fun descriptorByFileDirective(testDataFile: File): KotlinWithJdkAndRuntimeLightProjectDescriptor { + return object : KotlinWithJdkAndRuntimeLightProjectDescriptor() { private fun projectDescriptorByFileDirective(): LightProjectDescriptor { - if (isAllFilesPresentInTest) return INSTANCE val fileText = FileUtil.loadFile(testDataFile, true) return if (InTextDirectivesUtils.isDirectiveDefined(fileText, "RUNTIME_WITH_FULL_JDK")) INSTANCE_FULL_JDK @@ -44,4 +43,5 @@ fun descriptorByFileDirective(testDataFile: File, isAllFilesPresentInTest: Boole model.getModuleExtension(LanguageLevelModuleExtension::class.java).languageLevel = LanguageLevel.JDK_1_8 } } +} diff --git a/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/KotlinDescriptorTestCase.kt b/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/KotlinDescriptorTestCase.kt index 094658c91955..05e3b9731c79 100644 --- a/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/KotlinDescriptorTestCase.kt +++ b/plugins/kotlin/jvm-debugger/test/test/org/jetbrains/kotlin/idea/debugger/test/KotlinDescriptorTestCase.kt @@ -223,10 +223,6 @@ abstract class KotlinDescriptorTestCase : DescriptorTestCase() { } override fun checkTestOutput() { - if (isAllFilesPresentTest(getTestName(false))) { - return - } - try { super.checkTestOutput() } catch (e: ComparisonFailure) { diff --git a/plugins/kotlin/maven/test/org/jetbrains/kotlin/idea/maven/configuration/AbstractMavenConfigureProjectByChangingFileTest.kt b/plugins/kotlin/maven/test/org/jetbrains/kotlin/idea/maven/configuration/AbstractMavenConfigureProjectByChangingFileTest.kt index e1ba97ea3a78..bd6c1e72c5b1 100644 --- a/plugins/kotlin/maven/test/org/jetbrains/kotlin/idea/maven/configuration/AbstractMavenConfigureProjectByChangingFileTest.kt +++ b/plugins/kotlin/maven/test/org/jetbrains/kotlin/idea/maven/configuration/AbstractMavenConfigureProjectByChangingFileTest.kt @@ -25,7 +25,6 @@ import org.jetbrains.kotlin.idea.configuration.AbstractConfigureProjectByChangin import org.jetbrains.kotlin.idea.configuration.NotificationMessageCollector import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.test.KotlinTestUtils -import org.jetbrains.kotlin.test.KotlinTestUtils.isAllFilesPresentTest import java.io.File abstract class AbstractMavenConfigureProjectByChangingFileTest : AbstractConfigureProjectByChangingFileTest() { @@ -52,16 +51,15 @@ abstract class AbstractMavenConfigureProjectByChangingFileTest : AbstractConfigu } override fun getProjectJDK(): Sdk { - if (!isAllFilesPresentTest(getTestName(false))) { - val root = KotlinTestUtils.getTestsRoot(this::class.java) - val dir = KotlinTestUtils.getTestDataFileName(this::class.java, name) + val root = KotlinTestUtils.getTestsRoot(this::class.java) + val dir = KotlinTestUtils.getTestDataFileName(this::class.java, name) - val pomFile = File("$root/$dir", MavenConstants.POM_XML) - if (pomFile.readText().contains("9")) { - return PluginTestCaseBase.mockJdk9() - } + val pomFile = File("$root/$dir", MavenConstants.POM_XML) + + if (pomFile.readText().contains("9")) { + return PluginTestCaseBase.mockJdk9() + } else { + return super.getProjectJDK() } - - return super.getProjectJDK() } } diff --git a/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt b/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt index 2120b6c8e3c0..89ac4a29fec0 100644 --- a/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt +++ b/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/KotlinLightCodeInsightFixtureTestCase.kt @@ -161,10 +161,6 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix } private fun getProjectDescriptorFromFileDirective(): LightProjectDescriptor { - if (isAllFilesPresentInTest()) { - return KotlinLightProjectDescriptor.INSTANCE - } - val file = File(testDataPath, fileName()) if (!file.exists()) { return KotlinLightProjectDescriptor.INSTANCE @@ -218,8 +214,6 @@ abstract class KotlinLightCodeInsightFixtureTestCase : KotlinLightCodeInsightFix protected open fun getDefaultProjectDescriptor(): KotlinLightProjectDescriptor = KotlinLightProjectDescriptor.INSTANCE - protected fun isAllFilesPresentInTest(): Boolean = KotlinTestUtils.isAllFilesPresentTest(getTestName(false)) - protected fun performNotWriteEditorAction(actionId: String): Boolean { val dataContext = (myFixture.editor as EditorEx).dataContext diff --git a/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/PluginTestCaseBase.java b/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/PluginTestCaseBase.java index ebcccc6f91b3..067b4768b543 100644 --- a/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/PluginTestCaseBase.java +++ b/plugins/kotlin/test-framework/test/org/jetbrains/kotlin/idea/test/PluginTestCaseBase.java @@ -121,10 +121,6 @@ public class PluginTestCaseBase { } } - public static boolean isAllFilesPresentTest(@NotNull String testName) { - return StringUtil.startsWithIgnoreCase(testName, "allFilesPresentIn"); - } - @TestOnly public static void clearSdkTable(@NotNull Disposable disposable) { Disposer.register(disposable, () -> ApplicationManager.getApplication().runWriteAction(() -> { diff --git a/plugins/kotlin/tests-common/test/org/jetbrains/kotlin/test/KotlinTestUtils.java b/plugins/kotlin/tests-common/test/org/jetbrains/kotlin/test/KotlinTestUtils.java index 13de96b0d1ad..6c4d0928f1bf 100644 --- a/plugins/kotlin/tests-common/test/org/jetbrains/kotlin/test/KotlinTestUtils.java +++ b/plugins/kotlin/tests-common/test/org/jetbrains/kotlin/test/KotlinTestUtils.java @@ -11,7 +11,10 @@ import com.intellij.openapi.editor.Caret; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.*; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.Ref; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.util.text.StringUtilRt; @@ -27,29 +30,21 @@ import com.intellij.testFramework.UsefulTestCase; import com.intellij.util.PathUtil; import com.intellij.util.containers.ContainerUtil; import junit.framework.TestCase; -import kotlin.Unit; import kotlin.collections.CollectionsKt; -import kotlin.collections.SetsKt; -import kotlin.jvm.functions.Function0; import kotlin.jvm.functions.Function1; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.kotlin.analyzer.AnalysisResult; import org.jetbrains.kotlin.builtins.DefaultBuiltIns; import org.jetbrains.kotlin.builtins.KotlinBuiltIns; import org.jetbrains.kotlin.checkers.CompilerTestLanguageVersionSettings; -import org.jetbrains.kotlin.checkers.CompilerTestLanguageVersionSettingsKt; import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys; -import org.jetbrains.kotlin.cli.common.config.ContentRootsKt; -import org.jetbrains.kotlin.cli.common.config.KotlinSourceRoot; -import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation; import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity; +import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSourceLocation; import org.jetbrains.kotlin.cli.common.messages.MessageCollector; import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles; import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment; import org.jetbrains.kotlin.cli.jvm.config.JvmContentRootsKt; -import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime; import org.jetbrains.kotlin.config.*; import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl; import org.jetbrains.kotlin.idea.KotlinLanguage; @@ -57,8 +52,6 @@ import org.jetbrains.kotlin.idea.artifacts.KotlinArtifacts; import org.jetbrains.kotlin.lexer.KtTokens; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.KtFile; -import org.jetbrains.kotlin.psi.KtPsiFactoryKt; -import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil; import org.jetbrains.kotlin.storage.LockBasedStorageManager; import org.jetbrains.kotlin.test.util.JetTestUtilsKt; import org.jetbrains.kotlin.utils.ExceptionUtilsKt; @@ -69,7 +62,6 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.StringWriter; -import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.nio.charset.Charset; import java.nio.file.Files; @@ -79,13 +71,12 @@ import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static org.jetbrains.kotlin.test.InTextDirectivesUtils.*; +import static org.jetbrains.kotlin.test.InTextDirectivesUtils.IGNORE_BACKEND_DIRECTIVE_PREFIX; +import static org.jetbrains.kotlin.test.InTextDirectivesUtils.isIgnoredTarget; public class KotlinTestUtils { public static final String TEST_MODULE_NAME = "test-module"; - private static final String PLEASE_REGENERATE_TESTS = "Please regenerate tests (GenerateTests.kt)"; - private static final boolean RUN_IGNORED_TESTS_AS_REGULAR = Boolean.getBoolean("org.jetbrains.kotlin.run.ignored.tests.as.regular"); @@ -758,145 +749,12 @@ public class KotlinTestUtils { } } - public static void assertAllTestsPresentByMetadataWithExcluded( - @NotNull Class testCaseClass, - @NotNull File testDataDir, - @NotNull Pattern filenamePattern, - @Nullable Pattern excludedPattern, - boolean recursive, - @NotNull String... excludeDirs - ) { - assertAllTestsPresentByMetadataWithExcluded(testCaseClass, testDataDir, filenamePattern, excludedPattern, TargetBackend.ANY, recursive, excludeDirs); - } - - public static void assertAllTestsPresentByMetadataWithExcluded( - @NotNull Class testCaseClass, - @NotNull File testDataDir, - @NotNull Pattern filenamePattern, - @Nullable Pattern excludedPattern, - @NotNull TargetBackend targetBackend, - boolean recursive, - @NotNull String... excludeDirs - ) { - File rootFile = new File(getTestsRoot(testCaseClass)); - - Set filePaths = collectPathsMetadata(testCaseClass); - Set exclude = SetsKt.setOf(excludeDirs); - - File[] files = testDataDir.listFiles(); - if (files != null) { - for (File file : files) { - if (file.isDirectory()) { - if (recursive && containsTestData(file, filenamePattern, excludedPattern) && !exclude.contains(file.getName())) { - assertTestClassPresentByMetadata(testCaseClass, file); - } - } - else { - boolean excluded = excludedPattern != null && excludedPattern.matcher(file.getName()).matches(); - if (!excluded && filenamePattern.matcher(file.getName()).matches() && isCompatibleTarget(targetBackend, file)) { - assertFilePathPresent(file, rootFile, filePaths); - } - } - } - } - } - - public static void assertAllTestsPresentInSingleGeneratedClass( - @NotNull Class testCaseClass, - @NotNull File testDataDir, - @NotNull Pattern filenamePattern, - @NotNull TargetBackend targetBackend - ) { - assertAllTestsPresentInSingleGeneratedClass(testCaseClass, testDataDir, filenamePattern, null, targetBackend); - } - - public static void assertAllTestsPresentInSingleGeneratedClass( - @NotNull Class testCaseClass, - @NotNull File testDataDir, - @NotNull Pattern filenamePattern, - @Nullable Pattern excludePattern, - @NotNull TargetBackend targetBackend - ) { - File rootFile = new File(getTestsRoot(testCaseClass)); - - Set filePaths = collectPathsMetadata(testCaseClass); - - FileUtil.processFilesRecursively(testDataDir, file -> { - boolean excluded = excludePattern != null && excludePattern.matcher(file.getName()).matches(); - if (file.isFile() && !excluded && filenamePattern.matcher(file.getName()).matches() && isCompatibleTarget(targetBackend, file)) { - assertFilePathPresent(file, rootFile, filePaths); - } - - return true; - }); - } - - private static void assertFilePathPresent(File file, File rootFile, Set filePaths) { - String path = FileUtil.getRelativePath(rootFile, file); - if (path != null) { - String relativePath = nameToCompare(path); - if (!filePaths.contains(relativePath)) { - Assert.fail("Test data file missing from the generated test class: " + file + "\n" + PLEASE_REGENERATE_TESTS); - } - } - } - - private static Set collectPathsMetadata(Class testCaseClass) { - return ContainerUtil.newHashSet(ContainerUtil.map(collectMethodsMetadata(testCaseClass), KotlinTestUtils::nameToCompare)); - } - @Nullable private static String getMethodMetadata(Method method) { TestMetadata testMetadata = method.getAnnotation(TestMetadata.class); return (testMetadata != null) ? testMetadata.value() : null; } - private static Set collectMethodsMetadata(Class testCaseClass) { - Set filePaths = new HashSet<>(); - for (Method method : testCaseClass.getDeclaredMethods()) { - String path = getMethodMetadata(method); - if (path != null) { - filePaths.add(path); - } - } - return filePaths; - } - - private static boolean containsTestData(File dir, Pattern filenamePattern, @Nullable Pattern excludedPattern) { - File[] files = dir.listFiles(); - assert files != null; - for (File file : files) { - if (file.isDirectory()) { - if (containsTestData(file, filenamePattern, excludedPattern)) { - return true; - } - } - else { - boolean excluded = excludedPattern != null && excludedPattern.matcher(file.getName()).matches(); - if (! excluded && filenamePattern.matcher(file.getName()).matches()) { - return true; - } - } - } - return false; - } - - private static void assertTestClassPresentByMetadata(@NotNull Class outerClass, @NotNull File testDataDir) { - for (Class nestedClass : outerClass.getDeclaredClasses()) { - TestMetadata testMetadata = nestedClass.getAnnotation(TestMetadata.class); - if (testMetadata != null && testMetadata.value().equals(getFilePath(testDataDir))) { - return; - } - } - Assert.fail("Test data directory missing from the generated test class: " + testDataDir + "\n" + PLEASE_REGENERATE_TESTS); - } - - @NotNull - public static KtFile loadJetFile(@NotNull Project project, @NotNull File ioFile) throws IOException { - String text = FileUtil.loadFile(ioFile, true); - return KtPsiFactoryKt.KtPsiFactory(project).createPhysicalFile(ioFile.getName(), text); - } - @NotNull public static ModuleDescriptorImpl createEmptyModule() { return createEmptyModule(""); @@ -917,15 +775,6 @@ public class KotlinTestUtils { return new File(file.getParentFile(), FileUtil.getNameWithoutExtension(file) + (newExtension == null ? "" : "." + newExtension)); } - public static boolean isAllFilesPresentTest(String testName) { - //noinspection SpellCheckingInspection - return testName.toLowerCase().startsWith("allfilespresentin"); - } - - public static String nameToCompare(@NotNull String name) { - return (SystemInfo.isFileSystemCaseSensitive ? name : name.toLowerCase()).replace('\\', '/'); - } - public static boolean isMultiExtensionName(@NotNull String name) { int firstDotIndex = name.indexOf('.'); if (firstDotIndex == -1) {