vfs: bring open_tests.go generator back into line with the generated tests
In
54deb01f00
vfs: Make OpenFile and friends return EINVAL if O_RDONLY and O_TRUNC
The generated file open_test.go was edited directly without editing
the generator.
This commit brings the generator make_open_tests.go back into line
with that edit. It also makes it so `go generate` can be used to
regenerate the tests.
This commit is contained in:
parent
fdada79ebf
commit
07908f3f54
3 changed files with 29 additions and 4 deletions
|
@ -1,6 +1,11 @@
|
|||
// This makes the open test suite
|
||||
// This makes the open test suite. It tries to open a file (existing
|
||||
// or not existing) with all possible file modes and writes a test
|
||||
// matrix.
|
||||
//
|
||||
// Run with go run make_open_tests.go | gofmt > open_test.go
|
||||
// The behaviour is as run on Linux, with the small modification that
|
||||
// O_TRUNC with O_RDONLY does **not** truncate the file.
|
||||
//
|
||||
// Run with go generate (defined in vfs.go)
|
||||
//
|
||||
//+build none
|
||||
|
||||
|
@ -26,6 +31,8 @@ func whichError(err error) string {
|
|||
return "nil"
|
||||
case io.EOF:
|
||||
return "io.EOF"
|
||||
case os.ErrInvalid:
|
||||
return "EINVAL"
|
||||
}
|
||||
s := err.Error()
|
||||
switch {
|
||||
|
@ -40,6 +47,8 @@ func whichError(err error) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
const accessModeMask = (os.O_RDONLY | os.O_WRONLY | os.O_RDWR)
|
||||
|
||||
// test Opening, reading and writing the file handle with the flags given
|
||||
func test(fileName string, flags int, mode string) {
|
||||
// first try with file not existing
|
||||
|
@ -123,6 +132,19 @@ func test(fileName string, flags int, mode string) {
|
|||
log.Fatalf("failed to remove: %v", err)
|
||||
}
|
||||
|
||||
// http://pubs.opengroup.org/onlinepubs/7908799/xsh/open.html
|
||||
// The result of using O_TRUNC with O_RDONLY is undefined.
|
||||
// Linux seems to truncate the file, but we prefer to return EINVAL
|
||||
if (flags&accessModeMask) == os.O_RDONLY && flags&os.O_TRUNC != 0 {
|
||||
openNonExistentErr = os.ErrInvalid // EINVAL
|
||||
readNonExistentErr = nil
|
||||
writeNonExistentErr = nil
|
||||
openExistingErr = os.ErrInvalid // EINVAL
|
||||
readExistingErr = nil
|
||||
writeExistingErr = nil
|
||||
contents = "hello"
|
||||
}
|
||||
|
||||
// output the struct
|
||||
fmt.Printf(`{
|
||||
flags: %s,
|
||||
|
@ -147,7 +169,7 @@ func test(fileName string, flags int, mode string) {
|
|||
}
|
||||
|
||||
func main() {
|
||||
fmt.Printf(`// data generated by go run make_open_tests.go | gofmt > open_test.go
|
||||
fmt.Printf(`// AUTO GENERATED by make_open_tests.go - DO NOT EDIT - use go generate to rebuild
|
||||
|
||||
package vfs
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// data generated by go run make_open_tests.go | gofmt > open_test.go
|
||||
// AUTO GENERATED by make_open_tests.go - DO NOT EDIT - use go generate to rebuild
|
||||
|
||||
package vfs
|
||||
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
// error conditions have ocurred. It may also return general errors
|
||||
// it receives. It tries to use os Error values (eg os.ErrExist)
|
||||
// where possible.
|
||||
|
||||
//go:generate sh -c "go run make_open_tests.go | gofmt > open_test.go"
|
||||
|
||||
package vfs
|
||||
|
||||
import (
|
||||
|
|
Loading…
Reference in a new issue