fix: no test file issue

This commit is contained in:
rrhlrmrr 2025-02-12 18:00:43 +09:00
parent 58f65c60c2
commit 47da47105a

View file

@ -323,10 +323,27 @@ func doTest(cmdline []string) {
gotest.Args = append(gotest.Args, "-short") gotest.Args = append(gotest.Args, "-short")
} }
packages := []string{"./..."} // List only packages that contain test files
if len(flag.CommandLine.Args()) > 0 { cmd := exec.Command("go", "list", "-f", "{{if .TestGoFiles}}{{.ImportPath}}{{end}}", "./...")
packages = flag.CommandLine.Args() out, err := cmd.Output()
if err != nil {
log.Fatalf("failed to list testable packages: %v", err)
} }
packages := strings.Fields(string(out))
// List only testable user-specified packages
if len(flag.CommandLine.Args()) > 0 {
userPackages := flag.CommandLine.Args()
userCmd := exec.Command("go", append([]string{"list", "-f", "{{if .TestGoFiles}}{{.ImportPath}}{{end}}"}, userPackages...)...)
userOut, _ := userCmd.Output()
filteredPackages := strings.Fields(string(userOut))
if len(filteredPackages) == 0 {
log.Fatalf("No test files found in the specified packages: %v", userPackages)
}
packages = filteredPackages
}
gotest.Args = append(gotest.Args, packages...) gotest.Args = append(gotest.Args, packages...)
build.MustRun(gotest) build.MustRun(gotest)
} }