Repository: go-bdd/gobdd
Pull request #41 (2019-09-16 03:58:36)

remove gherkin output format


Patch:
diff --git a/.gitignore b/.gitignore
index f1c181e..91b8504 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
 *.dll
 *.so
 *.dylib
+*.idea/
 
 # Test binary, build with `go test -c`
 *.test
diff --git a/gobdd.go b/gobdd.go
index 3ce536e..5881045 100644
--- a/gobdd.go
+++ b/gobdd.go
@@ -15,7 +15,6 @@ import (
 
 	"github.com/cucumber/gherkin-go"
 	"github.com/go-bdd/gobdd/context"
-	"github.com/go-bdd/gobdd/reporter"
 	"github.com/go-bdd/gobdd/step"
 )
 
@@ -164,52 +163,51 @@ func (s *Suite) executeFeature(file string) error {
 
 func (s *Suite) runFeature(feature *gherkin.Feature) error {
 	log.SetOutput(ioutil.Discard)
-	r := reporter.NewReporter()
-	_ = r.Report(feature)
 	hasErrors := false
-	var bkgSteps *gherkin.Background
 
-	for _, child := range feature.Children {
-		if scenario, ok := child.(*gherkin.Scenario); ok {
-			if s.skipScenario(scenario.Tags) {
-				r.Skip(scenario)
-				continue
-			}
-			ctx := context.New()
+	s.t.Run(feature.Name, func(t *testing.T) {
+		var bkgSteps *gherkin.Background
 
-			if bkgSteps != nil {
-				s.runSteps(ctx, r, bkgSteps.Steps)
-			}
-			err := s.runScenario(ctx, scenario, bkgSteps, r)
-			if err != nil {
-				hasErrors = true
-			}
-		}
+		for _, child := range feature.Children {
+			if scenario, ok := child.(*gherkin.Scenario); ok {
+				if s.skipScenario(scenario.Tags) {
+					t.Log(fmt.Sprintf("Skipping scenario %s", scenario.Name))
+					continue
+				}
+				ctx := context.New()
 
-		if scenario, ok := child.(*gherkin.ScenarioOutline); ok {
-			if s.skipScenario(scenario.Tags) {
-				r.Skip(scenario)
-				continue
+				if bkgSteps != nil {
+					s.runSteps(ctx, t, bkgSteps.Steps)
+				}
+				err := s.runScenario(ctx, scenario, bkgSteps, t)
+				if err != nil {
+					hasErrors = true
+				}
 			}
 
-			ctx := context.New()
-			if bkgSteps != nil {
-				s.runSteps(ctx, r, bkgSteps.Steps)
-			}
+			if scenario, ok := child.(*gherkin.ScenarioOutline); ok {
+				if s.skipScenario(scenario.Tags) {
+					t.Log(fmt.Sprintf("Skipping scenario %s", scenario.Name))
+					continue
+				}
+
+				ctx := context.New()
+				if bkgSteps != nil {
+					s.runSteps(ctx, t, bkgSteps.Steps)
+				}
 
-			err := s.runScenarioOutline(scenario, r)
-			if err != nil {
-				hasErrors = true
+				err := s.runScenarioOutline(scenario, t)
+				if err != nil {
+					hasErrors = true
+				}
 			}
-		}
 
-		if bkg, ok := child.(*gherkin.Background); ok {
-			bkgSteps = bkg
-			_ = r.Report(bkg)
+			if bkg, ok := child.(*gherkin.Background); ok {
+				bkgSteps = bkg
+			}
 		}
-	}
+	})
 
-	r.GenerateReport()
 	if hasErrors {
 		return errors.New("the feature contains errors")
 	}
@@ -217,24 +215,26 @@ func (s *Suite) runFeature(feature *gherkin.Feature) error {
 	return nil
 }
 
-func (s *Suite) runScenarioOutline(outline *gherkin.ScenarioOutline, reporter *reporter.Reporter) error {
+func (s *Suite) runScenarioOutline(outline *gherkin.ScenarioOutline, t *testing.T) error {
 	s.callBeforeScenarios()
 	defer s.callAfterScenarios()
-	_ = reporter.Report(outline)
-	for _, ex := range outline.Examples {
-		if len(ex.TableBody) == 0 {
-			continue
-		}
+	t.Run(fmt.Sprintf("%s %s", outline.Keyword, outline.Name), func(t *testing.T) {
+		for _, ex := range outline.Examples {
+			if len(ex.TableBody) == 0 {
+				continue
+			}
 
-		placeholders := ex.TableHeader.Cells
-		groups := ex.TableBody
+			placeholders := ex.TableHeader.Cells
+			groups := ex.TableBody
 
-		for _, group := range groups {
-			ctx := context.New()
-			steps := s.runOutlineStep(outline, placeholders, group)
-			s.runSteps(ctx, reporter, steps)
+			for _, group := range groups {
+				ctx := context.New()
+				steps := s.runOutlineStep(outline, placeholders, group)
+				s.runSteps(ctx, t, steps)
+			}
 		}
-	}
+	})
+
 	return nil
 }
 
@@ -325,50 +325,50 @@ func (s *Suite) outlineDataTableArguments(t *gherkin.DataTable, placeholders []*
 	return tbl
 }
 
-func (s *Suite) runScenario(ctx context.Context, scenario *gherkin.Scenario, bkg *gherkin.Background, reporter *reporter.Reporter) error {
+func (s *Suite) runScenario(ctx context.Context, scenario *gherkin.Scenario, bkg *gherkin.Background, t *testing.T) error {
 	s.callBeforeScenarios()
 
 	defer s.callAfterScenarios()
-	_ = reporter.Report(scenario)
+	t.Run(scenario.Name, func(t *testing.T) {
+		if bkg != nil {
+			steps := s.getBackgroundSteps(bkg)
+			s.runSteps(ctx, t, steps)
+		}
+		s.runSteps(ctx, t, scenario.Steps)
+	})
 
-	if bkg != nil {
-		steps := s.getBackgroundSteps(bkg)
-		s.runSteps(ctx, reporter, steps)
-	}
-	s.runSteps(ctx, reporter, scenario.Steps)
 
 	return nil
 }
 
-func (s *Suite) runSteps(ctx context.Context, reporter *reporter.Reporter, steps []*gherkin.Step) {
+func (s *Suite) runSteps(ctx context.Context, t *testing.T, steps []*gherkin.Step) {
 	for _, step := range steps {
-		s.runStep(ctx, reporter, step)
+		s.runStep(ctx, t, step)
 	}
 }
 
-func (s *Suite) runStep(ctx context.Context, reporter *reporter.Reporter, step *gherkin.Step) {
+func (s *Suite) runStep(ctx context.Context, t *testing.T, step *gherkin.Step) {
 	defer func() {
 		if r := recover(); r != nil {
-			s.t.Error(r)
+			t.Error(r)
 		}
 	}()
 
 	def, err := s.findStepDef(step.Text)
 	if err != nil {
-		reporter.Undefined(step)
-		s.t.Errorf("cannot find step definition for step '%s'", step.Text)
+		t.Errorf("cannot find step definition for step: %s %s", step.Keyword, step.Text)
 		return
 	}
 
 	b := def.expr.FindSubmatch([]byte(step.Text))
 	ctx.SetParams(b[1:])
-	err = def.f(ctx)
-	if err != nil {
-		reporter.Failed(step, err)
-		s.t.Error(err)
-	} else {
-		_ = reporter.Report(step)
-	}
+	t.Run(step.Text, func(t *testing.T) {
+		err = def.f(ctx)
+		if err != nil {
+
+			t.Errorf(step.Keyword, step.Text, err)
+		}
+	})
 }
 
 func (s *Suite) findStepDef(text string) (stepDef, error) {
diff --git a/reporter/fmt.go b/reporter/fmt.go
deleted file mode 100644
index 9b0d197..0000000
--- a/reporter/fmt.go
+++ /dev/null
@@ -1,106 +0,0 @@
-package reporter
-
-import (
-	"fmt"
-
-	"github.com/cucumber/gherkin-go"
-	. "github.com/logrusorgru/aurora"
-)
-
-type fmtReporter struct {
-}
-
-func (r fmtReporter) Step(step *gherkin.Step) {
-	fmt.Printf("   %s%s\n", Yellow(step.Keyword), Green(step.Text))
-}
-
-func (r fmtReporter) Scenario(scenario *gherkin.Scenario) {
-	if len(scenario.Tags) != 0 {
-		for _, tag := range scenario.Tags {
-			fmt.Printf(" %s\n", Yellow(tag.Name))
-		}
-	}
-	fmt.Printf(" %s:%s\n", Yellow(scenario.Keyword), Green(scenario.Name))
-}
-
-func (r fmtReporter) ScenarioOutline(scenario *gherkin.ScenarioOutline) {
-	if len(scenario.Tags) != 0 {
-		for _, tag := range scenario.Tags {
-			fmt.Printf(" %s\n", Yellow(tag.Name))
-		}
-	}
-	fmt.Printf(" %s:%s\n", Yellow(scenario.Keyword), Green(scenario.Name))
-
-	for _, example := range scenario.Examples {
-		fmt.Printf(" %s:\n", Yellow(example.Keyword))
-	}
-
-	for _, step := range scenario.Steps {
-		fmt.Printf("     %s%s\n", Yellow(step.Keyword), Green(step.Text))
-	}
-}
-
-func (r fmtReporter) Undefined(s *gherkin.Step) {
-	fmt.Printf("   %s%s\n", Red("Undefined step"), Yellow(s.Text))
-}
-
-func (r fmtReporter) Skip(s *gherkin.Step) {
-	fmt.Printf(" %s%s\n", s.Keyword, Gray(10, s.Text))
-}
-
-func (r fmtReporter) Failed(step *gherkin.Step, e error) {
-	fmt.Printf("   %s%s\n", Yellow(step.Keyword), Red(step.Text))
-}
-
-func (r fmtReporter) Background(background *gherkin.Background) {
-	fmt.Printf("  %s%s\n", Yellow(background.Keyword), Green(background.Name))
-	for _, s := range background.Steps {
-		r.Step(s)
-	}
-}
-
-func (r fmtReporter) Feature(feature *gherkin.Feature) {
-	fmt.Printf("%s%s\n", Yellow(feature.Keyword), Green(feature.Name))
-}
-
-func (r fmtReporter) SkipScenario(s *gherkin.Scenario) {
-	if len(s.Tags) != 0 {
-		for _, tag := range s.Tags {
-			fmt.Printf(" %s\n", Yellow(tag.Name))
-		}
-	}
-	fmt.Printf(" %s%s\n", Gray(10, s.Keyword), Gray(10, s.Name))
-	for _, step := range s.Steps {
-		r.Skip(step)
-	}
-}
-
-func (r fmtReporter) SkipScenarioOutline(s *gherkin.ScenarioOutline) {
-	if len(s.Tags) != 0 {
-		for _, tag := range s.Tags {
-			fmt.Printf(" %s\n", Yellow(tag.Name))
-		}
-	}
-	for _, example := range s.Examples {
-		fmt.Printf(" %s:\n", Gray(10, example.Keyword))
-	}
-
-	fmt.Printf(" %s:%s\n", Gray(10, s.Keyword), Gray(10, s.Name))
-	for _, step := range s.Steps {
-		r.Skip(step)
-	}
-}
-
-func (r fmtReporter) Report(report executionReport) {
-	fmt.Printf("%d scenarios\n", report.countScenarios)
-	fmt.Printf("%d steps\n", report.countSteps)
-	if c := report.countFailedSteps; c > 0 {
-		fmt.Printf("%d failed steps\n", report.countFailedSteps)
-	}
-
-	if c := report.countUndefined; c > 0 {
-		fmt.Printf("%d undefined steps\n", report.countUndefined)
-	}
-
-	fmt.Printf("took %s\n", report.timeTook.String())
-}
diff --git a/reporter/reporter.go b/reporter/reporter.go
deleted file mode 100644
index 749850b..0000000
--- a/reporter/reporter.go
+++ /dev/null
@@ -1,135 +0,0 @@
-package reporter
-
-import (
-	"fmt"
-	"time"
-
-	"github.com/cucumber/gherkin-go"
-)
-
-func NewReporter() *Reporter {
-	return &Reporter{
-		timer:          time.Now(),
-		scenarios:      []interface{}{},
-		undefinedSteps: []*gherkin.Step{},
-		succeededSteps: []*gherkin.Step{},
-		failedSteps:    []*gherkin.Step{},
-		skippedSteps:   []*gherkin.Step{},
-		backgrounds:    []*gherkin.Background{},
-	}
-}
-
-type Reporter struct {
-	timer            time.Time
-	output           fmtReporter
-	features         []*gherkin.Feature
-	scenarios        []interface{} // *gherkin.Scenario or *gherkin.ScenarioOutline
-	skippedScenarios []interface{} // *gherkin.Scenario or *gherkin.ScenarioOutline
-	undefinedSteps   []*gherkin.Step
-	succeededSteps   []*gherkin.Step
-	failedSteps      []*gherkin.Step
-	skippedSteps     []*gherkin.Step
-	backgrounds      []*gherkin.Background
-}
-
-type executionReport struct {
-	countScenarios   int
-	countSteps       int
-	countFailedSteps int
-	countUndefined   int
-	timeTook         time.Duration
-}
-
-func (r *Reporter) Report(reported interface{}) error {
-	switch reported.(type) {
-	case *gherkin.Step:
-		s := reported.(*gherkin.Step)
-		r.output.Step(s)
-
-		r.succeededSteps = append(r.succeededSteps, s)
-	case *gherkin.Scenario:
-		s := reported.(*gherkin.Scenario)
-		r.output.Scenario(s)
-		r.scenarios = append(r.scenarios, s)
-	case *gherkin.ScenarioOutline:
-		s := reported.(*gherkin.ScenarioOutline)
-		r.output.ScenarioOutline(s)
-		r.scenarios = append(r.scenarios, s)
-
-	case *gherkin.Feature:
-		f := reported.(*gherkin.Feature)
-		r.output.Feature(f)
-		r.features = append(r.features, f)
-	case *gherkin.Background:
-		s := reported.(*gherkin.Background)
-		r.output.Background(s)
-
-		r.backgrounds = append(r.backgrounds, s)
-	default:
-		return fmt.Errorf("%T", reported)
-	}
-
-	return nil
-}
-
-func (r *Reporter) Undefined(s *gherkin.Step) {
-	r.output.Undefined(s)
-	r.undefinedSteps = append(r.undefinedSteps, s)
-}
-
-func (r *Reporter) Skip(reported interface{}) {
-	switch reported.(type) {
-	case *gherkin.Step:
-		s := reported.(*gherkin.Step)
-		r.output.Skip(s)
-
-		r.skippedSteps = append(r.skippedSteps, s)
-	case *gherkin.Scenario:
-		s := reported.(*gherkin.Scenario)
-		r.output.SkipScenario(s)
-		r.skippedScenarios = append(r.skippedScenarios, s)
-	case *gherkin.ScenarioOutline:
-		s := reported.(*gherkin.ScenarioOutline)
-		r.output.SkipScenarioOutline(s)
-		r.skippedScenarios = append(r.skippedScenarios, s)
-	default:
-		panic("should never happen")
-	}
-}
-
-func (r *Reporter) Failed(s *gherkin.Step, err error) {
-	r.output.Failed(s, err)
-	r.failedSteps = append(r.failedSteps, s)
-}
-
-func (r Reporter) GenerateReport() {
-	er := executionReport{
-		countScenarios:   r.countScenarios(),
-		countSteps:       r.countSteps(),
-		countFailedSteps: r.countFailed(),
-		countUndefined:   r.countUndefined(),
-		timeTook:         time.Since(r.timer),
-	}
-
-	r.output.Report(er)
-}
-
-func (r Reporter) countScenarios() int {
-	return len(r.scenarios)
-}
-
-func (r Reporter) countSteps() int {
-	return len(r.succeededSteps)
-}
-
-func (r *Reporter) countUndefined() int {
-	return len(r.undefinedSteps)
-}
-
-func (r *Reporter) countFailed() int {
-	return len(r.failedSteps)
-}
-
-func (r *Reporter) countSkippedSteps() int {
-	return len(r.skippedSteps)
-}


Test patch:
diff --git a/reporter/reporter_test.go b/reporter/reporter_test.go
deleted file mode 100644
index 409fffa..0000000
--- a/reporter/reporter_test.go
+++ /dev/null
@@ -1,45 +0,0 @@
-package reporter
-
-import (
-	"errors"
-	"testing"
-
-	"github.com/cucumber/gherkin-go"
-	"github.com/stretchr/testify/assert"
-)
-
-func TestReporter_Report(t *testing.T) {
-	step := &gherkin.Step{}
-	r := NewReporter()
-	err := r.Report(step)
-	assert.NoError(t, err)
-	assert.Equal(t, 1, r.countSteps())
-}
-
-func TestReporter_Report_Invalid_Type(t *testing.T) {
-	r := NewReporter()
-	err := r.Report("this shouldn't go here")
-	assert.Error(t, err)
-	assert.Equal(t, 0, r.countSteps())
-}
-
-func TestReporter_Undefined(t *testing.T) {
-	step := &gherkin.Step{}
-	r := NewReporter()
-	r.Undefined(step)
-	assert.Equal(t, 1, r.countUndefined())
-}
-
-func TestReporter_Failed(t *testing.T) {
-	step := &gherkin.Step{}
-	r := NewReporter()
-	r.Failed(step, errors.New("some error"))
-	assert.Equal(t, 1, r.countFailed())
-}
-
-func TestReporter_Skip_Step(t *testing.T) {
-	step := &gherkin.Step{}
-	r := NewReporter()
-	r.Skip(step)
-	assert.Equal(t, 1, r.countSkippedSteps())
-}