github.com/peggyl/go@v0.0.0-20151008231540-ae315999c2d5/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  	switch {
    28  	case runtime.GOOS == "linux" && (runtime.GOARCH == "ppc64le" || runtime.GOARCH == "ppc64"):
    29  		t.Skipf("skipping - external linking not supported, golang.org/issue/11184")
    30  	case runtime.GOOS == "linux" && (runtime.GOARCH == "mips64le" || runtime.GOARCH == "mips64"):
    31  		t.Skipf("skipping - external linking not supported, golang.org/issue/12560")
    32  	case runtime.GOOS == "openbsd" && runtime.GOARCH == "arm":
    33  		t.Skipf("skipping - external linking not supported, golang.org/issue/10619")
    34  	case runtime.GOOS == "plan9":
    35  		t.Skipf("skipping - external linking not supported")
    36  	}
    37  
    38  	tg.run("build", "-ldflags", "-buildid="+buildID+" -linkmode=external", "-o", tg.path("hello.exe"), tg.path("hello.go"))
    39  	id, err = main.ReadBuildIDFromBinary(tg.path("hello.exe"))
    40  	if err != nil {
    41  		t.Fatalf("reading build ID from hello binary (linkmode=external): %v", err)
    42  	}
    43  	if id != buildID {
    44  		t.Fatalf("buildID in hello binary = %q, want %q (linkmode=external)", id, buildID)
    45  	}
    46  }