diff --git a/internal/collect.go b/internal/collect.go index de9566d..0a6f994 100644 --- a/internal/collect.go +++ b/internal/collect.go @@ -20,6 +20,17 @@ type testf struct { Name string } +func isGoModule(path string) bool { + _, err := os.Lstat(filepath.Join(path, "go.mod")) + if os.IsNotExist(err) { + return false + } + if err != nil { + panic(err) + } + return true +} + func Collect(root string) ([]testf, error) { tests := []testf{} err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error { @@ -28,7 +39,9 @@ func Collect(root string) ([]testf, error) { } // Don't collect testdata directories. - if info.IsDir() && filepath.Base(info.Name()) == "testdata" { + if info.IsDir() && + (filepath.Base(info.Name()) == "testdata" || filepath.Base(info.Name()) == "vendor" || + (info.Name() != root && isGoModule(info.Name()))) { return filepath.SkipDir } diff --git a/main.go b/main.go index 1d8d1ab..c3fb927 100644 --- a/main.go +++ b/main.go @@ -73,8 +73,8 @@ func (p prog) run() (string, error) { switch p.output { case "env": - return fmt.Sprintf("SHARD_TESTS=%s\nSHARD_PATHS=%s", pattern, strings.Join(paths, " ")), nil + return fmt.Sprintf(`SHARD_TESTS="%s"\nSHARD_PATHS="%s"`, pattern, strings.Join(paths, " ")), nil default: - return fmt.Sprintf("-run %s %s", pattern, strings.Join(paths, " ")), nil + return fmt.Sprintf(`-run "%s" %s`, pattern, strings.Join(paths, " ")), nil } }