Skip to content

Commit

Permalink
Forward OS signals to go test (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
frzifus committed Jun 7, 2020
1 parent 29d015f commit b45cfa3
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"log"
"os"
"os/exec"
"os/signal"
"strings"
"sync"
"syscall"
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit b45cfa3

Please sign in to comment.