mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-11-27 23:11:20 +08:00
pkg/testutil: Add utility for setting umask during tests.
This commit is contained in:
parent
e0b824bbdf
commit
be56f72729
|
@ -5,7 +5,6 @@ package lscolors
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var errNotSupportedOnNonUNIX = errors.New("not supported on non-UNIX OS")
|
||||
|
@ -13,5 +12,3 @@ var errNotSupportedOnNonUNIX = errors.New("not supported on non-UNIX OS")
|
|||
func createNamedPipe(fname string) error {
|
||||
return errNotSupportedOnNonUNIX
|
||||
}
|
||||
|
||||
func setUmask(t *testing.T, m int) {}
|
||||
|
|
|
@ -18,7 +18,7 @@ type opt struct {
|
|||
|
||||
func TestDetermineFeature(t *testing.T) {
|
||||
testutil.InTempDir(t)
|
||||
setUmask(t, 0)
|
||||
testutil.Umask(t, 0)
|
||||
|
||||
test := func(name, fname string, wantFeature feature, o opt) {
|
||||
t.Helper()
|
||||
|
|
|
@ -4,16 +4,9 @@
|
|||
package lscolors
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func createNamedPipe(fname string) error {
|
||||
return unix.Mkfifo(fname, 0600)
|
||||
}
|
||||
|
||||
func setUmask(t *testing.T, m int) {
|
||||
save := unix.Umask(m)
|
||||
t.Cleanup(func() { unix.Umask(save) })
|
||||
}
|
||||
|
|
7
pkg/testutil/umask.go
Normal file
7
pkg/testutil/umask.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package testutil
|
||||
|
||||
// Umask sets the umask for the duration of the test, and restores it afterwards.
|
||||
func Umask(c Cleanuper, m int) {
|
||||
save := umask(m)
|
||||
c.Cleanup(func() { umask(save) })
|
||||
}
|
8
pkg/testutil/umask_unix.go
Normal file
8
pkg/testutil/umask_unix.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
//go:build !windows && !plan9 && !js
|
||||
// +build !windows,!plan9,!js
|
||||
|
||||
package testutil
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
var umask = unix.Umask
|
3
pkg/testutil/umask_windows.go
Normal file
3
pkg/testutil/umask_windows.go
Normal file
|
@ -0,0 +1,3 @@
|
|||
package testutil
|
||||
|
||||
func umask(int) int { return 0 }
|
Loading…
Reference in New Issue
Block a user