github.com/alash3al/go@v0.0.0-20150827002835-d497eeb00540/src/cmd/go/note_test.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package main_test 6 7 import ( 8 main "cmd/go" 9 "runtime" 10 "testing" 11 ) 12 13 func TestNoteReading(t *testing.T) { 14 tg := testgo(t) 15 defer tg.cleanup() 16 tg.tempFile("hello.go", `package main; func main() { print("hello, world\n") }`) 17 const buildID = "TestNoteReading-Build-ID" 18 tg.run("build", "-ldflags", "-buildid="+buildID, "-o", tg.path("hello.exe"), tg.path("hello.go")) 19 id, err := main.ReadBuildIDFromBinary(tg.path("hello.exe")) 20 if err != nil { 21 t.Fatalf("reading build ID from hello binary: %v", err) 22 } 23 if id != buildID { 24 t.Fatalf("buildID in hello binary = %q, want %q", id, buildID) 25 } 26 27 if runtime.GOOS == "linux" && (runtime.GOARCH == "ppc64le" || runtime.GOARCH == "ppc64") { 28 t.Skipf("skipping - golang.org/issue/11184") 29 } 30 31 switch runtime.GOOS { 32 case "plan9": 33 // no external linking 34 t.Logf("no external linking - skipping linkmode=external test") 35 36 case "solaris": 37 t.Logf("skipping - golang.org/issue/12178") 38 39 default: 40 tg.run("build", "-ldflags", "-buildid="+buildID+" -linkmode=external", "-o", tg.path("hello.exe"), tg.path("hello.go")) 41 id, err := main.ReadBuildIDFromBinary(tg.path("hello.exe")) 42 if err != nil { 43 t.Fatalf("reading build ID from hello binary (linkmode=external): %v", err) 44 } 45 if id != buildID { 46 t.Fatalf("buildID in hello binary = %q, want %q (linkmode=external)", id, buildID) 47 } 48 } 49 }