[Test] Introduce two module structure transformers for codegen test

This commit is contained in:
Dmitriy Novozhilov
2021-01-25 18:21:42 +03:00
parent 13a778fd9c
commit 60e0831c11
2 changed files with 94 additions and 0 deletions
@@ -0,0 +1,37 @@
/*
* Copyright 2010-2021 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.test.services
import org.jetbrains.kotlin.test.TargetBackend
import org.jetbrains.kotlin.test.TestInfrastructureInternals
import org.jetbrains.kotlin.test.model.DependencyDescription
import org.jetbrains.kotlin.test.model.DependencyKind
import org.jetbrains.kotlin.test.model.DependencyRelation
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.impl.TestModuleStructureImpl
/**
* This transformers is used for transforming target backend
* in tests with exactly two modules in it
*/
@TestInfrastructureInternals
class ModuleTransformerForSwitchingBackend(
val backendForLib: TargetBackend,
val backendForMain: TargetBackend
) : ModuleStructureTransformer() {
override fun transformModuleStructure(moduleStructure: TestModuleStructure): TestModuleStructure {
if (moduleStructure.modules.size != 2) error("Test should contain only one module")
val (first, second) = moduleStructure.modules
return TestModuleStructureImpl(
listOf(
first.copy(targetBackend = backendForLib),
second.copy(targetBackend = backendForMain)
),
moduleStructure.originalTestDataFiles
)
}
}
@@ -0,0 +1,57 @@
/*
* Copyright 2010-2021 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.test.services
import org.jetbrains.kotlin.test.TestInfrastructureInternals
import org.jetbrains.kotlin.test.model.DependencyDescription
import org.jetbrains.kotlin.test.model.DependencyKind
import org.jetbrains.kotlin.test.model.DependencyRelation
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.impl.TestModuleStructureImpl
/**
* This transformers is used for transforming test with two files
* into test with two modules
*
* It will fail in case when module structure contains more than one module
* or not exactly two files in it
*/
@TestInfrastructureInternals
class ModuleTransformerForTwoFilesBoxTests : ModuleStructureTransformer() {
override fun transformModuleStructure(moduleStructure: TestModuleStructure): TestModuleStructure {
val module = moduleStructure.modules.singleOrNull() ?: error("Test should contain only one module")
val realFiles = module.files.filterNot { it.isAdditional }
if (realFiles.size != 2) error("Test should contain exactly two files")
val additionalFiles = module.files.filter { it.isAdditional }
val (first, second) = realFiles
val firstModule = TestModule(
name = "lib",
module.targetPlatform,
module.targetBackend,
module.frontendKind,
module.binaryKind,
files = listOf(first) + additionalFiles,
dependencies = emptyList(),
friends = emptyList(),
module.directives,
module.languageVersionSettings
)
val secondModule = TestModule(
name = "main",
module.targetPlatform,
module.targetBackend,
module.frontendKind,
module.binaryKind,
files = listOf(second) + additionalFiles,
dependencies = listOf(DependencyDescription("lib", DependencyKind.Binary, DependencyRelation.Dependency)),
friends = emptyList(),
module.directives,
module.languageVersionSettings
)
return TestModuleStructureImpl(listOf(firstModule, secondModule), moduleStructure.originalTestDataFiles)
}
}