forked from cucumber/godog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
52 lines (44 loc) · 955 Bytes
/
main.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
package main
import (
"fmt"
"os"
"os/exec"
"time"
"github.com/DATA-DOG/godog"
"github.com/shiena/ansicolor"
)
func main() {
// will support Ansi colors for windows
stdout := ansicolor.NewAnsiColorWriter(os.Stdout)
builtFile := fmt.Sprintf("%s/%dgodog.go", os.TempDir(), time.Now().UnixNano())
buf, err := godog.Build()
if err != nil {
os.Remove(builtFile)
panic(err)
}
w, err := os.Create(builtFile)
if err != nil {
os.Remove(builtFile)
panic(err)
}
_, err = w.Write(buf)
if err != nil {
os.Remove(builtFile)
panic(err)
}
w.Close()
cmd := exec.Command("go")
cmd.Args = append([]string{"go", "run", builtFile}, os.Args[1:]...)
cmd.Stdout = stdout
cmd.Stderr = stdout
err = cmd.Run()
switch err.(type) {
case *exec.ExitError:
// then there is a suite error, we need to provide a
// way to see the built file and do not remove it here
os.Exit(1)
case *exec.Error:
os.Remove(builtFile)
panic(err)
}
}