elvish/pkg/eval/builtin_fn_misc_unix_test.go
Qi Xiao f7cb556d9b Require Go 1.18.
- Run "go fix" to remove legacy build tags

- Use staticcheck@master until it has a release that supports Go 1.18

- Turn off autocrlf for Windows tasks
2022-03-20 15:28:23 +00:00

39 lines
936 B
Go

//go:build !windows && !plan9 && !js
package eval_test
import (
"os"
"testing"
"time"
. "src.elv.sh/pkg/eval"
"src.elv.sh/pkg/testutil"
. "src.elv.sh/pkg/eval/evaltest"
)
func interruptedTimeAfterMock(fm *Frame, d time.Duration) <-chan time.Time {
if d == time.Second {
// Special-case intended to verity that a sleep can be interrupted.
go func() {
// Wait a little bit to ensure that the control flow in the "sleep"
// function is in the select block when the interrupt is sent.
time.Sleep(testutil.Scaled(time.Millisecond))
p, _ := os.FindProcess(os.Getpid())
p.Signal(os.Interrupt)
}()
return time.After(1 * time.Second)
}
panic("unreachable")
}
func TestInterruptedSleep(t *testing.T) {
TimeAfter = interruptedTimeAfterMock
Test(t,
// Special-case that should result in the sleep being interrupted. See
// timeAfterMock above.
That(`sleep 1s`).Throws(ErrInterrupted, "sleep 1s"),
)
}