From fe1e0e978bb49ca6e0a29387b145a0e0682d6b77 Mon Sep 17 00:00:00 2001 From: hedhyw Date: Mon, 10 Apr 2023 07:20:18 +0300 Subject: [PATCH 1/2] feat: use simple template #81 --- README.md | 38 +++++ internal/app/app.feature | 1 + internal/app/app_test.go | 1 + internal/assets/assets_test.go | 1 + internal/assets/std.simple.v1.go.tmpl | 135 ++++++++++++++++++ .../simple/background.feature_test.go | 57 ++++++++ .../examples/simple/bool.feature_test.go | 33 +++++ .../examples/simple/complex.feature_test.go | 48 +++++++ .../examples/simple/issue_26.feature_test.go | 24 ++++ .../simple/issue_27_multi.feature_test.go | 20 +++ .../simple/issue_27_single.feature_test.go | 12 ++ .../examples/simple/readme.feature_test.go | 34 +++++ .../examples/simple/rules.feature_test.go | 44 ++++++ .../examples/simple/scenario.feature_test.go | 30 ++++ .../examples/simple/simple.feature_test.go | 16 +++ .../simpleparallel/background.feature_test.go | 65 +++++++++ .../simpleparallel/bool.feature_test.go | 39 +++++ .../simpleparallel/complex.feature_test.go | 55 +++++++ .../simpleparallel/issue_26.feature_test.go | 30 ++++ .../issue_27_multi.feature_test.go | 24 ++++ .../issue_27_single.feature_test.go | 16 +++ .../simpleparallel/readme.feature_test.go | 40 ++++++ .../simpleparallel/rules.feature_test.go | 55 +++++++ .../simpleparallel/scenario.feature_test.go | 34 +++++ .../simpleparallel/simple.feature_test.go | 20 +++ scripts/examples.sh | 15 ++ 26 files changed, 887 insertions(+) create mode 100644 internal/assets/std.simple.v1.go.tmpl create mode 100644 internal/generator/examples/simple/background.feature_test.go create mode 100644 internal/generator/examples/simple/bool.feature_test.go create mode 100644 internal/generator/examples/simple/complex.feature_test.go create mode 100644 internal/generator/examples/simple/issue_26.feature_test.go create mode 100644 internal/generator/examples/simple/issue_27_multi.feature_test.go create mode 100644 internal/generator/examples/simple/issue_27_single.feature_test.go create mode 100644 internal/generator/examples/simple/readme.feature_test.go create mode 100644 internal/generator/examples/simple/rules.feature_test.go create mode 100644 internal/generator/examples/simple/scenario.feature_test.go create mode 100644 internal/generator/examples/simple/simple.feature_test.go create mode 100644 internal/generator/examples/simpleparallel/background.feature_test.go create mode 100644 internal/generator/examples/simpleparallel/bool.feature_test.go create mode 100644 internal/generator/examples/simpleparallel/complex.feature_test.go create mode 100644 internal/generator/examples/simpleparallel/issue_26.feature_test.go create mode 100644 internal/generator/examples/simpleparallel/issue_27_multi.feature_test.go create mode 100644 internal/generator/examples/simpleparallel/issue_27_single.feature_test.go create mode 100644 internal/generator/examples/simpleparallel/readme.feature_test.go create mode 100644 internal/generator/examples/simpleparallel/rules.feature_test.go create mode 100644 internal/generator/examples/simpleparallel/scenario.feature_test.go create mode 100644 internal/generator/examples/simpleparallel/simple.feature_test.go diff --git a/README.md b/README.md index 76ac57a..98cc709 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,44 @@ f.TestCases(testCases, func(t *testing.T, f *bdd.Feature, tc testCase) { }) ``` +## Simplified template + +A simplified template is also available. It uses only the std [testing](https://pkg.go.dev/testing) package without any other dependency. Steps are defined by comments. +Provide `-template std.simple.v1.go.tmpl` to to use [this](internal/assets/std.simple.v1.go.tmpl) template. + +```go +func TestApplicationCommandLineTool(t *testing.T) { + t.Parallel() + + t.Run("User wants to see usage information", func(t *testing.T) { + t.Parallel() + + type testCase struct { + Flag string `field:""` + ExitStatus int `field:""` + Printed bool `field:""` + } + + testCases := map[string]testCase{ + "--help_0_true": {"--help", 0, true}, + "-help_0_true": {"-help", 0, true}, + "-invalid_1_false": {"-invalid", 1, false}, + } + + for name, tc := range testCases { + t.Run(name, func(t *testing.T) { + // When flag is provided + + // Then usage should be printed + + // And exit status should be + + }) + } + }) +} +``` + ## More advanced example See [internal/app/app.feature](internal/app/app.feature) and [internal/app/app_test.go](internal/app/app_test.go). diff --git a/internal/app/app.feature b/internal/app/app.feature index bca561f..c94d625 100644 --- a/internal/app/app.feature +++ b/internal/app/app.feature @@ -33,6 +33,7 @@ Feature: Application command line tool | |