Skip to content

Commit dd59993

Browse files
committed
Duplicate the test to cover both scenarios
1 parent 5446578 commit dd59993

File tree

1 file changed

+54
-40
lines changed

1 file changed

+54
-40
lines changed

modules/core/src/test/scala/org/scalasteward/core/edit/hooks/HookExecutorTest.scala

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,51 @@ class HookExecutorTest extends CatsEffectSuite {
3131
state.map(assertEquals(_, MockState.empty))
3232
}
3333

34-
test("scalafmt: enabled by config") {
35-
val gitBlameIgnoreRevs = repoDir / gitBlameIgnoreRevsName
36-
val update = (scalafmtGroupId % scalafmtArtifactId % "2.7.4" %> "2.7.5").single
37-
val initial = MockState.empty.copy(commandOutputs =
38-
Map(
39-
FileGitAlg.gitCmd.toList ++
40-
List("status", "--porcelain", "--untracked-files=no", "--ignore-submodules") ->
41-
Right(List("build.sbt")),
42-
FileGitAlg.gitCmd.toList ++ List("rev-parse", "--verify", "HEAD") ->
43-
Right(List(dummySha1.value.value)),
44-
FileGitAlg.gitCmd.toList ++ List("check-ignore", gitBlameIgnoreRevs.pathAsString) ->
45-
Left(dummyProcessError)
34+
Seq(true, false).foreach { case blameRevIgnored =>
35+
val isIgnored = if (blameRevIgnored) "ignored" else "not ignored"
36+
37+
test(s"scalafmt: enabled by config / $gitBlameIgnoreRevsName $isIgnored") {
38+
val gitBlameIgnoreRevs = repoDir / gitBlameIgnoreRevsName
39+
val update = (scalafmtGroupId % scalafmtArtifactId % "2.7.4" %> "2.7.5").single
40+
val initial = MockState.empty.copy(commandOutputs =
41+
Map(
42+
FileGitAlg.gitCmd.toList ++
43+
List("status", "--porcelain", "--untracked-files=no", "--ignore-submodules") ->
44+
Right(List("build.sbt")),
45+
FileGitAlg.gitCmd.toList ++ List("rev-parse", "--verify", "HEAD") ->
46+
Right(List(dummySha1.value.value)),
47+
FileGitAlg.gitCmd.toList ++ List("check-ignore", gitBlameIgnoreRevs.pathAsString) ->
48+
(if (blameRevIgnored) Right(List.empty) else Left(dummyProcessError))
49+
)
4650
)
47-
)
48-
val state = FileAlgTest.ioFileAlg.deleteForce(gitBlameIgnoreRevs) >>
49-
hookExecutor.execPostUpdateHooks(data, update).runS(initial)
51+
val state = FileAlgTest.ioFileAlg.deleteForce(gitBlameIgnoreRevs) >>
52+
hookExecutor.execPostUpdateHooks(data, update).runS(initial)
5053

51-
val expected = initial.copy(
52-
trace = Vector(
54+
val logIfIgnored =
55+
if (blameRevIgnored)
56+
Vector(Log(s"Impossible to add '$gitBlameIgnoreRevs' because it is git ignored."))
57+
else
58+
Vector(
59+
Cmd(gitCmd(repoDir), "add", gitBlameIgnoreRevs.pathAsString),
60+
Cmd(
61+
gitCmd(repoDir),
62+
"status",
63+
"--porcelain",
64+
"--untracked-files=no",
65+
"--ignore-submodules"
66+
),
67+
Cmd(
68+
gitCmd(repoDir),
69+
"commit",
70+
"--all",
71+
"--no-gpg-sign",
72+
"-m",
73+
s"Add 'Reformat with scalafmt 2.7.5' to $gitBlameIgnoreRevsName"
74+
),
75+
Cmd(gitCmd(repoDir), "rev-parse", "--verify", "HEAD")
76+
)
77+
78+
val traces = Vector(
5379
Log(
5480
"Executing post-update hook for org.scalameta:scalafmt-core with command 'scalafmt --non-interactive'"
5581
),
@@ -76,31 +102,19 @@ class HookExecutorTest extends CatsEffectSuite {
76102
Cmd(gitCmd(repoDir), "rev-parse", "--verify", "HEAD"),
77103
Cmd("read", gitBlameIgnoreRevs.pathAsString),
78104
Cmd("write", gitBlameIgnoreRevs.pathAsString),
79-
Cmd(gitCmd(repoDir), "check-ignore", gitBlameIgnoreRevs.pathAsString),
80-
Cmd(gitCmd(repoDir), "add", gitBlameIgnoreRevs.pathAsString),
81-
Cmd(
82-
gitCmd(repoDir),
83-
"status",
84-
"--porcelain",
85-
"--untracked-files=no",
86-
"--ignore-submodules"
87-
),
88-
Cmd(
89-
gitCmd(repoDir),
90-
"commit",
91-
"--all",
92-
"--no-gpg-sign",
93-
"-m",
94-
s"Add 'Reformat with scalafmt 2.7.5' to $gitBlameIgnoreRevsName"
95-
),
96-
Cmd(gitCmd(repoDir), "rev-parse", "--verify", "HEAD")
97-
),
98-
files = Map(
99-
gitBlameIgnoreRevs -> s"# Scala Steward: Reformat with scalafmt 2.7.5\n${dummySha1.value.value}\n"
105+
Cmd(gitCmd(repoDir), "check-ignore", gitBlameIgnoreRevs.pathAsString)
106+
) ++
107+
logIfIgnored ++ Vector(
108+
)
109+
val expected = initial.copy(
110+
trace = traces,
111+
files = Map(
112+
gitBlameIgnoreRevs -> s"# Scala Steward: Reformat with scalafmt 2.7.5\n${dummySha1.value.value}\n"
113+
)
100114
)
101-
)
102115

103-
state.map(assertEquals(_, expected))
116+
state.map(assertEquals(_, expected))
117+
}
104118
}
105119

106120
test("scalafmt: disabled by config") {

0 commit comments

Comments
 (0)