]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: rewrite TestNoteReading to use test harness
authorIan Lance Taylor <iant@golang.org>
Mon, 20 Jul 2015 01:14:53 +0000 (18:14 -0700)
committerIan Lance Taylor <iant@golang.org>
Mon, 20 Jul 2015 03:25:18 +0000 (03:25 +0000)
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>
src/cmd/go/note_test.go
src/cmd/go/pkg.go

index 0170108672925e4686a68632a626e040a7b25d76..fb25f94ec31c91ce73c98b0d15884ea634baff62 100644 (file)
@@ -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)
        }
index 03858d9b4c1a4a4f718f0d698b802d5483cbe258..ae9744218d29cb74c8c3df1f650459a096a36833 100644 (file)
@@ -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}
        }