@@ -1371,15 +1371,16 @@ func TestPathsArg(t *testing.T) {
1371
1371
as .NoError (os .Chdir (cwd ))
1372
1372
})
1373
1373
1374
- // create a project root under a temp dir, in order verify behavior with
1375
- // files inside of temp dir, but outside of the project root
1374
+ // create a project root under a temp dir to verify behaviour with files inside the temp dir, but outside the
1375
+ // project root
1376
1376
tempDir := t .TempDir ()
1377
1377
treeRoot := filepath .Join (tempDir , "tree-root" )
1378
+
1378
1379
test .TempExamplesInDir (t , treeRoot )
1379
1380
1380
1381
configPath := filepath .Join (treeRoot , "/treefmt.toml" )
1381
1382
1382
- // create a file outside of treeRoot
1383
+ // create a file outside the treeRoot
1383
1384
externalFile , err := os .Create (filepath .Join (tempDir , "outside_tree.go" ))
1384
1385
as .NoError (err )
1385
1386
@@ -1399,55 +1400,74 @@ func TestPathsArg(t *testing.T) {
1399
1400
test .WriteConfig (t , configPath , cfg )
1400
1401
1401
1402
// without any path args
1402
- _ , statz , err := treefmt ( t )
1403
- as . NoError ( err )
1404
-
1405
- assertStats ( t , as , statz , map [ stats.Type ] int {
1406
- stats .Traversed : 32 ,
1407
- stats .Matched : 32 ,
1408
- stats .Formatted : 32 ,
1409
- stats . Changed : 0 ,
1410
- } )
1403
+ treefmt2 ( t ,
1404
+ withNoError ( t ),
1405
+ withStats ( t , map [stats. Type ] int {
1406
+ stats .Traversed : 32 ,
1407
+ stats .Matched : 32 ,
1408
+ stats .Formatted : 32 ,
1409
+ stats .Changed : 0 ,
1410
+ }) ,
1411
+ )
1411
1412
1412
1413
// specify some explicit paths
1413
- _ , statz , err = treefmt (t , "-c" , "elm/elm.json" , "haskell/Nested/Foo.hs" )
1414
- as .NoError (err )
1415
-
1416
- assertStats (t , as , statz , map [stats.Type ]int {
1417
- stats .Traversed : 2 ,
1418
- stats .Matched : 2 ,
1419
- stats .Formatted : 2 ,
1420
- stats .Changed : 0 ,
1421
- })
1414
+ treefmt2 (t ,
1415
+ withArgs ("elm/elm.json" , "haskell/Nested/Foo.hs" ),
1416
+ withNoError (t ),
1417
+ withStats (t , map [stats.Type ]int {
1418
+ stats .Traversed : 2 ,
1419
+ stats .Matched : 2 ,
1420
+ stats .Formatted : 0 ,
1421
+ stats .Changed : 0 ,
1422
+ }),
1423
+ )
1422
1424
1423
1425
// specify an absolute path
1424
1426
absoluteInternalPath , err := filepath .Abs ("elm/elm.json" )
1425
1427
as .NoError (err )
1426
1428
1427
- _ , statz , err = treefmt (t , "-c" , absoluteInternalPath )
1428
- as .NoError (err )
1429
-
1430
- assertStats (t , as , statz , map [stats.Type ]int {
1431
- stats .Traversed : 1 ,
1432
- stats .Matched : 1 ,
1433
- stats .Formatted : 1 ,
1434
- stats .Changed : 0 ,
1435
- })
1429
+ treefmt2 (t ,
1430
+ withArgs (absoluteInternalPath ),
1431
+ withNoError (t ),
1432
+ withStats (t , map [stats.Type ]int {
1433
+ stats .Traversed : 1 ,
1434
+ stats .Matched : 1 ,
1435
+ stats .Formatted : 0 ,
1436
+ stats .Changed : 0 ,
1437
+ }),
1438
+ )
1436
1439
1437
1440
// specify a bad path
1438
- _ , _ , err = treefmt (t , "-c" , "elm/elm.json" , "haskell/Nested/Bar.hs" )
1439
- as .Errorf (err , "path haskell/Nested/Bar.hs not found" )
1441
+ treefmt2 (t ,
1442
+ withArgs ("elm/elm.json" , "haskell/Nested/Bar.hs" ),
1443
+ withError (func (err error ) {
1444
+ as .Errorf (err , "path haskell/Nested/Bar.hs not found" )
1445
+ }),
1446
+ )
1440
1447
1441
1448
// specify an absolute path outside the tree root
1442
1449
absoluteExternalPath , err := filepath .Abs (externalFile .Name ())
1443
1450
as .NoError (err )
1444
- as .FileExists (absoluteExternalPath , "exernal file must exist" )
1445
- _ , _ , err = treefmt (t , "-c" , absoluteExternalPath )
1446
- as .Errorf (err , "path %s not found within the tree root" , absoluteExternalPath )
1451
+ as .FileExists (absoluteExternalPath , "external file must exist" )
1452
+
1453
+ treefmt2 (t ,
1454
+ withArgs (absoluteExternalPath ),
1455
+ withError (func (err error ) {
1456
+ as .Errorf (err , "path %s not found within the tree root" , absoluteExternalPath )
1457
+ }),
1458
+ )
1447
1459
1448
1460
// specify a relative path outside the tree root
1449
1461
relativeExternalPath := "../outside_tree.go"
1450
1462
as .FileExists (relativeExternalPath , "exernal file must exist" )
1463
+
1464
+ treefmt2 (t ,
1465
+ withArgs (relativeExternalPath ),
1466
+ withError (func (err error ) {
1467
+ as .Errorf (err , "path %s not found within the tree root" , relativeExternalPath )
1468
+ }),
1469
+ )
1470
+
1451
1471
_ , _ , err = treefmt (t , "-c" , relativeExternalPath )
1452
1472
as .Errorf (err , "path %s not found within the tree root" , relativeExternalPath )
1453
1473
}
0 commit comments