mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-14 23:17:27 +01:00
internal/shaderlister: output [] instead of null when no shaders are found
Updates #3157
This commit is contained in:
parent
9b849819f3
commit
75d7a26fcd
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user