mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
testing: replace all GOOS-specific path separators in TempDir
For GOOS=windows the path separator characters '\' and ':' also need be replaced. Updates #38465 Change-Id: If7c8cf93058c87d7df6cda140e82fd76578fe699 Reviewed-on: https://go-review.googlesource.com/c/go/+/229837 Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
49f10f3797
commit
41e925bbcc
2 changed files with 14 additions and 1 deletions
|
|
@ -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.
|
// TempDir returns a temporary directory for the test to use.
|
||||||
// It is lazily created on first access, and calls t.Fatal if the directory
|
// It is lazily created on first access, and calls t.Fatal if the directory
|
||||||
// creation fails.
|
// creation fails.
|
||||||
|
|
@ -809,7 +814,10 @@ func (c *common) TempDir() string {
|
||||||
|
|
||||||
// ioutil.TempDir doesn't like path separators in its pattern,
|
// ioutil.TempDir doesn't like path separators in its pattern,
|
||||||
// so mangle the name to accommodate subtests.
|
// 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)
|
c.tempDir, c.tempDirErr = ioutil.TempDir("", pattern)
|
||||||
if c.tempDirErr == nil {
|
if c.tempDirErr == nil {
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,11 @@ func TestMain(m *testing.M) {
|
||||||
func TestTempDir(t *testing.T) {
|
func TestTempDir(t *testing.T) {
|
||||||
testTempDir(t)
|
testTempDir(t)
|
||||||
t.Run("InSubtest", testTempDir)
|
t.Run("InSubtest", testTempDir)
|
||||||
|
t.Run("test/subtest", testTempDir)
|
||||||
|
t.Run("test\\subtest", testTempDir)
|
||||||
|
t.Run("test:subtest", testTempDir)
|
||||||
|
t.Run("test/..", testTempDir)
|
||||||
|
t.Run("../test", testTempDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
func testTempDir(t *testing.T) {
|
func testTempDir(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue