Fix test failure because of duplicates file templates in classpath

There're two ways for getting templates in test runtime. One is from
sources resource files, the second one is from compiled jar.

Remove the first entry manually.

A better fix is to extract tests to separate module. This will leave
only jar in the test runtime classpath.
This commit is contained in:
Nikolay Krasko
2019-07-11 17:17:48 +03:00
parent 0eea2479fc
commit e28802fbfa
3 changed files with 56 additions and 59 deletions
@@ -48,8 +48,9 @@ public class PrintingLogger extends Logger {
@Override
public void debug(@Nullable Throwable t) {
//noinspection ConstantConditions
t.printStackTrace(out);
if (t != null) {
t.printStackTrace(out);
}
}
@Override
+12
View File
@@ -78,6 +78,18 @@ testsJar()
projectTest(parallel = true) {
workingDir = rootDir
useAndroidSdk()
doFirst {
val mainResourceDirPath = File(project.buildDir, "resources/main").absolutePath
sourceSets["test"].runtimeClasspath = sourceSets["test"].runtimeClasspath.filter { file ->
if (!file.absolutePath.contains(mainResourceDirPath)) {
true
} else {
println("Remove `${file.path}` from the test runtime classpath")
false
}
}
}
}
configureFormInstrumentation()
@@ -45,7 +45,7 @@ import com.intellij.util.containers.ContainerUtil
import com.intellij.util.containers.ContainerUtilRt
import junit.framework.TestCase
import org.jetbrains.kotlin.idea.codeInsight.gradle.GradleImportingTestCase
import org.jetbrains.kotlin.idea.configuration.KotlinGradleAbstractMultiplatformModuleBuilder
import org.jetbrains.kotlin.idea.configuration.*
import org.jetbrains.kotlin.utils.PrintingLogger
import org.jetbrains.plugins.gradle.service.execution.GradleExecutionHelper
import org.jetbrains.plugins.gradle.settings.DistributionType
@@ -85,66 +85,50 @@ abstract class AbstractGradleMultiplatformWizardTest : ProjectWizardTestCase<Abs
performImport: Boolean = true,
useQualifiedModuleNames: Boolean = false
): Project {
// TODO: check whether it's necessary to have templates in sources
// Temporary workaround for duplicated bundled template
class PrintingFactory : Logger.Factory {
override fun getLoggerInstance(category: String): Logger {
return PrintingLogger(System.out)
}
}
val project = createProject { step ->
if (step is ProjectTypeStep) {
TestCase.assertTrue(step.setSelectedTemplate("Kotlin", builder.presentableName))
val steps = myWizard.sequence.selectedSteps
TestCase.assertEquals(4, steps.size)
val projectBuilder = myWizard.projectBuilder
UsefulTestCase.assertInstanceOf(projectBuilder, builder::class.java)
with(projectBuilder as KotlinGradleAbstractMultiplatformModuleBuilder) {
explicitPluginVersion = pluginVersion
}
val oldFactory = Logger.getFactory().javaClass
try {
Logger.setFactory(PrintingFactory::class.java)
val project = createProject { step ->
if (step is ProjectTypeStep) {
TestCase.assertTrue(step.setSelectedTemplate("Kotlin", builder.presentableName))
val steps = myWizard.sequence.selectedSteps
TestCase.assertEquals(4, steps.size)
val projectBuilder = myWizard.projectBuilder
UsefulTestCase.assertInstanceOf(projectBuilder, builder::class.java)
with(projectBuilder as KotlinGradleAbstractMultiplatformModuleBuilder) {
explicitPluginVersion = pluginVersion
}
myProject.reconfigureGradleSettings {
distributionType = DistributionType.DEFAULT_WRAPPED
}
myProject.reconfigureGradleSettings {
distributionType = DistributionType.DEFAULT_WRAPPED
}
}
val modules = ModuleManager.getInstance(project).modules
TestCase.assertEquals(1, modules.size)
val module = modules[0]
TestCase.assertTrue(ModuleRootManager.getInstance(module).isSdkInherited)
val root = ProjectRootManager.getInstance(project).contentRoots[0]
val settingsScript = VfsUtilCore.findRelativeFile("settings.gradle", root)
TestCase.assertNotNull(settingsScript)
val settingsScriptText = StringUtil.convertLineSeparators(VfsUtilCore.loadText(settingsScript!!))
TestCase.assertTrue("rootProject.name = " in settingsScriptText)
if (metadataInside) {
TestCase.assertTrue("enableFeaturePreview('GRADLE_METADATA')" in settingsScriptText)
}
File(root.canonicalPath).assertNoEmptyChildren()
val buildScript = VfsUtilCore.findRelativeFile("build.gradle", root)!!
val buildScriptText = StringUtil.convertLineSeparators(VfsUtilCore.loadText(buildScript))
println(buildScriptText)
if (!performImport) return project
doImportProject(project, useQualifiedModuleNames)
if (testClassNames.isNotEmpty()) {
doTestProject(project, *testClassNames)
}
return project
} finally {
Logger.setFactory(oldFactory)
}
val modules = ModuleManager.getInstance(project).modules
TestCase.assertEquals(1, modules.size)
val module = modules[0]
TestCase.assertTrue(ModuleRootManager.getInstance(module).isSdkInherited)
val root = ProjectRootManager.getInstance(project).contentRoots[0]
val settingsScript = VfsUtilCore.findRelativeFile("settings.gradle", root)
TestCase.assertNotNull(settingsScript)
val settingsScriptText = StringUtil.convertLineSeparators(VfsUtilCore.loadText(settingsScript!!))
TestCase.assertTrue("rootProject.name = " in settingsScriptText)
if (metadataInside) {
TestCase.assertTrue("enableFeaturePreview('GRADLE_METADATA')" in settingsScriptText)
}
File(root.canonicalPath).assertNoEmptyChildren()
val buildScript = VfsUtilCore.findRelativeFile("build.gradle", root)!!
val buildScriptText = StringUtil.convertLineSeparators(VfsUtilCore.loadText(buildScript))
println(buildScriptText)
if (!performImport) return project
doImportProject(project, useQualifiedModuleNames)
if (testClassNames.isNotEmpty()) {
doTestProject(project, *testClassNames)
}
return project
}
private fun File.assertNoEmptyChildren() {