Skip to content

Commit 529e11a

Browse files
committed
Add test to check that only dependencies on expected configuration are removed
1 parent e7de4c8 commit 529e11a

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

src/test/kotlin/com/autonomousapps/internal/parse/KotlinBuildScriptDependenciesRewriterTest.kt

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,87 @@ internal class KotlinBuildScriptDependenciesRewriterTest {
404404
)
405405
}
406406

407+
@Test fun `only removes dependencies on expected configuration`() {
408+
// Given
409+
val sourceFile = dir.resolve("build.gradle.kts")
410+
sourceFile.writeText(
411+
"""
412+
plugins {
413+
id("foo")
414+
}
415+
416+
repositories {
417+
google()
418+
mavenCentral()
419+
}
420+
421+
apply(plugin = "bar")
422+
423+
extra["magic"] = 42
424+
425+
android {
426+
whatever
427+
}
428+
429+
dependencies {
430+
implementation("heart:of-gold:1.+")
431+
api(project(":marvin"))
432+
testImplementation("pan-galactic:gargle-blaster:2.0-SNAPSHOT") {
433+
because("life's too short not to")
434+
}
435+
}
436+
437+
println("hello, world!")
438+
""".trimIndent()
439+
)
440+
val advice = setOf(
441+
Advice.ofChange(Coordinates.of(":marvin"), "api", "compileOnly"),
442+
Advice.ofRemove(Coordinates.of("pan-galactic:gargle-blaster:2.0-SNAPSHOT"), "implementation"),
443+
Advice.ofAdd(Coordinates.of(":sad-robot"), "runtimeOnly"),
444+
)
445+
446+
// When
447+
val parser = KotlinBuildScriptDependenciesRewriter.of(
448+
sourceFile,
449+
advice,
450+
AdvicePrinter(DslKind.KOTLIN),
451+
)
452+
453+
println(parser.rewritten().trimmedLines())
454+
// Then
455+
assertThat(parser.rewritten().trimmedLines()).containsExactlyElementsIn(
456+
"""
457+
plugins {
458+
id("foo")
459+
}
460+
461+
repositories {
462+
google()
463+
mavenCentral()
464+
}
465+
466+
apply(plugin = "bar")
467+
468+
extra["magic"] = 42
469+
470+
android {
471+
whatever
472+
}
473+
474+
dependencies {
475+
implementation("heart:of-gold:1.+")
476+
compileOnly(project(":marvin"))
477+
runtimeOnly(project(":sad-robot"))
478+
testImplementation("pan-galactic:gargle-blaster:2.0-SNAPSHOT") {
479+
because("life's too short not to")
480+
}
481+
}
482+
483+
println("hello, world!")
484+
""".trimIndent().trimmedLines()
485+
)
486+
}
487+
407488
private fun Path.writeText(text: String): Path = Files.writeString(this, text)
408489
private fun String.trimmedLines() = lines().map { it.trimEnd() }
409490
}

0 commit comments

Comments
 (0)