Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions cmd/go-mutesting/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"context"
"crypto/md5"
"fmt"
"go/ast"
Expand All @@ -17,6 +18,7 @@ import (
"regexp"
"strings"
"syscall"
"time"

"gopkg.in/yaml.v3"

Expand Down Expand Up @@ -515,7 +517,10 @@ func mutateExec(

console.Debug(opts, "Execute %q for mutation", opts.Exec.Exec)

execCommand := exec.Command(execs[0], execs[1:]...)
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(opts.Exec.Timeout)*time.Second)
defer cancel()

execCommand := exec.CommandContext(ctx, execs[0], execs[1:]...)

execCommand.Stderr = os.Stderr
execCommand.Stdout = os.Stdout
Expand All @@ -532,17 +537,12 @@ func mutateExec(
execCommand.Env = append(execCommand.Env, "TEST_RECURSIVE=true")
}

err := execCommand.Start()
if err != nil {
panic(err)
}

// TODO timeout here

err = execCommand.Wait()
err := execCommand.Run()

if err == nil {
execExitCode = 0
} else if ctx.Err() == context.DeadlineExceeded {
execExitCode = 2
} else if e, ok := err.(*exec.ExitError); ok {
execExitCode = e.Sys().(syscall.WaitStatus).ExitStatus()
} else {
Expand Down