internal/shaderlister: bug fix: wrong shader hash

Updates #3157
This commit is contained in:
Hajime Hoshi 2025-02-08 19:01:53 +09:00
parent 5b551bbf09
commit 3666920fb7
2 changed files with 14 additions and 4 deletions

View File

@ -128,7 +128,7 @@ func xmain() error {
// Add source hashes. // Add source hashes.
for i := range shaders[origN:] { for i := range shaders[origN:] {
shader := &shaders[i] shader := &shaders[origN+i]
hash, err := graphics.CalcSourceHash([]byte(shader.Source)) hash, err := graphics.CalcSourceHash([]byte(shader.Source))
if err != nil { if err != nil {
visitErr = err visitErr = err

View File

@ -22,6 +22,8 @@ import (
"slices" "slices"
"strings" "strings"
"testing" "testing"
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
) )
func hasGoCommand() bool { func hasGoCommand() bool {
@ -46,9 +48,10 @@ func TestRun(t *testing.T) {
} }
type shader struct { type shader struct {
Package string Package string
File string File string
Source string Source string
SourceHash string
} }
var shaders []shader var shaders []shader
if err := json.Unmarshal(out, &shaders); err != nil { if err := json.Unmarshal(out, &shaders); err != nil {
@ -70,6 +73,13 @@ func TestRun(t *testing.T) {
if s.File == "" { if s.File == "" {
t.Errorf("s.File is empty: %v", s) t.Errorf("s.File is empty: %v", s)
} }
hash, err := graphics.CalcSourceHash([]byte(s.Source))
if err != nil {
t.Fatal(err)
}
if got, want := s.SourceHash, hash.String(); got != want {
t.Errorf("s.SourceHash: got: %q, want: %q", got, want)
}
if got, want := s.Source, fmt.Sprintf("shader %d", i+1); got != want { if got, want := s.Source, fmt.Sprintf("shader %d", i+1); got != want {
t.Errorf("s.Source: got: %q, want: %q", got, want) t.Errorf("s.Source: got: %q, want: %q", got, want)
} }