aboutsummaryrefslogtreecommitdiff
path: root/misc/cgo/life/life_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'misc/cgo/life/life_test.go')
-rw-r--r--misc/cgo/life/life_test.go19
1 files changed, 10 insertions, 9 deletions
diff --git a/misc/cgo/life/life_test.go b/misc/cgo/life/life_test.go
index 0becb262b4..98d25a197d 100644
--- a/misc/cgo/life/life_test.go
+++ b/misc/cgo/life/life_test.go
@@ -10,7 +10,6 @@ import (
"os"
"os/exec"
"path/filepath"
- "strings"
"testing"
)
@@ -44,20 +43,22 @@ func testMain(m *testing.M) int {
return m.Run()
}
+// TestTestRun runs a test case for cgo //export.
func TestTestRun(t *testing.T) {
if os.Getenv("GOOS") == "android" {
t.Skip("the go tool runs with CGO_ENABLED=0 on the android device")
}
- out, err := exec.Command("go", "env", "GOROOT").Output()
+
+ cmd := exec.Command("go", "run", "main.go")
+ got, err := cmd.CombinedOutput()
if err != nil {
- t.Fatal(err)
+ t.Fatalf("%v: %s\n%s", cmd, err, got)
}
- GOROOT := string(bytes.TrimSpace(out))
-
- cmd := exec.Command("go", "run", filepath.Join(GOROOT, "test", "run.go"), "-", ".")
- out, err = cmd.CombinedOutput()
+ want, err := os.ReadFile("main.out")
if err != nil {
- t.Fatalf("%s: %s\n%s", strings.Join(cmd.Args, " "), err, out)
+ t.Fatal("reading golden output:", err)
+ }
+ if !bytes.Equal(got, want) {
+ t.Errorf("'%v' output does not match expected in main.out. Instead saw:\n%s", cmd, got)
}
- t.Logf("%s:\n%s", strings.Join(cmd.Args, " "), out)
}