add test for wasm buildinfo

This commit is contained in:
Zxilly 2025-05-17 02:37:33 +08:00
parent de6e9b9f61
commit 6f6997ce30
No known key found for this signature in database
GPG Key ID: 47AB1DEC841BC6A2
1 changed files with 41 additions and 0 deletions

View File

@ -1673,3 +1673,44 @@ func TestLinknameBSS(t *testing.T) {
t.Errorf("executable failed to run: %v\n%s", err, out)
}
}
func TestWasmBuildinfo(t *testing.T) {
testenv.MustHaveGoBuild(t)
t.Parallel()
tmpdir := t.TempDir()
src := filepath.Join(tmpdir, "hello.go")
err := os.WriteFile(src, []byte(`package main; func main() { println("hello") }`), 0666)
if err != nil {
t.Fatal(err)
}
exe := filepath.Join(tmpdir, "hello.wasm")
cmd := testenv.Command(t, testenv.GoToolPath(t), "build", "-o", exe, src)
env := []string{"GOOS=js", "GOARCH=wasm"}
for _, v := range os.Environ() {
if strings.HasPrefix(v, "GOOS=") || strings.HasPrefix(v, "GOARCH=") {
continue
}
env = append(env, v)
}
cmd.Env = env
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("build failed: %v\n%s", err, out)
}
const magic = "\xff Go buildinf:"
data, err := os.ReadFile(exe)
if err != nil {
t.Fatalf("failed to read output file: %v", err)
}
if !bytes.Contains(data, []byte(magic)) {
t.Fatalf("output does not contain buildinfo magic: %q", out)
}
}