Skip to content

Commit 68d374b

Browse files
committed
Observe changes done by scalafmt
1 parent c5589ff commit 68d374b

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ class EditAlgTest extends FunSuite {
7070
val buildSbt = (repoDir / "build.sbt") -> "\n"
7171
val target = repoDir / "target"
7272
// this file should not be read because it's under target which is git ignored
73-
val targetScalaFile = (target / "SomeFile.scala") -> s"""object Test {"2.0.0"}"""
73+
val targetScalaFile = target / "SomeFile.scala"
7474

7575
val state = MockState.empty
7676
.copy(execCommands = true)
7777
.initGitRepo(repoDir, scalafmtConf -> scalafmtConfContent, buildSbt, gitignore)
78-
.flatMap(_.addFiles(targetScalaFile))
78+
.flatMap(_.addFiles(targetScalaFile -> s""" object Test {"2.0.0"} """))
7979
.flatMap(editAlg.applyUpdate(data, update).runS)
8080
.unsafeRunSync()
8181

@@ -105,7 +105,7 @@ class EditAlgTest extends FunSuite {
105105
|""".stripMargin,
106106
buildSbt,
107107
gitignore,
108-
targetScalaFile
108+
targetScalaFile -> s"""object Test { "2.0.0" }\n"""
109109
)
110110
)
111111

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.scalasteward.core.io
22

3+
import cats.syntax.all._
34
import cats.data.Kleisli
45
import cats.effect.IO
56
import org.scalasteward.core.application.Config.ProcessCfg
@@ -11,19 +12,30 @@ object MockProcessAlg {
1112
new ProcessAlg(config)({ args =>
1213
Kleisli { ctx =>
1314
for {
14-
state <- ctx.get
15+
state0 <- ctx.get
1516
cmd = Cmd(
1617
args.extraEnv.map { case (k, v) => s"$k=$v" } ++
1718
args.workingDirectory.map(_.toString).toList ++
1819
args.command.toList
1920
)
20-
_ <- ctx.set(state.appendTraceEntry(cmd))
21-
res <- state.commandOutputs.get(cmd) match {
22-
case Some(output) => IO.fromEither(output)
23-
case None if state.execCommands => ProcessAlgTest.ioProcessAlg.execImpl(args)
24-
case None => IO.pure(List.empty)
21+
state1 = state0.appendTraceEntry(cmd)
22+
_ <- ctx.set(state1)
23+
res <- state1.commandOutputs.get(cmd) match {
24+
case Some(output) => IO.fromEither(output).tupleRight(state1.files)
25+
case None if state1.execCommands =>
26+
for {
27+
output <- ProcessAlgTest.ioProcessAlg.execImpl(args)
28+
// External processes can modify tracked files. We read them again here so that
29+
// they are in sync with the files in the filesystem.
30+
files <- state1.files.keys.toList.traverse { file =>
31+
FileAlgTest.ioFileAlg.readFile(file).map(_.getOrElse("")).tupleLeft(file)
32+
}
33+
} yield (output, files.toMap)
34+
case None => IO.pure((List.empty, state1.files))
2535
}
26-
} yield res
36+
(output, files) = res
37+
_ <- ctx.set(state1.copy(files = files))
38+
} yield output
2739
}
2840
})
2941
}

0 commit comments

Comments
 (0)