diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2021-04-04 13:44:21 +0200 |
---|---|---|
committer | Tobias Klauser <tobias.klauser@gmail.com> | 2021-04-04 20:04:37 +0000 |
commit | 4230a6ebdd88f3f9202e1a55f993f6ac62f8f8e7 (patch) | |
tree | c55143ba0365cffb836f2c2d2883fc52b6822c9b /src/os | |
parent | 7bfd681c2f11918c6245ad2906b2efc12eda2914 (diff) | |
download | go-4230a6ebdd88f3f9202e1a55f993f6ac62f8f8e7.tar.gz go-4230a6ebdd88f3f9202e1a55f993f6ac62f8f8e7.zip |
os: don't use T.Cleanup in TestRemoveAllLongPath
Revert CL 306290 changes to TestRemoveAllLongPath. This breaks the test
on aix, illumos and solaris. We need to chdir out of startPath before
attempting to remove it.
Updates #45182
Change-Id: Ic14fa1962d6f2cc83238f6fc2c6932fd9a6e52a1
Reviewed-on: https://go-review.googlesource.com/c/go/+/307189
Trust: Tobias Klauser <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Diffstat (limited to 'src/os')
-rw-r--r-- | src/os/os_windows_test.go | 19 | ||||
-rw-r--r-- | src/os/removeall_test.go | 35 |
2 files changed, 34 insertions, 20 deletions
diff --git a/src/os/os_windows_test.go b/src/os/os_windows_test.go index b4339c3f7e..f310a75f39 100644 --- a/src/os/os_windows_test.go +++ b/src/os/os_windows_test.go @@ -29,6 +29,25 @@ import ( // For TestRawConnReadWrite. type syscallDescriptor = syscall.Handle +// chdir changes the current working directory to the named directory, +// and then restore the original working directory at the end of the test. +func chdir(t *testing.T, dir string) { + olddir, err := os.Getwd() + if err != nil { + t.Fatalf("chdir: %v", err) + } + if err := os.Chdir(dir); err != nil { + t.Fatalf("chdir %s: %v", dir, err) + } + + t.Cleanup(func() { + if err := os.Chdir(olddir); err != nil { + t.Errorf("chdir to original working directory %s: %v", olddir, err) + os.Exit(1) + } + }) +} + func TestSameWindowsFile(t *testing.T) { temp, err := os.MkdirTemp("", "TestSameWindowsFile") if err != nil { diff --git a/src/os/removeall_test.go b/src/os/removeall_test.go index 45a85792ce..3a2f6e3759 100644 --- a/src/os/removeall_test.go +++ b/src/os/removeall_test.go @@ -156,25 +156,6 @@ func TestRemoveAllLarge(t *testing.T) { } } -// chdir changes the current working directory to the named directory, -// and then restore the original working directory at the end of the test. -func chdir(t *testing.T, dir string) { - olddir, err := os.Getwd() - if err != nil { - t.Fatalf("chdir: %v", err) - } - if err := os.Chdir(dir); err != nil { - t.Fatalf("chdir %s: %v", dir, err) - } - - t.Cleanup(func() { - if err := os.Chdir(olddir); err != nil { - t.Errorf("chdir to original working directory %s: %v", olddir, err) - os.Exit(1) - } - }) -} - func TestRemoveAllLongPath(t *testing.T) { switch runtime.GOOS { case "aix", "darwin", "ios", "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "illumos", "solaris": @@ -183,12 +164,21 @@ func TestRemoveAllLongPath(t *testing.T) { t.Skip("skipping for not implemented platforms") } + prevDir, err := Getwd() + if err != nil { + t.Fatalf("Could not get wd: %s", err) + } + startPath, err := os.MkdirTemp("", "TestRemoveAllLongPath-") if err != nil { t.Fatalf("Could not create TempDir: %s", err) } defer RemoveAll(startPath) - chdir(t, startPath) + + err = Chdir(startPath) + if err != nil { + t.Fatalf("Could not chdir %s: %s", startPath, err) + } // Removing paths with over 4096 chars commonly fails for i := 0; i < 41; i++ { @@ -205,6 +195,11 @@ func TestRemoveAllLongPath(t *testing.T) { } } + err = Chdir(prevDir) + if err != nil { + t.Fatalf("Could not chdir %s: %s", prevDir, err) + } + err = RemoveAll(startPath) if err != nil { t.Errorf("RemoveAll could not remove long file path %s: %s", startPath, err) |