From b45cfa39b3016d216647177e8a03002e24fae408 Mon Sep 17 00:00:00 2001 From: Ben B Date: Sun, 7 Jun 2020 21:06:58 +0200 Subject: [PATCH] Forward OS signals to go test (#15) --- main.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/main.go b/main.go index 2cbccfb..b22b0c7 100644 --- a/main.go +++ b/main.go @@ -13,6 +13,7 @@ import ( "log" "os" "os/exec" + "os/signal" "strings" "sync" "syscall" @@ -50,6 +51,24 @@ func gotest(args []string) int { go consume(&wg, r) + sigc := make(chan os.Signal) + done := make(chan struct{}) + defer func() { + done <- struct{}{} + }() + signal.Notify(sigc) + + go func() { + for { + select { + case sig := <-sigc: + cmd.Process.Signal(sig) + case <-done: + return + } + } + }() + if err := cmd.Run(); err != nil { if ws, ok := cmd.ProcessState.Sys().(syscall.WaitStatus); ok { return ws.ExitStatus()