[Analysis API] Support multi-module projects in compiler facility tests
This commit is contained in:
+23
-3
@@ -69,9 +69,7 @@ abstract class AbstractCompilerFacilityTest : AbstractAnalysisApiBasedTest() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun doTestByModuleStructure(moduleStructure: TestModuleStructure, testServices: TestServices) {
|
override fun doTestByModuleStructure(moduleStructure: TestModuleStructure, testServices: TestServices) {
|
||||||
val mainModule = moduleStructure.modules.first { it.name == "main" }
|
val (mainModule, ktFile) = findTargetFile(moduleStructure, testServices)
|
||||||
val ktFiles = testServices.ktModuleProvider.getModuleFiles(mainModule).filterIsInstance<KtFile>()
|
|
||||||
val ktFile = ktFiles.singleOrNull() ?: ktFiles.first { it.name == "main.kt" }
|
|
||||||
|
|
||||||
val irCollector = CollectingIrGenerationExtension()
|
val irCollector = CollectingIrGenerationExtension()
|
||||||
|
|
||||||
@@ -119,6 +117,28 @@ abstract class AbstractCompilerFacilityTest : AbstractAnalysisApiBasedTest() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun findTargetFile(moduleStructure: TestModuleStructure, testServices: TestServices): Pair<TestModule, KtFile> {
|
||||||
|
if (moduleStructure.modules.size == 1) {
|
||||||
|
val testModule = moduleStructure.modules.single()
|
||||||
|
val psiFiles = testServices.ktModuleProvider.getModuleFiles(testModule)
|
||||||
|
val ktFiles = psiFiles.filterIsInstance<KtFile>()
|
||||||
|
if (ktFiles.size == 1) {
|
||||||
|
// In simpler whole-file compilation tests, do not require the '<caret>'
|
||||||
|
return testModule to ktFiles.single()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (testModule in moduleStructure.modules) {
|
||||||
|
for (psiFile in testServices.ktModuleProvider.getModuleFiles(testModule)) {
|
||||||
|
if (psiFile is KtFile && testServices.expressionMarkerProvider.getCaretPositionOrNull(psiFile) != null) {
|
||||||
|
return testModule to psiFile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
error("Cannot find the main test file")
|
||||||
|
}
|
||||||
|
|
||||||
override fun configureTest(builder: TestConfigurationBuilder) {
|
override fun configureTest(builder: TestConfigurationBuilder) {
|
||||||
super.configureTest(builder)
|
super.configureTest(builder)
|
||||||
with(builder) {
|
with(builder) {
|
||||||
|
|||||||
+1
-1
@@ -13,6 +13,6 @@ import lib.Foo
|
|||||||
object Main {
|
object Main {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
Foo().foo()
|
<caret>Foo().foo()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+1
-1
@@ -13,5 +13,5 @@ fun lib(): String = "foo"
|
|||||||
import lib.lib
|
import lib.lib
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
lib()
|
<caret>lib()
|
||||||
}
|
}
|
||||||
+1
-1
@@ -13,5 +13,5 @@ fun lib(a: Int = 5): String {
|
|||||||
import lib.lib
|
import lib.lib
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
lib()
|
<caret>lib()
|
||||||
}
|
}
|
||||||
Vendored
+1
-1
@@ -11,5 +11,5 @@ internal fun lib(): String = "foo"
|
|||||||
import lib.lib
|
import lib.lib
|
||||||
|
|
||||||
fun test() {
|
fun test() {
|
||||||
lib()
|
<caret>lib()
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user