Skip to content

Commit

Permalink
testscript: use unix.CloneFile on MacOs
Browse files Browse the repository at this point in the history
To fix unexpected errors of type:

```
[signal: killed]
FAIL: testscripts/myecho.txt:1: unexpected command failure
```

Fixes rogpeppe#200
  • Loading branch information
bep authored and ldemailly committed Sep 6, 2024
1 parent cf3b5d7 commit fd1755f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion clonefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package testscript

import "os"

// cloneFile makes a clone of a file via a hard link.
// cloneFile creates to as a hard link to the from file.
func cloneFile(from, to string) error {
return os.Link(from, to)
}
2 changes: 1 addition & 1 deletion clonefile_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package testscript

import "golang.org/x/sys/unix"

// cloneFile makes a clone of a file via MacOS's `clonefile` syscall.
// cloneFile clones the file from to the file to.
func cloneFile(from, to string) error {
return unix.Clonefile(from, to, 0)
}
4 changes: 1 addition & 3 deletions clonefile_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ package testscript

import "fmt"

// cloneFile does not attempt anything on Windows, as hard links on it have
// led to "access denied" errors when deleting files at the end of a test.
// We haven't tested platforms like plan9 or wasm/wasi.
// We don't want to use hard links on Windows, as that can lead to "access denied" errors when removing.
func cloneFile(from, to string) error {
return fmt.Errorf("unavailable")
}
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module fortio.org/testscript
go 1.20

require (
golang.org/x/sys v0.8.0
golang.org/x/tools v0.8.0
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f
golang.org/x/tools v0.1.12
)
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y=
golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f h1:v4INt8xihDGvnrfjMDVXGxw9wrfxYyCjk0KbXjhR55s=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

0 comments on commit fd1755f

Please sign in to comment.