mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 09:57:51 +08:00
f7cb556d9b
- 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
48 lines
933 B
Go
48 lines
933 B
Go
//go:build !windows && !plan9
|
|
|
|
package cli_test
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"golang.org/x/sys/unix"
|
|
. "src.elv.sh/pkg/cli"
|
|
)
|
|
|
|
func TestTTYSignal(t *testing.T) {
|
|
tty := NewTTY(os.Stdin, os.Stderr)
|
|
sigch := tty.NotifySignals()
|
|
|
|
err := unix.Kill(unix.Getpid(), unix.SIGUSR1)
|
|
if err != nil {
|
|
t.Skip("cannot send SIGUSR1 to myself:", err)
|
|
}
|
|
|
|
if sig := nextSig(sigch); sig != unix.SIGUSR1 {
|
|
t.Errorf("Got signal %v, want SIGUSR1", sig)
|
|
}
|
|
|
|
tty.StopSignals()
|
|
|
|
err = unix.Kill(unix.Getpid(), unix.SIGUSR2)
|
|
if err != nil {
|
|
t.Skip("cannot send SIGUSR2 to myself:", err)
|
|
}
|
|
|
|
if sig := nextSig(sigch); sig != nil {
|
|
t.Errorf("Got signal %v, want nil", sig)
|
|
}
|
|
}
|
|
|
|
// Gets the next signal from the channel, ignoring all SIGURG generated by the
|
|
// Go runtime. See https://github.com/golang/go/issues/37942.
|
|
func nextSig(sigch <-chan os.Signal) os.Signal {
|
|
for {
|
|
sig := <-sigch
|
|
if sig != unix.SIGURG {
|
|
return sig
|
|
}
|
|
}
|
|
}
|