Commit 9be2a279 authored by Hiroshi Ioka's avatar Hiroshi Ioka Committed by Alex Brainman

internal/testenv: make MustHaveSymlink message friendly

Change-Id: If6e12ebc41152bc0534d3d383df80e960efe97f0
Reviewed-on: https://go-review.googlesource.com/27577Reviewed-by: 's avatarBrad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: 's avatarAlex Brainman <alex.brainman@gmail.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 5bddca64
...@@ -129,14 +129,16 @@ func MustHaveExternalNetwork(t *testing.T) { ...@@ -129,14 +129,16 @@ func MustHaveExternalNetwork(t *testing.T) {
// HasSymlink reports whether the current system can use os.Symlink. // HasSymlink reports whether the current system can use os.Symlink.
func HasSymlink() bool { func HasSymlink() bool {
return hasSymlink() ok, _ := hasSymlink()
return ok
} }
// MustHaveSymlink reports whether the current system can use os.Symlink. // MustHaveSymlink reports whether the current system can use os.Symlink.
// If not, MustHaveSymlink calls t.Skip with an explanation. // If not, MustHaveSymlink calls t.Skip with an explanation.
func MustHaveSymlink(t *testing.T) { func MustHaveSymlink(t *testing.T) {
if !HasSymlink() { ok, reason := hasSymlink()
t.Skipf("skipping test: cannot make symlinks on %s/%s", runtime.GOOS, runtime.GOARCH) if !ok {
t.Skipf("skipping test: cannot make symlinks on %s/%s%s", runtime.GOOS, runtime.GOARCH, reason)
} }
} }
......
...@@ -10,11 +10,11 @@ import ( ...@@ -10,11 +10,11 @@ import (
"runtime" "runtime"
) )
func hasSymlink() bool { func hasSymlink() (ok bool, reason string) {
switch runtime.GOOS { switch runtime.GOOS {
case "android", "nacl", "plan9": case "android", "nacl", "plan9":
return false return false, ""
} }
return true return true, ""
} }
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
) )
var symlinkOnce sync.Once var symlinkOnce sync.Once
var winHasSymlink = true var winSymlinkErr error
func initWinHasSymlink() { func initWinHasSymlink() {
tmpdir, err := ioutil.TempDir("", "symtest") tmpdir, err := ioutil.TempDir("", "symtest")
...@@ -27,14 +27,23 @@ func initWinHasSymlink() { ...@@ -27,14 +27,23 @@ func initWinHasSymlink() {
err = err.(*os.LinkError).Err err = err.(*os.LinkError).Err
switch err { switch err {
case syscall.EWINDOWS, syscall.ERROR_PRIVILEGE_NOT_HELD: case syscall.EWINDOWS, syscall.ERROR_PRIVILEGE_NOT_HELD:
winHasSymlink = false winSymlinkErr = err
} }
} }
os.Remove("target") os.Remove("target")
} }
func hasSymlink() bool { func hasSymlink() (ok bool, reason string) {
symlinkOnce.Do(initWinHasSymlink) symlinkOnce.Do(initWinHasSymlink)
return winHasSymlink switch winSymlinkErr {
case nil:
return true, ""
case syscall.EWINDOWS:
return false, ": symlinks are not supported on your version of Windows"
case syscall.ERROR_PRIVILEGE_NOT_HELD:
return false, ": you don't have enough privileges to create symlinks"
}
return false, ""
} }
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