mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Tests for KobaltContext#fileFor.
This commit is contained in:
parent
ff2795946b
commit
19eb7c9aeb
3 changed files with 63 additions and 5 deletions
|
@ -1,15 +1,25 @@
|
||||||
package com.beust.kobalt
|
package com.beust.kobalt
|
||||||
|
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
|
import com.beust.kobalt.api.KobaltContext
|
||||||
import com.beust.kobalt.app.BuildFileCompiler
|
import com.beust.kobalt.app.BuildFileCompiler
|
||||||
import com.beust.kobalt.internal.JvmCompilerPlugin
|
import com.beust.kobalt.internal.JvmCompilerPlugin
|
||||||
import com.beust.kobalt.internal.KobaltPluginXml
|
import com.beust.kobalt.internal.KobaltPluginXml
|
||||||
import com.beust.kobalt.internal.PluginInfo
|
import com.beust.kobalt.internal.PluginInfo
|
||||||
import com.beust.kobalt.internal.build.BuildFile
|
import com.beust.kobalt.internal.build.BuildFile
|
||||||
|
import com.beust.kobalt.maven.aether.KobaltAether
|
||||||
|
import org.testng.annotations.BeforeSuite
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
|
|
||||||
interface BaseTest {
|
open class BaseTest(open val aether: KobaltAether) {
|
||||||
|
val context = KobaltContext(Args())
|
||||||
|
|
||||||
|
@BeforeSuite
|
||||||
|
fun bs() {
|
||||||
|
context.aether = aether
|
||||||
|
}
|
||||||
|
|
||||||
fun compileBuildFile(buildFileText: String, args: Args, compilerFactory: BuildFileCompiler.IFactory)
|
fun compileBuildFile(buildFileText: String, args: Args, compilerFactory: BuildFileCompiler.IFactory)
|
||||||
: BuildFileCompiler.FindProjectResult {
|
: BuildFileCompiler.FindProjectResult {
|
||||||
val tmpBuildFile = File.createTempFile("kobaltTest", "").apply {
|
val tmpBuildFile = File.createTempFile("kobaltTest", "").apply {
|
||||||
|
|
49
src/test/kotlin/com/beust/kobalt/ContextTest.kt
Normal file
49
src/test/kotlin/com/beust/kobalt/ContextTest.kt
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
package com.beust.kobalt
|
||||||
|
|
||||||
|
import com.beust.kobalt.api.KobaltContext
|
||||||
|
import com.beust.kobalt.maven.aether.KobaltAether
|
||||||
|
import com.google.inject.Inject
|
||||||
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
|
import org.testng.annotations.DataProvider
|
||||||
|
import org.testng.annotations.Guice
|
||||||
|
import org.testng.annotations.Test
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
@Guice(modules = arrayOf(TestModule::class))
|
||||||
|
class ContextTest @Inject constructor(override val aether: KobaltAether): BaseTest(aether) {
|
||||||
|
|
||||||
|
val GROUP = "org.testng"
|
||||||
|
val ARTIFACT = "testng"
|
||||||
|
val VERSION = "6.9.11"
|
||||||
|
val REPO_PATH = TEST_KOBALT_SETTINGS.localCache
|
||||||
|
val id = "$GROUP:$ARTIFACT:$VERSION"
|
||||||
|
|
||||||
|
@DataProvider
|
||||||
|
fun dp() : Array<Array<out Any?>> {
|
||||||
|
return arrayOf(
|
||||||
|
arrayOf(KobaltContext.FileType.JAR, ARTIFACT + "-" + VERSION + ".jar"),
|
||||||
|
arrayOf(KobaltContext.FileType.POM, ARTIFACT + "-" + VERSION + ".pom"),
|
||||||
|
arrayOf(KobaltContext.FileType.JAVADOC, ARTIFACT + "-" + VERSION + "-javadoc.jar"),
|
||||||
|
arrayOf(KobaltContext.FileType.SOURCES, ARTIFACT + "-" + VERSION + "-sources.jar")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun normalize(path: String) = path.replace('.', File.separatorChar)
|
||||||
|
|
||||||
|
@Test(dataProvider = "dp")
|
||||||
|
fun fileForIdShouldWork(fileType: KobaltContext.FileType, expectedFileName: String) {
|
||||||
|
val expected = listOf(REPO_PATH, normalize(GROUP), ARTIFACT, VERSION,
|
||||||
|
ARTIFACT + "-" + VERSION + ".jar").joinToString(File.separator)
|
||||||
|
val file = context.fileFor(id, KobaltContext.FileType.JAR)
|
||||||
|
assertThat(file.absolutePath).isEqualTo(expected)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun fileForIdOther() {
|
||||||
|
val expected = listOf(REPO_PATH, "io/reactivex/rxandroid/1.0.1/rxandroid-1.0.1.aar")
|
||||||
|
.joinToString(File.separator)
|
||||||
|
val file = context.fileFor("io.reactivex:rxandroid:aar:1.0.1", KobaltContext.FileType.OTHER)
|
||||||
|
assertThat(file.absolutePath).isEqualTo(expected)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,16 +6,15 @@ import com.beust.kobalt.TestModule
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.app.BuildFileCompiler
|
import com.beust.kobalt.app.BuildFileCompiler
|
||||||
|
import com.beust.kobalt.maven.aether.KobaltAether
|
||||||
import com.google.inject.Inject
|
import com.google.inject.Inject
|
||||||
import org.assertj.core.api.Assertions.assertThat
|
import org.assertj.core.api.Assertions.assertThat
|
||||||
import org.testng.annotations.Guice
|
import org.testng.annotations.Guice
|
||||||
import org.testng.annotations.Test
|
import org.testng.annotations.Test
|
||||||
|
|
||||||
@Guice(modules = arrayOf(TestModule::class))
|
@Guice(modules = arrayOf(TestModule::class))
|
||||||
class ProfileTest @Inject constructor(val compilerFactory: BuildFileCompiler.IFactory
|
class ProfileTest @Inject constructor(val compilerFactory: BuildFileCompiler.IFactory,
|
||||||
// val jvmCompilerPlugin: JvmCompilerPlugin
|
override val aether: KobaltAether): BaseTest(aether) {
|
||||||
// val buildScriptUtil: BuildScriptUtil
|
|
||||||
) : BaseTest {
|
|
||||||
private fun runTestWithProfile(enabled: Boolean) : Project {
|
private fun runTestWithProfile(enabled: Boolean) : Project {
|
||||||
val buildFileString = """
|
val buildFileString = """
|
||||||
| import com.beust.kobalt.*
|
| import com.beust.kobalt.*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue