Skip to content

Commit 5bb0ecc

Browse files
committed
WIP
1 parent 39b618f commit 5bb0ecc

File tree

2 files changed

+62
-26
lines changed

2 files changed

+62
-26
lines changed

modules/core/src/main/scala/org/scalasteward/core/nurture/NurtureAlg.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ final class NurtureAlg[F[_]](config: VCSCfg)(implicit
162162
gitAlg.returnToCurrentBranch(data.repo) {
163163
val createBranch = logger.info(s"Create branch ${data.updateBranch.name}") >>
164164
gitAlg.createBranch(data.repo, data.updateBranch)
165+
println("applyNewUpdate")
166+
println(s" data.update = ${data.update}")
165167
data.update
166168
.on(
167169
update = editAlg.applyUpdate(data.repoData, _, createBranch),
@@ -296,6 +298,8 @@ final class NurtureAlg[F[_]](config: VCSCfg)(implicit
296298
)
297299
maybeRevertCommit <- gitAlg.revertChanges(data.repo, data.baseBranch)
298300
maybeMergeCommit <- gitAlg.mergeTheirs(data.repo, data.baseBranch)
301+
_ = println("mergeAndApplyAgain")
302+
_ = println(s" data.update = ${data.update}")
299303
edits <- data.update.on(
300304
update = editAlg.applyUpdate(data.repoData, _),
301305
grouped = _.updates.flatTraverse(editAlg.applyUpdate(data.repoData, _))

modules/core/src/test/scala/org/scalasteward/core/edit/RewriteTest.scala

Lines changed: 58 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package org.scalasteward.core.edit
22

3+
import cats.data.NonEmptyList
34
import cats.effect.unsafe.implicits.global
45
import munit.FunSuite
56
import org.scalasteward.core.TestInstances.dummyRepoCache
67
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}
810
import org.scalasteward.core.mock.MockContext.context._
911
import org.scalasteward.core.mock.MockState
1012
import org.scalasteward.core.mock.MockState.TraceEntry
@@ -912,13 +914,7 @@ class RewriteTest extends FunSuite {
912914
runApplyUpdate(update, original, expected)
913915
}
914916

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") {
922918
val original = Map(
923919
"build.sbt" ->
924920
"""
@@ -940,23 +936,64 @@ class RewriteTest extends FunSuite {
940936
|""".stripMargin
941937
)
942938

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+
// }
954991

955992
private def runApplyUpdate(
956993
update: Update.Single,
957994
files: Map[String, String],
958995
expected: Map[String, String]
959-
): Unit = {
996+
): Vector[TraceEntry] = {
960997
val repo = Repo("edit-alg", s"runApplyUpdate-${nextInt()}")
961998
val data = RepoData(repo, dummyRepoCache, RepoConfig.empty)
962999
val repoDir = workspaceAlg.repoDir(repo).unsafeRunSync()
@@ -965,15 +1002,10 @@ class RewriteTest extends FunSuite {
9651002
.addFiles(filesInRepoDir.toSeq: _*)
9661003
.flatMap(editAlg.applyUpdate(data, update).runS)
9671004
.unsafeRunSync()
968-
terribleMutableLogBufferDoNotMergeThis.clear()
969-
state.trace.foreach {
970-
case l: TraceEntry.Log =>
971-
terribleMutableLogBufferDoNotMergeThis += l.log._2
972-
case _ => ()
973-
}
9741005
val obtained = state.files
9751006
.map { case (file, content) => file.toString.replace(repoDir.toString + "/", "") -> content }
9761007
assertEquals(obtained, expected)
1008+
state.trace
9771009
}
9781010

9791011
private var counter = 0

0 commit comments

Comments
 (0)