From 4a76a6e8d681cb1bb18f6ee5717865e74609d740 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20L=C3=B6nnblad?= Date: Wed, 8 Jul 2020 21:33:22 +0200 Subject: [PATCH] --format junit:result.xml will now write to result.xml --- godog.go | 8 ++++---- run.go | 23 +++++++++++++++++++++-- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/godog.go b/godog.go index 895032e4..d3bdb960 100644 --- a/godog.go +++ b/godog.go @@ -10,7 +10,7 @@ Godog acts similar compared to go test command. It uses go compiler and linker tool in order to produce test executable. Godog contexts needs to be exported same as Test functions for go test. -For example, imagine you’re about to create the famous UNIX ls command. +For example, imagine you're about to create the famous UNIX ls command. Before you begin, you describe how the feature should work, see the example below.. Example: @@ -30,9 +30,9 @@ Example: foo """ -Now, wouldn’t it be cool if something could read this sentence and use it to actually -run a test against the ls command? Hey, that’s exactly what this package does! -As you’ll see, Godog is easy to learn, quick to use, and will put the fun back into tests. +Now, wouldn't it be cool if something could read this sentence and use it to actually +run a test against the ls command? Hey, that's exactly what this package does! +As you'll see, Godog is easy to learn, quick to use, and will put the fun back into tests. Godog was inspired by Behat and Cucumber the above description is taken from it's documentation. */ diff --git a/run.go b/run.go index de2a0c56..8d84cebb 100644 --- a/run.go +++ b/run.go @@ -15,6 +15,7 @@ import ( "github.com/cucumber/messages-go/v10" "github.com/cucumber/godog/colors" + "github.com/cucumber/godog/formatters" "github.com/cucumber/godog/internal/models" "github.com/cucumber/godog/internal/parser" "github.com/cucumber/godog/internal/storage" @@ -140,6 +141,24 @@ func runWithOptions(suiteName string, runner runner, opt Options) int { output = opt.Output } + if formatterParts := strings.Split(opt.Format, ":"); len(formatterParts) > 1 { + f, err := os.Create(formatterParts[1]) + if err != nil { + err = fmt.Errorf( + `couldn't create file with name: "%s", error: %s`, + formatterParts[1], err.Error(), + ) + fmt.Fprintln(os.Stderr, err) + + return exitOptionError + } + + defer f.Close() + + output = f + opt.Format = formatterParts[0] + } + if opt.NoColors { output = colors.Uncolored(output) } else { @@ -165,10 +184,10 @@ func runWithOptions(suiteName string, runner runner, opt Options) int { opt.Concurrency = 1 } - formatter := FindFmt(opt.Format) + formatter := formatters.FindFmt(opt.Format) if nil == formatter { var names []string - for name := range AvailableFormatters() { + for name := range formatters.AvailableFormatters() { names = append(names, name) } fmt.Fprintln(os.Stderr, fmt.Errorf(