summaryrefslogtreecommitdiff
path: root/src/pkg/os/os_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/os/os_test.go')
-rw-r--r--src/pkg/os/os_test.go34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/pkg/os/os_test.go b/src/pkg/os/os_test.go
index 551b86508..65475c118 100644
--- a/src/pkg/os/os_test.go
+++ b/src/pkg/os/os_test.go
@@ -567,8 +567,8 @@ func checkSize(t *testing.T, f *File, size int64) {
}
}
-func TestTruncate(t *testing.T) {
- f := newFile("TestTruncate", t)
+func TestFTruncate(t *testing.T) {
+ f := newFile("TestFTruncate", t)
defer Remove(f.Name())
defer f.Close()
@@ -585,6 +585,24 @@ func TestTruncate(t *testing.T) {
checkSize(t, f, 13+9) // wrote at offset past where hello, world was.
}
+func TestTruncate(t *testing.T) {
+ f := newFile("TestTruncate", t)
+ defer Remove(f.Name())
+ defer f.Close()
+
+ checkSize(t, f, 0)
+ f.Write([]byte("hello, world\n"))
+ checkSize(t, f, 13)
+ Truncate(f.Name(), 10)
+ checkSize(t, f, 10)
+ Truncate(f.Name(), 1024)
+ checkSize(t, f, 1024)
+ Truncate(f.Name(), 0)
+ checkSize(t, f, 0)
+ f.Write([]byte("surprise!"))
+ checkSize(t, f, 13+9) // wrote at offset past where hello, world was.
+}
+
// Use TempDir() to make sure we're on a local file system,
// so that timings are not distorted by latency and caching.
// On NFS, timings can be off due to caching of meta-data on
@@ -886,6 +904,18 @@ func TestAppend(t *testing.T) {
if s != "new|append" {
t.Fatalf("writeFile: have %q want %q", s, "new|append")
}
+ s = writeFile(t, f, O_CREATE|O_APPEND|O_RDWR, "|append")
+ if s != "new|append|append" {
+ t.Fatalf("writeFile: have %q want %q", s, "new|append|append")
+ }
+ err := Remove(f)
+ if err != nil {
+ t.Fatalf("Remove: %v", err)
+ }
+ s = writeFile(t, f, O_CREATE|O_APPEND|O_RDWR, "new&append")
+ if s != "new&append" {
+ t.Fatalf("writeFile: have %q want %q", s, "new&append")
+ }
}
func TestStatDirWithTrailingSlash(t *testing.T) {