Skip to content

Commit

Permalink
chore(test): add sub-folder test
Browse files Browse the repository at this point in the history
Describe what happens when running treefmt in a sub-folder of the
project.
  • Loading branch information
zimbatm authored and brianmcgee committed Aug 29, 2024
1 parent f89b410 commit f1c8c76
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions cli/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,3 +702,43 @@ func TestDeterministicOrderingInPipeline(t *testing.T) {
}
}
}

func TestRunInSubdir(t *testing.T) {
as := require.New(t)

// capture current cwd, so we can replace it after the test is finished
cwd, err := os.Getwd()
as.NoError(err)

t.Cleanup(func() {
// return to the previous working directory
as.NoError(os.Chdir(cwd))
})

tempDir := test.TempExamples(t)
configPath := filepath.Join(tempDir, "/treefmt.toml")

// change working directory to sub directory
as.NoError(os.Chdir(filepath.Join(tempDir, "elm")))

// basic config
cfg := config.Config{
Formatters: map[string]*config.Formatter{
"echo": {
Command: "echo",
Includes: []string{"*"},
},
},
}
test.WriteConfig(t, configPath, cfg)

// without any path args, should reformat the whole tree
_, err = cmd(t)
as.NoError(err)
assertStats(t, as, 32, 32, 32, 0)

// specify some explicit paths, relative to the elm/ sub-folder
_, err = cmd(t, "-c", "elm.json", "../haskell/Nested/Foo.hs")
as.NoError(err)
assertStats(t, as, 2, 2, 2, 0)
}

0 comments on commit f1c8c76

Please sign in to comment.