elvish/pkg/testutil/chmod.go
Qi Xiao 607fa68aca Implement os:stat.
Time fields are omitted for now; they will be added when there's a proper Elvish
binding for time.Time.

This addresses #1659.
2023-08-21 00:05:05 -04:00

23 lines
453 B
Go

package testutil
import (
"io/fs"
"os"
)
// ChmodOrSkip runs [os.Chmod], but skips the test if file's mode is not exactly
// mode or if there is any error.
func ChmodOrSkip(s Skipper, name string, mode fs.FileMode) {
err := os.Chmod(name, mode)
if err != nil {
s.Skipf("chmod: %v", err)
}
fi, err := os.Stat(name)
if err != nil {
s.Skipf("stat: %v", err)
}
if fi.Mode() != mode {
s.Skipf("file mode %O is not %O", fi.Mode(), mode)
}
}