feat: add includes and excludes tests
Signed-off-by: Brian McGee <brian@bmcgee.ie>
This commit is contained in:
parent
56cf0cf979
commit
85ac1717f7
|
@ -1,6 +1,7 @@
|
||||||
package cli
|
package cli
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"git.numtide.com/numtide/treefmt/internal/test"
|
"git.numtide.com/numtide/treefmt/internal/test"
|
||||||
|
@ -77,3 +78,75 @@ func TestSpecifyingFormatters(t *testing.T) {
|
||||||
out, err = cmd(t, "--clear-cache", "--config-file", configPath, "--tree-root", tempDir, "--formatters", "bar,foo")
|
out, err = cmd(t, "--clear-cache", "--config-file", configPath, "--tree-root", tempDir, "--formatters", "bar,foo")
|
||||||
as.Errorf(err, "formatter not found in config: bar")
|
as.Errorf(err, "formatter not found in config: bar")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIncludesAndExcludes(t *testing.T) {
|
||||||
|
as := require.New(t)
|
||||||
|
|
||||||
|
tempDir := test.TempExamples(t)
|
||||||
|
configPath := tempDir + "/echo.toml"
|
||||||
|
|
||||||
|
// test without any excludes
|
||||||
|
config := format.Config{
|
||||||
|
Formatters: map[string]*format.Formatter{
|
||||||
|
"echo": {
|
||||||
|
Command: "echo",
|
||||||
|
Includes: []string{"*"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
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", 29))
|
||||||
|
|
||||||
|
// globally exclude nix files
|
||||||
|
config.Global = struct{ Excludes []string }{
|
||||||
|
Excludes: []string{"*.nix"},
|
||||||
|
}
|
||||||
|
|
||||||
|
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", 28))
|
||||||
|
|
||||||
|
// add haskell files to the global exclude
|
||||||
|
config.Global.Excludes = []string{"*.nix", "*.hs"}
|
||||||
|
|
||||||
|
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", 22))
|
||||||
|
|
||||||
|
// remove python files from the echo formatter
|
||||||
|
config.Formatters["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"}
|
||||||
|
|
||||||
|
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"}
|
||||||
|
|
||||||
|
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"}
|
||||||
|
|
||||||
|
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", 2))
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user