diff options
author | Andrei Tudor Călin <mail@acln.ro> | 2020-04-23 04:04:33 +0300 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2020-04-23 01:34:16 +0000 |
commit | 952f7de3b403d2ffb45708ea5f69168bbdbfe1f0 (patch) | |
tree | 4ad9bedb812d8323165bf167ada662599c5581d4 /src/testing/testing.go | |
parent | f049d911e93b84577577e73108605627ed522409 (diff) | |
download | go-952f7de3b403d2ffb45708ea5f69168bbdbfe1f0.tar.gz go-952f7de3b403d2ffb45708ea5f69168bbdbfe1f0.zip |
testing: make TempDir work for subtests
ioutil.TempDir doesn't like path separators in its pattern. Modify
(*common).TempDir to replace path separators with underscores before
using the test name as a pattern for ioutil.TempDir.
Fixes #38465.
Change-Id: I9e8ae48b99648b2bf9f561762e845165aff01972
Reviewed-on: https://go-review.googlesource.com/c/go/+/229399
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/testing/testing.go')
-rw-r--r-- | src/testing/testing.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go index d546f56478..44bccd384e 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -806,7 +806,12 @@ func (c *common) Cleanup(f func()) { func (c *common) TempDir() string { c.tempDirOnce.Do(func() { c.Helper() - c.tempDir, c.tempDirErr = ioutil.TempDir("", c.Name()) + + // ioutil.TempDir doesn't like path separators in its pattern, + // so mangle the name to accommodate subtests. + pattern := strings.ReplaceAll(c.Name(), "/", "_") + + c.tempDir, c.tempDirErr = ioutil.TempDir("", pattern) if c.tempDirErr == nil { c.Cleanup(func() { if err := os.RemoveAll(c.tempDir); err != nil { |