1
1
package org .scalasteward .core .edit
2
2
3
+ import cats .data .NonEmptyList
3
4
import cats .effect .unsafe .implicits .global
4
5
import munit .FunSuite
5
6
import org .scalasteward .core .TestInstances .dummyRepoCache
6
7
import org .scalasteward .core .TestSyntax ._
7
- import org .scalasteward .core .data .{RepoData , Update }
8
+ import org .scalasteward .core .data .Update .ForArtifactId
9
+ import org .scalasteward .core .data .{ArtifactId , CrossDependency , Dependency , GroupId , RepoData , Update , Version }
8
10
import org .scalasteward .core .mock .MockContext .context ._
9
11
import org .scalasteward .core .mock .MockState
10
12
import org .scalasteward .core .mock .MockState .TraceEntry
@@ -912,13 +914,7 @@ class RewriteTest extends FunSuite {
912
914
runApplyUpdate(update, original, expected)
913
915
}
914
916
915
- // Sketchy placeholder bI'm not sure how else to assert on the presence/absence of a log.
916
- private val terribleMutableLogBufferDoNotMergeThis =
917
- scala.collection.mutable.ListBuffer .empty[String ]
918
-
919
- test(" issue ..." ) {
920
- val update1 = (" com.foo" .g % " library-1" .a % " 1.2.3" %> " 1.3.0" ).single
921
- val update2 = (" com.foo" .g % " library-2" .a % " 1.2.3" %> " 1.3.0" ).single
917
+ test(" issue 2906" ) {
922
918
val original = Map (
923
919
" build.sbt" ->
924
920
"""
@@ -940,23 +936,64 @@ class RewriteTest extends FunSuite {
940
936
|""" .stripMargin
941
937
)
942
938
943
- runApplyUpdate(update1, original, expected)
944
- require(
945
- ! terribleMutableLogBufferDoNotMergeThis.exists(_.startsWith(" Unable to bump version" ))
946
- )
947
-
948
- // The second update prints a misleading warning.
949
- runApplyUpdate(update2, expected, expected)
950
- require(
951
- terribleMutableLogBufferDoNotMergeThis.last == " Unable to bump version for update com.foo:library-2 : 1.2.3 -> 1.3.0"
952
- )
953
- }
939
+ val update = ForArtifactId (
940
+ crossDependency = CrossDependency (
941
+ dependencies =
942
+ NonEmptyList (Dependency (GroupId (" com.foo" ), ArtifactId (" library-1" ), Version (" 1.2.3" )), List .empty)
943
+ ),
944
+ newerVersions = NonEmptyList (Version (" 1.3.0" ), List .empty))
945
+
946
+ val trace = runApplyUpdate(update, original, expected)
947
+ trace.foreach(println)
948
+ }
949
+
950
+ // test("issue ...") {
951
+ // val update1: Update.ForArtifactId = ("com.foo".g % "library-1".a % "1.2.3" %> "1.3.0").single
952
+ // val update2: Update.ForArtifactId = ("com.foo".g % "library-2".a % "1.2.3" %> "1.3.0").single
953
+ // val update3 = Update.ForGroupId(NonEmptyList(update1, List(update2)))
954
+ // val original = Map(
955
+ // "build.sbt" ->
956
+ // """
957
+ // |val FooLibraryVersion = "1.2.3"
958
+ // |libraryDependencies ++= Seq(
959
+ // | "com.foo" %% "library-1" % FooLibraryVersion,
960
+ // | "com.foo" %% "library-2" % FooLibraryVersion
961
+ // |)
962
+ // |""".stripMargin
963
+ // )
964
+ // val expected = Map(
965
+ // "build.sbt" ->
966
+ // """
967
+ // |val FooLibraryVersion = "1.3.0"
968
+ // |libraryDependencies ++= Seq(
969
+ // | "com.foo" %% "library-1" % FooLibraryVersion,
970
+ // | "com.foo" %% "library-2" % FooLibraryVersion
971
+ // |)
972
+ // |""".stripMargin
973
+ // )
974
+ //
975
+ // println("update1")
976
+ // runApplyUpdate(update1, original, expected)
977
+ // require(
978
+ // !terribleMutableLogBufferDoNotMergeThis.exists(_.startsWith("Unable to bump version"))
979
+ // )
980
+ //
981
+ // // The second update prints a misleading warning.
982
+ // println("update2")
983
+ // runApplyUpdate(update2, expected, expected)
984
+ // require(
985
+ // terribleMutableLogBufferDoNotMergeThis.last == "Unable to bump version for update com.foo:library-2 : 1.2.3 -> 1.3.0"
986
+ // )
987
+ //
988
+ // println("update3")
989
+ // runApplyUpdate(update3, original, expected)
990
+ // }
954
991
955
992
private def runApplyUpdate (
956
993
update : Update .Single ,
957
994
files : Map [String , String ],
958
995
expected : Map [String , String ]
959
- ): Unit = {
996
+ ): Vector [ TraceEntry ] = {
960
997
val repo = Repo (" edit-alg" , s " runApplyUpdate- ${nextInt()}" )
961
998
val data = RepoData (repo, dummyRepoCache, RepoConfig .empty)
962
999
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
@@ -965,15 +1002,10 @@ class RewriteTest extends FunSuite {
965
1002
.addFiles(filesInRepoDir.toSeq: _* )
966
1003
.flatMap(editAlg.applyUpdate(data, update).runS)
967
1004
.unsafeRunSync()
968
- terribleMutableLogBufferDoNotMergeThis.clear()
969
- state.trace.foreach {
970
- case l : TraceEntry .Log =>
971
- terribleMutableLogBufferDoNotMergeThis += l.log._2
972
- case _ => ()
973
- }
974
1005
val obtained = state.files
975
1006
.map { case (file, content) => file.toString.replace(repoDir.toString + " /" , " " ) -> content }
976
1007
assertEquals(obtained, expected)
1008
+ state.trace
977
1009
}
978
1010
979
1011
private var counter = 0
0 commit comments