[TEST] Change semantics of CHECK_TYPE directive and update testdata
Previously helpers from checkType.kt was in special package, and
if directive was enabled then test runner (`AbstractDiagnosticTest`)
injected additional imports to test files and removed them after test
was completed.
It's very hard to support such behavior in new test infrastructure so
there was a decision about changing `CHECK_TYPE`:
1. All helpers from `checkType.kt` now stays in default package
2. `CHECK_TYPE` only adds `checkType.kt` to set of analyzed files
and don't modify their content
For test which are written in default package (most of tests actually)
there are no changes. On the other hand if there is a test where dev
want to use checkType functions in testfile with some package then he
should explicitly import functions which he needed (`checkSubtype`,
`checkType`, `_`)
This commit is contained in:
@@ -625,6 +625,7 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
getTopLevelPackagesFromFileList(getKtFiles(testFiles, false))
|
||||
).toSet()
|
||||
|
||||
val checkTypeEnabled = testFiles.any { it.declareCheckType }
|
||||
val stepIntoFilter = Predicate<DeclarationDescriptor> { descriptor ->
|
||||
val module = DescriptorUtils.getContainingModuleOrNull(descriptor)
|
||||
if (module !in modules) return@Predicate false
|
||||
@@ -634,6 +635,8 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
return@Predicate fqName.isRoot || fqName.pathSegments().first() in packagesNames
|
||||
}
|
||||
|
||||
if (checkTypeEnabled && descriptor.name in NAMES_OF_CHECK_TYPE_HELPER) return@Predicate false
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
@@ -768,5 +771,7 @@ abstract class AbstractDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
private val HASH_SANITIZER = fun(s: String): String = s.replace("@(\\d)+".toRegex(), "")
|
||||
|
||||
private val MODULE_FILES = ModuleCapability<List<KtFile>>("")
|
||||
|
||||
private val NAMES_OF_CHECK_TYPE_HELPER = listOf("checkSubtype", "CheckTypeInv", "_", "checkType").map { Name.identifier(it) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,9 +190,6 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
||||
private val imports: String
|
||||
get() = buildString {
|
||||
// Line separator is "\n" intentionally here (see DocumentImpl.assertValidSeparators)
|
||||
if (declareCheckType) {
|
||||
append(CHECK_TYPE_IMPORT + "\n")
|
||||
}
|
||||
if (declareFlexibleType) {
|
||||
append(EXPLICIT_FLEXIBLE_TYPES_IMPORT + "\n")
|
||||
}
|
||||
@@ -403,8 +400,6 @@ abstract class BaseDiagnosticsTest : KotlinMultiFileTestWithJava<TestModule, Tes
|
||||
)
|
||||
|
||||
val CHECK_TYPE_DIRECTIVE = "CHECK_TYPE"
|
||||
val CHECK_TYPE_PACKAGE = "tests._checkType"
|
||||
val CHECK_TYPE_IMPORT = "import $CHECK_TYPE_PACKAGE.*"
|
||||
|
||||
val EXPLICIT_FLEXIBLE_TYPES_DIRECTIVE = "EXPLICIT_FLEXIBLE_TYPES"
|
||||
val EXPLICIT_FLEXIBLE_PACKAGE = InternalFlexibleTypeTransformer.FLEXIBLE_TYPE_CLASSIFIER.packageFqName.asString()
|
||||
|
||||
Reference in New Issue
Block a user