9
9
"path/filepath"
10
10
"regexp"
11
11
"testing"
12
+ "time"
12
13
13
14
"git.numtide.com/numtide/treefmt/config"
14
15
"git.numtide.com/numtide/treefmt/format"
@@ -159,22 +160,22 @@ func TestSpecifyingFormatters(t *testing.T) {
159
160
setup ()
160
161
_ , err := cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
161
162
as .NoError (err )
162
- assertStats (t , as , 31 , 31 , 3 , 3 )
163
+ assertStats (t , as , 32 , 32 , 3 , 3 )
163
164
164
165
setup ()
165
166
_ , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir , "--formatters" , "elm,nix" )
166
167
as .NoError (err )
167
- assertStats (t , as , 31 , 31 , 2 , 2 )
168
+ assertStats (t , as , 32 , 32 , 2 , 2 )
168
169
169
170
setup ()
170
171
_ , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir , "-f" , "ruby,nix" )
171
172
as .NoError (err )
172
- assertStats (t , as , 31 , 31 , 2 , 2 )
173
+ assertStats (t , as , 32 , 32 , 2 , 2 )
173
174
174
175
setup ()
175
176
_ , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir , "--formatters" , "nix" )
176
177
as .NoError (err )
177
- assertStats (t , as , 31 , 31 , 1 , 1 )
178
+ assertStats (t , as , 32 , 32 , 1 , 1 )
178
179
179
180
// test bad names
180
181
setup ()
@@ -204,23 +205,23 @@ func TestIncludesAndExcludes(t *testing.T) {
204
205
test .WriteConfig (t , configPath , cfg )
205
206
_ , err := cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
206
207
as .NoError (err )
207
- assertStats (t , as , 31 , 31 , 31 , 0 )
208
+ assertStats (t , as , 32 , 32 , 32 , 0 )
208
209
209
210
// globally exclude nix files
210
211
cfg .Global .Excludes = []string {"*.nix" }
211
212
212
213
test .WriteConfig (t , configPath , cfg )
213
214
_ , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
214
215
as .NoError (err )
215
- assertStats (t , as , 31 , 31 , 30 , 0 )
216
+ assertStats (t , as , 32 , 32 , 31 , 0 )
216
217
217
218
// add haskell files to the global exclude
218
219
cfg .Global .Excludes = []string {"*.nix" , "*.hs" }
219
220
220
221
test .WriteConfig (t , configPath , cfg )
221
222
_ , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
222
223
as .NoError (err )
223
- assertStats (t , as , 31 , 31 , 24 , 0 )
224
+ assertStats (t , as , 32 , 32 , 25 , 0 )
224
225
225
226
echo := cfg .Formatters ["echo" ]
226
227
@@ -230,31 +231,31 @@ func TestIncludesAndExcludes(t *testing.T) {
230
231
test .WriteConfig (t , configPath , cfg )
231
232
_ , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
232
233
as .NoError (err )
233
- assertStats (t , as , 31 , 31 , 22 , 0 )
234
+ assertStats (t , as , 32 , 32 , 23 , 0 )
234
235
235
236
// remove go files from the echo formatter
236
237
echo .Excludes = []string {"*.py" , "*.go" }
237
238
238
239
test .WriteConfig (t , configPath , cfg )
239
240
_ , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
240
241
as .NoError (err )
241
- assertStats (t , as , 31 , 31 , 21 , 0 )
242
+ assertStats (t , as , 32 , 32 , 22 , 0 )
242
243
243
244
// adjust the includes for echo to only include elm files
244
245
echo .Includes = []string {"*.elm" }
245
246
246
247
test .WriteConfig (t , configPath , cfg )
247
248
_ , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
248
249
as .NoError (err )
249
- assertStats (t , as , 31 , 31 , 1 , 0 )
250
+ assertStats (t , as , 32 , 32 , 1 , 0 )
250
251
251
252
// add js files to echo formatter
252
253
echo .Includes = []string {"*.elm" , "*.js" }
253
254
254
255
test .WriteConfig (t , configPath , cfg )
255
256
_ , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir )
256
257
as .NoError (err )
257
- assertStats (t , as , 31 , 31 , 2 , 0 )
258
+ assertStats (t , as , 32 , 32 , 2 , 0 )
258
259
}
259
260
260
261
func TestCache (t * testing.T ) {
@@ -281,7 +282,7 @@ func TestCache(t *testing.T) {
281
282
test .WriteConfig (t , configPath , cfg )
282
283
_ , err = cmd (t , "--config-file" , configPath , "--tree-root" , tempDir )
283
284
as .NoError (err )
284
- assertStats (t , as , 31 , 31 , 31 , 0 )
285
+ assertStats (t , as , 32 , 32 , 32 , 0 )
285
286
286
287
out , err = cmd (t , "--config-file" , configPath , "--tree-root" , tempDir )
287
288
as .NoError (err )
@@ -290,7 +291,7 @@ func TestCache(t *testing.T) {
290
291
// clear cache
291
292
_ , err = cmd (t , "--config-file" , configPath , "--tree-root" , tempDir , "-c" )
292
293
as .NoError (err )
293
- assertStats (t , as , 31 , 31 , 31 , 0 )
294
+ assertStats (t , as , 32 , 32 , 32 , 0 )
294
295
295
296
out , err = cmd (t , "--config-file" , configPath , "--tree-root" , tempDir )
296
297
as .NoError (err )
@@ -299,7 +300,7 @@ func TestCache(t *testing.T) {
299
300
// clear cache
300
301
_ , err = cmd (t , "--config-file" , configPath , "--tree-root" , tempDir , "-c" )
301
302
as .NoError (err )
302
- assertStats (t , as , 31 , 31 , 31 , 0 )
303
+ assertStats (t , as , 32 , 32 , 32 , 0 )
303
304
304
305
out , err = cmd (t , "--config-file" , configPath , "--tree-root" , tempDir )
305
306
as .NoError (err )
@@ -308,7 +309,7 @@ func TestCache(t *testing.T) {
308
309
// no cache
309
310
_ , err = cmd (t , "--config-file" , configPath , "--tree-root" , tempDir , "--no-cache" )
310
311
as .NoError (err )
311
- assertStats (t , as , 31 , 31 , 31 , 0 )
312
+ assertStats (t , as , 32 , 32 , 32 , 0 )
312
313
}
313
314
314
315
func TestChangeWorkingDirectory (t * testing.T ) {
@@ -342,7 +343,7 @@ func TestChangeWorkingDirectory(t *testing.T) {
342
343
// this should fail if the working directory hasn't been changed first
343
344
_ , err = cmd (t , "-C" , tempDir )
344
345
as .NoError (err )
345
- assertStats (t , as , 31 , 31 , 31 , 0 )
346
+ assertStats (t , as , 32 , 32 , 32 , 0 )
346
347
}
347
348
348
349
func TestFailOnChange (t * testing.T ) {
@@ -365,6 +366,9 @@ func TestFailOnChange(t *testing.T) {
365
366
_ , err := cmd (t , "--fail-on-change" , "--config-file" , configPath , "--tree-root" , tempDir )
366
367
as .ErrorIs (err , ErrFailOnChange )
367
368
369
+ // we have second precision mod time tracking
370
+ time .Sleep (time .Second )
371
+
368
372
// test with no cache
369
373
test .WriteConfig (t , configPath , cfg )
370
374
_ , err = cmd (t , "--fail-on-change" , "--config-file" , configPath , "--tree-root" , tempDir , "--no-cache" )
@@ -411,31 +415,31 @@ func TestBustCacheOnFormatterChange(t *testing.T) {
411
415
args := []string {"--config-file" , configPath , "--tree-root" , tempDir }
412
416
_ , err := cmd (t , args ... )
413
417
as .NoError (err )
414
- assertStats (t , as , 31 , 31 , 3 , 0 )
418
+ assertStats (t , as , 32 , 32 , 3 , 0 )
415
419
416
420
// tweak mod time of elm formatter
417
421
as .NoError (test .RecreateSymlink (t , binPath + "/" + "elm-format" ))
418
422
419
423
_ , err = cmd (t , args ... )
420
424
as .NoError (err )
421
- assertStats (t , as , 31 , 31 , 3 , 0 )
425
+ assertStats (t , as , 32 , 32 , 3 , 0 )
422
426
423
427
// check cache is working
424
428
_ , err = cmd (t , args ... )
425
429
as .NoError (err )
426
- assertStats (t , as , 31 , 0 , 0 , 0 )
430
+ assertStats (t , as , 32 , 0 , 0 , 0 )
427
431
428
432
// tweak mod time of python formatter
429
433
as .NoError (test .RecreateSymlink (t , binPath + "/" + "black" ))
430
434
431
435
_ , err = cmd (t , args ... )
432
436
as .NoError (err )
433
- assertStats (t , as , 31 , 31 , 3 , 0 )
437
+ assertStats (t , as , 32 , 32 , 3 , 0 )
434
438
435
439
// check cache is working
436
440
_ , err = cmd (t , args ... )
437
441
as .NoError (err )
438
- assertStats (t , as , 31 , 0 , 0 , 0 )
442
+ assertStats (t , as , 32 , 0 , 0 , 0 )
439
443
440
444
// add go formatter
441
445
cfg .Formatters ["go" ] = & config.Formatter {
@@ -447,38 +451,38 @@ func TestBustCacheOnFormatterChange(t *testing.T) {
447
451
448
452
_ , err = cmd (t , args ... )
449
453
as .NoError (err )
450
- assertStats (t , as , 31 , 31 , 4 , 0 )
454
+ assertStats (t , as , 32 , 32 , 4 , 0 )
451
455
452
456
// check cache is working
453
457
_ , err = cmd (t , args ... )
454
458
as .NoError (err )
455
- assertStats (t , as , 31 , 0 , 0 , 0 )
459
+ assertStats (t , as , 32 , 0 , 0 , 0 )
456
460
457
461
// remove python formatter
458
462
delete (cfg .Formatters , "python" )
459
463
test .WriteConfig (t , configPath , cfg )
460
464
461
465
_ , err = cmd (t , args ... )
462
466
as .NoError (err )
463
- assertStats (t , as , 31 , 31 , 2 , 0 )
467
+ assertStats (t , as , 32 , 32 , 2 , 0 )
464
468
465
469
// check cache is working
466
470
_ , err = cmd (t , args ... )
467
471
as .NoError (err )
468
- assertStats (t , as , 31 , 0 , 0 , 0 )
472
+ assertStats (t , as , 32 , 0 , 0 , 0 )
469
473
470
474
// remove elm formatter
471
475
delete (cfg .Formatters , "elm" )
472
476
test .WriteConfig (t , configPath , cfg )
473
477
474
478
_ , err = cmd (t , args ... )
475
479
as .NoError (err )
476
- assertStats (t , as , 31 , 31 , 1 , 0 )
480
+ assertStats (t , as , 32 , 32 , 1 , 0 )
477
481
478
482
// check cache is working
479
483
_ , err = cmd (t , args ... )
480
484
as .NoError (err )
481
- assertStats (t , as , 31 , 0 , 0 , 0 )
485
+ assertStats (t , as , 32 , 0 , 0 , 0 )
482
486
}
483
487
484
488
func TestGitWorktree (t * testing.T ) {
@@ -524,7 +528,7 @@ func TestGitWorktree(t *testing.T) {
524
528
// add everything to the worktree
525
529
as .NoError (wt .AddGlob ("." ))
526
530
as .NoError (err )
527
- run (31 , 31 , 31 , 0 )
531
+ run (32 , 32 , 32 , 0 )
528
532
529
533
// remove python directory
530
534
as .NoError (wt .RemoveGlob ("python/*" ))
@@ -533,7 +537,7 @@ func TestGitWorktree(t *testing.T) {
533
537
// walk with filesystem instead of git
534
538
_ , err = cmd (t , "-c" , "--config-file" , configPath , "--tree-root" , tempDir , "--walk" , "filesystem" )
535
539
as .NoError (err )
536
- assertStats (t , as , 59 , 59 , 59 , 0 )
540
+ assertStats (t , as , 61 , 61 , 61 , 0 )
537
541
}
538
542
539
543
func TestPathsArg (t * testing.T ) {
@@ -568,7 +572,7 @@ func TestPathsArg(t *testing.T) {
568
572
// without any path args
569
573
_ , err = cmd (t , "-C" , tempDir )
570
574
as .NoError (err )
571
- assertStats (t , as , 31 , 31 , 31 , 0 )
575
+ assertStats (t , as , 32 , 32 , 32 , 0 )
572
576
573
577
// specify some explicit paths
574
578
_ , err = cmd (t , "-C" , tempDir , "-c" , "elm/elm.json" , "haskell/Nested/Foo.hs" )
0 commit comments