[Testing] Add more flexiblity to AbstractMultiModuleTest
- Preserve root names - Provide an ability to transform copied file - Allow passing several implemented modules in AbstractMultiModuleTest
This commit is contained in:
@@ -71,9 +71,18 @@ abstract class AbstractMultiModuleTest : DaemonAnalyzerTestCase() {
|
|||||||
return super.createModule(path, moduleType)
|
return super.createModule(path, moduleType)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addRoot(module: Module, sourceDirInTestData: File, isTestRoot: Boolean) {
|
fun addRoot(module: Module, sourceDirInTestData: File, isTestRoot: Boolean, transformContainedFiles: ((File) -> Unit)? = null) {
|
||||||
val tmpRootDir = createTempDirectory()
|
val tmpDir = createTempDirectory()
|
||||||
|
|
||||||
|
// Preserve original root name. This might be useful for later matching of copied files to original ones
|
||||||
|
val tmpRootDir = File(tmpDir, sourceDirInTestData.name).also { it.mkdir() }
|
||||||
|
|
||||||
FileUtil.copyDir(sourceDirInTestData, tmpRootDir)
|
FileUtil.copyDir(sourceDirInTestData, tmpRootDir)
|
||||||
|
|
||||||
|
if (transformContainedFiles != null) {
|
||||||
|
tmpRootDir.listFiles().forEach(transformContainedFiles)
|
||||||
|
}
|
||||||
|
|
||||||
val virtualTempDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tmpRootDir)!!
|
val virtualTempDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tmpRootDir)!!
|
||||||
object : WriteCommandAction.Simple<Unit>(project) {
|
object : WriteCommandAction.Simple<Unit>(project) {
|
||||||
override fun run() {
|
override fun run() {
|
||||||
@@ -133,7 +142,7 @@ abstract class AbstractMultiModuleTest : DaemonAnalyzerTestCase() {
|
|||||||
fun Module.createFacet(
|
fun Module.createFacet(
|
||||||
platformKind: TargetPlatform? = null,
|
platformKind: TargetPlatform? = null,
|
||||||
useProjectSettings: Boolean = true,
|
useProjectSettings: Boolean = true,
|
||||||
implementedModuleName: String? = null
|
implementedModuleNames: List<String>? = null
|
||||||
) {
|
) {
|
||||||
WriteAction.run<Throwable> {
|
WriteAction.run<Throwable> {
|
||||||
val modelsProvider = IdeModifiableModelsProviderImpl(project)
|
val modelsProvider = IdeModifiableModelsProviderImpl(project)
|
||||||
@@ -143,8 +152,8 @@ fun Module.createFacet(
|
|||||||
modelsProvider.getModifiableRootModel(this@createFacet),
|
modelsProvider.getModifiableRootModel(this@createFacet),
|
||||||
platformKind
|
platformKind
|
||||||
)
|
)
|
||||||
if (implementedModuleName != null) {
|
if (implementedModuleNames != null) {
|
||||||
this.implementedModuleNames = listOf(implementedModuleName)
|
this.implementedModuleNames = implementedModuleNames
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
modelsProvider.commit()
|
modelsProvider.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user