Skip to content

Commit 62ff72d

Browse files
committed
cmd/go: convert TestLinkXImportPathEscape to the script framework
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 <jayconrod@google.com>
1 parent c6d281e commit 62ff72d

File tree

4 files changed

+18
-54
lines changed

4 files changed

+18
-54
lines changed

src/cmd/go/go_test.go

-44
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,6 @@ var mtimeTick time.Duration = 1 * time.Second
317317
type testgoData struct {
318318
t *testing.T
319319
temps []string
320-
wd string
321320
env []string
322321
tempdir string
323322
ran bool
@@ -367,9 +366,6 @@ func (tg *testgoData) parallel() {
367366
if tg.ran {
368367
tg.t.Fatal("internal testsuite error: call to parallel after run")
369368
}
370-
if tg.wd != "" {
371-
tg.t.Fatal("internal testsuite error: call to parallel after cd")
372-
}
373369
for _, e := range tg.env {
374370
if strings.HasPrefix(e, "GOROOT=") || strings.HasPrefix(e, "GOPATH=") || strings.HasPrefix(e, "GOBIN=") {
375371
val := e[strings.Index(e, "=")+1:]
@@ -680,15 +676,6 @@ func (tg *testgoData) creatingTemp(path string) {
680676
if filepath.IsAbs(path) && !strings.HasPrefix(path, tg.tempdir) {
681677
tg.t.Fatalf("internal testsuite error: creatingTemp(%q) with absolute path not in temporary directory", path)
682678
}
683-
// If we have changed the working directory, make sure we have
684-
// an absolute path, because we are going to change directory
685-
// back before we remove the temporary.
686-
if !filepath.IsAbs(path) {
687-
if tg.wd == "" || strings.HasPrefix(tg.wd, testGOROOT) {
688-
tg.t.Fatalf("internal testsuite error: creatingTemp(%q) within GOROOT/src", path)
689-
}
690-
path = filepath.Join(tg.wd, path)
691-
}
692679
tg.must(robustio.RemoveAll(path))
693680
tg.temps = append(tg.temps, path)
694681
}
@@ -842,16 +829,6 @@ var testWork = flag.Bool("testwork", false, "")
842829
// cleanup cleans up a test that runs testgo.
843830
func (tg *testgoData) cleanup() {
844831
tg.t.Helper()
845-
if tg.wd != "" {
846-
wd, _ := os.Getwd()
847-
tg.t.Logf("ended in %s", wd)
848-
849-
if err := os.Chdir(tg.wd); err != nil {
850-
// We are unlikely to be able to continue.
851-
fmt.Fprintln(os.Stderr, "could not restore working directory, crashing:", err)
852-
os.Exit(2)
853-
}
854-
}
855832
if *testWork {
856833
tg.t.Logf("TESTWORK=%s\n", tg.path("."))
857834
return
@@ -2093,27 +2070,6 @@ const (
20932070
okPattern = `(?m)^ok`
20942071
)
20952072

2096-
func TestLinkXImportPathEscape(t *testing.T) {
2097-
// golang.org/issue/16710
2098-
skipIfGccgo(t, "gccgo does not support -ldflags -X")
2099-
tg := testgo(t)
2100-
defer tg.cleanup()
2101-
tg.parallel()
2102-
tg.makeTempdir()
2103-
tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
2104-
exe := tg.path("linkx" + exeSuffix)
2105-
tg.creatingTemp(exe)
2106-
tg.run("build", "-o", exe, "-ldflags", "-X=my.pkg.Text=linkXworked", "my.pkg/main")
2107-
out, err := exec.Command(exe).CombinedOutput()
2108-
if err != nil {
2109-
tg.t.Fatal(err)
2110-
}
2111-
if string(out) != "linkXworked\n" {
2112-
tg.t.Log(string(out))
2113-
tg.t.Fatal(`incorrect output: expected "linkXworked\n"`)
2114-
}
2115-
}
2116-
21172073
// Issue 18044.
21182074
func TestLdBindNow(t *testing.T) {
21192075
tg := testgo(t)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[gccgo] skip 'gccgo does not support -ldflags -X'
2+
3+
go build -o linkx$GOEXE -ldflags -X=my.pkg.Text=linkXworked my.pkg/main
4+
exec ./linkx$GOEXE
5+
stderr '^linkXworked$'
6+
7+
-- my.pkg/main/main.go --
8+
package main
9+
10+
import "my.pkg"
11+
12+
func main() {
13+
println(pkg.Text)
14+
}
15+
-- my.pkg/pkg.go --
16+
package pkg
17+
18+
var Text = "unset"

src/cmd/go/testdata/src/my.pkg/main/main.go

-7
This file was deleted.

src/cmd/go/testdata/src/my.pkg/pkg.go

-3
This file was deleted.

0 commit comments

Comments
 (0)