diff --git a/internal/shaderlister/main.go b/internal/shaderlister/main.go index f6937c74373c..60c10523a21e 100644 --- a/internal/shaderlister/main.go +++ b/internal/shaderlister/main.go @@ -56,13 +56,15 @@ func xmain() error { } pkgs, err := packages.Load(&packages.Config{ - Mode: packages.NeedName | packages.NeedTypes | packages.NeedImports | packages.NeedDeps | packages.NeedSyntax | packages.NeedTypesInfo, + Mode: packages.NeedName | packages.NeedImports | packages.NeedDeps | packages.NeedTypes | packages.NeedSyntax | packages.NeedTypesInfo, }, flag.Args()...) if err != nil { return err } - var shaders []Shader + // Collect shader information. + // Even if no shader is found, the output should be a JSON array. Start with an empty slice, not nil. + shaders := []Shader{} packages.Visit(pkgs, func(pkg *packages.Package) bool { path := pkg.PkgPath diff --git a/internal/shaderlister/shaderlister_test.go b/internal/shaderlister/shaderlister_test.go index a2a189c009ee..86e4d3ac0658 100644 --- a/internal/shaderlister/shaderlister_test.go +++ b/internal/shaderlister/shaderlister_test.go @@ -20,6 +20,7 @@ import ( "fmt" "os/exec" "slices" + "strings" "testing" ) @@ -63,3 +64,19 @@ func TestRun(t *testing.T) { } } } + +func TestEmpty(t *testing.T) { + cmd := exec.Command("go", "run", "github.com/hajimehoshi/ebiten/v2/internal/shaderlister", "github.com/ebitengine/purego") + out, err := cmd.Output() + if err != nil { + if err, ok := err.(*exec.ExitError); ok { + t.Fatalf("Error: %v\n%s", err, err.Stderr) + } + t.Fatal(err) + } + + // Check the output is `[]`, not `null`. + if got, want := strings.TrimSpace(string(out)), "[]"; got != want { + t.Errorf("output: got: %q, want: %q", got, want) + } +}