Skip to content

Commit

Permalink
--format junit:result.xml will now write to result.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
lonnblad committed Jul 8, 2020
1 parent e6223ba commit 4a76a6e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
8 changes: 4 additions & 4 deletions godog.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 youre 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:
Expand All @@ -30,9 +30,9 @@ Example:
foo
"""
Now, wouldnt it be cool if something could read this sentence and use it to actually
run a test against the ls command? Hey, thats exactly what this package does!
As youll 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.
*/
Expand Down
23 changes: 21 additions & 2 deletions run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand All @@ -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(
Expand Down

0 comments on commit 4a76a6e

Please sign in to comment.