Skip to content

Commit

Permalink
feat: simplify some test code
Browse files Browse the repository at this point in the history
Signed-off-by: Brian McGee <brian@bmcgee.ie>
  • Loading branch information
brianmcgee committed Jan 2, 2024
1 parent 96b1560 commit ada9a72
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions internal/cli/format_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ func TestIncludesAndExcludes(t *testing.T) {
as.Contains(string(out), fmt.Sprintf("%d files changed", 29))

// globally exclude nix files
config.Global = struct{ Excludes []string }{
Excludes: []string{"*.nix"},
}
config.Global.Excludes = []string{"*.nix"}

test.WriteConfig(t, configPath, config)
out, err = cmd(t, "-c", "--config-file", configPath, "--tree-root", tempDir)
Expand All @@ -118,32 +116,34 @@ func TestIncludesAndExcludes(t *testing.T) {
as.NoError(err)
as.Contains(string(out), fmt.Sprintf("%d files changed", 22))

echo := config.Formatters["echo"]

// remove python files from the echo formatter
config.Formatters["echo"].Excludes = []string{"*.py"}
echo.Excludes = []string{"*.py"}

test.WriteConfig(t, configPath, config)
out, err = cmd(t, "-c", "--config-file", configPath, "--tree-root", tempDir)
as.NoError(err)
as.Contains(string(out), fmt.Sprintf("%d files changed", 20))

// remove go files from the echo formatter
config.Formatters["echo"].Excludes = []string{"*.py", "*.go"}
echo.Excludes = []string{"*.py", "*.go"}

test.WriteConfig(t, configPath, config)
out, err = cmd(t, "-c", "--config-file", configPath, "--tree-root", tempDir)
as.NoError(err)
as.Contains(string(out), fmt.Sprintf("%d files changed", 19))

// adjust the includes for echo to only include elm files
config.Formatters["echo"].Includes = []string{"*.elm"}
echo.Includes = []string{"*.elm"}

test.WriteConfig(t, configPath, config)
out, err = cmd(t, "-c", "--config-file", configPath, "--tree-root", tempDir)
as.NoError(err)
as.Contains(string(out), fmt.Sprintf("%d files changed", 1))

// add js files to echo formatter
config.Formatters["echo"].Includes = []string{"*.elm", "*.js"}
echo.Includes = []string{"*.elm", "*.js"}

test.WriteConfig(t, configPath, config)
out, err = cmd(t, "-c", "--config-file", configPath, "--tree-root", tempDir)
Expand Down

0 comments on commit ada9a72

Please sign in to comment.