@@ -1629,18 +1629,11 @@ func TestRunInSubdir(t *testing.T) {
1629
1629
// Run the same test for each walk type
1630
1630
for _ , walkType := range walk .TypeValues () {
1631
1631
t .Run (walkType .String (), func (t * testing.T ) {
1632
- // capture current cwd, so we can replace it after the test is finished
1633
- cwd , err := os .Getwd ()
1634
- as .NoError (err )
1635
-
1636
- t .Cleanup (func () {
1637
- // return to the previous working directory
1638
- as .NoError (os .Chdir (cwd ))
1639
- })
1640
-
1641
1632
tempDir := test .TempExamples (t )
1642
1633
configPath := filepath .Join (tempDir , "/treefmt.toml" )
1643
1634
1635
+ test .ChangeWorkDir (t , tempDir )
1636
+
1644
1637
// set the walk type via environment variable
1645
1638
t .Setenv ("TREEFMT_WALK_TYPE" , walkType .String ())
1646
1639
@@ -1678,34 +1671,40 @@ func TestRunInSubdir(t *testing.T) {
1678
1671
},
1679
1672
},
1680
1673
}
1674
+
1681
1675
test .WriteConfig (t , configPath , cfg )
1682
1676
1683
1677
// without any path args, should reformat the whole tree
1684
- statz , err := treefmt ( t )
1685
- as . NoError ( err )
1686
-
1687
- assertStats ( t , as , statz , map [ stats.Type ] int {
1688
- stats .Traversed : 32 ,
1689
- stats .Matched : 32 ,
1690
- stats .Formatted : 32 ,
1691
- stats . Changed : 0 ,
1692
- } )
1678
+ treefmt2 ( t ,
1679
+ withNoError ( t ),
1680
+ withStats ( t , map [stats. Type ] int {
1681
+ stats .Traversed : 32 ,
1682
+ stats .Matched : 32 ,
1683
+ stats .Formatted : 32 ,
1684
+ stats .Changed : 0 ,
1685
+ }) ,
1686
+ )
1693
1687
1694
1688
// specify some explicit paths, relative to the tree root
1695
1689
// this should not work, as we're in a subdirectory
1696
- _ , err = treefmt (t , "-c" , "elm/elm.json" , "haskell/Nested/Foo.hs" )
1697
- as .ErrorContains (err , "path elm/elm.json not found" )
1690
+ treefmt2 (t ,
1691
+ withArgs ("-c" , "elm/elm.json" , "haskell/Nested/Foo.hs" ),
1692
+ withError (func (err error ) {
1693
+ as .ErrorContains (err , "path elm/elm.json not found" )
1694
+ }),
1695
+ )
1698
1696
1699
1697
// specify some explicit paths, relative to the current directory
1700
- statz , err = treefmt (t , "-c" , "elm.json" , "../haskell/Nested/Foo.hs" )
1701
- as .NoError (err )
1702
-
1703
- assertStats (t , as , statz , map [stats.Type ]int {
1704
- stats .Traversed : 2 ,
1705
- stats .Matched : 2 ,
1706
- stats .Formatted : 2 ,
1707
- stats .Changed : 0 ,
1708
- })
1698
+ treefmt2 (t ,
1699
+ withArgs ("-c" , "elm.json" , "../haskell/Nested/Foo.hs" ),
1700
+ withNoError (t ),
1701
+ withStats (t , map [stats.Type ]int {
1702
+ stats .Traversed : 2 ,
1703
+ stats .Matched : 2 ,
1704
+ stats .Formatted : 2 ,
1705
+ stats .Changed : 0 ,
1706
+ }),
1707
+ )
1709
1708
})
1710
1709
}
1711
1710
}
0 commit comments