@@ -422,135 +422,6 @@ internal class KotlinBuildScriptDependenciesRewriterTest {
422422 )
423423 }
424424
425- @Nested
426- inner class TestFixtures {
427- @Test fun `test fixtures of different dependency` () {
428- // Given
429- val sourceFile = dir.resolve(" build.gradle.kts" )
430- sourceFile.writeText(
431- """
432- dependencies {
433- implementation("heart:of-gold:1.+")
434- implementation(testFixtures(project(":foo")))
435- }
436- """ .trimIndent()
437- )
438-
439- // When
440- val parser = KotlinBuildScriptDependenciesRewriter .of(
441- sourceFile,
442- emptySet(),
443- AdvicePrinter (
444- dslKind = DslKind .KOTLIN ,
445- projectType = projectType,
446- useTypesafeProjectAccessors = false ,
447- ),
448- )
449-
450- // Then
451- assertThat(parser.rewritten().trimmedLines()).containsExactlyElementsIn(
452- """
453- dependencies {
454- implementation("heart:of-gold:1.+")
455- implementation(testFixtures(project(":foo")))
456- }
457- """ .trimIndent().trimmedLines()
458- ).inOrder()
459- }
460-
461- @Test fun `advice to change main visibility, with testFixtures dep on same project` () {
462- // Given
463- val sourceFile = dir.resolve(" build.gradle.kts" )
464- sourceFile.writeText(
465- """
466- dependencies {
467- implementation(project(":producer"))
468- implementation(testFixtures(project(":producer")))
469- }
470- """ .trimIndent()
471- )
472- val advice = Advice .ofChange(
473- coordinates = ProjectCoordinates (" :producer" , GradleVariantIdentification .EMPTY ),
474- fromConfiguration = " implementation" ,
475- toConfiguration = " api" ,
476- ).intoSet()
477-
478- // When
479- val parser = KotlinBuildScriptDependenciesRewriter .of(
480- file = sourceFile,
481- advice = advice,
482- advicePrinter = AdvicePrinter (
483- dslKind = DslKind .KOTLIN ,
484- projectType = projectType,
485- useTypesafeProjectAccessors = false ,
486- ),
487- )
488-
489- // Then
490- assertThat(parser.rewritten()).isEqualTo(
491- """
492- dependencies {
493- api(project(":producer"))
494- implementation(testFixtures(project(":producer")))
495- }
496- """ .trimIndent()
497- )
498- }
499-
500- @Test fun `advice to change main and testFixtures visibility, with deps on same project` () {
501- // Given
502- val sourceFile = dir.resolve(" build.gradle.kts" )
503- sourceFile.writeText(
504- """
505- dependencies {
506- implementation(project(":producer"))
507- api(testFixtures(project(":producer")))
508- }
509- """ .trimIndent()
510- )
511- val advice = setOf (
512- // Advice for main variant
513- Advice .ofChange(
514- coordinates = ProjectCoordinates (" :producer" , GradleVariantIdentification .EMPTY ),
515- fromConfiguration = " implementation" ,
516- toConfiguration = " api" ,
517- ),
518- // Advice for test-fixtures variant
519- Advice .ofChange(
520- coordinates = ProjectCoordinates (
521- " :producer" , GradleVariantIdentification (
522- capabilities = setOf (" :producer${GradleVariantIdentification .TEST_FIXTURES } " ),
523- attributes = emptyMap(),
524- )
525- ),
526- fromConfiguration = " api" ,
527- toConfiguration = " implementation" ,
528- )
529- )
530-
531- // When
532- val parser = KotlinBuildScriptDependenciesRewriter .of(
533- file = sourceFile,
534- advice = advice,
535- advicePrinter = AdvicePrinter (
536- dslKind = DslKind .KOTLIN ,
537- projectType = projectType,
538- useTypesafeProjectAccessors = false ,
539- ),
540- )
541-
542- // Then
543- assertThat(parser.rewritten()).isEqualTo(
544- """
545- dependencies {
546- api(project(":producer"))
547- implementation(testFixtures(project(":producer")))
548- }
549- """ .trimIndent()
550- )
551- }
552- }
553-
554425 @Test fun `can add dependencies to build script that didn't have a dependencies block` () {
555426 // Given
556427 val sourceFile = dir.resolve(" build.gradle.kts" )
@@ -816,6 +687,135 @@ internal class KotlinBuildScriptDependenciesRewriterTest {
816687 ).inOrder()
817688 }
818689
690+ @Nested
691+ inner class TestFixtures {
692+ @Test fun `test fixtures of different dependency` () {
693+ // Given
694+ val sourceFile = dir.resolve(" build.gradle.kts" )
695+ sourceFile.writeText(
696+ """
697+ dependencies {
698+ implementation("heart:of-gold:1.+")
699+ implementation(testFixtures(project(":foo")))
700+ }
701+ """ .trimIndent()
702+ )
703+
704+ // When
705+ val parser = KotlinBuildScriptDependenciesRewriter .of(
706+ sourceFile,
707+ emptySet(),
708+ AdvicePrinter (
709+ dslKind = DslKind .KOTLIN ,
710+ projectType = projectType,
711+ useTypesafeProjectAccessors = false ,
712+ ),
713+ )
714+
715+ // Then
716+ assertThat(parser.rewritten().trimmedLines()).containsExactlyElementsIn(
717+ """
718+ dependencies {
719+ implementation("heart:of-gold:1.+")
720+ implementation(testFixtures(project(":foo")))
721+ }
722+ """ .trimIndent().trimmedLines()
723+ ).inOrder()
724+ }
725+
726+ @Test fun `advice to change main visibility, with testFixtures dep on same project` () {
727+ // Given
728+ val sourceFile = dir.resolve(" build.gradle.kts" )
729+ sourceFile.writeText(
730+ """
731+ dependencies {
732+ implementation(project(":producer"))
733+ implementation(testFixtures(project(":producer")))
734+ }
735+ """ .trimIndent()
736+ )
737+ val advice = Advice .ofChange(
738+ coordinates = ProjectCoordinates (" :producer" , GradleVariantIdentification .EMPTY ),
739+ fromConfiguration = " implementation" ,
740+ toConfiguration = " api" ,
741+ ).intoSet()
742+
743+ // When
744+ val parser = KotlinBuildScriptDependenciesRewriter .of(
745+ file = sourceFile,
746+ advice = advice,
747+ advicePrinter = AdvicePrinter (
748+ dslKind = DslKind .KOTLIN ,
749+ projectType = projectType,
750+ useTypesafeProjectAccessors = false ,
751+ ),
752+ )
753+
754+ // Then
755+ assertThat(parser.rewritten()).isEqualTo(
756+ """
757+ dependencies {
758+ api(project(":producer"))
759+ implementation(testFixtures(project(":producer")))
760+ }
761+ """ .trimIndent()
762+ )
763+ }
764+
765+ @Test fun `advice to change main and testFixtures visibility, with deps on same project` () {
766+ // Given
767+ val sourceFile = dir.resolve(" build.gradle.kts" )
768+ sourceFile.writeText(
769+ """
770+ dependencies {
771+ implementation(project(":producer"))
772+ api(testFixtures(project(":producer")))
773+ }
774+ """ .trimIndent()
775+ )
776+ val advice = setOf (
777+ // Advice for main variant
778+ Advice .ofChange(
779+ coordinates = ProjectCoordinates (" :producer" , GradleVariantIdentification .EMPTY ),
780+ fromConfiguration = " implementation" ,
781+ toConfiguration = " api" ,
782+ ),
783+ // Advice for test-fixtures variant
784+ Advice .ofChange(
785+ coordinates = ProjectCoordinates (
786+ " :producer" , GradleVariantIdentification (
787+ capabilities = setOf (" :producer${GradleVariantIdentification .TEST_FIXTURES } " ),
788+ attributes = emptyMap(),
789+ )
790+ ),
791+ fromConfiguration = " api" ,
792+ toConfiguration = " implementation" ,
793+ )
794+ )
795+
796+ // When
797+ val parser = KotlinBuildScriptDependenciesRewriter .of(
798+ file = sourceFile,
799+ advice = advice,
800+ advicePrinter = AdvicePrinter (
801+ dslKind = DslKind .KOTLIN ,
802+ projectType = projectType,
803+ useTypesafeProjectAccessors = false ,
804+ ),
805+ )
806+
807+ // Then
808+ assertThat(parser.rewritten()).isEqualTo(
809+ """
810+ dependencies {
811+ api(project(":producer"))
812+ implementation(testFixtures(project(":producer")))
813+ }
814+ """ .trimIndent()
815+ )
816+ }
817+ }
818+
819819 private fun Path.writeText (text : String ): Path = Files .writeString(this , text)
820820 private fun String.trimmedLines () = lines().map { it.trimEnd() }
821821}
0 commit comments