mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Attempt to fix the tests for TeamCity.
This commit is contained in:
parent
bd861a9198
commit
c16aa0aa67
3 changed files with 19 additions and 8 deletions
|
@ -9,6 +9,7 @@ import com.beust.kobalt.internal.PluginInfo
|
|||
import com.beust.kobalt.internal.build.BuildFile
|
||||
import com.beust.kobalt.misc.KobaltLogger
|
||||
import org.testng.annotations.BeforeClass
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
|
@ -26,17 +27,20 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
|
|||
*/
|
||||
fun compileSingleProject(projectText: String, args: Args = Args()) : Project {
|
||||
val projectName = "p" + Math.abs(Random().nextInt())
|
||||
val projectDirectory = Files.createTempDirectory("kobaltTest").toFile().path
|
||||
|
||||
val buildFileText= """
|
||||
import com.beust.kobalt.*
|
||||
import com.beust.kobalt.api.*
|
||||
val $projectName = project {
|
||||
name = "$projectName"
|
||||
directory = "$projectDirectory"
|
||||
$projectText
|
||||
}
|
||||
"""
|
||||
""".trim()
|
||||
|
||||
args.noIncremental = true
|
||||
val projectResults = compileBuildFile(buildFileText, args)
|
||||
val projectResults = compileBuildFile(projectDirectory, buildFileText, args)
|
||||
val result = projectResults.projects.firstOrNull { it.name == projectName }
|
||||
if (result == null) {
|
||||
throw IllegalArgumentException("Couldn't find project named $projectName in "
|
||||
|
@ -51,10 +55,11 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
|
|||
* should preferably use random names for the projects defined in their build file to avoid
|
||||
* interfering with other tests.
|
||||
*/
|
||||
fun compileBuildFile(buildFileText: String, args: Args = Args()): BuildFileCompiler.FindProjectResult {
|
||||
fun compileBuildFile(projectDirectory: String, buildFileText: String, args: Args = Args())
|
||||
: BuildFileCompiler .FindProjectResult {
|
||||
KobaltLogger.LOG_LEVEL = 3
|
||||
val tmpBaseDir = Files.createTempDirectory("kobaltTest")
|
||||
val tmpBuildFile = Files.createTempFile(tmpBaseDir, "kobaltTest", "").toFile().apply {
|
||||
val path = Paths.get(projectDirectory)
|
||||
val tmpBuildFile = File(path.toFile(), "Build.kt").apply {
|
||||
deleteOnExit()
|
||||
writeText(buildFileText)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import org.assertj.core.api.Assertions.assertThat
|
|||
import org.testng.annotations.DataProvider
|
||||
import org.testng.annotations.Guice
|
||||
import org.testng.annotations.Test
|
||||
import java.nio.file.Files
|
||||
import java.util.*
|
||||
|
||||
@Guice(modules = arrayOf(TestModule::class))
|
||||
|
@ -18,6 +19,7 @@ class ProfileTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor
|
|||
|
||||
private fun runTestWithProfile(enabled: Boolean) : Project {
|
||||
val projectVal = "p" + Math.abs(Random().nextInt())
|
||||
val projectDirectory = Files.createTempDirectory("kobaltTest").toFile().path
|
||||
|
||||
fun buildFileString(): String {
|
||||
return """
|
||||
|
@ -26,13 +28,14 @@ class ProfileTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactor
|
|||
val profile = false
|
||||
val $projectVal = project {
|
||||
name = if (profile) "profileOn" else "profileOff"
|
||||
directory = "$projectDirectory"
|
||||
}
|
||||
"""
|
||||
""".trim()
|
||||
}
|
||||
|
||||
val args = Args()
|
||||
if (enabled) args.profiles = "profile"
|
||||
val results = compileBuildFile(buildFileString(), args)
|
||||
val results = compileBuildFile(projectDirectory, buildFileString(), args)
|
||||
return results.projects[0]
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ import org.assertj.core.api.Assertions.assertThat
|
|||
import org.eclipse.aether.util.filter.AndDependencyFilter
|
||||
import org.testng.annotations.Guice
|
||||
import org.testng.annotations.Test
|
||||
import java.nio.file.Files
|
||||
|
||||
@Guice(modules = arrayOf(TestModule::class))
|
||||
class DependencyManagerTest @Inject constructor(val dependencyManager: DependencyManager,
|
||||
|
@ -106,11 +107,13 @@ class DependencyManagerTest @Inject constructor(val dependencyManager: Dependenc
|
|||
}
|
||||
|
||||
private fun findDependentProject(): Project {
|
||||
val projectDirectory = Files.createTempDirectory("kobaltTest").toFile().path
|
||||
val sharedBuildFile = """
|
||||
import com.beust.kobalt.*
|
||||
|
||||
val lib2 = project {
|
||||
name = "lib2"
|
||||
directory = "$projectDirectory"
|
||||
dependencies {
|
||||
// pick dependencies that don't have dependencies themselves, to avoid interferences
|
||||
compile("com.beust:klaxon:0.27",
|
||||
|
@ -125,7 +128,7 @@ class DependencyManagerTest @Inject constructor(val dependencyManager: Dependenc
|
|||
}
|
||||
"""
|
||||
Kobalt.context = null
|
||||
return compileBuildFile(sharedBuildFile).projects.first { it.name == "transitive2" }
|
||||
return compileBuildFile(projectDirectory, sharedBuildFile).projects.first { it.name == "transitive2" }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue