Add more tests to the maven resolver lib
This commit is contained in:
+1
-1
@@ -48,7 +48,7 @@ class MavenDependenciesResolver : ExternalDependenciesResolver {
|
||||
private fun allRepositories() = remoteRepositories() + localRepo
|
||||
|
||||
private fun String.toMavenArtifact(): DefaultArtifact? =
|
||||
if (this.isNotBlank() && this.count { it == ':' } == 2) DefaultArtifact(this)
|
||||
if (this.isNotBlank() && this.count { it == ':' } >= 2) DefaultArtifact(this)
|
||||
else null
|
||||
|
||||
override suspend fun resolve(artifactCoordinates: String): ResultWithDiagnostics<List<File>> {
|
||||
|
||||
+25
-3
@@ -7,6 +7,7 @@ package kotlin.script.experimental.test
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert
|
||||
import java.io.File
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.script.experimental.dependencies.maven.MavenDependenciesResolver
|
||||
import kotlin.script.experimental.api.ResultWithDiagnostics
|
||||
@@ -15,11 +16,32 @@ import kotlin.script.experimental.api.valueOrThrow
|
||||
@ExperimentalContracts
|
||||
class MavenResolverTest : ResolversTestBase() {
|
||||
|
||||
fun testResolve() {
|
||||
fun resolveAndCheck(coordinates: String, checkBody: (Iterable<File>) -> Boolean = { true } ) {
|
||||
val resolver = MavenDependenciesResolver()
|
||||
val result = runBlocking { resolver.resolve("org.jetbrains.kotlin:kotlin-annotations-jvm:1.3.50") }
|
||||
Assert.assertTrue(result is ResultWithDiagnostics.Success)
|
||||
val result = runBlocking { resolver.resolve(coordinates) }
|
||||
if (result is ResultWithDiagnostics.Failure) {
|
||||
Assert.fail(result.reports.joinToString("\n") { it.exception?.toString() ?: it.message })
|
||||
}
|
||||
val files = result.valueOrThrow()
|
||||
if (!checkBody(files)) {
|
||||
Assert.fail("Unexpected resolving results:\n ${files.joinToString("\n ")}")
|
||||
}
|
||||
files.forEach { it.delete() }
|
||||
}
|
||||
|
||||
fun testResolveSimple() {
|
||||
resolveAndCheck("org.jetbrains.kotlin:kotlin-annotations-jvm:1.3.50") { files ->
|
||||
files.any { it.name.startsWith("kotlin-annotations-jvm") }
|
||||
}
|
||||
}
|
||||
|
||||
fun testResolveVersionsRange() {
|
||||
resolveAndCheck("org.jetbrains.kotlin:kotlin-annotations-jvm:(1.3.40,1.3.60)")
|
||||
}
|
||||
|
||||
fun testResolveDifferentType() {
|
||||
resolveAndCheck("org.javamoney:moneta:pom:1.3") { files ->
|
||||
files.any { it.extension == "pom" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user