Skip to content

Commit 03723c9

Browse files
hirochachachabradfitz
authored andcommitted
path/filepath: use testenv.MustHaveSymlink to simplify symlink tests
Cleanup test code for symbolic links. Change-Id: I25f561cd34dc4d120a4143f933619d233a6cffc5 Reviewed-on: https://go-review.googlesource.com/27573 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent e893c72 commit 03723c9

File tree

3 files changed

+5
-45
lines changed

3 files changed

+5
-45
lines changed

src/path/filepath/match_test.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package filepath_test
66

77
import (
88
"fmt"
9+
"internal/testenv"
910
"io/ioutil"
1011
"os"
1112
. "path/filepath"
@@ -174,15 +175,7 @@ var globSymlinkTests = []struct {
174175
}
175176

176177
func TestGlobSymlink(t *testing.T) {
177-
switch runtime.GOOS {
178-
case "android", "nacl", "plan9":
179-
t.Skipf("skipping on %s", runtime.GOOS)
180-
case "windows":
181-
if !supportsSymlinks {
182-
t.Skipf("skipping on %s", runtime.GOOS)
183-
}
184-
185-
}
178+
testenv.MustHaveSymlink(t)
186179

187180
tmpDir, err := ioutil.TempDir("", "globsymlink")
188181
if err != nil {

src/path/filepath/path_test.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package filepath_test
66

77
import (
88
"errors"
9+
"internal/testenv"
910
"io/ioutil"
1011
"os"
1112
"path/filepath"
@@ -15,8 +16,6 @@ import (
1516
"testing"
1617
)
1718

18-
var supportsSymlinks = true
19-
2019
type PathTest struct {
2120
path, result string
2221
}
@@ -776,13 +775,7 @@ func simpleJoin(dir, path string) string {
776775
}
777776

778777
func TestEvalSymlinks(t *testing.T) {
779-
switch runtime.GOOS {
780-
case "android", "nacl", "plan9":
781-
t.Skipf("skipping on %s", runtime.GOOS)
782-
}
783-
if !supportsSymlinks {
784-
t.Skip("skipping because symlinks are not supported")
785-
}
778+
testenv.MustHaveSymlink(t)
786779

787780
tmpDir, err := ioutil.TempDir("", "evalsymlink")
788781
if err != nil {
@@ -896,13 +889,7 @@ func TestEvalSymlinks(t *testing.T) {
896889
}
897890

898891
func TestIssue13582(t *testing.T) {
899-
switch runtime.GOOS {
900-
case "android", "nacl", "plan9":
901-
t.Skipf("skipping on %s", runtime.GOOS)
902-
}
903-
if !supportsSymlinks {
904-
t.Skip("skipping because symlinks are not supported")
905-
}
892+
testenv.MustHaveSymlink(t)
906893

907894
tmpDir, err := ioutil.TempDir("", "issue13582")
908895
if err != nil {

src/path/filepath/path_windows_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,9 @@ import (
1313
"path/filepath"
1414
"reflect"
1515
"strings"
16-
"syscall"
1716
"testing"
1817
)
1918

20-
func init() {
21-
tmpdir, err := ioutil.TempDir("", "symtest")
22-
if err != nil {
23-
panic("failed to create temp directory: " + err.Error())
24-
}
25-
defer os.RemoveAll(tmpdir)
26-
27-
err = os.Symlink("target", filepath.Join(tmpdir, "symlink"))
28-
if err == nil {
29-
return
30-
}
31-
32-
err = err.(*os.LinkError).Err
33-
switch err {
34-
case syscall.EWINDOWS, syscall.ERROR_PRIVILEGE_NOT_HELD:
35-
supportsSymlinks = false
36-
}
37-
}
38-
3919
func TestWinSplitListTestsAreValid(t *testing.T) {
4020
comspec := os.Getenv("ComSpec")
4121
if comspec == "" {

0 commit comments

Comments
 (0)