Add the ability to keep the executable - reflecting **go build -o dest** and skipping execution (as suggested by Gediminas Morkevicius).
Этот коммит содержится в:
родитель
351a1adaf9
коммит
9264cba300
3 изменённых файлов: 34 добавлений и 7 удалений
|
@ -18,7 +18,7 @@ var parsedStatus int
|
|||
var stdout = io.Writer(os.Stdout)
|
||||
var stderr = statusOutputFilter(os.Stderr)
|
||||
|
||||
func buildAndRun() (int, error) {
|
||||
func buildAndRun(output string) (int, error) {
|
||||
var status int
|
||||
|
||||
bin, err := godog.Build()
|
||||
|
@ -26,6 +26,15 @@ func buildAndRun() (int, error) {
|
|||
return 1, err
|
||||
}
|
||||
defer os.Remove(bin)
|
||||
//output the generated binary file and exit if the output option was provided
|
||||
if output != ""{
|
||||
err = Copy(output,bin)
|
||||
status := 0
|
||||
if err != nil {
|
||||
status = 1
|
||||
}
|
||||
return status, err
|
||||
}
|
||||
|
||||
cmd := exec.Command(bin, os.Args[1:]...)
|
||||
cmd.Stdout = stdout
|
||||
|
@ -57,10 +66,10 @@ func buildAndRun() (int, error) {
|
|||
|
||||
func main() {
|
||||
var vers, defs, sof, noclr bool
|
||||
var tags, format string
|
||||
var tags, format, output string
|
||||
var concurrency int
|
||||
|
||||
flagSet := godog.FlagSet(&format, &tags, &defs, &sof, &noclr, &concurrency)
|
||||
flagSet := godog.FlagSet(&format, &tags, &defs, &sof, &noclr, &concurrency, &output)
|
||||
flagSet.BoolVar(&vers, "version", false, "Show current version.")
|
||||
|
||||
err := flagSet.Parse(os.Args[1:])
|
||||
|
@ -82,7 +91,7 @@ func main() {
|
|||
os.Exit(0) // should it be 0?
|
||||
}
|
||||
|
||||
status, err := buildAndRun()
|
||||
status, err := buildAndRun(output)
|
||||
if err != nil {
|
||||
fmt.Fprintln(stderr, err)
|
||||
os.Exit(1)
|
||||
|
@ -111,3 +120,16 @@ type writerFunc func([]byte) (int, error)
|
|||
func (w writerFunc) Write(b []byte) (int, error) {
|
||||
return w(b)
|
||||
}
|
||||
|
||||
func Copy(dst, src string) error {
|
||||
in, err := os.Open(src)
|
||||
if err != nil { return err }
|
||||
defer in.Close()
|
||||
out, err := os.Create(dst)
|
||||
if err != nil { return err }
|
||||
defer out.Close()
|
||||
_, err = io.Copy(out, in)
|
||||
cerr := out.Close()
|
||||
if err != nil { return err }
|
||||
return cerr
|
||||
}
|
||||
|
|
7
flags.go
7
flags.go
|
@ -23,8 +23,11 @@ var descTagsOption = "Filter scenarios by tags. Expression can be:\n" +
|
|||
s(4) + "- " + cl(`"@wip && ~@new"`, yellow) + ": run wip scenarios, but exclude new\n" +
|
||||
s(4) + "- " + cl(`"@wip,@undone"`, yellow) + ": run wip or undone scenarios"
|
||||
|
||||
var descOutputOption = "Output the temporary test runner executable:\n" +
|
||||
s(4) + "- supply the name to give the executable " + cl("test_features.exe", yellow) + "\n"
|
||||
|
||||
// FlagSet allows to manage flags by external suite runner
|
||||
func FlagSet(format, tags *string, defs, sof, noclr *bool, cr *int) *flag.FlagSet {
|
||||
func FlagSet(format, tags *string, defs, sof, noclr *bool, cr *int, output *string) *flag.FlagSet {
|
||||
descFormatOption := "How to format tests output. Available formats:\n"
|
||||
for _, f := range formatters {
|
||||
descFormatOption += s(4) + "- " + cl(f.name, yellow) + ": " + f.description + "\n"
|
||||
|
@ -42,6 +45,8 @@ func FlagSet(format, tags *string, defs, sof, noclr *bool, cr *int) *flag.FlagSe
|
|||
set.BoolVar(defs, "d", false, "Print all available step definitions.")
|
||||
set.BoolVar(sof, "stop-on-failure", false, "Stop processing on first failed scenario.")
|
||||
set.BoolVar(noclr, "no-colors", false, "Disable ansi colors.")
|
||||
set.StringVar(output, "output", "", descOutputOption)
|
||||
set.StringVar(output, "o", "", descOutputOption)
|
||||
set.Usage = usage(set)
|
||||
return set
|
||||
}
|
||||
|
|
4
run.go
4
run.go
|
@ -74,9 +74,9 @@ func (r *runner) run() (failed bool) {
|
|||
// the step definitions and event handlers.
|
||||
func Run(contextInitializer func(suite *Suite)) int {
|
||||
var defs, sof, noclr bool
|
||||
var tags, format string
|
||||
var tags, format, output string
|
||||
var concurrency int
|
||||
flagSet := FlagSet(&format, &tags, &defs, &sof, &noclr, &concurrency)
|
||||
flagSet := FlagSet(&format, &tags, &defs, &sof, &noclr, &concurrency, &output)
|
||||
err := flagSet.Parse(os.Args[1:])
|
||||
fatal(err)
|
||||
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче