Этот коммит содержится в:
gedi 2015-06-30 15:17:41 +03:00
родитель 5829b59e80
коммит b2e7b20045

Просмотреть файл

@ -10,43 +10,44 @@ import (
"github.com/shiena/ansicolor" "github.com/shiena/ansicolor"
) )
func main() { func buildAndRun() error {
// will support Ansi colors for windows // will support Ansi colors for windows
stdout := ansicolor.NewAnsiColorWriter(os.Stdout) stdout := ansicolor.NewAnsiColorWriter(os.Stdout)
builtFile := fmt.Sprintf("%s/%dgodog.go", os.TempDir(), time.Now().UnixNano()) builtFile := fmt.Sprintf("%s/%dgodog.go", os.TempDir(), time.Now().UnixNano())
// @TODO: then there is a suite error or panic, it may
// be interesting to see the built file. But we
// even cannot determine the status of exit error
// so leaving it for the future
defer os.Remove(builtFile)
buf, err := godog.Build() buf, err := godog.Build()
if err != nil { if err != nil {
os.Remove(builtFile) return err
panic(err)
} }
w, err := os.Create(builtFile) w, err := os.Create(builtFile)
if err != nil { if err != nil {
os.Remove(builtFile) return err
panic(err)
} }
_, err = w.Write(buf) if _, err = w.Write(buf); err != nil {
if err != nil { w.Close()
os.Remove(builtFile) return err
panic(err)
} }
w.Close() w.Close()
cmd := exec.Command("go") cmd := exec.Command("go", append([]string{"run", builtFile}, os.Args[1:]...)...)
cmd.Args = append([]string{"go", "run", builtFile}, os.Args[1:]...)
cmd.Stdout = stdout cmd.Stdout = stdout
cmd.Stderr = stdout cmd.Stderr = stdout
err = cmd.Run() return cmd.Run()
switch err.(type) { }
func main() {
switch err := buildAndRun().(type) {
case nil:
case *exec.ExitError: 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) os.Exit(1)
case *exec.Error: default:
os.Remove(builtFile)
panic(err) panic(err)
} }
} }