mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-11-27 15:01:22 +08:00
pkg/shell: Test signal handling.
This commit is contained in:
parent
fbf0bfc13b
commit
4fb96d515c
|
@ -53,6 +53,16 @@ func ReadAllAndClose(r io.ReadCloser) []byte {
|
|||
return v
|
||||
}
|
||||
|
||||
// ReadFile wraps os.ReadFile.
|
||||
func ReadFile(fname string) []byte {
|
||||
return OK1(os.ReadFile(fname))
|
||||
}
|
||||
|
||||
// ReadFileString converts the result of ReadFile to a string.
|
||||
func ReadFileString(fname string) string {
|
||||
return string(ReadFile(fname))
|
||||
}
|
||||
|
||||
// MkdirAll calls os.MkdirAll for each argument.
|
||||
func MkdirAll(names ...string) {
|
||||
for _, name := range names {
|
||||
|
|
|
@ -70,7 +70,9 @@ func Run(fds [3]*os.File, args []string, p Program) int {
|
|||
|
||||
if log != "" {
|
||||
err = logutil.SetOutputFile(log)
|
||||
if err != nil {
|
||||
if err == nil {
|
||||
defer logutil.SetOutput(io.Discard)
|
||||
} else {
|
||||
fmt.Fprintln(fds[2], err)
|
||||
}
|
||||
}
|
||||
|
|
28
pkg/shell/shell_unix_test.go
Normal file
28
pkg/shell/shell_unix_test.go
Normal file
|
@ -0,0 +1,28 @@
|
|||
package shell
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"src.elv.sh/pkg/must"
|
||||
. "src.elv.sh/pkg/prog/progtest"
|
||||
"src.elv.sh/pkg/testutil"
|
||||
)
|
||||
|
||||
func TestSignal_USR1(t *testing.T) {
|
||||
Test(t, &Program{},
|
||||
ThatElvish("-c", "kill -USR1 $pid").WritesStderrContaining("src.elv.sh/pkg/shell"))
|
||||
}
|
||||
|
||||
func TestSignal_Ignored(t *testing.T) {
|
||||
testutil.InTempDir(t)
|
||||
|
||||
Test(t, &Program{},
|
||||
ThatElvish("-log", "logCHLD", "-c", "kill -CHLD $pid").DoesNothing())
|
||||
|
||||
wantLogCHLD := "signal " + syscall.SIGCHLD.String()
|
||||
if logCHLD := must.ReadFileString("logCHLD"); !strings.Contains(logCHLD, wantLogCHLD) {
|
||||
t.Errorf("want log when getting SIGCHLD to contain %q; got:\n%s", wantLogCHLD, logCHLD)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user