From 5659267925f37938dc323fe7831bddb3b20b3e04 Mon Sep 17 00:00:00 2001 From: Brian McGee Date: Sat, 19 Oct 2024 10:41:47 +0100 Subject: [PATCH] feat: improve missing formatter test Signed-off-by: Brian McGee --- cmd/root_test.go | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/cmd/root_test.go b/cmd/root_test.go index 5dc5abb7..400568b9 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -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{ @@ -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) {