Skip to content

Commit 09e21c5

Browse files
dimonchik0036Space Team
authored and
Space Team
committed
[Analysis API] AnalysisApiTestConfigurator: convert testPrefix -> testPrefixes
It allows us to provide a few prefixes at once to avoid duplication. Use case: 3 tests use one test data file. The first test has some output. The second one can either produce the same output or provide another with some prefix. And the last one can either produce the same output as any previous one or a new one. With `testPrefixes` we can allow the last one to reuse both other outputs (without a prefix and with one prefix) ^KT-71787
1 parent 74d2147 commit 09e21c5

File tree

11 files changed

+38
-56
lines changed

11 files changed

+38
-56
lines changed

analysis/analysis-api-fe10/tests/org/jetbrains/kotlin/analysis/api/fe10/test/configurator/AnalysisApiFe10TestConfigurator.kt

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -11,14 +11,11 @@ import org.jetbrains.kotlin.analysis.api.impl.base.test.configurators.AnalysisAp
1111
import org.jetbrains.kotlin.analysis.api.impl.base.test.configurators.AnalysisApiDecompiledCodeTestServiceRegistrar
1212
import org.jetbrains.kotlin.analysis.api.impl.base.test.configurators.AnalysisApiIdeModeTestServiceRegistrar
1313
import org.jetbrains.kotlin.analysis.api.standalone.base.projectStructure.AnalysisApiServiceRegistrar
14-
import org.jetbrains.kotlin.analysis.test.framework.projectStructure.KtSourceTestModuleFactory
15-
import org.jetbrains.kotlin.analysis.test.framework.projectStructure.KtTestModule
16-
import org.jetbrains.kotlin.analysis.test.framework.projectStructure.KtTestModuleFactory
17-
import org.jetbrains.kotlin.analysis.test.framework.projectStructure.KtTestModuleStructure
18-
import org.jetbrains.kotlin.analysis.test.framework.projectStructure.TestModuleStructureFactory
14+
import org.jetbrains.kotlin.analysis.test.framework.projectStructure.*
1915
import org.jetbrains.kotlin.analysis.test.framework.services.configuration.AnalysisApiBinaryLibraryIndexingMode
2016
import org.jetbrains.kotlin.analysis.test.framework.services.configuration.AnalysisApiIndexingConfiguration
21-
import org.jetbrains.kotlin.analysis.test.framework.services.libraries.*
17+
import org.jetbrains.kotlin.analysis.test.framework.services.libraries.configureLibraryCompilationSupport
18+
import org.jetbrains.kotlin.analysis.test.framework.services.libraries.configurePlatformEnvironmentConfigurators
2219
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfigurator
2320
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.FrontendKind
2421
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
@@ -32,11 +29,8 @@ import kotlin.io.path.nameWithoutExtension
3229

3330
object AnalysisApiFe10TestConfigurator : AnalysisApiTestConfigurator() {
3431
override val analyseInDependentSession: Boolean get() = false
35-
3632
override val frontendKind: FrontendKind get() = FrontendKind.Fe10
37-
38-
override val testPrefix: String
39-
get() = "descriptors"
33+
override val testPrefixes: List<String> get() = listOf("descriptors")
4034

4135
override fun configureTest(builder: TestConfigurationBuilder, disposable: Disposable) {
4236
builder.apply {
@@ -72,7 +66,7 @@ object AnalysisApiFe10TestConfigurator : AnalysisApiTestConfigurator() {
7266
}
7367

7468
override fun computeTestDataPath(path: Path): Path {
75-
val newPath = path.resolveSibling(path.nameWithoutExtension + "." + testPrefix + "." + path.extension)
69+
val newPath = path.resolveSibling(path.nameWithoutExtension + "." + testPrefixes.single() + "." + path.extension)
7670
if (newPath.toFile().exists()) return newPath
7771
return path
7872
}

analysis/analysis-api-impl-base/tests/org/jetbrains/kotlin/analysis/api/impl/base/test/cases/session/AbstractSessionInvalidationTest.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

66
package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.session
77

8-
import org.jetbrains.kotlin.analysis.api.projectStructure.KaModule
98
import org.jetbrains.kotlin.analysis.api.platform.modification.KotlinModificationEventKind
9+
import org.jetbrains.kotlin.analysis.api.projectStructure.KaModule
1010
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiBasedTest
1111
import org.jetbrains.kotlin.analysis.test.framework.directives.publishWildcardModificationEventsByDirective
1212
import org.jetbrains.kotlin.analysis.test.framework.projectStructure.ktTestModuleStructure
@@ -90,7 +90,7 @@ abstract class AbstractSessionInvalidationTest<SESSION> : AbstractAnalysisApiBas
9090
// Standalone modes) to have different test results (since `testPrefix` normally supports this functionality), but (1) we are
9191
// currently only testing the IDE mode and (2) the test results between different modes should not differ for session
9292
// invalidation in the first place.
93-
testPrefix = resultFileSuffix,
93+
testPrefixes = listOfNotNull(resultFileSuffix),
9494
)
9595
}
9696

analysis/analysis-api-standalone/tests/org/jetbrains/kotlin/analysis/api/standalone/fir/test/configurators/StandaloneModeConfiguratorBase.kt

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -15,9 +15,7 @@ import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
1515
abstract class StandaloneModeConfiguratorBase : AnalysisApiTestConfigurator() {
1616
override val analyseInDependentSession: Boolean get() = false
1717
override val frontendKind: FrontendKind get() = FrontendKind.Fir
18-
19-
override val testPrefix: String
20-
get() = "standalone.fir"
18+
override val testPrefixes: List<String> get() = listOf("standalone.fir")
2119

2220
override fun configureTest(builder: TestConfigurationBuilder, disposable: Disposable) {
2321
builder.apply {

analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/base/AbstractAnalysisApiBasedTest.kt

+6-19
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -282,19 +282,6 @@ abstract class AbstractAnalysisApiBasedTest : TestWithDisposable() {
282282
file.virtualFile.nameWithoutExtension == ktTestModule.testModule.mainFileName
283283
}
284284

285-
/**
286-
* Checks whether the [actual] string matches the content of the test output file.
287-
*
288-
* Check the [assertEqualsToTestDataFileSibling] overload accepting a prefix list for more information.
289-
*/
290-
protected fun AssertionsService.assertEqualsToTestDataFileSibling(
291-
actual: String,
292-
extension: String = ".txt",
293-
testPrefix: String? = configurator.testPrefix,
294-
) {
295-
assertEqualsToTestDataFileSibling(actual, extension, listOfNotNull(testPrefix))
296-
}
297-
298285
/**
299286
* Checks whether the [actual] string matches the content of the test output file.
300287
*
@@ -311,7 +298,7 @@ abstract class AbstractAnalysisApiBasedTest : TestWithDisposable() {
311298
protected fun AssertionsService.assertEqualsToTestDataFileSibling(
312299
actual: String,
313300
extension: String = ".txt",
314-
testPrefixes: List<String>,
301+
testPrefixes: List<String> = configurator.testPrefixes,
315302
) {
316303
val expectedFiles = buildList {
317304
testPrefixes.mapNotNullTo(this) { findPrefixedTestDataSibling(extension, it) }
@@ -331,11 +318,11 @@ abstract class AbstractAnalysisApiBasedTest : TestWithDisposable() {
331318
}
332319

333320
/**
334-
* Returns the test output file with a [testPrefix] if it exists, of the non-prefixed (default) test output file.
321+
* Returns the test output file with any of [testPrefixes] if it exists, of the non-prefixed (default) test output file.
335322
*/
336-
protected fun getTestDataSibling(extension: String = "txt", testPrefix: String? = configurator.testPrefix): Path {
337-
if (testPrefix != null) {
338-
findPrefixedTestDataSibling(extension, testPrefix)?.let { return it }
323+
protected fun getTestDataSibling(extension: String = "txt", testPrefixes: List<String> = configurator.testPrefixes): Path {
324+
for (prefix in testPrefixes) {
325+
findPrefixedTestDataSibling(extension, prefix)?.let { return it }
339326
}
340327

341328
return getDefaultTestDataSibling(extension)

analysis/analysis-test-framework/tests/org/jetbrains/kotlin/analysis/test/framework/test/configurators/AnalysisApiTestConfigurator.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -20,7 +20,10 @@ import org.jetbrains.kotlin.test.testFramework.runWriteAction
2020
import java.nio.file.Path
2121

2222
abstract class AnalysisApiTestConfigurator {
23-
open val testPrefix: String? get() = null
23+
/**
24+
* @see org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiBasedTest.assertEqualsToTestDataFileSibling
25+
*/
26+
open val testPrefixes: List<String> get() = emptyList()
2427

2528
abstract val frontendKind: FrontendKind
2629

analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/test/configurators/AnalysisApiFirLibrarySourceTestConfigurator.kt

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -21,7 +21,8 @@ import org.jetbrains.kotlin.analysis.test.framework.projectStructure.TestModuleS
2121
import org.jetbrains.kotlin.analysis.test.framework.services.configuration.AnalysisApiBinaryLibraryIndexingMode
2222
import org.jetbrains.kotlin.analysis.test.framework.services.configuration.AnalysisApiIndexingConfiguration
2323
import org.jetbrains.kotlin.analysis.test.framework.services.configuration.AnalysisApiJvmEnvironmentConfigurator
24-
import org.jetbrains.kotlin.analysis.test.framework.services.libraries.*
24+
import org.jetbrains.kotlin.analysis.test.framework.services.libraries.DispatchingTestModuleCompiler
25+
import org.jetbrains.kotlin.analysis.test.framework.services.libraries.TestModuleCompiler
2526
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfigurator
2627
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.FrontendKind
2728
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
@@ -32,7 +33,7 @@ import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurato
3233
object AnalysisApiFirLibrarySourceTestConfigurator : AnalysisApiTestConfigurator() {
3334
override val analyseInDependentSession: Boolean get() = false
3435
override val frontendKind: FrontendKind get() = FrontendKind.Fir
35-
override val testPrefix: String get() = "librarySource"
36+
override val testPrefixes: List<String> get() = listOf("librarySource")
3637

3738
override fun configureTest(
3839
builder: TestConfigurationBuilder,

analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/test/configurators/AnalysisApiFirOutOfContentRootTestConfigurator.kt

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -30,8 +30,7 @@ import org.jetbrains.kotlin.test.services.targetPlatform
3030
import java.nio.file.Path
3131

3232
object AnalysisApiFirOutOfContentRootTestConfigurator : AnalysisApiFirSourceLikeTestConfigurator(false) {
33-
override val testPrefix: String
34-
get() = "out_of_src_roots"
33+
override val testPrefixes: List<String> get() = listOf("out_of_src_roots")
3534

3635
override fun configureTest(builder: TestConfigurationBuilder, disposable: Disposable) {
3736
super.configureTest(builder, disposable)

analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/test/configurators/AnalysisApiFirSourceLikeTestConfigurator.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -40,8 +40,8 @@ abstract class AnalysisApiFirSourceLikeTestConfigurator(override val analyseInDe
4040
}
4141
}
4242

43-
override val testPrefix: String?
44-
get() = if (analyseInDependentSession) "dependent.fir" else null
43+
override val testPrefixes: List<String>
44+
get() = if (analyseInDependentSession) listOf("dependent.fir") else emptyList()
4545

4646
override val serviceRegistrars: List<AnalysisApiServiceRegistrar<TestServices>> = listOf(
4747
AnalysisApiBaseTestServiceRegistrar,

analysis/symbol-light-classes/tests/org/jetbrains/kotlin/light/classes/symbol/base/AbstractSymbolLightClassesStructureByFqNameTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -31,7 +31,7 @@ abstract class AbstractSymbolLightClassesStructureByFqNameTest(
3131
psiClass?.let { handleClass(it) } ?: append(LightClassTestCommon.NOT_GENERATED_DIRECTIVE)
3232
}
3333

34-
testServices.assertions.assertEqualsToTestDataFileSibling(result, testPrefix = testPrefix)
34+
testServices.assertions.assertEqualsToTestDataFileSibling(result, testPrefixes = listOf(testPrefix))
3535

3636
doTestInheritors(ktFiles, testServices)
3737
}

analysis/symbol-light-classes/tests/org/jetbrains/kotlin/light/classes/symbol/base/AbstractSymbolLightClassesStructureTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -32,7 +32,7 @@ abstract class AbstractSymbolLightClassesStructureTest(
3232
}
3333
}
3434

35-
testServices.assertions.assertEqualsToTestDataFileSibling(result, testPrefix = testPrefix)
35+
testServices.assertions.assertEqualsToTestDataFileSibling(result, testPrefixes = listOf(testPrefix))
3636
doTestInheritors(ktFiles, testServices)
3737
}
3838
}

analysis/symbol-light-classes/tests/org/jetbrains/kotlin/light/classes/symbol/base/AbstractSymbolLightClassesStructureTestBase.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -35,7 +35,7 @@ open class AbstractSymbolLightClassesStructureTestBase(
3535
) : AbstractSymbolLightClassesTestBase(configurator) {
3636
override val currentExtension: String get() = throw UnsupportedOperationException()
3737
protected fun doTestInheritors(ktFiles: List<KtFile>, testServices: TestServices) {
38-
val testData = getTestDataSibling(extension = INHERITORS_EXTENSION, testPrefix = testPrefix)
38+
val testData = getTestDataSibling(extension = INHERITORS_EXTENSION, testPrefixes = listOf(testPrefix))
3939
if (testData.notExists()) return
4040
val project = ktFiles.first().project
4141

@@ -63,8 +63,8 @@ open class AbstractSymbolLightClassesStructureTestBase(
6363

6464
testServices.assertions.assertEqualsToTestDataFileSibling(
6565
actual = result,
66-
testPrefix = testPrefix,
6766
extension = INHERITORS_EXTENSION,
67+
testPrefixes = listOf(testPrefix),
6868
)
6969
}
7070

0 commit comments

Comments
 (0)