From 38723816b7d32bfeb9182733dee2f70fd8bb01fa Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Thu, 9 Jun 2022 14:23:36 +0300 Subject: [PATCH] [Native][tests] Fix file annotation patching in test files Previously, the test engine was copying @file:OptIn annotations from each file to all the other files inside the same test data, and also was removing other file annotations in certain cases. Now it only adds the opt-ins specified with `!OPT_IN` directives, and doesn't remove anything. --- .../support/group/ExtTestCaseGroupProvider.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/group/ExtTestCaseGroupProvider.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/group/ExtTestCaseGroupProvider.kt index c82c04e747e..b0693322d55 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/group/ExtTestCaseGroupProvider.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/group/ExtTestCaseGroupProvider.kt @@ -464,19 +464,23 @@ private class ExtTestDataFile( val allFileLevelAnnotationsSorted = allFileLevelAnnotations.sorted() // Finally, make sure that every test file contains all the necessary file-level annotations. - if (allFileLevelAnnotationsSorted.isNotEmpty()) { + if (testDataFileSettings.optInsForSourceCode.isNotEmpty()) { filesToTransform.forEach { handler -> handler.accept(object : KtTreeVisitorVoid() { override fun visitKtFile(file: KtFile) { val oldFileAnnotationList = file.fileAnnotationList val newFileAnnotationList = handler.psiFactory.createFile(buildString { - allFileLevelAnnotationsSorted.forEach(::appendLine) + testDataFileSettings.optInsForSourceCode.forEach { + appendLine(getAnnotationText(it)) + } }).fileAnnotationList!! if (oldFileAnnotationList != null) { - // Replace old annotations list by the new one. - oldFileAnnotationList.replace(newFileAnnotationList).ensureSurroundedByWhiteSpace() + // Add new annotations to the old ones. + newFileAnnotationList.annotationEntries.forEach { + oldFileAnnotationList.add(it).ensureSurroundedByWhiteSpace() + } } else { // Insert the annotations list immediately before package directive. file.addBefore(newFileAnnotationList, file.packageDirective).ensureSurroundedByWhiteSpace()