1
1
package org .scalasteward .core .io
2
2
3
+ import cats .syntax .all ._
3
4
import cats .data .Kleisli
4
5
import cats .effect .IO
5
6
import org .scalasteward .core .application .Config .ProcessCfg
@@ -11,19 +12,30 @@ object MockProcessAlg {
11
12
new ProcessAlg (config)({ args =>
12
13
Kleisli { ctx =>
13
14
for {
14
- state <- ctx.get
15
+ state0 <- ctx.get
15
16
cmd = Cmd (
16
17
args.extraEnv.map { case (k, v) => s " $k= $v" } ++
17
18
args.workingDirectory.map(_.toString).toList ++
18
19
args.command.toList
19
20
)
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))
25
35
}
26
- } yield res
36
+ (output, files) = res
37
+ _ <- ctx.set(state1.copy(files = files))
38
+ } yield output
27
39
}
28
40
})
29
41
}
0 commit comments