Commit e893c72f authored by Hiroshi Ioka's avatar Hiroshi Ioka Committed by Brad Fitzpatrick

os: use testenv.MustHaveSymlink to simplify symlink tests

Cleanup test code for symbolic links.

Change-Id: I7a116e4d5c0e955578eca53c1af559e9092f60cd
Reviewed-on: https://go-review.googlesource.com/27572Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 25d18954
...@@ -25,8 +25,6 @@ import ( ...@@ -25,8 +25,6 @@ import (
"time" "time"
) )
var supportsSymlinks = true
var dot = []string{ var dot = []string{
"dir_unix.go", "dir_unix.go",
"env.go", "env.go",
...@@ -652,14 +650,8 @@ func chtmpdir(t *testing.T) func() { ...@@ -652,14 +650,8 @@ func chtmpdir(t *testing.T) func() {
} }
func TestSymlink(t *testing.T) { func TestSymlink(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)
}
}
defer chtmpdir(t)() defer chtmpdir(t)()
from, to := "symlinktestfrom", "symlinktestto" from, to := "symlinktestfrom", "symlinktestto"
Remove(from) // Just in case. Remove(from) // Just in case.
...@@ -719,14 +711,8 @@ func TestSymlink(t *testing.T) { ...@@ -719,14 +711,8 @@ func TestSymlink(t *testing.T) {
} }
func TestLongSymlink(t *testing.T) { func TestLongSymlink(t *testing.T) {
switch runtime.GOOS { testenv.MustHaveSymlink(t)
case "android", "plan9", "nacl":
t.Skipf("skipping on %s", runtime.GOOS)
case "windows":
if !supportsSymlinks {
t.Skipf("skipping on %s", runtime.GOOS)
}
}
defer chtmpdir(t)() defer chtmpdir(t)()
s := "0123456789abcdef" s := "0123456789abcdef"
// Long, but not too long: a common limit is 255. // Long, but not too long: a common limit is 255.
......
...@@ -18,22 +18,6 @@ import ( ...@@ -18,22 +18,6 @@ import (
var supportJunctionLinks = true var supportJunctionLinks = true
func init() { 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 {
err = err.(*os.LinkError).Err
switch err {
case syscall.EWINDOWS, syscall.ERROR_PRIVILEGE_NOT_HELD:
supportsSymlinks = false
}
}
defer os.Remove("target")
b, _ := osexec.Command("cmd", "/c", "mklink", "/?").Output() b, _ := osexec.Command("cmd", "/c", "mklink", "/?").Output()
if !strings.Contains(string(b), " /J ") { if !strings.Contains(string(b), " /J ") {
supportJunctionLinks = false supportJunctionLinks = false
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package os_test package os_test
import ( import (
"internal/testenv"
"io/ioutil" "io/ioutil"
. "os" . "os"
"path/filepath" "path/filepath"
...@@ -169,14 +170,7 @@ func TestRemoveAll(t *testing.T) { ...@@ -169,14 +170,7 @@ func TestRemoveAll(t *testing.T) {
} }
func TestMkdirAllWithSymlink(t *testing.T) { func TestMkdirAllWithSymlink(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("", "TestMkdirAllWithSymlink-") tmpDir, err := ioutil.TempDir("", "TestMkdirAllWithSymlink-")
if err != nil { if err != nil {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment