-
Notifications
You must be signed in to change notification settings - Fork 1
/
runner.go
64 lines (56 loc) · 1.18 KB
/
runner.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"encoding/json"
"fmt"
"os"
"os/exec"
"runtime"
)
type testRunner struct {
cmd *exec.Cmd
}
// Looks for a runner configuration inside the runner directory
// finds the runner configuration matching to the manifest and executes the commands for the current OS
func startRunner(manifest *manifest) (*testRunner, error) {
type runner struct {
Name string
Command struct {
Windows string
Linux string
Darwin string
}
}
var r runner
contents := readFileContents(fmt.Sprintf("runner/%s.json", manifest.Language))
err := json.Unmarshal([]byte(contents), &r)
if err != nil {
return nil, err
}
command := ""
switch runtime.GOOS {
case "windows":
command = r.Command.Windows
break
case "darwin":
command = r.Command.Darwin
break
default:
command = r.Command.Linux
break
}
cmd := exec.Command(command)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Start()
if err != nil {
return nil, err
}
// Wait for the process to exit so we will get a detailed error message
go func() {
err := cmd.Wait()
if err != nil {
fmt.Printf("Runner exited with error: %s\n", err.Error())
}
}()
return &testRunner{cmd: cmd}, nil
}