mirror of
https://github.com/ddworken/hishtory.git
synced 2025-08-17 10:21:30 +02:00
Fix testPresaving/bash by calling SetSid to prevent SIGTTIN signal from killing the test
This commit is contained in:
@ -11,6 +11,7 @@ import (
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"testing"
|
||||
|
||||
"github.com/DataDog/datadog-go/statsd"
|
||||
@ -27,6 +28,7 @@ var GLOBAL_STATSD *statsd.Client
|
||||
type shellTester interface {
|
||||
RunInteractiveShell(t testing.TB, script string) string
|
||||
RunInteractiveShellRelaxed(t testing.TB, script string) (string, error)
|
||||
RunInteractiveShellBackground(t testing.TB, script string) error
|
||||
ShellName() string
|
||||
}
|
||||
type bashTester struct {
|
||||
@ -58,6 +60,16 @@ func (b bashTester) RunInteractiveShellRelaxed(t testing.TB, script string) (str
|
||||
return outStr, nil
|
||||
}
|
||||
|
||||
func (b bashTester) RunInteractiveShellBackground(t testing.TB, script string) error {
|
||||
cmd := exec.Command("bash", "-i")
|
||||
// SetSid: true is required to prevent SIGTTIN signal killing the entire test
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{Setsid: true}
|
||||
cmd.Stdin = strings.NewReader(script)
|
||||
cmd.Stdout = nil
|
||||
cmd.Stderr = nil
|
||||
return cmd.Start()
|
||||
}
|
||||
|
||||
func (b bashTester) ShellName() string {
|
||||
return "bash"
|
||||
}
|
||||
@ -88,6 +100,14 @@ func (z zshTester) RunInteractiveShellRelaxed(t testing.TB, script string) (stri
|
||||
return outStr, nil
|
||||
}
|
||||
|
||||
func (z zshTester) RunInteractiveShellBackground(t testing.TB, script string) error {
|
||||
cmd := exec.Command("zsh", "-is")
|
||||
cmd.Stdin = strings.NewReader(script)
|
||||
cmd.Stdout = nil
|
||||
cmd.Stderr = nil
|
||||
return cmd.Start()
|
||||
}
|
||||
|
||||
func (z zshTester) ShellName() string {
|
||||
return "zsh"
|
||||
}
|
||||
|
Reference in New Issue
Block a user