@@ -2,7 +2,6 @@ package cli
2
2
3
3
import (
4
4
"bufio"
5
- "fmt"
6
5
"os"
7
6
"os/exec"
8
7
"path"
@@ -68,19 +67,19 @@ func TestSpecifyingFormatters(t *testing.T) {
68
67
69
68
out , err := cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
70
69
as .NoError (err )
71
- as . Contains ( string ( out ), "3 files changed" )
70
+ assertFormatted ( t , as , out , 3 )
72
71
73
72
out , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir , "--formatters" , "elm,nix" )
74
73
as .NoError (err )
75
- as . Contains ( string ( out ), "2 files changed" )
74
+ assertFormatted ( t , as , out , 2 )
76
75
77
76
out , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir , "--formatters" , "ruby,nix" )
78
77
as .NoError (err )
79
- as . Contains ( string ( out ), "2 files changed" )
78
+ assertFormatted ( t , as , out , 2 )
80
79
81
80
out , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir , "--formatters" , "nix" )
82
81
as .NoError (err )
83
- as . Contains ( string ( out ), "1 files changed" )
82
+ assertFormatted ( t , as , out , 1 )
84
83
85
84
// test bad names
86
85
@@ -110,23 +109,23 @@ func TestIncludesAndExcludes(t *testing.T) {
110
109
test .WriteConfig (t , configPath , cfg )
111
110
out , err := cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
112
111
as .NoError (err )
113
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 31 ) )
112
+ assertFormatted ( t , as , out , 31 )
114
113
115
114
// globally exclude nix files
116
115
cfg .Global .Excludes = []string {"*.nix" }
117
116
118
117
test .WriteConfig (t , configPath , cfg )
119
118
out , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
120
119
as .NoError (err )
121
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 30 ) )
120
+ assertFormatted ( t , as , out , 30 )
122
121
123
122
// add haskell files to the global exclude
124
123
cfg .Global .Excludes = []string {"*.nix" , "*.hs" }
125
124
126
125
test .WriteConfig (t , configPath , cfg )
127
126
out , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
128
127
as .NoError (err )
129
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 24 ) )
128
+ assertFormatted ( t , as , out , 24 )
130
129
131
130
echo := cfg .Formatters ["echo" ]
132
131
@@ -136,31 +135,31 @@ func TestIncludesAndExcludes(t *testing.T) {
136
135
test .WriteConfig (t , configPath , cfg )
137
136
out , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
138
137
as .NoError (err )
139
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 22 ) )
138
+ assertFormatted ( t , as , out , 22 )
140
139
141
140
// remove go files from the echo formatter
142
141
echo .Excludes = []string {"*.py" , "*.go" }
143
142
144
143
test .WriteConfig (t , configPath , cfg )
145
144
out , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
146
145
as .NoError (err )
147
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 21 ) )
146
+ assertFormatted ( t , as , out , 21 )
148
147
149
148
// adjust the includes for echo to only include elm files
150
149
echo .Includes = []string {"*.elm" }
151
150
152
151
test .WriteConfig (t , configPath , cfg )
153
152
out , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
154
153
as .NoError (err )
155
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 1 ) )
154
+ assertFormatted ( t , as , out , 1 )
156
155
157
156
// add js files to echo formatter
158
157
echo .Includes = []string {"*.elm" , "*.js" }
159
158
160
159
test .WriteConfig (t , configPath , cfg )
161
160
out , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
162
161
as .NoError (err )
163
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 2 ) )
162
+ assertFormatted ( t , as , out , 2 )
164
163
}
165
164
166
165
func TestCache (t * testing.T ) {
@@ -182,34 +181,34 @@ func TestCache(t *testing.T) {
182
181
test .WriteConfig (t , configPath , cfg )
183
182
out , err := cmd (t , "--config-file" , configPath , "--tree-root" , tempDir )
184
183
as .NoError (err )
185
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 31 ) )
184
+ assertFormatted ( t , as , out , 31 )
186
185
187
186
out , err = cmd (t , "--config-file" , configPath , "--tree-root" , tempDir )
188
187
as .NoError (err )
189
- as . Contains ( string ( out ), "0 files changed" )
188
+ assertFormatted ( t , as , out , 0 )
190
189
191
190
// clear cache
192
191
out , err = cmd (t , "--config-file" , configPath , "--tree-root" , tempDir , "-c" )
193
192
as .NoError (err )
194
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 31 ) )
193
+ assertFormatted ( t , as , out , 31 )
195
194
196
195
out , err = cmd (t , "--config-file" , configPath , "--tree-root" , tempDir )
197
196
as .NoError (err )
198
- as . Contains ( string ( out ), "0 files changed" )
197
+ assertFormatted ( t , as , out , 0 )
199
198
200
199
// clear cache
201
200
out , err = cmd (t , "--config-file" , configPath , "--tree-root" , tempDir , "-c" )
202
201
as .NoError (err )
203
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 31 ) )
202
+ assertFormatted ( t , as , out , 31 )
204
203
205
204
out , err = cmd (t , "--config-file" , configPath , "--tree-root" , tempDir )
206
205
as .NoError (err )
207
- as . Contains ( string ( out ), "0 files changed" )
206
+ assertFormatted ( t , as , out , 0 )
208
207
209
208
// no cache
210
209
out , err = cmd (t , "--config-file" , configPath , "--tree-root" , tempDir , "--no-cache" )
211
210
as .NoError (err )
212
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 31 ) )
211
+ assertStats ( t , as , out , 31 , 31 , 31 , 0 )
213
212
}
214
213
215
214
func TestChangeWorkingDirectory (t * testing.T ) {
@@ -243,7 +242,7 @@ func TestChangeWorkingDirectory(t *testing.T) {
243
242
// this should fail if the working directory hasn't been changed first
244
243
out , err := cmd (t , "-C" , tempDir )
245
244
as .NoError (err )
246
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 31 ) )
245
+ assertFormatted ( t , as , out , 31 )
247
246
}
248
247
249
248
func TestFailOnChange (t * testing.T ) {
@@ -307,31 +306,31 @@ func TestBustCacheOnFormatterChange(t *testing.T) {
307
306
args := []string {"--config-file" , configPath , "--tree-root" , tempDir }
308
307
out , err := cmd (t , args ... )
309
308
as .NoError (err )
310
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 3 ) )
309
+ assertFormatted ( t , as , out , 3 )
311
310
312
311
// tweak mod time of elm formatter
313
312
as .NoError (test .RecreateSymlink (t , binPath + "/" + "elm-format" ))
314
313
315
314
out , err = cmd (t , args ... )
316
315
as .NoError (err )
317
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 3 ) )
316
+ assertFormatted ( t , as , out , 3 )
318
317
319
318
// check cache is working
320
319
out , err = cmd (t , args ... )
321
320
as .NoError (err )
322
- as . Contains ( string ( out ), "0 files changed" )
321
+ assertFormatted ( t , as , out , 0 )
323
322
324
323
// tweak mod time of python formatter
325
324
as .NoError (test .RecreateSymlink (t , binPath + "/" + "black" ))
326
325
327
326
out , err = cmd (t , args ... )
328
327
as .NoError (err )
329
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 3 ) )
328
+ assertFormatted ( t , as , out , 3 )
330
329
331
330
// check cache is working
332
331
out , err = cmd (t , args ... )
333
332
as .NoError (err )
334
- as . Contains ( string ( out ), "0 files changed" )
333
+ assertFormatted ( t , as , out , 0 )
335
334
336
335
// add go formatter
337
336
cfg .Formatters ["go" ] = & config2.Formatter {
@@ -343,38 +342,38 @@ func TestBustCacheOnFormatterChange(t *testing.T) {
343
342
344
343
out , err = cmd (t , args ... )
345
344
as .NoError (err )
346
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 4 ) )
345
+ assertFormatted ( t , as , out , 4 )
347
346
348
347
// check cache is working
349
348
out , err = cmd (t , args ... )
350
349
as .NoError (err )
351
- as . Contains ( string ( out ), "0 files changed" )
350
+ assertFormatted ( t , as , out , 0 )
352
351
353
352
// remove python formatter
354
353
delete (cfg .Formatters , "python" )
355
354
test .WriteConfig (t , configPath , cfg )
356
355
357
356
out , err = cmd (t , args ... )
358
357
as .NoError (err )
359
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 2 ) )
358
+ assertFormatted ( t , as , out , 2 )
360
359
361
360
// check cache is working
362
361
out , err = cmd (t , args ... )
363
362
as .NoError (err )
364
- as . Contains ( string ( out ), "0 files changed" )
363
+ assertFormatted ( t , as , out , 0 )
365
364
366
365
// remove elm formatter
367
366
delete (cfg .Formatters , "elm" )
368
367
test .WriteConfig (t , configPath , cfg )
369
368
370
369
out , err = cmd (t , args ... )
371
370
as .NoError (err )
372
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 1 ) )
371
+ assertFormatted ( t , as , out , 1 )
373
372
374
373
// check cache is working
375
374
out , err = cmd (t , args ... )
376
375
as .NoError (err )
377
- as . Contains ( string ( out ), "0 files changed" )
376
+ assertFormatted ( t , as , out , 0 )
378
377
}
379
378
380
379
func TestGitWorktree (t * testing.T ) {
@@ -408,10 +407,10 @@ func TestGitWorktree(t *testing.T) {
408
407
wt , err := repo .Worktree ()
409
408
as .NoError (err , "failed to get git worktree" )
410
409
411
- run := func (changed int ) {
410
+ run := func (formatted int ) {
412
411
out , err := cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
413
412
as .NoError (err )
414
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , changed ) )
413
+ assertFormatted ( t , as , out , formatted )
415
414
}
416
415
417
416
// run before adding anything to the worktree
@@ -429,7 +428,7 @@ func TestGitWorktree(t *testing.T) {
429
428
// walk with filesystem instead of git
430
429
out , err := cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir , "--walk" , "filesystem" )
431
430
as .NoError (err )
432
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 59 ) )
431
+ assertFormatted ( t , as , out , 59 )
433
432
}
434
433
435
434
func TestPathsArg (t * testing.T ) {
@@ -464,12 +463,12 @@ func TestPathsArg(t *testing.T) {
464
463
// without any path args
465
464
out , err := cmd (t , "-C" , tempDir )
466
465
as .NoError (err )
467
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 31 ) )
466
+ assertFormatted ( t , as , out , 31 )
468
467
469
468
// specify some explicit paths
470
469
out , err = cmd (t , "-C" , tempDir , "-c" , "elm/elm.json" , "haskell/Nested/Foo.hs" )
471
470
as .NoError (err )
472
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 2 ) )
471
+ assertFormatted ( t , as , out , 2 )
473
472
474
473
// specify a bad path
475
474
out , err = cmd (t , "-C" , tempDir , "-c" , "elm/elm.json" , "haskell/Nested/Bar.hs" )
@@ -529,7 +528,7 @@ go/main.go
529
528
530
529
out , err := cmd (t , "-C" , tempDir , "--stdin" )
531
530
as .NoError (err )
532
- as . Contains ( string ( out ), fmt . Sprintf ( "%d files changed" , 3 ) )
531
+ assertFormatted ( t , as , out , 3 )
533
532
}
534
533
535
534
func TestDeterministicOrderingInPipeline (t * testing.T ) {
0 commit comments