mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 00:17:11 -07:00
Tests for profiles.
This commit is contained in:
parent
6b1ddc2333
commit
f8d2d0ed23
2 changed files with 79 additions and 0 deletions
27
src/test/kotlin/com/beust/kobalt/BaseTest.kt
Normal file
27
src/test/kotlin/com/beust/kobalt/BaseTest.kt
Normal file
|
@ -0,0 +1,27 @@
|
|||
package com.beust.kobalt
|
||||
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.app.BuildFileCompiler
|
||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||
import com.beust.kobalt.internal.KobaltPluginXml
|
||||
import com.beust.kobalt.internal.PluginInfo
|
||||
import com.beust.kobalt.internal.build.BuildFile
|
||||
import java.io.File
|
||||
import java.nio.file.Paths
|
||||
|
||||
interface BaseTest {
|
||||
fun compileBuildFile(buildFileText: String, args: Args, compilerFactory: BuildFileCompiler.IFactory)
|
||||
: BuildFileCompiler.FindProjectResult {
|
||||
val tmpBuildFile = File.createTempFile("kobaltTest", "").apply {
|
||||
deleteOnExit()
|
||||
writeText(buildFileText)
|
||||
}
|
||||
val thisBuildFile = BuildFile(Paths.get(tmpBuildFile.absolutePath), "Build.kt")
|
||||
args.buildFile = tmpBuildFile.absolutePath
|
||||
val jvmCompilerPlugin = Kobalt.findPlugin("JvmCompiler") as JvmCompilerPlugin
|
||||
val pluginInfo = PluginInfo(KobaltPluginXml(), null, null).apply {
|
||||
projectContributors.add(jvmCompilerPlugin)
|
||||
}
|
||||
return compilerFactory.create(listOf(thisBuildFile), pluginInfo).compileBuildFiles(args)
|
||||
}
|
||||
}
|
52
src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt
Normal file
52
src/test/kotlin/com/beust/kobalt/internal/ProfileTest.kt
Normal file
|
@ -0,0 +1,52 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.Args
|
||||
import com.beust.kobalt.BaseTest
|
||||
import com.beust.kobalt.TestModule
|
||||
import com.beust.kobalt.api.Kobalt
|
||||
import com.beust.kobalt.api.Project
|
||||
import com.beust.kobalt.app.BuildFileCompiler
|
||||
import com.google.inject.Inject
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.testng.annotations.Guice
|
||||
import org.testng.annotations.Test
|
||||
|
||||
@Guice(modules = arrayOf(TestModule::class))
|
||||
class ProfileTest @Inject constructor(val compilerFactory: BuildFileCompiler.IFactory
|
||||
// val jvmCompilerPlugin: JvmCompilerPlugin
|
||||
// val buildScriptUtil: BuildScriptUtil
|
||||
) : BaseTest {
|
||||
private fun runTestWithProfile(enabled: Boolean) : Project {
|
||||
val buildFileString = """
|
||||
| import com.beust.kobalt.*
|
||||
| import com.beust.kobalt.api.*
|
||||
| val profile = false
|
||||
| val p = project {
|
||||
| name = if (profile) "profileOn" else "profileOff"
|
||||
| }
|
||||
""".trimMargin()
|
||||
|
||||
val args = Args()
|
||||
if (enabled) args.profiles = "profile"
|
||||
// val jvmCompilerPlugin = Kobalt.findPlugin("JvmCompiler") as JvmCompilerPlugin
|
||||
// val pluginInfo = PluginInfo(KobaltPluginXml(), null, null).apply {
|
||||
// projectContributors.add(jvmCompilerPlugin)
|
||||
// }
|
||||
// val projects = buildScriptUtil.runBuildScriptJarFile()
|
||||
val compileResult = compileBuildFile(buildFileString, args, compilerFactory)
|
||||
return compileResult.projects[0]
|
||||
}
|
||||
|
||||
@Test
|
||||
fun profilesShouldWork() {
|
||||
Kobalt.init(TestModule())
|
||||
assertThat(runTestWithProfile(true).name).isEqualTo("profileOn")
|
||||
// Kobalt.INJECTOR.getInstance(Plugins::class.java).shutdownPlugins()
|
||||
// Kobalt.init(TestModule())
|
||||
// val success = File(KFiles.KOBALT_DOT_DIR).deleteRecursively()
|
||||
// println("DELETING " + File(KFiles.KOBALT_DOT_DIR).absolutePath + ": $success")
|
||||
// assertThat(runTestWithProfile(false).name).isEqualTo("profileOff")
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue