Skip to content

Commit

Permalink
cmd/go: convert TestLinkXImportPathEscape to the script framework
Browse files Browse the repository at this point in the history
Part of converting all tests to script framework to improve
test parallelism.

Updates #36320
Updates #17751

Change-Id: Ib386838081abad8bc6b01c1f0a4656553d0b6ff3
Reviewed-on: https://go-review.googlesource.com/c/go/+/214579
Reviewed-by: Jay Conrod <[email protected]>
  • Loading branch information
matloob committed Feb 27, 2020
1 parent c6d281e commit 62ff72d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 54 deletions.
44 changes: 0 additions & 44 deletions src/cmd/go/go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ var mtimeTick time.Duration = 1 * time.Second
type testgoData struct {
t *testing.T
temps []string
wd string
env []string
tempdir string
ran bool
Expand Down Expand Up @@ -367,9 +366,6 @@ func (tg *testgoData) parallel() {
if tg.ran {
tg.t.Fatal("internal testsuite error: call to parallel after run")
}
if tg.wd != "" {
tg.t.Fatal("internal testsuite error: call to parallel after cd")
}
for _, e := range tg.env {
if strings.HasPrefix(e, "GOROOT=") || strings.HasPrefix(e, "GOPATH=") || strings.HasPrefix(e, "GOBIN=") {
val := e[strings.Index(e, "=")+1:]
Expand Down Expand Up @@ -680,15 +676,6 @@ func (tg *testgoData) creatingTemp(path string) {
if filepath.IsAbs(path) && !strings.HasPrefix(path, tg.tempdir) {
tg.t.Fatalf("internal testsuite error: creatingTemp(%q) with absolute path not in temporary directory", path)
}
// If we have changed the working directory, make sure we have
// an absolute path, because we are going to change directory
// back before we remove the temporary.
if !filepath.IsAbs(path) {
if tg.wd == "" || strings.HasPrefix(tg.wd, testGOROOT) {
tg.t.Fatalf("internal testsuite error: creatingTemp(%q) within GOROOT/src", path)
}
path = filepath.Join(tg.wd, path)
}
tg.must(robustio.RemoveAll(path))
tg.temps = append(tg.temps, path)
}
Expand Down Expand Up @@ -842,16 +829,6 @@ var testWork = flag.Bool("testwork", false, "")
// cleanup cleans up a test that runs testgo.
func (tg *testgoData) cleanup() {
tg.t.Helper()
if tg.wd != "" {
wd, _ := os.Getwd()
tg.t.Logf("ended in %s", wd)

if err := os.Chdir(tg.wd); err != nil {
// We are unlikely to be able to continue.
fmt.Fprintln(os.Stderr, "could not restore working directory, crashing:", err)
os.Exit(2)
}
}
if *testWork {
tg.t.Logf("TESTWORK=%s\n", tg.path("."))
return
Expand Down Expand Up @@ -2093,27 +2070,6 @@ const (
okPattern = `(?m)^ok`
)

func TestLinkXImportPathEscape(t *testing.T) {
// golang.org/issue/16710
skipIfGccgo(t, "gccgo does not support -ldflags -X")
tg := testgo(t)
defer tg.cleanup()
tg.parallel()
tg.makeTempdir()
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
exe := tg.path("linkx" + exeSuffix)
tg.creatingTemp(exe)
tg.run("build", "-o", exe, "-ldflags", "-X=my.pkg.Text=linkXworked", "my.pkg/main")
out, err := exec.Command(exe).CombinedOutput()
if err != nil {
tg.t.Fatal(err)
}
if string(out) != "linkXworked\n" {
tg.t.Log(string(out))
tg.t.Fatal(`incorrect output: expected "linkXworked\n"`)
}
}

// Issue 18044.
func TestLdBindNow(t *testing.T) {
tg := testgo(t)
Expand Down
18 changes: 18 additions & 0 deletions src/cmd/go/testdata/script/build_link_x_import_path_escape.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[gccgo] skip 'gccgo does not support -ldflags -X'

go build -o linkx$GOEXE -ldflags -X=my.pkg.Text=linkXworked my.pkg/main
exec ./linkx$GOEXE
stderr '^linkXworked$'

-- my.pkg/main/main.go --
package main

import "my.pkg"

func main() {
println(pkg.Text)
}
-- my.pkg/pkg.go --
package pkg

var Text = "unset"
7 changes: 0 additions & 7 deletions src/cmd/go/testdata/src/my.pkg/main/main.go

This file was deleted.

3 changes: 0 additions & 3 deletions src/cmd/go/testdata/src/my.pkg/pkg.go

This file was deleted.

0 comments on commit 62ff72d

Please sign in to comment.