diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/NativeGenerationState.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/NativeGenerationState.kt index 4764fa7caa5..27afb345765 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/NativeGenerationState.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/NativeGenerationState.kt @@ -58,9 +58,6 @@ internal class NativeGenerationState(private val context: Context) { getLocalClassName(source)?.let { name -> putLocalClassName(destination, name) } } - /* test suite class -> test function names */ - val testCasesToDump = mutableMapOf>() - init { llvmContext = LLVMContextCreate()!! } diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt index 8314c6d0fa6..44d5e414946 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/ToplevelPhases.kt @@ -361,29 +361,6 @@ internal val umbrellaCompilation = NamedCompilerPhase( } }) -internal val dumpTestsPhase = makeCustomPhase( - name = "dumpTestsPhase", - description = "Dump the list of all available tests", - op = { context, _ -> - val testDumpFile = context.config.testDumpFile - requireNotNull(testDumpFile) - - if (!testDumpFile.exists) - testDumpFile.createNew() - - if (context.generationState.testCasesToDump.isEmpty()) - return@makeCustomPhase - - testDumpFile.appendLines( - context.generationState.testCasesToDump - .flatMap { (suiteClassId, functionNames) -> - val suiteName = suiteClassId.asString() - functionNames.asSequence().map { "$suiteName:$it" } - } - ) - } -) - internal val entryPointPhase = makeCustomPhase( name = "addEntryPoint", description = "Add entry point for program", @@ -447,7 +424,6 @@ private val backendCodegen = NamedCompilerPhase( allLoweringsPhase then // Lower current module first. dependenciesLowerPhase then // Then lower all libraries in topological order. // With that we guarantee that inline functions are unlowered while being inlined. - dumpTestsPhase then bitcodePhase then verifyBitcodePhase then printBitcodePhase then @@ -566,7 +542,6 @@ internal fun PhaseConfig.konanPhasesConfig(config: KonanConfig) { disable(linkerPhase) } disableIf(testProcessorPhase, getNotNull(KonanConfigKeys.GENERATE_TEST_RUNNER) == TestRunnerKind.NONE) - disableIf(dumpTestsPhase, getNotNull(KonanConfigKeys.GENERATE_TEST_RUNNER) == TestRunnerKind.NONE || config.testDumpFile == null) if (!config.optimizationsEnabled) { disable(buildDFGPhase) disable(devirtualizationAnalysisPhase) diff --git a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt index 41c68b7f914..579630556f8 100644 --- a/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt +++ b/kotlin-native/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/lower/TestProcessor.kt @@ -65,6 +65,7 @@ internal class TestProcessor (val context: Context) { // region Useful extensions. private var testSuiteCnt = 0 + private fun Name.synthesizeSuiteClassName() = identifier.synthesizeSuiteClassName() private fun String.synthesizeSuiteClassName() = "$this\$test\$${testSuiteCnt++}".synthesizedName @@ -638,11 +639,14 @@ internal class TestProcessor (val context: Context) { // region test functions to be dumped private fun recordTestFunctions(annotationCollector: AnnotationCollector) { - if (context.config.testDumpFile == null) return + val testDumpFile = context.config.testDumpFile ?: return + + /* test suite class -> test function names */ + val testCasesToDump = mutableMapOf>() fun recordFunction(suiteClassId: ClassId, function: TestFunction) { if (function.kind == FunctionKind.TEST) - context.generationState.testCasesToDump.computeIfAbsent(suiteClassId) { mutableListOf() } += function.functionName + testCasesToDump.computeIfAbsent(suiteClassId) { mutableListOf() } += function.functionName } annotationCollector.topLevelFunctions.forEach { function -> @@ -652,6 +656,20 @@ internal class TestProcessor (val context: Context) { annotationCollector.testClasses.values.forEach { testClass -> testClass.functions.forEach { function -> recordFunction(testClass.suiteClassId, function) } } + + if (!testDumpFile.exists) + testDumpFile.createNew() + + if (testCasesToDump.isEmpty()) + return + + testDumpFile.appendLines( + testCasesToDump + .flatMap { (suiteClassId, functionNames) -> + val suiteName = suiteClassId.asString() + functionNames.asSequence().map { "$suiteName:$it" } + } + ) } // endregion