func testNoteReading(t *testing.T) { tg := testgo(t) defer tg.cleanup() tg.tempFile("hello.go", `package main; func main() { print("hello, world\n") }`) const buildID = "TestNoteReading-Build-ID" tg.run("build", "-ldflags", "-buildid="+buildID, "-o", tg.path("hello.exe"), tg.path("hello.go")) id, err := main.ReadBuildIDFromBinary(tg.path("hello.exe")) if err != nil { t.Fatalf("reading build ID from hello binary: %v", err) } if id != buildID { t.Fatalf("buildID in hello binary = %q, want %q", id, buildID) } switch { case runtime.GOOS == "linux" && (runtime.GOARCH == "ppc64le" || runtime.GOARCH == "ppc64"): t.Skipf("skipping - external linking not supported, golang.org/issue/11184") case runtime.GOOS == "linux" && (runtime.GOARCH == "mips64le" || runtime.GOARCH == "mips64"): t.Skipf("skipping - external linking not supported, golang.org/issue/12560") case runtime.GOOS == "openbsd" && runtime.GOARCH == "arm": t.Skipf("skipping - external linking not supported, golang.org/issue/10619") case runtime.GOOS == "plan9": t.Skipf("skipping - external linking not supported") } tg.run("build", "-ldflags", "-buildid="+buildID+" -linkmode=external", "-o", tg.path("hello.exe"), tg.path("hello.go")) id, err = main.ReadBuildIDFromBinary(tg.path("hello.exe")) if err != nil { t.Fatalf("reading build ID from hello binary (linkmode=external): %v", err) } if id != buildID { t.Fatalf("buildID in hello binary = %q, want %q (linkmode=external)", id, buildID) } }
func TestNoteReading(t *testing.T) { tg := testgo(t) defer tg.cleanup() tg.tempFile("hello.go", `package main; func main() { print("hello, world\n") }`) const buildID = "TestNoteReading-Build-ID" tg.run("build", "-ldflags", "-buildid="+buildID, "-o", tg.path("hello.exe"), tg.path("hello.go")) id, err := main.ReadBuildIDFromBinary(tg.path("hello.exe")) if err != nil { t.Fatalf("reading build ID from hello binary: %v", err) } if id != buildID { t.Fatalf("buildID in hello binary = %q, want %q", id, buildID) } if runtime.GOOS == "linux" && (runtime.GOARCH == "ppc64le" || runtime.GOARCH == "ppc64") { t.Skipf("skipping - golang.org/issue/11184") } switch runtime.GOOS { case "plan9": // no external linking t.Logf("no external linking - skipping linkmode=external test") default: tg.run("build", "-ldflags", "-buildid="+buildID+" -linkmode=external", "-o", tg.path("hello.exe"), tg.path("hello.go")) id, err := main.ReadBuildIDFromBinary(tg.path("hello.exe")) if err != nil { t.Fatalf("reading build ID from hello binary (linkmode=external): %v", err) } if id != buildID { t.Fatalf("buildID in hello binary = %q, want %q (linkmode=external)", id, buildID) } } }