mirror of
https://github.com/golang/go
synced 2024-09-30 12:18:33 -06:00
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 <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
e893c72f2a
commit
03723c909e
@ -6,6 +6,7 @@ package filepath_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"internal/testenv"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
. "path/filepath"
|
. "path/filepath"
|
||||||
@ -174,15 +175,7 @@ var globSymlinkTests = []struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGlobSymlink(t *testing.T) {
|
func TestGlobSymlink(t *testing.T) {
|
||||||
switch runtime.GOOS {
|
testenv.MustHaveSymlink(t)
|
||||||
case "android", "nacl", "plan9":
|
|
||||||
t.Skipf("skipping on %s", runtime.GOOS)
|
|
||||||
case "windows":
|
|
||||||
if !supportsSymlinks {
|
|
||||||
t.Skipf("skipping on %s", runtime.GOOS)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir("", "globsymlink")
|
tmpDir, err := ioutil.TempDir("", "globsymlink")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -6,6 +6,7 @@ package filepath_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"internal/testenv"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@ -15,8 +16,6 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var supportsSymlinks = true
|
|
||||||
|
|
||||||
type PathTest struct {
|
type PathTest struct {
|
||||||
path, result string
|
path, result string
|
||||||
}
|
}
|
||||||
@ -776,13 +775,7 @@ func simpleJoin(dir, path string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestEvalSymlinks(t *testing.T) {
|
func TestEvalSymlinks(t *testing.T) {
|
||||||
switch runtime.GOOS {
|
testenv.MustHaveSymlink(t)
|
||||||
case "android", "nacl", "plan9":
|
|
||||||
t.Skipf("skipping on %s", runtime.GOOS)
|
|
||||||
}
|
|
||||||
if !supportsSymlinks {
|
|
||||||
t.Skip("skipping because symlinks are not supported")
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir("", "evalsymlink")
|
tmpDir, err := ioutil.TempDir("", "evalsymlink")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -896,13 +889,7 @@ func TestEvalSymlinks(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIssue13582(t *testing.T) {
|
func TestIssue13582(t *testing.T) {
|
||||||
switch runtime.GOOS {
|
testenv.MustHaveSymlink(t)
|
||||||
case "android", "nacl", "plan9":
|
|
||||||
t.Skipf("skipping on %s", runtime.GOOS)
|
|
||||||
}
|
|
||||||
if !supportsSymlinks {
|
|
||||||
t.Skip("skipping because symlinks are not supported")
|
|
||||||
}
|
|
||||||
|
|
||||||
tmpDir, err := ioutil.TempDir("", "issue13582")
|
tmpDir, err := ioutil.TempDir("", "issue13582")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -13,29 +13,9 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
tmpdir, err := ioutil.TempDir("", "symtest")
|
|
||||||
if err != nil {
|
|
||||||
panic("failed to create temp directory: " + err.Error())
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(tmpdir)
|
|
||||||
|
|
||||||
err = os.Symlink("target", filepath.Join(tmpdir, "symlink"))
|
|
||||||
if err == nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = err.(*os.LinkError).Err
|
|
||||||
switch err {
|
|
||||||
case syscall.EWINDOWS, syscall.ERROR_PRIVILEGE_NOT_HELD:
|
|
||||||
supportsSymlinks = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestWinSplitListTestsAreValid(t *testing.T) {
|
func TestWinSplitListTestsAreValid(t *testing.T) {
|
||||||
comspec := os.Getenv("ComSpec")
|
comspec := os.Getenv("ComSpec")
|
||||||
if comspec == "" {
|
if comspec == "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user