aboutsummaryrefslogtreecommitdiff
path: root/src/testing/testing.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/testing/testing.go')
-rw-r--r--src/testing/testing.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 44bccd384e..8dfb61bcc3 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -797,6 +797,11 @@ func (c *common) Cleanup(f func()) {
}
}
+var (
+ rOnce sync.Once
+ r *strings.Replacer
+)
+
// TempDir returns a temporary directory for the test to use.
// It is lazily created on first access, and calls t.Fatal if the directory
// creation fails.
@@ -809,7 +814,10 @@ func (c *common) TempDir() string {
// ioutil.TempDir doesn't like path separators in its pattern,
// so mangle the name to accommodate subtests.
- pattern := strings.ReplaceAll(c.Name(), "/", "_")
+ rOnce.Do(func() {
+ r = strings.NewReplacer("/", "_", "\\", "_", ":", "_")
+ })
+ pattern := r.Replace(c.Name())
c.tempDir, c.tempDirErr = ioutil.TempDir("", pattern)
if c.tempDirErr == nil {