Skip to content

Commit 0ab2a67

Browse files
committed
Issue #2906: Misleading warning when two deps reference the same val version
1 parent 96303ba commit 0ab2a67

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

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

+47
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.scalasteward.core.TestSyntax._
77
import org.scalasteward.core.data.{RepoData, Update}
88
import org.scalasteward.core.mock.MockContext.context._
99
import org.scalasteward.core.mock.MockState
10+
import org.scalasteward.core.mock.MockState.TraceEntry
1011
import org.scalasteward.core.repoconfig.RepoConfig
1112
import org.scalasteward.core.scalafmt.scalafmtConfName
1213
import org.scalasteward.core.util.Nel
@@ -911,6 +912,46 @@ class RewriteTest extends FunSuite {
911912
runApplyUpdate(update, original, expected)
912913
}
913914

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
922+
val original = Map(
923+
"build.sbt" ->
924+
"""
925+
|val FooLibraryVersion = "1.2.3"
926+
|libraryDependencies ++= Seq(
927+
| "com.foo" %% "library-1" % FooLibraryVersion,
928+
| "com.foo" %% "library-2" % FooLibraryVersion
929+
|)
930+
|""".stripMargin
931+
)
932+
val expected = Map(
933+
"build.sbt" ->
934+
"""
935+
|val FooLibraryVersion = "1.3.0"
936+
|libraryDependencies ++= Seq(
937+
| "com.foo" %% "library-1" % FooLibraryVersion,
938+
| "com.foo" %% "library-2" % FooLibraryVersion
939+
|)
940+
|""".stripMargin
941+
)
942+
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+
}
954+
914955
private def runApplyUpdate(
915956
update: Update.Single,
916957
files: Map[String, String],
@@ -924,6 +965,12 @@ class RewriteTest extends FunSuite {
924965
.addFiles(filesInRepoDir.toSeq: _*)
925966
.flatMap(editAlg.applyUpdate(data, update).runS)
926967
.unsafeRunSync()
968+
terribleMutableLogBufferDoNotMergeThis.clear()
969+
state.trace.foreach {
970+
case l: TraceEntry.Log =>
971+
terribleMutableLogBufferDoNotMergeThis += l.log._2
972+
case _ => ()
973+
}
927974
val obtained = state.files
928975
.map { case (file, content) => file.toString.replace(repoDir.toString + "/", "") -> content }
929976
assertEquals(obtained, expected)

0 commit comments

Comments
 (0)