[Native][tests] Fix: Avoid including similar but mutually exclusive shared modules into the same compilation

This commit is contained in:
Dmitriy Dolovov
2022-03-30 20:56:18 +03:00
committed by Space
parent 862b8cd9e5
commit 7cf3ca29af
2 changed files with 38 additions and 10 deletions
@@ -105,7 +105,7 @@ internal sealed class TestModule {
other.directDependencySymbols == directDependencySymbols && other.directFriendSymbols == directFriendSymbols
}
class Shared(override val name: String) : TestModule() {
data class Shared(override val name: String) : TestModule() {
override val files: FailOnDuplicatesSet<TestFile<Shared>> = FailOnDuplicatesSet()
}
@@ -210,6 +210,17 @@ internal class TestCase(
rootModules as Set<TestModule.Exclusive>
}
// All shared modules used in the current test case.
val sharedModules: Set<TestModule.Shared> by lazy {
buildSet {
modules.forEach { module ->
module.allDependencies.forEach { dependency ->
if (dependency is TestModule.Shared) this += dependency
}
}
}
}
fun initialize(findSharedModule: ((moduleName: String) -> TestModule.Shared?)?) {
// Check that there are no duplicated files among different modules.
val duplicatedFiles = modules.flatMap { it.files }.groupingBy { it }.eachCount().filterValues { it > 1 }.keys
@@ -253,7 +264,12 @@ internal interface TestCaseGroupId {
internal interface TestCaseGroup {
fun isEnabled(testCaseId: TestCaseId): Boolean
fun getByName(testCaseId: TestCaseId): TestCase?
fun getRegularOnly(freeCompilerArgs: TestCompilerArgs, runnerType: TestRunnerType): Collection<TestCase>
fun getRegularOnly(
freeCompilerArgs: TestCompilerArgs,
sharedModules: Set<TestModule.Shared>,
runnerType: TestRunnerType
): Collection<TestCase>
class Default(
private val disabledTestCaseIds: Set<TestCaseId>,
@@ -264,19 +280,29 @@ internal interface TestCaseGroup {
override fun isEnabled(testCaseId: TestCaseId) = testCaseId !in disabledTestCaseIds
override fun getByName(testCaseId: TestCaseId) = testCasesById[testCaseId]
override fun getRegularOnly(freeCompilerArgs: TestCompilerArgs, runnerType: TestRunnerType) =
testCasesById.values.filter { testCase ->
testCase.kind == TestKind.REGULAR
&& testCase.extras<WithTestRunnerExtras>().runnerType == runnerType
&& testCase.freeCompilerArgs == freeCompilerArgs
}
override fun getRegularOnly(
freeCompilerArgs: TestCompilerArgs,
sharedModules: Set<TestModule.Shared>,
runnerType: TestRunnerType
) = testCasesById.values.filter { testCase ->
testCase.kind == TestKind.REGULAR
&& testCase.freeCompilerArgs == freeCompilerArgs
&& testCase.sharedModules == sharedModules
&& testCase.extras<WithTestRunnerExtras>().runnerType == runnerType
}
}
companion object {
val ALL_DISABLED = object : TestCaseGroup {
override fun isEnabled(testCaseId: TestCaseId) = false
override fun getByName(testCaseId: TestCaseId) = unsupported()
override fun getRegularOnly(freeCompilerArgs: TestCompilerArgs, runnerType: TestRunnerType) = unsupported()
override fun getRegularOnly(
freeCompilerArgs: TestCompilerArgs,
sharedModules: Set<TestModule.Shared>,
runnerType: TestRunnerType
) = unsupported()
private fun unsupported(): Nothing = fail { "This function should not be called" }
}
}
@@ -145,10 +145,11 @@ internal class TestRunProvider(
TestCompilationCacheKey.Grouped(
testCaseGroupId = testCaseId.testCaseGroupId,
freeCompilerArgs = testCase.freeCompilerArgs,
sharedModules = testCase.sharedModules,
runnerType = testRunnerType
)
) {
val testCases = testCaseGroup.getRegularOnly(testCase.freeCompilerArgs, testRunnerType)
val testCases = testCaseGroup.getRegularOnly(testCase.freeCompilerArgs, testCase.sharedModules, testRunnerType)
assertTrue(testCases.isNotEmpty())
compilationFactory.testCasesToExecutable(testCases, settings)
}
@@ -180,6 +181,7 @@ internal class TestRunProvider(
data class Grouped(
val testCaseGroupId: TestCaseGroupId,
val freeCompilerArgs: TestCompilerArgs,
val sharedModules: Set<TestModule.Shared>,
val runnerType: TestRunnerType
) : TestCompilationCacheKey()
}