mirror of
https://github.com/golang/go
synced 2024-11-26 16:26:49 -07:00
cmd/go: rewrite TestNoteReading to use test harness
On my laptop reduces time required for test from 22 seconds to 0.14 seconds. Update #11779. Change-Id: I715d85bd9c6f7683c6915eedd2539813aa5efc58 Reviewed-on: https://go-review.googlesource.com/12363 Reviewed-by: David Crawshaw <crawshaw@golang.org> Reviewed-by: Andrew Gerrand <adg@golang.org>
This commit is contained in:
parent
1125cd4997
commit
f7e7719f65
@ -2,42 +2,23 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main
|
||||
package main_test
|
||||
|
||||
import (
|
||||
"internal/testenv"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"cmd/go"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNoteReading(t *testing.T) {
|
||||
testenv.MustHaveGoBuild(t)
|
||||
|
||||
// TODO: Replace with new test scaffolding by iant.
|
||||
d, err := ioutil.TempDir("", "go-test-")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer os.RemoveAll(d)
|
||||
|
||||
out, err := exec.Command("go", "build", "-o", d+"/go.exe", "cmd/go").CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("go build cmd/go: %v\n%s", err, out)
|
||||
}
|
||||
|
||||
tg := testgo(t)
|
||||
defer tg.cleanup()
|
||||
tg.tempFile("hello.go", `package main; func main() { print("hello, world\n") }`)
|
||||
const buildID = "TestNoteReading-Build-ID"
|
||||
out, err = exec.Command(d+"/go.exe", "build", "-ldflags", "-buildid="+buildID, "-o", d+"/hello.exe", "../../../test/helloworld.go").CombinedOutput()
|
||||
if err != nil {
|
||||
t.Fatalf("go build hello: %v\n%s", err, out)
|
||||
}
|
||||
|
||||
id, err := readBuildIDFromBinary(d + "/hello.exe")
|
||||
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)
|
||||
}
|
||||
|
@ -1637,7 +1637,7 @@ func readBuildID(p *Package) (id string, err error) {
|
||||
|
||||
// For commands, read build ID directly from binary.
|
||||
if p.Name == "main" {
|
||||
return readBuildIDFromBinary(p.Target)
|
||||
return ReadBuildIDFromBinary(p.Target)
|
||||
}
|
||||
|
||||
// Otherwise, we expect to have an archive (.a) file,
|
||||
@ -1715,7 +1715,7 @@ var (
|
||||
elfPrefix = []byte("\x7fELF")
|
||||
)
|
||||
|
||||
// readBuildIDFromBinary reads the build ID from a binary.
|
||||
// ReadBuildIDFromBinary reads the build ID from a binary.
|
||||
//
|
||||
// ELF binaries store the build ID in a proper PT_NOTE section.
|
||||
//
|
||||
@ -1724,7 +1724,7 @@ var (
|
||||
// of the text segment, which should appear near the beginning
|
||||
// of the file. This is clumsy but fairly portable. Custom locations
|
||||
// can be added for other binary types as needed, like we did for ELF.
|
||||
func readBuildIDFromBinary(filename string) (id string, err error) {
|
||||
func ReadBuildIDFromBinary(filename string) (id string, err error) {
|
||||
if filename == "" {
|
||||
return "", &os.PathError{Op: "parse", Path: filename, Err: errBuildIDUnknown}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user