forked from tinygo-org/tinygo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
116 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//go:build darwin || (linux && !baremetal && !js && !wasi) | ||
|
||
// Copyright 2024 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package os_test | ||
|
||
import ( | ||
. "os" | ||
"path/filepath" | ||
"runtime" | ||
"testing" | ||
) | ||
|
||
func TestTruncate(t *testing.T) { | ||
// Truncate is not supported on Windows or wasi at the moment | ||
if runtime.GOOS == "windows" || runtime.GOOS == "wasip1" || runtime.GOOS == "wasip2" { | ||
t.Logf("skipping test on %s", runtime.GOOS) | ||
return | ||
} | ||
|
||
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) | ||
} | ||
defer fd.Close() | ||
|
||
// 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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters