mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
InstallTest and BuildFilesTest.
This commit is contained in:
parent
f83bdfe3b2
commit
b0e823958b
4 changed files with 60 additions and 4 deletions
|
@ -93,7 +93,7 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
|
|||
|
||||
fun createTemporaryProjectDirectory() = KFiles.fixSlashes(Files.createTempDirectory("kobaltTest").toFile())
|
||||
|
||||
class ProjectDescription(val path: File, val name: String, val version: String)
|
||||
class ProjectDescription(val file: File, val name: String, val version: String)
|
||||
|
||||
fun createProject(projectInfo: ProjectInfo) : ProjectDescription {
|
||||
val root = Files.createTempDirectory("kobalt-test").toFile()
|
||||
|
@ -125,7 +125,7 @@ open class BaseTest(val compilerFactory: BuildFileCompiler.IFactory? = null) {
|
|||
val main = Kobalt.INJECTOR.getInstance(Main::class.java)
|
||||
val args = Args()
|
||||
val jc = JCommander(args).apply { parse(*commandLine) }
|
||||
args.buildFile = project.path.absolutePath + "/kobalt/src/Build.kt"
|
||||
args.buildFile = project.file.absolutePath + "/kobalt/src/Build.kt"
|
||||
val result = Main.launchMain(main, jc, args, arrayOf("assemble"))
|
||||
return LaunchProjectResult(projectInfo, project, result)
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ class BuildFilesTest : BaseTest() {
|
|||
val result = launchProject(projectInfo, arrayOf("assemble"))
|
||||
|
||||
val project = result.projectDescription
|
||||
val jarFile = File(KFiles.joinDir(project.path.absolutePath, "kobaltBuild/libs", project.name + "-"
|
||||
val jarFile = File(KFiles.joinDir(project.file.absolutePath, "kobaltBuild/libs", project.name + "-"
|
||||
+ project.version + ".jar"))
|
||||
|
||||
assertThat(jarFile).exists()
|
||||
|
|
56
src/test/kotlin/com/beust/kobalt/internal/InstallTest.kt
Normal file
56
src/test/kotlin/com/beust/kobalt/internal/InstallTest.kt
Normal file
|
@ -0,0 +1,56 @@
|
|||
package com.beust.kobalt.internal
|
||||
|
||||
import com.beust.kobalt.*
|
||||
import com.beust.kobalt.app.BuildFileCompiler
|
||||
import com.google.inject.Inject
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.testng.IModuleFactory
|
||||
import org.testng.ITestContext
|
||||
import org.testng.annotations.Test
|
||||
import java.io.File
|
||||
|
||||
class ModuleFactory : IModuleFactory {
|
||||
companion object {
|
||||
val TEST_MODULE = TestModule()
|
||||
}
|
||||
|
||||
override fun createModule(tc: ITestContext?, c: Class<*>?) = TEST_MODULE
|
||||
}
|
||||
|
||||
class InstallTest @Inject constructor(compilerFactory: BuildFileCompiler.IFactory) : BaseTest(compilerFactory) {
|
||||
|
||||
private fun toPath(s: String) = "\"\${project.directory}/$s\""
|
||||
private fun from(path: String) = "from(" + toPath(path) + ")"
|
||||
private fun to(path: String) = "to(" + toPath(path) + ")"
|
||||
private fun include(s1: String, s2: String, s3: String) = "include(from(" + toPath(s1) + "), " +
|
||||
"to(" + toPath(s2) + "), " + s3 + ")"
|
||||
|
||||
private fun assertFile(lpr: LaunchProjectResult, path: String, content: String) {
|
||||
File(lpr.projectDescription.file.absolutePath, path).let { file ->
|
||||
assertThat(file).exists()
|
||||
assertThat(file.readText()).isEqualTo(content)
|
||||
}
|
||||
}
|
||||
|
||||
@Test(description = "Test that copy() and include() work properly")
|
||||
fun shouldInstall() {
|
||||
val from = from("testFile")
|
||||
val to = to("installed")
|
||||
val inc = include("a", "deployed2", "glob(\"**/*\")")
|
||||
val install = """
|
||||
install {
|
||||
copy($from, $to)
|
||||
$inc
|
||||
}
|
||||
""".trimIndent()
|
||||
val bf = BuildFile(listOf("com.beust.kobalt.plugin.packaging.*"), install)
|
||||
val testFileContent = "This should be in the file\n"
|
||||
val cContent = "Nested file\n"
|
||||
val files = listOf(ProjectFile("testFile", testFileContent),
|
||||
ProjectFile("a/b/c", cContent))
|
||||
val result = launchProject(ProjectInfo(bf, files), arrayOf("install"))
|
||||
|
||||
assertFile(result, "installed/testFile", testFileContent)
|
||||
assertFile(result, "deployed2/b/c", cContent)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue