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>
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 {
}
func TestTempDir(t *testing.T) {
+ testTempDir(t)
+ t.Run("InSubtest", testTempDir)
+}
+
+func testTempDir(t *testing.T) {
dirCh := make(chan string, 1)
t.Cleanup(func() {
// Verify directory has been removed.