From 83675453b7975435f74122191a2422cdc2b52fb1 Mon Sep 17 00:00:00 2001 From: gedi Date: Thu, 27 Apr 2017 17:19:27 +0300 Subject: [PATCH] runs tests with randomized scenario order, adds verbose mode --- .travis.yml | 2 +- Makefile | 7 ++++++- flags.go | 2 +- suite_test.go | 18 +++++++++++++++--- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4f7ce6a..a87782d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ go: - 1.5 - 1.6 - 1.7 - - tip + - 1.8 go_import_path: github.com/DATA-DOG/godog diff --git a/Makefile b/Makefile index 042067d..65ea931 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: test gherkin bump +.PHONY: test gherkin bump cover VERS := $(shell grep 'const Version' -m 1 godog.go | awk -F\" '{print $$2}') @@ -25,3 +25,8 @@ bump: @sed -i.bak 's/$(VERS)/$(VERSION)/g' godog.go @sed -i.bak 's/$(VERS)/$(VERSION)/g' examples/api/version.feature @find . -name '*.bak' | xargs rm + +cover: + go test -race -coverprofile=coverage.txt + go tool cover -html=coverage.txt + rm coverage.txt diff --git a/flags.go b/flags.go index 99e6025..9740e14 100644 --- a/flags.go +++ b/flags.go @@ -35,7 +35,7 @@ var descRandomOption = "Randomly shuffle the scenario execution order.\n" + // FlagSet allows to manage flags by external suite runner func FlagSet(opt *Options) *flag.FlagSet { - descFormatOption := "How to format tests output. Available formats:\n" + descFormatOption := "How to format tests output. Built-in formats:\n" // @TODO: sort by name for name, desc := range AvailableFormatters() { descFormatOption += s(4) + "- " + colors.Yellow(name) + ": " + desc + "\n" diff --git a/suite_test.go b/suite_test.go index aee19f8..1ccae7f 100644 --- a/suite_test.go +++ b/suite_test.go @@ -11,17 +11,29 @@ import ( "strconv" "strings" "testing" + "time" "github.com/DATA-DOG/godog/gherkin" ) func TestMain(m *testing.M) { - status := RunWithOptions("godogs", func(s *Suite) { + format := "progress" // non verbose mode + concurrency := 4 + + for _, arg := range os.Args[1:] { + if arg == "-test.v=true" { // go test transforms -v option - verbose mode + format = "pretty" + concurrency = 1 + break + } + } + status := RunWithOptions("godog", func(s *Suite) { SuiteContext(s) }, Options{ - Format: "progress", + Format: format, // pretty format for verbose mode, otherwise - progress Paths: []string{"features"}, - Concurrency: 4, + Concurrency: concurrency, // concurrency for verbose mode is 1 + Randomize: time.Now().UnixNano(), // randomize scenario execution order }) if st := m.Run(); st > status {