summaryrefslogtreecommitdiff
path: root/integrationtests/commons.go
diff options
context:
space:
mode:
Diffstat (limited to 'integrationtests/commons.go')
-rw-r--r--integrationtests/commons.go33
1 files changed, 23 insertions, 10 deletions
diff --git a/integrationtests/commons.go b/integrationtests/commons.go
index f789322..f96b532 100644
--- a/integrationtests/commons.go
+++ b/integrationtests/commons.go
@@ -2,6 +2,7 @@ package integrationtests
import (
"bufio"
+ "context"
"crypto/sha256"
"encoding/base64"
"fmt"
@@ -9,29 +10,41 @@ import (
"os"
"os/exec"
"strings"
+ "syscall"
"testing"
)
-func runCommand(t *testing.T, cmd string, args []string, stdoutFile string) error {
+func runCommand(t *testing.T, cmd string, args []string, stdoutFile string) (int, error) {
+ return runCommandContext(t, context.TODO(), cmd, args, stdoutFile)
+}
+
+func runCommandContext(t *testing.T, ctx context.Context, cmd string, args []string, stdoutFile string) (int, error) {
if _, err := os.Stat(cmd); err != nil {
- return fmt.Errorf("No such binary %s, please compile first (%v)", cmd, err)
+ return -1, fmt.Errorf("No such binary %s, please compile first (%v)", cmd, err)
}
- t.Log("Executing command:", cmd, strings.Join(args, " "))
- bytes, err := exec.Command(cmd, args...).Output()
- if err != nil {
- return err
- }
+ t.Log("Running command:", cmd, strings.Join(args, " "))
+ bytes, cmdErr := exec.CommandContext(ctx, cmd, args...).Output()
t.Log("Writing stdout to file", stdoutFile)
fd, err := os.Create(stdoutFile)
if err != nil {
- return err
+ return -1, err
}
+ defer fd.Close()
fd.Write(bytes)
- fd.Close()
- return nil
+ return exitCodeFromError(cmdErr), err
+}
+
+func exitCodeFromError(err error) int {
+ if err != nil {
+ if exitError, ok := err.(*exec.ExitError); ok {
+ ws := exitError.Sys().(syscall.WaitStatus)
+ return ws.ExitStatus()
+ }
+ }
+ return 0
}
// Checks whether both files have the same lines (order doesn't matter)