Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge MockState#{commands, logs} to MockState#trace #1954

Merged
merged 1 commit into from
Feb 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.scalasteward.core.data.{Resolver, Scope, Version}
import org.scalasteward.core.mock.MockContext.config
import org.scalasteward.core.mock.MockContext.context.buildToolDispatcher
import org.scalasteward.core.mock.MockState
import org.scalasteward.core.mock.MockState.TraceEntry.Cmd
import org.scalasteward.core.scalafmt
import org.scalasteward.core.vcs.data.Repo

Expand All @@ -22,14 +23,14 @@ class BuildToolDispatcherTest extends FunSuite {
val (state, deps) =
buildToolDispatcher.getDependencies(repo).run(initial).unsafeRunSync()

val expectedState = initial.copy(commands =
val expectedState = initial.copy(trace =
Vector(
List("read", s"$repoDir/.scala-steward.conf"),
List("read", s"/tmp/default.scala-steward.conf"),
List("test", "-f", s"$repoDir/pom.xml"),
List("test", "-f", s"$repoDir/build.sc"),
List("test", "-f", s"$repoDir/build.sbt"),
List(
Cmd("read", s"$repoDir/.scala-steward.conf"),
Cmd("read", s"/tmp/default.scala-steward.conf"),
Cmd("test", "-f", s"$repoDir/pom.xml"),
Cmd("test", "-f", s"$repoDir/build.sc"),
Cmd("test", "-f", s"$repoDir/build.sbt"),
Cmd(
repoDir.toString,
"firejail",
"--quiet",
Expand All @@ -42,8 +43,8 @@ class BuildToolDispatcherTest extends FunSuite {
"-Dsbt.supershell=false",
s";$crossStewardDependencies;$reloadPlugins;$stewardDependencies"
),
List("read", s"$repoDir/project/build.properties"),
List("read", s"$repoDir/.scalafmt.conf")
Cmd("read", s"$repoDir/project/build.properties"),
Cmd("read", s"$repoDir/.scalafmt.conf")
)
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,22 @@
package org.scalasteward.core.buildtool.maven

import better.files.File
import munit.FunSuite
import org.scalasteward.core.mock.MockContext._
import org.scalasteward.core.mock.MockContext.context.mavenAlg
import org.scalasteward.core.mock.MockState
import org.scalasteward.core.mock.MockState.TraceEntry.Cmd
import org.scalasteward.core.vcs.data.{BuildRoot, Repo}

class MavenAlgTest extends FunSuite {
test("getDependencies") {
val repo = Repo("namespace", "repo-name")
val buildRoot = BuildRoot(repo, ".")
val repoDir = config.workspace / repo.show
val files: Map[File, String] = Map.empty

val state =
mavenAlg.getDependencies(buildRoot).runS(MockState.empty.copy(files = files)).unsafeRunSync()

val state = mavenAlg.getDependencies(buildRoot).runS(MockState.empty).unsafeRunSync()
val expected = MockState.empty.copy(
files = files,
logs = Vector.empty,
commands = Vector(
List(
trace = Vector(
Cmd(
repoDir.toString,
"firejail",
"--quiet",
Expand All @@ -32,7 +27,7 @@ class MavenAlgTest extends FunSuite {
"--batch-mode",
command.listDependencies
),
List(
Cmd(
repoDir.toString,
"firejail",
"--quiet",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import org.scalasteward.core.buildtool.mill.MillAlg.extractDeps
import org.scalasteward.core.mock.MockContext.config
import org.scalasteward.core.mock.MockContext.context.millAlg
import org.scalasteward.core.mock.MockState
import org.scalasteward.core.mock.MockState.TraceEntry.Cmd
import org.scalasteward.core.vcs.data.{BuildRoot, Repo}

class MillAlgTest extends FunSuite {
Expand All @@ -29,10 +30,10 @@ class MillAlgTest extends FunSuite {
val initial = MockState.empty.copy(commandOutputs = Map(millCmd -> List("""{"modules":[]}""")))
val state = millAlg.getDependencies(buildRoot).runS(initial).unsafeRunSync()
val expected = initial.copy(
commands = Vector(
List("write", predef),
repoDir.toString :: millCmd,
List("rm", "-rf", predef)
trace = Vector(
Cmd("write", predef),
Cmd(repoDir.toString :: millCmd),
Cmd("rm", "-rf", predef)
)
)
assertEquals(state, expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.scalasteward.core.data.{GroupId, Version}
import org.scalasteward.core.mock.MockContext.context.sbtAlg
import org.scalasteward.core.mock.MockContext.config
import org.scalasteward.core.mock.MockState
import org.scalasteward.core.mock.MockState.TraceEntry.{Cmd, Log}
import org.scalasteward.core.scalafix.Migration
import org.scalasteward.core.util.Nel
import org.scalasteward.core.vcs.data.{BuildRoot, Repo}
Expand All @@ -18,16 +19,15 @@ class SbtAlgTest extends FunSuite {
.runS(MockState.empty)
.unsafeRunSync()
val expected = MockState.empty.copy(
commands = Vector(
List("read", "classpath:org/scalasteward/sbt/plugin/StewardPlugin.scala"),
List("write", "/tmp/steward/.sbt/0.13/plugins/StewardPlugin.scala"),
List("write", "/tmp/steward/.sbt/1.0/plugins/StewardPlugin.scala"),
List("fa"),
List("rm", "-rf", "/tmp/steward/.sbt/1.0/plugins/StewardPlugin.scala"),
List("rm", "-rf", "/tmp/steward/.sbt/0.13/plugins/StewardPlugin.scala")
),
logs = Vector((None, "Add global sbt plugins")),
files = Map.empty
trace = Vector(
Log("Add global sbt plugins"),
Cmd("read", "classpath:org/scalasteward/sbt/plugin/StewardPlugin.scala"),
Cmd("write", "/tmp/steward/.sbt/0.13/plugins/StewardPlugin.scala"),
Cmd("write", "/tmp/steward/.sbt/1.0/plugins/StewardPlugin.scala"),
Cmd("fa"),
Cmd("rm", "-rf", "/tmp/steward/.sbt/1.0/plugins/StewardPlugin.scala"),
Cmd("rm", "-rf", "/tmp/steward/.sbt/0.13/plugins/StewardPlugin.scala")
)
)
assertEquals(obtained, expected)
}
Expand All @@ -40,8 +40,8 @@ class SbtAlgTest extends FunSuite {
val initial = MockState.empty.copy(files = files)
val state = sbtAlg.getDependencies(buildRoot).runS(initial).unsafeRunSync()
val expected = initial.copy(
commands = Vector(
List(
trace = Vector(
Cmd(
repoDir.toString,
"firejail",
"--quiet",
Expand All @@ -54,7 +54,7 @@ class SbtAlgTest extends FunSuite {
"-Dsbt.supershell=false",
s";$crossStewardDependencies;$reloadPlugins;$stewardDependencies"
),
List("read", s"$repoDir/project/build.properties")
Cmd("read", s"$repoDir/project/build.properties")
)
)
assertEquals(state, expected)
Expand All @@ -74,10 +74,10 @@ class SbtAlgTest extends FunSuite {
)
val state = sbtAlg.runMigration(buildRoot, migration).runS(MockState.empty).unsafeRunSync()
val expected = MockState.empty.copy(
commands = Vector(
List("write", "/tmp/steward/.sbt/0.13/plugins/scala-steward-scalafix.sbt"),
List("write", "/tmp/steward/.sbt/1.0/plugins/scala-steward-scalafix.sbt"),
List(
trace = Vector(
Cmd("write", "/tmp/steward/.sbt/0.13/plugins/scala-steward-scalafix.sbt"),
Cmd("write", "/tmp/steward/.sbt/1.0/plugins/scala-steward-scalafix.sbt"),
Cmd(
repoDir.toString,
"firejail",
"--quiet",
Expand All @@ -90,8 +90,8 @@ class SbtAlgTest extends FunSuite {
"-Dsbt.supershell=false",
s";$scalafixEnable;$scalafixAll github:functional-streams-for-scala/fs2/v1?sha=v1.0.5"
),
List("rm", "-rf", "/tmp/steward/.sbt/1.0/plugins/scala-steward-scalafix.sbt"),
List("rm", "-rf", "/tmp/steward/.sbt/0.13/plugins/scala-steward-scalafix.sbt")
Cmd("rm", "-rf", "/tmp/steward/.sbt/1.0/plugins/scala-steward-scalafix.sbt"),
Cmd("rm", "-rf", "/tmp/steward/.sbt/0.13/plugins/scala-steward-scalafix.sbt")
)
)
assertEquals(state, expected)
Expand All @@ -111,11 +111,11 @@ class SbtAlgTest extends FunSuite {
)
val state = sbtAlg.runMigration(buildRoot, migration).runS(MockState.empty).unsafeRunSync()
val expected = MockState.empty.copy(
commands = Vector(
List("write", "/tmp/steward/.sbt/0.13/plugins/scala-steward-scalafix.sbt"),
List("write", "/tmp/steward/.sbt/1.0/plugins/scala-steward-scalafix.sbt"),
List("write", s"$repoDir/scala-steward-scalafix-options.sbt"),
List(
trace = Vector(
Cmd("write", "/tmp/steward/.sbt/0.13/plugins/scala-steward-scalafix.sbt"),
Cmd("write", "/tmp/steward/.sbt/1.0/plugins/scala-steward-scalafix.sbt"),
Cmd("write", s"$repoDir/scala-steward-scalafix-options.sbt"),
Cmd(
repoDir.toString,
"firejail",
"--quiet",
Expand All @@ -128,9 +128,9 @@ class SbtAlgTest extends FunSuite {
"-Dsbt.supershell=false",
s";$scalafixEnable;$scalafixAll github:cb372/cats/Cats_v2_2_0?sha=235bd7c92e431ab1902db174cf4665b05e08f2f1"
),
List("rm", "-rf", s"$repoDir/scala-steward-scalafix-options.sbt"),
List("rm", "-rf", "/tmp/steward/.sbt/1.0/plugins/scala-steward-scalafix.sbt"),
List("rm", "-rf", "/tmp/steward/.sbt/0.13/plugins/scala-steward-scalafix.sbt")
Cmd("rm", "-rf", s"$repoDir/scala-steward-scalafix-options.sbt"),
Cmd("rm", "-rf", "/tmp/steward/.sbt/1.0/plugins/scala-steward-scalafix.sbt"),
Cmd("rm", "-rf", "/tmp/steward/.sbt/0.13/plugins/scala-steward-scalafix.sbt")
)
)
assertEquals(state, expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.scalasteward.core.data.{GroupId, Update}
import org.scalasteward.core.mock.MockContext.context.editAlg
import org.scalasteward.core.mock.MockContext.{config, envVars}
import org.scalasteward.core.mock.MockState
import org.scalasteward.core.mock.MockState.TraceEntry.{Cmd, Log}
import org.scalasteward.core.repoconfig.RepoConfig
import org.scalasteward.core.scalafmt.scalafmtBinary
import org.scalasteward.core.util.Nel
Expand All @@ -29,21 +30,19 @@ class EditAlgTest extends FunSuite {
.unsafeRunSync()

val expected = MockState.empty.copy(
commands = Vector(
List("test", "-f", file1.pathAsString),
List("read", file1.pathAsString),
List("test", "-f", file2.pathAsString),
List("read", file2.pathAsString),
List("read", file1.pathAsString),
List("read", file1.pathAsString),
List("read", file1.pathAsString),
List("write", file1.pathAsString),
envVars ++ (repoDir.toString :: gitStatus)
),
logs = Vector(
(None, "Trying heuristic 'moduleId'"),
(None, "Trying heuristic 'strict'"),
(None, "Trying heuristic 'original'")
trace = Vector(
Cmd("test", "-f", file1.pathAsString),
Cmd("read", file1.pathAsString),
Cmd("test", "-f", file2.pathAsString),
Cmd("read", file2.pathAsString),
Log("Trying heuristic 'moduleId'"),
Cmd("read", file1.pathAsString),
Log("Trying heuristic 'strict'"),
Cmd("read", file1.pathAsString),
Log("Trying heuristic 'original'"),
Cmd("read", file1.pathAsString),
Cmd("write", file1.pathAsString),
Cmd(envVars ++ (repoDir.toString :: gitStatus))
),
files = Map(file1 -> """val catsVersion = "1.3.0"""", file2 -> "")
)
Expand All @@ -68,33 +67,31 @@ class EditAlgTest extends FunSuite {
.unsafeRunSync()

val expected = MockState.empty.copy(
commands = Vector(
List("test", "-f", scalafmtConf.pathAsString),
List("read", scalafmtConf.pathAsString),
List("test", "-f", buildSbt.pathAsString),
List("read", scalafmtConf.pathAsString),
List("read", scalafmtConf.pathAsString),
List("read", scalafmtConf.pathAsString),
List("read", scalafmtConf.pathAsString),
List("read", scalafmtConf.pathAsString),
List("read", scalafmtConf.pathAsString),
List("read", scalafmtConf.pathAsString),
List("read", scalafmtConf.pathAsString),
List("write", scalafmtConf.pathAsString),
envVars ++ (repoDir.toString :: gitStatus),
List("VAR1=val1", "VAR2=val2", repoDir.toString, scalafmtBinary, "--non-interactive"),
envVars ++ (repoDir.toString :: gitStatus)
),
logs = Vector(
(None, "Trying heuristic 'moduleId'"),
(None, "Trying heuristic 'strict'"),
(None, "Trying heuristic 'original'"),
(None, "Trying heuristic 'relaxed'"),
(None, "Trying heuristic 'sliding'"),
(None, "Trying heuristic 'completeGroupId'"),
(None, "Trying heuristic 'groupId'"),
(None, "Trying heuristic 'specific'"),
(None, "Executing post-update hook for org.scalameta:scalafmt-core")
trace = Vector(
Cmd("test", "-f", scalafmtConf.pathAsString),
Cmd("read", scalafmtConf.pathAsString),
Cmd("test", "-f", buildSbt.pathAsString),
Log("Trying heuristic 'moduleId'"),
Cmd("read", scalafmtConf.pathAsString),
Log("Trying heuristic 'strict'"),
Cmd("read", scalafmtConf.pathAsString),
Log("Trying heuristic 'original'"),
Cmd("read", scalafmtConf.pathAsString),
Log("Trying heuristic 'relaxed'"),
Cmd("read", scalafmtConf.pathAsString),
Log("Trying heuristic 'sliding'"),
Cmd("read", scalafmtConf.pathAsString),
Log("Trying heuristic 'completeGroupId'"),
Cmd("read", scalafmtConf.pathAsString),
Log("Trying heuristic 'groupId'"),
Cmd("read", scalafmtConf.pathAsString),
Log("Trying heuristic 'specific'"),
Cmd("read", scalafmtConf.pathAsString),
Cmd("write", scalafmtConf.pathAsString),
Cmd(envVars ++ (repoDir.toString :: gitStatus)),
Log("Executing post-update hook for org.scalameta:scalafmt-core"),
Cmd("VAR1=val1", "VAR2=val2", repoDir.toString, scalafmtBinary, "--non-interactive"),
Cmd(envVars ++ (repoDir.toString :: gitStatus))
),
files = Map(
scalafmtConf ->
Expand Down Expand Up @@ -126,19 +123,17 @@ class EditAlgTest extends FunSuite {
.unsafeRunSync()

val expected = MockState.empty.copy(
commands = Vector(
List("test", "-f", file1.pathAsString),
List("read", file1.pathAsString),
List("test", "-f", file2.pathAsString),
List("read", file2.pathAsString),
List("read", file1.pathAsString),
List("write", file1.pathAsString),
List("read", file2.pathAsString),
List("write", file2.pathAsString),
envVars ++ (repoDir.toString :: gitStatus)
),
logs = Vector(
(None, "Trying heuristic 'moduleId'")
trace = Vector(
Cmd("test", "-f", file1.pathAsString),
Cmd("read", file1.pathAsString),
Cmd("test", "-f", file2.pathAsString),
Cmd("read", file2.pathAsString),
Log("Trying heuristic 'moduleId'"),
Cmd("read", file1.pathAsString),
Cmd("write", file1.pathAsString),
Cmd("read", file2.pathAsString),
Cmd("write", file2.pathAsString),
Cmd(envVars ++ (repoDir.toString :: gitStatus))
),
files = Map(
file1 -> """import $ivy.`org.typelevel::cats-core:1.3.0`, cats.implicits._"""",
Expand Down
Loading