[CHERRY PICKED FROM IJ] [tests] KotlinJpsBuildTest*: cleanup code
GitOrigin-RevId: 626313b2a47cab2f63a721d3de33d97af42b01fb Original commit: https://github.com/JetBrains/intellij-community/commit/50dbdf9d30afa914978abb97f45b82cf226a5d8d
This commit is contained in:
committed by
Nikita Bobko
parent
8debe8667e
commit
ef27b134a2
+28
-30
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.jps.build
|
||||
|
||||
import com.google.common.collect.Lists
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.util.io.FileUtil.toSystemIndependentName
|
||||
import com.intellij.openapi.util.io.FileUtilRt
|
||||
@@ -24,13 +23,13 @@ import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.openapi.vfs.StandardFileSystems
|
||||
import com.intellij.testFramework.LightVirtualFile
|
||||
import com.intellij.testFramework.UsefulTestCase
|
||||
import com.intellij.util.io.Decompressor
|
||||
import com.intellij.util.io.URLUtil
|
||||
import com.intellij.util.io.ZipUtil
|
||||
import org.jetbrains.jps.ModuleChunk
|
||||
import org.jetbrains.jps.api.CanceledStatus
|
||||
import org.jetbrains.jps.builders.BuildResult
|
||||
import org.jetbrains.jps.builders.CompileScopeTestBuilder
|
||||
import org.jetbrains.jps.builders.JpsBuildTestCase
|
||||
import org.jetbrains.jps.builders.TestProjectBuilderLogger
|
||||
import org.jetbrains.jps.builders.impl.BuildDataPathsImpl
|
||||
import org.jetbrains.jps.builders.logging.BuildLoggingManager
|
||||
@@ -86,13 +85,13 @@ import java.util.zip.ZipOutputStream
|
||||
|
||||
open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
companion object {
|
||||
private val ADDITIONAL_MODULE_NAME = "module2"
|
||||
private const val ADDITIONAL_MODULE_NAME = "module2"
|
||||
|
||||
private val EXCLUDE_FILES = arrayOf("Excluded.class", "YetAnotherExcluded.class")
|
||||
private val NOTHING = arrayOf<String>()
|
||||
private val KOTLIN_JS_LIBRARY = "jslib-example"
|
||||
private const val KOTLIN_JS_LIBRARY = "jslib-example"
|
||||
private val PATH_TO_KOTLIN_JS_LIBRARY = AbstractKotlinJpsBuildTestCase.TEST_DATA_PATH + "general/KotlinJavaScriptProjectWithDirectoryAsLibrary/" + KOTLIN_JS_LIBRARY
|
||||
private val KOTLIN_JS_LIBRARY_JAR = "$KOTLIN_JS_LIBRARY.jar"
|
||||
private const val KOTLIN_JS_LIBRARY_JAR = "$KOTLIN_JS_LIBRARY.jar"
|
||||
|
||||
private fun getMethodsOfClass(classFile: File): Set<String> {
|
||||
val result = TreeSet<String>()
|
||||
@@ -117,17 +116,17 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
}
|
||||
}
|
||||
|
||||
fun doTest() {
|
||||
protected fun doTest() {
|
||||
initProject(JVM_MOCK_RUNTIME)
|
||||
buildAllModules().assertSuccessful()
|
||||
}
|
||||
|
||||
fun doTestWithRuntime() {
|
||||
protected fun doTestWithRuntime() {
|
||||
initProject(JVM_FULL_RUNTIME)
|
||||
buildAllModules().assertSuccessful()
|
||||
}
|
||||
|
||||
fun doTestWithKotlinJavaScriptLibrary() {
|
||||
protected fun doTestWithKotlinJavaScriptLibrary() {
|
||||
initProject(JS_STDLIB)
|
||||
createKotlinJavaScriptLibraryArchive()
|
||||
addDependency(KOTLIN_JS_LIBRARY, File(workDir, KOTLIN_JS_LIBRARY_JAR))
|
||||
@@ -170,14 +169,13 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
val moduleNamesSet = moduleNames.toSet()
|
||||
val list = mutableListOf<String>()
|
||||
|
||||
myProject.modules.forEach {
|
||||
if (it.name in moduleNamesSet) {
|
||||
val outputDir = it.productionBuildTarget.outputDir!!
|
||||
list.add(toSystemIndependentName(File("$outputDir/${it.name}.js").relativeTo(workDir).path))
|
||||
list.add(toSystemIndependentName(File("$outputDir/${it.name}.meta.js").relativeTo(workDir).path))
|
||||
myProject.modules.forEach { module ->
|
||||
if (module.name in moduleNamesSet) {
|
||||
val outputDir = module.productionBuildTarget.outputDir!!
|
||||
list.add(toSystemIndependentName(File("$outputDir/${module.name}.js").relativeTo(workDir).path))
|
||||
list.add(toSystemIndependentName(File("$outputDir/${module.name}.meta.js").relativeTo(workDir).path))
|
||||
|
||||
val kjsmFiles = outputDir.walk()
|
||||
.filter { it.isFile && it.extension.equals("kjsm", ignoreCase = true) }
|
||||
val kjsmFiles = outputDir.walk().filter { it.isFile && it.extension.equals("kjsm", ignoreCase = true) }
|
||||
|
||||
list.addAll(kjsmFiles.map { toSystemIndependentName(it.relativeTo(workDir).path) })
|
||||
}
|
||||
@@ -248,7 +246,7 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
val jslibJar = PathUtil.kotlinPathsForDistDirectory.jsStdLibJarPath
|
||||
val jslibDir = File(workDir, "KotlinJavaScript")
|
||||
try {
|
||||
ZipUtil.extract(jslibJar, jslibDir, null)
|
||||
Decompressor.Zip(jslibJar).extract(jslibDir.toPath())
|
||||
}
|
||||
catch (ex: IOException) {
|
||||
throw IllegalStateException(ex.message)
|
||||
@@ -341,7 +339,7 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
fun testExcludeFolderInSourceRoot() {
|
||||
doTest()
|
||||
|
||||
val module = myProject.modules.get(0)
|
||||
val module = myProject.modules[0]
|
||||
assertFilesExistInOutput(module, "Foo.class")
|
||||
assertFilesNotExistInOutput(module, *EXCLUDE_FILES)
|
||||
|
||||
@@ -371,7 +369,7 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
fun testExcludeFileUsingCompilerSettings() {
|
||||
doTest()
|
||||
|
||||
val module = myProject.modules.get(0)
|
||||
val module = myProject.modules[0]
|
||||
assertFilesExistInOutput(module, "Foo.class", "Bar.class")
|
||||
assertFilesNotExistInOutput(module, *EXCLUDE_FILES)
|
||||
|
||||
@@ -390,7 +388,7 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
fun testExcludeFolderNonRecursivelyUsingCompilerSettings() {
|
||||
doTest()
|
||||
|
||||
val module = myProject.modules.get(0)
|
||||
val module = myProject.modules[0]
|
||||
assertFilesExistInOutput(module, "Foo.class", "Bar.class")
|
||||
assertFilesNotExistInOutput(module, *EXCLUDE_FILES)
|
||||
|
||||
@@ -411,7 +409,7 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
fun testExcludeFolderRecursivelyUsingCompilerSettings() {
|
||||
doTest()
|
||||
|
||||
val module = myProject.modules.get(0)
|
||||
val module = myProject.modules[0]
|
||||
assertFilesExistInOutput(module, "Foo.class", "Bar.class")
|
||||
assertFilesNotExistInOutput(module, *EXCLUDE_FILES)
|
||||
|
||||
@@ -447,7 +445,7 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
packagePartClass("kotlinProject", "src/test2.kt", "_DefaultPackage"),
|
||||
module("kotlinProject")))
|
||||
|
||||
assertFilesNotExistInOutput(myProject.modules.get(0), "_DefaultPackage.class")
|
||||
assertFilesNotExistInOutput(myProject.modules[0], "_DefaultPackage.class")
|
||||
}
|
||||
|
||||
fun testDefaultLanguageVersionCustomApiVersion() {
|
||||
@@ -615,7 +613,7 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
|
||||
val libraryJar = MockLibraryUtilExt.compileJvmLibraryToJar(workDir.absolutePath + File.separator + "oldModuleLib/src", "module-lib")
|
||||
|
||||
AbstractKotlinJpsBuildTestCase.addDependency(JpsJavaDependencyScope.COMPILE, Lists.newArrayList(findModule("module1"), findModule("module2")), false, "module-lib", libraryJar)
|
||||
AbstractKotlinJpsBuildTestCase.addDependency(JpsJavaDependencyScope.COMPILE, listOf(findModule("module1"), findModule("module2")), false, "module-lib", libraryJar)
|
||||
|
||||
val result = buildAllModules()
|
||||
result.assertSuccessful()
|
||||
@@ -626,7 +624,7 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
|
||||
val libraryJar = MockLibraryUtilExt.compileJvmLibraryToJar(workDir.absolutePath + File.separator + "oldModuleLib/src", "module-lib")
|
||||
|
||||
AbstractKotlinJpsBuildTestCase.addDependency(JpsJavaDependencyScope.COMPILE, Lists.newArrayList(findModule("module")), false, "module-lib", libraryJar)
|
||||
AbstractKotlinJpsBuildTestCase.addDependency(JpsJavaDependencyScope.COMPILE, listOf(findModule("module")), false, "module-lib", libraryJar)
|
||||
|
||||
addKotlinStdlibDependency()
|
||||
|
||||
@@ -702,7 +700,7 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
|
||||
fun testReexportedDependency() {
|
||||
initProject()
|
||||
AbstractKotlinJpsBuildTestCase.addKotlinStdlibDependency(myProject.modules.filter { module -> module.name == "module2" }, true)
|
||||
addKotlinStdlibDependency(myProject.modules.filter { module -> module.name == "module2" }, true)
|
||||
buildAllModules().assertSuccessful()
|
||||
}
|
||||
|
||||
@@ -752,7 +750,7 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
initProject(JVM_MOCK_RUNTIME)
|
||||
buildAllModules().assertSuccessful()
|
||||
|
||||
val module = myProject.modules.get(0)
|
||||
val module = myProject.modules[0]
|
||||
assertFilesExistInOutput(module, "foo/Bar.class")
|
||||
|
||||
val buildResult = BuildResult()
|
||||
@@ -761,7 +759,7 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
|
||||
override fun isCanceled(): Boolean {
|
||||
val messages = buildResult.getMessages(BuildMessage.Kind.INFO)
|
||||
for (i in checkFromIndex..messages.size - 1) {
|
||||
for (i in checkFromIndex until messages.size) {
|
||||
if (messages[i].messageText.matches("kotlinc-jvm .+ \\(JRE .+\\)".toRegex())) {
|
||||
return true
|
||||
}
|
||||
@@ -786,12 +784,12 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
val filesToBeReported = absoluteFiles("badroot.jar", "some/test.class")
|
||||
val otherFiles = absoluteFiles("test/other/file.xml", "some/other/baddir")
|
||||
|
||||
AbstractKotlinJpsBuildTestCase.addDependency(
|
||||
addDependency(
|
||||
JpsJavaDependencyScope.COMPILE,
|
||||
Lists.newArrayList(findModule("module")),
|
||||
listOf(findModule("module")),
|
||||
false,
|
||||
"LibraryWithBadRoots",
|
||||
*(filesToBeReported + otherFiles)
|
||||
*(filesToBeReported + otherFiles),
|
||||
)
|
||||
|
||||
val result = buildAllModules()
|
||||
@@ -1103,7 +1101,7 @@ open class KotlinJpsBuildTest : KotlinJpsBuildTestBase() {
|
||||
protected fun del(path: String): Action = Action(Operation.DELETE, path)
|
||||
|
||||
// TODO inline after KT-3974 will be fixed
|
||||
protected fun touch(file: File): Unit = JpsBuildTestCase.change(file.absolutePath)
|
||||
protected fun touch(file: File): Unit = change(file.absolutePath)
|
||||
|
||||
protected inner class Action constructor(private val operation: Operation, private val path: String) {
|
||||
fun apply() {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2020 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.
|
||||
*/
|
||||
|
||||
|
||||
+33
-22
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.jps.build
|
||||
|
||||
import com.intellij.util.ThrowableRunnable
|
||||
import org.jetbrains.jps.builders.JpsBuildTestCase
|
||||
import org.jetbrains.kotlin.cli.common.arguments.CommonCompilerArguments
|
||||
import org.jetbrains.kotlin.compilerRunner.JpsKotlinCompilerRunner
|
||||
import org.jetbrains.kotlin.config.LanguageVersion
|
||||
@@ -50,7 +49,7 @@ class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() {
|
||||
|
||||
val class2Kt = File(workDir, "src/Class2.kt")
|
||||
val newClass2KtContent = class2Kt.readText().replace("package2", "package1")
|
||||
JpsBuildTestCase.change(class2Kt.path, newClass2KtContent)
|
||||
change(class2Kt.path, newClass2KtContent)
|
||||
buildAllModules().assertSuccessful()
|
||||
checkOutputFilesList(File(workDir, "out/production"))
|
||||
}
|
||||
@@ -60,16 +59,16 @@ class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() {
|
||||
assertTrue("Daemon was not enabled!", isDaemonEnabled())
|
||||
|
||||
doTest()
|
||||
val module = myProject.modules.get(0)
|
||||
val module = myProject.modules[0]
|
||||
val mainKtClassFile = findFileInOutputDir(module, "MainKt.class")
|
||||
assertTrue("$mainKtClassFile does not exist!", mainKtClassFile.exists())
|
||||
|
||||
val fooKt = File(workDir, "src/Foo.kt")
|
||||
JpsBuildTestCase.change(fooKt.path, null)
|
||||
change(fooKt.path, null)
|
||||
buildAllModules().assertSuccessful()
|
||||
assertCompiled(KotlinBuilder.KOTLIN_BUILDER_NAME, "src/Foo.kt")
|
||||
|
||||
JpsBuildTestCase.change(fooKt.path, "class Foo(val x: Int = 0)")
|
||||
change(fooKt.path, "class Foo(val x: Int = 0)")
|
||||
buildAllModules().assertSuccessful()
|
||||
assertCompiled(KotlinBuilder.KOTLIN_BUILDER_NAME, "src/main.kt", "src/Foo.kt")
|
||||
}
|
||||
@@ -84,16 +83,18 @@ class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() {
|
||||
fun testManyFiles() {
|
||||
doTest()
|
||||
|
||||
val module = myProject.modules.get(0)
|
||||
val module = myProject.modules[0]
|
||||
assertFilesExistInOutput(module, "foo/MainKt.class", "boo/BooKt.class", "foo/Bar.class")
|
||||
|
||||
checkWhen(touch("src/main.kt"), null, packageClasses("kotlinProject", "src/main.kt", "foo.MainKt"))
|
||||
checkWhen(touch("src/boo.kt"), null, packageClasses("kotlinProject", "src/boo.kt", "boo.BooKt"))
|
||||
checkWhen(touch("src/Bar.kt"), arrayOf("src/Bar.kt"), arrayOf(module("kotlinProject"), klass("kotlinProject", "foo.Bar")))
|
||||
|
||||
checkWhen(del("src/main.kt"),
|
||||
pathsToCompile = null,
|
||||
pathsToDelete = packageClasses("kotlinProject", "src/main.kt", "foo.MainKt"))
|
||||
checkWhen(
|
||||
del("src/main.kt"),
|
||||
pathsToCompile = null,
|
||||
pathsToDelete = packageClasses("kotlinProject", "src/main.kt", "foo.MainKt")
|
||||
)
|
||||
assertFilesExistInOutput(module, "boo/BooKt.class", "foo/Bar.class")
|
||||
assertFilesNotExistInOutput(module, "foo/MainKt.class")
|
||||
|
||||
@@ -104,27 +105,37 @@ class KotlinJpsBuildTestIncremental : KotlinJpsBuildTest() {
|
||||
fun testManyFilesForPackage() {
|
||||
doTest()
|
||||
|
||||
val module = myProject.modules.get(0)
|
||||
val module = myProject.modules[0]
|
||||
assertFilesExistInOutput(module, "foo/MainKt.class", "boo/BooKt.class", "foo/Bar.class")
|
||||
|
||||
checkWhen(touch("src/main.kt"), null, packageClasses("kotlinProject", "src/main.kt", "foo.MainKt"))
|
||||
checkWhen(touch("src/boo.kt"), null, packageClasses("kotlinProject", "src/boo.kt", "boo.BooKt"))
|
||||
checkWhen(touch("src/Bar.kt"),
|
||||
arrayOf("src/Bar.kt"),
|
||||
arrayOf(klass("kotlinProject", "foo.Bar"),
|
||||
packagePartClass("kotlinProject", "src/Bar.kt", "foo.MainKt"),
|
||||
module("kotlinProject")))
|
||||
checkWhen(
|
||||
touch("src/Bar.kt"),
|
||||
arrayOf("src/Bar.kt"),
|
||||
arrayOf(
|
||||
klass("kotlinProject", "foo.Bar"),
|
||||
packagePartClass("kotlinProject", "src/Bar.kt", "foo.MainKt"),
|
||||
module("kotlinProject")
|
||||
)
|
||||
)
|
||||
|
||||
checkWhen(del("src/main.kt"),
|
||||
pathsToCompile = null,
|
||||
pathsToDelete = packageClasses("kotlinProject", "src/main.kt", "foo.MainKt"))
|
||||
checkWhen(
|
||||
del("src/main.kt"),
|
||||
pathsToCompile = null,
|
||||
pathsToDelete = packageClasses("kotlinProject", "src/main.kt", "foo.MainKt")
|
||||
)
|
||||
assertFilesExistInOutput(module, "boo/BooKt.class", "foo/Bar.class")
|
||||
|
||||
checkWhen(touch("src/boo.kt"), null, packageClasses("kotlinProject", "src/boo.kt", "boo.BooKt"))
|
||||
checkWhen(touch("src/Bar.kt"), null,
|
||||
arrayOf(klass("kotlinProject", "foo.Bar"),
|
||||
packagePartClass("kotlinProject", "src/Bar.kt", "foo.MainKt"),
|
||||
module("kotlinProject")))
|
||||
checkWhen(
|
||||
touch("src/Bar.kt"), null,
|
||||
arrayOf(
|
||||
klass("kotlinProject", "foo.Bar"),
|
||||
packagePartClass("kotlinProject", "src/Bar.kt", "foo.MainKt"),
|
||||
module("kotlinProject")
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@WorkingDir("LanguageOrApiVersionChanged")
|
||||
|
||||
Reference in New Issue
Block a user