1
0
Fork 0
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:
Cedric Beust 2016-07-25 02:40:44 -08:00
parent ff2795946b
commit 19eb7c9aeb
3 changed files with 63 additions and 5 deletions

View file

@ -1,15 +1,25 @@
package com.beust.kobalt
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.KobaltContext
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 com.beust.kobalt.maven.aether.KobaltAether
import org.testng.annotations.BeforeSuite
import java.io.File
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)
: BuildFileCompiler.FindProjectResult {
val tmpBuildFile = File.createTempFile("kobaltTest", "").apply {

View 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)
}
}

View file

@ -6,16 +6,15 @@ 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.beust.kobalt.maven.aether.KobaltAether
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 {
class ProfileTest @Inject constructor(val compilerFactory: BuildFileCompiler.IFactory,
override val aether: KobaltAether): BaseTest(aether) {
private fun runTestWithProfile(enabled: Boolean) : Project {
val buildFileString = """
| import com.beust.kobalt.*