aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/test/test.go
diff options
context:
space:
mode:
authorPhilipp Sauter <sauterp@protonmail.com>2020-11-08 22:12:38 +0100
committerBryan C. Mills <bcmills@google.com>2021-05-05 01:28:34 +0000
commit4df662fb373480b5055e645120558bb536fae42c (patch)
tree56e29e105f1f96e348060959b03ab4d49ea959b0 /src/cmd/go/internal/test/test.go
parentbb5e45219af69135c389c6b68f9a67207bb32e05 (diff)
downloadgo-4df662fb373480b5055e645120558bb536fae42c.tar.gz
go-4df662fb373480b5055e645120558bb536fae42c.zip
cmd/go: don't crash when running "go version" in deleted directory
If the go command is executed on Linux in a deleted directory, it fails. This behavior is reasonable for commands which depend on the CWD, but it's unexpected for commands like `go version`. This change delays initialization of a global CWD variable. Fixed #34499 Change-Id: I7302fb84a3b7f5f149a123d277abd5b9b5bc95b2 Reviewed-on: https://go-review.googlesource.com/c/go/+/268261 Reviewed-by: Bryan C. Mills <bcmills@google.com> Trust: Bryan C. Mills <bcmills@google.com> Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Go Bot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/test/test.go')
-rw-r--r--src/cmd/go/internal/test/test.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go
index c2f8aed004..59ea1ef544 100644
--- a/src/cmd/go/internal/test/test.go
+++ b/src/cmd/go/internal/test/test.go
@@ -486,7 +486,7 @@ var (
testJSON bool // -json flag
testList string // -list flag
testO string // -o flag
- testOutputDir = base.Cwd // -outputdir flag
+ testOutputDir outputdirFlag // -outputdir flag
testShuffle shuffleFlag // -shuffle flag
testTimeout time.Duration // -timeout flag
testV bool // -v flag
@@ -710,7 +710,7 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) {
match := make([]func(*load.Package) bool, len(testCoverPaths))
matched := make([]bool, len(testCoverPaths))
for i := range testCoverPaths {
- match[i] = load.MatchPackage(testCoverPaths[i], base.Cwd)
+ match[i] = load.MatchPackage(testCoverPaths[i], base.Cwd())
}
// Select for coverage all dependencies matching the testCoverPaths patterns.
@@ -945,11 +945,11 @@ func builderTest(b *work.Builder, ctx context.Context, pkgOpts load.PackageOpts,
var installAction, cleanAction *work.Action
if testC || testNeedBinary() {
// -c or profiling flag: create action to copy binary to ./test.out.
- target := filepath.Join(base.Cwd, testBinary+cfg.ExeSuffix)
+ target := filepath.Join(base.Cwd(), testBinary+cfg.ExeSuffix)
if testO != "" {
target = testO
if !filepath.IsAbs(target) {
- target = filepath.Join(base.Cwd, target)
+ target = filepath.Join(base.Cwd(), target)
}
}
if target == os.DevNull {