diff --git a/compiler/util-klib-abi/build.gradle.kts b/compiler/util-klib-abi/build.gradle.kts index 809763770e5..d77466e40d4 100644 --- a/compiler/util-klib-abi/build.gradle.kts +++ b/compiler/util-klib-abi/build.gradle.kts @@ -37,3 +37,5 @@ projectTest(jUnitMode = JUnitMode.JUnit5) { } val generateTests by generator("org.jetbrains.kotlin.library.abi.GenerateLibraryAbiReaderTestsKt") + +testsJar() diff --git a/compiler/util-klib-abi/test/org/jetbrains/kotlin/library/abi/AbstractOldLibraryAbiReaderTest.kt b/compiler/util-klib-abi/test/org/jetbrains/kotlin/library/abi/AbstractOldLibraryAbiReaderTest.kt deleted file mode 100644 index bfdac7bb586..00000000000 --- a/compiler/util-klib-abi/test/org/jetbrains/kotlin/library/abi/AbstractOldLibraryAbiReaderTest.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2010-2023 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. - */ - -package org.jetbrains.kotlin.library.abi - -import org.jetbrains.kotlin.library.abi.impl.AbiSignatureVersions -import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEqualsToFile -import org.junit.jupiter.api.BeforeEach -import org.junit.jupiter.api.TestInfo -import java.io.File - -@OptIn(ExperimentalLibraryAbiReader::class) -abstract class AbstractOldLibraryAbiReaderTest { - private lateinit var testName: String - private lateinit var buildDir: File - - @BeforeEach - fun setUp(testInfo: TestInfo) { - testName = getTestName(testInfo) - buildDir = setUpBuildDir(testInfo) - } - - fun runTest(relativePath: String) { - val (sourceFile, dumpFiles) = computeTestFiles(relativePath, AbiSignatureVersions.Supported.entries) - - val (moduleName, filters) = computeModuleNameAndFiltersFromTestDirectives(sourceFile) - - val library = buildLibrary(sourceFile, moduleName, buildDir) - val libraryAbi = LibraryAbiReader.readAbiInfo(library, filters) - - dumpFiles.entries.forEach { (signatureVersion, dumpFile) -> - val abiDump = LibraryAbiRenderer.render( - libraryAbi, - AbiRenderingSettings(signatureVersion) - ) - - assertEqualsToFile(dumpFile, abiDump) - } - } -} diff --git a/compiler/util-klib-abi/test/org/jetbrains/kotlin/library/abi/GenerateLibraryAbiReaderTests.kt b/compiler/util-klib-abi/test/org/jetbrains/kotlin/library/abi/GenerateLibraryAbiReaderTests.kt index 10c1823defe..b86761cecad 100644 --- a/compiler/util-klib-abi/test/org/jetbrains/kotlin/library/abi/GenerateLibraryAbiReaderTests.kt +++ b/compiler/util-klib-abi/test/org/jetbrains/kotlin/library/abi/GenerateLibraryAbiReaderTests.kt @@ -10,14 +10,6 @@ import org.jetbrains.kotlin.generators.generateTestGroupSuiteWithJUnit5 fun main() { System.setProperty("java.awt.headless", "true") - generateTestGroupSuiteWithJUnit5 { - testGroup("compiler/util-klib-abi/tests-gen", "compiler/util-klib-abi/testData") { - testClass(suiteTestClassName = "OldLibraryAbiReaderTest") { - model("content") - } - } - } - generateTestGroupSuiteWithJUnit5 { testGroup("compiler/util-klib-abi/tests-gen", "compiler/util-klib-abi/testData") { testClass { diff --git a/compiler/util-klib-abi/test/org/jetbrains/kotlin/library/abi/utils.kt b/compiler/util-klib-abi/test/org/jetbrains/kotlin/library/abi/utils.kt index 63434f6379c..e8dae92ef59 100644 --- a/compiler/util-klib-abi/test/org/jetbrains/kotlin/library/abi/utils.kt +++ b/compiler/util-klib-abi/test/org/jetbrains/kotlin/library/abi/utils.kt @@ -30,11 +30,7 @@ import org.jetbrains.kotlin.konan.properties.saveToFile import org.jetbrains.kotlin.library.* import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.serialization.js.ModuleKind -import org.jetbrains.kotlin.test.util.KtTestUtil.getHomeDirectory import org.jetbrains.kotlin.test.utils.TestDisposable -import org.jetbrains.kotlin.util.parseSpaceSeparatedArgs -import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty -import org.jetbrains.kotlin.utils.fileUtils.withReplacedExtensionOrNull import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.TestInfo import java.io.ByteArrayOutputStream @@ -46,8 +42,6 @@ import org.jetbrains.kotlin.konan.file.File as KFile private val TestInfo.className: String get() = testClass.orElseGet { fail("Can't get test class name") }.simpleName private val TestInfo.methodName: String get() = testMethod.orElseGet { fail("Can't get test method name") }.name -internal fun getTestName(testInfo: TestInfo): String = testInfo.methodName - internal fun setUpBuildDir(testInfo: TestInfo): File { val projectBuildDir = System.getenv(ENV_VAR_PROJECT_BUILD_DIR) ?.let { File(it) } @@ -61,80 +55,6 @@ internal fun setUpBuildDir(testInfo: TestInfo): File { } } -@OptIn(ExperimentalLibraryAbiReader::class) -internal fun computeTestFiles( - relativePath: String, - signatureVersions: List -): Pair> { - assertTrue(signatureVersions.isNotEmpty()) { "Signature versions not specified" } - - val sourceFile = File(getHomeDirectory()).resolve(relativePath) - assertEquals("kt", sourceFile.extension) { "Invalid source file: $sourceFile" } - assertTrue(sourceFile.isFile) { "Source file does not exist: $sourceFile" } - - return sourceFile to signatureVersions.associateWith { signatureVersion -> - val dumpFile = sourceFile.withReplacedExtensionOrNull("kt", "v${signatureVersion.versionNumber}.txt")!! - assertTrue(dumpFile.isFile) { "Dump file does not exist: $dumpFile" } - dumpFile - } -} - -@OptIn(ExperimentalLibraryAbiReader::class) -internal fun computeModuleNameAndFiltersFromTestDirectives(sourceFile: File): Pair> { - fun String.parseQualifiedName() = AbiQualifiedName( - packageName = AbiCompoundName(substringBefore('/', missingDelimiterValue = "")), - relativeName = AbiCompoundName(substringAfter('/')) - ) - - var moduleName: String? = null - val excludedPackages = mutableListOf() - val excludedClasses = mutableListOf() - val nonPublicMarkers = mutableListOf() - - for (line in sourceFile.bufferedReader().lineSequence()) { - if (!line.parseTestDirective(DIRECTIVE_EXCLUDED_PACKAGES, ::AbiCompoundName, excludedPackages::add) - && !line.parseTestDirective(DIRECTIVE_EXCLUDED_CLASSES, String::parseQualifiedName, excludedClasses::add) - && !line.parseTestDirective(DIRECTIVE_NON_PUBLIC_MARKERS, String::parseQualifiedName, nonPublicMarkers::add) - && !line.parseTestDirective(DIRECTIVE_MODULE, { it }, { moduleName = it }) - && !line.startsWith("//") - && line.isNotBlank() - ) { - break - } - } - - assert(moduleName != null) { "No module name specified with MODULE test directive" } - - return moduleName!! to listOfNotNull( - excludedPackages.ifNotEmpty(AbiReadingFilter::ExcludedPackages), - excludedClasses.ifNotEmpty(AbiReadingFilter::ExcludedClasses), - nonPublicMarkers.ifNotEmpty(AbiReadingFilter::NonPublicMarkerAnnotations) - ) -} - -private inline fun String.parseTestDirective( - directivePrefix: String, - parser: (String) -> T, - consumer: (T) -> Unit, -): Boolean { - if (!startsWith(directivePrefix)) - return false - - val remainder = substring(directivePrefix.length) - try { - val items = parseSpaceSeparatedArgs(remainder) - items.forEach { item -> consumer(parser(item)) } - return true - } catch (e: Exception) { - throw fail("Failure during parsing test directive: $this", e) - } -} - -private const val DIRECTIVE_MODULE = "// MODULE:" -private const val DIRECTIVE_EXCLUDED_PACKAGES = "// EXCLUDED_PACKAGES:" -private const val DIRECTIVE_EXCLUDED_CLASSES = "// EXCLUDED_CLASSES:" -private const val DIRECTIVE_NON_PUBLIC_MARKERS = "// NON_PUBLIC_MARKERS:" - internal fun buildLibrary(sourceFile: File, libraryName: String, buildDir: File): File { val configuration = CompilerConfiguration() val environment = createForParallelTests(TestDisposable(), configuration, EnvironmentConfigFiles.JS_CONFIG_FILES) diff --git a/native/native.tests/build.gradle.kts b/native/native.tests/build.gradle.kts index 0223a021fb5..60850074cd5 100644 --- a/native/native.tests/build.gradle.kts +++ b/native/native.tests/build.gradle.kts @@ -18,6 +18,8 @@ dependencies { testImplementation(projectTests(":generators:test-generator")) testImplementation(project(":native:kotlin-native-utils")) testImplementation(project(":native:executors")) + testImplementation(project(":kotlin-util-klib-abi")) + testImplementation(projectTests(":kotlin-util-klib-abi")) testApiJUnit5() testImplementation(commonDependency("org.jetbrains.kotlinx", "kotlinx-metadata-klib")) testImplementation(commonDependency("org.jetbrains.kotlinx", "kotlinx-coroutines-core")) { isTransitive = false } diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeLibraryAbiReaderTest.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeLibraryAbiReaderTest.java new file mode 100644 index 00000000000..9e54718e26b --- /dev/null +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/FirNativeLibraryAbiReaderTest.java @@ -0,0 +1,169 @@ +/* + * Copyright 2010-2023 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. + */ + +package org.jetbrains.kotlin.konan.blackboxtest; + +import com.intellij.testFramework.TestDataPath; +import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.junit.jupiter.api.Tag; +import org.jetbrains.kotlin.konan.blackboxtest.support.group.FirPipeline; +import org.jetbrains.kotlin.test.TargetBackend; +import org.jetbrains.kotlin.test.TestMetadata; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; + +import java.io.File; +import java.util.regex.Pattern; + +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("compiler/util-klib-abi/testData/content") +@TestDataPath("$PROJECT_ROOT") +@Tag("frontend-fir") +@FirPipeline() +public class FirNativeLibraryAbiReaderTest extends AbstractNativeLibraryAbiReaderTest { + @Test + public void testAllFilesPresentInContent() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/util-klib-abi/testData/content"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); + } + + @Test + @TestMetadata("callables.kt") + public void testCallables() throws Exception { + runTest("compiler/util-klib-abi/testData/content/callables.kt"); + } + + @Test + @TestMetadata("classifiers.kt") + public void testClassifiers() throws Exception { + runTest("compiler/util-klib-abi/testData/content/classifiers.kt"); + } + + @Test + @TestMetadata("excluded_classes_1.kt") + public void testExcluded_classes_1() throws Exception { + runTest("compiler/util-klib-abi/testData/content/excluded_classes_1.kt"); + } + + @Test + @TestMetadata("excluded_classes_2.kt") + public void testExcluded_classes_2() throws Exception { + runTest("compiler/util-klib-abi/testData/content/excluded_classes_2.kt"); + } + + @Test + @TestMetadata("excluded_classes_3.kt") + public void testExcluded_classes_3() throws Exception { + runTest("compiler/util-klib-abi/testData/content/excluded_classes_3.kt"); + } + + @Test + @TestMetadata("excluded_packages_non_root_1.kt") + public void testExcluded_packages_non_root_1() throws Exception { + runTest("compiler/util-klib-abi/testData/content/excluded_packages_non_root_1.kt"); + } + + @Test + @TestMetadata("excluded_packages_non_root_2.kt") + public void testExcluded_packages_non_root_2() throws Exception { + runTest("compiler/util-klib-abi/testData/content/excluded_packages_non_root_2.kt"); + } + + @Test + @TestMetadata("excluded_packages_non_root_3.kt") + public void testExcluded_packages_non_root_3() throws Exception { + runTest("compiler/util-klib-abi/testData/content/excluded_packages_non_root_3.kt"); + } + + @Test + @TestMetadata("excluded_packages_non_root_4.kt") + public void testExcluded_packages_non_root_4() throws Exception { + runTest("compiler/util-klib-abi/testData/content/excluded_packages_non_root_4.kt"); + } + + @Test + @TestMetadata("excluded_packages_root_1.kt") + public void testExcluded_packages_root_1() throws Exception { + runTest("compiler/util-klib-abi/testData/content/excluded_packages_root_1.kt"); + } + + @Test + @TestMetadata("excluded_packages_root_2.kt") + public void testExcluded_packages_root_2() throws Exception { + runTest("compiler/util-klib-abi/testData/content/excluded_packages_root_2.kt"); + } + + @Test + @TestMetadata("inheritance.kt") + public void testInheritance() throws Exception { + runTest("compiler/util-klib-abi/testData/content/inheritance.kt"); + } + + @Test + @TestMetadata("root_package.kt") + public void testRoot_package() throws Exception { + runTest("compiler/util-klib-abi/testData/content/root_package.kt"); + } + + @Test + @TestMetadata("specific_types_dnn.kt") + public void testSpecific_types_dnn() throws Exception { + runTest("compiler/util-klib-abi/testData/content/specific_types_dnn.kt"); + } + + @Test + @TestMetadata("type_parameters.kt") + public void testType_parameters() throws Exception { + runTest("compiler/util-klib-abi/testData/content/type_parameters.kt"); + } + + @Test + @TestMetadata("value_parameters.kt") + public void testValue_parameters() throws Exception { + runTest("compiler/util-klib-abi/testData/content/value_parameters.kt"); + } + + @Test + @TestMetadata("visibilities.kt") + public void testVisibilities() throws Exception { + runTest("compiler/util-klib-abi/testData/content/visibilities.kt"); + } + + @Test + @TestMetadata("with_non_public_markers_1.kt") + public void testWith_non_public_markers_1() throws Exception { + runTest("compiler/util-klib-abi/testData/content/with_non_public_markers_1.kt"); + } + + @Test + @TestMetadata("with_non_public_markers_2.kt") + public void testWith_non_public_markers_2() throws Exception { + runTest("compiler/util-klib-abi/testData/content/with_non_public_markers_2.kt"); + } + + @Test + @TestMetadata("with_non_public_markers_3.kt") + public void testWith_non_public_markers_3() throws Exception { + runTest("compiler/util-klib-abi/testData/content/with_non_public_markers_3.kt"); + } + + @Test + @TestMetadata("with_non_public_markers_4.kt") + public void testWith_non_public_markers_4() throws Exception { + runTest("compiler/util-klib-abi/testData/content/with_non_public_markers_4.kt"); + } + + @Test + @TestMetadata("with_non_public_markers_5.kt") + public void testWith_non_public_markers_5() throws Exception { + runTest("compiler/util-klib-abi/testData/content/with_non_public_markers_5.kt"); + } + + @Test + @TestMetadata("with_non_public_markers_private_annotations.kt") + public void testWith_non_public_markers_private_annotations() throws Exception { + runTest("compiler/util-klib-abi/testData/content/with_non_public_markers_private_annotations.kt"); + } +} diff --git a/compiler/util-klib-abi/tests-gen/org/jetbrains/kotlin/library/abi/OldLibraryAbiReaderTest.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeLibraryAbiReaderTest.java similarity index 90% rename from compiler/util-klib-abi/tests-gen/org/jetbrains/kotlin/library/abi/OldLibraryAbiReaderTest.java rename to native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeLibraryAbiReaderTest.java index 0ea7defca4f..467a88b86ae 100644 --- a/compiler/util-klib-abi/tests-gen/org/jetbrains/kotlin/library/abi/OldLibraryAbiReaderTest.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeLibraryAbiReaderTest.java @@ -3,10 +3,11 @@ * 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.library.abi; +package org.jetbrains.kotlin.konan.blackboxtest; import com.intellij.testFramework.TestDataPath; import org.jetbrains.kotlin.test.util.KtTestUtil; +import org.jetbrains.kotlin.test.TargetBackend; import org.jetbrains.kotlin.test.TestMetadata; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -14,14 +15,14 @@ import org.junit.jupiter.api.Test; import java.io.File; import java.util.regex.Pattern; -/** This class is generated by {@link org.jetbrains.kotlin.library.abi.GenerateLibraryAbiReaderTestsKt}. DO NOT MODIFY MANUALLY */ +/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateNativeTestsKt}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("compiler/util-klib-abi/testData/content") @TestDataPath("$PROJECT_ROOT") -public class OldLibraryAbiReaderTest extends AbstractOldLibraryAbiReaderTest { +public class NativeLibraryAbiReaderTest extends AbstractNativeLibraryAbiReaderTest { @Test public void testAllFilesPresentInContent() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/util-klib-abi/testData/content"), Pattern.compile("^(.+)\\.kt$"), null, true); + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/util-klib-abi/testData/content"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); } @Test @@ -102,6 +103,12 @@ public class OldLibraryAbiReaderTest extends AbstractOldLibraryAbiReaderTest { runTest("compiler/util-klib-abi/testData/content/root_package.kt"); } + @Test + @TestMetadata("specific_types_dnn.kt") + public void testSpecific_types_dnn() throws Exception { + runTest("compiler/util-klib-abi/testData/content/specific_types_dnn.kt"); + } + @Test @TestMetadata("type_parameters.kt") public void testType_parameters() throws Exception { diff --git a/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt b/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt index 89dd85173e6..01380dfbffb 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/generators/tests/GenerateNativeTests.kt @@ -266,6 +266,27 @@ fun main() { model("diagnostics/nativeTests", excludedPattern = CUSTOM_TEST_DATA_EXTENSION_PATTERN) } } + + generateTestGroupSuiteWithJUnit5 { + testGroup("native/native.tests/tests-gen", "compiler/util-klib-abi/testData") { + testClass( + suiteTestClassName = "NativeLibraryAbiReaderTest" + ) { + model("content", targetBackend = TargetBackend.NATIVE) + } + } + + testGroup("native/native.tests/tests-gen", "compiler/util-klib-abi/testData") { + testClass( + suiteTestClassName = "FirNativeLibraryAbiReaderTest", + annotations = listOf( + *frontendFir() + ) + ) { + model("content", targetBackend = TargetBackend.NATIVE) + } + } + } } } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeLibraryAbiReaderTest.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeLibraryAbiReaderTest.kt new file mode 100644 index 00000000000..4ebed9ad52e --- /dev/null +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/AbstractNativeLibraryAbiReaderTest.kt @@ -0,0 +1,100 @@ +/* + * Copyright 2010-2023 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. + */ + +package org.jetbrains.kotlin.konan.blackboxtest + +import org.jetbrains.kotlin.konan.blackboxtest.support.Location +import org.jetbrains.kotlin.konan.blackboxtest.support.TestCompilerArgs +import org.jetbrains.kotlin.konan.blackboxtest.support.TestDirectives +import org.jetbrains.kotlin.konan.blackboxtest.support.TestDirectives.MODULE +import org.jetbrains.kotlin.konan.blackboxtest.support.parseModule +import org.jetbrains.kotlin.konan.blackboxtest.support.util.getAbsoluteFile +import org.jetbrains.kotlin.library.abi.* +import org.jetbrains.kotlin.library.abi.directives.LibraryAbiDumpDirectives +import org.jetbrains.kotlin.library.abi.directives.LibraryAbiDumpDirectives.EXCLUDED_CLASSES +import org.jetbrains.kotlin.library.abi.directives.LibraryAbiDumpDirectives.EXCLUDED_PACKAGES +import org.jetbrains.kotlin.library.abi.directives.LibraryAbiDumpDirectives.NON_PUBLIC_MARKERS +import org.jetbrains.kotlin.test.directives.model.ComposedDirectivesContainer +import org.jetbrains.kotlin.test.services.JUnit5Assertions +import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEqualsToFile +import org.jetbrains.kotlin.test.services.impl.RegisteredDirectivesParser +import org.jetbrains.kotlin.test.services.impl.RegisteredDirectivesParser.ParsedDirective +import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty +import org.jetbrains.kotlin.utils.fileUtils.withReplacedExtensionOrNull +import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Tag +import java.io.File + +@Tag("klib") +@OptIn(ExperimentalLibraryAbiReader::class) +abstract class AbstractNativeLibraryAbiReaderTest : AbstractNativeSimpleTest() { + fun runTest(localPath: String) { + val (sourceFile, dumpFiles) = computeTestFiles(localPath) + val (moduleName, filters) = parseDirectives(sourceFile) + + val library = compileToLibrary( + testCase = generateTestCaseWithSingleFile( + sourceFile = sourceFile, + moduleName = moduleName, + freeCompilerArgs = TestCompilerArgs("-Xcontext-receivers") + ) + ).resultingArtifact.klibFile + + val libraryAbi = LibraryAbiReader.readAbiInfo(library, filters) + + dumpFiles.entries.forEach { (signatureVersion, dumpFile) -> + val abiDump = LibraryAbiRenderer.render( + libraryAbi, + AbiRenderingSettings(signatureVersion) + ) + + assertEqualsToFile(dumpFile, abiDump) + } + } + + companion object { + private fun computeTestFiles(localPath: String): Pair> { + val sourceFile = getAbsoluteFile(localPath) + assertEquals("kt", sourceFile.extension) { "Invalid source file: $sourceFile" } + assertTrue(sourceFile.isFile) { "Source file does not exist: $sourceFile" } + + return sourceFile to AbiSignatureVersion.allSupportedByAbiReader.associateWith { signatureVersion -> + val dumpFile = sourceFile.withReplacedExtensionOrNull("kt", "v${signatureVersion.versionNumber}.txt")!! + assertTrue(dumpFile.isFile) { "Dump file does not exist: $dumpFile" } + dumpFile + } + } + + internal data class FromDirectives(val moduleName: String, val filters: List) + + internal fun parseDirectives(sourceFile: File): FromDirectives { + val directivesParser = RegisteredDirectivesParser( + ComposedDirectivesContainer(LibraryAbiDumpDirectives, TestDirectives), + JUnit5Assertions + ) + sourceFile.forEachLine(action = directivesParser::parse) + + val registeredDirectives = directivesParser.build() + + val moduleName = parseModule( + ParsedDirective(MODULE, registeredDirectives[MODULE]), + Location(sourceFile) + ).name + + val excludedPackages = registeredDirectives[EXCLUDED_PACKAGES] + val excludedClasses = registeredDirectives[EXCLUDED_CLASSES] + val nonPublicMarkers = registeredDirectives[NON_PUBLIC_MARKERS] + + return FromDirectives( + moduleName = moduleName, + filters = listOfNotNull( + excludedPackages.ifNotEmpty(AbiReadingFilter::ExcludedPackages), + excludedClasses.ifNotEmpty(AbiReadingFilter::ExcludedClasses), + nonPublicMarkers.ifNotEmpty(AbiReadingFilter::NonPublicMarkerAnnotations) + ) + ) + } + } +} diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/NativeSimpleTestUtils.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/NativeSimpleTestUtils.kt index 857250ddd69..dfb91e73cc7 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/NativeSimpleTestUtils.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/NativeSimpleTestUtils.kt @@ -221,11 +221,11 @@ internal fun AbstractNativeSimpleTest.generateTestCaseWithSingleModule( internal fun AbstractNativeSimpleTest.generateTestCaseWithSingleFile( sourceFile: File, + moduleName: String = sourceFile.name, freeCompilerArgs: TestCompilerArgs = TestCompilerArgs.EMPTY, testKind: TestKind = TestKind.STANDALONE, extras: TestCase.Extras = TestCase.WithTestRunnerExtras(TestRunnerType.DEFAULT) ): TestCase { - val moduleName: String = sourceFile.name ?: LAUNCHER_MODULE_NAME val module = TestModule.Exclusive(moduleName, emptySet(), emptySet(), emptySet()) module.files += TestFile.createCommitted(sourceFile, module)