Skip to content

Commit

Permalink
feat: improve missing formatter test
Browse files Browse the repository at this point in the history
Signed-off-by: Brian McGee <[email protected]>
  • Loading branch information
brianmcgee committed Oct 21, 2024
1 parent 45592a9 commit 5659267
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ func TestAllowMissingFormatter(t *testing.T) {
as := require.New(t)

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

test.ChangeWorkDir(t, tempDir)

test.WriteConfig(t, configPath, &config.Config{
FormatterConfigs: map[string]*config.Formatter{
Expand All @@ -162,15 +164,21 @@ func TestAllowMissingFormatter(t *testing.T) {
},
})

_, _, err := treefmt(t, "--config-file", configPath, "--tree-root", tempDir, "-vv")
as.ErrorIs(err, format.ErrCommandNotFound)
// default
treefmt2(t, args(), func(_ []byte, _ *stats.Stats, err error) {
as.ErrorIs(err, format.ErrCommandNotFound)
})

_, _, err = treefmt(t, "--config-file", configPath, "--tree-root", tempDir, "--allow-missing-formatter")
as.NoError(err)
// arg
treefmt2(t, args("--allow-missing-formatter"), func(_ []byte, _ *stats.Stats, err error) {
as.NoError(err)
})

// env
t.Setenv("TREEFMT_ALLOW_MISSING_FORMATTER", "true")
_, _, err = treefmt(t, "--config-file", configPath, "--tree-root", tempDir)
as.NoError(err)
treefmt2(t, args(), func(_ []byte, _ *stats.Stats, err error) {
as.NoError(err)
})
}

func TestSpecifyingFormatters(t *testing.T) {
Expand Down

0 comments on commit 5659267

Please sign in to comment.