Test: use one function to find test's build log for jps and gradle

This commit is contained in:
Alexey Tsvetkov
2016-03-14 15:52:40 +03:00
parent 3d8ec118cb
commit c1a61b17c7
5 changed files with 63 additions and 24 deletions
@@ -0,0 +1,44 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.incremental.testingUtils
import java.io.File
class BuildLogFinder(
private val isExperimentalEnabled: Boolean = false,
private val isDataContainerBuildLogEnabled: Boolean = false
) {
companion object {
private const val DATA_CONTAINER_LOG = "data-container-version-build.log"
private const val EXPERIMENTAL_LOG = "experimental-ic-build.log"
private const val SIMPLE_LOG = "build.log"
}
fun findBuildLog(dir: File): File? {
val names = dir.list() ?: arrayOf()
val files = names.filter { File(dir, it).isFile }.toSet()
val matchedName = when {
isDataContainerBuildLogEnabled && DATA_CONTAINER_LOG in files -> DATA_CONTAINER_LOG
isExperimentalEnabled && EXPERIMENTAL_LOG in files -> EXPERIMENTAL_LOG
SIMPLE_LOG in files -> SIMPLE_LOG
else -> null
}
return File(dir, matchedName ?: return null)
}
}
@@ -74,8 +74,6 @@ abstract class AbstractIncrementalJpsTest(
val TEMP_DIRECTORY_TO_USE = File(FileUtilRt.getTempDirectory())
val DEBUG_LOGGING_ENABLED = System.getProperty("debug.logging.enabled") == "true"
private val BUILD_LOG_FILE_NAME = "build.log"
}
protected open val enableExperimentalIncrementalCompilation = false
@@ -90,7 +88,8 @@ abstract class AbstractIncrementalJpsTest(
protected var mapWorkingToOriginalFile: MutableMap<File, File> = hashMapOf()
protected open val experimentalBuildLogFileName = "experimental-ic-build.log"
protected open val buildLogFinder: BuildLogFinder
get() = BuildLogFinder(isExperimentalEnabled = enableExperimentalIncrementalCompilation)
private fun enableDebugLogging() {
com.intellij.openapi.diagnostic.Logger.setFactory(TestLoggerFactory::class.java)
@@ -274,18 +273,15 @@ abstract class AbstractIncrementalJpsTest(
initialMake()
val otherMakeResults = performModificationsAndMake(moduleNames)
val buildLogFile = File(testDataDir, BUILD_LOG_FILE_NAME)
val experimentalBuildLog = File(testDataDir, experimentalBuildLogFileName)
val buildLogFile = buildLogFinder.findBuildLog(testDataDir)
val logs = createBuildLog(otherMakeResults)
if (enableExperimentalIncrementalCompilation && experimentalBuildLog.exists()) {
UsefulTestCase.assertSameLinesWithFile(experimentalBuildLog.absolutePath, logs)
}
else if (buildLogFile.exists() || !allowNoBuildLogFileInTestData) {
if (buildLogFile != null && buildLogFile.exists()) {
UsefulTestCase.assertSameLinesWithFile(buildLogFile.absolutePath, logs)
}
else if (!allowNoBuildLogFileInTestData) {
throw IllegalStateException("No build log file in $testDataDir")
}
if (!enableExperimentalIncrementalCompilation && File(testDataDir, "dont-check-caches-in-non-experimental-ic.txt").exists()) return
@@ -17,6 +17,7 @@
package org.jetbrains.kotlin.jps.build
import org.jetbrains.jps.incremental.ModuleBuildTarget
import org.jetbrains.kotlin.incremental.testingUtils.BuildLogFinder
import org.jetbrains.kotlin.jps.incremental.CacheVersionProvider
abstract class AbstractExperimentalIncrementalJpsTest : AbstractIncrementalJpsTest() {
@@ -40,7 +41,8 @@ abstract class AbstractExperimentalIncrementalCacheVersionChangedTest : Abstract
}
abstract class AbstractDataContainerVersionChangedTest : AbstractExperimentalIncrementalCacheVersionChangedTest() {
override val experimentalBuildLogFileName = "data-container-version-build.log"
override val buildLogFinder: BuildLogFinder
get() = BuildLogFinder(isExperimentalEnabled = true, isDataContainerBuildLogEnabled = true)
override fun getVersions(cacheVersionProvider: CacheVersionProvider, targets: Iterable<ModuleBuildTarget>) =
listOf(cacheVersionProvider.dataContainerVersion())
@@ -3,18 +3,14 @@ package org.jetbrains.kotlin.gradle
import org.gradle.api.logging.LogLevel
import org.jetbrains.kotlin.gradle.incremental.BuildStep
import org.jetbrains.kotlin.gradle.incremental.parseTestBuildLog
import org.jetbrains.kotlin.incremental.testingUtils.TouchPolicy
import org.jetbrains.kotlin.incremental.testingUtils.assertEqualDirectories
import org.jetbrains.kotlin.incremental.testingUtils.copyTestSources
import org.jetbrains.kotlin.incremental.testingUtils.getModificationsToPerform
import org.jetbrains.kotlin.incremental.testingUtils.*
import org.junit.Assume
import java.io.File
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
abstract class BaseIncrementalGradleIT : BaseGradleIT() {
inner class JpsTestProject(val resourcesBase: File, val relPath: String, wrapperVersion: String = "2.10", minLogLevel: LogLevel = LogLevel.DEBUG) : Project(File(relPath).name, wrapperVersion, minLogLevel) {
inner class JpsTestProject(val buildLogFinder: BuildLogFinder, val resourcesBase: File, val relPath: String, wrapperVersion: String = "2.10", minLogLevel: LogLevel = LogLevel.DEBUG) : Project(File(relPath).name, wrapperVersion, minLogLevel) {
override val resourcesRoot = File(resourcesBase, relPath)
val mapWorkingToOriginalFile = hashMapOf<File, File>()
@@ -39,10 +35,9 @@ abstract class BaseIncrementalGradleIT : BaseGradleIT() {
assertReportExists()
}
val buildLogFile = resourcesRoot.listFiles { f: File -> f.name.endsWith("build.log") }?.sortedBy { it.length() }?.firstOrNull()
assertNotNull(buildLogFile, "*build.log file not found" )
val buildLogSteps = parseTestBuildLog(buildLogFile!!)
val buildLogFile = buildLogFinder.findBuildLog(resourcesRoot) ?:
throw IllegalStateException("build log file not found in $resourcesRoot")
val buildLogSteps = parseTestBuildLog(buildLogFile)
val modifications = getModificationsToPerform(resourcesRoot,
moduleNames = null,
allowNoFilesWithSuffixInTestData = false,
@@ -1,5 +1,6 @@
package org.jetbrains.kotlin.gradle
import org.jetbrains.kotlin.incremental.testingUtils.BuildLogFinder
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized
@@ -20,7 +21,7 @@ class KotlinGradlePluginJpsParametrizedCLIOnly : BaseIncrementalGradleIT() {
@Test
fun testFromJps() {
JpsTestProject(jpsResourcesPath, relativePath).performAndAssertBuildStages(weakTesting = true)
JpsTestProject(buildLogFinder, jpsResourcesPath, relativePath).performAndAssertBuildStages(weakTesting = true)
}
override fun defaultBuildOptions(): BuildOptions =
@@ -33,6 +34,7 @@ class KotlinGradlePluginJpsParametrizedCLIOnly : BaseIncrementalGradleIT() {
File(jpsResourcesPath, "changeIncrementalOption"),
File(jpsResourcesPath, "custom"),
File(jpsResourcesPath, "lookupTracker"))
private val buildLogFinder = BuildLogFinder(isExperimentalEnabled = true)
@Suppress("unused")
@Parameterized.Parameters(name = "{index}: {0}")
@@ -40,7 +42,7 @@ class KotlinGradlePluginJpsParametrizedCLIOnly : BaseIncrementalGradleIT() {
fun data(): List<Array<String>> =
jpsResourcesPath.walk()
.onEnter { it !in ignoredDirs }
.filter { it.isDirectory && isJpsTestProject(it) }
.filter { it.isDirectory && buildLogFinder.findBuildLog(it) != null }
.map { arrayOf(it.toRelativeString(jpsResourcesPath)) }
.toList()
}