Skip to content

Commit

Permalink
adjust test error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
leongross committed Apr 4, 2024
1 parent d910beb commit c51e9c5
Showing 1 changed file with 39 additions and 36 deletions.
75 changes: 39 additions & 36 deletions src/os/truncate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,45 +9,48 @@ package os_test
import (
. "os"
"path/filepath"
"runtime"
"testing"
)

func TestTruncate(t *testing.T) {
tmpDir := t.TempDir()
file := filepath.Join(tmpDir, "truncate_0x100")

fd, err := Create(file)
if err != nil {
t.Fatalf("create %q: %s", file, err)
}

// truncate up to 0x100
if err := fd.Truncate(0x100); err != nil {
t.Fatalf("truncate %q: %s", file, err)
}

// check if size is 0x100
fi, err := Stat(file)
if err != nil {
t.Fatalf("stat %q: %s", file, err)
}

if fi.Size() != 0x100 {
t.Fatalf("size of %q is %d; want 0x100", file, fi.Size())
}

// truncate down to 0x80
if err := fd.Truncate(0x80); err != nil {
t.Fatalf("truncate %q: %s", file, err)
}

// check if size is 0x80
fi, err = Stat(file)
if err != nil {
t.Fatalf("stat %q: %s", file, err)
}

if fi.Size() != 0x80 {
t.Fatalf("size of %q is %d; want 0x80", file, fi.Size())
if runtime.GOOS != "windows" {
tmpDir := t.TempDir()
file := filepath.Join(tmpDir, "truncate_test")

fd, err := Create(file)
if err != nil {
t.Fatalf("create %q: got %v, want nil", file, err)
}

// truncate up to 0x100
if err := fd.Truncate(0x100); err != nil {
t.Fatalf("truncate %q: got %v, want nil", file, err)
}

// check if size is 0x100
fi, err := Stat(file)
if err != nil {
t.Fatalf("stat %q: got %v, want nil", file, err)
}

if fi.Size() != 0x100 {
t.Fatalf("size of %q is %d; want 0x100", file, fi.Size())
}

// truncate down to 0x80
if err := fd.Truncate(0x80); err != nil {
t.Fatalf("truncate %q: got %v, want nil", file, err)
}

// check if size is 0x80
fi, err = Stat(file)
if err != nil {
t.Fatalf("stat %q: got %v, want nil", file, err)
}

if fi.Size() != 0x80 {
t.Fatalf("size of %q is %d; want 0x80", file, fi.Size())
}
}
}

0 comments on commit c51e9c5

Please sign in to comment.