@@ -31,25 +31,51 @@ class HookExecutorTest extends CatsEffectSuite {
31
31
state.map(assertEquals(_, MockState .empty))
32
32
}
33
33
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
+ )
46
50
)
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)
50
53
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 (
53
79
Log (
54
80
" Executing post-update hook for org.scalameta:scalafmt-core with command 'scalafmt --non-interactive'"
55
81
),
@@ -76,31 +102,19 @@ class HookExecutorTest extends CatsEffectSuite {
76
102
Cmd (gitCmd(repoDir), " rev-parse" , " --verify" , " HEAD" ),
77
103
Cmd (" read" , gitBlameIgnoreRevs.pathAsString),
78
104
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
+ )
100
114
)
101
- )
102
115
103
- state.map(assertEquals(_, expected))
116
+ state.map(assertEquals(_, expected))
117
+ }
104
118
}
105
119
106
120
test(" scalafmt: disabled by config" ) {
0 commit comments