From 47da47105ad3ba9cadcc17b77472185e6cfef662 Mon Sep 17 00:00:00 2001 From: rrhlrmrr Date: Wed, 12 Feb 2025 18:00:43 +0900 Subject: [PATCH] fix: no test file issue --- build/ci.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/build/ci.go b/build/ci.go index 6aa57f9cd5..4bff4e853c 100644 --- a/build/ci.go +++ b/build/ci.go @@ -323,10 +323,27 @@ func doTest(cmdline []string) { gotest.Args = append(gotest.Args, "-short") } - packages := []string{"./..."} - if len(flag.CommandLine.Args()) > 0 { - packages = flag.CommandLine.Args() + // List only packages that contain test files + cmd := exec.Command("go", "list", "-f", "{{if .TestGoFiles}}{{.ImportPath}}{{end}}", "./...") + 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...) build.MustRun(gotest) }