From 76226f19f52515c12480f4c36f15d4edf7120d0e Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 18 Mar 2015 16:16:24 +1100 Subject: [PATCH] Updated PosixTest.WriteStartsPastEndOfFile_AppendMode for Linux. --- samples/memfs/posix_test.go | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/samples/memfs/posix_test.go b/samples/memfs/posix_test.go index e11dc84..48fe75e 100644 --- a/samples/memfs/posix_test.go +++ b/samples/memfs/posix_test.go @@ -22,6 +22,7 @@ import ( "io/ioutil" "os" "path" + "runtime" "testing" . "github.com/jacobsa/oglematchers" @@ -183,9 +184,22 @@ func (t *PosixTest) WriteStartsPastEndOfFile_AppendMode() { AssertEq(3, n) // Read the full contents of the file. + // + // Linux's support for pwrite is buggy; the pwrite(2) man page says this: + // + // POSIX requires that opening a file with the O_APPEND flag should have + // no affect on the location at which pwrite() writes data. However, on + // Linux, if a file is opened with O_APPEND, pwrite() appends data to + // the end of the file, regardless of the value of offset. + // contents, err := ioutil.ReadFile(f.Name()) AssertEq(nil, err) - ExpectEq("111\x00\x00\x00222", string(contents)) + + if runtime.GOOS == "linux" { + ExpectEq("111222", string(contents)) + } else { + ExpectEq("111\x00\x00\x00222", string(contents)) + } } func (t *PosixTest) WriteAtDoesntChangeOffset_NotAppendMode() { @@ -300,7 +314,12 @@ func (t *PosixTest) AppendMode() { // So we allow either the POSIX result or the Linux result. n, err = f.ReadAt(buf, 0) AssertEq(io.EOF, err) - ExpectThat(string(buf[:n]), AnyOf("Hello, world!", "Jello, world!H")) + + if runtime.GOOS == "linux" { + ExpectEq("Jello, world!H", string(buf[:n])) + } else { + ExpectEq("Hello, world!", string(buf[:n])) + } } func (t *PosixTest) ReadsPastEndOfFile() {