33 lines
922 B
Go
33 lines
922 B
Go
package assets
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestCheckMDL(t *testing.T) {
|
|
dir := t.TempDir()
|
|
// Uncompiled ASCII model with a name mismatch.
|
|
bad := filepath.Join(dir, "foo.mdl")
|
|
if err := os.WriteFile(bad, []byte("newmodel wrong\nbeginmodelgeom wrong\nendmodelgeom wrong\ndonemodel wrong\n"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
var out, errw bytes.Buffer
|
|
if code := runCheckMDL([]string{dir}, &out, &errw); code != exitFail {
|
|
t.Fatalf("bad mdl exit = %d, want %d\n%s", code, exitFail, errw.String())
|
|
}
|
|
|
|
// A binary (compiled) model is fine.
|
|
good := t.TempDir()
|
|
if err := os.WriteFile(filepath.Join(good, "bar.mdl"), []byte("\x00\x00compiled binary blob"), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
out.Reset()
|
|
errw.Reset()
|
|
if code := runCheckMDL([]string{good}, &out, &errw); code != exitOK {
|
|
t.Fatalf("binary mdl exit = %d, want %d\n%s", code, exitOK, errw.String())
|
|
}
|
|
}
|