Сравнить коммиты

...

338 коммитов

Автор SHA1 Сообщение Дата
Softonik
6087fc101c AST: файл Magefile.go пропускается при поиске имени пакета
Некоторые проверки провалились
test / test (1.16.x) (push) Has been cancelled
test / test (1.17.x) (push) Has been cancelled
test / test (oldstable) (push) Has been cancelled
test / test (stable) (push) Has been cancelled
2025-06-06 17:06:26 +03:00
Softonik
f5ec4cadce +Magefile.go
Ожидается выполнение проверок
test / test (1.16.x) (push) Waiting to run
test / test (1.17.x) (push) Waiting to run
test / test (oldstable) (push) Waiting to run
test / test (stable) (push) Waiting to run
2025-06-06 16:12:53 +03:00
Softonik
ccc4a42649 AST: из Base скопирован/поправлен генератор функций:
с прямой последовательностью и добавлением шагов в тестовые файлы
2025-06-06 16:10:49 +03:00
Softonik
59344caf33 AST: тесты вынесены во вложенный пакет, чтобы не было циклической зависимости 2025-06-06 15:52:32 +03:00
Softonik
56522e757a + Сценарий: Добавление шага с параметрами строкой 2025-06-06 15:15:44 +03:00
Softonik
bda4071975 ++ Сценарии: Добавление шага 2025-06-05 06:44:44 +03:00
Softonik
af6027bad2 + Сценарий: Добавление функции к существующей + без дубликаций 2025-06-05 03:50:32 +03:00
Softonik
9ad168ae70 + Сценарий: Добавление функции с параметрами: int, string 2025-06-05 03:29:34 +03:00
Softonik
4a15650887 + Сценарий: Добавление функции с параметрами: int 2025-06-05 03:02:37 +03:00
Softonik
6f2a5fef98 + Сценарий: Добавление сгенерированных функций в test-файл 2025-06-05 02:08:33 +03:00
Softonik
4e3e82b79e Добавлено godog_and_gomega + сопутствующие обновления модулей и кода 2025-06-04 23:20:51 +03:00
Softonik
26dafa0117 +Для русских сценариев генерируются русские функции 2025-06-04 22:53:47 +03:00
Softonik
3b25e9eb02 Сокращён вывод результатов 2025-06-04 22:29:13 +03:00
Softonik
78bab577c5 Добавлен формат AST 2025-06-03 05:03:20 +03:00
Softonik
0c030e0a6c Модуль переименован для публикации 2025-06-03 04:16:23 +03:00
Softonik
1b9806b25b чистка 2025-06-03 03:30:46 +03:00
Softonik
d2686eb13d чистка 2025-06-03 03:12:20 +03:00
Softonik
f0399fda41 Добавлена поддержка focused-тестов во множестве feature-файлов 2025-06-03 03:11:14 +03:00
Softonik
13639e7df7 Добавлена поддержка тестов с f-тегом 2025-06-03 03:06:08 +03:00
Softonik
60442133fc Тесты: отключены хрупкие тесты, проверяющие общее их количество 2025-06-03 02:58:55 +03:00
Dominik Gedon
74fa488023
Replace deprecated ::set-output (#681)
As per the deprecation warning and explanation at https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/
2025-03-24 11:05:30 +01:00
Tighearnán Carroll
4a4fd8ab3a
fix(errors): Fix expected Step argument count for steps with context.Context (#679)
* fix(errors): print correct number of expected steps when step has  defined

* add unit test

* remove duplicate part from unit test

* update changelog
2025-03-19 23:04:06 +00:00
renovate[bot]
e03da742a5
fix(deps): update module github.com/spf13/pflag to v1.0.6 (#675)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-01-30 23:24:31 +00:00
Ahmadreza
14fe127e3d
Update honnef.co/go/tools/cmd/staticcheck version in Makefile (#670) 2024-12-19 11:12:33 +01:00
Viacheslav Poturaev
e55eab64f7
Add details to "step is undefined" error (#669)
* Add details to "step is undefined" error

* Update changelog
2024-12-10 16:54:49 +01:00
GrindStone
da4633a421
Localisation support (#665)
* Add dialect options to support localisation

* Add test for ParseFeatures support for localisation
2024-11-14 10:42:18 +01:00
Tighearnán Carroll
c5a88f62c2
fix(formatter): On concurrent execution, execute formatter at end of Scenario (#645)
* fix(formatter): add onflush logger only print output at end of scenario when running concurrently

* add to changelog

* fix tests

* fix scenario outline output for the Pretty formatter

* fix casing for linter

* add coverage for new storage function

* relate suite back to where it was originally

* better type assertion on flush log

* var name for asserted formatter that doesn't clash with stdlib's fmt

* add coverage to summary

* only defer flush func when running concurrently

* much more concise way of deferring the flush

---------

Co-authored-by: Viacheslav Poturaev <vearutop@gmail.com>
2024-11-08 17:05:40 +01:00
renovate[bot]
9b699ff9a8
fix(deps): update module github.com/cucumber/godog to v0.15.0 (#661)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-02 01:42:01 +00:00
Viacheslav Poturaev
dc6950b1e3 Update CHANGELOG.md 2024-10-31 19:06:21 +01:00
John Lonergan
ecd2dfebbd
Ambiguous step detection - add support to all formatters (#648)
* added the missing impl of json/events/junit/pretty - still need 'progress' and 'junit,pretty'

* added tests for "progress formatter"

* switched from tabs to spaces in the ambiguous steps error message

* rename some_scenarions_including_failing
to     some_scenarios_including_failing

* changelog
2024-10-16 15:41:47 +01:00
John Lonergan
223efc3b14
Fix some type checks on the signatures of nested step handlers (#647)
* at some point someone changed the return type for nested steps from []string to godog.Steps but they forgot to adjust the type checks. The existing type checks were lax and unable to distinguish  []string from godog.Steps but in a couple of places in the code the value is coerced to godog.Steps and so if someone returned []string then the code would blow up. Additionally there were some tests aroudn these types but they also had not been updated but the test was passing for the wrong reason - the particular test expected an error but the cause of the error wasn't the one the code expected.

* CHANGELOG.md

* use chatgpt to regen the top of the code based on the new tests

* use chatgpt to regen the top of the code based on the new tests

* corrected the error messages of the param checks to indicate that the problem is the function signature and not the args being passed to the function, also added numerous extra assertions on the precise error messages returned. Now that the precise error is being verified in the test I have improved certain error messages to that more accurate detail is included in the errors

* added further constraints to the step arg mapping tests

* removed redundant test

* include a step error result in the reported error even when the ctx is nil
2024-10-15 13:25:13 +01:00
John Lonergan
8edde7f30c
Bugfix afterscenario attachments (#646)
* Minor doc and comment corrections

* Fixed bug where it was impossible to make attachments from 'after scenario' hook, also removed some dud comments.

* typo
2024-10-06 02:12:56 +01:00
John Lonergan
1e7c45eb78
Minor doc and comment corrections (#644) 2024-10-05 02:40:42 +01:00
M.P. Korstanje
6e4f452389
Replace more slack with discord
See:
- https://github.com/cucumber/common/issues/2195
- https://github.com/orgs/cucumber/discussions/2197
2024-08-09 16:58:01 +02:00
M.P. Korstanje
9b51734429
Replace slack with discord
See:
- https://github.com/cucumber/common/issues/2195
- https://github.com/orgs/cucumber/discussions/2197
2024-08-09 16:51:01 +02:00
John Lonergan
901da7fa3d
fixed a bug where the attachments are extracted from the context too early, this prevented AfterStep from making attachments (#637)
* fixed a bug where the attachments are extracted from the context too early, this prevented AfterStep from making attachments
2024-07-23 17:22:51 +01:00
John Lonergan
bcf6bce793
ambiguous step def detection akin to cucumber jvm (#636)
* added basic detection for ambiguous steps, but causes an error and not yet recorded in the reports as 'Ambiguous', and no test cases figured out yet

* added initial support for detection of ambiguous steps - further work take a look at how cuke jvm report ambiguous steps and sets the step status to 'ambiguous' rather than my current solution which just blows the test up as a regular step error

* added suite_context_test and also introduced missing 'ambiguous' status to make cucumber jvm'

* update CHANGELOG for ambiguous step defs

* missed file from commit

* added internal/formatters/fmt_multi_test.go

* add tests for other peoples code

* added "ambigous" to the help text

* tests

* added some more tests for attachments

* Update internal/flags/flags.go

Co-authored-by: Viacheslav Poturaev <nanopeni@gmail.com>

---------

Co-authored-by: Viacheslav Poturaev <nanopeni@gmail.com>
2024-07-01 10:28:39 +01:00
John Lonergan
3abb346b28
provisional: Attachments now uses base64 padding not raw mode (#629)
* corrected base64 encoding of attachments to use padding as that's what cuke JVM does
2024-05-31 21:33:57 +01:00
John Lonergan
9558224cce
Additional code review observations on Attach() functionality from https://github.com/cucumber/godog/pull/623 (#628)
* support multiple calls to the Attach() function from a single step

* run_progress_test.go changed so it's not sensitive to the name of the clone target directory

* applied code review comments also added _example/attachments

* applied code review comments also added _example/attachments

* applied code review comments also added _example/attachments
2024-05-30 02:29:14 +00:00
John Lonergan
f85def32ee
Moved CHANGHELOG entry to correct location (#626) 2024-05-29 09:19:33 +02:00
John Lonergan
201e526078
added support for Attachments (aka Embedddings) (#623)
* added support for attachments in the cucumber json and events output formats - done by sneaking the attachment into the context.Context object.
2024-05-29 00:02:08 +01:00
Viacheslav Poturaev
4ade3314e8
Update CI and Makefile (#619) 2024-05-02 14:51:52 +02:00
renovate[bot]
c3756d1aa2
fix(deps): update module github.com/cucumber/godog to v0.14.1 (#618)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-30 14:31:36 +00:00
Viacheslav Poturaev
095a19b85d
Update CHANGELOG.md 2024-04-29 10:49:40 +02:00
Mark Hughes
7017c73ef8
Provide a useful implementation of something compatible with testing.T (#571)
* Attempting to provide a useful implementation of something compatible with testing.T

* Handle Fail calls on the TestingT in the right place

* Provide as much of testing.T as possible + tidy up

* Add initial tests for testingT support

* Check compatibility with testing.T and friends

Co-authored-by: Piotr Bocheński <bochenski.piotr@gmail.com>

* Update assert-godogs example to show new usage. Rename 'GetTestingT(ctx)' to 'T(ctx)'

* Update changelog and readme with new usage

* Improve test coverage

* Review updates

---------

Co-authored-by: Piotr Bocheński <bochenski.piotr@gmail.com>
2024-04-29 10:26:25 +02:00
Cornel Damian
10407bc5a9
fix invalid memory address or nil pointer dereference when calling TestSuite RetrieveFeatures (#566)
Co-authored-by: Cornel Damian <cornel.damian@adswizz.com>
2024-04-08 14:53:28 +02:00
renovate[bot]
fd3e0d5f9c
chore(deps): update actions/cache action to v4 (#598)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-08 14:48:46 +02:00
renovate[bot]
18088dfc91
chore(deps): update codecov/codecov-action action to v4 (#607)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-08 14:48:09 +02:00
Iaroslav Ciupin
da57dd0766
Fix step duration calculation (#616) 2024-04-08 14:08:21 +02:00
renovate[bot]
153db4eacb
chore(deps): update dominikh/staticcheck-action action to v1.3.1 (#614)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-03-24 21:40:17 +00:00
Glib Briia
27ad3c245e
Create releasing guidelines (#608) 2024-02-06 14:19:51 +00:00
renovate[bot]
244de8274a
fix(deps): update module github.com/cucumber/godog to v0.14.0 (#610)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-02-01 22:35:22 +00:00
Glib Briia
757988328b
Prepare CHANGELOG.md for new release (#606) 2024-01-31 16:39:28 +00:00
Glib Briia
250d69ab63
Fixes #604 - remove line overwriting for scenario outlines in cucumber formatter (#605) 2024-01-31 07:04:29 +00:00
Viacheslav Poturaev
5a5631a758
Remove duplicate warning message (#590) 2023-12-07 21:34:04 +01:00
renovate[bot]
592f1cdb71
chore(deps): update actions/setup-go action to v5 (#588)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-12-07 21:29:50 +01:00
Viacheslav Poturaev
888fe3f294
Improve ErrSkip handling, add test for Summary and operations order (#584) 2023-10-29 22:59:14 +01:00
Kirubel Adamu
25274b0291
updated base formatter to set a scenario as passed unless there exist… (#582) 2023-10-27 19:28:41 +02:00
Viacheslav Poturaev
c61a93931d
Update test.yml (#583) 2023-10-24 00:11:29 +02:00
renovate[bot]
76039dc0d2
chore(deps): update codecov/codecov-action action to v4 (#576)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-09-14 19:05:33 +02:00
renovate[bot]
4550862450
chore(deps): update actions/checkout action to v4 (#575)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-09-07 18:56:06 +02:00
renovate[bot]
a37ff90667
fix(deps): update module github.com/cucumber/godog to v0.13.0 (#574)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-08-23 20:45:17 +00:00
Viacheslav Poturaev
6b96d47e70 Prepare CHANGELOG.md for new release 2023-08-22 14:31:19 +02:00
Viacheslav Poturaev
d3aec7142e
Improve example with concurrency support (#573) 2023-08-22 14:21:34 +02:00
Yury Yurochko
75d5cab90d
fix(examples): update api example (#532) 2023-08-17 11:23:10 +02:00
Viacheslav Poturaev
3e0f9026f3
Improve hooks invocation flow (#568) 2023-07-13 09:31:56 +02:00
Viacheslav Poturaev
51d164ff57 Print verbose error to enable traces 2023-07-07 18:16:21 +02:00
Longyue Li
72db47c519
refactor: test_context.go (#564)
* 1. ScenarioContext has methods on both value and pointer receivers, make all methods have value receivers.
2. fix the syntax error in the comment
3. remove unused function Build

Signed-off-by: longyue0521 <longyueli0521@gmail.com>

* convert ctx (type ScenarioContext) to StepContext

Signed-off-by: longyue0521 <longyueli0521@gmail.com>

* rollback the deleted Build function

Signed-off-by: longyue0521 <longyueli0521@gmail.com>

---------

Signed-off-by: longyue0521 <longyueli0521@gmail.com>
2023-06-07 11:37:46 +02:00
Viacheslav Poturaev
ea50e4bdfc
Use staticcheck GitHub Action (#563) 2023-06-06 16:52:06 +02:00
Viacheslav Poturaev
7f75c5d4ee Remove redundant return 2023-05-26 16:43:48 +02:00
Viacheslav Poturaev
35820ff9fe Reduce deps, fix CI for go1.16, format imports 2023-05-26 16:38:51 +02:00
Viacheslav Poturaev
3eae6c0437 Update dependencies 2023-05-26 14:57:29 +02:00
Viacheslav Poturaev
561cb85371 Add test for context cancellation 2023-04-04 01:30:19 +02:00
Dragan Milic
0dcbfef9be
cancel context for each scenario (#514)
* fix(deps): update module github.com/cucumber/gherkin/go/v26 to v26.1.0 (#549)

* Update CI for go1.20 (#552)

* fix(deps): update module github.com/cucumber/gherkin/go/v26 to v26.1.0

* Tidy modules

---------

Co-authored-by: Viacheslav Poturaev <vearutop@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>

* cancel context for each scenario

* Update suite.go

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Viacheslav Poturaev <vearutop@gmail.com>
Co-authored-by: Viacheslav Poturaev <nanopeni@gmail.com>
2023-04-04 01:28:03 +02:00
renovate[bot]
472ea2735d
fix(deps): update module github.com/cucumber/gherkin/go/v26 to v26.1.0 (#549)
* Update CI for go1.20 (#552)

* fix(deps): update module github.com/cucumber/gherkin/go/v26 to v26.1.0

* Tidy modules

---------

Co-authored-by: Viacheslav Poturaev <vearutop@gmail.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-04-04 00:43:31 +02:00
Viacheslav Poturaev
aba6a689a4
Update CI for go1.20 (#552) 2023-04-04 00:11:09 +02:00
Tomohiko Himura
dc8c9c4378
Result of testing.T respect strict option (#539)
* test: testing.T.Failed should be false when strict is false and has pending steps

* fix: testing.T respect strict option
2023-04-03 16:05:05 +02:00
Tighearnán Carroll
6ce2b8696b
Use fs.FS abstraction for filesystem (#550)
* compiles

* mock fs in tests

* fix parser tests

* fix run.go

* rename FeatureFS to FS

* fix docs typos

* remove debug log

* add os.DirFS("./") to default options

* reword docstring

* add fs wrapper

* updated readme and changelog

* added note

* fix changelog

* remove ./ gating from defaults

* add new storage.FS tests

* increase coverage of parser.parsePath

* increase coverage of TestSuite.RetrieveFeatures

* remove another os.Stat

---------

Co-authored-by: Tighearnán Carroll <tighearnan.carroll@gamil.com>
2023-03-27 21:52:51 +02:00
Daniel Helfand
3bd9e9ca4f
docs: prefer go test to use of godog cli in README (#548) 2023-03-24 09:19:12 +01:00
renovate[bot]
17f07d243a
chore(deps): update actions/setup-go action to v4 (#546)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-03-16 21:43:51 +01:00
renovate[bot]
bcffb1c829
fix(deps): update module github.com/stretchr/testify to v1.8.2 (#541)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-02-26 18:49:40 +00:00
renovate[bot]
d4d18646f6
fix(deps): update module github.com/data-dog/go-txdb to v0.1.6 (#540)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-02-24 21:49:25 +00:00
Alexandru Chitu
5368ee0229
docs(*): correct example (#538)
* docs(*): correct example

* docs(*): reorder step declarations
2023-02-21 11:52:24 +00:00
Alexandru Chitu
62d84eedbc
Implement unambiguous keywords (#509)
feat(*): create keyword functions

* chore(*): update messages and gherkin, relocate Keyword

* chore(*): update messages and gherkin, relocate Keyword

* chore(*): update messages and gherkin, relocate Keyword

* feat(*): mandate keyword type when unambiguous keyword function is used

* test(*): keyword type in feature files

* docs(*): update step-by-step walkthrough to mention the option of using keyword functions

* docs(*): update CHANGELOG.md

* test(*): keyword substeps

* chore(*): go mod
2023-01-23 14:22:19 +00:00
M.P. Korstanje
c035051d94
Setup Renovate with default Configs (#531) 2023-01-08 17:53:57 +01:00
renovate[bot]
0892aced88
fix(deps): update module github.com/smartystreets/goconvey to v1.7.2 (#525)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: M.P. Korstanje <rien.korstanje@gmail.com>
2023-01-08 16:47:14 +00:00
renovate[bot]
0fd767543f
fix(deps): update module github.com/spf13/cobra to v1.6.1 (#526)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: M.P. Korstanje <rien.korstanje@gmail.com>
2023-01-08 17:41:08 +01:00
renovate[bot]
2e91c32e91
fix(deps): update module github.com/hashicorp/go-memdb to v1.3.4 (#523)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: M.P. Korstanje <rien.korstanje@gmail.com>
2023-01-08 17:36:50 +01:00
renovate[bot]
70b4f7fecb
fix(deps): update module github.com/go-sql-driver/mysql to v1.7.0 (#524)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-08 17:30:54 +01:00
renovate[bot]
3918bda77b
fix(deps): update module github.com/data-dog/go-txdb to v0.1.5 (#522)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-08 17:30:19 +01:00
renovate[bot]
8cd8a8014a
fix(deps): update module github.com/cucumber/gherkin/go/v26 to v26.0.3 (#519)
* fix(deps): update module github.com/cucumber/gherkin/go/v26 to v26.0.3

* Clean up

* Clean up

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: M.P. Korstanje <rien.korstanje@gmail.com>
2023-01-08 17:27:21 +01:00
renovate[bot]
714af882bf
chore(deps): update actions/cache action to v3 (#527)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-08 17:27:04 +01:00
renovate[bot]
fca3075757
chore(deps): update actions/setup-go action to v3 (#529)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-08 17:26:53 +01:00
renovate[bot]
48af591c17
chore(deps): update actions/checkout action to v3 (#528)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-08 16:26:09 +00:00
renovate[bot]
63d4b1be52
chore(deps): update codecov/codecov-action action to v3 (#530)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-08 17:24:53 +01:00
renovate[bot]
802c8978a2
fix(deps): update module github.com/cucumber/godog to v0.12.6 (#520)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-08 17:20:37 +01:00
renovate[bot]
d7e1e95c04
Add renovate.json (#512)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2023-01-08 17:10:16 +01:00
Alexandru Chitu
2264a0037b
chore(*): BREAKING CHANGE, use new repos for cucumber and messages (#515)
* chore(*): use new repos for cucumber and messages

* chore(*): go mod tidy _examples

Co-authored-by: otrava7 <alexandru.chit@gmail.com>
2023-01-05 12:41:56 +01:00
Viacheslav Poturaev
9007f1f26d
Update CHANGELOG.md for release v0.12.6 (#516) 2023-01-05 11:00:23 +01:00
Viacheslav Poturaev
c35ea0b236
Remove deprecation from flags, update example to use CLI flags (#498)
* Remove deprecation from flags, update example to use CLI flags

* Add comment to ShowHelp option

* Fix test

* Update CHANGELOG.md
2022-08-31 10:17:00 +02:00
Viacheslav Poturaev
202882807b
Skip undefined steps in after scenario hooks (#494) 2022-08-16 09:37:33 +02:00
Viacheslav Poturaev
fd5b6a1034
Add gorelease GitHub Action task (#493)
* Add gorelease GitHub Action task

* Update .github/workflows/gorelease.yml

Co-authored-by: Nhat <thmnhat@gmail.com>

Co-authored-by: Nhat <thmnhat@gmail.com>
2022-08-09 16:43:20 +02:00
Viacheslav Poturaev
6f3e792c52
Add deprecation notice to godog CLI (#489)
* Add deprecation notice to godog CLI

* Update CHANGELOG
2022-07-31 15:38:05 +02:00
Aaron Kaswen-Wilk
d45a9aaaa3
add new option for created features with parsing from byte slices (#476) 2022-07-26 15:36:23 +02:00
Wichert Akkerman
b2672bb933
Do not discard context from substeps (#488) 2022-07-25 13:43:36 +02:00
Packet Please
5e176da433
Fix green copypasta (#484) 2022-07-05 08:19:37 +02:00
Brian Hnat
b5400809cd
Update CHANGELOG.md (#482)
Add bug fix from PR #480 to CHANGELOG.md.
2022-06-17 21:10:11 -04:00
Brian Hnat
5d705e5b8e
Pretty Print when using rules (#440) (#480)
* Pretty Print when using rules (#440)

* Pretty Print when using rules (#440)

* fix a few formatting mistakes (#440)

* added test with rule and scenario outline (#440)
2022-06-17 07:32:07 -07:00
Viacheslav Poturaev
c5a86a4e56 Update vulnerable test dependency 2022-05-28 12:03:13 +02:00
Viacheslav Poturaev
99655f7e7e
Update README to reflect current best practices in creating and running tests (#477)
* Update README to reflect current best practices in creating and running tests

* Update CHANGELOG and README

Co-authored-by: Matt Wynne <matt@cucumber.io>
2022-05-21 08:21:41 +02:00
James Cooper
d52a4d3f4d
Fix version subcommand. Do not print usage if run subcommand fails. (#475)
* Fix version subcommand. Do not print usage if run subcommand fails.

* Remove newline to clean up PR diff
2022-05-20 14:18:09 +02:00
Matt Wynne
5793a95e1c
Reformat CHANGELOG.md using standard changelog CLI tool (#474)
* Reformat using standard `changelog` CLI tool

See https://github.com/cucumber/changelog

* Fix missing link to username

* Tidy
2022-04-30 14:43:35 -07:00
Martin de Olmos
4ca5ec040b
Update go version in go.mod (go1.16). Update dependencies (#471)
* Update go version in go.mod (go1.17). Update dependencies.

* Update go version in go.mod (go1.17). Run go mod tidy in _examples.

* Update go version in go.mod (go1.16).

* Update go version in go.mod (go1.16).
2022-04-28 14:36:38 +02:00
Arianna Cooper
1a795f1dde
Fix issue#383 (#468)
* Add example about incorrect project structure

This is to help reproduce #383

* Added some debugging statements

* Update go.sum for example project

* Made a cmd_run_test.go file in order to test and run the builderAndRunGodog function in order to see it fail

* added new assertion test

* Matt and I added debugging

Co-authored-by: Matt Wynne <matt@mattwynne.net>

* Matt and I tried to logging through the cobra command

by using cmd.OutOrStdout( )

* Improved some debugging

* Add a failing test for Builder that reproduces #383

* added new test for IncorrectProjectStructure #383

* Revert "Add a failing test for Builder that reproduces #383"

This reverts commit e5b26933b5d4e979009f8f4341448fa8322720d2.

* ignored vscode files

Co-authored-by: Matt Wynne <matt@cucumber.io>

* undid debugging changes

* undid debugging changes

* removed redundant test

* added check for incorrect project structure

we examined the output from running `go test` which tells us if we didn't
find any test files.
we tweaked the error message to follow the capitalization rules

Co-authored-by: Matt Wynne <matt@cucumber.io>

* Update internal/builder/builder_test.go

Co-authored-by: Matt Wynne <matt@mattwynne.net>
Co-authored-by: Matt Wynne <matt@cucumber.io>
Co-authored-by: Viacheslav Poturaev <nanopeni@gmail.com>
2022-04-28 14:33:24 +02:00
Matt Wynne
237a855127
Replace #StandWithUkraine banner with badge (#470)
As decided at today's community meeting.
2022-04-15 07:59:09 -07:00
Aslak Hellesøy
4f2140a09a
Add Stand With Ukraine badge
See https://github.com/cucumber/cucumber-js/issues/1961
2022-03-31 15:43:06 +01:00
Viacheslav Poturaev
d77238eef3 Prepare for release 2022-03-26 10:18:09 +01:00
Viacheslav Poturaev
6f877d6b03
Fix support for go1.18 (#466) 2022-03-26 10:16:17 +01:00
Ricardo García Fernández
5efecbaf10
Update tests and examples with up to date API (#460) 2022-02-18 18:26:17 +01:00
Carl Menezes
c95871f3ce
Switch from golint to staticcheck (#457)
* Switch from golint to staticcheck

* Remove unused function

run_test.go:618:6: func passingStepDefWithoutReturn is unused (U1000)

* Remove unused function

suite.go:421:6: func isEmptyFeature is unused (U1000)

* Fix unnecessary use of fmt.Sprintf

test_context_test.go:45:66: unnecessary use of fmt.Sprintf (S1039)
test_context_test.go:46:61: unnecessary use of fmt.Sprintf (S1039)

* Fix CI error

https://github.com/cucumber/godog/runs/5146601108?check_suite_focus=true#step:7:28

* Change CI to run staticcheck instead of golint

* Use staticcheck that definitely pass

* Fix CI staticcheck error

https://github.com/cucumber/godog/runs/5147133955?check_suite_focus=true#step:6:17

* Only run staticcheck for Go 1.17

Co-authored-by: Viacheslav Poturaev <nanopeni@gmail.com>

* Add staticcheck linux binary

* Update Go module dependencies in _examples

* Use static check binary in bin for CI

* Reduce number of dependencies

Also add a note to CONTRIBUTING.md about the _examples module

* Pin the version of staticcheck

Co-authored-by: Viacheslav Poturaev <nanopeni@gmail.com>

Co-authored-by: Matt Wynne <matt@cucumber.io>
Co-authored-by: Viacheslav Poturaev <nanopeni@gmail.com>
2022-02-15 13:37:27 -08:00
Matt Wynne
1c91e6f9ea
Make sure make test runs all tests
Fixes #458
2022-02-14 09:51:17 -08:00
Matt Wynne
2695c3f359
Delete .github/ISSUE_TEMPLATE directory
We can rely on the default templates from https://github.com/cucumber/.github instead
2022-02-10 12:48:22 -08:00
Matt Wynne
1f7231cb42
Delete feature_request.md 2022-02-10 11:42:14 -08:00
Gemini Smith
5001c4f4fe
Change cmd setup to bubble up errors over exiting (#454)
* Change cmd setup to bubble up errors over exiting

* Update main to handle execute error

* Update changelog with PR #454

* Slight cleanup tweaks
2022-01-25 16:52:57 -07:00
Viacheslav Poturaev
30de46da25
Prepare changelog for release 2022-01-12 23:43:48 +01:00
Viacheslav Poturaev
9baac0fdfa
Allow suite-level configuration of steps and hooks (#453)
* Allow suite-level configuration of steps and hooks

* Fix a few typos

* Update CHANGELOG.md

* Add test

* Run scenario in same goroutine to preserve stack when concurrency is disabled

* Remove redundant check
2022-01-12 23:40:41 +01:00
Viacheslav Poturaev
a6fef3f171
Prepare v0.12.3 (#451) 2022-01-05 23:06:58 +01:00
Viacheslav Poturaev
95278dfd39
Automate binary releases (#437)
* Add release assets automation

* Use single module with local replace for examples

* Update CHANGELOG.md

* Allow expected failure for custom formatter example test

* Set version value with ldflags

* Restore artifacts cleanup
2022-01-05 23:00:29 +01:00
Thales Oliveira
1dcc44f35b
Bump version (#450) 2022-01-05 15:08:06 +01:00
Dmitry Savintsev
4d9b548d61
use 'go get' instead of 'go install' to install (#449) 2021-12-29 13:29:50 +01:00
Viacheslav Poturaev
b850b44b48
Invoke After Scenario hooks after After Step hooks (#444)
* Invoke After Scenario hooks after After Step hooks

* Update CHANGELOG.md

Co-authored-by: Matt Wynne <matt@cucumber.io>
2021-12-02 16:09:23 -08:00
Gemini Smith
82bcce7bdc
Add WSL friendly check-go-version setup (#443)
* Add WSL friendly check-go-version setup

* Add changelog entry and update my username

* Add PR link to changelog

* Stop it saying 'noting to be done for check-go-version'

* Update CHANGELOG.md

Co-authored-by: Viacheslav Poturaev <vearutop@gmail.com>

Co-authored-by: Matt Wynne <matt@cucumber.io>
Co-authored-by: Viacheslav Poturaev <vearutop@gmail.com>
2021-12-01 07:22:04 -08:00
Matt Wynne
df294698f5
Update CONTRIBUTING.md 2021-11-17 08:50:20 -08:00
Matt Wynne
1532a1ceba
Allow some coverage drop in PRs too 2021-11-16 17:01:21 -08:00
Matt Wynne
07b9e82910
Try configuring codecov to allow a little bit of coverage drop (#442) 2021-11-16 16:54:43 -08:00
Matt Wynne
477135d2fe
Friendlier contributing guide (#439)
* Use a warmer tone in CONTRIBUTING guide and provide practical help with getting up and running.

* Update instructions to include golint so you can run `make`

* Update CONTRIBUTING.md

Co-authored-by: Aurélien Reeves <aurelien.reeves@smartbear.com>

* Update README.md

Co-authored-by: Aurélien Reeves <aurelien.reeves@smartbear.com>

* Update CONTRIBUTING.md

Co-authored-by: Viacheslav Poturaev <vearutop@gmail.com>

* Remove the need for golint installation instructions

Co-authored-by: Aurélien Reeves <aurelien.reeves@smartbear.com>
Co-authored-by: Viacheslav Poturaev <vearutop@gmail.com>
2021-11-17 00:38:57 +00:00
Viacheslav Poturaev
86a56351ef
Fix compilation for non-modules (#436) 2021-10-14 19:25:30 +02:00
Viacheslav Poturaev
239a42468a Update CHANGELOG for release 2021-08-27 00:11:57 +02:00
Viacheslav Poturaev
953acd5d90
Remove CircleCI tasks (#427) 2021-08-27 00:08:29 +02:00
Viacheslav Poturaev
dfe99eadf5
Run tests in GitHub Actions (#426) 2021-08-26 23:46:03 +02:00
Viacheslav Poturaev
7d984effb3
Run before step hooks before matching (#425)
* Run before step hooks before matching

* Add note to CHANGELOG.md

Co-authored-by: nhatthm <nt@hellofresh.com>
2021-08-24 23:02:41 +02:00
Viacheslav Poturaev
afaebf26c1
Add go1.17 to CI tests (#423) 2021-08-17 11:29:12 +02:00
Viacheslav Poturaev
d074262d59
Rename godog.Feature alias to godog.GherkinDocument to be more accurate (#422) 2021-08-17 10:53:53 +02:00
Viacheslav Poturaev
92ea38e7ce
Reduce dependency when implementing custom formatter with local alias (#421) 2021-08-15 21:59:39 +02:00
Viacheslav Poturaev
61730298a5
Add option to run scenarios as *testing.T subtests (#419) 2021-08-11 17:19:05 +02:00
Levi Noecker
c6c2a0885b
Export internal formatters (#372) 2021-08-10 11:27:17 +02:00
Viacheslav Poturaev
ad7feb3298
Add release notes and bump version (#416) 2021-08-09 08:51:27 +02:00
Viacheslav Poturaev
8cf3f415b3
Add scenario hook errors to first and last steps (#417) 2021-08-08 22:42:41 +02:00
Viacheslav Poturaev
f1ca5dc00e
Add test case for DocString and Table suggestion rendering, closes #367 (#415) 2021-08-07 23:07:37 +02:00
Viacheslav Poturaev
09d7d85abf
Fix execution of scenarios provided as a list of path:line (#414) 2021-08-07 22:37:31 +02:00
Lorencz Aviale
6fb74a5334
Remove obsolete recommendation from README (#412)
Co-authored-by: Viacheslav Poturaev <vearutop@users.noreply.github.com>
2021-08-03 18:54:01 +02:00
Viacheslav Poturaev
b1728ff551
Add new contextualized API for hooks and steps (#409)
* Add new contextualized API for hooks and steps

* Make default context configurable

* Run AfterStep hooks even after failed steps, fixes #370

* Update CHANGELOG and README

* Add step result status to After hook, fixes #378

* Elaborate hooks documentation

* Add test to pass state between contextualized steps

* Update README with example of passing state between steps
2021-08-03 17:48:05 +02:00
Karsten Franke
7d343d4e35
Fix step definition output for Data Tables (#411)
* Fix step definition output for Data Tables

This fixes incorrect step definition output for Data Tables. The
PickleStepArgument_PickleTable type does not exist in the current
messages-go version.

* updated CHANGELOG.md
2021-07-29 10:27:00 +02:00
Viacheslav Poturaev
15358d20e7
Merge pull request #364 from cucumber/allow_empty_return_step
feat(step_definition): Allows to define step function without return.
2021-07-22 20:59:48 +02:00
Viacheslav Poturaev
cdbb0ac3f3 Update documentation 2021-07-22 20:56:26 +02:00
Matt Wynne
48c0e0dd77
Merge pull request #276 from radtriste/issue_222
Added GetGherkinFeatures method to godog.Suite
2021-07-19 12:06:05 -07:00
Matt Wynne
17a562ca79
Merge pull request #407 from vearutop/rel-v0.11.0-main
Merge v0.11.0 release back to main to remove version lag
2021-07-19 10:57:23 -07:00
Viacheslav Poturaev
8860b17e67 Merge branch 'main' into rel-v0.11.0-main
# Conflicts:
#	CHANGELOG.md
#	README.md
2021-07-19 18:12:03 +02:00
radtriste
5566c15759 added GetFeatures method to godog.Suite 2021-07-13 15:00:52 +02:00
tfreville
63fd657a22 test: Add test for stepdef model 2021-07-13 10:35:45 +02:00
tfreville
fca39e4e89 test(convey): Add goconvey for test to ease test writting.
Add tests for panic in test_context initialization.

Made as independ commit so it can be rollbacked.
2021-07-13 10:34:25 +02:00
tfreville
fbed999ad8 feat(step_definition): Allows to define step function without return.
Issue: It is not possible to use function without return when
       matching steps, resulting in a lot of Nil only error
       returns.

Fix: Allows to provide empty result function by correctly matching
     reflect Calls on step Handler.
     When nothing is returned by the Handler, it will return
     nil as if errors was nil.
2021-07-13 10:31:39 +02:00
Matt Wynne
3de6fb09f3
Merge pull request #391 from cucumber/flag-to-pflag
remove renamed imports of pflag.
2021-07-12 23:14:48 -07:00
Viacheslav Poturaev
9a335aed22
Merge pull request #404 from vearutop/gofmt
Fix tests and CircleCI jobs
2021-07-09 16:18:16 +02:00
Viacheslav Poturaev
885805bfd3 Remove parallel testing to avoid "go: updating go.mod: existing contents have changed since last read" 2021-07-07 21:06:13 +02:00
Viacheslav Poturaev
15ab3cd84f Remove parallel testing to avoid "go: updating go.mod: existing contents have changed since last read" 2021-07-07 21:01:26 +02:00
Viacheslav Poturaev
bd397253a4 Run "go mod tidy" during build to comply with https://blog.golang.org/go116-module-changes#TOC_3. 2021-07-07 20:45:51 +02:00
Viacheslav Poturaev
f42c85989f Fix home directory for cimg/go:1.16.5 CI image 2021-07-07 20:32:50 +02:00
Viacheslav Poturaev
8af91e50f6 Revert minimal Go version to 1.13 2021-07-07 20:22:32 +02:00
Viacheslav Poturaev
c6e9cd0e19 Revert return logic to restore previous behavior and pass the original test 2021-07-07 20:12:56 +02:00
Viacheslav Poturaev
ee7ab9c52b Fix example build by pinning untagged version of godog 2021-07-07 19:48:47 +02:00
Viacheslav Poturaev
f34f37dfd2 Upgrade MultiFormatter to use messages-go/v16 2021-07-07 19:47:46 +02:00
Viacheslav Poturaev
d4c6c236b1 Apply gofmt to fix CircleCI jobs 2021-07-07 18:12:11 +02:00
Aslak Hellesøy
7cadaeffdb
Merge pull request #392 from vearutop/multi
Use multiple formatters in the same test run
2021-07-07 16:32:58 +01:00
Matt Wynne
df8c6e49b4
Update CHANGELOG for #402 2021-07-05 12:26:06 -07:00
Matt Wynne
7547f42e11
Merge pull request #402 from mbow/feature/update-cucumber-go-ver
update gherkin-go to v19.0.3
2021-07-05 12:18:06 -07:00
MBow
5414f3c5da update gherkin-go to v19.0.3
update messages-go to v16.0.1
bump gomod version
comment on log line in std os.Stderr
examples to non rc version
go mod tidy
update circle (tbd)
2021-06-28 17:19:43 +01:00
Viacheslav Poturaev
707025de28 Add test for multi formatter 2021-05-30 22:32:34 +02:00
Viacheslav Poturaev
9d4b221f7a Use multiple formatters in the same test run 2021-05-30 22:11:44 +02:00
Rickard Englund
cdf3bfc099 removed renamed imports of pflag.
This was causing way to much investigating in order for me to find
That I've only copied parts of the examples resulting in "flag".Parse
instead of pflag.Parse()
2021-05-30 19:14:26 +02:00
Aslak Hellesøy
60e2e2f4df
Update README.md 2021-04-09 15:15:18 +01:00
Hiram Chirino
5ac22c454c feat: generate simpler snippets that use *godog.DocString and *godog.Table 2021-03-16 09:42:22 +01:00
Hiram Chirino
2b6c9dc82e feat: support auto converting doc strings to plain strings 2021-03-16 09:40:37 +01:00
Anton Ekberg
3bdc35e28e Fix godog version command in issue template 2021-03-16 09:38:01 +01:00
Fredrik Lönnblad
3589a9b1bf
Update CHANGELOG.md 2021-01-17 10:38:44 +01:00
Fredrik Lönnblad
1548642333 Removed rc references for the v0.11.0 release 2021-01-12 20:21:21 +01:00
Fredrik Lönnblad
2b426f8969 Removed rc references for the v0.11.0 release 2021-01-12 20:16:11 +01:00
Rickard Englund
2fc2995149
make pickleStepIDs unique accross multiple paths (#366)
* make pickleStepIDs unique accross multiple paths

* add test case for duplicate pickle ids

* go fmt

Co-authored-by: Rickard Englund <rickard.englund@skf.com>
2020-12-16 13:22:11 +01:00
Fredrik Lönnblad
adfc936dd7
Update README.md 2020-12-05 15:34:27 +01:00
Fredrik Lönnblad
74698e52fa Created v0.11.0-rc2 2020-12-05 15:29:39 +01:00
Fredrik Lönnblad
59cd5d8e3f
Fixed an issue when go test is parsing command-line flags (#359)
* Fixed an issue when go test is parsing command-line flags

* Added some extra information for parsing flags to the README.md
2020-11-26 13:47:47 +01:00
Fredrik Lönnblad
69162a0d82
Removed go1.12 and added go1.15 to CI config (#356)
* Removed go1.12 and added go1.15 to CI config

* Updated release-notes
2020-11-26 11:43:42 +01:00
Fredrik Lönnblad
2f80d08545 Reverted "Create CODE_OF_CONDUCT.md" and added a Code of Conduct info to the README.md
This reverts commit 8ef630bed7.
2020-10-23 12:54:59 +02:00
Fredrik Lönnblad
8ef630bed7
Create CODE_OF_CONDUCT.md 2020-10-21 17:13:30 +02:00
Fredrik Lönnblad
e56f454291 Created release notes and changelog for v0.11.0 2020-10-19 19:02:10 +02:00
Fredrik Lönnblad
c4aea2e999
Update README.md 2020-10-14 11:03:29 +02:00
Fredrik Lönnblad
d4c18852f0
Made a fix for the unstable Randomize Run tests (#354) 2020-10-14 10:39:01 +02:00
Fredrik Lönnblad
d4190b06d8
Added a comment regarding running the examples within the $GOPATH (#352)
* Added a comment regarding running the examples within the GOPATH

* Update README.md
2020-10-14 09:57:06 +02:00
Fredrik Lönnblad
7014a10e2f
Fixed the undefined step definitions help (#350) 2020-10-14 08:39:14 +02:00
Hans van den Bogert
027a1abf0e
Pdoc(FAQ/TestMain): testing.M.Run() is optional (#353) 2020-10-14 07:30:45 +02:00
Fredrik Lönnblad
ae808ea89b
Removed $GOPATH from the README.md and updated the example (#349)
* Removed /Users/fredrik/Projects/go from the README.md and updated the example

* made some more improvements
2020-10-12 09:14:14 +02:00
Fredrik Lönnblad
5e994943b3
Improved the help text of the formatter flag in the run command (#347)
* Improved the help text of the formatter flag in the run command

* Made some more changes to the help text for the run command

* made some small changes to the help text of the run and build cmd
2020-10-12 09:13:45 +02:00
Fredrik Lönnblad
66793de350
Merge pull request #321 from cucumber/new-flag-pkg
Added Cobra for the Command Line Interface
2020-10-08 18:35:06 +02:00
Fredrik Lönnblad
c99a04ca90
Merge pull request #333 from cucumber/upload-artifacts
Added make commands to create artifacts and upload them to a github release
2020-07-25 14:37:40 +02:00
Fredrik Lönnblad
41ff4b4a16 Added make commands to create artifacts and upload them to a github release 2020-07-18 13:18:20 +02:00
Fredrik Lönnblad
daa36b6922
Merge pull request #332 from cucumber/moved-stepdef-to-the-public-formatters-pkg
Moved StepDefinition to the formatters pkg
2020-07-14 18:40:23 +02:00
Fredrik Lönnblad
2fa3b9f08c Moved StepDefinition to the formatters pkg 2020-07-11 10:49:36 +02:00
Fredrik Lönnblad
ce8036f79d
Merge pull request #331 from cucumber/write-output-to-file
--format junit:result.xml will now write to result.xml
2020-07-09 14:26:15 +02:00
Fredrik Lönnblad
d0991c8488 --format junit:result.xml will now write to result.xml 2020-07-08 23:08:49 +02:00
Fredrik Lönnblad
722d97bc48 Added Cobra for the Command Line Interface 2020-07-07 21:13:25 +02:00
Fredrik Lönnblad
e6223baaff
Merge pull request #330 from cucumber/custom-formatter-example
Created a simple example for a custom formatter
2020-07-07 17:26:12 +02:00
Fredrik Lönnblad
eb6779c4ac
Merge pull request #329 from cucumber/internal-parser-pkg
Moved the parser code to a new internal pkg
2020-07-07 08:10:17 +02:00
Fredrik Lönnblad
6d3da7a27b Created a simple example for a custom formatter 2020-07-07 07:54:27 +02:00
Fredrik Lönnblad
813312606f Moved the parser code to a new internal pkg 2020-07-05 18:40:56 +02:00
Fredrik Lönnblad
783f5e40a3
Merge pull request #323 from cucumber/move-formatters-to-internal-pkg
Added internal packages for formatters, storage and models
2020-07-05 18:14:53 +02:00
Fredrik Lönnblad
150c400163 Created internal packages for formatters, storage and models 2020-07-02 08:51:31 +02:00
Fredrik Lönnblad
28ad994ad1
Merge pull request #327 from cucumber/internal-builder-pkg
Added an internal pkg for the builder
2020-07-02 08:21:59 +02:00
Fredrik Lönnblad
99723f8220 Moved the builder code to a new internal pkg 2020-07-01 07:54:59 +02:00
Fredrik Lönnblad
4da375f4c0
Merge pull request #326 from cucumber/internal-parser-pkg
Added an internal package for tags filtering
2020-07-01 07:13:37 +02:00
Fredrik Lönnblad
e38c6ed719 Added an internal package for tags filtering 2020-06-30 22:52:50 +02:00
Fredrik Lönnblad
183de20e80
Merge pull request #322 from cucumber/removed-deprecated-things
Removed deprecated code
2020-06-29 08:36:33 +02:00
Fredrik Lönnblad
dbd8cdf723 Removed deprecated code 2020-06-27 19:13:38 +02:00
Fredrik Lönnblad
c7d739336b Updated CHANGELOG.md references in the release-notes 2020-06-25 10:12:20 +02:00
Fredrik Lönnblad
51a387469c v0.10.0 release 2020-06-25 08:58:03 +02:00
Fredrik Lönnblad
cff1e2f197
Merge pull request #313 from cucumber/v0.10.0-rc1
Wrote Release Notes and updated CHANGELOG, README, etc. for v0.10.0-rc1
2020-06-25 08:24:16 +02:00
Fredrik Lönnblad
fc084134a0 Wrote Release Notes, updated CHANGELOG.md and versions in README.md and godog version const 2020-06-23 20:42:48 +02:00
Fredrik Lönnblad
2cc5a5548a
Update CHANGELOG.md 2020-06-23 20:37:03 +02:00
Fredrik Lönnblad
b7dd08770f
Merge pull request #315 from cucumber/remove-features-with-no-scenarios
Fixed so that we don't execute features with zero scenarios
2020-06-23 20:33:14 +02:00
Fredrik Lönnblad
7df9dadeb9 Fixed so that we don't execute features with zero scenarios 2020-06-23 19:53:46 +02:00
Fredrik Lönnblad
1033ce083b
Merge pull request #317 from cucumber/fixed-the-random-flag-bug
Fixed the broken --random flag
2020-06-21 21:22:13 +02:00
Fredrik Lönnblad
376280cfc6 Fixed the broken --random flag 2020-06-21 14:43:15 +02:00
Fredrik Lönnblad
9795588012 Updated CHANGELOG.md 2020-06-20 23:31:31 +02:00
Fredrik Lönnblad
46c8dbcbcb
Merge pull request #314 from cucumber/deprecations
Deprecated SuiteContext and ConcurrentFormatter
2020-06-20 23:20:29 +02:00
Fredrik Lönnblad
0ef3d6d5e1 Deprecated SuiteContext and ConcurrentFormatter 2020-06-20 23:18:24 +02:00
Fredrik Lönnblad
d9e0ff7489
Merge pull request #312 from cucumber/removed-deprecated-feature-hooks
Removed the deprecated feature hooks
2020-06-20 23:03:03 +02:00
Fredrik Lönnblad
1d724e2107 Removed the deprecated feature hooks 2020-06-20 20:06:30 +02:00
Fredrik Lönnblad
6e01c51e3d
Merge pull request #311 from cucumber/feature/concurrent-scenarios
Added support for concurrent scenarios
2020-06-15 07:10:21 +02:00
Fredrik Lönnblad
39940f55bc Added support for concurrent scenarios 2020-06-14 19:21:01 +02:00
Fredrik Lönnblad
57422f2015
Merge pull request #310 from cucumber/remove-fmt-states
Refactored some states in the formatters and feature struct
2020-06-14 12:12:48 +02:00
Fredrik Lönnblad
b717039e16 Refactored some states in the formatters and feature struct 2020-06-14 09:49:22 +02:00
Fredrik Lönnblad
a03a1b8d2c
Merge pull request #308 from cucumber/bugfix/junit-testsuite-time
Fixed an issue with calculating time for junit testsuite
2020-06-13 10:45:01 +02:00
Fredrik Lönnblad
e61d3558c6 Fixed an issue with calculating time for junit testsuite 2020-06-13 10:39:07 +02:00
Fredrik Lönnblad
849e8e499b
Merge pull request #307 from cucumber/broke-up-some-files
Broke out some code from massive files into new files
2020-06-13 09:25:45 +02:00
Fredrik Lönnblad
25b1915272 Broke out some code from massive files into new files 2020-06-13 09:20:06 +02:00
Fredrik Lönnblad
a57f082852
Merge pull request #306 from cucumber/store-gherkin-ast-in-storage
Added features to the in-mem storage
2020-06-13 09:18:19 +02:00
Fredrik Lönnblad
b1a69ae142 Added features to the in-mem storage 2020-06-13 06:45:14 +02:00
Fredrik Lönnblad
18a045f989
Merge pull request #305 from cucumber/store-results-in-storage
Added Pickle and PickleStep results to the in-mem storage
2020-06-13 06:43:16 +02:00
Fredrik Lönnblad
cd7663fccf Added Pickle and PickleStep results to the in-mem storage 2020-06-10 21:45:23 +02:00
Fredrik Lönnblad
f50bd30ec0
Merge pull request #302 from cucumber/updated-readme
Updated the README.md
2020-06-10 21:44:44 +02:00
Fredrik Lönnblad
0bd3a0e729 Updated the README.md 2020-06-10 21:24:54 +02:00
Fredrik Lönnblad
12a387ec46
Merge pull request #304 from cucumber/in-mem-storage
Added an in-mem storage for pickles
2020-06-09 21:50:59 +02:00
Fredrik Lönnblad
4356addf9f Added an in-mem storage for pickles 2020-06-09 13:30:32 +02:00
Fredrik Lönnblad
055f87f731
Merge pull request #303 from cucumber/unexported-some-exported-properties
Unexported some exported properties in unexported structs
2020-06-07 15:38:43 +02:00
Fredrik Lönnblad
df3ce739e8 Unexported some exported properties in unexported structs 2020-06-07 15:22:50 +02:00
Fredrik Lönnblad
c5a0a58123 Broke out the tag filtering logic to its own file 2020-06-07 09:10:56 +02:00
Fredrik Lönnblad
0b6b3a7b06 Upgraded the minor version of the testify dependency 2020-06-06 18:48:40 +02:00
Fredrik Lönnblad
7f46bb3b36
Merge pull request #301 from cucumber/add-tests-for-the-new-initializers
Added better testing of the Context Initializers and TestSuite{}.Run()
2020-06-06 18:24:11 +02:00
Fredrik Lönnblad
6b2e72016b Copied the SuiteContext for testing of TestSuite{}.Run() 2020-06-06 16:12:19 +02:00
Fredrik Lönnblad
678c3ae733
Merge pull request #300 from cucumber/refactored-suite_context
Refactored suite_context.go
2020-06-06 15:44:44 +02:00
Fredrik Lönnblad
f08bd7c463 Refactored suite_context.go 2020-06-06 15:39:17 +02:00
Fredrik Lönnblad
1deee1058e
Merge pull request #298 from cucumber/parallel-build-tests
Made the builder tests run in parallel
2020-05-27 09:40:07 +02:00
Fredrik Lönnblad
d0a345e507
Update README.md 2020-05-25 09:19:29 +02:00
Fredrik Lönnblad
55d43e1b59 Made the builder tests run in parallel 2020-05-24 19:05:08 +02:00
Fredrik Lönnblad
84e064bd56
Update CHANGELOG.md 2020-05-23 09:11:49 +02:00
Fredrik Lönnblad
43844be3e9
Merge pull request #297 from cucumber/context-docs
Readded some legacy doc for FeatureContext
2020-05-23 09:02:20 +02:00
Fredrik Lönnblad
13acd2d219 Readded some legacy doc for FeatureContext 2020-05-23 08:51:23 +02:00
Fredrik Lönnblad
b0f295dc28
Merge pull request #295 from cucumber/formatter-test-lookover
Moved fmt tests to a godog_test pkg and restructured the fmt output tests
2020-05-23 08:04:28 +02:00
Fredrik Lönnblad
10728fac0b
Merge pull request #294 from cucumber/new-test-contexts
Added the new TestSuiteInitializer and ScenarioInitializer
2020-05-22 22:44:55 +02:00
Fredrik Lönnblad
abdd8685e5
Merge pull request #296 from cucumber/builder-test-lookover
Moved builder tests to a godog_test pkg
2020-05-22 13:58:18 +02:00
Fredrik Lönnblad
a1152ca1c9 Moved builder tests to a godog_test pkg 2020-05-22 13:56:20 +02:00
Fredrik Lönnblad
3ca7156650 Moved the fmt tests to a godog_test pkg and restructured the fmt output tests 2020-05-22 12:52:27 +02:00
Fredrik Lönnblad
e6227a2e0f Added the new TestSuiteInitializer and ScenarioInitializer 2020-05-18 09:48:06 +02:00
Fredrik Lönnblad
7568b291e4
Merge pull request #293 from cucumber/cleaning/remove-pre-go112-stuff
Removed pre go112 build code
2020-05-17 08:37:37 +02:00
Fredrik Lönnblad
86229dbbf9 Removed pre go112 build code 2020-05-16 10:03:13 +02:00
Fredrik Lönnblad
0f354e867a
Update config.yml 2020-05-05 09:24:15 +02:00
Fredrik Lönnblad
45e0973e60
Update CHANGELOG.md 2020-05-05 07:31:58 +02:00
Fredrik Lönnblad
27fc1bb031
Merge pull request #290 from cucumber/linting-improvement
Updated linting checks in circleci config and fixed linting issues
2020-05-05 07:29:25 +02:00
Fredrik Lönnblad
d0a28b5a94 Updated linting checks in circleci config and fixed linting issues 2020-05-03 12:09:51 +02:00
Fredrik Lönnblad
700c90b3f0
Update CHANGELOG.md 2020-05-03 11:24:50 +02:00
Fredrik Lönnblad
521a9688b9
Merge pull request #289 from cucumber/assert-godogs-example
Added an example for how to use assertion pkgs like testify with godog
2020-05-03 08:04:36 +02:00
Fredrik Lönnblad
bfee72ddec Added an example for how to use assertion pkgs like testify with godog 2020-05-02 18:52:19 +02:00
Fredrik Lönnblad
075d624710 Added a missed test file and updated the CHANGELOG 2020-04-30 14:32:13 +02:00
Fredrik Lönnblad
8fb7cd9769
Merge pull request #288 from cucumber/bugfix/empty-feature-nil-pointer
Fixed issue with empty feature file causing nil pointer deref
2020-04-30 14:30:31 +02:00
Fredrik Lönnblad
0c864f1400 Fixed issue with empty feature file causing nil pointer deref 2020-04-30 11:15:40 +02:00
Jayson Smith
64ede2d482
Update README.md 2020-04-14 23:58:05 -07:00
Fredrik Lönnblad
68d94c03b8
Update CHANGELOG.md 2020-03-26 12:53:11 +01:00
Fredrik Lönnblad
eb36b99512
Merge pull request #278 from cucumber/concurrent-runs-only
Updated so that we run all tests concurrent now
2020-03-26 12:44:47 +01:00
Fredrik Lönnblad
edfd2a1c3a Updated so that we run all tests concurrent now 2020-03-26 12:40:15 +01:00
Fredrik Lönnblad
4da503aab2
Merge pull request #273 from cucumber/concurrent-cucumber-formatter
Added concurrency support to the cucumber formatter
2020-03-26 12:20:32 +01:00
Fredrik Lönnblad
d6f491a3dc Added concurrency support to the cucumber formatter 2020-03-26 12:18:01 +01:00
Fredrik Lönnblad
b8863f42ea
Merge pull request #274 from cucumber/concurrent-events-formatter
Added concurrency support to the events formatter
2020-03-26 12:14:12 +01:00
Fredrik Lönnblad
172b91ea58 Added concurrency support to the events formatter 2020-03-26 12:11:45 +01:00
Fredrik Lönnblad
8cd177247a
Merge pull request #275 from cucumber/concurrent-pretty-formatter
Added concurrency support to the pretty formatter
2020-03-26 12:07:46 +01:00
Fredrik Lönnblad
2deda99861 Added concurrency support to the pretty formatter 2020-03-26 11:56:28 +01:00
Fredrik Lönnblad
c9206b43f6
Merge pull request #272 from cucumber/improved-verification-of-concurrent-runs
Added comparison between single and multi threaded runs
2020-03-25 08:27:57 +01:00
Fredrik Lönnblad
11f28803ec Added comparison between single and multi threaded runs 2020-03-24 12:01:58 +01:00
Fredrik Lönnblad
4d5024dc24
Merge pull request #271 from cucumber/broke-out-snippets-gen
Broke out snippets gen and added sorting on method name
2020-03-24 10:59:13 +01:00
Fredrik Lönnblad
5afad4dee9
Update CHANGELOG.md 2020-03-24 10:34:01 +01:00
Fredrik Lönnblad
0d1fb60ba0 Added sorting for undefined snippets on method name 2020-03-24 10:05:05 +01:00
Fredrik Lönnblad
4871754e06 Broke out snippets to its own file 2020-03-24 10:00:36 +01:00
Fredrik Lönnblad
5d351e86c4 Made progress formatter verification a bit more accurate 2020-03-24 09:56:59 +01:00
Fredrik Lönnblad
11dde19cd3
Merge pull request #270 from leviable/fix-screenshot-paths
Update paths to screenshots for examples
2020-03-23 17:27:22 +01:00
leviable
7e432e13ed Update example screenshot paths 2020-03-23 11:24:31 -05:00
Fredrik Lönnblad
d56cf10d0d
Update CHANGELOG.md 2020-03-23 13:16:17 +01:00
Fredrik Lönnblad
e6e66731b5 Fixed failing builder tests due to the v0.9.0 change 2020-03-23 13:12:51 +01:00
Fredrik Lönnblad
93abaf53bc
Update CHANGELOG.md 2020-03-23 13:06:48 +01:00
Fredrik Lönnblad
0180f9304e
Merge pull request #268 from cucumber/release/v0.9.0
Release/v0.9.0
2020-03-23 11:05:38 +01:00
Fredrik Lönnblad
ec88ee5226 Fixed final release doc for v0.9.0 2020-03-22 18:08:17 +01:00
Fredrik Lönnblad
f8287cd48c Merge branch 'master' into release/v0.9.0 2020-03-22 18:06:50 +01:00
Fredrik Lönnblad
d5c7a25361
Update CHANGELOG.md 2020-03-22 17:31:40 +01:00
Fredrik Lönnblad
12946b55d6
Merge pull request #266 from cucumber/release/v0.9.0-rc2
Created release candidate v0.9.0-rc2
2020-03-16 09:27:06 -03:00
Fredrik Lönnblad
315f9e96d8 Created release candidate 2 2020-03-16 08:10:04 -03:00
Fredrik Lönnblad
1b471d62c4 Merge branch 'master' into release/v0.9.0 2020-03-16 08:04:07 -03:00
Fredrik Lönnblad
732eff4c29
Merge pull request #263 from denis-trofimov/patch-1
Fix Bug then running the example of an API, a feature version need to bump to latest reported 0.8.1 #262
2020-03-16 07:44:53 -03:00
Denis Trofimov
05db4cc9a9
Fix #262
Bug then running the example of an API, a feature version need to bump to latest reported 0.8.1 #262
2020-03-16 12:24:05 +03:00
Fredrik Lönnblad
4bef0c945a Fixed a bug when having multiple failed steps across multiple features 2020-03-15 21:09:11 -03:00
Fredrik Lönnblad
3a53f6f6bf
Update README.md 2020-03-15 10:03:09 -03:00
Fredrik Lönnblad
1c38b5b245 Updated doc references to gherkin-go and messages-go 2020-03-14 09:13:14 -03:00
Fredrik Lönnblad
c64517055d
Create CONTRIBUTING.md 2020-03-14 08:50:44 -03:00
Fredrik Lönnblad
0c0ce69ce5 Update issue templates 2020-03-14 08:44:56 -03:00
Fredrik Lönnblad
8a7bb1dc02 Update issue templates 2020-03-14 08:43:55 -03:00
Fredrik Lönnblad
5cef7b6577
Merge pull request #258 from cucumber/upgrade-gherkin-and-messages
Upgraded gherkin-go and messages-go to latest
2020-03-13 14:48:58 -03:00
Fredrik Lönnblad
1b1efd4a3b Downgraded go version in go.mod 2020-03-12 15:19:19 -03:00
Fredrik Lönnblad
58bcac6a61 Upgraded gherkin-go and messages-go to latest 2020-03-12 15:16:43 -03:00
Fredrik Lönnblad
f045623fcf Fixed dependency issue 2020-03-10 15:10:12 -03:00
Fredrik Lönnblad
0ab3e09327 Merge branch 'master' into release/v0.9.0 2020-03-10 09:23:19 -03:00
Fredrik Lönnblad
568d966cd4
Update README.md 2020-03-10 07:47:51 -03:00
Fredrik Lönnblad
cc800f1231
Merge pull request #246 from cucumber/release/v0.9.0-rc1
Updated README.md and added release-notes/v0.9.0.md
2020-03-10 07:43:52 -03:00
Fredrik Lönnblad
9d238731cf
Update CHANGELOG.md 2020-03-09 17:02:46 -03:00
Fredrik Lönnblad
f3c9737402
Update CHANGELOG.md 2020-03-09 17:02:21 -03:00
Fredrik Lönnblad
b6e87e0655
Merge pull request #247 from titouanfreville/fix_formatter_injected_text
<fix>(PRETIFIER): fix s method
2020-03-09 16:58:38 -03:00
Fredrik Lönnblad
591e055a38
Update README.md 2020-03-09 16:54:42 -03:00
tfreville
fe2a967670 Clean change on pretty. Make test on new TC meaningfull again. 2020-03-09 20:54:10 +01:00
tfreville
32741b9662 Clean logs 2020-03-09 14:42:16 +01:00
Titouan
6e9459c454
Merge pull request #1 from lonnblad/fix_formatter_injected_text
Fixed indent issue with json output fixture
2020-03-09 14:08:02 +01:00
Fredrik Lönnblad
2a5f53a04e Fixed indent issue with json output fixture 2020-03-09 08:36:44 -03:00
tfreville
d76374bf14 Test ok but the output of cucumber.json is broken. Pushed so someone else can also take a look. 2020-03-09 11:51:41 +01:00
tfreville
eb75d692bd <fix>(PRETIFIER): Fix s method to not have errors on negative entry
Context:
While trying to create an helper library to manage http rest api testing, I made a system witch allow to pick value from responses, header, cookie, ... and inject then as variables.
Issue:
Doing this, when the inject variable make the line longer than the longest declared step, godog will failed to render test result under pretty formatting cause it will try to write a comment on a negative index
Fix:
Fix s methods so it will not goes to fatal when recieving negative number.
2020-03-09 10:39:20 +01:00
261 изменённых файлов: 16951 добавлений и 6552 удалений

Просмотреть файл

@ -1,86 +0,0 @@
version: 2.1
orbs:
codecov: codecov/codecov@1.0.5
executors:
exec_go_1_12:
docker:
- image: circleci/golang:1.12.16
exec_go_1_13:
docker:
- image: circleci/golang:1.13.8
exec_go_1_14:
docker:
- image: circleci/golang:1.14.0
commands:
install:
description: "Install dependencies"
steps:
- run: GO111MODULE=on go mod vendor -v
vet:
description: "Run go vet"
steps:
- run: go vet github.com/cucumber/godog
- run: go vet github.com/cucumber/godog/colors
fmt:
description: "Run go fmt"
steps:
- run: test -z "$(go fmt ./...)"
lint:
description: "Run golint"
steps:
- run: go get -u golang.org/x/lint/golint
- run: golint ./godog
- run: golint ./cmd/godog/main.go
godog:
description: "Run godog"
steps:
- run: go install ./cmd/godog
- run: godog -f progress --strict
go_test:
description: "Run go test"
steps:
- run: go test -v -race -coverprofile=coverage.txt -covermode=atomic
coverage:
description: "Report on code coverage"
steps:
- codecov/upload:
file: "coverage.txt"
all:
description: "Run all commands against godog code"
steps:
- checkout
- install
- vet
- fmt
- lint
- godog
- go_test
- coverage
jobs:
go1_12:
working_directory: /go/src/github.com/cucumber/godog
executor: exec_go_1_12
steps:
- all
go1_13:
working_directory: /go/src/github.com/cucumber/godog
executor: exec_go_1_13
steps:
- all
go1_14:
working_directory: /go/src/github.com/cucumber/godog
executor: exec_go_1_14
steps:
- all
workflows:
version: 2
test:
jobs:
- go1_12
- go1_13
- go1_14

6
.github/renovate.json предоставленный Обычный файл
Просмотреть файл

@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"github>cucumber/renovate-config"
]
}

47
.github/workflows/gorelease.yml предоставленный Обычный файл
Просмотреть файл

@ -0,0 +1,47 @@
# Gorelease comments public API changes to pull request.
name: gorelease
on:
pull_request:
# Cancel the workflow in progress in newer build is about to start.
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
env:
GO_VERSION: stable
jobs:
gorelease:
runs-on: ubuntu-latest
steps:
- name: Install Go stable
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Checkout code
uses: actions/checkout@v4
- name: Gorelease cache
uses: actions/cache@v4
with:
path: |
~/go/bin/gorelease
key: ${{ runner.os }}-gorelease-generic
- name: Gorelease
id: gorelease
run: |
test -e ~/go/bin/gorelease || go install golang.org/x/exp/cmd/gorelease@latest
OUTPUT=$(gorelease 2>&1 || exit 0)
echo "${OUTPUT}"
OUTPUT="${OUTPUT//$'\n'/%0A}"
echo "report=$OUTPUT" >> $GITHUB_OUTPUT
- name: Comment Report
continue-on-error: true
uses: marocchino/sticky-pull-request-comment@v2
with:
header: gorelease
message: |
### Go API Changes
<pre>
${{ steps.gorelease.outputs.report }}
</pre>

44
.github/workflows/release-assets.yml предоставленный Обычный файл
Просмотреть файл

@ -0,0 +1,44 @@
# This script uploads application binaries as GitHub release assets.
name: release-assets
on:
release:
types:
- created
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
jobs:
build:
name: Upload Release Assets
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: stable
- name: Checkout code
uses: actions/checkout@v4
- name: Build artifacts
run: |
make artifacts
- name: Upload linux amd64 binary
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./_artifacts/godog-${{ github.event.release.tag_name }}-linux-amd64.tar.gz
asset_name: godog-${{ github.event.release.tag_name }}-linux-amd64.tar.gz
asset_content_type: application/tar+gzip
- name: Upload linux arm64 binary
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./_artifacts/godog-${{ github.event.release.tag_name }}-linux-arm64.tar.gz
asset_name: godog-${{ github.event.release.tag_name }}-linux-arm64.tar.gz
asset_content_type: application/tar+gzip
- name: Upload darwin amd64 binary
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./_artifacts/godog-${{ github.event.release.tag_name }}-darwin-amd64.tar.gz
asset_name: godog-${{ github.event.release.tag_name }}-darwin-amd64.tar.gz
asset_content_type: application/tar+gzip

55
.github/workflows/test.yml предоставленный Обычный файл
Просмотреть файл

@ -0,0 +1,55 @@
name: test
on:
push:
branches:
- main
pull_request:
jobs:
test:
strategy:
matrix:
go-version: [ 1.16.x, 1.17.x, oldstable, stable ] # Lowest supported and current stable versions.
runs-on: ubuntu-latest
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
- name: Go cache
uses: actions/cache@v4
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-cache-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-cache
- name: Run gofmt
run: gofmt -d -e . 2>&1 | tee outfile && test -z "$(cat outfile)" && rm outfile
- name: Run staticcheck
if: matrix.go-version == 'stable'
uses: dominikh/staticcheck-action@v1.3.1
with:
version: "latest"
install-go: false
cache-key: ${{ matrix.go }}
- name: Run go vet
run: |
go vet ./...
cd _examples && go vet ./... && cd ..
- name: Run go test
run: |
go test -v -race -coverprofile=coverage.txt -covermode=atomic ./...
cd _examples && go test -v -race ./... && cd ..
- name: Run godog
run: |
go install ./cmd/godog
godog -f progress --strict
- name: Report on code coverage
if: matrix.go-version == 'stable'
uses: codecov/codecov-action@v4
with:
file: ./coverage.txt

8
.gitignore предоставленный
Просмотреть файл

@ -4,4 +4,10 @@
Gopkg.lock
Gopkg.toml
.DS_Store
.DS_Store
.idea
.vscode
_artifacts
vendor

Просмотреть файл

@ -1,4 +1,4 @@
# CHANGE LOG
# Changelog
All notable changes to this project will be documented in this file.
@ -6,75 +6,264 @@ This project adheres to [Semantic Versioning](http://semver.org).
This document is formatted according to the principles of [Keep A CHANGELOG](http://keepachangelog.com).
----
## [Unreleased]
## Unreleased
### Added
- Step text is added to "step is undefined" error - ([669](https://github.com/cucumber/godog/pull/669) - [vearutop](https://github.com/vearutop))
### Changed
- Run godog features in CircleCI in strict mode ([jaysonesmith])
- Removed TestMain call in `suite_test.go` for CI. ([jaysonesmith])
- Migrated to [gherkin-go - v9.2.0](https://github.com/cucumber/gherkin-go/releases/tag/v9.2.0). ([240](https://github.com/cucumber/godog/pull/240) - [lonnblad])
### Deprecated
### Removed
- Replace deprecated `::set-output` - ([681](https://github.com/cucumber/godog/pull/681) - [nodeg](https://github.com/nodeg))
### Fixed
- fix(errors): fix(errors): Fix expected Step argument count for steps with `context.Context` ([679](https://github.com/cucumber/godog/pull/679) - [tigh-latte](https://github.com/tigh-latte))
- fix(formatter): On concurrent execution, execute formatter at end of Scenario - ([645](https://github.com/cucumber/godog/pull/645) - [tigh-latte](https://github.com/tigh-latte))
- Fixed the time attributes in the JUnit formatter. ([232](https://github.com/cucumber/godog/pull/232) - [lonnblad])
- Re enable custom formatters. ([238](https://github.com/cucumber/godog/pull/238) - [ericmcbride])
- Added back suite_test.go ([jaysonesmith])
- Normalise module paths for use on Windows ([242](https://github.com/cucumber/godog/pull/242) - [gjtaylor])
## [v0.15.0]
### Added
- Improved the type checking of step return types and improved the error messages - ([647](https://github.com/cucumber/godog/pull/647) - [johnlon](https://github.com/johnlon))
- Ambiguous step definitions will now be detected when strict mode is activated - ([636](https://github.com/cucumber/godog/pull/636)/([648](https://github.com/cucumber/godog/pull/648) - [johnlon](https://github.com/johnlon))
- Provide support for attachments / embeddings including a new example in the examples dir - ([623](https://github.com/cucumber/godog/pull/623) - [johnlon](https://github.com/johnlon))
### Changed
- Formatters now have a `Close` method and associated `io.Writer` changed to `io.WriteCloser`.
## [v0.14.1]
### Added
- Provide testing.T-compatible interface on test context, allowing usage of assertion libraries such as testify's assert/require - ([571](https://github.com/cucumber/godog/pull/571) - [mrsheepuk](https://github.com/mrsheepuk))
- Created releasing guidelines - ([608](https://github.com/cucumber/godog/pull/608) - [glibas](https://github.com/glibas))
### Fixed
- Step duration calculation - ([616](https://github.com/cucumber/godog/pull/616) - [iaroslav-ciupin](https://github.com/iaroslav-ciupin))
- Invalid memory address or nil pointer dereference in RetrieveFeatures - ([566](https://github.com/cucumber/godog/pull/566) - [corneldamian](https://github.com/corneldamian))
## [v0.14.0]
### Added
- Improve ErrSkip handling, add test for Summary and operations order ([584](https://github.com/cucumber/godog/pull/584) - [vearutop](https://github.com/vearutop))
### Fixed
- Remove line overwriting for scenario outlines in cucumber formatter ([605](https://github.com/cucumber/godog/pull/605) - [glibas](https://github.com/glibas))
- Remove duplicate warning message ([590](https://github.com/cucumber/godog/pull/590) - [vearutop](https://github.com/vearutop))
- updated base formatter to set a scenario as passed unless there exist ([582](https://github.com/cucumber/godog/pull/582) - [roskee](https://github.com/roskee))
### Changed
- Update test.yml ([583](https://github.com/cucumber/godog/pull/583) - [vearutop](https://github.com/vearutop))
## [v0.13.0]
### Added
- Support for reading feature files from an `fs.FS` ([550](https://github.com/cucumber/godog/pull/550) - [tigh-latte](https://github.com/tigh-latte))
- Added keyword functions. ([509](https://github.com/cucumber/godog/pull/509) - [otrava7](https://github.com/otrava7))
- Prefer go test to use of godog cli in README ([548](https://github.com/cucumber/godog/pull/548) - [danielhelfand](https://github.com/danielhelfand))
- Use `fs.FS` abstraction for filesystem ([550](https://github.com/cucumber/godog/pull/550) - [tigh-latte](https://github.com/tigh-latte))
- Cancel context for each scenario ([514](https://github.com/cucumber/godog/pull/514) - [draganm](https://github.com/draganm))
### Fixed
- Improve hooks invocation flow ([568](https://github.com/cucumber/godog/pull/568) - [vearutop](https://github.com/vearutop))
- Result of testing.T respect strict option ([539](https://github.com/cucumber/godog/pull/539) - [eiel](https://github.com/eiel))
### Changed
- BREAKING CHANGE, upgraded cucumber and messages dependencies = ([515](https://github.com/cucumber/godog/pull/515) - [otrava7](https://github.com/otrava7))
## [v0.12.6]
### Changed
- Each scenario is run with a cancellable `context.Context` which is cancelled at the end of the scenario. ([514](https://github.com/cucumber/godog/pull/514) - [draganm](https://github.com/draganm))
- README example is updated with `context.Context` and `go test` usage. ([477](https://github.com/cucumber/godog/pull/477) - [vearutop](https://github.com/vearutop))
- Removed deprecation of `godog.BindFlags`. ([498](https://github.com/cucumber/godog/pull/498) - [vearutop](https://github.com/vearutop))
- Pretty Print when using rules. ([480](https://github.com/cucumber/godog/pull/480) - [dumpsterfireproject](https://github.com/dumpsterfireproject))
### Fixed
- Fixed a bug which would ignore the context returned from a substep.([488](https://github.com/cucumber/godog/pull/488) - [wichert](https://github.com/wichert))
- Fixed a bug which would cause a panic when using the pretty formatter with a feature that contained a rule. ([480](https://github.com/cucumber/godog/pull/480) - [dumpsterfireproject](https://github.com/dumpsterfireproject))
- Multiple invocations of AfterScenario hooks in case of undefined steps. ([494](https://github.com/cucumber/godog/pull/494) - [vearutop](https://github.com/vearutop))
- Add a check for missing test files and raise a more helpful error. ([468](https://github.com/cucumber/godog/pull/468) - [ALCooper12](https://github.com/ALCooper12))
- Fix version subcommand. Do not print usage if run subcommand fails. ([475](https://github.com/cucumber/godog/pull/475) - [coopernurse](https://github.com/coopernurse))
### Added
- Add new option for created features with parsing from byte slices. ([476](https://github.com/cucumber/godog/pull/476) - [akaswenwilk](https://github.com/akaswenwilk))
### Deprecated
- `godog` CLI tool prints deprecation warning. ([489](https://github.com/cucumber/godog/pull/489) - [vearutop](https://github.com/vearutop))
## [v0.12.5]
### Changed
- Changed underlying cobra command setup to return errors instead of calling `os.Exit` directly to enable simpler testing. ([454](https://github.com/cucumber/godog/pull/454) - [mxygem](https://github.com/mxygem))
- Remove use of deprecated methods from `_examples`. ([460](https://github.com/cucumber/godog/pull/460) - [ricardogarfe](https://github.com/ricardogarfe))
### Fixed
- Support for go1.18 in `godog` cli mode ([466](https://github.com/cucumber/godog/pull/466) - [vearutop](https://github.com/vearutop))
## [v0.12.4]
### Added
- Allow suite-level configuration of steps and hooks ([453](https://github.com/cucumber/godog/pull/453) - [vearutop](https://github.com/vearutop))
## [v0.12.3]
### Added
- Automated binary releases with GitHub Actions ([437](https://github.com/cucumber/godog/pull/437) - [vearutop](https://github.com/vearutop))
- Automated binary versioning with `go install` ([437](https://github.com/cucumber/godog/pull/437) - [vearutop](https://github.com/vearutop))
- Module with local replace in examples ([437](https://github.com/cucumber/godog/pull/437) - [vearutop](https://github.com/vearutop))
### Changed
- suggest to use `go install` instead of the deprecated `go get` to install the `godog` binary ([449](https://github.com/cucumber/godog/pull/449) - [dmitris](https://github.com/dmitris))
### Fixed
- After Scenario hook is called before After Step ([444](https://github.com/cucumber/godog/pull/444) - [vearutop](https://github.com/vearutop))
- `check-go-version` in Makefile to run on WSL. ([443](https://github.com/cucumber/godog/pull/443) - [mxygem](https://github.com/mxygem))
## [v0.12.2]
### Fixed
- Error in `go mod tidy` with `GO111MODULE=off` ([436](https://github.com/cucumber/godog/pull/436) - [vearutop](https://github.com/vearutop))
## [v0.12.1]
### Fixed
- Unintended change of behavior in before step hook ([424](https://github.com/cucumber/godog/pull/424) - [nhatthm](https://github.com/nhatthm))
## [v0.12.0]
### Added
- Support for step definitions without return ([364](https://github.com/cucumber/godog/pull/364) - [titouanfreville](https://github.com/titouanfreville))
- Contextualized hooks for scenarios and steps ([409](https://github.com/cucumber/godog/pull/409) - [vearutop](https://github.com/vearutop))
- Step result status in After hook ([409](https://github.com/cucumber/godog/pull/409) - [vearutop](https://github.com/vearutop))
- Support auto converting doc strings to plain strings ([380](https://github.com/cucumber/godog/pull/380) - [chirino](https://github.com/chirino))
- Use multiple formatters in the same test run ([392](https://github.com/cucumber/godog/pull/392) - [vearutop](https://github.com/vearutop))
- Added `RetrieveFeatures()` method to `godog.TestSuite` ([276](https://github.com/cucumber/godog/pull/276) - [radtriste](https://github.com/radtriste))
- Added support to create custom formatters ([372](https://github.com/cucumber/godog/pull/372) - [leviable](https://github.com/leviable))
### Changed
- Upgraded gherkin-go to v19 and messages-go to v16 ([402](https://github.com/cucumber/godog/pull/402) - [mbow](https://github.com/mbow))
- Generate simpler snippets that use *godog.DocString and *godog.Table ([379](https://github.com/cucumber/godog/pull/379) - [chirino](https://github.com/chirino))
### Deprecated
- `ScenarioContext.BeforeScenario`, use `ScenarioContext.Before` ([409](https://github.com/cucumber/godog/pull/409)) - [vearutop](https://github.com/vearutop))
- `ScenarioContext.AfterScenario`, use `ScenarioContext.After` ([409](https://github.com/cucumber/godog/pull/409)) - [vearutop](https://github.com/vearutop))
- `ScenarioContext.BeforeStep`, use `ScenarioContext.StepContext().Before` ([409](https://github.com/cucumber/godog/pull/409)) - [vearutop](https://github.com/vearutop))
- `ScenarioContext.AfterStep`, use `ScenarioContext.StepContext().After` ([409](https://github.com/cucumber/godog/pull/409)) - [vearutop](https://github.com/vearutop))
### Fixed
- Incorrect step definition output for Data Tables ([411](https://github.com/cucumber/godog/pull/411) - [karfrank](https://github.com/karfrank))
- `ScenarioContext.AfterStep` not invoked after a failed case ([409](https://github.com/cucumber/godog/pull/409) - [vearutop](https://github.com/vearutop)))
- Can't execute multiple specific scenarios in the same feature file ([414](https://github.com/cucumber/godog/pull/414) - [vearutop](https://github.com/vearutop)))
## [v0.11.0]
### Added
- Created a simple example for a custom formatter ([330](https://github.com/cucumber/godog/pull/330) - [lonnblad](https://github.com/lonnblad))
- --format junit:result.xml will now write to result.xml ([331](https://github.com/cucumber/godog/pull/331) - [lonnblad](https://github.com/lonnblad))
- Added make commands to create artifacts and upload them to a github release ([333](https://github.com/cucumber/godog/pull/333) - [lonnblad](https://github.com/lonnblad))
- Created release notes and changelog for v0.11.0 ([355](https://github.com/cucumber/godog/pull/355) - [lonnblad](https://github.com/lonnblad))
- Created v0.11.0-rc2 ([362](https://github.com/cucumber/godog/pull/362) - [lonnblad](https://github.com/lonnblad))
### Changed
- Added Cobra for the Command Line Interface ([321](https://github.com/cucumber/godog/pull/321) - [lonnblad](https://github.com/lonnblad))
- Added internal packages for formatters, storage and models ([323](https://github.com/cucumber/godog/pull/323) - [lonnblad](https://github.com/lonnblad))
- Added an internal package for tags filtering ([326](https://github.com/cucumber/godog/pull/326) - [lonnblad](https://github.com/lonnblad))
- Added an internal pkg for the builder ([327](https://github.com/cucumber/godog/pull/327) - [lonnblad](https://github.com/lonnblad))
- Moved the parser code to a new internal pkg ([329](https://github.com/cucumber/godog/pull/329) - [lonnblad](https://github.com/lonnblad))
- Moved StepDefinition to the formatters pkg ([332](https://github.com/cucumber/godog/pull/332) - [lonnblad](https://github.com/lonnblad))
- Removed go1.12 and added go1.15 to CI config ([356](https://github.com/cucumber/godog/pull/356) - [lonnblad](https://github.com/lonnblad))
### Fixed
- Improved the help text of the formatter flag in the run command ([347](https://github.com/cucumber/godog/pull/347) - [lonnblad](https://github.com/lonnblad))
- Removed $GOPATH from the README.md and updated the example ([349](https://github.com/cucumber/godog/pull/349) - [lonnblad](https://github.com/lonnblad))
- Fixed the undefined step definitions help ([350](https://github.com/cucumber/godog/pull/350) - [lonnblad](https://github.com/lonnblad))
- Added a comment regarding running the examples within the $GOPATH ([352](https://github.com/cucumber/godog/pull/352) - [lonnblad](https://github.com/lonnblad))
- doc(FAQ/TestMain): `testing.M.Run()` is optional ([353](https://github.com/cucumber/godog/pull/353) - [hansbogert](https://github.com/hansbogert))
- Made a fix for the unstable Randomize Run tests ([354](https://github.com/cucumber/godog/pull/354) - [lonnblad](https://github.com/lonnblad))
- Fixed an issue when go test is parsing command-line flags ([359](https://github.com/cucumber/godog/pull/359) - [lonnblad](https://github.com/lonnblad))
- Make pickleStepIDs unique accross multiple paths ([366](https://github.com/cucumber/godog/pull/366) - [rickardenglund](https://github.com/rickardenglund))
### Removed
- Removed deprecated code ([322](https://github.com/cucumber/godog/pull/322) - [lonnblad](https://github.com/lonnblad))
## [v0.10.0]
### Added
- Added concurrency support to the pretty formatter ([275](https://github.com/cucumber/godog/pull/275) - [lonnblad](https://github.com/lonnblad))
- Added concurrency support to the events formatter ([274](https://github.com/cucumber/godog/pull/274) - [lonnblad](https://github.com/lonnblad))
- Added concurrency support to the cucumber formatter ([273](https://github.com/cucumber/godog/pull/273) - [lonnblad](https://github.com/lonnblad))
- Added an example for how to use assertion pkgs like testify with godog ([289](https://github.com/cucumber/godog/pull/289) - [lonnblad](https://github.com/lonnblad))
- Added the new TestSuiteInitializer and ScenarioInitializer ([294](https://github.com/cucumber/godog/pull/294) - [lonnblad](https://github.com/lonnblad))
- Added an in-mem storage for pickles ([304](https://github.com/cucumber/godog/pull/304) - [lonnblad](https://github.com/lonnblad))
- Added Pickle and PickleStep results to the in-mem storage ([305](https://github.com/cucumber/godog/pull/305) - [lonnblad](https://github.com/lonnblad))
- Added features to the in-mem storage ([306](https://github.com/cucumber/godog/pull/306) - [lonnblad](https://github.com/lonnblad))
- Broke out some code from massive files into new files ([307](https://github.com/cucumber/godog/pull/307) - [lonnblad](https://github.com/lonnblad))
- Added support for concurrent scenarios ([311](https://github.com/cucumber/godog/pull/311) - [lonnblad](https://github.com/lonnblad))
### Changed
- Broke out snippets gen and added sorting on method name ([271](https://github.com/cucumber/godog/pull/271) - [lonnblad](https://github.com/lonnblad))
- Updated so that we run all tests concurrent now ([278](https://github.com/cucumber/godog/pull/278) - [lonnblad](https://github.com/lonnblad))
- Moved fmt tests to a godog_test pkg and restructured the fmt output tests ([295](https://github.com/cucumber/godog/pull/295) - [lonnblad](https://github.com/lonnblad))
- Moved builder tests to a godog_test pkg ([296](https://github.com/cucumber/godog/pull/296) - [lonnblad](https://github.com/lonnblad))
- Made the builder tests run in parallel ([298](https://github.com/cucumber/godog/pull/298) - [lonnblad](https://github.com/lonnblad))
- Refactored suite_context.go ([300](https://github.com/cucumber/godog/pull/300) - [lonnblad](https://github.com/lonnblad))
- Added better testing of the Context Initializers and TestSuite{}.Run() ([301](https://github.com/cucumber/godog/pull/301) - [lonnblad](https://github.com/lonnblad))
- Updated the README.md ([302](https://github.com/cucumber/godog/pull/302) - [lonnblad](https://github.com/lonnblad))
- Unexported some exported properties in unexported structs ([303](https://github.com/cucumber/godog/pull/303) - [lonnblad](https://github.com/lonnblad))
- Refactored some states in the formatters and feature struct ([310](https://github.com/cucumber/godog/pull/310) - [lonnblad](https://github.com/lonnblad))
### Deprecated
- Deprecated SuiteContext and ConcurrentFormatter ([314](https://github.com/cucumber/godog/pull/314) - [lonnblad](https://github.com/lonnblad))
### Fixed
- Fixed failing builder tests due to the v0.9.0 change ([lonnblad](https://github.com/lonnblad))
- Update paths to screenshots for examples ([270](https://github.com/cucumber/godog/pull/270) - [leviable](https://github.com/leviable))
- Made progress formatter verification a bit more accurate ([lonnblad](https://github.com/lonnblad))
- Added comparison between single and multi threaded runs ([272](https://github.com/cucumber/godog/pull/272) - [lonnblad](https://github.com/lonnblad))
- Fixed issue with empty feature file causing nil pointer deref ([288](https://github.com/cucumber/godog/pull/288) - [lonnblad](https://github.com/lonnblad))
- Updated linting checks in circleci config and fixed linting issues ([290](https://github.com/cucumber/godog/pull/290) - [lonnblad](https://github.com/lonnblad))
- Readded some legacy doc for FeatureContext ([297](https://github.com/cucumber/godog/pull/297) - [lonnblad](https://github.com/lonnblad))
- Fixed an issue with calculating time for junit testsuite ([308](https://github.com/cucumber/godog/pull/308) - [lonnblad](https://github.com/lonnblad))
- Fixed so that we don't execute features with zero scenarios ([315](https://github.com/cucumber/godog/pull/315) - [lonnblad](https://github.com/lonnblad))
- Fixed the broken --random flag ([317](https://github.com/cucumber/godog/pull/317) - [lonnblad](https://github.com/lonnblad))
### Removed
- Removed pre go112 build code ([293](https://github.com/cucumber/godog/pull/293) - [lonnblad](https://github.com/lonnblad))
- Removed the deprecated feature hooks ([312](https://github.com/cucumber/godog/pull/312) - [lonnblad](https://github.com/lonnblad))
## [0.9.0]
### Changed
- Run godog features in CircleCI in strict mode ([mxygem](https://github.com/mxygem))
- Removed TestMain call in `suite_test.go` for CI. ([mxygem](https://github.com/mxygem))
- Migrated to [gherkin-go - v11.0.0](https://github.com/cucumber/gherkin-go/releases/tag/v11.0.0). ([240](https://github.com/cucumber/godog/pull/240) - [lonnblad](https://github.com/lonnblad))
### Fixed
- Fixed the time attributes in the JUnit formatter. ([232](https://github.com/cucumber/godog/pull/232) - [lonnblad](https://github.com/lonnblad))
- Re enable custom formatters. ([238](https://github.com/cucumber/godog/pull/238) - [ericmcbride](https://github.com/ericmcbride))
- Added back suite_test.go ([mxygem](https://github.com/mxygem))
- Normalise module paths for use on Windows ([242](https://github.com/cucumber/godog/pull/242) - [gjtaylor](https://github.com/gjtaylor))
- Fixed panic in indenting function `s` ([247](https://github.com/cucumber/godog/pull/247) - [titouanfreville](https://github.com/titouanfreville))
- Fixed wrong version in API example ([263](https://github.com/cucumber/godog/pull/263) - [denis-trofimov](https://github.com/denis-trofimov))
## [0.8.1]
### Added
- Link in Readme to the Slack community. ([210](https://github.com/cucumber/godog/pull/210) - [smikulcik])
- Added run tests for Cucumber formatting. ([214](https://github.com/cucumber/godog/pull/214), [216](https://github.com/cucumber/godog/pull/216) - [lonnblad])
- Link in Readme to the Slack community. ([210](https://github.com/cucumber/godog/pull/210) - [smikulcik](https://github.com/smikulcik))
- Added run tests for Cucumber formatting. ([214](https://github.com/cucumber/godog/pull/214), [216](https://github.com/cucumber/godog/pull/216) - [lonnblad](https://github.com/lonnblad))
### Changed
- Renamed the `examples` directory to `_examples`, removing dependencies from the Go module ([218](https://github.com/cucumber/godog/pull/218) - [axw])
### Deprecated
### Removed
- Renamed the `examples` directory to `_examples`, removing dependencies from the Go module ([218](https://github.com/cucumber/godog/pull/218) - [axw](https://github.com/axw))
### Fixed
- Find/Replaced references to DATA-DOG/godog -> cucumber/godog for docs. ([209](https://github.com/cucumber/godog/pull/209) - [smikulcik])
- Fixed missing links in changelog to be correctly included! ([jaysonesmith])
- Find/Replaced references to DATA-DOG/godog -> cucumber/godog for docs. ([209](https://github.com/cucumber/godog/pull/209) - [smikulcik](https://github.com/smikulcik))
- Fixed missing links in changelog to be correctly included! ([mxygem](https://github.com/mxygem))
## [0.8.0]
### Added
- Added initial CircleCI config. ([jaysonesmith])
- Added concurrency support for JUnit formatting ([lonnblad])
- Added initial CircleCI config. ([mxygem](https://github.com/mxygem))
- Added concurrency support for JUnit formatting ([lonnblad](https://github.com/lonnblad))
### Changed
- Changed code references to DATA-DOG/godog to cucumber/godog to help get things building correctly. ([mxygem](https://github.com/mxygem))
- Changed code references to DATA-DOG/godog to cucumber/godog to help get things building correctly. ([jaysonesmith])
### Deprecated
### Removed
### Fixed
<!-- Releases -->
[Unreleased]: https://github.com/cucumber/cucumber/compare/godog/v0.8.1...master
[0.8.0]: https://github.com/cucumber/cucumber/compare/godog/v0.8.0...godog/v0.8.1
[0.8.0]: https://github.com/cucumber/cucumber/compare/godog/v0.7.13...godog/v0.8.0
<!-- Contributors -->
[axw]: https://github.com/axw
[jaysonesmith]: https://github.com/jaysonesmith
[lonnblad]: https://github.com/lonnblad
[smikulcik]: https://github.com/smikulcik
[ericmcbride]: https://github.com/ericmcbride
[gjtaylor]: https://github.com/gjtaylor
[v0.15.0]: https://github.com/cucumber/godog/compare/v0.14.1...v0.15.0
[v0.14.1]: https://github.com/cucumber/godog/compare/v0.14.0...v0.14.1
[v0.14.0]: https://github.com/cucumber/godog/compare/v0.13.0...v0.14.0
[v0.13.0]: https://github.com/cucumber/godog/compare/v0.12.6...v0.13.0
[v0.12.6]: https://github.com/cucumber/godog/compare/v0.12.5...v0.12.6
[v0.12.5]: https://github.com/cucumber/godog/compare/v0.12.4...v0.12.5
[v0.12.4]: https://github.com/cucumber/godog/compare/v0.12.3...v0.12.4
[v0.12.3]: https://github.com/cucumber/godog/compare/v0.12.2...v0.12.3
[v0.12.2]: https://github.com/cucumber/godog/compare/v0.12.1...v0.12.2
[v0.12.1]: https://github.com/cucumber/godog/compare/v0.12.0...v0.12.1
[v0.12.0]: https://github.com/cucumber/godog/compare/v0.11.0...v0.12.0
[v0.11.0]: https://github.com/cucumber/godog/compare/v0.10.0...v0.11.0
[v0.10.0]: https://github.com/cucumber/godog/compare/v0.9.0...v0.10.0
[0.9.0]: https://github.com/cucumber/godog/compare/v0.8.1...v0.9.0
[0.8.1]: https://github.com/cucumber/godog/compare/v0.8.0...v0.8.1
[0.8.0]: https://github.com/cucumber/godog/compare/v0.7.13...v0.8.0

28
CONTRIBUTING.md Обычный файл
Просмотреть файл

@ -0,0 +1,28 @@
# Welcome 💖
Before anything else, thank you for taking some of your precious time to help this project move forward. ❤️
If you're new to open source and feeling a bit nervous 😳, we understand! We recommend watching [this excellent guide](https://egghead.io/talks/git-how-to-make-your-first-open-source-contribution)
to give you a grounding in some of the basic concepts. You could also watch [this talk](https://www.youtube.com/watch?v=tuSk6dMoTIs) from our very own wonderful [Marit van Dijk](https://github.com/mlvandijk) on her experiences contributing to Cucumber.
We want you to feel safe to make mistakes, and ask questions. If anything in this guide or anywhere else in the codebase doesn't make sense to you, please let us know! It's through your feedback that we can make this codebase more welcoming, so we'll be glad to hear thoughts.
You can chat with us in the `#committers` channel in our [community Discord](https://cucumber.io/docs/community/get-in-touch/#discord), or feel free to [raise an issue] if you're experiencing any friction trying make your contribution.
## Setup
To get your development environment set up, you'll need to [install Go]. We're currently using version 1.17 for development.
Once that's done, try running the tests:
make test
If everything passes, you're ready to hack!
[install go]: https://golang.org/doc/install
[community Discord]: https://cucumber.io/community#discord
[raise an issue]: https://github.com/cucumber/godog/issues/new/choose
## Changing dependencies
If dependencies have changed, you will also need to update the _examples module. `go mod tidy` should be sufficient.

138
Magefile.go Обычный файл
Просмотреть файл

@ -0,0 +1,138 @@
//go:build mage
// +build mage
package main
import (
// mage:import
. "magefile/docker"
)
var (
GolangVolume = "golang.upstream"
)
func init() {
AppName = "godog"
ImageName = "my/go"
}
func Test() {
TestNative()
}
func TestNative() {
Bash(`sudo docker run -ti --rm \
-h host \
--net=bridge \
-v /etc/localtime:/etc/localtime:ro \
-v ` + GolangVolume + `:/usr/local/go:ro \
\
-v /gopath:/gopath:rw \
-v ${PWD}:/app \
\
-e GOPATH=/gopath \
-e GOCACHE=/gopath/gocache \
\
-w /app \
-u 1000 \
\
--entrypoint=/bin/bash \
\
` + ImageName + " -c '" + `\
go test -race -count=1 ./... \
'`)
}
func TestMakefile() {
Bash(`sudo docker run -ti --rm \
-h host \
--net=bridge \
-v /etc/localtime:/etc/localtime:ro \
-v ` + GolangVolume + `:/usr/local/go:ro \
\
-v /gopath:/gopath:rw \
-v ${PWD}:/app \
\
-e GOPATH=/gopath \
-e GOCACHE=/gopath/gocache \
\
-w /app \
-u 1000 \
\
--entrypoint=/bin/bash \
\
` + ImageName + " -c '" + `set -x; \
make test \
'`)
}
func TestSnippets() {
Bash(`sudo docker run -ti --rm \
-h host \
--net=bridge \
-v /etc/localtime:/etc/localtime:ro \
-v ` + GolangVolume + `:/usr/local/go:ro \
\
-v /gopath:/gopath:rw \
-v ${PWD}:/app \
\
-e GOPATH=/gopath \
-e GOCACHE=/gopath/gocache \
\
-w /app \
-u 1000 \
\
--entrypoint=/bin/bash \
\
` + ImageName + " -c '" + `set -x; \
godog run -f progress -c 4 \
features/snippets.feature \
'`)
}
func TestTags() {
Bash(`sudo docker run -ti --rm \
-h host \
--net=bridge \
-v /etc/localtime:/etc/localtime:ro \
-v ` + GolangVolume + `:/usr/local/go:ro \
\
-v /gopath:/gopath:rw \
-v ${PWD}:/app \
\
-e GOPATH=/gopath \
-e GOCACHE=/gopath/gocache \
\
-w /app \
-u 1000 \
\
--entrypoint=/bin/bash \
\
` + ImageName + " -c '" + `set -x; \
godog run -f progress -c 4 \
features/tags.feature \
'`)
}
func Install() {
Bash(`sudo docker run -ti --rm \
-h host \
--net=bridge \
-v /etc/localtime:/etc/localtime:ro \
-v ` + GolangVolume + `:/usr/local/go:ro \
\
-v /gopath:/gopath:rw \
-v ${PWD}:/app \
\
-e GOPATH=/gopath \
-e GOCACHE=/gopath/gocache \
\
-w /app \
-u 1000 \
\
--entrypoint=/bin/bash \
\
` + ImageName + " -c '" + `set -x; \
go install ./cmd/godog \
'`)
}

Просмотреть файл

@ -1,16 +1,33 @@
.PHONY: test gherkin bump cover
VERS := $(shell grep 'const Version' -m 1 godog.go | awk -F\" '{print $$2}')
VERS ?= $(shell git symbolic-ref -q --short HEAD || git describe --tags --exact-match)
test:
GO_MAJOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
GO_MINOR_VERSION = $(shell go version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
MINIMUM_SUPPORTED_GO_MINOR_VERSION = 16
GO_VERSION_VALIDATION_ERR_MSG = Go version $(GO_MAJOR_VERSION).$(GO_MINOR_VERSION) is not supported, please update to at least $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION).$(MINIMUM_SUPPORTED_GO_MINOR_VERSION)
.PHONY: check-go-version
check-go-version:
@if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
exit 0 ;\
elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
exit 1; \
elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
exit 1; \
fi
test: check-go-version
@echo "running all tests"
@go install ./...
@go fmt ./...
@golint github.com/cucumber/godog
@golint github.com/cucumber/godog/cmd/godog
@go run honnef.co/go/tools/cmd/staticcheck@v0.5.1 git.golang1.ru/softonik/godog
@go run honnef.co/go/tools/cmd/staticcheck@v0.5.1 git.golang1.ru/softonik/godog/cmd/godog
go vet ./...
go test -race
godog -f progress -c 4
go test -race ./...
go run ./cmd/godog -f progress -c 4
gherkin:
@if [ -z "$(VERS)" ]; then echo "Provide gherkin version like: 'VERS=commit-hash'"; exit 1; fi
@ -30,3 +47,31 @@ cover:
go test -race -coverprofile=coverage.txt
go tool cover -html=coverage.txt
rm coverage.txt
ARTIFACT_DIR := _artifacts
# To upload artifacts for the current version;
# execute: make upload
#
# Check https://github.com/tcnksm/ghr for usage of ghr
upload: artifacts
ghr -replace $(VERS) $(ARTIFACT_DIR)
# To build artifacts for the current version;
# execute: make artifacts
artifacts:
rm -rf $(ARTIFACT_DIR)
mkdir $(ARTIFACT_DIR)
$(call _build,darwin,amd64)
$(call _build,linux,amd64)
$(call _build,linux,arm64)
define _build
mkdir $(ARTIFACT_DIR)/godog-$(VERS)-$1-$2
env GOOS=$1 GOARCH=$2 go build -ldflags "-X git.golang1.ru/softonik/godog.Version=$(VERS)" -o $(ARTIFACT_DIR)/godog-$(VERS)-$1-$2/godog ./cmd/godog
cp README.md $(ARTIFACT_DIR)/godog-$(VERS)-$1-$2/README.md
cp LICENSE $(ARTIFACT_DIR)/godog-$(VERS)-$1-$2/LICENSE
cd $(ARTIFACT_DIR) && tar -c --use-compress-program="pigz --fast" -f godog-$(VERS)-$1-$2.tar.gz godog-$(VERS)-$1-$2 && cd ..
rm -rf $(ARTIFACT_DIR)/godog-$(VERS)-$1-$2
endef

640
README.md
Просмотреть файл

@ -1,92 +1,81 @@
[![CircleCI](https://circleci.com/gh/cucumber/godog/tree/master.svg?style=svg)](https://circleci.com/gh/cucumber/godog/tree/master)
[![GoDoc](https://godoc.org/github.com/cucumber/godog?status.svg)](https://godoc.org/github.com/cucumber/godog)
[![Build Status](https://github.com/cucumber/godog/workflows/test/badge.svg)](https://github.com/cucumber/godog/actions?query=branch%main+workflow%3Atest)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/cucumber/godog)](https://pkg.go.dev/github.com/cucumber/godog)
[![codecov](https://codecov.io/gh/cucumber/godog/branch/master/graph/badge.svg)](https://codecov.io/gh/cucumber/godog)
[![pull requests](https://oselvar.com/api/badge?label=pull%20requests&csvUrl=https%3A%2F%2Fraw.githubusercontent.com%2Fcucumber%2Foselvar-github-metrics%2Fmain%2Fdata%2Fcucumber%2Fgodog%2FpullRequests.csv)](https://oselvar.com/github/cucumber/oselvar-github-metrics/main/cucumber/godog)
[![issues](https://oselvar.com/api/badge?label=issues&csvUrl=https%3A%2F%2Fraw.githubusercontent.com%2Fcucumber%2Foselvar-github-metrics%2Fmain%2Fdata%2Fcucumber%2Fgodog%2Fissues.csv)](https://oselvar.com/github/cucumber/oselvar-github-metrics/main/cucumber/godog)
# Godog
<p align="center"><img src="/logo.png" alt="Godog logo" style="width:250px;" /></p>
<p align="center"><img src="logo.png" alt="Godog logo" style="width:250px;" /></p>
**The API is likely to change a few times before we reach 1.0.0**
Please read all the README, you may find it very useful. And do not forget
to peek into the
[CHANGELOG](https://github.com/cucumber/godog/blob/master/CHANGELOG.md)
from time to time.
Please read the full README, you may find it very useful. And do not forget to peek into the [Release Notes](https://github.com/cucumber/godog/blob/master/release-notes) and the [CHANGELOG](https://github.com/cucumber/godog/blob/master/CHANGELOG.md) from time to time.
Package godog is the official Cucumber BDD framework for Golang, it merges
specification and test documentation into one cohesive whole. The author
is a member of [cucumber team](https://github.com/cucumber).
Package godog is the official Cucumber BDD framework for Golang, it merges specification and test documentation into one cohesive whole, using Gherkin formatted scenarios in the format of Given, When, Then.
The project is inspired by [behat][behat] and [cucumber][cucumber] and is
based on cucumber [gherkin3 parser][gherkin].
The project was inspired by [behat][behat] and [cucumber][cucumber].
**Godog** does not intervene with the standard **go test** command
behavior. You can leverage both frameworks to functionally test your
application while maintaining all test related source code in **_test.go**
files.
## Why Godog/Cucumber
**Godog** acts similar compared to **go test** command, by using go
compiler and linker tool in order to produce test executable. Godog
contexts need to be exported the same way as **Test** functions for go
tests. Note, that if you use **godog** command tool, it will use `go`
executable to determine compiler and linker.
### A single source of truth
**Godog** ships gherkin parser dependency as a subpackage. This will
ensure that it is always compatible with the installed version of godog.
So in general there are no vendor dependencies needed for installation.
Godog merges specification and test documentation into one cohesive whole.
The following about section was taken from
[cucumber](https://cucumber.io/) homepage.
### Living documentation
## About
#### A single source of truth
Cucumber merges specification and test documentation into one cohesive whole.
#### Living documentation
Because they're automatically tested by Cucumber, your specifications are
Because they're automatically tested by Godog, your specifications are
always bang up-to-date.
#### Focus on the customer
### Focus on the customer
Business and IT don't always understand each other. Cucumber's executable
specifications encourage closer collaboration, helping teams keep the
business goal in mind at all times.
Business and IT don't always understand each other. Godog's executable specifications encourage closer collaboration, helping teams keep the business goal in mind at all times.
#### Less rework
### Less rework
When automated testing is this much fun, teams can easily protect
themselves from costly regressions.
When automated testing is this much fun, teams can easily protect themselves from costly regressions.
## Install
```
go get github.com/cucumber/godog/cmd/godog@v0.9.0-rc1
```
Adding `@v0.9.0-rc1` will install v0.9.0-rc1 specifically instead of master.
### Read more
- [Behaviour-Driven Development](https://cucumber.io/docs/bdd/)
- [Gherkin Reference](https://cucumber.io/docs/gherkin/reference/)
Running `within the $GOPATH`, you would also need to set `GO111MODULE=on`, like this:
```
GO111MODULE=on go get github.com/cucumber/godog/cmd/godog@v0.9.0-rc1
```
## Contributions
## Example
Godog is a community driven Open Source Project within the Cucumber organization. We [welcome contributions from everyone](https://cucumber.io/blog/open-source/tackling-structural-racism-(and-sexism)-in-open-so/), and we're ready to support you if you have the enthusiasm to contribute.
The following example can be [found
here](/_examples/godogs).
See the [contributing guide] for more detail on how to get started.
### Step 1
See the [releasing guide] for release flow details.
Given we create a new go package **$GOPATH/src/godogs**. From now on, this
is our work directory `cd $GOPATH/src/godogs`.
## Getting help
Imagine we have a **godog cart** to serve godogs for lunch. First of all,
we describe our feature in plain text - `vim
$GOPATH/src/godogs/features/godogs.feature`:
We have a [community Discord](https://cucumber.io/docs/community/get-in-touch/#discord) where you can chat with other users, developers, and BDD practitioners.
## Examples
You can find a few examples [here](/_examples).
**Note** that if you want to execute any of the examples and have the Git repository checked out in the `$GOPATH`, you need to use: `GO111MODULE=off`. [Issue](https://github.com/cucumber/godog/issues/344) for reference.
### Godogs
The following example can be [found here](/_examples/godogs).
#### Step 1 - Setup a go module
Create a new go module named **godogs** in your go workspace by running `mkdir godogs`
From now on, use **godogs** as your working directory by running `cd godogs`
Initiate the go module inside the **godogs** directory by running `go mod init godogs`
#### Step 2 - Create gherkin feature
Imagine we have a **godog cart** to serve godogs for lunch.
First of all, we describe our feature in plain text:
``` gherkin
# file: $GOPATH/src/godogs/features/godogs.feature
Feature: eat godogs
In order to be happy
As a hungry gopher
@ -98,46 +87,72 @@ Feature: eat godogs
Then there should be 7 remaining
```
**NOTE:** same as **go test** godog respects package level isolation. All
your step definitions should be in your tested package root directory. In
this case - `$GOPATH/src/godogs`
Run `vim features/godogs.feature` and add the text above into the vim editor and save the file.
### Step 2
#### Step 3 - Create godog step definitions
If godog is installed in your GOPATH. We can run `godog` inside the
**$GOPATH/src/godogs** directory. You should see that the steps are
undefined:
![Undefined step snippets](/screenshots/undefined.png?raw=true)
If we wish to vendor godog dependency, we can do it as usual, using tools
you prefer:
git clone https://github.com/cucumber/godog.git $GOPATH/src/godogs/vendor/github.com/cucumber/godog
It gives you undefined step snippets to implement in your test context.
You may copy these snippets into your `godogs_test.go` file.
Our directory structure should now look like:
![Directory layout](/screenshots/dir-tree.png?raw=true)
If you copy the snippets into our test file and run godog again. We should
see the step definition is now pending:
![Pending step definition](/screenshots/pending.png?raw=true)
You may change **ErrPending** to **nil** and the scenario will
pass successfully.
Since we need a working implementation, we may start by implementing only what is necessary.
### Step 3
We only need a number of **godogs** for now. Lets keep it simple.
**NOTE:** Same as **go test**, godog respects package level isolation. All your step definitions should be in your tested package root directory. In this case: **godogs**.
Create and copy the step definitions below into a new file by running `vim godogs_test.go`:
``` go
/* file: $GOPATH/src/godogs/godogs.go */
package main
import "github.com/cucumber/godog"
func iEat(arg1 int) error {
return godog.ErrPending
}
func thereAreGodogs(arg1 int) error {
return godog.ErrPending
}
func thereShouldBeRemaining(arg1 int) error {
return godog.ErrPending
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Step(`^I eat (\d+)$`, iEat)
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
}
```
Alternatively, you can also specify the keyword (Given, When, Then...) when creating the step definitions:
``` go
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Given(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.When(`^I eat (\d+)$`, iEat)
ctx.Then(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
}
```
Our module should now look like this:
```
godogs
- features
- godogs.feature
- go.mod
- go.sum
- godogs_test.go
```
Run `go test` in the **godogs** directory to run the steps you have defined. You should now see that the scenario runs
with a warning stating there are no tests to run.
```
testing: warning: no tests to run
PASS
ok godogs 0.225s
```
By adding some logic to these steps, you will be able to thoroughly test the feature you just defined.
#### Step 4 - Create the main program to test
Let's keep it simple by only requiring an amount of **godogs** for now.
Create and copy the code below into a new file by running `vim godogs.go`
```go
package main
// Godogs available to eat
@ -146,87 +161,150 @@ var Godogs int
func main() { /* usual main func */ }
```
### Step 4
Our module should now look like this:
```
godogs
- features
- godogs.feature
- go.mod
- go.sum
- godogs.go
- godogs_test.go
```
Now lets implement our step definitions, which we can copy from generated
console output snippets in order to test our feature requirements:
#### Step 5 - Add some logic to the step definitions
``` go
/* file: $GOPATH/src/godogs/godogs_test.go */
Now lets implement our step definitions to test our feature requirements.
Replace the contents of `godogs_test.go` with the code below by running `vim godogs_test.go`.
```go
package main
import (
"fmt"
"context"
"errors"
"fmt"
"testing"
"github.com/cucumber/godog"
messages "github.com/cucumber/messages-go/v9"
"github.com/cucumber/godog"
)
func thereAreGodogs(available int) error {
Godogs = available
return nil
// godogsCtxKey is the key used to store the available godogs in the context.Context.
type godogsCtxKey struct{}
func thereAreGodogs(ctx context.Context, available int) (context.Context, error) {
return context.WithValue(ctx, godogsCtxKey{}, available), nil
}
func iEat(num int) error {
if Godogs < num {
return fmt.Errorf("you cannot eat %d godogs, there are %d available", num, Godogs)
}
Godogs -= num
return nil
func iEat(ctx context.Context, num int) (context.Context, error) {
available, ok := ctx.Value(godogsCtxKey{}).(int)
if !ok {
return ctx, errors.New("there are no godogs available")
}
if available < num {
return ctx, fmt.Errorf("you cannot eat %d godogs, there are %d available", num, available)
}
available -= num
return context.WithValue(ctx, godogsCtxKey{}, available), nil
}
func thereShouldBeRemaining(remaining int) error {
if Godogs != remaining {
return fmt.Errorf("expected %d godogs to be remaining, but there is %d", remaining, Godogs)
}
return nil
func thereShouldBeRemaining(ctx context.Context, remaining int) error {
available, ok := ctx.Value(godogsCtxKey{}).(int)
if !ok {
return errors.New("there are no godogs available")
}
if available != remaining {
return fmt.Errorf("expected %d godogs to be remaining, but there is %d", remaining, available)
}
return nil
}
func FeatureContext(s *godog.Suite) {
s.Step(`^there are (\d+) godogs$`, thereAreGodogs)
s.Step(`^I eat (\d+)$`, iEat)
s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
func TestFeatures(t *testing.T) {
suite := godog.TestSuite{
ScenarioInitializer: InitializeScenario,
Options: &godog.Options{
Format: "pretty",
Paths: []string{"features"},
TestingT: t, // Testing instance that will run subtests.
},
}
s.BeforeScenario(func(*messages.Pickle) {
Godogs = 0 // clean the state before every scenario
})
if suite.Run() != 0 {
t.Fatal("non-zero status returned, failed to run feature tests")
}
}
func InitializeScenario(sc *godog.ScenarioContext) {
sc.Step(`^there are (\d+) godogs$`, thereAreGodogs)
sc.Step(`^I eat (\d+)$`, iEat)
sc.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
}
```
Now when you run the `godog` again, you should see:
In this example, we are using `context.Context` to pass the state between the steps.
Every scenario starts with an empty context and then steps and hooks can add relevant information to it.
Instrumented context is chained through the steps and hooks and is safe to use when multiple scenarios are running concurrently.
![Passed suite](/screenshots/passed.png?raw=true)
When you run godog again with `go test -v godogs_test.go`, you should see a passing run:
```
=== RUN TestFeatures
Feature: eat godogs
In order to be happy
As a hungry gopher
I need to be able to eat godogs
=== RUN TestFeatures/Eat_5_out_of_12
We have hooked to **BeforeScenario** event in order to reset application
state before each scenario. You may hook into more events, like
**AfterStep** to print all state in case of an error. Or
**BeforeSuite** to prepare a database.
Scenario: Eat 5 out of 12 # features/godogs.feature:6
Given there are 12 godogs # godog_test.go:15 -> command-line-arguments.thereAreGodogs
When I eat 5 # godog_test.go:19 -> command-line-arguments.iEat
Then there should be 7 remaining # godog_test.go:34 -> command-line-arguments.thereShouldBeRemaining
By now, you should have figured out, how to use **godog**. Another advice
is to make steps orthogonal, small and simple to read for a user. Whether
the user is a dumb website user or an API developer, who may understand
a little more technical context - it should target that user.
1 scenarios (1 passed)
3 steps (3 passed)
279.917µs
--- PASS: TestFeatures (0.00s)
--- PASS: TestFeatures/Eat_5_out_of_12 (0.00s)
PASS
ok command-line-arguments 0.164s
```
When steps are orthogonal and small, you can combine them just like you do
with Unix tools. Look how to simplify or remove ones, which can be
composed.
You may hook to `ScenarioContext` **Before** event in order to reset or pre-seed the application state before each scenario.
You may hook into more events, like `sc.StepContext()` **After** to print all state in case of an error.
Or **BeforeSuite** to prepare a database.
### References and Tutorials
By now, you should have figured out, how to use **godog**. Another piece of advice is to make steps orthogonal, small and simple to read for a user.
Whether the user is a dumb website user or an API developer, who may understand a little more technical context - it should target that user.
- [cucumber-html-reporter](https://github.com/gkushang/cucumber-html-reporter)
may be used in order to generate **html** reports together with
**cucumber** output formatter. See the [following docker
image](https://github.com/myie/cucumber-html-reporter) for usage
details.
When steps are orthogonal and small, you can combine them just like you do with Unix tools. Look how to simplify or remove ones, which can be composed.
`TestFeatures` acts as a regular Go test, so you can leverage your IDE facilities to run and debug it.
### Attachments
An example showing how to make attachments (aka embeddings) to the results is shown in [_examples/attachments](/_examples/attachments/)
## Code of Conduct
Everyone interacting in this codebase and issue tracker is expected to follow the Cucumber [code of conduct](https://github.com/cucumber/cucumber/blob/master/CODE_OF_CONDUCT.md).
## References and Tutorials
- [cucumber-html-reporter](https://github.com/gkushang/cucumber-html-reporter),
may be used in order to generate **html** reports together with **cucumber** output formatter. See the [following docker image](https://github.com/myie/cucumber-html-reporter) for usage details.
- [how to use godog by semaphoreci](https://semaphoreci.com/community/tutorials/how-to-use-godog-for-behavior-driven-development-in-go)
- see [examples](https://github.com/cucumber/godog/tree/master/_examples)
- see extension [AssistDog](https://github.com/hellomd/assistdog), which
may have useful **gherkin.DataTable** transformations or comparison
methods for assertions.
- see extension [AssistDog](https://github.com/hellomd/assistdog),
which may have useful **gherkin.DataTable** transformations or comparison methods for assertions.
### Documentation
## Documentation
See [godoc][godoc] for general API details.
See [pkg documentation][godoc] for general API details.
See **[Circle Config](/.circleci/config.yml)** for supported **go** versions.
See `godog -h` for general command options.
@ -240,72 +318,135 @@ See implementation examples:
### Running Godog with go test
You may integrate running **godog** in your **go test** command. You can
run it using go [TestMain](https://golang.org/pkg/testing/#hdr-Main) func
available since **go 1.4**. In this case it is not necessary to have
**godog** command installed. See the following examples.
You may integrate running **godog** in your **go test** command.
The following example binds **godog** flags with specified prefix `godog`
in order to prevent flag collisions.
#### Subtests of *testing.T
``` go
var opt = godog.Options{
You can run test suite using go [Subtests](https://pkg.go.dev/testing#hdr-Subtests_and_Sub_benchmarks).
In this case it is not necessary to have **godog** command installed. See the following example.
```go
package main_test
import (
"testing"
"github.com/cucumber/godog"
)
func TestFeatures(t *testing.T) {
suite := godog.TestSuite{
ScenarioInitializer: func(s *godog.ScenarioContext) {
// Add step definitions here.
},
Options: &godog.Options{
Format: "pretty",
Paths: []string{"features"},
TestingT: t, // Testing instance that will run subtests.
},
}
if suite.Run() != 0 {
t.Fatal("non-zero status returned, failed to run feature tests")
}
}
```
Then you can run suite.
```
go test -test.v -test.run ^TestFeatures$
```
Or a particular scenario.
```
go test -test.v -test.run ^TestFeatures$/^my_scenario$
```
#### TestMain
You can run test suite using go [TestMain](https://golang.org/pkg/testing/#hdr-Main) func available since **go 1.4**.
In this case it is not necessary to have **godog** command installed. See the following examples.
The following example binds **godog** flags with specified prefix `godog` in order to prevent flag collisions.
```go
package main
import (
"os"
"testing"
"github.com/cucumber/godog"
"github.com/cucumber/godog/colors"
"github.com/spf13/pflag" // godog v0.11.0 and later
)
var opts = godog.Options{
Output: colors.Colored(os.Stdout),
Format: "progress", // can define default values
}
func init() {
godog.BindFlags("godog.", flag.CommandLine, &opt)
godog.BindFlags("godog.", pflag.CommandLine, &opts) // godog v0.10.0 and earlier
godog.BindCommandLineFlags("godog.", &opts) // godog v0.11.0 and later
}
func TestMain(m *testing.M) {
flag.Parse()
opt.Paths = flag.Args()
pflag.Parse()
opts.Paths = pflag.Args()
status := godog.RunWithOptions("godogs", func(s *godog.Suite) {
FeatureContext(s)
}, opt)
status := godog.TestSuite{
Name: "godogs",
TestSuiteInitializer: InitializeTestSuite,
ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run()
// Optional: Run `testing` package's logic besides godog.
if st := m.Run(); st > status {
status = st
}
os.Exit(status)
}
```
Then you may run tests with by specifying flags in order to filter
features.
Then you may run tests with by specifying flags in order to filter features.
```
go test -v --godog.random --godog.tags=wip
go test -v --godog.format=pretty --godog.random -race -coverprofile=coverage.txt -covermode=atomic
```
The following example does not bind godog flags, instead manually
configuring needed options.
The following example does not bind godog flags, instead manually configuring needed options.
``` go
```go
func TestMain(m *testing.M) {
status := godog.RunWithOptions("godog", func(s *godog.Suite) {
FeatureContext(s)
}, godog.Options{
opts := godog.Options{
Format: "progress",
Paths: []string{"features"},
Randomize: time.Now().UTC().UnixNano(), // randomize scenario execution order
})
}
status := godog.TestSuite{
Name: "godogs",
TestSuiteInitializer: InitializeTestSuite,
ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run()
// Optional: Run `testing` package's logic besides godog.
if st := m.Run(); st > status {
status = st
}
os.Exit(status)
}
```
You can even go one step further and reuse **go test** flags, like
**verbose** mode in order to switch godog **format**. See the following
example:
You can even go one step further and reuse **go test** flags, like **verbose** mode in order to switch godog **format**. See the following example:
``` go
```go
func TestMain(m *testing.M) {
format := "progress"
for _, arg := range os.Args[1:] {
@ -314,16 +455,24 @@ func TestMain(m *testing.M) {
break
}
}
status := godog.RunWithOptions("godog", func(s *godog.Suite) {
godog.SuiteContext(s)
}, godog.Options{
opts := godog.Options{
Format: format,
Paths: []string{"features"},
})
}
status := godog.TestSuite{
Name: "godogs",
TestSuiteInitializer: InitializeTestSuite,
ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run()
// Optional: Run `testing` package's logic besides godog.
if st := m.Run(); st > status {
status = st
}
os.Exit(status)
}
```
@ -332,73 +481,102 @@ Now when running `go test -v` it will use **pretty** format.
### Tags
If you want to filter scenarios by tags, you can use the
`-t=<expression>` or `--tags=<expression>` where `<expression>`
is one of the following:
If you want to filter scenarios by tags, you can use the `-t=<expression>` or `--tags=<expression>` where `<expression>` is one of the following:
- `@wip` - run all scenarios with wip tag
- `~@wip` - exclude all scenarios with wip tag
- `@wip && ~@new` - run wip scenarios, but exclude new
- `@wip,@undone` - run wip or undone scenarios
### Using assertion packages like testify with Godog
A more extensive example can be [found here](/_examples/assert-godogs).
```go
func thereShouldBeRemaining(ctx context.Context, remaining int) error {
assert.Equal(
godog.T(ctx), Godogs, remaining,
"Expected %d godogs to be remaining, but there is %d", remaining, Godogs,
)
return nil
}
```
### Embeds
If you're looking to compile your test binary in advance of running, you can compile the feature files into the binary via `go:embed`:
```go
//go:embed features/*
var features embed.FS
var opts = godog.Options{
Paths: []string{"features"},
FS: features,
}
```
Now, the test binary can be compiled with all feature files embedded, and can be ran independently from the feature files:
```sh
> go test -c ./test/integration/integration_test.go
> mv integration.test /some/random/dir
> cd /some/random/dir
> ./integration.test
```
**NOTE:** `godog.Options.FS` is as `fs.FS`, so custom filesystem loaders can be used.
## CLI Mode
**NOTE:** The [`godog` CLI has been deprecated](https://github.com/cucumber/godog/discussions/478). It is recommended to use `go test` instead.
Another way to use `godog` is to run it in CLI mode.
In this mode `godog` CLI will use `go` under the hood to compile and run your test suite.
**Godog** does not intervene with the standard **go test** command behavior. You can leverage both frameworks to functionally test your application while maintaining all test related source code in **_test.go** files.
**Godog** acts similar compared to **go test** command, by using go compiler and linker tool in order to produce test executable. Godog contexts need to be exported the same way as **Test** functions for go tests. Note, that if you use **godog** command tool, it will use `go` executable to determine compiler and linker.
### Install
```
go install github.com/cucumber/godog/cmd/godog@latest
```
Adding `@v0.12.0` will install v0.12.0 specifically instead of master.
With `go` version prior to 1.17, use `go get github.com/cucumber/godog/cmd/godog@v0.12.0`.
Running `within the $GOPATH`, you would also need to set `GO111MODULE=on`, like this:
```
GO111MODULE=on go get github.com/cucumber/godog/cmd/godog@v0.12.0
```
### Configure common options for godog CLI
There are no global options or configuration files. Alias your common or
project based commands: `alias godog-wip="godog --format=progress
--tags=@wip"`
There are no global options or configuration files. Alias your common or project based commands: `alias godog-wip="godog --format=progress --tags=@wip"`
### Testing browser interactions
## Concurrency
**godog** does not come with builtin packages to connect to the browser.
You may want to look at [selenium](http://www.seleniumhq.org/) and
probably [phantomjs](http://phantomjs.org/). See also the following
components:
When concurrency is configured in options, godog will execute the scenarios concurrently, which is supported by all supplied formatters.
1. [browsersteps](https://github.com/llonchj/browsersteps) - provides
basic context steps to start selenium and navigate browser content.
2. You may wish to have [goquery](https://github.com/PuerkitoBio/goquery)
in order to work with HTML responses like with JQuery.
In order to support concurrency well, you should reset the state and isolate each scenario. They should not share any state. It is suggested to run the suite concurrently in order to make sure there is no state corruption or race conditions in the application.
### Concurrency
It is also useful to randomize the order of scenario execution, which you can now do with `--random` command option or `godog.Options.Randomize` setting.
In order to support concurrency well, you should reset the state and
isolate each scenario. They should not share any state. It is suggested to
run the suite concurrently in order to make sure there is no state
corruption or race conditions in the application.
It is also useful to randomize the order of scenario execution, which you
can now do with **--random** command option.
**NOTE:** if suite runs with concurrency option, it concurrently runs
every feature, not scenario per different features. This gives
a flexibility to isolate state per feature. For example using
**BeforeFeature** hook, it is possible to spin up costly service and shut
it down only in **AfterFeature** hook and share the service between all
scenarios in that feature. It is not advisable though, because you are
risking having a state dependency.
## Contributions
Feel free to open a pull request. Note, if you wish to contribute an extension to public (exported methods or types) -
please open an issue before to discuss whether these changes can be accepted. All backward incompatible changes are
and will be treated cautiously.
Reach out to the community on our [Cucumber Slack Community](https://cucumberbdd.slack.com/).
Join [here](https://cucumberbdd-slack-invite.herokuapp.com/).
### Popular Cucumber Slack channels for Godog:
- [#help-godog](https://cucumberbdd.slack.com/archives/CTNL1JCVA) - General Godog Adoption Help
- [#committers-go](https://cucumberbdd.slack.com/archives/CA5NJPDJ4) - Golang focused Cucumber Contributors
- [#committers](https://cucumberbdd.slack.com/archives/C62D0FK0E) - General Cucumber Contributors
### Building your own custom formatter
A simple example can be [found here](/_examples/custom-formatter).
## License
- **Godog** is licensed under the [MIT][license]
- **Gherkin** is licensed under the [MIT][license] and developed as
a part of the [cucumber project][cucumber]
**Godog** and **Gherkin** are licensed under the [MIT][license] and developed as a part of the [cucumber project][cucumber]
[godoc]: http://godoc.org/github.com/cucumber/godog "Documentation on godoc"
[godoc]: https://pkg.go.dev/github.com/cucumber/godog "Documentation on godog"
[golang]: https://golang.org/ "GO programming language"
[behat]: http://docs.behat.org/ "Behavior driven development framework for PHP"
[cucumber]: https://cucumber.io/ "Behavior driven development framework"
[gherkin]: https://github.com/cucumber/gherkin-go "Gherkin3 parser for GO"
[license]: https://en.wikipedia.org/wiki/MIT_License "The MIT license"
[contributing guide]: https://github.com/cucumber/godog/blob/main/CONTRIBUTING.md
[releasing guide]: https://github.com/cucumber/godog/blob/main/RELEASING.md
[community Discord]: https://cucumber.io/community#discord

67
RELEASING.md Обычный файл
Просмотреть файл

@ -0,0 +1,67 @@
# Releasing Guidelines for Cucumber Godog
This document provides guidelines for releasing new versions of Cucumber Godog. Follow these steps to ensure a smooth and consistent release process.
## Versioning
Cucumber Godog follows [Semantic Versioning]. Version numbers are in the format `MAJOR.MINOR.PATCH`.
### Current (for v0.MINOR.PATCH)
- **MINOR**: Incompatible API changes.
- **PATCH**: Backward-compatible new features and bug fixes.
### After v1.X.X release
- **MAJOR**: Incompatible API changes.
- **MINOR**: Backward-compatible new features.
- **PATCH**: Backward-compatible bug fixes.
## Release Process
1. **Update Changelog:**
- Open `CHANGELOG.md` and add an entry for the upcoming release formatting according to the principles of [Keep A CHANGELOG].
- Include details about new features, enhancements, and bug fixes.
2. **Run Tests:**
- Run the test suite to ensure all existing features are working as expected.
3. **Manual Testing for Backwards Compatibility:**
- Manually test the new release with external libraries that depend on Cucumber Godog.
- Look for any potential backwards compatibility issues, especially with widely-used libraries.
- Address any identified issues before proceeding.
4. **Create Release on GitHub:**
- Go to the [Releases] page on GitHub.
- Click on "Draft a new release."
- Tag version should be set to the new tag vMAJOR.MINOR.PATCH
- Title the release using the version number (e.g., "vMAJOR.MINOR.PATCH").
- Click 'Generate release notes'
5. **Publish Release:**
- Click "Publish release" to make the release public.
6. **Announce the Release:**
- Make an announcement on relevant communication channels (e.g., [community Discord]) about the new release.
## Additional Considerations
- **Documentation:**
- Update the project documentation on the [website], if applicable.
- **Deprecation Notices:**
- If any features are deprecated, clearly document them in the release notes and provide guidance on migration.
- **Compatibility:**
- Clearly state any compatibility requirements or changes in the release notes.
- **Feedback:**
- Encourage users to provide feedback and report any issues with the new release.
Following these guidelines, including manual testing with external libraries, will help ensure a thorough release process for Cucumber Godog, allowing detection and resolution of potential backwards compatibility issues before tagging the release.
[community Discord]: https://cucumber.io/community#discord
[website]: https://cucumber.github.io/godog/
[Releases]: https://github.com/cucumber/godog/releases
[Semantic Versioning]: http://semver.org
[Keep A CHANGELOG]: http://keepachangelog.com

Просмотреть файл

@ -4,8 +4,8 @@ The following example demonstrates steps how we describe and test our API using
### Step 1
Describe our feature. Imagine we need a REST API with **json** format. Lets from the point, that
we need to have a **/version** endpoint, which responds with a version number. We also need to manage
Describe our feature. Imagine we need a REST API with `json` format. Lets from the point, that
we need to have a `/version` endpoint, which responds with a version number. We also need to manage
error responses.
``` gherkin
@ -31,24 +31,24 @@ Feature: get version
And the response should match json:
"""
{
"version": "v0.5.3"
"version": "v0.0.0-dev"
}
"""
```
Save it as **version.feature**.
Save it as `features/version.feature`.
Now we have described a success case and an error when the request method is not allowed.
### Step 2
Run **godog version.feature**. You should see the following result, which says that all of our
Execute `godog run`. You should see the following result, which says that all of our
steps are yet undefined and provide us with the snippets to implement them.
![Screenshot](https://raw.github.com/cucumber/godog/master/examples/api/screenshots/undefined.png)
![Screenshot](https://raw.git.golang1.ru/softonik/godog/master/_examples/api/screenshots/undefined.png)
### Step 3
Lets copy the snippets to **api_test.go** and modify it for our use case. Since we know that we will
Lets copy the snippets to `api_test.go` and modify it for our use case. Since we know that we will
need to store state within steps (a response), we should introduce a structure with some variables.
``` go
@ -56,8 +56,7 @@ need to store state within steps (a response), we should introduce a structure w
package main
import (
"github.com/cucumber/gherkin-go/v9"
"github.com/cucumber/godog"
"git.golang1.ru/softonik/godog"
)
type apiFeature struct {
@ -71,11 +70,26 @@ func (a *apiFeature) theResponseCodeShouldBe(code int) error {
return godog.ErrPending
}
func (a *apiFeature) theResponseShouldMatchJSON(body *messages.PickleStepArgument_PickleDocString) error {
func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) error {
return godog.ErrPending
}
func FeatureContext(s *godog.Suite) {
func TestFeatures(t *testing.T) {
suite := godog.TestSuite{
ScenarioInitializer: InitializeScenario,
Options: &godog.Options{
Format: "pretty",
Paths: []string{"features"},
TestingT: t, // Testing instance that will run subtests.
},
}
if suite.Run() != 0 {
t.Fatal("non-zero status returned, failed to run feature tests")
}
}
func InitializeScenario(s *godog.ScenarioContext) {
api := &apiFeature{}
s.Step(`^I send "([^"]*)" request to "([^"]*)"$`, api.iSendrequestTo)
s.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
@ -85,28 +99,29 @@ func FeatureContext(s *godog.Suite) {
### Step 4
Now we can implemented steps, since we know what behavior we expect:
Now we can implement steps, since we know what behavior we expect:
``` go
// file: api_test.go
package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"reflect"
"testing"
"github.com/cucumber/gherkin-go/v9"
"github.com/cucumber/godog"
"git.golang1.ru/softonik/godog"
)
type apiFeature struct {
resp *httptest.ResponseRecorder
}
func (a *apiFeature) resetResponse(interface{}) {
func (a *apiFeature) resetResponse(*godog.Scenario) {
a.resp = httptest.NewRecorder()
}
@ -142,37 +157,59 @@ func (a *apiFeature) theResponseCodeShouldBe(code int) error {
return nil
}
func (a *apiFeature) theResponseShouldMatchJSON(body *messages.PickleStepArgument_PickleDocString) error {
var expected, actual []byte
var data interface{}
if err = json.Unmarshal([]byte(body.Content), &data); err != nil {
func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) (err error) {
var expected, actual interface{}
// re-encode expected response
if err = json.Unmarshal([]byte(body.Content), &expected); err != nil {
return
}
if expected, err = json.Marshal(data); err != nil {
// re-encode actual response too
if err = json.Unmarshal(a.resp.Body.Bytes(), &actual); err != nil {
return
}
actual = a.resp.Body.Bytes()
if !bytes.Equal(actual, expected) {
err = fmt.Errorf("expected json, does not match actual: %s", string(actual))
// the matching may be adapted per different requirements.
if !reflect.DeepEqual(expected, actual) {
return fmt.Errorf("expected JSON does not match actual, %v vs. %v", expected, actual)
}
return
return nil
}
func FeatureContext(s *godog.Suite) {
func TestFeatures(t *testing.T) {
suite := godog.TestSuite{
ScenarioInitializer: InitializeScenario,
Options: &godog.Options{
Format: "pretty",
Paths: []string{"features"},
TestingT: t, // Testing instance that will run subtests.
},
}
if suite.Run() != 0 {
t.Fatal("non-zero status returned, failed to run feature tests")
}
}
func InitializeScenario(ctx *godog.ScenarioContext) {
api := &apiFeature{}
s.BeforeScenario(api.resetResponse)
s.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
s.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
s.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON)
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
api.resetResponse(sc)
return ctx, nil
})
ctx.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
ctx.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
ctx.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON)
}
```
**NOTE:** the `getVersion` handler call on **/version** endpoint. We actually need to implement it now.
**NOTE:** the `getVersion` handler is called on `/version` endpoint.
Executing `godog run` or `go test -v` will provide `undefined: getVersion` error, so we actually need to implement it now.
If we made some mistakes in step implementations, we will know about it when we run the tests.
Though, we could also improve our **JSON** comparison function to range through the interfaces and
Though, we could also improve our `JSON` comparison function to range through the interfaces and
match their types and values.
In case if some router is used, you may search the handler based on the endpoint. Current example
@ -180,7 +217,7 @@ uses a standard http package.
### Step 5
Finally, lets implement the **api** server:
Finally, lets implement the `API` server:
``` go
// file: api.go
@ -189,17 +226,17 @@ package main
import (
"encoding/json"
"fmt"
"net/http"
"github.com/cucumber/godog"
"git.golang1.ru/softonik/godog"
)
func getVersion(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
if r.Method != http.MethodGet {
fail(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
data := struct {
Version string `json:"version"`
}{Version: godog.Version}
@ -207,42 +244,34 @@ func getVersion(w http.ResponseWriter, r *http.Request) {
ok(w, data)
}
func main() {
http.HandleFunc("/version", getVersion)
http.ListenAndServe(":8080", nil)
}
// fail writes a json response with error msg and status header
func fail(w http.ResponseWriter, msg string, status int) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
data := struct {
Error string `json:"error"`
}{Error: msg}
resp, _ := json.Marshal(data)
w.WriteHeader(status)
fmt.Fprintf(w, string(resp))
w.Header().Set("Content-Type", "application/json")
w.Write(resp)
}
// ok writes data to response with 200 status
func ok(w http.ResponseWriter, data interface{}) {
w.Header().Set("Content-Type", "application/json")
if s, ok := data.(string); ok {
fmt.Fprintf(w, s)
return
}
resp, err := json.Marshal(data)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fail(w, "oops something evil has happened", 500)
fail(w, "Oops something evil has happened", http.StatusInternalServerError)
return
}
fmt.Fprintf(w, string(resp))
w.Header().Set("Content-Type", "application/json")
w.Write(resp)
}
func main() {
http.HandleFunc("/version", getVersion)
http.ListenAndServe(":8080", nil)
}
```
@ -251,9 +280,9 @@ used to respond with the correct constant version number.
### Step 6
Run our tests to see whether everything is happening as we have expected: `godog version.feature`
Run our tests to see whether everything is happening as we have expected: `go test -v`
![Screenshot](https://raw.github.com/cucumber/godog/master/examples/api/screenshots/passed.png)
![Screenshot](https://raw.git.golang1.ru/softonik/godog/master/_examples/api/screenshots/passed.png)
### Conclusions

Просмотреть файл

@ -3,17 +3,17 @@ package main
import (
"encoding/json"
"fmt"
"net/http"
"github.com/cucumber/godog"
"git.golang1.ru/softonik/godog"
)
func getVersion(w http.ResponseWriter, r *http.Request) {
if r.Method != "GET" {
if r.Method != http.MethodGet {
fail(w, "Method not allowed", http.StatusMethodNotAllowed)
return
}
data := struct {
Version string `json:"version"`
}{Version: godog.Version}
@ -21,40 +21,32 @@ func getVersion(w http.ResponseWriter, r *http.Request) {
ok(w, data)
}
func main() {
http.HandleFunc("/version", getVersion)
http.ListenAndServe(":8080", nil)
}
// fail writes a json response with error msg and status header
func fail(w http.ResponseWriter, msg string, status int) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
data := struct {
Error string `json:"error"`
}{Error: msg}
resp, _ := json.Marshal(data)
w.WriteHeader(status)
fmt.Fprintf(w, string(resp))
w.Header().Set("Content-Type", "application/json")
w.Write(resp)
}
// ok writes data to response with 200 status
func ok(w http.ResponseWriter, data interface{}) {
w.Header().Set("Content-Type", "application/json")
if s, ok := data.(string); ok {
fmt.Fprintf(w, s)
return
}
resp, err := json.Marshal(data)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
fail(w, "oops something evil has happened", 500)
fail(w, "Oops something evil has happened", http.StatusInternalServerError)
return
}
fmt.Fprintf(w, string(resp))
w.Header().Set("Content-Type", "application/json")
w.Write(resp)
}
func main() {
http.HandleFunc("/version", getVersion)
http.ListenAndServe(":8080", nil)
}

Просмотреть файл

@ -1,21 +1,22 @@
package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
"net/http/httptest"
"reflect"
"testing"
"github.com/cucumber/godog"
"github.com/cucumber/messages-go/v9"
"git.golang1.ru/softonik/godog"
)
type apiFeature struct {
resp *httptest.ResponseRecorder
}
func (a *apiFeature) resetResponse(*messages.Pickle) {
func (a *apiFeature) resetResponse(*godog.Scenario) {
a.resp = httptest.NewRecorder()
}
@ -51,7 +52,7 @@ func (a *apiFeature) theResponseCodeShouldBe(code int) error {
return nil
}
func (a *apiFeature) theResponseShouldMatchJSON(body *messages.PickleStepArgument_PickleDocString) (err error) {
func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) (err error) {
var expected, actual interface{}
// re-encode expected response
@ -71,12 +72,29 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *messages.PickleStepArgumen
return nil
}
func FeatureContext(s *godog.Suite) {
func TestFeatures(t *testing.T) {
suite := godog.TestSuite{
ScenarioInitializer: InitializeScenario,
Options: &godog.Options{
Format: "pretty",
Paths: []string{"features"},
TestingT: t, // Testing instance that will run subtests.
},
}
if suite.Run() != 0 {
t.Fatal("non-zero status returned, failed to run feature tests")
}
}
func InitializeScenario(ctx *godog.ScenarioContext) {
api := &apiFeature{}
s.BeforeScenario(api.resetResponse)
s.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
s.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
s.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON)
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
api.resetResponse(sc)
return ctx, nil
})
ctx.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
ctx.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
ctx.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON)
}

Просмотреть файл

@ -20,6 +20,6 @@ Feature: get version
And the response should match json:
"""
{
"version": "v0.7.14"
"version": "v0.0.0-dev"
}
"""

Двоичные данные
_examples/api/screenshots/passed.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 75 КиБ

После

Ширина:  |  Высота:  |  Размер: 39 КиБ

Двоичные данные
_examples/api/screenshots/undefined.png

Двоичный файл не отображается.

До

Ширина:  |  Высота:  |  Размер: 99 КиБ

После

Ширина:  |  Высота:  |  Размер: 58 КиБ

Просмотреть файл

@ -0,0 +1,15 @@
# file: $GOPATH/godogs/features/godogs.feature
Feature: eat godogs
In order to be happy
As a hungry gopher
I need to be able to eat godogs
Scenario: Eat 5 out of 12
Given there are 12 godogs
When I eat 5
Then there should be 7 remaining
Scenario: Eat 12 out of 12
Given there are 12 godogs
When I eat 12
Then there should be none remaining

6
_examples/assert-godogs/godogs.go Обычный файл
Просмотреть файл

@ -0,0 +1,6 @@
package main
// Godogs available to eat
var Godogs int
func main() { /* usual main func */ }

66
_examples/assert-godogs/godogs_test.go Обычный файл
Просмотреть файл

@ -0,0 +1,66 @@
package main
import (
"context"
"os"
"testing"
"git.golang1.ru/softonik/godog"
"git.golang1.ru/softonik/godog/colors"
"github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
)
var opts = godog.Options{Output: colors.Colored(os.Stdout)}
func init() {
godog.BindCommandLineFlags("godog.", &opts)
}
func TestMain(m *testing.M) {
pflag.Parse()
opts.Paths = pflag.Args()
status := godog.TestSuite{
Name: "godogs",
ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run()
os.Exit(status)
}
func thereAreGodogs(available int) error {
Godogs = available
return nil
}
func iEat(ctx context.Context, num int) error {
if !assert.GreaterOrEqual(godog.T(ctx), Godogs, num, "You cannot eat %d godogs, there are %d available", num, Godogs) {
return nil
}
Godogs -= num
return nil
}
func thereShouldBeRemaining(ctx context.Context, remaining int) error {
assert.Equal(godog.T(ctx), Godogs, remaining, "Expected %d godogs to be remaining, but there is %d", remaining, Godogs)
return nil
}
func thereShouldBeNoneRemaining(ctx context.Context) error {
assert.Empty(godog.T(ctx), Godogs, "Expected none godogs to be remaining, but there is %d", Godogs)
return nil
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
Godogs = 0 // clean the state before every scenario
return ctx, nil
})
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Step(`^I eat (\d+)$`, iEat)
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
ctx.Step(`^there should be none remaining$`, thereShouldBeNoneRemaining)
}

16
_examples/attachments/README.md Обычный файл
Просмотреть файл

@ -0,0 +1,16 @@
# An example of Making attachments to the reports
The JSON (and in future NDJSON) report formats allow the inclusion of data attachments.
These attachments could be console logs or file data or images for instance.
The example in this directory shows how the godog API is used to add attachments to the JSON report.
## Run the example
You must use the '-v' flag or you will not see the cucumber JSON output.
go test -v attachments_test.go

89
_examples/attachments/attachments_test.go Обычный файл
Просмотреть файл

@ -0,0 +1,89 @@
package attachments_test
// This "demo" doesn't actually get run as a test by the build.
// This "example" shows how to attach data to the cucumber reports
// Run the sample with : go test -v attachments_test.go
// Then review the "embeddings" within the JSON emitted on the console.
import (
"context"
"os"
"testing"
"git.golang1.ru/softonik/godog"
"git.golang1.ru/softonik/godog/colors"
)
var opts = godog.Options{
Output: colors.Colored(os.Stdout),
Format: "cucumber", // cucumber json format
}
func TestFeatures(t *testing.T) {
o := opts
o.TestingT = t
status := godog.TestSuite{
Name: "attachments",
Options: &o,
ScenarioInitializer: InitializeScenario,
}.Run()
if status == 2 {
t.SkipNow()
}
if status != 0 {
t.Fatalf("zero status code expected, %d received", status)
}
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
ctx = godog.Attach(ctx,
godog.Attachment{Body: []byte("BeforeScenarioAttachment"), FileName: "Step Attachment 1", MediaType: "text/plain"},
)
return ctx, nil
})
ctx.After(func(ctx context.Context, sc *godog.Scenario, err error) (context.Context, error) {
ctx = godog.Attach(ctx,
godog.Attachment{Body: []byte("AfterScenarioAttachment"), FileName: "Step Attachment 2", MediaType: "text/plain"},
)
return ctx, nil
})
ctx.StepContext().Before(func(ctx context.Context, st *godog.Step) (context.Context, error) {
ctx = godog.Attach(ctx,
godog.Attachment{Body: []byte("BeforeStepAttachment"), FileName: "Step Attachment 3", MediaType: "text/plain"},
)
return ctx, nil
})
ctx.StepContext().After(func(ctx context.Context, st *godog.Step, status godog.StepResultStatus, err error) (context.Context, error) {
ctx = godog.Attach(ctx,
godog.Attachment{Body: []byte("AfterStepAttachment"), FileName: "Step Attachment 4", MediaType: "text/plain"},
)
return ctx, nil
})
ctx.Step(`^I have attached two documents in sequence$`, func(ctx context.Context) (context.Context, error) {
// the attached bytes will be base64 encoded by the framework and placed in the embeddings section of the cuke report
ctx = godog.Attach(ctx,
godog.Attachment{Body: []byte("TheData1"), FileName: "Step Attachment 5", MediaType: "text/plain"},
)
ctx = godog.Attach(ctx,
godog.Attachment{Body: []byte("{ \"a\" : 1 }"), FileName: "Step Attachment 6", MediaType: "application/json"},
)
return ctx, nil
})
ctx.Step(`^I have attached two documents at once$`, func(ctx context.Context) (context.Context, error) {
ctx = godog.Attach(ctx,
godog.Attachment{Body: []byte("TheData1"), FileName: "Step Attachment 7", MediaType: "text/plain"},
godog.Attachment{Body: []byte("TheData2"), FileName: "Step Attachment 8", MediaType: "text/plain"},
)
return ctx, nil
})
}

Просмотреть файл

@ -0,0 +1,7 @@
Feature: Attaching content to the cucumber report
The cucumber JSON and NDJSON support the inclusion of attachments.
These can be text or images or any data really.
Scenario: Attaching files to the report
Given I have attached two documents in sequence
And I have attached two documents at once

19
_examples/custom-formatter/README.md Обычный файл
Просмотреть файл

@ -0,0 +1,19 @@
# Custom Formatter Example
This example custom formatter demonstrates some ways to build and use custom formatters with godog
## Emoji Progress
The first example is the Emoji formatter, built on top of the Progress formatter that is included with godog.
To run it:
```
$ godog -f emoji
```
Which would output step progress as emojis rather than text:
![](imgs/emoji-output-example.png)

122
_examples/custom-formatter/emoji.go Обычный файл
Просмотреть файл

@ -0,0 +1,122 @@
package main
import (
"fmt"
"io"
"math"
"git.golang1.ru/softonik/godog"
)
const (
passedEmoji = "✅"
skippedEmoji = ""
failedEmoji = "❌"
undefinedEmoji = "❓"
pendingEmoji = "🚧"
)
func init() {
godog.Format("emoji", "Progress formatter with emojis", emojiFormatterFunc)
}
func emojiFormatterFunc(suite string, out io.Writer) godog.Formatter {
return newEmojiFmt(suite, out)
}
func newEmojiFmt(suite string, out io.Writer) *emojiFmt {
return &emojiFmt{
ProgressFmt: godog.NewProgressFmt(suite, out),
out: out,
}
}
type emojiFmt struct {
*godog.ProgressFmt
out io.Writer
}
func (f *emojiFmt) TestRunStarted() {}
func (f *emojiFmt) Passed(scenario *godog.Scenario, step *godog.Step, match *godog.StepDefinition) {
f.ProgressFmt.Base.Passed(scenario, step, match)
f.ProgressFmt.Base.Lock.Lock()
defer f.ProgressFmt.Base.Lock.Unlock()
f.step(step.Id)
}
func (f *emojiFmt) Skipped(scenario *godog.Scenario, step *godog.Step, match *godog.StepDefinition) {
f.ProgressFmt.Base.Skipped(scenario, step, match)
f.ProgressFmt.Base.Lock.Lock()
defer f.ProgressFmt.Base.Lock.Unlock()
f.step(step.Id)
}
func (f *emojiFmt) Undefined(scenario *godog.Scenario, step *godog.Step, match *godog.StepDefinition) {
f.ProgressFmt.Base.Undefined(scenario, step, match)
f.ProgressFmt.Base.Lock.Lock()
defer f.ProgressFmt.Base.Lock.Unlock()
f.step(step.Id)
}
func (f *emojiFmt) Failed(scenario *godog.Scenario, step *godog.Step, match *godog.StepDefinition, err error) {
f.ProgressFmt.Base.Failed(scenario, step, match, err)
f.ProgressFmt.Base.Lock.Lock()
defer f.ProgressFmt.Base.Lock.Unlock()
f.step(step.Id)
}
func (f *emojiFmt) Pending(scenario *godog.Scenario, step *godog.Step, match *godog.StepDefinition) {
f.ProgressFmt.Base.Pending(scenario, step, match)
f.ProgressFmt.Base.Lock.Lock()
defer f.ProgressFmt.Base.Lock.Unlock()
f.step(step.Id)
}
func (f *emojiFmt) Summary() {
f.printSummaryLegend()
f.ProgressFmt.Summary()
}
func (f *emojiFmt) printSummaryLegend() {
fmt.Fprint(f.out, "\n\nOutput Legend:\n")
fmt.Fprint(f.out, fmt.Sprintf("\t%s Passed\n", passedEmoji))
fmt.Fprint(f.out, fmt.Sprintf("\t%s Failed\n", failedEmoji))
fmt.Fprint(f.out, fmt.Sprintf("\t%s Skipped\n", skippedEmoji))
fmt.Fprint(f.out, fmt.Sprintf("\t%s Undefined\n", undefinedEmoji))
fmt.Fprint(f.out, fmt.Sprintf("\t%s Pending\n", pendingEmoji))
}
func (f *emojiFmt) step(pickleStepID string) {
pickleStepResult := f.Storage.MustGetPickleStepResult(pickleStepID)
switch pickleStepResult.Status {
case godog.StepPassed:
fmt.Fprint(f.out, fmt.Sprintf(" %s", passedEmoji))
case godog.StepSkipped:
fmt.Fprint(f.out, fmt.Sprintf(" %s", skippedEmoji))
case godog.StepFailed:
fmt.Fprint(f.out, fmt.Sprintf(" %s", failedEmoji))
case godog.StepUndefined:
fmt.Fprint(f.out, fmt.Sprintf(" %s", undefinedEmoji))
case godog.StepPending:
fmt.Fprint(f.out, fmt.Sprintf(" %s", pendingEmoji))
}
*f.Steps++
if math.Mod(float64(*f.Steps), float64(f.StepsPerRow)) == 0 {
fmt.Fprintf(f.out, " %d\n", *f.Steps)
}
}

Просмотреть файл

@ -0,0 +1,26 @@
# file: $GOPATH/godogs/features/godogs.feature
Feature: Custom emoji formatter examples
In order to be happy
As a hungry gopher
I need to be able to eat godogs
Scenario: Passing test
Given there are 12 godogs
When I eat 5
Then there should be 7 remaining
Scenario: Failing and Skipped test
Given there are 12 godogs
When I eat 5
Then there should be 6 remaining
And there should be 4 remaining
Scenario: Undefined steps
Given there are 12 godogs
When I eat 5
Then this step is not defined
Scenario: Pending step
Given there are 12 godogs
When I eat 5
Then this step is pending

6
_examples/custom-formatter/godogs.go Обычный файл
Просмотреть файл

@ -0,0 +1,6 @@
package main
// Godogs available to eat
var Godogs int
func main() { /* usual main func */ }

78
_examples/custom-formatter/godogs_test.go Обычный файл
Просмотреть файл

@ -0,0 +1,78 @@
package main
import (
"context"
"fmt"
"os"
"testing"
"git.golang1.ru/softonik/godog"
"git.golang1.ru/softonik/godog/colors"
flag "github.com/spf13/pflag"
)
var opts = godog.Options{
Output: colors.Colored(os.Stdout),
Format: "emoji",
}
func init() {
godog.BindCommandLineFlags("godog.", &opts)
}
func TestMain(m *testing.M) {
flag.Parse()
opts.Paths = flag.Args()
status := godog.TestSuite{
Name: "godogs",
TestSuiteInitializer: InitializeTestSuite,
ScenarioInitializer: InitializeScenario,
Options: &opts,
}.Run()
// This example test is expected to fail to showcase custom formatting, suppressing status.
if status != 1 {
os.Exit(1)
}
}
func thereAreGodogs(available int) error {
Godogs = available
return nil
}
func iEat(num int) error {
if Godogs < num {
return fmt.Errorf("you cannot eat %d godogs, there are %d available", num, Godogs)
}
Godogs -= num
return nil
}
func thereShouldBeRemaining(remaining int) error {
if Godogs != remaining {
return fmt.Errorf("expected %d godogs to be remaining, but there is %d", remaining, Godogs)
}
return nil
}
func thisStepIsPending() error {
return godog.ErrPending
}
func InitializeTestSuite(ctx *godog.TestSuiteContext) {
ctx.BeforeSuite(func() { Godogs = 0 })
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
Godogs = 0 // clean the state before every scenario
return ctx, nil
})
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Step(`^I eat (\d+)$`, iEat)
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
ctx.Step(`^this step is pending$`, thisStepIsPending)
}

Двоичные данные
_examples/custom-formatter/imgs/emoji-output-example.png Обычный файл

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 87 КиБ

Просмотреть файл

@ -1,7 +1,7 @@
# An example of API with DB
The following example demonstrates steps how we describe and test our API with DB using **godog**.
To start with, see [API example](https://github.com/cucumber/godog/tree/master/examples/api) before.
To start with, see [API example](https://git.golang1.ru/softonik/godog/tree/master/_examples/api) before.
We have extended it to be used with database.
The interesting point is, that we have [go-txdb](https://github.com/DATA-DOG/go-txdb) library,

Просмотреть файл

@ -1,6 +1,7 @@
package main
import (
"context"
"database/sql"
"encoding/json"
"fmt"
@ -10,8 +11,7 @@ import (
"strings"
txdb "github.com/DATA-DOG/go-txdb"
"github.com/cucumber/godog"
"github.com/cucumber/messages-go/v9"
"git.golang1.ru/softonik/godog"
)
func init() {
@ -24,7 +24,7 @@ type apiFeature struct {
resp *httptest.ResponseRecorder
}
func (a *apiFeature) resetResponse(*messages.Pickle) {
func (a *apiFeature) resetResponse(*godog.Scenario) {
a.resp = httptest.NewRecorder()
if a.db != nil {
a.db.Close()
@ -71,7 +71,7 @@ func (a *apiFeature) theResponseCodeShouldBe(code int) error {
return nil
}
func (a *apiFeature) theResponseShouldMatchJSON(body *messages.PickleStepArgument_PickleDocString) (err error) {
func (a *apiFeature) theResponseShouldMatchJSON(body *godog.DocString) (err error) {
var expected, actual interface{}
// re-encode expected response
@ -91,7 +91,7 @@ func (a *apiFeature) theResponseShouldMatchJSON(body *messages.PickleStepArgumen
return nil
}
func (a *apiFeature) thereAreUsers(users *messages.PickleStepArgument_PickleTable) error {
func (a *apiFeature) thereAreUsers(users *godog.Table) error {
var fields []string
var marks []string
head := users.Rows[0].Cells
@ -123,13 +123,16 @@ func (a *apiFeature) thereAreUsers(users *messages.PickleStepArgument_PickleTabl
return nil
}
func FeatureContext(s *godog.Suite) {
func InitializeScenario(ctx *godog.ScenarioContext) {
api := &apiFeature{}
s.BeforeScenario(api.resetResponse)
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
api.resetResponse(sc)
return ctx, nil
})
s.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
s.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
s.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON)
s.Step(`^there are users:$`, api.thereAreUsers)
ctx.Step(`^I send "(GET|POST|PUT|DELETE)" request to "([^"]*)"$`, api.iSendrequestTo)
ctx.Step(`^the response code should be (\d+)$`, api.theResponseCodeShouldBe)
ctx.Step(`^the response should match json:$`, api.theResponseShouldMatchJSON)
ctx.Step(`^there are users:$`, api.thereAreUsers)
}

18
_examples/go.mod Обычный файл
Просмотреть файл

@ -0,0 +1,18 @@
module git.golang1.ru/softonik/godog/_examples
go 1.16
replace git.golang1.ru/softonik/godog => ../
require (
github.com/DATA-DOG/go-txdb v0.1.6
git.golang1.ru/softonik/godog v0.15.0
github.com/go-sql-driver/mysql v1.7.1
github.com/spf13/pflag v1.0.6
github.com/stretchr/testify v1.8.2
)
require (
github.com/kr/pretty v0.3.0 // indirect
github.com/lib/pq v1.10.3 // indirect
)

65
_examples/go.sum Обычный файл
Просмотреть файл

@ -0,0 +1,65 @@
github.com/DATA-DOG/go-txdb v0.1.6 h1:D1Ob/L79mCW6UCFL6vwM/9TWs/rshZujxTsvy7+gicw=
github.com/DATA-DOG/go-txdb v0.1.6/go.mod h1:DhAhxMXZpUJVGnT+p9IbzJoRKvlArO2pkHjnGX7o0n0=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/cucumber/gherkin/go/v26 v26.2.0 h1:EgIjePLWiPeslwIWmNQ3XHcypPsWAHoMCz/YEBKP4GI=
github.com/cucumber/gherkin/go/v26 v26.2.0/go.mod h1:t2GAPnB8maCT4lkHL99BDCVNzCh1d7dBhCLt150Nr/0=
github.com/cucumber/messages/go/v21 v21.0.1 h1:wzA0LxwjlWQYZd32VTlAVDTkW6inOFmSM+RuOwHZiMI=
github.com/cucumber/messages/go/v21 v21.0.1/go.mod h1:zheH/2HS9JLVFukdrsPWoPdmUtmYQAQPLk7w5vWsk5s=
github.com/cucumber/messages/go/v22 v22.0.0/go.mod h1:aZipXTKc0JnjCsXrJnuZpWhtay93k7Rn3Dee7iyPJjs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.3.1+incompatible h1:0/KbAdpx3UXAx1kEOWHJeOkpbgRFGHVgv+CFIY7dBJI=
github.com/gofrs/uuid v4.3.1+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc=
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-memdb v1.3.4 h1:XSL3NR682X/cVk2IeV0d70N4DZ9ljI885xAEU8IoK3c=
github.com/hashicorp/go-memdb v1.3.4/go.mod h1:uBTr1oQbtuMgd1SSGoR8YV27eT3sBHbYiNm53bMpgSg=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lib/pq v1.10.3 h1:v9QZf2Sn6AmjXtQeFpdoq/eaNtYP6IN+7lcrygsIAtg=
github.com/lib/pq v1.10.3/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.6.1 h1:/FiVV8dS/e+YqF2JvO3yXRFbBLTIuSDkuC7aBOAvL+k=
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

Просмотреть файл

@ -1,4 +1,3 @@
# file: $GOPATH/godogs/features/godogs.feature
Feature: eat godogs
In order to be happy
As a hungry gopher
@ -8,3 +7,8 @@ Feature: eat godogs
Given there are 12 godogs
When I eat 5
Then there should be 7 remaining
Scenario: Eat 12 out of 12
Given there are 12 godogs
When I eat 12
Then there should be none remaining

14
_examples/godogs/features/nodogs.feature Обычный файл
Просмотреть файл

@ -0,0 +1,14 @@
Feature: do not eat godogs
In order to be fit
As a well-fed gopher
I need to be able to avoid godogs
Scenario: Eat 0 out of 12
Given there are 12 godogs
When I eat 0
Then there should be 12 remaining
Scenario: Eat 0 out of 0
Given there are 0 godogs
When I eat 0
Then there should be none remaining

Просмотреть файл

@ -1,7 +1,37 @@
/* file: $GOPATH/src/godogs/godogs.go */
package main
package godogs
// Godogs available to eat
var Godogs int
import (
"fmt"
)
func main() { /* usual main func */ }
// Godogs is an example behavior holder.
type Godogs int
// Add increments Godogs count.
func (g *Godogs) Add(n int) {
*g = *g + Godogs(n)
}
// Eat decrements Godogs count or fails if there is not enough available.
func (g *Godogs) Eat(n int) error {
ng := Godogs(n)
if (g == nil && ng > 0) || ng > *g {
return fmt.Errorf("you cannot eat %d godogs, there are %d available", n, g.Available())
}
if ng > 0 {
*g = *g - ng
}
return nil
}
// Available returns the number of currently available Godogs.
func (g *Godogs) Available() int {
if g == nil {
return 0
}
return int(*g)
}

Просмотреть файл

@ -1,63 +1,109 @@
/* file: $GOPATH/src/godogs/godogs_test.go */
package main
package godogs_test
// This example shows how to set up test suite runner with Go subtests and godog command line parameters.
// Sample commands:
// * run all scenarios from default directory (features): go test -test.run "^TestFeatures/"
// * run all scenarios and list subtest names: go test -test.v -test.run "^TestFeatures/"
// * run all scenarios from one feature file: go test -test.v -godog.paths features/nodogs.feature -test.run "^TestFeatures/"
// * run all scenarios from multiple feature files: go test -test.v -godog.paths features/nodogs.feature,features/godogs.feature -test.run "^TestFeatures/"
// * run single scenario as a subtest: go test -test.v -test.run "^TestFeatures/Eat_5_out_of_12$"
// * show usage help: go test -godog.help
// * show usage help if there were other test files in directory: go test -godog.help godogs_test.go
// * run scenarios with multiple formatters: go test -test.v -godog.format cucumber:cuc.json,pretty -test.run "^TestFeatures/"
import (
"context"
"flag"
"fmt"
"git.golang1.ru/softonik/godog/_examples/godogs"
"os"
"testing"
"github.com/cucumber/godog"
"github.com/cucumber/godog/colors"
messages "github.com/cucumber/messages-go/v9"
"git.golang1.ru/softonik/godog"
"git.golang1.ru/softonik/godog/colors"
)
var opt = godog.Options{Output: colors.Colored(os.Stdout)}
var opts = godog.Options{
Output: colors.Colored(os.Stdout),
Concurrency: 4,
}
func init() {
godog.BindFlags("godog.", flag.CommandLine, &opt)
godog.BindFlags("godog.", flag.CommandLine, &opts)
}
func TestMain(m *testing.M) {
flag.Parse()
opt.Paths = flag.Args()
func TestFeatures(t *testing.T) {
o := opts
o.TestingT = t
status := godog.RunWithOptions("godogs", func(s *godog.Suite) {
FeatureContext(s)
}, opt)
status := godog.TestSuite{
Name: "godogs",
Options: &o,
TestSuiteInitializer: InitializeTestSuite,
ScenarioInitializer: InitializeScenario,
}.Run()
if st := m.Run(); st > status {
status = st
if status == 2 {
t.SkipNow()
}
if status != 0 {
t.Fatalf("zero status code expected, %d received", status)
}
os.Exit(status)
}
func thereAreGodogs(available int) error {
Godogs = available
type godogsCtxKey struct{}
func godogsToContext(ctx context.Context, g godogs.Godogs) context.Context {
return context.WithValue(ctx, godogsCtxKey{}, &g)
}
func godogsFromContext(ctx context.Context) *godogs.Godogs {
g, _ := ctx.Value(godogsCtxKey{}).(*godogs.Godogs)
return g
}
// Concurrent execution of scenarios may lead to race conditions on shared resources.
// Use context to maintain data separation and avoid data races.
// Step definition can optionally receive context as a first argument.
func thereAreGodogs(ctx context.Context, available int) {
godogsFromContext(ctx).Add(available)
}
// Step definition can return error, context, context and error, or nothing.
func iEat(ctx context.Context, num int) error {
return godogsFromContext(ctx).Eat(num)
}
func thereShouldBeRemaining(ctx context.Context, remaining int) error {
available := godogsFromContext(ctx).Available()
if available != remaining {
return fmt.Errorf("expected %d godogs to be remaining, but there is %d", remaining, available)
}
return nil
}
func iEat(num int) error {
if Godogs < num {
return fmt.Errorf("you cannot eat %d godogs, there are %d available", num, Godogs)
}
Godogs -= num
return nil
func thereShouldBeNoneRemaining(ctx context.Context) error {
return thereShouldBeRemaining(ctx, 0)
}
func thereShouldBeRemaining(remaining int) error {
if Godogs != remaining {
return fmt.Errorf("expected %d godogs to be remaining, but there is %d", remaining, Godogs)
}
return nil
func InitializeTestSuite(ctx *godog.TestSuiteContext) {
ctx.BeforeSuite(func() { fmt.Println("Get the party started!") })
}
func FeatureContext(s *godog.Suite) {
s.Step(`^there are (\d+) godogs$`, thereAreGodogs)
s.Step(`^I eat (\d+)$`, iEat)
s.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
s.BeforeScenario(func(*messages.Pickle) {
Godogs = 0 // clean the state before every scenario
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Before(func(ctx context.Context, sc *godog.Scenario) (context.Context, error) {
// Add initial godogs to context.
return godogsToContext(ctx, 0), nil
})
ctx.Step(`^there are (\d+) godogs$`, thereAreGodogs)
ctx.Step(`^I eat (\d+)$`, iEat)
ctx.Step(`^there should be (\d+) remaining$`, thereShouldBeRemaining)
ctx.Step(`^there should be none remaining$`, thereShouldBeNoneRemaining)
}

Просмотреть файл

@ -0,0 +1,6 @@
This example is to help reproduce issue [#383](https://git.golang1.ru/softonik/godog/issues/383)
To run the example:
cd _examples/incorrect-project-structure
go run ../../cmd/godog

Просмотреть файл

@ -0,0 +1,7 @@
module incorrect-project-structure
go 1.13
require git.golang1.ru/softonik/godog v0.15.0
replace git.golang1.ru/softonik/godog => ../../

Просмотреть файл

@ -0,0 +1,71 @@
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cucumber/gherkin/go/v26 v26.0.2 h1:DjNKtTIv5VG0F1XaJ2xYNk+ck8pJWRNFzyajkc/Y4l4=
github.com/cucumber/gherkin/go/v26 v26.0.2/go.mod h1:Xf+SrSuFbivEDZvmHjTShord3zlEkqsj7QB4sxl1SuU=
github.com/cucumber/gherkin/go/v26 v26.2.0 h1:EgIjePLWiPeslwIWmNQ3XHcypPsWAHoMCz/YEBKP4GI=
github.com/cucumber/gherkin/go/v26 v26.2.0/go.mod h1:t2GAPnB8maCT4lkHL99BDCVNzCh1d7dBhCLt150Nr/0=
github.com/cucumber/messages/go/v21 v21.0.1 h1:wzA0LxwjlWQYZd32VTlAVDTkW6inOFmSM+RuOwHZiMI=
github.com/cucumber/messages/go/v21 v21.0.1/go.mod h1:zheH/2HS9JLVFukdrsPWoPdmUtmYQAQPLk7w5vWsk5s=
github.com/cucumber/messages/go/v22 v22.0.0/go.mod h1:aZipXTKc0JnjCsXrJnuZpWhtay93k7Rn3Dee7iyPJjs=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0=
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gofrs/uuid v4.3.1+incompatible h1:0/KbAdpx3UXAx1kEOWHJeOkpbgRFGHVgv+CFIY7dBJI=
github.com/gofrs/uuid v4.3.1+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc=
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-memdb v1.3.2 h1:RBKHOsnSszpU6vxq80LzC2BaQjuuvoyaQbkLTf7V7g8=
github.com/hashicorp/go-memdb v1.3.2/go.mod h1:Mluclgwib3R93Hk5fxEfiRhB+6Dar64wWh71LpNSe3g=
github.com/hashicorp/go-memdb v1.3.4 h1:XSL3NR682X/cVk2IeV0d70N4DZ9ljI885xAEU8IoK3c=
github.com/hashicorp/go-memdb v1.3.4/go.mod h1:uBTr1oQbtuMgd1SSGoR8YV27eT3sBHbYiNm53bMpgSg=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

Просмотреть файл

@ -0,0 +1,7 @@
package main
import "git.golang1.ru/softonik/godog"
func InitializeScenario(ctx *godog.ScenarioContext) {
}

28
attachment_test.go Обычный файл
Просмотреть файл

@ -0,0 +1,28 @@
package godog
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
)
func TestAttach(t *testing.T) {
ctx := context.Background()
ctx = Attach(ctx, Attachment{Body: []byte("body1"), FileName: "fileName1", MediaType: "mediaType1"})
ctx = Attach(ctx, Attachment{Body: []byte("body2"), FileName: "fileName2", MediaType: "mediaType2"})
attachments := Attachments(ctx)
assert.Equal(t, 2, len(attachments))
assert.Equal(t, []byte("body1"), attachments[0].Body)
assert.Equal(t, "fileName1", attachments[0].FileName)
assert.Equal(t, "mediaType1", attachments[0].MediaType)
assert.Equal(t, []byte("body2"), attachments[1].Body)
assert.Equal(t, "fileName2", attachments[1].FileName)
assert.Equal(t, "mediaType2", attachments[1].MediaType)
}

Просмотреть файл

@ -1,354 +0,0 @@
// +build !go1.10
package godog
import (
"bytes"
"fmt"
"go/build"
"go/parser"
"go/token"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"strings"
"text/template"
"time"
"unicode"
)
var tooldir = findToolDir()
var compiler = filepath.Join(tooldir, "compile")
var linker = filepath.Join(tooldir, "link")
var gopaths = filepath.SplitList(build.Default.GOPATH)
var goarch = build.Default.GOARCH
var goos = build.Default.GOOS
var godogImportPath = "github.com/cucumber/godog"
var runnerTemplate = template.Must(template.New("testmain").Parse(`package main
import (
"github.com/cucumber/godog"
{{if .Contexts}}_test "{{.ImportPath}}"{{end}}
"os"
)
func main() {
status := godog.Run("{{ .Name }}", func (suite *godog.Suite) {
os.Setenv("GODOG_TESTED_PACKAGE", "{{.ImportPath}}")
{{range .Contexts}}
_test.{{ . }}(suite)
{{end}}
})
os.Exit(status)
}`))
// Build creates a test package like go test command at given target path.
// If there are no go files in tested directory, then
// it simply builds a godog executable to scan features.
//
// If there are go test files, it first builds a test
// package with standard go test command.
//
// Finally it generates godog suite executable which
// registers exported godog contexts from the test files
// of tested package.
//
// Returns the path to generated executable
func Build(bin string) error {
abs, err := filepath.Abs(".")
if err != nil {
return err
}
// we allow package to be nil, if godog is run only when
// there is a feature file in empty directory
pkg := importPackage(abs)
src, anyContexts, err := buildTestMain(pkg)
if err != nil {
return err
}
workdir := fmt.Sprintf(filepath.Join("%s", "godog-%d"), os.TempDir(), time.Now().UnixNano())
testdir := workdir
// if none of test files exist, or there are no contexts found
// we will skip test package compilation, since it is useless
if anyContexts {
// first of all compile test package dependencies
// that will save was many compilations for dependencies
// go does it better
out, err := exec.Command("go", "test", "-i").CombinedOutput()
if err != nil {
return fmt.Errorf("failed to compile package: %s, reason: %v, output: %s", pkg.Name, err, string(out))
}
// build and compile the tested package.
// generated test executable will be removed
// since we do not need it for godog suite.
// we also print back the temp WORK directory
// go has built. We will reuse it for our suite workdir.
// go1.5 does not support os.DevNull as void output
temp := fmt.Sprintf(filepath.Join("%s", "temp-%d.test"), os.TempDir(), time.Now().UnixNano())
out, err = exec.Command("go", "test", "-c", "-work", "-o", temp).CombinedOutput()
if err != nil {
return fmt.Errorf("failed to compile tested package: %s, reason: %v, output: %s", pkg.Name, err, string(out))
}
defer os.Remove(temp)
// extract go-build temporary directory as our workdir
lines := strings.Split(strings.TrimSpace(string(out)), "\n")
// it may have some compilation warnings, in the output, but these are not
// considered to be errors, since command exit status is 0
for _, ln := range lines {
if !strings.HasPrefix(ln, "WORK=") {
continue
}
workdir = strings.Replace(ln, "WORK=", "", 1)
break
}
// may not locate it in output
if workdir == testdir {
return fmt.Errorf("expected WORK dir path to be present in output: %s", string(out))
}
// check whether workdir exists
stats, err := os.Stat(workdir)
if os.IsNotExist(err) {
return fmt.Errorf("expected WORK dir: %s to be available", workdir)
}
if !stats.IsDir() {
return fmt.Errorf("expected WORK dir: %s to be directory", workdir)
}
testdir = filepath.Join(workdir, pkg.ImportPath, "_test")
} else {
// still need to create temporary workdir
if err = os.MkdirAll(testdir, 0755); err != nil {
return err
}
}
defer os.RemoveAll(workdir)
// replace _testmain.go file with our own
testmain := filepath.Join(testdir, "_testmain.go")
err = ioutil.WriteFile(testmain, src, 0644)
if err != nil {
return err
}
// godog library may not be imported in tested package
// but we need it for our testmain package.
// So we look it up in available source paths
// including vendor directory, supported since 1.5.
try := maybeVendorPaths(abs)
for _, d := range build.Default.SrcDirs() {
try = append(try, filepath.Join(d, godogImportPath))
}
godogPkg, err := locatePackage(try)
if err != nil {
return err
}
// make sure godog package archive is installed, gherkin
// will be installed as dependency of godog
cmd := exec.Command("go", "install", godogPkg.ImportPath)
cmd.Env = os.Environ()
out, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("failed to install godog package: %s, reason: %v", string(out), err)
}
// collect all possible package dirs, will be
// used for includes and linker
pkgDirs := []string{workdir, testdir}
for _, gopath := range gopaths {
pkgDirs = append(pkgDirs, filepath.Join(gopath, "pkg", goos+"_"+goarch))
}
pkgDirs = uniqStringList(pkgDirs)
// compile godog testmain package archive
// we do not depend on CGO so a lot of checks are not necessary
testMainPkgOut := filepath.Join(testdir, "main.a")
args := []string{
"-o", testMainPkgOut,
// "-trimpath", workdir,
"-p", "main",
"-complete",
}
// if godog library is in vendor directory
// link it with import map
if i := strings.LastIndex(godogPkg.ImportPath, "vendor/"); i != -1 {
args = append(args, "-importmap", godogImportPath+"="+godogPkg.ImportPath)
}
for _, inc := range pkgDirs {
args = append(args, "-I", inc)
}
args = append(args, "-pack", testmain)
cmd = exec.Command(compiler, args...)
cmd.Env = os.Environ()
out, err = cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("failed to compile testmain package: %v - output: %s", err, string(out))
}
// link test suite executable
args = []string{
"-o", bin,
"-buildmode=exe",
}
for _, link := range pkgDirs {
args = append(args, "-L", link)
}
args = append(args, testMainPkgOut)
cmd = exec.Command(linker, args...)
cmd.Env = os.Environ()
out, err = cmd.CombinedOutput()
if err != nil {
msg := `failed to link test executable:
reason: %s
command: %s`
return fmt.Errorf(msg, string(out), linker+" '"+strings.Join(args, "' '")+"'")
}
return nil
}
func locatePackage(try []string) (*build.Package, error) {
for _, p := range try {
abs, err := filepath.Abs(p)
if err != nil {
continue
}
pkg, err := build.ImportDir(abs, 0)
if err != nil {
continue
}
return pkg, nil
}
return nil, fmt.Errorf("failed to find godog package in any of:\n%s", strings.Join(try, "\n"))
}
func importPackage(dir string) *build.Package {
pkg, _ := build.ImportDir(dir, 0)
// normalize import path for local import packages
// taken from go source code
// see: https://github.com/golang/go/blob/go1.7rc5/src/cmd/go/pkg.go#L279
if pkg != nil && pkg.ImportPath == "." {
pkg.ImportPath = path.Join("_", strings.Map(makeImportValid, filepath.ToSlash(dir)))
}
return pkg
}
// from go src
func makeImportValid(r rune) rune {
// Should match Go spec, compilers, and ../../go/parser/parser.go:/isValidImport.
const illegalChars = `!"#$%&'()*,:;<=>?[\]^{|}` + "`\uFFFD"
if !unicode.IsGraphic(r) || unicode.IsSpace(r) || strings.ContainsRune(illegalChars, r) {
return '_'
}
return r
}
type void struct{}
func uniqStringList(strs []string) (unique []string) {
uniq := make(map[string]void, len(strs))
for _, s := range strs {
if _, ok := uniq[s]; !ok {
uniq[s] = void{}
unique = append(unique, s)
}
}
return
}
// buildTestMain if given package is valid
// it scans test files for contexts
// and produces a testmain source code.
func buildTestMain(pkg *build.Package) ([]byte, bool, error) {
var contexts []string
var importPath string
name := "main"
if nil != pkg {
ctxs, err := processPackageTestFiles(
pkg.TestGoFiles,
pkg.XTestGoFiles,
)
if err != nil {
return nil, false, err
}
contexts = ctxs
importPath = pkg.ImportPath
name = pkg.Name
}
data := struct {
Name string
Contexts []string
ImportPath string
}{name, contexts, importPath}
var buf bytes.Buffer
if err := runnerTemplate.Execute(&buf, data); err != nil {
return nil, len(contexts) > 0, err
}
return buf.Bytes(), len(contexts) > 0, nil
}
// maybeVendorPaths determines possible vendor paths
// which goes levels down from given directory
// until it reaches GOPATH source dir
func maybeVendorPaths(dir string) (paths []string) {
for _, gopath := range gopaths {
gopath = filepath.Join(gopath, "src")
for strings.HasPrefix(dir, gopath) && dir != gopath {
paths = append(paths, filepath.Join(dir, "vendor", godogImportPath))
dir = filepath.Dir(dir)
}
}
return
}
// processPackageTestFiles runs through ast of each test
// file pack and looks for godog suite contexts to register
// on run
func processPackageTestFiles(packs ...[]string) ([]string, error) {
var ctxs []string
fset := token.NewFileSet()
for _, pack := range packs {
for _, testFile := range pack {
node, err := parser.ParseFile(fset, testFile, nil, 0)
if err != nil {
return ctxs, err
}
ctxs = append(ctxs, astContexts(node)...)
}
}
var failed []string
for _, ctx := range ctxs {
runes := []rune(ctx)
if unicode.IsLower(runes[0]) {
expected := append([]rune{unicode.ToUpper(runes[0])}, runes[1:]...)
failed = append(failed, fmt.Sprintf("%s - should be: %s", ctx, string(expected)))
}
}
if len(failed) > 0 {
return ctxs, fmt.Errorf("godog contexts must be exported:\n\t%s", strings.Join(failed, "\n\t"))
}
return ctxs, nil
}
func findToolDir() string {
if out, err := exec.Command("go", "env", "GOTOOLDIR").Output(); err != nil {
return filepath.Clean(strings.TrimSpace(string(out)))
}
return filepath.Clean(build.ToolDir)
}

Просмотреть файл

@ -1,186 +0,0 @@
// +build go1.11
package godog
import (
"bytes"
"fmt"
"os"
"os/exec"
"path/filepath"
"testing"
)
func TestGodogBuildWithModuleOutsideGopathAndHavingOnlyFeature(t *testing.T) {
dir := filepath.Join(os.TempDir(), "godogs")
err := buildTestPackage(dir, map[string]string{
"godogs.feature": builderFeatureFile,
})
if err != nil {
os.RemoveAll(dir)
t.Fatal(err)
}
defer os.RemoveAll(dir)
prevDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}
defer os.Chdir(prevDir)
if out, err := exec.Command("go", "mod", "init", "godogs").CombinedOutput(); err != nil {
t.Log(string(out))
t.Fatal(err)
}
if out, err := exec.Command("go", "mod", "edit", "-require", fmt.Sprintf("github.com/cucumber/godog@%s", Version)).CombinedOutput(); err != nil {
t.Log(string(out))
t.Fatal(err)
}
var stdout, stderr bytes.Buffer
cmd := buildTestCommand(t, "godogs.feature")
cmd.Stdout = &stdout
cmd.Stderr = &stderr
cmd.Env = os.Environ()
if err := cmd.Run(); err != nil {
t.Log(stdout.String())
t.Log(stderr.String())
t.Fatal(err)
}
}
func TestGodogBuildWithModuleOutsideGopath(t *testing.T) {
dir := filepath.Join(os.TempDir(), "godogs")
err := buildTestPackage(dir, map[string]string{
"godogs.feature": builderFeatureFile,
"godogs.go": builderMainCodeFile,
"godogs_test.go": builderTestFile,
})
if err != nil {
os.RemoveAll(dir)
t.Fatal(err)
}
defer os.RemoveAll(dir)
prevDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}
defer os.Chdir(prevDir)
if out, err := exec.Command("go", "mod", "init", "godogs").CombinedOutput(); err != nil {
t.Log(string(out))
t.Fatal(err)
}
var stdout, stderr bytes.Buffer
cmd := buildTestCommand(t, "godogs.feature")
cmd.Stdout = &stdout
cmd.Stderr = &stderr
cmd.Env = os.Environ()
if err := cmd.Run(); err != nil {
t.Log(stdout.String())
t.Log(stderr.String())
t.Fatal(err)
}
}
func TestGodogBuildWithModuleWithXTestOutsideGopath(t *testing.T) {
dir := filepath.Join(os.TempDir(), "godogs")
err := buildTestPackage(dir, map[string]string{
"godogs.feature": builderFeatureFile,
"godogs.go": builderMainCodeFile,
"godogs_test.go": builderXTestFile,
})
if err != nil {
os.RemoveAll(dir)
t.Fatal(err)
}
defer os.RemoveAll(dir)
prevDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}
defer os.Chdir(prevDir)
if out, err := exec.Command("go", "mod", "init", "godogs").CombinedOutput(); err != nil {
t.Log(string(out))
t.Fatal(err)
}
var stdout, stderr bytes.Buffer
cmd := buildTestCommand(t, "godogs.feature")
cmd.Stdout = &stdout
cmd.Stderr = &stderr
cmd.Env = os.Environ()
if err := cmd.Run(); err != nil {
t.Log(stdout.String())
t.Log(stderr.String())
t.Fatal(err)
}
}
func TestGodogBuildWithModuleInsideGopath(t *testing.T) {
gopath := filepath.Join(os.TempDir(), "_gp")
dir := filepath.Join(gopath, "src", "godogs")
err := buildTestPackage(dir, map[string]string{
"godogs.feature": builderFeatureFile,
"godogs.go": builderMainCodeFile,
"godogs_test.go": builderTestFile,
})
if err != nil {
os.RemoveAll(gopath)
t.Fatal(err)
}
defer os.RemoveAll(gopath)
prevDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}
defer os.Chdir(prevDir)
c := exec.Command("go", "mod", "init", "godogs")
c.Env = os.Environ()
c.Env = append(c.Env, "GOPATH="+gopath)
c.Env = append(c.Env, "GO111MODULE=on")
if out, err := c.CombinedOutput(); err != nil {
t.Log(string(out))
t.Fatal(err)
}
var stdout, stderr bytes.Buffer
cmd := buildTestCommand(t, "godogs.feature")
cmd.Stdout = &stdout
cmd.Stderr = &stderr
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "GOPATH="+gopath)
cmd.Env = append(cmd.Env, "GO111MODULE=on")
if err := cmd.Run(); err != nil {
t.Log(stdout.String())
t.Log(stderr.String())
t.Fatal(err)
}
}

Просмотреть файл

@ -1,60 +0,0 @@
// +build go1.12
// +build !go1.13
package godog
import (
"bytes"
"os"
"path/filepath"
"testing"
)
func TestGodogBuildWithVendoredGodogAndMod(t *testing.T) {
gopath := filepath.Join(os.TempDir(), "_gpc")
dir := filepath.Join(gopath, "src", "godogs")
err := buildTestPackage(dir, map[string]string{
"godogs.feature": builderFeatureFile,
"godogs.go": builderMainCodeFile,
"godogs_test.go": builderTestFile,
"go.mod": builderModFile,
})
if err != nil {
os.RemoveAll(gopath)
t.Fatal(err)
}
defer os.RemoveAll(gopath)
pkg := filepath.Join(dir, "vendor", "github.com", "cucumber")
if err := os.MkdirAll(pkg, 0755); err != nil {
t.Fatal(err)
}
prevDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
// symlink godog package
if err := os.Symlink(prevDir, filepath.Join(pkg, "godog")); err != nil {
t.Fatal(err)
}
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}
defer os.Chdir(prevDir)
cmd := buildTestCommand(t, "godogs.feature")
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
cmd.Env = append(envVarsWithoutGopath(), "GOPATH="+gopath)
if err := cmd.Run(); err != nil {
t.Log(stdout.String())
t.Log(stderr.String())
t.Fatal(err)
}
}

Просмотреть файл

@ -1,54 +0,0 @@
// +build go1.13
package godog
import (
"bytes"
"os"
"os/exec"
"path/filepath"
"testing"
)
func TestGodogBuildWithVendoredGodogAndMod(t *testing.T) {
gopath := filepath.Join(os.TempDir(), "_gpc")
dir := filepath.Join(gopath, "src", "godogs")
err := buildTestPackage(dir, map[string]string{
"godogs.feature": builderFeatureFile,
"godogs.go": builderMainCodeFile,
"godogs_test.go": builderTestFile,
"go.mod": builderModFile,
})
if err != nil {
os.RemoveAll(gopath)
t.Fatal(err)
}
defer os.RemoveAll(gopath)
prevDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
if err = exec.Command("go", "mod", "vendor").Run(); err != nil {
t.Fatal(err)
}
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}
defer os.Chdir(prevDir)
cmd := buildTestCommand(t, "godogs.feature")
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
cmd.Env = append(envVarsWithoutGopath(), "GOPATH="+gopath)
if err := cmd.Run(); err != nil {
t.Log(stdout.String())
t.Log(stderr.String())
t.Fatal(err)
}
}

Просмотреть файл

@ -1,357 +0,0 @@
package godog
import (
"bytes"
"go/build"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)
var builderFeatureFile = `Feature: eat godogs
In order to be happy
As a hungry gopher
I need to be able to eat godogs
Scenario: Eat 5 out of 12
Given there are 12 godogs
When I eat 5
Then there should be 7 remaining
`
var builderTestFile = `package godogs
import (
"fmt"
"github.com/cucumber/godog"
)
func thereAreGodogs(available int) error {
Godogs = available
return nil
}
func iEat(num int) error {
if Godogs < num {
return fmt.Errorf("you cannot eat %d godogs, there are %d available", num, Godogs)
}
Godogs -= num
return nil
}
func thereShouldBeRemaining(remaining int) error {
if Godogs != remaining {
return fmt.Errorf("expected %d godogs to be remaining, but there is %d", remaining, Godogs)
}
return nil
}
func FeatureContext(s *godog.Suite) {
s.Step("^there are (\\d+) godogs$", thereAreGodogs)
s.Step("^I eat (\\d+)$", iEat)
s.Step("^there should be (\\d+) remaining$", thereShouldBeRemaining)
s.BeforeScenario(func(interface{}) {
Godogs = 0 // clean the state before every scenario
})
}
`
var builderXTestFile = `package godogs_test
import (
"fmt"
"github.com/cucumber/godog"
"godogs"
)
func thereAreGodogs(available int) error {
godogs.Godogs = available
return nil
}
func iEat(num int) error {
if godogs.Godogs < num {
return fmt.Errorf("you cannot eat %d godogs, there are %d available", num, godogs.Godogs)
}
godogs.Godogs -= num
return nil
}
func thereShouldBeRemaining(remaining int) error {
if godogs.Godogs != remaining {
return fmt.Errorf("expected %d godogs to be remaining, but there is %d", remaining, godogs.Godogs)
}
return nil
}
func FeatureContext(s *godog.Suite) {
s.Step("^there are (\\d+) godogs$", thereAreGodogs)
s.Step("^I eat (\\d+)$", iEat)
s.Step("^there should be (\\d+) remaining$", thereShouldBeRemaining)
s.BeforeScenario(func(interface{}) {
godogs.Godogs = 0 // clean the state before every scenario
})
}
`
var builderMainCodeFile = `package godogs
// Godogs available to eat
var Godogs int
func main() {
}
`
var builderModFile = `module godogs`
func buildTestPackage(dir string, files map[string]string) error {
if err := os.MkdirAll(dir, 0755); err != nil {
return err
}
for name, content := range files {
if err := ioutil.WriteFile(filepath.Join(dir, name), []byte(content), 0644); err != nil {
return err
}
}
return nil
}
func buildTestCommand(t *testing.T, args ...string) *exec.Cmd {
bin, err := filepath.Abs("godog.test")
if err != nil {
t.Fatal(err)
}
if build.Default.GOOS == "windows" {
bin += ".exe"
}
if err = Build(bin); err != nil {
t.Fatal(err)
}
return exec.Command(bin, args...)
}
func envVarsWithoutGopath() []string {
var env []string
for _, def := range os.Environ() {
if strings.Index(def, "GOPATH=") == 0 {
continue
}
env = append(env, def)
}
return env
}
func TestGodogBuildWithSourceNotInGoPath(t *testing.T) {
dir := filepath.Join(os.TempDir(), "godogs")
err := buildTestPackage(dir, map[string]string{
"godogs.feature": builderFeatureFile,
"godogs.go": builderMainCodeFile,
"godogs_test.go": builderTestFile,
"go.mod": builderModFile,
})
if err != nil {
os.RemoveAll(dir)
t.Fatal(err)
}
defer os.RemoveAll(dir)
prevDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}
defer os.Chdir(prevDir)
cmd := buildTestCommand(t, "godogs.feature")
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
t.Log(stdout.String())
t.Log(stderr.String())
t.Fatal(err)
}
}
func TestGodogBuildWithoutSourceNotInGoPath(t *testing.T) {
dir := filepath.Join(os.TempDir(), "godogs")
err := buildTestPackage(dir, map[string]string{
"godogs.feature": builderFeatureFile,
"go.mod": builderModFile,
})
if err != nil {
os.RemoveAll(dir)
t.Fatal(err)
}
defer os.RemoveAll(dir)
prevDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}
defer os.Chdir(prevDir)
cmd := buildTestCommand(t, "godogs.feature")
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
t.Log(stdout.String())
t.Log(stderr.String())
t.Fatal(err)
}
}
func TestGodogBuildWithoutTestSourceNotInGoPath(t *testing.T) {
dir := filepath.Join(os.TempDir(), "godogs")
err := buildTestPackage(dir, map[string]string{
"godogs.feature": builderFeatureFile,
"godogs.go": builderMainCodeFile,
"go.mod": builderModFile,
})
if err != nil {
os.RemoveAll(dir)
t.Fatal(err)
}
defer os.RemoveAll(dir)
prevDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}
defer os.Chdir(prevDir)
cmd := buildTestCommand(t, "godogs.feature")
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
if err := cmd.Run(); err != nil {
t.Log(stdout.String())
t.Log(stderr.String())
t.Fatal(err)
}
}
func TestGodogBuildWithinGopath(t *testing.T) {
gopath := filepath.Join(os.TempDir(), "_gp")
dir := filepath.Join(gopath, "src", "godogs")
err := buildTestPackage(dir, map[string]string{
"godogs.feature": builderFeatureFile,
"godogs.go": builderMainCodeFile,
"godogs_test.go": builderTestFile,
"go.mod": builderModFile,
})
if err != nil {
os.RemoveAll(gopath)
t.Fatal(err)
}
defer os.RemoveAll(gopath)
pkg := filepath.Join(gopath, "src", "github.com", "cucumber")
if err := os.MkdirAll(pkg, 0755); err != nil {
t.Fatal(err)
}
prevDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
// symlink godog package
if err := os.Symlink(prevDir, filepath.Join(pkg, "godog")); err != nil {
t.Fatal(err)
}
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}
defer os.Chdir(prevDir)
cmd := buildTestCommand(t, "godogs.feature")
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "GOPATH="+gopath)
if err := cmd.Run(); err != nil {
t.Log(stdout.String())
t.Log(stderr.String())
t.Fatal(err)
}
}
func TestGodogBuildWithVendoredGodogWithoutModule(t *testing.T) {
gopath := filepath.Join(os.TempDir(), "_gp")
dir := filepath.Join(gopath, "src", "godogs")
err := buildTestPackage(dir, map[string]string{
"godogs.feature": builderFeatureFile,
})
if err != nil {
os.RemoveAll(gopath)
t.Fatal(err)
}
defer os.RemoveAll(gopath)
pkg := filepath.Join(dir, "vendor", "github.com", "cucumber")
if err := os.MkdirAll(pkg, 0755); err != nil {
t.Fatal(err)
}
prevDir, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
// symlink godog package
if err := os.Symlink(prevDir, filepath.Join(pkg, "godog")); err != nil {
t.Fatal(err)
}
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}
defer os.Chdir(prevDir)
cmd := buildTestCommand(t, "godogs.feature")
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr
cmd.Env = append(envVarsWithoutGopath(), "GOPATH="+gopath)
if err := cmd.Run(); err != nil {
t.Log(stdout.String())
t.Log(stderr.String())
t.Fatal(err)
}
}

55
cmd/godog/internal/cmd_build.go Обычный файл
Просмотреть файл

@ -0,0 +1,55 @@
package internal
import (
"fmt"
"go/build"
"path/filepath"
"git.golang1.ru/softonik/godog/colors"
"git.golang1.ru/softonik/godog/internal/builder"
"github.com/spf13/cobra"
)
var buildOutput string
var buildOutputDefault = "godog.test"
// CreateBuildCmd creates the build subcommand.
func CreateBuildCmd() cobra.Command {
if build.Default.GOOS == "windows" {
buildOutputDefault += ".exe"
}
buildCmd := cobra.Command{
Use: "build",
Short: "Compiles a test runner",
Long: `Compiles a test runner. Command should be run from the directory of tested
package and contain buildable go source.
The test runner can be executed with the same flags as when using godog run.`,
Example: ` godog build
godog build -o ` + buildOutputDefault,
RunE: buildCmdRunFunc,
}
buildCmd.Flags().StringVarP(&buildOutput, "output", "o", buildOutputDefault, `compiles the test runner to the named file
`)
return buildCmd
}
func buildCmdRunFunc(cmd *cobra.Command, args []string) error {
fmt.Println(colors.Yellow("Use of godog CLI is deprecated, please use *testing.T instead."))
fmt.Println(colors.Yellow("See https://git.golang1.ru/softonik/godog/discussions/478 for details."))
bin, err := filepath.Abs(buildOutput)
if err != nil {
return fmt.Errorf("could not locate absolute path for: %q. reason: %v", buildOutput, err)
}
if err = builder.Build(bin); err != nil {
return fmt.Errorf("could not build binary at: %q. reason: %v", buildOutput, err)
}
return nil
}

65
cmd/godog/internal/cmd_root.go Обычный файл
Просмотреть файл

@ -0,0 +1,65 @@
package internal
import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"git.golang1.ru/softonik/godog/internal/flags"
)
var version bool
var output string
// CreateRootCmd creates the root command.
func CreateRootCmd() cobra.Command {
rootCmd := cobra.Command{
Use: "godog",
Long: `Creates and runs test runner for the given feature files.
Command should be run from the directory of tested package
and contain buildable go source.`,
Args: cobra.ArbitraryArgs,
// Deprecated: Use godog build, godog run or godog version.
// This is to support the legacy direct usage of the root command.
RunE: runRootCmd,
}
bindRootCmdFlags(rootCmd.Flags())
return rootCmd
}
func runRootCmd(cmd *cobra.Command, args []string) error {
if version {
versionCmdRunFunc(cmd, args)
return nil
}
if len(output) > 0 {
buildOutput = output
if err := buildCmdRunFunc(cmd, args); err != nil {
return err
}
}
return runCmdRunFunc(cmd, args)
}
func bindRootCmdFlags(flagSet *pflag.FlagSet) {
flagSet.StringVarP(&output, "output", "o", "", "compiles the test runner to the named file")
flagSet.BoolVar(&version, "version", false, "show current version")
flags.BindRunCmdFlags("", flagSet, &opts)
// Since using the root command directly is deprecated.
// All flags will be hidden
flagSet.MarkHidden("output")
flagSet.MarkHidden("version")
flagSet.MarkHidden("no-colors")
flagSet.MarkHidden("concurrency")
flagSet.MarkHidden("tags")
flagSet.MarkHidden("format")
flagSet.MarkHidden("definitions")
flagSet.MarkHidden("stop-on-failure")
flagSet.MarkHidden("strict")
flagSet.MarkHidden("random")
}

111
cmd/godog/internal/cmd_run.go Обычный файл
Просмотреть файл

@ -0,0 +1,111 @@
package internal
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"syscall"
"github.com/spf13/cobra"
"git.golang1.ru/softonik/godog/colors"
"git.golang1.ru/softonik/godog/internal/builder"
"git.golang1.ru/softonik/godog/internal/flags"
)
var opts flags.Options
// CreateRunCmd creates the run subcommand.
func CreateRunCmd() cobra.Command {
runCmd := cobra.Command{
Use: "run [features]",
Short: "Compiles and runs a test runner",
Long: `Compiles and runs test runner for the given feature files.
Command should be run from the directory of tested package and contain
buildable go source.`,
Example: ` godog run
godog run <feature>
godog run <feature> <feature>
Optional feature(s) to run:
dir (features/)
feature (*.feature)
scenario at specific line (*.feature:10)
If no feature arguments are supplied, godog will use "features/" by default.`,
RunE: runCmdRunFunc,
SilenceUsage: true,
}
flags.BindRunCmdFlags("", runCmd.Flags(), &opts)
return runCmd
}
func runCmdRunFunc(cmd *cobra.Command, args []string) error {
fmt.Println(colors.Yellow("Use of godog CLI is deprecated, please use *testing.T instead."))
fmt.Println(colors.Yellow("See https://git.golang1.ru/softonik/godog/discussions/478 for details."))
osArgs := os.Args[1:]
if len(osArgs) > 0 && osArgs[0] == "run" {
osArgs = osArgs[1:]
}
if err := buildAndRunGodog(osArgs); err != nil {
return err
}
return nil
}
func buildAndRunGodog(args []string) (err error) {
bin, err := filepath.Abs(buildOutputDefault)
if err != nil {
return err
}
if err = builder.Build(bin); err != nil {
return err
}
defer os.Remove(bin)
return runGodog(bin, args)
}
func runGodog(bin string, args []string) (err error) {
cmd := exec.Command(bin, args...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
cmd.Env = os.Environ()
if err = cmd.Start(); err != nil {
return err
}
if err = cmd.Wait(); err == nil {
return nil
}
exiterr, ok := err.(*exec.ExitError)
if !ok {
return err
}
st, ok := exiterr.Sys().(syscall.WaitStatus)
if !ok {
return fmt.Errorf("failed to convert error to syscall wait status. original error: %w", exiterr)
}
// This works on both Unix and Windows. Although package
// syscall is generally platform dependent, WaitStatus is
// defined for both Unix and Windows and in both cases has
// an ExitStatus() method with the same signature.
if st.ExitStatus() > 0 {
return err
}
return nil
}

26
cmd/godog/internal/cmd_version.go Обычный файл
Просмотреть файл

@ -0,0 +1,26 @@
package internal
import (
"fmt"
"os"
"github.com/spf13/cobra"
"git.golang1.ru/softonik/godog"
)
// CreateVersionCmd creates the version subcommand.
func CreateVersionCmd() cobra.Command {
versionCmd := cobra.Command{
Use: "version",
Short: "Show current version",
Run: versionCmdRunFunc,
Version: godog.Version,
}
return versionCmd
}
func versionCmdRunFunc(cmd *cobra.Command, args []string) {
fmt.Fprintln(os.Stdout, "Godog version is:", godog.Version)
}

Просмотреть файл

@ -2,104 +2,21 @@ package main
import (
"fmt"
"go/build"
"os"
"os/exec"
"path/filepath"
"syscall"
"github.com/cucumber/godog"
"github.com/cucumber/godog/colors"
"git.golang1.ru/softonik/godog/cmd/godog/internal"
)
var parsedStatus int
func buildAndRun() (int, error) {
var status int
bin, err := filepath.Abs("godog.test")
if err != nil {
return 1, err
}
if build.Default.GOOS == "windows" {
bin += ".exe"
}
if err = godog.Build(bin); err != nil {
return 1, err
}
defer os.Remove(bin)
cmd := exec.Command(bin, os.Args[1:]...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
cmd.Env = os.Environ()
if err = cmd.Start(); err != nil {
return status, err
}
if err = cmd.Wait(); err != nil {
if exiterr, ok := err.(*exec.ExitError); ok {
// The program has exited with an exit code != 0
status = 1
// This works on both Unix and Windows. Although package
// syscall is generally platform dependent, WaitStatus is
// defined for both Unix and Windows and in both cases has
// an ExitStatus() method with the same signature.
if st, ok := exiterr.Sys().(syscall.WaitStatus); ok {
status = st.ExitStatus()
}
return status, nil
}
return status, err
}
return status, nil
}
func main() {
var vers bool
var output string
rootCmd := internal.CreateRootCmd()
buildCmd := internal.CreateBuildCmd()
runCmd := internal.CreateRunCmd()
versionCmd := internal.CreateVersionCmd()
opt := godog.Options{Output: colors.Colored(os.Stdout)}
flagSet := godog.FlagSet(&opt)
flagSet.BoolVar(&vers, "version", false, "Show current version.")
flagSet.StringVar(&output, "o", "", "Build and output test runner executable to given target path.")
flagSet.StringVar(&output, "output", "", "Build and output test runner executable to given target path.")
rootCmd.AddCommand(&buildCmd, &runCmd, &versionCmd)
if err := flagSet.Parse(os.Args[1:]); err != nil {
fmt.Fprintln(os.Stderr, err)
if err := rootCmd.Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
if len(output) > 0 {
bin, err := filepath.Abs(output)
if err != nil {
fmt.Fprintln(os.Stderr, "could not locate absolute path for:", output, err)
os.Exit(1)
}
if err = godog.Build(bin); err != nil {
fmt.Fprintln(os.Stderr, "could not build binary at:", output, err)
os.Exit(1)
}
os.Exit(0)
}
if vers {
fmt.Fprintln(os.Stdout, "Godog version is:", godog.Version)
os.Exit(0) // should it be 0?
}
status, err := buildAndRun()
if err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
// it might be a case, that status might not be resolved
// in some OSes. this is attempt to parse it from stderr
if parsedStatus > status {
status = parsedStatus
}
os.Exit(status)
}

8
codecov.yml Обычный файл
Просмотреть файл

@ -0,0 +1,8 @@
coverage:
status:
project:
default:
threshold: 0.5%
patch:
default:
threshold: 0.5%

Просмотреть файл

@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
//go:build !windows
// +build !windows
package colors

Просмотреть файл

@ -2,6 +2,7 @@
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
//go:build windows
// +build windows
package colors

Просмотреть файл

@ -26,34 +26,43 @@ func colorize(s interface{}, c color) string {
return fmt.Sprintf("%s[%dm%v%s[0m", ansiEscape, c, s, ansiEscape)
}
// ColorFunc is a helper type to create colorized strings.
type ColorFunc func(interface{}) string
// Bold will accept a ColorFunc and return a new ColorFunc
// that will make the string bold.
func Bold(fn ColorFunc) ColorFunc {
return ColorFunc(func(input interface{}) string {
return strings.Replace(fn(input), ansiEscape+"[", ansiEscape+"[1;", 1)
})
}
// Green will accept an interface and return a colorized green string.
func Green(s interface{}) string {
return colorize(s, green)
}
// Red will accept an interface and return a colorized red string.
func Red(s interface{}) string {
return colorize(s, red)
}
// Cyan will accept an interface and return a colorized cyan string.
func Cyan(s interface{}) string {
return colorize(s, cyan)
}
// Black will accept an interface and return a colorized black string.
func Black(s interface{}) string {
return colorize(s, black)
}
// Yellow will accept an interface and return a colorized yellow string.
func Yellow(s interface{}) string {
return colorize(s, yellow)
}
// White will accept an interface and return a colorized white string.
func White(s interface{}) string {
return colorize(s, white)
}

Просмотреть файл

@ -11,6 +11,8 @@ type noColors struct {
lastbuf bytes.Buffer
}
// Uncolored will accept and io.Writer and return a
// new io.Writer that won't include colors.
func Uncolored(w io.Writer) io.Writer {
return &noColors{out: w}
}

45
example_subtests_test.go Обычный файл
Просмотреть файл

@ -0,0 +1,45 @@
package godog_test
import (
"testing"
"git.golang1.ru/softonik/godog"
)
func ExampleTestSuite_Run_subtests() {
var t *testing.T // Comes from your test function, e.g. func TestFeatures(t *testing.T).
suite := godog.TestSuite{
ScenarioInitializer: func(s *godog.ScenarioContext) {
// Add step definitions here.
},
Options: &godog.Options{
Format: "pretty",
Paths: []string{"features"},
TestingT: t, // Testing instance that will run subtests.
},
}
if suite.Run() != 0 {
t.Fatal("non-zero status returned, failed to run feature tests")
}
}
func TestFeatures(t *testing.T) {
suite := godog.TestSuite{
ScenarioInitializer: func(s *godog.ScenarioContext) {
godog.InitializeScenario(s)
// Add step definitions here.
},
Options: &godog.Options{
Format: "pretty",
Paths: []string{"features"},
TestingT: t, // Testing instance that will run subtests.
},
}
if suite.Run() != 0 {
t.Fatal("non-zero status returned, failed to run feature tests")
}
}

0
features/empty.feature Обычный файл
Просмотреть файл

Просмотреть файл

@ -16,12 +16,10 @@ Feature: suite events
When I run feature suite
Then these events had to be fired for a number of times:
| BeforeSuite | 1 |
| BeforeFeature | 1 |
| BeforeScenario | 1 |
| BeforeStep | 3 |
| AfterStep | 3 |
| AfterScenario | 1 |
| AfterFeature | 1 |
| AfterSuite | 1 |
Scenario: triggers appropriate events whole feature
@ -29,12 +27,10 @@ Feature: suite events
When I run feature suite
Then these events had to be fired for a number of times:
| BeforeSuite | 1 |
| BeforeFeature | 1 |
| BeforeScenario | 6 |
| BeforeStep | 19 |
| AfterStep | 19 |
| AfterScenario | 6 |
| AfterFeature | 1 |
| AfterSuite | 1 |
Scenario: triggers appropriate events for two feature files
@ -43,12 +39,10 @@ Feature: suite events
When I run feature suite
Then these events had to be fired for a number of times:
| BeforeSuite | 1 |
| BeforeFeature | 2 |
| BeforeScenario | 2 |
| BeforeStep | 7 |
| AfterStep | 7 |
| AfterScenario | 2 |
| AfterFeature | 2 |
| AfterSuite | 1 |
Scenario: should not trigger events on empty feature
@ -63,12 +57,10 @@ Feature: suite events
When I run feature suite
Then these events had to be fired for a number of times:
| BeforeSuite | 1 |
| BeforeFeature | 0 |
| BeforeScenario | 0 |
| BeforeStep | 0 |
| AfterStep | 0 |
| AfterScenario | 0 |
| AfterFeature | 0 |
| AfterSuite | 1 |
Scenario: should not trigger events on empty scenarios
@ -80,6 +72,9 @@ Feature: suite events
Scenario: two
Then passing step
And adding step state to context
And having correct context
And failing step
Scenario Outline: three
Then passing step
@ -91,10 +86,71 @@ Feature: suite events
When I run feature suite
Then these events had to be fired for a number of times:
| BeforeSuite | 1 |
| BeforeFeature | 1 |
| BeforeScenario | 2 |
| BeforeStep | 2 |
| AfterStep | 2 |
| BeforeStep | 5 |
| AfterStep | 5 |
| AfterScenario | 2 |
| AfterFeature | 1 |
| AfterSuite | 1 |
And the suite should have failed
Scenario: should add scenario hook errors to steps
Given a feature "normal.feature" file:
"""
Feature: scenario hook errors
Scenario: failing before and after scenario
Then adding step state to context
And passing step
Scenario: failing before scenario
Then adding step state to context
And passing step
Scenario: failing after scenario
Then adding step state to context
And passing step
"""
When I run feature suite with formatter "pretty"
Then the suite should have failed
And the rendered output will be as follows:
"""
Feature: scenario hook errors
Scenario: failing before and after scenario # normal.feature:3
Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func17
after scenario hook failed: failed in after scenario hook, step error: before scenario hook failed: failed in before scenario hook
And passing step # suite_context_test.go:0 -> InitializeScenario.func2
Scenario: failing before scenario # normal.feature:7
Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func17
before scenario hook failed: failed in before scenario hook
And passing step # suite_context_test.go:0 -> InitializeScenario.func2
Scenario: failing after scenario # normal.feature:11
Then adding step state to context # suite_context_test.go:0 -> InitializeScenario.func17
And passing step # suite_context_test.go:0 -> InitializeScenario.func2
after scenario hook failed: failed in after scenario hook
--- Failed steps:
Scenario: failing before and after scenario # normal.feature:3
Then adding step state to context # normal.feature:4
Error: after scenario hook failed: failed in after scenario hook, step error: before scenario hook failed: failed in before scenario hook
Scenario: failing before scenario # normal.feature:7
Then adding step state to context # normal.feature:8
Error: before scenario hook failed: failed in before scenario hook
Scenario: failing after scenario # normal.feature:11
And passing step # normal.feature:13
Error: after scenario hook failed: failed in after scenario hook
3 scenarios (3 failed)
6 steps (1 passed, 3 failed, 2 skipped)
0s
"""

Просмотреть файл

@ -323,7 +323,7 @@ Feature: cucumber json formatter
{
"keyword": "Given ",
"name": "passing step",
"line": 11,
"line": 7,
"match": {
"location": "suite_context.go:64"
},
@ -345,7 +345,7 @@ Feature: cucumber json formatter
{
"keyword": "Given ",
"name": "failing step",
"line": 12,
"line": 7,
"match": {
"location": "suite_context.go:47"
},

Просмотреть файл

@ -9,12 +9,11 @@ Feature: event stream formatter
Then the following events should be fired:
"""
TestRunStarted
TestSource
TestRunFinished
"""
Scenario: should process simple scenario
Given a feature path "features/load.feature:26"
Given a feature path "features/load.feature:27"
When I run feature suite with formatter "events"
Then the following events should be fired:
"""
@ -35,7 +34,7 @@ Feature: event stream formatter
"""
Scenario: should process outline scenario
Given a feature path "features/load.feature:34"
Given a feature path "features/load.feature:35"
When I run feature suite with formatter "events"
Then the following events should be fired:
"""

Просмотреть файл

@ -45,6 +45,7 @@ Feature: pretty formatter
No steps
0s
"""
Scenario: Support of Feature Plus Scenario Outline
Given a feature "features/simple.feature" file:
"""
@ -111,6 +112,7 @@ Feature: pretty formatter
No steps
0s
"""
Scenario: Support of Feature Plus Scenario With Steps
Given a feature "features/simple.feature" file:
"""
@ -146,6 +148,7 @@ Feature: pretty formatter
2 steps (1 passed, 1 failed)
0s
"""
Scenario: Support of Feature Plus Scenario Outline With Steps
Given a feature "features/simple.feature" file:
"""
@ -214,6 +217,7 @@ Feature: pretty formatter
No steps
0s
"""
Scenario: Support of Docstrings
Given a feature "features/simple.feature" file:
"""
@ -244,6 +248,7 @@ Feature: pretty formatter
1 steps (1 passed)
0s
"""
Scenario: Support of Undefined, Pending and Skipped status
Given a feature "features/simple.feature" file:
"""
@ -255,7 +260,13 @@ Feature: pretty formatter
Given passing step
And pending step
And undefined
And undefined doc string
\"\"\"
abc
\"\"\"
And undefined table
| a | b | c |
| 1 | 2 | 3 |
And passing step
"""
@ -265,24 +276,412 @@ Feature: pretty formatter
Feature: simple feature
simple feature description
Scenario: simple scenario # features/simple.feature:4
Given passing step # suite_context.go:0 -> SuiteContext.func2
And pending step # suite_context.go:0 -> SuiteContext.func1
Scenario: simple scenario # features/simple.feature:4
Given passing step # suite_context.go:0 -> SuiteContext.func2
And pending step # suite_context.go:0 -> SuiteContext.func1
TODO: write pending definition
And undefined
And passing step # suite_context.go:0 -> SuiteContext.func2
And undefined doc string
\"\"\"
abc
\"\"\"
And undefined table
| a | b | c |
| 1 | 2 | 3 |
And passing step # suite_context.go:0 -> SuiteContext.func2
1 scenarios (1 pending, 1 undefined)
4 steps (1 passed, 1 pending, 1 undefined, 1 skipped)
5 steps (1 passed, 1 pending, 2 undefined, 1 skipped)
0s
You can implement step definitions for undefined steps with these snippets:
func undefined() error {
func undefinedDocString(arg1 *godog.DocString) error {
return godog.ErrPending
}
func FeatureContext(s *godog.Suite) {
s.Step(`^undefined$`, undefined)
func undefinedTable(arg1 *godog.Table) error {
return godog.ErrPending
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^undefined doc string$`, undefinedDocString)
ctx.Step(`^undefined table$`, undefinedTable)
}
"""
# Ensure s will not break when injecting data from BeforeStep
Scenario: Support data injection in BeforeStep
Given a feature "features/inject.feature" file:
"""
Feature: inject long value
Scenario: test scenario
Given Ignore I save some value X under key Y
And I allow variable injection
When Ignore I use value {{Y}}
Then Ignore Godog rendering should not break
And Ignore test
| key | val |
| 1 | 2 |
| 3 | 4 |
And I disable variable injection
"""
When I run feature suite with formatter "pretty"
Then the rendered output will be as follows:
"""
Feature: inject long value
Scenario: test scenario # features/inject.feature:3
Given Ignore I save some value X under key Y # suite_context.go:0 -> SuiteContext.func12
And I allow variable injection # suite_context.go:0 -> *suiteContext
When Ignore I use value someverylonginjectionsoweacanbesureitsurpasstheinitiallongeststeplenghtanditwillhelptestsmethodsafety # suite_context.go:0 -> SuiteContext.func12
Then Ignore Godog rendering should not break # suite_context.go:0 -> SuiteContext.func12
And Ignore test # suite_context.go:0 -> SuiteContext.func12
| key | val |
| 1 | 2 |
| 3 | 4 |
And I disable variable injection # suite_context.go:0 -> *suiteContext
1 scenarios (1 passed)
6 steps (6 passed)
0s
"""
Scenario: Should scenarios identified with path:line and preserve the order.
Given a feature path "features/load.feature:6"
And a feature path "features/multistep.feature:6"
And a feature path "features/load.feature:27"
And a feature path "features/multistep.feature:23"
When I run feature suite with formatter "pretty"
Then the rendered output will be as follows:
"""
Feature: load features
In order to run features
As a test suite
I need to be able to load features
Scenario: load features within path # features/load.feature:6
Given a feature path "features" # suite_context_test.go:0 -> *godogFeaturesScenario
When I parse features # suite_context_test.go:0 -> *godogFeaturesScenario
Then I should have 14 feature files: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
features/background.feature
features/events.feature
features/formatter/cucumber.feature
features/formatter/events.feature
features/formatter/junit.feature
features/formatter/pretty.feature
features/lang.feature
features/load.feature
features/multistep.feature
features/outline.feature
features/run.feature
features/snippets.feature
features/tags.feature
features/testingt.feature
\"\"\"
Feature: run features with nested steps
In order to test multisteps
As a test suite
I need to be able to execute multisteps
Scenario: should run passing multistep successfully # features/multistep.feature:6
Given a feature "normal.feature" file: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
Feature: normal feature
Scenario: run passing multistep
Given passing step
Then passing multistep
\"\"\"
When I run feature suite # suite_context_test.go:0 -> *godogFeaturesScenario
Then the suite should have passed # suite_context_test.go:0 -> *godogFeaturesScenario
And the following steps should be passed: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
passing step
passing multistep
\"\"\"
Feature: load features
In order to run features
As a test suite
I need to be able to load features
Scenario: load a specific feature file # features/load.feature:27
Given a feature path "features/load.feature" # suite_context_test.go:0 -> *godogFeaturesScenario
When I parse features # suite_context_test.go:0 -> *godogFeaturesScenario
Then I should have 1 feature file: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
features/load.feature
\"\"\"
Feature: run features with nested steps
In order to test multisteps
As a test suite
I need to be able to execute multisteps
Scenario: should fail multistep # features/multistep.feature:23
Given a feature "failed.feature" file: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
Feature: failed feature
Scenario: run failing multistep
Given passing step
When failing multistep
Then I should have 1 scenario registered
\"\"\"
When I run feature suite # suite_context_test.go:0 -> *godogFeaturesScenario
Then the suite should have failed # suite_context_test.go:0 -> *godogFeaturesScenario
And the following step should be failed: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
failing multistep
\"\"\"
And the following steps should be skipped: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
I should have 1 scenario registered
\"\"\"
And the following steps should be passed: # suite_context_test.go:0 -> *godogFeaturesScenario
\"\"\"
passing step
\"\"\"
4 scenarios (4 passed)
16 steps (16 passed)
0s
"""
Scenario: Support of Feature Plus Rule
Given a feature "features/simple.feature" file:
"""
Feature: simple feature with a rule
simple feature description
Rule: simple rule
simple rule description
Example: simple scenario
simple scenario description
Given passing step
"""
When I run feature suite with formatter "pretty"
Then the rendered output will be as follows:
"""
Feature: simple feature with a rule
simple feature description
Example: simple scenario # features/simple.feature:5
Given passing step # suite_context.go:0 -> SuiteContext.func2
1 scenarios (1 passed)
1 steps (1 passed)
0s
"""
Scenario: Support of Feature Plus Rule with Background
Given a feature "features/simple.feature" file:
"""
Feature: simple feature with a rule with Background
simple feature description
Rule: simple rule
simple rule description
Background:
Given passing step
Example: simple scenario
simple scenario description
Given passing step
"""
When I run feature suite with formatter "pretty"
Then the rendered output will be as follows:
"""
Feature: simple feature with a rule with Background
simple feature description
Background:
Given passing step # suite_context.go:0 -> SuiteContext.func2
Example: simple scenario # features/simple.feature:7
Given passing step # suite_context.go:0 -> SuiteContext.func2
1 scenarios (1 passed)
2 steps (2 passed)
0s
"""
Scenario: Support of Feature Plus Rule with Scenario Outline
Given a feature "features/simple.feature" file:
"""
Feature: simple feature with a rule with Scenario Outline
simple feature description
Rule: simple rule
simple rule description
Scenario Outline: simple scenario
simple scenario description
Given <status> step
Examples: simple examples
| status |
| passing |
| failing |
"""
When I run feature suite with formatter "pretty"
Then the rendered output will be as follows:
"""
Feature: simple feature with a rule with Scenario Outline
simple feature description
Scenario Outline: simple scenario # features/simple.feature:5
Given <status> step # suite_context.go:0 -> SuiteContext.func2
Examples: simple examples
| status |
| passing |
| failing |
intentional failure
--- Failed steps:
Scenario Outline: simple scenario # features/simple.feature:5
Given failing step # features/simple.feature:8
Error: intentional failure
2 scenarios (1 passed, 1 failed)
2 steps (1 passed, 1 failed)
0s
"""
Scenario: Use 'given' keyword on a declared 'when' step
Given a feature "features/simple.feature" file:
"""
Feature: simple feature with a rule
simple feature description
Rule: simple rule
simple rule description
Example: simple scenario
simple scenario description
Given a when step
"""
When I run feature suite with formatter "pretty"
Then the rendered output will be as follows:
"""
Feature: simple feature with a rule
simple feature description
Example: simple scenario # features/simple.feature:5
Given a when step
1 scenarios (1 undefined)
1 steps (1 undefined)
0s
You can implement step definitions for undefined steps with these snippets:
func aWhenStep() error {
return godog.ErrPending
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^a when step$`, aWhenStep)
}
"""
Scenario: Use 'when' keyword on a declared 'then' step
Given a feature "features/simple.feature" file:
"""
Feature: simple feature with a rule
simple feature description
Rule: simple rule
simple rule description
Example: simple scenario
simple scenario description
When a then step
"""
When I run feature suite with formatter "pretty"
Then the rendered output will be as follows:
"""
Feature: simple feature with a rule
simple feature description
Example: simple scenario # features/simple.feature:5
When a then step
1 scenarios (1 undefined)
1 steps (1 undefined)
0s
You can implement step definitions for undefined steps with these snippets:
func aThenStep() error {
return godog.ErrPending
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^a then step$`, aThenStep)
}
"""
Scenario: Use 'then' keyword on a declared 'given' step
Given a feature "features/simple.feature" file:
"""
Feature: simple feature with a rule
simple feature description
Rule: simple rule
simple rule description
Example: simple scenario
simple scenario description
Then a given step
"""
When I run feature suite with formatter "pretty"
Then the rendered output will be as follows:
"""
Feature: simple feature with a rule
simple feature description
Example: simple scenario # features/simple.feature:5
Then a given step
1 scenarios (1 undefined)
1 steps (1 undefined)
0s
You can implement step definitions for undefined steps with these snippets:
func aGivenStep() error {
return godog.ErrPending
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^a given step$`, aGivenStep)
}
"""
Scenario: Match keyword functions correctly
Given a feature "features/simple.feature" file:
"""
Feature: simple feature with a rule
simple feature description
Rule: simple rule
simple rule description
Example: simple scenario
simple scenario description
Given a given step
When a when step
Then a then step
And a then step
"""
When I run feature suite with formatter "pretty"
Then the rendered output will be as follows:
"""
Feature: simple feature with a rule
simple feature description
Example: simple scenario # features/simple.feature:5
Given a given step # suite_context_test.go:0 -> InitializeScenario.func3
When a when step # suite_context_test.go:0 -> InitializeScenario.func4
Then a then step # suite_context_test.go:0 -> InitializeScenario.func5
And a then step # suite_context_test.go:0 -> InitializeScenario.func5
1 scenarios (1 passed)
4 steps (4 passed)
0s
"""

Просмотреть файл

@ -8,7 +8,7 @@ Savybė: užkrauti savybes
Scenarijus: savybių užkrovimas iš aplanko
Duota savybių aplankas "features"
Kai aš išskaitau savybes
Tada aš turėčiau turėti 13 savybių failus:
Tada aš turėčiau turėti 14 savybių failus:
"""
features/background.feature
features/events.feature
@ -23,4 +23,5 @@ Savybė: užkrauti savybes
features/run.feature
features/snippets.feature
features/tags.feature
features/testingt.feature
"""

Просмотреть файл

@ -6,7 +6,7 @@ Feature: load features
Scenario: load features within path
Given a feature path "features"
When I parse features
Then I should have 13 feature files:
Then I should have 14 feature files:
"""
features/background.feature
features/events.feature
@ -21,6 +21,7 @@ Feature: load features
features/run.feature
features/snippets.feature
features/tags.feature
features/testingt.feature
"""
Scenario: load a specific feature file

Просмотреть файл

@ -138,3 +138,63 @@ Feature: run features with nested steps
"""
I should have 1 scenario registered
"""
Scenario: context passed between steps
Given a feature "normal.feature" file:
"""
Feature: normal feature
Scenario: run passing multistep
Given I return a context from a step
Then I should see the context in the next step
"""
When I run feature suite
Then the suite should have passed
Scenario: context passed between steps
Given a feature "normal.feature" file:
"""
Feature: normal feature
Scenario: run passing multistep
Given I can see contexts passed in multisteps
"""
When I run feature suite
Then the suite should have passed
Scenario: should run passing multistep using keyword function successfully
Given a feature "normal.feature" file:
"""
Feature: normal feature
Scenario: run passing multistep
Given passing step
Then passing multistep using 'then' function
"""
When I run feature suite
Then the suite should have passed
And the following steps should be passed:
"""
passing step
passing multistep using 'then' function
"""
Scenario: should identify undefined multistep using keyword function
Given a feature "normal.feature" file:
"""
Feature: normal feature
Scenario: run passing multistep
Given passing step
Then undefined multistep using 'then' function
"""
When I run feature suite
Then the suite should have passed
And the following steps should be passed:
"""
passing step
"""
And the following step should be undefined:
"""
undefined multistep using 'then' function
"""

Просмотреть файл

@ -262,3 +262,16 @@ Feature: run features
another undefined step
"""
And the suite should have failed
Scenario: should be able to convert a Doc String to a `*godog.DocString` argument
Given call func(*godog.DocString) with:
"""
text
"""
Scenario: should be able to convert a Doc String to a `string` argument
Given call func(string) with:
"""
text
"""

Просмотреть файл

@ -28,9 +28,9 @@ Feature: undefined step snippets
return godog.ErrPending
}
func FeatureContext(s *godog.Suite) {
s.Step(`^I send "([^"]*)" request to "([^"]*)"$`, iSendRequestTo)
s.Step(`^the response code should be (\d+)$`, theResponseCodeShouldBe)
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^I send "([^"]*)" request to "([^"]*)"$`, iSendRequestTo)
ctx.Step(`^the response code should be (\d+)$`, theResponseCodeShouldBe)
}
"""
@ -44,11 +44,19 @@ Feature: undefined step snippets
| col1 | val1 |
| col2 | val2 |
Then the response code should be 200 and header "X-Powered-By" should be "godog"
And the response body should be:
\"\"\"
Hello World
\"\"\"
"""
When I run feature suite
Then the undefined step snippets should be:
"""
func iSendRequestToWith(arg1, arg2 string, arg3 *messages.PickleStepArgument_PickleTable) error {
func iSendRequestToWith(arg1, arg2 string, arg3 *godog.Table) error {
return godog.ErrPending
}
func theResponseBodyShouldBe(arg1 *godog.DocString) error {
return godog.ErrPending
}
@ -56,9 +64,10 @@ Feature: undefined step snippets
return godog.ErrPending
}
func FeatureContext(s *godog.Suite) {
s.Step(`^I send "([^"]*)" request to "([^"]*)" with:$`, iSendRequestToWith)
s.Step(`^the response code should be (\d+) and header "([^"]*)" should be "([^"]*)"$`, theResponseCodeShouldBeAndHeaderShouldBe)
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^I send "([^"]*)" request to "([^"]*)" with:$`, iSendRequestToWith)
ctx.Step(`^the response body should be:$`, theResponseBodyShouldBe)
ctx.Step(`^the response code should be (\d+) and header "([^"]*)" should be "([^"]*)"$`, theResponseCodeShouldBeAndHeaderShouldBe)
}
"""
@ -87,9 +96,9 @@ Feature: undefined step snippets
return godog.ErrPending
}
func FeatureContext(s *godog.Suite) {
s.Step(`^I pull from github\.com$`, iPullFromGithubcom)
s.Step(`^the project should be there$`, theProjectShouldBeThere)
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^I pull from github\.com$`, iPullFromGithubcom)
ctx.Step(`^the project should be there$`, theProjectShouldBeThere)
}
"""
@ -105,17 +114,17 @@ Feature: undefined step snippets
When I run feature suite
And the undefined step snippets should be:
"""
func thereIsAWhichCosts(arg1 string, arg2 int) error {
return godog.ErrPending
}
func iAddTheToTheBasket(arg1 string) error {
return godog.ErrPending
}
func FeatureContext(s *godog.Suite) {
s.Step(`^there is a "([^"]*)", which costs £(\d+)$`, thereIsAWhichCosts)
s.Step(`^I add the "([^"]*)" to the basket$`, iAddTheToTheBasket)
func thereIsAWhichCosts(arg1 string, arg2 int) error {
return godog.ErrPending
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^I add the "([^"]*)" to the basket$`, iAddTheToTheBasket)
ctx.Step(`^there is a "([^"]*)", which costs £(\d+)$`, thereIsAWhichCosts)
}
"""
@ -131,16 +140,56 @@ Feature: undefined step snippets
When I run feature suite
And the undefined step snippets should be:
"""
func whichCosts(arg1 string, arg2 int) error {
return godog.ErrPending
}
func godogs(arg1 int) error {
return godog.ErrPending
}
func FeatureContext(s *godog.Suite) {
s.Step(`^"([^"]*)", which costs £(\d+)$`, whichCosts)
s.Step(`^(\d+) godogs$`, godogs)
func whichCosts(arg1 string, arg2 int) error {
return godog.ErrPending
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^(\d+) godogs$`, godogs)
ctx.Step(`^"([^"]*)", which costs £(\d+)$`, whichCosts)
}
"""
Scenario: Для русских сценариев генерируются русские функции
Given a feature "undefined.feature" file:
"""
# language: ru
Функционал: суперфича
Сценарий: делает что-то полезное
Дано что-то
Когда я делаю ещё что-то
То получается ещё более что-то
"""
When I run feature suite
Then the following steps should be undefined:
"""
получается ещё более что-то
что-то
я делаю ещё что-то
"""
And the undefined step snippets should be:
"""
func получаетсяЕщёБолееЧтото() error {
return godog.ErrPending
}
func чтото() error {
return godog.ErrPending
}
func яДелаюЕщёЧтото() error {
return godog.ErrPending
}
func InitializeScenario(ctx *godog.ScenarioContext) {
ctx.Step(`^получается ещё более что-то$`, получаетсяЕщёБолееЧтото)
ctx.Step(`^что-то$`, чтото)
ctx.Step(`^я делаю ещё что-то$`, яДелаюЕщёЧтото)
}
"""

Просмотреть файл

@ -10,6 +10,7 @@ Feature: tag filters
Background:
Given passing step
And passing step without return
Scenario Outline: parse a scenario
Given a feature path "<path>"
@ -124,3 +125,75 @@ Feature: tag filters
"""
a feature path "four"
"""
Scenario: empty filter and scenarios with f-tag - are executed only
Given a feature "normal.feature" file:
"""
Feature: f-tagged
Scenario: one
Given a feature path "one"
Scenario: two
Given a feature path "two"
@f
Scenario: three
Given a feature path "three"
@f
Scenario: four
Given a feature path "four"
"""
When I run feature suite with tags ""
Then the suite should have passed
And I should have 2 scenario registered
And the following steps should be passed:
"""
a feature path "three"
a feature path "four"
"""
Scenario: two feature files and scenarios with f-tag - are executed only
Given a feature "normal.feature" file:
"""
Feature: f-tagged
Scenario: one
Given a feature path "one"
Scenario: two
Given a feature path "two"
@f
Scenario: three
Given a feature path "three"
@f
Scenario: four
Given a feature path "four"
"""
And a feature "another.feature" file:
"""
Feature: non-tagged
Scenario: five
Given a feature path "five"
Scenario: six
Given a feature path "six"
Scenario: seven
Given a feature path "seven"
Scenario: eight
Given a feature path "eight"
"""
When I run feature suite with tags ""
Then the suite should have passed
And I should have 2 scenario registered
And the following steps should be passed:
"""
a feature path "three"
a feature path "four"
"""

194
features/testingt.feature Обычный файл
Просмотреть файл

@ -0,0 +1,194 @@
Feature: providing testingT compatibility
In order to test application behavior using standard go assertion techniques
As a test suite
I need to be able to provide a testing.T compatible interface
Scenario Outline: should fail test with no message if <op> called on testing T
Given a feature "failed.feature" file:
"""
Feature: failed feature
Scenario: fail a scenario
Given passing step
When my step fails the test by calling <op> on testing T
"""
When I run feature suite
Then the suite should have failed
And the following steps should be passed:
"""
passing step
"""
And the following step should be failed:
"""
my step fails the test by calling <op> on testing T
"""
Examples:
| op |
| Fail |
| FailNow |
Scenario Outline: should fail test with message if <op> called on T
Given a feature "failed.feature" file:
"""
Feature: failed feature
Scenario: fail a scenario
Given passing step
When my step fails the test by calling <op> on testing T with message "an unformatted message"
"""
When I run feature suite
Then the suite should have failed
And the following steps should be passed:
"""
passing step
"""
And the following step should be failed:
"""
my step fails the test by calling <op> on testing T with message "an unformatted message"
"""
Examples:
| op |
| Error |
| Fatal |
Scenario Outline: should fail test with formatted message if <op> called on T
Given a feature "failed.feature" file:
"""
Feature: failed feature
Scenario: fail a scenario
Given passing step
When my step fails the test by calling <op> on testing T with message "a formatted message %s" and argument "arg1"
"""
When I run feature suite
Then the suite should have failed
And the following steps should be passed:
"""
passing step
"""
And the following step should be failed:
"""
my step fails the test by calling <op> on testing T with message "a formatted message %s" and argument "arg1"
"""
Examples:
| op |
| Errorf |
| Fatalf |
Scenario: should pass test when testify assertions pass
Given a feature "testify.feature" file:
"""
Feature: passed feature
Scenario: pass a scenario
Given passing step
When my step calls testify's assert.Equal with expected "exp" and actual "exp"
When my step calls testify's require.Equal with expected "exp" and actual "exp"
"""
When I run feature suite
Then the suite should have passed
And the following steps should be passed:
"""
passing step
my step calls testify's assert.Equal with expected "exp" and actual "exp"
my step calls testify's require.Equal with expected "exp" and actual "exp"
"""
Scenario: should fail test when testify assertions do not pass
Given a feature "testify.feature" file:
"""
Feature: failed feature
Scenario: fail a scenario
Given passing step
When my step calls testify's assert.Equal with expected "exp" and actual "not"
And my step calls testify's assert.Equal with expected "exp2" and actual "not"
"""
When I run feature suite
Then the suite should have failed
And the following steps should be passed:
"""
passing step
"""
And the following steps should be failed:
"""
my step calls testify's assert.Equal with expected "exp" and actual "not"
"""
And the following steps should be skipped:
"""
my step calls testify's assert.Equal with expected "exp2" and actual "not"
"""
Scenario: should fail test when multiple testify assertions are used in a step
Given a feature "testify.feature" file:
"""
Feature: failed feature
Scenario: fail a scenario
Given passing step
When my step calls testify's assert.Equal 3 times
"""
When I run feature suite
Then the suite should have failed
And the following steps should be passed:
"""
passing step
"""
And the following steps should be failed:
"""
my step calls testify's assert.Equal 3 times
"""
Scenario: should pass test when multiple testify assertions are used successfully in a step
Given a feature "testify.feature" file:
"""
Feature: passed feature
Scenario: pass a scenario
Given passing step
When my step calls testify's assert.Equal 3 times with match
"""
When I run feature suite
Then the suite should have passed
And the following steps should be passed:
"""
passing step
my step calls testify's assert.Equal 3 times with match
"""
Scenario Outline: should skip test when <op> is called on the testing.T
Given a feature "testify.feature" file:
"""
Feature: skipped feature
Scenario: skip a scenario
Given passing step
When my step skips the test by calling <op> on testing T
"""
When I run feature suite
Then the suite should have passed
And the following steps should be passed:
"""
passing step
"""
And the following steps should be skipped:
"""
my step skips the test by calling <op> on testing T
"""
Examples:
| op |
| Skip |
| SkipNow |
Scenario: should log when Logf/Log called on testing.T
When my step calls Logf on testing T with message "format this %s" and argument "formatparam1"
And my step calls Log on testing T with message "log this message"
Then the logged messages should include "format this formatparam1"
And the logged messages should include "log this message"
Scenario: should log when godog.Logf/Log called
When my step calls godog.Logf with message "format this %s" and argument "formatparam1"
And my step calls godog.Log with message "log this message"
Then the logged messages should include "format this formatparam1"
And the logged messages should include "log this message"

Просмотреть файл

@ -1,107 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="succeed" tests="78" skipped="0" failures="0" errors="0" time="0">
<testsuite name="JUnit XML formatter" tests="9" skipped="0" failures="0" errors="0" time="0">
<testcase name="Support of Feature Plus Scenario Node" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario Node With Tags" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario Outline" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario Outline With Tags" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario With Steps" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario Outline With Steps" status="passed" time="0"></testcase>
<testcase name="Support of Comments" status="passed" time="0"></testcase>
<testcase name="Support of Docstrings" status="passed" time="0"></testcase>
<testcase name="Support of Undefined, Pending and Skipped status" status="passed" time="0"></testcase>
</testsuite>
<testsuite name="cucumber json formatter" tests="9" skipped="0" failures="0" errors="0" time="0">
<testcase name="Support of Feature Plus Scenario Node" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario Node With Tags" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario Outline" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario Outline With Tags" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario With Steps" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario Outline With Steps" status="passed" time="0"></testcase>
<testcase name="Support of Comments" status="passed" time="0"></testcase>
<testcase name="Support of Docstrings" status="passed" time="0"></testcase>
<testcase name="Support of Undefined, Pending and Skipped status" status="passed" time="0"></testcase>
</testsuite>
<testsuite name="event stream formatter" tests="3" skipped="0" failures="0" errors="0" time="0">
<testcase name="should fire only suite events without any scenario" status="passed" time="0"></testcase>
<testcase name="should process simple scenario" status="passed" time="0"></testcase>
<testcase name="should process outline scenario" status="passed" time="0"></testcase>
</testsuite>
<testsuite name="load features" tests="6" skipped="0" failures="0" errors="0" time="0">
<testcase name="load features within path" status="passed" time="0"></testcase>
<testcase name="load a specific feature file" status="passed" time="0"></testcase>
<testcase name="loaded feature should have a number of scenarios #1" status="passed" time="0"></testcase>
<testcase name="loaded feature should have a number of scenarios #2" status="passed" time="0"></testcase>
<testcase name="loaded feature should have a number of scenarios #3" status="passed" time="0"></testcase>
<testcase name="load a number of feature files" status="passed" time="0"></testcase>
</testsuite>
<testsuite name="pretty formatter" tests="9" skipped="0" failures="0" errors="0" time="0">
<testcase name="Support of Feature Plus Scenario Node" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario Node With Tags" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario Outline" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario Outline With Tags" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario With Steps" status="passed" time="0"></testcase>
<testcase name="Support of Feature Plus Scenario Outline With Steps" status="passed" time="0"></testcase>
<testcase name="Support of Comments" status="passed" time="0"></testcase>
<testcase name="Support of Docstrings" status="passed" time="0"></testcase>
<testcase name="Support of Undefined, Pending and Skipped status" status="passed" time="0"></testcase>
</testsuite>
<testsuite name="run background" tests="3" skipped="0" failures="0" errors="0" time="0">
<testcase name="should run background steps" status="passed" time="0"></testcase>
<testcase name="should skip all consequent steps on failure" status="passed" time="0"></testcase>
<testcase name="should continue undefined steps" status="passed" time="0"></testcase>
</testsuite>
<testsuite name="run features" tests="11" skipped="0" failures="0" errors="0" time="0">
<testcase name="should run a normal feature" status="passed" time="0"></testcase>
<testcase name="should skip steps after failure" status="passed" time="0"></testcase>
<testcase name="should skip all scenarios if background fails" status="passed" time="0"></testcase>
<testcase name="should skip steps after undefined" status="passed" time="0"></testcase>
<testcase name="should match undefined steps in a row" status="passed" time="0"></testcase>
<testcase name="should skip steps on pending" status="passed" time="0"></testcase>
<testcase name="should handle pending step" status="passed" time="0"></testcase>
<testcase name="should mark undefined steps after pending" status="passed" time="0"></testcase>
<testcase name="should fail suite if undefined steps follow after the failure" status="passed" time="0"></testcase>
<testcase name="should fail suite and skip pending step after failed step" status="passed" time="0"></testcase>
<testcase name="should fail suite and skip next step after failed step" status="passed" time="0"></testcase>
</testsuite>
<testsuite name="run features with nested steps" tests="6" skipped="0" failures="0" errors="0" time="0">
<testcase name="should run passing multistep successfully" status="passed" time="0"></testcase>
<testcase name="should fail multistep" status="passed" time="0"></testcase>
<testcase name="should fail nested multistep" status="passed" time="0"></testcase>
<testcase name="should skip steps after undefined multistep" status="passed" time="0"></testcase>
<testcase name="should match undefined steps in a row" status="passed" time="0"></testcase>
<testcase name="should mark undefined steps after pending" status="passed" time="0"></testcase>
</testsuite>
<testsuite name="run outline" tests="6" skipped="0" failures="0" errors="0" time="0">
<testcase name="should run a normal outline" status="passed" time="0"></testcase>
<testcase name="should continue through examples on failure" status="passed" time="0"></testcase>
<testcase name="should skip examples on background failure" status="passed" time="0"></testcase>
<testcase name="should translate step table body" status="passed" time="0"></testcase>
<testcase name="should translate step doc string argument #1" status="passed" time="0"></testcase>
<testcase name="should translate step doc string argument #2" status="passed" time="0"></testcase>
</testsuite>
<testsuite name="suite events" tests="6" skipped="0" failures="0" errors="0" time="0">
<testcase name="triggers before scenario event" status="passed" time="0"></testcase>
<testcase name="triggers appropriate events for a single scenario" status="passed" time="0"></testcase>
<testcase name="triggers appropriate events whole feature" status="passed" time="0"></testcase>
<testcase name="triggers appropriate events for two feature files" status="passed" time="0"></testcase>
<testcase name="should not trigger events on empty feature" status="passed" time="0"></testcase>
<testcase name="should not trigger events on empty scenarios" status="passed" time="0"></testcase>
</testsuite>
<testsuite name="tag filters" tests="4" skipped="0" failures="0" errors="0" time="0">
<testcase name="should filter outline examples by tags" status="passed" time="0"></testcase>
<testcase name="should filter scenarios by X tag" status="passed" time="0"></testcase>
<testcase name="should filter scenarios by X tag not having Y" status="passed" time="0"></testcase>
<testcase name="should filter scenarios having Y and Z tags" status="passed" time="0"></testcase>
</testsuite>
<testsuite name="undefined step snippets" tests="5" skipped="0" failures="0" errors="0" time="0">
<testcase name="should generate snippets" status="passed" time="0"></testcase>
<testcase name="should generate snippets with more arguments" status="passed" time="0"></testcase>
<testcase name="should handle escaped symbols" status="passed" time="0"></testcase>
<testcase name="should handle string argument followed by comma" status="passed" time="0"></testcase>
<testcase name="should handle arguments in the beggining or end of the step" status="passed" time="0"></testcase>
</testsuite>
<testsuite name="užkrauti savybes" tests="1" skipped="0" failures="0" errors="0" time="0">
<testcase name="savybių užkrovimas iš aplanko" status="passed" time="0"></testcase>
</testsuite>
</testsuites>

Просмотреть файл

@ -1,10 +0,0 @@
...................................................................... 70
...................................................................... 140
...................................................................... 210
...................................................................... 280
....................... 303
78 scenarios (78 passed)
303 steps (303 passed)
0s

Просмотреть файл

@ -4,19 +4,23 @@ import (
"flag"
"fmt"
"io"
"math/rand"
"sort"
"strconv"
"strings"
"time"
"github.com/cucumber/godog/colors"
"git.golang1.ru/softonik/godog/colors"
"git.golang1.ru/softonik/godog/internal/utils"
)
// repeats a space n times
var s = utils.S
var descFeaturesArgument = "Optional feature(s) to run. Can be:\n" +
s(4) + "- dir " + colors.Yellow("(features/)") + "\n" +
s(4) + "- feature " + colors.Yellow("(*.feature)") + "\n" +
s(4) + "- scenario at specific line " + colors.Yellow("(*.feature:10)") + "\n" +
"If no feature paths are listed, suite tries " + colors.Yellow("features") + " path by default.\n"
"If no feature paths are listed, suite tries " + colors.Yellow("features") + " path by default.\n" +
"Multiple comma-separated values can be provided.\n"
var descConcurrencyOption = "Run the test suite with concurrency level:\n" +
s(4) + "- " + colors.Yellow(`= 1`) + ": supports all types of formats.\n" +
@ -35,6 +39,8 @@ var descRandomOption = "Randomly shuffle the scenario execution order.\n" +
// FlagSet allows to manage flags by external suite runner
// builds flag.FlagSet with godog flags binded
//
// Deprecated:
func FlagSet(opt *Options) *flag.FlagSet {
set := flag.NewFlagSet("godog", flag.ExitOnError)
BindFlags("", set, opt)
@ -45,11 +51,29 @@ func FlagSet(opt *Options) *flag.FlagSet {
// BindFlags binds godog flags to given flag set prefixed
// by given prefix, without overriding usage
func BindFlags(prefix string, set *flag.FlagSet, opt *Options) {
set.Usage = usage(set, set.Output())
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"
type fm struct {
name string
desc string
}
var fms []fm
for name, desc := range AvailableFormatters() {
fms = append(fms, fm{
name: name,
desc: desc,
})
}
sort.Slice(fms, func(i, j int) bool {
return fms[i].name < fms[j].name
})
for _, fm := range fms {
descFormatOption += s(4) + "- " + colors.Yellow(fm.name) + ": " + fm.desc + "\n"
}
descFormatOption = strings.TrimSpace(descFormatOption)
// override flag defaults if any corresponding properties were supplied on the incoming `opt`
@ -57,26 +81,32 @@ func BindFlags(prefix string, set *flag.FlagSet, opt *Options) {
if opt.Format != "" {
defFormatOption = opt.Format
}
defTagsOption := ""
if opt.Tags != "" {
defTagsOption = opt.Tags
}
defConcurrencyOption := 1
if opt.Concurrency != 0 {
defConcurrencyOption = opt.Concurrency
}
defShowStepDefinitions := false
if opt.ShowStepDefinitions {
defShowStepDefinitions = opt.ShowStepDefinitions
}
defStopOnFailure := false
if opt.StopOnFailure {
defStopOnFailure = opt.StopOnFailure
}
defStrict := false
if opt.Strict {
defStrict = opt.Strict
}
defNoColors := false
if opt.NoColors {
defNoColors = opt.NoColors
@ -91,9 +121,17 @@ func BindFlags(prefix string, set *flag.FlagSet, opt *Options) {
set.BoolVar(&opt.ShowStepDefinitions, prefix+"definitions", defShowStepDefinitions, "Print all available step definitions.")
set.BoolVar(&opt.ShowStepDefinitions, prefix+"d", defShowStepDefinitions, "Print all available step definitions.")
set.BoolVar(&opt.StopOnFailure, prefix+"stop-on-failure", defStopOnFailure, "Stop processing on first failed scenario.")
set.BoolVar(&opt.Strict, prefix+"strict", defStrict, "Fail suite when there are pending or undefined steps.")
set.BoolVar(&opt.Strict, prefix+"strict", defStrict, "Fail suite when there are pending or undefined or ambiguous steps.")
set.BoolVar(&opt.NoColors, prefix+"no-colors", defNoColors, "Disable ansi colors.")
set.Var(&randomSeed{&opt.Randomize}, prefix+"random", descRandomOption)
set.BoolVar(&opt.ShowHelp, "godog.help", false, "Show usage help.")
set.Func(prefix+"paths", descFeaturesArgument, func(paths string) error {
if paths != "" {
opt.Paths = strings.Split(paths, ",")
}
return nil
})
}
type flagged struct {
@ -170,15 +208,7 @@ func usage(set *flag.FlagSet, w io.Writer) func() {
// --- GENERAL ---
fmt.Fprintln(w, colors.Yellow("Usage:"))
fmt.Fprintf(w, s(2)+"godog [options] [<features>]\n\n")
// description
fmt.Fprintln(w, "Builds a test package and runs given feature files.")
fmt.Fprintf(w, "Command should be run from the directory of tested package and contain buildable go source.\n\n")
// --- ARGUMENTS ---
fmt.Fprintln(w, colors.Yellow("Arguments:"))
// --> features
fmt.Fprintln(w, opt("features", descFeaturesArgument))
fmt.Fprint(w, s(2)+"go test [options]\n\n")
// --- OPTIONS ---
fmt.Fprintln(w, colors.Yellow("Options:"))
@ -194,12 +224,6 @@ type randomSeed struct {
ref *int64
}
// Choose randomly assigns a convenient pseudo-random seed value.
// The resulting seed will be between `1-99999` for later ease of specification.
func makeRandomSeed() int64 {
return rand.New(rand.NewSource(time.Now().UTC().UnixNano())).Int63n(99998) + 1
}
func (rs *randomSeed) Set(s string) error {
if s == "true" {
*rs.ref = makeRandomSeed()

Просмотреть файл

@ -7,7 +7,8 @@ import (
"strings"
"testing"
"github.com/cucumber/godog/colors"
"git.golang1.ru/softonik/godog/colors"
"git.golang1.ru/softonik/godog/internal/formatters"
)
func TestFlagsShouldRandomizeAndGenerateSeed(t *testing.T) {
@ -61,7 +62,7 @@ func TestFlagsUsageShouldIncludeFormatDescriptons(t *testing.T) {
output := colors.Uncolored(&buf)
// register some custom formatter
Format("custom", "custom format description", junitFunc)
Format("custom", "custom format description", formatters.JUnitFormatterFunc)
var opt Options
flags := FlagSet(&opt)
@ -120,7 +121,9 @@ func TestBindFlagsShouldRespectOptDefaults(t *testing.T) {
Randomize: int64(7),
}
BindFlags("optDefaults.", flag.CommandLine, &opts)
flagSet := flag.FlagSet{}
BindFlags("optDefaults.", &flagSet, &opts)
if opts.Format != "progress" {
t.Fatalf("expected Format: progress, but it was: %s", opts.Format)

33
flags_v0110.go Обычный файл
Просмотреть файл

@ -0,0 +1,33 @@
package godog
import (
"errors"
"flag"
"math/rand"
"time"
"github.com/spf13/pflag"
"git.golang1.ru/softonik/godog/internal/flags"
)
// Choose randomly assigns a convenient pseudo-random seed value.
// The resulting seed will be between `1-99999` for later ease of specification.
func makeRandomSeed() int64 {
return rand.New(rand.NewSource(time.Now().UTC().UnixNano())).Int63n(99998) + 1
}
func flagSet(opt *Options) *pflag.FlagSet {
set := pflag.NewFlagSet("godog", pflag.ExitOnError)
flags.BindRunCmdFlags("", set, opt)
pflag.ErrHelp = errors.New("godog: help requested")
return set
}
// BindCommandLineFlags binds godog flags to given flag set prefixed
// by given prefix, without overriding usage
func BindCommandLineFlags(prefix string, opts *Options) {
flagSet := pflag.CommandLine
flags.BindRunCmdFlags(prefix, flagSet, opts)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
}

23
flags_v0110_test.go Обычный файл
Просмотреть файл

@ -0,0 +1,23 @@
package godog
import (
"testing"
"git.golang1.ru/softonik/godog/internal/flags"
"github.com/stretchr/testify/assert"
)
func Test_BindFlagsShouldRespectFlagDefaults(t *testing.T) {
opts := flags.Options{}
BindCommandLineFlags("flagDefaults.", &opts)
assert.Equal(t, "pretty", opts.Format)
assert.Equal(t, "", opts.Tags)
assert.Equal(t, 1, opts.Concurrency)
assert.False(t, opts.ShowStepDefinitions)
assert.False(t, opts.StopOnFailure)
assert.False(t, opts.Strict)
assert.False(t, opts.NoColors)
assert.Equal(t, int64(0), opts.Randomize)
}

562
fmt.go
Просмотреть файл

@ -1,70 +1,23 @@
package godog
import (
"bytes"
"fmt"
"io"
"os"
"reflect"
"regexp"
"strconv"
"strings"
"sync"
"text/template"
"time"
"unicode"
"unicode/utf8"
"github.com/cucumber/godog/colors"
"github.com/cucumber/messages-go/v9"
"git.golang1.ru/softonik/godog/colors"
"git.golang1.ru/softonik/godog/formatters"
internal_fmt "git.golang1.ru/softonik/godog/internal/formatters"
"git.golang1.ru/softonik/godog/internal/models"
"git.golang1.ru/softonik/godog/internal/storage"
)
// some snippet formatting regexps
var snippetExprCleanup = regexp.MustCompile("([\\/\\[\\]\\(\\)\\\\^\\$\\.\\|\\?\\*\\+\\'])")
var snippetExprQuoted = regexp.MustCompile("(\\W|^)\"(?:[^\"]*)\"(\\W|$)")
var snippetMethodName = regexp.MustCompile("[^a-zA-Z\\_\\ ]")
var snippetNumbers = regexp.MustCompile("(\\d+)")
var snippetHelperFuncs = template.FuncMap{
"backticked": func(s string) string {
return "`" + s + "`"
},
}
var undefinedSnippetsTpl = template.Must(template.New("snippets").Funcs(snippetHelperFuncs).Parse(`
{{ range . }}func {{ .Method }}({{ .Args }}) error {
return godog.ErrPending
}
{{end}}func FeatureContext(s *godog.Suite) { {{ range . }}
s.Step({{ backticked .Expr }}, {{ .Method }}){{end}}
}
`))
type undefinedSnippet struct {
Method string
Expr string
argument *messages.PickleStepArgument
}
type registeredFormatter struct {
name string
fmt FormatterFunc
description string
}
var formatters []*registeredFormatter
// FindFmt searches available formatters registered
// and returns FormaterFunc matched by given
// format name or nil otherwise
func FindFmt(name string) FormatterFunc {
for _, el := range formatters {
if el.name == name {
return el.fmt
}
}
return nil
return formatters.FindFmt(name)
}
// Format registers a feature suite output
@ -72,22 +25,14 @@ func FindFmt(name string) FormatterFunc {
// FormatterFunc constructor function, to initialize
// formatter with the output recorder.
func Format(name, description string, f FormatterFunc) {
formatters = append(formatters, &registeredFormatter{
name: name,
fmt: f,
description: description,
})
formatters.Format(name, description, f)
}
// AvailableFormatters gives a map of all
// formatters registered with their name as key
// and description as value
func AvailableFormatters() map[string]string {
fmts := make(map[string]string, len(formatters))
for _, f := range formatters {
fmts[f.name] = f.description
}
return fmts
return formatters.AvailableFormatters()
}
// Formatter is an interface for feature runner
@ -97,462 +42,83 @@ func AvailableFormatters() map[string]string {
// suite results in different ways. These new
// formatters needs to be registered with a
// godog.Format function call
type Formatter interface {
Feature(*messages.GherkinDocument, string, []byte)
Pickle(*messages.Pickle)
Defined(*messages.Pickle, *messages.Pickle_PickleStep, *StepDefinition)
Failed(*messages.Pickle, *messages.Pickle_PickleStep, *StepDefinition, error)
Passed(*messages.Pickle, *messages.Pickle_PickleStep, *StepDefinition)
Skipped(*messages.Pickle, *messages.Pickle_PickleStep, *StepDefinition)
Undefined(*messages.Pickle, *messages.Pickle_PickleStep, *StepDefinition)
Pending(*messages.Pickle, *messages.Pickle_PickleStep, *StepDefinition)
Summary()
}
type Formatter = formatters.Formatter
// ConcurrentFormatter is an interface for a Concurrent
// version of the Formatter interface.
type ConcurrentFormatter interface {
Formatter
Copy(ConcurrentFormatter)
Sync(ConcurrentFormatter)
type storageFormatter interface {
SetStorage(*storage.Storage)
}
// FormatterFunc builds a formatter with given
// suite name and io.Writer to record output
type FormatterFunc func(string, io.Writer) Formatter
type FormatterFunc = formatters.FormatterFunc
type stepResultStatus int
const (
passed stepResultStatus = iota
failed
skipped
undefined
pending
)
func (st stepResultStatus) clr() colors.ColorFunc {
switch st {
case passed:
return green
case failed:
return red
case skipped:
return cyan
default:
return yellow
}
}
func (st stepResultStatus) String() string {
switch st {
case passed:
return "passed"
case failed:
return "failed"
case skipped:
return "skipped"
case undefined:
return "undefined"
case pending:
return "pending"
default:
return "unknown"
}
}
type stepResult struct {
status stepResultStatus
time time.Time
err error
owner *messages.Pickle
step *messages.Pickle_PickleStep
def *StepDefinition
}
func newStepResult(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) *stepResult {
return &stepResult{time: timeNowFunc(), owner: pickle, step: step, def: match}
}
func newBaseFmt(suite string, out io.Writer) *basefmt {
return &basefmt{
suiteName: suite,
started: timeNowFunc(),
indent: 2,
out: out,
lock: new(sync.Mutex),
}
}
type basefmt struct {
suiteName string
out io.Writer
owner interface{}
indent int
started time.Time
features []*feature
lock *sync.Mutex
}
func (f *basefmt) lastFeature() *feature {
return f.features[len(f.features)-1]
}
func (f *basefmt) lastStepResult() *stepResult {
return f.lastFeature().lastStepResult()
}
func (f *basefmt) findScenario(scenarioAstID string) *messages.GherkinDocument_Feature_Scenario {
for _, ft := range f.features {
if sc := ft.findScenario(scenarioAstID); sc != nil {
return sc
func printStepDefinitions(steps []*models.StepDefinition, w io.Writer) {
var longest int
for _, def := range steps {
n := utf8.RuneCountInString(def.Expr.String())
if longest < n {
longest = n
}
}
panic("Couldn't find scenario for AST ID: " + scenarioAstID)
}
func (f *basefmt) findBackground(scenarioAstID string) *messages.GherkinDocument_Feature_Background {
for _, ft := range f.features {
if bg := ft.findBackground(scenarioAstID); bg != nil {
return bg
}
for _, def := range steps {
n := utf8.RuneCountInString(def.Expr.String())
location := internal_fmt.DefinitionID(def)
spaces := strings.Repeat(" ", longest-n)
fmt.Fprintln(w,
colors.Yellow(def.Expr.String())+spaces,
colors.Bold(colors.Black)("# "+location))
}
return nil
}
func (f *basefmt) findExample(exampleAstID string) (*messages.GherkinDocument_Feature_Scenario_Examples, *messages.GherkinDocument_Feature_TableRow) {
for _, ft := range f.features {
if es, rs := ft.findExample(exampleAstID); es != nil && rs != nil {
return es, rs
}
}
return nil, nil
}
func (f *basefmt) findStep(stepAstID string) *messages.GherkinDocument_Feature_Step {
for _, ft := range f.features {
if st := ft.findStep(stepAstID); st != nil {
return st
}
}
panic("Couldn't find step for AST ID: " + stepAstID)
}
func (f *basefmt) Pickle(p *messages.Pickle) {
f.lock.Lock()
defer f.lock.Unlock()
feature := f.features[len(f.features)-1]
feature.pickleResults = append(feature.pickleResults, &pickleResult{Name: p.Name, time: timeNowFunc()})
}
func (f *basefmt) Defined(*messages.Pickle, *messages.Pickle_PickleStep, *StepDefinition) {}
func (f *basefmt) Feature(ft *messages.GherkinDocument, p string, c []byte) {
f.lock.Lock()
defer f.lock.Unlock()
f.features = append(f.features, &feature{Path: p, GherkinDocument: ft, time: timeNowFunc()})
}
func (f *basefmt) Passed(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.lock.Lock()
defer f.lock.Unlock()
s := newStepResult(pickle, step, match)
s.status = passed
f.lastFeature().appendStepResult(s)
}
func (f *basefmt) Skipped(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.lock.Lock()
defer f.lock.Unlock()
s := newStepResult(pickle, step, match)
s.status = skipped
f.lastFeature().appendStepResult(s)
}
func (f *basefmt) Undefined(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.lock.Lock()
defer f.lock.Unlock()
s := newStepResult(pickle, step, match)
s.status = undefined
f.lastFeature().appendStepResult(s)
}
func (f *basefmt) Failed(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition, err error) {
f.lock.Lock()
defer f.lock.Unlock()
s := newStepResult(pickle, step, match)
s.status = failed
s.err = err
f.lastFeature().appendStepResult(s)
}
func (f *basefmt) Pending(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.lock.Lock()
defer f.lock.Unlock()
s := newStepResult(pickle, step, match)
s.status = pending
f.lastFeature().appendStepResult(s)
}
func (f *basefmt) Summary() {
var totalSc, passedSc, undefinedSc int
var totalSt, passedSt, failedSt, skippedSt, pendingSt, undefinedSt int
for _, feat := range f.features {
for _, pr := range feat.pickleResults {
var prStatus stepResultStatus
totalSc++
if len(pr.stepResults) == 0 {
prStatus = undefined
}
for _, sr := range pr.stepResults {
totalSt++
switch sr.status {
case passed:
prStatus = passed
passedSt++
case failed:
prStatus = failed
failedSt++
case skipped:
skippedSt++
case undefined:
prStatus = undefined
undefinedSt++
case pending:
prStatus = pending
pendingSt++
}
}
if prStatus == passed {
passedSc++
} else if prStatus == undefined {
undefinedSc++
}
}
}
var steps, parts, scenarios []string
if passedSt > 0 {
steps = append(steps, green(fmt.Sprintf("%d passed", passedSt)))
}
if failedSt > 0 {
parts = append(parts, red(fmt.Sprintf("%d failed", failedSt)))
steps = append(steps, red(fmt.Sprintf("%d failed", failedSt)))
}
if pendingSt > 0 {
parts = append(parts, yellow(fmt.Sprintf("%d pending", pendingSt)))
steps = append(steps, yellow(fmt.Sprintf("%d pending", pendingSt)))
}
if undefinedSt > 0 {
parts = append(parts, yellow(fmt.Sprintf("%d undefined", undefinedSc)))
steps = append(steps, yellow(fmt.Sprintf("%d undefined", undefinedSt)))
} else if undefinedSc > 0 {
// there may be some scenarios without steps
parts = append(parts, yellow(fmt.Sprintf("%d undefined", undefinedSc)))
}
if skippedSt > 0 {
steps = append(steps, cyan(fmt.Sprintf("%d skipped", skippedSt)))
}
if passedSc > 0 {
scenarios = append(scenarios, green(fmt.Sprintf("%d passed", passedSc)))
}
scenarios = append(scenarios, parts...)
elapsed := timeNowFunc().Sub(f.started)
fmt.Fprintln(f.out, "")
if totalSc == 0 {
fmt.Fprintln(f.out, "No scenarios")
} else {
fmt.Fprintln(f.out, fmt.Sprintf("%d scenarios (%s)", totalSc, strings.Join(scenarios, ", ")))
}
if totalSt == 0 {
fmt.Fprintln(f.out, "No steps")
} else {
fmt.Fprintln(f.out, fmt.Sprintf("%d steps (%s)", totalSt, strings.Join(steps, ", ")))
}
elapsedString := elapsed.String()
if elapsed.Nanoseconds() == 0 {
// go 1.5 and 1.6 prints 0 instead of 0s, if duration is zero.
elapsedString = "0s"
}
fmt.Fprintln(f.out, elapsedString)
// prints used randomization seed
seed, err := strconv.ParseInt(os.Getenv("GODOG_SEED"), 10, 64)
if err == nil && seed != 0 {
fmt.Fprintln(f.out, "")
fmt.Fprintln(f.out, "Randomized with seed:", colors.Yellow(seed))
}
if text := f.snippets(); text != "" {
fmt.Fprintln(f.out, "")
fmt.Fprintln(f.out, yellow("You can implement step definitions for undefined steps with these snippets:"))
fmt.Fprintln(f.out, yellow(text))
if len(steps) == 0 {
fmt.Fprintln(w, "there were no contexts registered, could not find any step definition..")
}
}
func (f *basefmt) Sync(cf ConcurrentFormatter) {
if source, ok := cf.(*basefmt); ok {
f.lock = source.lock
}
// NewBaseFmt creates a new base formatter.
func NewBaseFmt(suite string, out io.Writer) *BaseFmt {
return internal_fmt.NewBase(suite, out)
}
func (f *basefmt) Copy(cf ConcurrentFormatter) {
if source, ok := cf.(*basefmt); ok {
for _, v := range source.features {
f.features = append(f.features, v)
}
}
// NewProgressFmt creates a new progress formatter.
func NewProgressFmt(suite string, out io.Writer) *ProgressFmt {
return internal_fmt.NewProgress(suite, out)
}
func (s *undefinedSnippet) Args() (ret string) {
var (
args []string
pos int
breakLoop bool
)
for !breakLoop {
part := s.Expr[pos:]
ipos := strings.Index(part, "(\\d+)")
spos := strings.Index(part, "\"([^\"]*)\"")
switch {
case spos == -1 && ipos == -1:
breakLoop = true
case spos == -1:
pos += ipos + len("(\\d+)")
args = append(args, reflect.Int.String())
case ipos == -1:
pos += spos + len("\"([^\"]*)\"")
args = append(args, reflect.String.String())
case ipos < spos:
pos += ipos + len("(\\d+)")
args = append(args, reflect.Int.String())
case spos < ipos:
pos += spos + len("\"([^\"]*)\"")
args = append(args, reflect.String.String())
}
}
if s.argument != nil {
if s.argument.GetDocString() != nil {
args = append(args, "*messages.PickleStepArgument_PickleDocString")
}
if s.argument.GetDataTable() != nil {
args = append(args, "*messages.PickleStepArgument_PickleTable")
}
}
var last string
for i, arg := range args {
if last == "" || last == arg {
ret += fmt.Sprintf("arg%d, ", i+1)
} else {
ret = strings.TrimRight(ret, ", ") + fmt.Sprintf(" %s, arg%d, ", last, i+1)
}
last = arg
}
return strings.TrimSpace(strings.TrimRight(ret, ", ") + " " + last)
// NewPrettyFmt creates a new pretty formatter.
func NewPrettyFmt(suite string, out io.Writer) *PrettyFmt {
return &PrettyFmt{Base: NewBaseFmt(suite, out)}
}
func (f *basefmt) findStepResults(status stepResultStatus) (res []*stepResult) {
for _, feat := range f.features {
for _, pr := range feat.pickleResults {
for _, sr := range pr.stepResults {
if sr.status == status {
res = append(res, sr)
}
}
}
}
return
// NewEventsFmt creates a new event streaming formatter.
func NewEventsFmt(suite string, out io.Writer) *EventsFmt {
return &EventsFmt{Base: NewBaseFmt(suite, out)}
}
func (f *basefmt) snippets() string {
undefinedStepResults := f.findStepResults(undefined)
if len(undefinedStepResults) == 0 {
return ""
}
var index int
var snips []*undefinedSnippet
// build snippets
for _, u := range undefinedStepResults {
steps := []string{u.step.Text}
arg := u.step.Argument
if u.def != nil {
steps = u.def.undefined
arg = nil
}
for _, step := range steps {
expr := snippetExprCleanup.ReplaceAllString(step, "\\$1")
expr = snippetNumbers.ReplaceAllString(expr, "(\\d+)")
expr = snippetExprQuoted.ReplaceAllString(expr, "$1\"([^\"]*)\"$2")
expr = "^" + strings.TrimSpace(expr) + "$"
name := snippetNumbers.ReplaceAllString(step, " ")
name = snippetExprQuoted.ReplaceAllString(name, " ")
name = strings.TrimSpace(snippetMethodName.ReplaceAllString(name, ""))
var words []string
for i, w := range strings.Split(name, " ") {
switch {
case i != 0:
w = strings.Title(w)
case len(w) > 0:
w = string(unicode.ToLower(rune(w[0]))) + w[1:]
}
words = append(words, w)
}
name = strings.Join(words, "")
if len(name) == 0 {
index++
name = fmt.Sprintf("StepDefinitioninition%d", index)
}
var found bool
for _, snip := range snips {
if snip.Expr == expr {
found = true
break
}
}
if !found {
snips = append(snips, &undefinedSnippet{Method: name, Expr: expr, argument: arg})
}
}
}
var buf bytes.Buffer
if err := undefinedSnippetsTpl.Execute(&buf, snips); err != nil {
panic(err)
}
// there may be trailing spaces
return strings.Replace(buf.String(), " \n", "\n", -1)
// NewCukeFmt creates a new Cucumber JSON formatter.
func NewCukeFmt(suite string, out io.Writer) *CukeFmt {
return &CukeFmt{Base: NewBaseFmt(suite, out)}
}
func isLastStep(pickle *messages.Pickle, step *messages.Pickle_PickleStep) bool {
return pickle.Steps[len(pickle.Steps)-1].Id == step.Id
// NewJUnitFmt creates a new JUnit formatter.
func NewJUnitFmt(suite string, out io.Writer) *JUnitFmt {
return &JUnitFmt{Base: NewBaseFmt(suite, out)}
}
// BaseFmt exports Base formatter.
type BaseFmt = internal_fmt.Base
// ProgressFmt exports Progress formatter.
type ProgressFmt = internal_fmt.Progress
// PrettyFmt exports Pretty formatter.
type PrettyFmt = internal_fmt.Pretty
// EventsFmt exports Events formatter.
type EventsFmt = internal_fmt.Events
// CukeFmt exports Cucumber JSON formatter.
type CukeFmt = internal_fmt.Cuke
// JUnitFmt exports JUnit formatter.
type JUnitFmt = internal_fmt.JUnit

Просмотреть файл

@ -1,310 +0,0 @@
package godog
/*
The specification for the formatting originated from https://www.relishapp.com/cucumber/cucumber/docs/formatters/json-output-formatter.
I found that documentation was misleading or out dated. To validate formatting I create a ruby cucumber test harness and ran the
same feature files through godog and the ruby cucumber.
The docstrings in the cucumber.feature represent the cucumber output for those same feature definitions.
I did note that comments in ruby could be at just about any level in particular Feature, Scenario and Step. In godog I
could only find comments under the Feature data structure.
*/
import (
"encoding/json"
"fmt"
"io"
"strings"
"time"
"github.com/cucumber/messages-go/v9"
)
func init() {
Format("cucumber", "Produces cucumber JSON format output.", cucumberFunc)
}
func cucumberFunc(suite string, out io.Writer) Formatter {
return &cukefmt{basefmt: newBaseFmt(suite, out)}
}
// Replace spaces with - This function is used to create the "id" fields of the cucumber output.
func makeID(name string) string {
return strings.Replace(strings.ToLower(name), " ", "-", -1)
}
// The sequence of type structs are used to marshall the json object.
type cukeComment struct {
Value string `json:"value"`
Line int `json:"line"`
}
type cukeDocstring struct {
Value string `json:"value"`
ContentType string `json:"content_type"`
Line int `json:"line"`
}
type cukeTag struct {
Name string `json:"name"`
Line int `json:"line"`
}
type cukeResult struct {
Status string `json:"status"`
Error string `json:"error_message,omitempty"`
Duration *int `json:"duration,omitempty"`
}
type cukeMatch struct {
Location string `json:"location"`
}
type cukeStep struct {
Keyword string `json:"keyword"`
Name string `json:"name"`
Line int `json:"line"`
Docstring *cukeDocstring `json:"doc_string,omitempty"`
Match cukeMatch `json:"match"`
Result cukeResult `json:"result"`
DataTable []*cukeDataTableRow `json:"rows,omitempty"`
}
type cukeDataTableRow struct {
Cells []string `json:"cells"`
}
type cukeElement struct {
ID string `json:"id"`
Keyword string `json:"keyword"`
Name string `json:"name"`
Description string `json:"description"`
Line int `json:"line"`
Type string `json:"type"`
Tags []cukeTag `json:"tags,omitempty"`
Steps []cukeStep `json:"steps,omitempty"`
}
type cukeFeatureJSON struct {
URI string `json:"uri"`
ID string `json:"id"`
Keyword string `json:"keyword"`
Name string `json:"name"`
Description string `json:"description"`
Line int `json:"line"`
Comments []cukeComment `json:"comments,omitempty"`
Tags []cukeTag `json:"tags,omitempty"`
Elements []cukeElement `json:"elements,omitempty"`
}
type cukefmt struct {
*basefmt
// currently running feature path, to be part of id.
// this is sadly not passed by gherkin nodes.
// it restricts this formatter to run only in synchronous single
// threaded execution. Unless running a copy of formatter for each feature
path string
status stepResultStatus // last step status, before skipped
ID string // current test id.
results []cukeFeatureJSON // structure that represent cuke results
curStep *cukeStep // track the current step
curElement *cukeElement // track the current element
curFeature *cukeFeatureJSON // track the current feature
curOutline cukeElement // Each example show up as an outline element but the outline is parsed only once
// so I need to keep track of the current outline
curRow int // current row of the example table as it is being processed.
curExampleTags []cukeTag // temporary storage for tags associate with the current example table.
startTime time.Time // used to time duration of the step execution
curExampleName string // Due to the fact that examples are parsed once and then iterated over for each result then we need to keep track
// of the example name inorder to build id fields.
}
func (f *cukefmt) Pickle(pickle *messages.Pickle) {
f.basefmt.Pickle(pickle)
scenario := f.findScenario(pickle.AstNodeIds[0])
f.curFeature.Elements = append(f.curFeature.Elements, cukeElement{})
f.curElement = &f.curFeature.Elements[len(f.curFeature.Elements)-1]
f.curElement.Name = pickle.Name
f.curElement.Line = int(scenario.Location.Line)
f.curElement.Description = scenario.Description
f.curElement.Keyword = scenario.Keyword
f.curElement.ID = f.curFeature.ID + ";" + makeID(pickle.Name)
f.curElement.Type = "scenario"
f.curElement.Tags = make([]cukeTag, len(scenario.Tags)+len(f.curFeature.Tags))
if len(f.curElement.Tags) > 0 {
// apply feature level tags
copy(f.curElement.Tags, f.curFeature.Tags)
// apply scenario level tags.
for idx, element := range scenario.Tags {
f.curElement.Tags[idx+len(f.curFeature.Tags)].Line = int(element.Location.Line)
f.curElement.Tags[idx+len(f.curFeature.Tags)].Name = element.Name
}
}
if len(pickle.AstNodeIds) == 1 {
return
}
example, _ := f.findExample(pickle.AstNodeIds[1])
// apply example level tags.
for _, tag := range example.Tags {
tag := cukeTag{Line: int(tag.Location.Line), Name: tag.Name}
f.curElement.Tags = append(f.curElement.Tags, tag)
}
examples := scenario.GetExamples()
if len(examples) > 0 {
rowID := pickle.AstNodeIds[1]
for _, example := range examples {
for idx, row := range example.TableBody {
if rowID == row.Id {
f.curElement.ID += fmt.Sprintf(";%s;%d", makeID(example.Name), idx+2)
f.curElement.Line = int(row.Location.Line)
}
}
}
}
}
func (f *cukefmt) Feature(gd *messages.GherkinDocument, p string, c []byte) {
f.basefmt.Feature(gd, p, c)
f.path = p
f.ID = makeID(gd.Feature.Name)
f.results = append(f.results, cukeFeatureJSON{})
f.curFeature = &f.results[len(f.results)-1]
f.curFeature.URI = p
f.curFeature.Name = gd.Feature.Name
f.curFeature.Keyword = gd.Feature.Keyword
f.curFeature.Line = int(gd.Feature.Location.Line)
f.curFeature.Description = gd.Feature.Description
f.curFeature.ID = f.ID
f.curFeature.Tags = make([]cukeTag, len(gd.Feature.Tags))
for idx, element := range gd.Feature.Tags {
f.curFeature.Tags[idx].Line = int(element.Location.Line)
f.curFeature.Tags[idx].Name = element.Name
}
f.curFeature.Comments = make([]cukeComment, len(gd.Comments))
for idx, comment := range gd.Comments {
f.curFeature.Comments[idx].Value = strings.TrimSpace(comment.Text)
f.curFeature.Comments[idx].Line = int(comment.Location.Line)
}
}
func (f *cukefmt) Summary() {
dat, err := json.MarshalIndent(f.results, "", " ")
if err != nil {
panic(err)
}
fmt.Fprintf(f.out, "%s\n", string(dat))
}
func (f *cukefmt) step(res *stepResult) {
d := int(timeNowFunc().Sub(f.startTime).Nanoseconds())
f.curStep.Result.Duration = &d
f.curStep.Result.Status = res.status.String()
if res.err != nil {
f.curStep.Result.Error = res.err.Error()
}
}
func (f *cukefmt) Defined(pickle *messages.Pickle, pickleStep *messages.Pickle_PickleStep, def *StepDefinition) {
f.startTime = timeNowFunc() // start timing the step
f.curElement.Steps = append(f.curElement.Steps, cukeStep{})
f.curStep = &f.curElement.Steps[len(f.curElement.Steps)-1]
step := f.findStep(pickleStep.AstNodeIds[0])
line := step.Location.Line
if len(pickle.AstNodeIds) == 2 {
_, row := f.findExample(pickle.AstNodeIds[1])
line = row.Location.Line
}
f.curStep.Name = pickleStep.Text
f.curStep.Line = int(line)
f.curStep.Keyword = step.Keyword
arg := pickleStep.Argument
if arg.GetDocString() != nil && step.GetDocString() != nil {
f.curStep.Docstring = &cukeDocstring{}
f.curStep.Docstring.ContentType = strings.TrimSpace(arg.GetDocString().MediaType)
f.curStep.Docstring.Line = int(step.GetDocString().Location.Line)
f.curStep.Docstring.Value = arg.GetDocString().Content
}
if arg.GetDataTable() != nil {
f.curStep.DataTable = make([]*cukeDataTableRow, len(arg.GetDataTable().Rows))
for i, row := range arg.GetDataTable().Rows {
cells := make([]string, len(row.Cells))
for j, cell := range row.Cells {
cells[j] = cell.Value
}
f.curStep.DataTable[i] = &cukeDataTableRow{Cells: cells}
}
}
if def != nil {
f.curStep.Match.Location = strings.Split(def.definitionID(), " ")[0]
}
}
func (f *cukefmt) Passed(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Passed(pickle, step, match)
f.status = passed
f.step(f.lastStepResult())
}
func (f *cukefmt) Skipped(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Skipped(pickle, step, match)
f.step(f.lastStepResult())
// no duration reported for skipped.
f.curStep.Result.Duration = nil
}
func (f *cukefmt) Undefined(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Undefined(pickle, step, match)
f.status = undefined
f.step(f.lastStepResult())
// the location for undefined is the feature file location not the step file.
f.curStep.Match.Location = fmt.Sprintf("%s:%d", f.path, f.findStep(step.AstNodeIds[0]).Location.Line)
f.curStep.Result.Duration = nil
}
func (f *cukefmt) Failed(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition, err error) {
f.basefmt.Failed(pickle, step, match, err)
f.status = failed
f.step(f.lastStepResult())
}
func (f *cukefmt) Pending(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Pending(pickle, step, match)
f.status = pending
f.step(f.lastStepResult())
// the location for pending is the feature file location not the step file.
f.curStep.Match.Location = fmt.Sprintf("%s:%d", f.path, f.findStep(step.AstNodeIds[0]).Location.Line)
f.curStep.Result.Duration = nil
}

Просмотреть файл

@ -1,254 +0,0 @@
package godog
import (
"encoding/json"
"fmt"
"io"
"github.com/cucumber/messages-go/v9"
)
const nanoSec = 1000000
const spec = "0.1.0"
func init() {
Format("events", fmt.Sprintf("Produces JSON event stream, based on spec: %s.", spec), eventsFunc)
}
func eventsFunc(suite string, out io.Writer) Formatter {
formatter := &events{basefmt: newBaseFmt(suite, out)}
formatter.event(&struct {
Event string `json:"event"`
Version string `json:"version"`
Timestamp int64 `json:"timestamp"`
Suite string `json:"suite"`
}{
"TestRunStarted",
spec,
timeNowFunc().UnixNano() / nanoSec,
suite,
})
return formatter
}
type events struct {
*basefmt
// currently running feature path, to be part of id.
// this is sadly not passed by gherkin nodes.
// it restricts this formatter to run only in synchronous single
// threaded execution. Unless running a copy of formatter for each feature
path string
status stepResultStatus // last step status, before skipped
outlineSteps int // number of current outline scenario steps
}
func (f *events) event(ev interface{}) {
data, err := json.Marshal(ev)
if err != nil {
panic(fmt.Sprintf("failed to marshal stream event: %+v - %v", ev, err))
}
fmt.Fprintln(f.out, string(data))
}
func (f *events) Pickle(pickle *messages.Pickle) {
f.basefmt.Pickle(pickle)
f.event(&struct {
Event string `json:"event"`
Location string `json:"location"`
Timestamp int64 `json:"timestamp"`
}{
"TestCaseStarted",
f.scenarioLocation(pickle.AstNodeIds),
timeNowFunc().UnixNano() / nanoSec,
})
if len(pickle.Steps) == 0 {
// @TODO: is status undefined or passed? when there are no steps
// for this scenario
f.event(&struct {
Event string `json:"event"`
Location string `json:"location"`
Timestamp int64 `json:"timestamp"`
Status string `json:"status"`
}{
"TestCaseFinished",
f.scenarioLocation(pickle.AstNodeIds),
timeNowFunc().UnixNano() / nanoSec,
"undefined",
})
}
}
func (f *events) Feature(ft *messages.GherkinDocument, p string, c []byte) {
f.basefmt.Feature(ft, p, c)
f.path = p
f.event(&struct {
Event string `json:"event"`
Location string `json:"location"`
Source string `json:"source"`
}{
"TestSource",
fmt.Sprintf("%s:%d", p, ft.Feature.Location.Line),
string(c),
})
}
func (f *events) Summary() {
// @TODO: determine status
status := passed
if len(f.findStepResults(failed)) > 0 {
status = failed
} else if len(f.findStepResults(passed)) == 0 {
if len(f.findStepResults(undefined)) > len(f.findStepResults(pending)) {
status = undefined
} else {
status = pending
}
}
snips := f.snippets()
if len(snips) > 0 {
snips = "You can implement step definitions for undefined steps with these snippets:\n" + snips
}
f.event(&struct {
Event string `json:"event"`
Status string `json:"status"`
Timestamp int64 `json:"timestamp"`
Snippets string `json:"snippets"`
Memory string `json:"memory"`
}{
"TestRunFinished",
status.String(),
timeNowFunc().UnixNano() / nanoSec,
snips,
"", // @TODO not sure that could be correctly implemented
})
}
func (f *events) step(res *stepResult) {
step := f.findStep(res.step.AstNodeIds[0])
var errMsg string
if res.err != nil {
errMsg = res.err.Error()
}
f.event(&struct {
Event string `json:"event"`
Location string `json:"location"`
Timestamp int64 `json:"timestamp"`
Status string `json:"status"`
Summary string `json:"summary,omitempty"`
}{
"TestStepFinished",
fmt.Sprintf("%s:%d", f.path, step.Location.Line),
timeNowFunc().UnixNano() / nanoSec,
res.status.String(),
errMsg,
})
if isLastStep(res.owner, res.step) {
f.event(&struct {
Event string `json:"event"`
Location string `json:"location"`
Timestamp int64 `json:"timestamp"`
Status string `json:"status"`
}{
"TestCaseFinished",
f.scenarioLocation(res.owner.AstNodeIds),
timeNowFunc().UnixNano() / nanoSec,
f.status.String(),
})
}
}
func (f *events) Defined(pickle *messages.Pickle, pickleStep *messages.Pickle_PickleStep, def *StepDefinition) {
step := f.findStep(pickleStep.AstNodeIds[0])
if def != nil {
m := def.Expr.FindStringSubmatchIndex(pickleStep.Text)[2:]
var args [][2]int
for i := 0; i < len(m)/2; i++ {
pair := m[i : i*2+2]
var idxs [2]int
idxs[0] = pair[0]
idxs[1] = pair[1]
args = append(args, idxs)
}
if len(args) == 0 {
args = make([][2]int, 0)
}
f.event(&struct {
Event string `json:"event"`
Location string `json:"location"`
DefID string `json:"definition_id"`
Args [][2]int `json:"arguments"`
}{
"StepDefinitionFound",
fmt.Sprintf("%s:%d", f.path, step.Location.Line),
def.definitionID(),
args,
})
}
f.event(&struct {
Event string `json:"event"`
Location string `json:"location"`
Timestamp int64 `json:"timestamp"`
}{
"TestStepStarted",
fmt.Sprintf("%s:%d", f.path, step.Location.Line),
timeNowFunc().UnixNano() / nanoSec,
})
}
func (f *events) Passed(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Passed(pickle, step, match)
f.status = passed
f.step(f.lastStepResult())
}
func (f *events) Skipped(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Skipped(pickle, step, match)
f.step(f.lastStepResult())
}
func (f *events) Undefined(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Undefined(pickle, step, match)
f.status = undefined
f.step(f.lastStepResult())
}
func (f *events) Failed(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition, err error) {
f.basefmt.Failed(pickle, step, match, err)
f.status = failed
f.step(f.lastStepResult())
}
func (f *events) Pending(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Pending(pickle, step, match)
f.status = pending
f.step(f.lastStepResult())
}
func (f *events) scenarioLocation(astNodeIds []string) string {
scenario := f.findScenario(astNodeIds[0])
line := scenario.Location.Line
if len(astNodeIds) == 2 {
_, row := f.findExample(astNodeIds[1])
line = row.Location.Line
}
return fmt.Sprintf("%s:%d", f.path, line)
}

Просмотреть файл

@ -1,175 +0,0 @@
package godog
import (
"bytes"
"encoding/xml"
"fmt"
"io"
"strings"
"testing"
"github.com/cucumber/gherkin-go/v9"
"github.com/cucumber/messages-go/v9"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/cucumber/godog/colors"
)
var sampleGherkinFeature = `
Feature: junit formatter
Background:
Given passing
Scenario: passing scenario
Then passing
Scenario: failing scenario
When failing
Then passing
Scenario: pending scenario
When pending
Then passing
Scenario: undefined scenario
When undefined
Then next undefined
Scenario Outline: outline
Given <one>
When <two>
Examples:
| one | two |
| passing | passing |
| passing | failing |
| passing | pending |
Examples:
| one | two |
| passing | undefined |
`
func TestJUnitFormatterOutput(t *testing.T) {
const path = "any.feature"
gd, err := gherkin.ParseGherkinDocument(strings.NewReader(sampleGherkinFeature), (&messages.Incrementing{}).NewId)
require.NoError(t, err)
pickles := gherkin.Pickles(*gd, path, (&messages.Incrementing{}).NewId)
var buf bytes.Buffer
w := colors.Uncolored(&buf)
s := &Suite{
fmt: junitFunc("junit", w),
features: []*feature{{
GherkinDocument: gd,
pickles: pickles,
Path: path,
Content: []byte(sampleGherkinFeature),
}},
}
s.Step(`^passing$`, func() error { return nil })
s.Step(`^failing$`, func() error { return fmt.Errorf("errored") })
s.Step(`^pending$`, func() error { return ErrPending })
const zeroDuration = "0"
expected := junitPackageSuite{
Name: "junit",
Tests: 8,
Skipped: 0,
Failures: 2,
Errors: 4,
Time: zeroDuration,
TestSuites: []*junitTestSuite{{
Name: "junit formatter",
Tests: 8,
Skipped: 0,
Failures: 2,
Errors: 4,
Time: zeroDuration,
TestCases: []*junitTestCase{
{
Name: "passing scenario",
Status: "passed",
Time: zeroDuration,
},
{
Name: "failing scenario",
Status: "failed",
Time: zeroDuration,
Failure: &junitFailure{
Message: "Step failing: errored",
},
Error: []*junitError{
{Message: "Step passing", Type: "skipped"},
},
},
{
Name: "pending scenario",
Status: "pending",
Time: zeroDuration,
Error: []*junitError{
{Message: "Step pending: TODO: write pending definition", Type: "pending"},
{Message: "Step passing", Type: "skipped"},
},
},
{
Name: "undefined scenario",
Status: "undefined",
Time: zeroDuration,
Error: []*junitError{
{Message: "Step undefined", Type: "undefined"},
{Message: "Step next undefined", Type: "undefined"},
},
},
{
Name: "outline #1",
Status: "passed",
Time: zeroDuration,
},
{
Name: "outline #2",
Status: "failed",
Time: zeroDuration,
Failure: &junitFailure{
Message: "Step failing: errored",
},
},
{
Name: "outline #3",
Status: "pending",
Time: zeroDuration,
Error: []*junitError{
{Message: "Step pending: TODO: write pending definition", Type: "pending"},
},
},
{
Name: "outline #4",
Status: "undefined",
Time: zeroDuration,
Error: []*junitError{
{Message: "Step undefined", Type: "undefined"},
},
},
},
}},
}
s.run()
s.fmt.Summary()
var exp bytes.Buffer
_, err = io.WriteString(&exp, xml.Header)
require.NoError(t, err)
enc := xml.NewEncoder(&exp)
enc.Indent("", " ")
err = enc.Encode(expected)
require.NoError(t, err)
assert.Equal(t, exp.String(), buf.String())
}

Просмотреть файл

@ -1,468 +0,0 @@
package godog
import (
"fmt"
"io"
"regexp"
"strings"
"unicode/utf8"
"github.com/cucumber/messages-go/v9"
"github.com/cucumber/godog/colors"
)
func init() {
Format("pretty", "Prints every feature with runtime statuses.", prettyFunc)
}
func prettyFunc(suite string, out io.Writer) Formatter {
return &pretty{basefmt: newBaseFmt(suite, out)}
}
var outlinePlaceholderRegexp = regexp.MustCompile("<[^>]+>")
// a built in default pretty formatter
type pretty struct {
*basefmt
}
func (f *pretty) Feature(gd *messages.GherkinDocument, p string, c []byte) {
f.basefmt.Feature(gd, p, c)
f.printFeature(gd.Feature)
}
// Pickle takes a gherkin node for formatting
func (f *pretty) Pickle(pickle *messages.Pickle) {
f.basefmt.Pickle(pickle)
if len(pickle.Steps) == 0 {
f.printUndefinedPickle(pickle)
return
}
}
func (f *pretty) Passed(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Passed(pickle, step, match)
f.printStep(f.lastStepResult())
}
func (f *pretty) Skipped(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Skipped(pickle, step, match)
f.printStep(f.lastStepResult())
}
func (f *pretty) Undefined(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Undefined(pickle, step, match)
f.printStep(f.lastStepResult())
}
func (f *pretty) Failed(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition, err error) {
f.basefmt.Failed(pickle, step, match, err)
f.printStep(f.lastStepResult())
}
func (f *pretty) Pending(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Pending(pickle, step, match)
f.printStep(f.lastStepResult())
}
func (f *pretty) printFeature(feature *messages.GherkinDocument_Feature) {
if len(f.features) > 1 {
fmt.Fprintln(f.out, "") // not a first feature, add a newline
}
fmt.Fprintln(f.out, keywordAndName(feature.Keyword, feature.Name))
if strings.TrimSpace(feature.Description) != "" {
for _, line := range strings.Split(feature.Description, "\n") {
fmt.Fprintln(f.out, s(f.indent)+strings.TrimSpace(line))
}
}
}
func keywordAndName(keyword, name string) string {
title := whiteb(keyword + ":")
if len(name) > 0 {
title += " " + name
}
return title
}
func (f *pretty) scenarioLengths(scenarioAstID string) (scenarioHeaderLength int, maxLength int) {
astScenario := f.findScenario(scenarioAstID)
astBackground := f.findBackground(scenarioAstID)
scenarioHeaderLength = f.lengthPickle(astScenario.Keyword, astScenario.Name)
maxLength = f.longestStep(astScenario.Steps, scenarioHeaderLength)
if astBackground != nil {
maxLength = f.longestStep(astBackground.Steps, maxLength)
}
return scenarioHeaderLength, maxLength
}
func (f *pretty) printScenarioHeader(astScenario *messages.GherkinDocument_Feature_Scenario, spaceFilling int) {
text := s(f.indent) + keywordAndName(astScenario.Keyword, astScenario.Name)
text += s(spaceFilling) + f.line(astScenario.Location)
fmt.Fprintln(f.out, "\n"+text)
}
func (f *pretty) printUndefinedPickle(pickle *messages.Pickle) {
astScenario := f.findScenario(pickle.AstNodeIds[0])
astBackground := f.findBackground(pickle.AstNodeIds[0])
scenarioHeaderLength, maxLength := f.scenarioLengths(pickle.AstNodeIds[0])
if astBackground != nil {
fmt.Fprintln(f.out, "\n"+s(f.indent)+keywordAndName(astBackground.Keyword, astBackground.Name))
for _, step := range astBackground.Steps {
text := s(f.indent*2) + cyan(strings.TrimSpace(step.Keyword)) + " " + cyan(step.Text)
fmt.Fprintln(f.out, text)
}
}
// do not print scenario headers and examples multiple times
if len(astScenario.Examples) > 0 {
exampleTable, exampleRow := f.findExample(pickle.AstNodeIds[1])
firstExampleRow := exampleTable.TableBody[0].Id == exampleRow.Id
firstExamplesTable := astScenario.Examples[0].Location.Line == exampleTable.Location.Line
if !(firstExamplesTable && firstExampleRow) {
return
}
}
f.printScenarioHeader(astScenario, maxLength-scenarioHeaderLength)
for _, examples := range astScenario.Examples {
max := longestExampleRow(examples, cyan, cyan)
fmt.Fprintln(f.out, "")
fmt.Fprintln(f.out, s(f.indent*2)+keywordAndName(examples.Keyword, examples.Name))
f.printTableHeader(examples.TableHeader, max)
for _, row := range examples.TableBody {
f.printTableRow(row, max, cyan)
}
}
}
// Summary sumarize the feature formatter output
func (f *pretty) Summary() {
failedStepResults := f.findStepResults(failed)
if len(failedStepResults) > 0 {
fmt.Fprintln(f.out, "\n--- "+red("Failed steps:")+"\n")
for _, fail := range failedStepResults {
astScenario := f.findScenario(fail.owner.AstNodeIds[0])
scenarioDesc := fmt.Sprintf("%s: %s", astScenario.Keyword, fail.owner.Name)
astStep := f.findStep(fail.step.AstNodeIds[0])
stepDesc := strings.TrimSpace(astStep.Keyword) + " " + fail.step.Text
fmt.Fprintln(f.out, s(f.indent)+red(scenarioDesc)+f.line(astScenario.Location))
fmt.Fprintln(f.out, s(f.indent*2)+red(stepDesc)+f.line(astStep.Location))
fmt.Fprintln(f.out, s(f.indent*3)+red("Error: ")+redb(fmt.Sprintf("%+v", fail.err))+"\n")
}
}
f.basefmt.Summary()
}
func (f *pretty) printOutlineExample(pickle *messages.Pickle, backgroundSteps int) {
var errorMsg string
var clr = green
astScenario := f.findScenario(pickle.AstNodeIds[0])
scenarioHeaderLength, maxLength := f.scenarioLengths(pickle.AstNodeIds[0])
exampleTable, exampleRow := f.findExample(pickle.AstNodeIds[1])
printExampleHeader := exampleTable.TableBody[0].Id == exampleRow.Id
firstExamplesTable := astScenario.Examples[0].Location.Line == exampleTable.Location.Line
firstExecutedScenarioStep := len(f.lastFeature().lastPickleResult().stepResults) == backgroundSteps+1
if firstExamplesTable && printExampleHeader && firstExecutedScenarioStep {
f.printScenarioHeader(astScenario, maxLength-scenarioHeaderLength)
}
if len(exampleTable.TableBody) == 0 {
// do not print empty examples
return
}
lastStep := len(f.lastFeature().lastPickleResult().stepResults) == len(pickle.Steps)
if !lastStep {
// do not print examples unless all steps has finished
return
}
for _, result := range f.lastFeature().lastPickleResult().stepResults {
// determine example row status
switch {
case result.status == failed:
errorMsg = result.err.Error()
clr = result.status.clr()
case result.status == undefined || result.status == pending:
clr = result.status.clr()
case result.status == skipped && clr == nil:
clr = cyan
}
if firstExamplesTable && printExampleHeader {
// in first example, we need to print steps
var text string
astStep := f.findStep(result.step.AstNodeIds[0])
if result.def != nil {
if m := outlinePlaceholderRegexp.FindAllStringIndex(astStep.Text, -1); len(m) > 0 {
var pos int
for i := 0; i < len(m); i++ {
pair := m[i]
text += cyan(astStep.Text[pos:pair[0]])
text += cyanb(astStep.Text[pair[0]:pair[1]])
pos = pair[1]
}
text += cyan(astStep.Text[pos:len(astStep.Text)])
} else {
text = cyan(astStep.Text)
}
_, maxLength := f.scenarioLengths(result.owner.AstNodeIds[0])
stepLength := f.lengthPickleStep(astStep.Keyword, astStep.Text)
text += s(maxLength - stepLength)
text += " " + blackb("# "+result.def.definitionID())
} else {
text = cyan(astStep.Text)
}
// print the step outline
fmt.Fprintln(f.out, s(f.indent*2)+cyan(strings.TrimSpace(astStep.Keyword))+" "+text)
if table := result.step.Argument.GetDataTable(); table != nil {
f.printTable(table, cyan)
}
if docString := astStep.GetDocString(); docString != nil {
f.printDocString(docString)
}
}
}
max := longestExampleRow(exampleTable, clr, cyan)
// an example table header
if printExampleHeader {
fmt.Fprintln(f.out, "")
fmt.Fprintln(f.out, s(f.indent*2)+keywordAndName(exampleTable.Keyword, exampleTable.Name))
f.printTableHeader(exampleTable.TableHeader, max)
}
f.printTableRow(exampleRow, max, clr)
if errorMsg != "" {
fmt.Fprintln(f.out, s(f.indent*4)+redb(errorMsg))
}
}
func (f *pretty) printTableRow(row *messages.GherkinDocument_Feature_TableRow, max []int, clr colors.ColorFunc) {
cells := make([]string, len(row.Cells))
for i, cell := range row.Cells {
val := clr(cell.Value)
ln := utf8.RuneCountInString(val)
cells[i] = val + s(max[i]-ln)
}
fmt.Fprintln(f.out, s(f.indent*3)+"| "+strings.Join(cells, " | ")+" |")
}
func (f *pretty) printTableHeader(row *messages.GherkinDocument_Feature_TableRow, max []int) {
f.printTableRow(row, max, cyan)
}
func (f *pretty) printStep(result *stepResult) {
astBackground := f.findBackground(result.owner.AstNodeIds[0])
astScenario := f.findScenario(result.owner.AstNodeIds[0])
astStep := f.findStep(result.step.AstNodeIds[0])
var backgroundSteps int
if astBackground != nil {
backgroundSteps = len(astBackground.Steps)
}
astBackgroundStep := backgroundSteps > 0 && backgroundSteps >= len(f.lastFeature().lastPickleResult().stepResults)
if astBackgroundStep {
if len(f.lastFeature().pickleResults) > 1 {
return
}
firstExecutedBackgroundStep := astBackground != nil && len(f.lastFeature().lastPickleResult().stepResults) == 1
if firstExecutedBackgroundStep {
fmt.Fprintln(f.out, "\n"+s(f.indent)+keywordAndName(astBackground.Keyword, astBackground.Name))
}
}
if !astBackgroundStep && len(astScenario.Examples) > 0 {
f.printOutlineExample(result.owner, backgroundSteps)
return
}
scenarioHeaderLength, maxLength := f.scenarioLengths(result.owner.AstNodeIds[0])
stepLength := f.lengthPickleStep(astStep.Keyword, astStep.Text)
firstExecutedScenarioStep := len(f.lastFeature().lastPickleResult().stepResults) == backgroundSteps+1
if !astBackgroundStep && firstExecutedScenarioStep {
f.printScenarioHeader(astScenario, maxLength-scenarioHeaderLength)
}
text := s(f.indent*2) + result.status.clr()(strings.TrimSpace(astStep.Keyword)) + " " + result.status.clr()(astStep.Text)
if result.def != nil {
text += s(maxLength - stepLength + 1)
text += blackb("# " + result.def.definitionID())
}
fmt.Fprintln(f.out, text)
if table := result.step.Argument.GetDataTable(); table != nil {
f.printTable(table, cyan)
}
if docString := astStep.GetDocString(); docString != nil {
f.printDocString(docString)
}
if result.err != nil {
fmt.Fprintln(f.out, s(f.indent*2)+redb(fmt.Sprintf("%+v", result.err)))
}
if result.status == pending {
fmt.Fprintln(f.out, s(f.indent*3)+yellow("TODO: write pending definition"))
}
}
func (f *pretty) printDocString(docString *messages.GherkinDocument_Feature_Step_DocString) {
var ct string
if len(docString.MediaType) > 0 {
ct = " " + cyan(docString.MediaType)
}
fmt.Fprintln(f.out, s(f.indent*3)+cyan(docString.Delimiter)+ct)
for _, ln := range strings.Split(docString.Content, "\n") {
fmt.Fprintln(f.out, s(f.indent*3)+cyan(ln))
}
fmt.Fprintln(f.out, s(f.indent*3)+cyan(docString.Delimiter))
}
// print table with aligned table cells
// @TODO: need to make example header cells bold
func (f *pretty) printTable(t *messages.PickleStepArgument_PickleTable, c colors.ColorFunc) {
maxColLengths := maxColLengths(t, c)
var cols = make([]string, len(t.Rows[0].Cells))
for _, row := range t.Rows {
for i, cell := range row.Cells {
val := c(cell.Value)
colLength := utf8.RuneCountInString(val)
cols[i] = val + s(maxColLengths[i]-colLength)
}
fmt.Fprintln(f.out, s(f.indent*3)+"| "+strings.Join(cols, " | ")+" |")
}
}
// longest gives a list of longest columns of all rows in Table
func maxColLengths(t *messages.PickleStepArgument_PickleTable, clrs ...colors.ColorFunc) []int {
if t == nil {
return []int{}
}
longest := make([]int, len(t.Rows[0].Cells))
for _, row := range t.Rows {
for i, cell := range row.Cells {
for _, c := range clrs {
ln := utf8.RuneCountInString(c(cell.Value))
if longest[i] < ln {
longest[i] = ln
}
}
ln := utf8.RuneCountInString(cell.Value)
if longest[i] < ln {
longest[i] = ln
}
}
}
return longest
}
func longestExampleRow(t *messages.GherkinDocument_Feature_Scenario_Examples, clrs ...colors.ColorFunc) []int {
if t == nil {
return []int{}
}
longest := make([]int, len(t.TableHeader.Cells))
for i, cell := range t.TableHeader.Cells {
for _, c := range clrs {
ln := utf8.RuneCountInString(c(cell.Value))
if longest[i] < ln {
longest[i] = ln
}
}
ln := utf8.RuneCountInString(cell.Value)
if longest[i] < ln {
longest[i] = ln
}
}
for _, row := range t.TableBody {
for i, cell := range row.Cells {
for _, c := range clrs {
ln := utf8.RuneCountInString(c(cell.Value))
if longest[i] < ln {
longest[i] = ln
}
}
ln := utf8.RuneCountInString(cell.Value)
if longest[i] < ln {
longest[i] = ln
}
}
}
return longest
}
func (f *pretty) longestStep(steps []*messages.GherkinDocument_Feature_Step, pickleLength int) int {
max := pickleLength
for _, step := range steps {
length := f.lengthPickleStep(step.Keyword, step.Text)
if length > max {
max = length
}
}
return max
}
// a line number representation in feature file
func (f *pretty) line(loc *messages.Location) string {
return " " + blackb(fmt.Sprintf("# %s:%d", f.lastFeature().Path, loc.Line))
}
func (f *pretty) lengthPickleStep(keyword, text string) int {
return f.indent*2 + utf8.RuneCountInString(strings.TrimSpace(keyword)+" "+text)
}
func (f *pretty) lengthPickle(keyword, name string) int {
return f.indent + utf8.RuneCountInString(strings.TrimSpace(keyword)+": "+name)
}

Просмотреть файл

@ -1,148 +0,0 @@
package godog
import (
"fmt"
"io"
"math"
"strings"
"github.com/cucumber/messages-go/v9"
)
func init() {
Format("progress", "Prints a character per step.", progressFunc)
}
func progressFunc(suite string, out io.Writer) Formatter {
steps := 0
return &progress{
basefmt: newBaseFmt(suite, out),
stepsPerRow: 70,
steps: &steps,
}
}
type progress struct {
*basefmt
stepsPerRow int
steps *int
}
func (f *progress) Summary() {
left := math.Mod(float64(*f.steps), float64(f.stepsPerRow))
if left != 0 {
if *f.steps > f.stepsPerRow {
fmt.Fprintf(f.out, s(f.stepsPerRow-int(left))+fmt.Sprintf(" %d\n", *f.steps))
} else {
fmt.Fprintf(f.out, " %d\n", *f.steps)
}
}
var failedStepsOutput []string
for _, sr := range f.findStepResults(failed) {
if sr.status == failed {
sc := f.findScenario(sr.owner.AstNodeIds[0])
scenarioDesc := fmt.Sprintf("%s: %s", sc.Keyword, sr.owner.Name)
scenarioLine := fmt.Sprintf("%s:%d", sr.owner.Uri, sc.Location.Line)
step := f.findStep(sr.step.AstNodeIds[0])
stepDesc := strings.TrimSpace(step.Keyword) + " " + sr.step.Text
stepLine := fmt.Sprintf("%s:%d", sr.owner.Uri, step.Location.Line)
failedStepsOutput = append(
failedStepsOutput,
s(2)+red(scenarioDesc)+blackb(" # "+scenarioLine),
s(4)+red(stepDesc)+blackb(" # "+stepLine),
s(6)+red("Error: ")+redb(fmt.Sprintf("%+v", sr.err)),
"",
)
}
}
if len(failedStepsOutput) > 0 {
fmt.Fprintln(f.out, "\n\n--- "+red("Failed steps:")+"\n")
fmt.Fprint(f.out, strings.Join(failedStepsOutput, "\n"))
}
fmt.Fprintln(f.out, "")
f.basefmt.Summary()
}
func (f *progress) step(res *stepResult) {
switch res.status {
case passed:
fmt.Fprint(f.out, green("."))
case skipped:
fmt.Fprint(f.out, cyan("-"))
case failed:
fmt.Fprint(f.out, red("F"))
case undefined:
fmt.Fprint(f.out, yellow("U"))
case pending:
fmt.Fprint(f.out, yellow("P"))
}
*f.steps++
if math.Mod(float64(*f.steps), float64(f.stepsPerRow)) == 0 {
fmt.Fprintf(f.out, " %d\n", *f.steps)
}
}
func (f *progress) Passed(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Passed(pickle, step, match)
f.lock.Lock()
defer f.lock.Unlock()
f.step(f.lastStepResult())
}
func (f *progress) Skipped(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Skipped(pickle, step, match)
f.lock.Lock()
defer f.lock.Unlock()
f.step(f.lastStepResult())
}
func (f *progress) Undefined(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Undefined(pickle, step, match)
f.lock.Lock()
defer f.lock.Unlock()
f.step(f.lastStepResult())
}
func (f *progress) Failed(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition, err error) {
f.basefmt.Failed(pickle, step, match, err)
f.lock.Lock()
defer f.lock.Unlock()
f.step(f.lastStepResult())
}
func (f *progress) Pending(pickle *messages.Pickle, step *messages.Pickle_PickleStep, match *StepDefinition) {
f.basefmt.Pending(pickle, step, match)
f.lock.Lock()
defer f.lock.Unlock()
f.step(f.lastStepResult())
}
func (f *progress) Sync(cf ConcurrentFormatter) {
if source, ok := cf.(*progress); ok {
f.basefmt.Sync(source.basefmt)
f.steps = source.steps
}
}
func (f *progress) Copy(cf ConcurrentFormatter) {
if source, ok := cf.(*progress); ok {
f.basefmt.Copy(source.basefmt)
}
}

Просмотреть файл

@ -1,356 +0,0 @@
package godog
import (
"bytes"
"fmt"
"strings"
"testing"
"github.com/cucumber/gherkin-go/v9"
"github.com/cucumber/messages-go/v9"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/cucumber/godog/colors"
)
var basicGherkinFeature = `
Feature: basic
Scenario: passing scenario
When one
Then two
`
func TestProgressFormatterOutput(t *testing.T) {
const path = "any.feature"
gd, err := gherkin.ParseGherkinDocument(strings.NewReader(sampleGherkinFeature), (&messages.Incrementing{}).NewId)
require.NoError(t, err)
pickles := gherkin.Pickles(*gd, path, (&messages.Incrementing{}).NewId)
var buf bytes.Buffer
w := colors.Uncolored(&buf)
r := runner{
fmt: progressFunc("progress", w),
features: []*feature{{
GherkinDocument: gd,
pickles: pickles,
Path: path,
Content: []byte(sampleGherkinFeature),
}},
initializer: func(s *Suite) {
s.Step(`^passing$`, func() error { return nil })
s.Step(`^failing$`, func() error { return fmt.Errorf("errored") })
s.Step(`^pending$`, func() error { return ErrPending })
},
}
expected := `
...F-.P-.UU.....F..P..U 23
--- Failed steps:
Scenario: failing scenario # any.feature:10
When failing # any.feature:11
Error: errored
Scenario Outline: outline # any.feature:22
When failing # any.feature:24
Error: errored
8 scenarios (2 passed, 2 failed, 2 pending, 2 undefined)
23 steps (14 passed, 2 failed, 2 pending, 3 undefined, 2 skipped)
0s
You can implement step definitions for undefined steps with these snippets:
func undefined() error {
return godog.ErrPending
}
func nextUndefined() error {
return godog.ErrPending
}
func FeatureContext(s *godog.Suite) {
s.Step(` + "`^undefined$`" + `, undefined)
s.Step(` + "`^next undefined$`" + `, nextUndefined)
}`
require.True(t, r.run())
expected = trimAllLines(expected)
actual := trimAllLines(buf.String())
assert.Equal(t, expected, actual)
}
func TestProgressFormatterWhenStepPanics(t *testing.T) {
const path = "any.feature"
gd, err := gherkin.ParseGherkinDocument(strings.NewReader(basicGherkinFeature), (&messages.Incrementing{}).NewId)
require.NoError(t, err)
pickles := gherkin.Pickles(*gd, path, (&messages.Incrementing{}).NewId)
var buf bytes.Buffer
w := colors.Uncolored(&buf)
r := runner{
fmt: progressFunc("progress", w),
features: []*feature{{GherkinDocument: gd, pickles: pickles}},
initializer: func(s *Suite) {
s.Step(`^one$`, func() error { return nil })
s.Step(`^two$`, func() error { panic("omg") })
},
}
require.True(t, r.run())
actual := buf.String()
assert.Contains(t, actual, "godog/fmt_progress_test.go:107")
}
func TestProgressFormatterWithPassingMultisteps(t *testing.T) {
const path = "any.feature"
gd, err := gherkin.ParseGherkinDocument(strings.NewReader(basicGherkinFeature), (&messages.Incrementing{}).NewId)
require.NoError(t, err)
pickles := gherkin.Pickles(*gd, path, (&messages.Incrementing{}).NewId)
var buf bytes.Buffer
w := colors.Uncolored(&buf)
r := runner{
fmt: progressFunc("progress", w),
features: []*feature{{GherkinDocument: gd, pickles: pickles}},
initializer: func(s *Suite) {
s.Step(`^sub1$`, func() error { return nil })
s.Step(`^sub-sub$`, func() error { return nil })
s.Step(`^sub2$`, func() Steps { return Steps{"sub-sub", "sub1", "one"} })
s.Step(`^one$`, func() error { return nil })
s.Step(`^two$`, func() Steps { return Steps{"sub1", "sub2"} })
},
}
assert.False(t, r.run())
}
func TestProgressFormatterWithFailingMultisteps(t *testing.T) {
const path = "some.feature"
gd, err := gherkin.ParseGherkinDocument(strings.NewReader(basicGherkinFeature), (&messages.Incrementing{}).NewId)
require.NoError(t, err)
pickles := gherkin.Pickles(*gd, path, (&messages.Incrementing{}).NewId)
var buf bytes.Buffer
w := colors.Uncolored(&buf)
r := runner{
fmt: progressFunc("progress", w),
features: []*feature{{GherkinDocument: gd, pickles: pickles, Path: path}},
initializer: func(s *Suite) {
s.Step(`^sub1$`, func() error { return nil })
s.Step(`^sub-sub$`, func() error { return fmt.Errorf("errored") })
s.Step(`^sub2$`, func() Steps { return Steps{"sub-sub", "sub1", "one"} })
s.Step(`^one$`, func() error { return nil })
s.Step(`^two$`, func() Steps { return Steps{"sub1", "sub2"} })
},
}
require.True(t, r.run())
expected := `
.F 2
--- Failed steps:
Scenario: passing scenario # some.feature:4
Then two # some.feature:6
Error: sub2: sub-sub: errored
1 scenarios (1 failed)
2 steps (1 passed, 1 failed)
0s
`
expected = trimAllLines(expected)
actual := trimAllLines(buf.String())
assert.Equal(t, expected, actual)
}
func TestProgressFormatterWithPanicInMultistep(t *testing.T) {
const path = "any.feature"
gd, err := gherkin.ParseGherkinDocument(strings.NewReader(basicGherkinFeature), (&messages.Incrementing{}).NewId)
require.NoError(t, err)
pickles := gherkin.Pickles(*gd, path, (&messages.Incrementing{}).NewId)
var buf bytes.Buffer
w := colors.Uncolored(&buf)
r := runner{
fmt: progressFunc("progress", w),
features: []*feature{{GherkinDocument: gd, pickles: pickles}},
initializer: func(s *Suite) {
s.Step(`^sub1$`, func() error { return nil })
s.Step(`^sub-sub$`, func() error { return nil })
s.Step(`^sub2$`, func() []string { return []string{"sub-sub", "sub1", "one"} })
s.Step(`^one$`, func() error { return nil })
s.Step(`^two$`, func() []string { return []string{"sub1", "sub2"} })
},
}
assert.True(t, r.run())
}
func TestProgressFormatterMultistepTemplates(t *testing.T) {
const path = "any.feature"
gd, err := gherkin.ParseGherkinDocument(strings.NewReader(basicGherkinFeature), (&messages.Incrementing{}).NewId)
require.NoError(t, err)
pickles := gherkin.Pickles(*gd, path, (&messages.Incrementing{}).NewId)
var buf bytes.Buffer
w := colors.Uncolored(&buf)
r := runner{
fmt: progressFunc("progress", w),
features: []*feature{{GherkinDocument: gd, pickles: pickles}},
initializer: func(s *Suite) {
s.Step(`^sub-sub$`, func() error { return nil })
s.Step(`^substep$`, func() Steps { return Steps{"sub-sub", `unavailable "John" cost 5`, "one", "three"} })
s.Step(`^one$`, func() error { return nil })
s.Step(`^(t)wo$`, func(s string) Steps { return Steps{"undef", "substep"} })
},
}
require.False(t, r.run())
expected := `
.U 2
1 scenarios (1 undefined)
2 steps (1 passed, 1 undefined)
0s
You can implement step definitions for undefined steps with these snippets:
func undef() error {
return godog.ErrPending
}
func unavailableCost(arg1 string, arg2 int) error {
return godog.ErrPending
}
func three() error {
return godog.ErrPending
}
func FeatureContext(s *godog.Suite) {
s.Step(` + "`^undef$`" + `, undef)
s.Step(` + "`^unavailable \"([^\"]*)\" cost (\\d+)$`" + `, unavailableCost)
s.Step(` + "`^three$`" + `, three)
}
`
expected = trimAllLines(expected)
actual := trimAllLines(buf.String())
assert.Equal(t, expected, actual)
}
func TestProgressFormatterWhenMultiStepHasArgument(t *testing.T) {
const path = "any.feature"
var featureSource = `
Feature: basic
Scenario: passing scenario
When one
Then two:
"""
text
"""
`
gd, err := gherkin.ParseGherkinDocument(strings.NewReader(featureSource), (&messages.Incrementing{}).NewId)
require.NoError(t, err)
pickles := gherkin.Pickles(*gd, path, (&messages.Incrementing{}).NewId)
var buf bytes.Buffer
w := colors.Uncolored(&buf)
r := runner{
fmt: progressFunc("progress", w),
features: []*feature{{GherkinDocument: gd, pickles: pickles}},
initializer: func(s *Suite) {
s.Step(`^one$`, func() error { return nil })
s.Step(`^two:$`, func(doc *messages.PickleStepArgument_PickleDocString) Steps { return Steps{"one"} })
},
}
assert.False(t, r.run())
}
func TestProgressFormatterWhenMultiStepHasStepWithArgument(t *testing.T) {
const path = "any.feature"
var featureSource = `
Feature: basic
Scenario: passing scenario
When one
Then two`
gd, err := gherkin.ParseGherkinDocument(strings.NewReader(featureSource), (&messages.Incrementing{}).NewId)
require.NoError(t, err)
pickles := gherkin.Pickles(*gd, path, (&messages.Incrementing{}).NewId)
var subStep = `three:
"""
content
"""`
var buf bytes.Buffer
w := colors.Uncolored(&buf)
r := runner{
fmt: progressFunc("progress", w),
features: []*feature{{GherkinDocument: gd, pickles: pickles}},
initializer: func(s *Suite) {
s.Step(`^one$`, func() error { return nil })
s.Step(`^two$`, func() Steps { return Steps{subStep} })
s.Step(`^three:$`, func(doc *messages.PickleStepArgument_PickleDocString) error { return nil })
},
}
require.True(t, r.run())
expected := `
.F 2
--- Failed steps:
Scenario: passing scenario # any.feature:4
Then two # any.feature:6
Error: nested steps cannot be multiline and have table or content body argument
1 scenarios (1 failed)
2 steps (1 passed, 1 failed)
0s
`
expected = trimAllLines(expected)
actual := trimAllLines(buf.String())
assert.Equal(t, expected, actual)
}

Просмотреть файл

@ -1,25 +1,67 @@
package godog
package godog_test
import "testing"
import (
"io"
"testing"
func TestShouldFindFormatter(t *testing.T) {
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"git.golang1.ru/softonik/godog"
)
func Test_FindFmt(t *testing.T) {
cases := map[string]bool{
"progress": true, // true means should be available
"unknown": false,
"junit": true,
"cucumber": true,
"pretty": true,
"custom": true, // is available for test purposes only
"events": true,
"junit": true,
"pretty": true,
"progress": true,
"unknown": false,
"undef": false,
}
for name, shouldFind := range cases {
actual := FindFmt(name)
if actual == nil && shouldFind {
t.Fatalf("expected %s formatter should be available", name)
}
if actual != nil && !shouldFind {
t.Fatalf("expected %s formatter should not be available", name)
}
for name, expected := range cases {
t.Run(
name,
func(t *testing.T) {
actual := godog.FindFmt(name)
if expected {
assert.NotNilf(t, actual, "expected %s formatter should be available", name)
} else {
assert.Nilf(t, actual, "expected %s formatter should be available", name)
}
},
)
}
}
func Test_AvailableFormatters(t *testing.T) {
expected := map[string]string{
"cucumber": "Produces cucumber JSON format output.",
"custom": "custom format description", // is available for test purposes only
"events": "Produces JSON event stream, based on spec: 0.1.0.",
"junit": "Prints junit compatible xml to stdout",
"pretty": "Prints every feature with runtime statuses.",
"progress": "Prints a character per step.",
}
actual := godog.AvailableFormatters()
assert.Equal(t, expected, actual)
}
func Test_Format(t *testing.T) {
actual := godog.FindFmt("Test_Format")
require.Nil(t, actual)
godog.Format("Test_Format", "...", testFormatterFunc)
actual = godog.FindFmt("Test_Format")
assert.NotNil(t, actual)
}
func testFormatterFunc(suiteName string, out io.Writer) godog.Formatter {
return nil
}

Просмотреть файл

@ -1,10 +0,0 @@
[
{
"uri": "formatter-tests/features/empty.feature",
"id": "empty-feature",
"keyword": "Feature",
"name": "empty feature",
"description": "",
"line": 1
}
]

Просмотреть файл

@ -1,10 +0,0 @@
[
{
"uri": "formatter-tests/features/empty_with_description.feature",
"id": "empty-feature",
"keyword": "Feature",
"name": "empty feature",
"description": " describes\n an empty\n feature",
"line": 1
}
]

Просмотреть файл

@ -1,29 +0,0 @@
{"event":"TestRunStarted","version":"0.1.0","timestamp":-6795364578871,"suite":"events"}
{"event":"TestSource","location":"formatter-tests/features/some_scenarions_including_failing.feature:1","source":"Feature: some scenarios\n\n Scenario: failing\n Given passing step\n When failing step\n Then passing step\n\n Scenario: pending\n When pending step\n Then passing step\n\n Scenario: undefined\n When undefined\n Then passing step\n"}
{"event":"TestCaseStarted","location":"formatter-tests/features/some_scenarions_including_failing.feature:3","timestamp":-6795364578871}
{"event":"StepDefinitionFound","location":"formatter-tests/features/some_scenarions_including_failing.feature:4","definition_id":"formatters_print_test.go:63 -\u003e passingStepDef","arguments":[]}
{"event":"TestStepStarted","location":"formatter-tests/features/some_scenarions_including_failing.feature:4","timestamp":-6795364578871}
{"event":"TestStepFinished","location":"formatter-tests/features/some_scenarions_including_failing.feature:4","timestamp":-6795364578871,"status":"passed"}
{"event":"StepDefinitionFound","location":"formatter-tests/features/some_scenarions_including_failing.feature:5","definition_id":"formatters_print_test.go:79 -\u003e failingStepDef","arguments":[]}
{"event":"TestStepStarted","location":"formatter-tests/features/some_scenarions_including_failing.feature:5","timestamp":-6795364578871}
{"event":"TestStepFinished","location":"formatter-tests/features/some_scenarions_including_failing.feature:5","timestamp":-6795364578871,"status":"failed","summary":"step failed"}
{"event":"StepDefinitionFound","location":"formatter-tests/features/some_scenarions_including_failing.feature:6","definition_id":"formatters_print_test.go:63 -\u003e passingStepDef","arguments":[]}
{"event":"TestStepStarted","location":"formatter-tests/features/some_scenarions_including_failing.feature:6","timestamp":-6795364578871}
{"event":"TestStepFinished","location":"formatter-tests/features/some_scenarions_including_failing.feature:6","timestamp":-6795364578871,"status":"skipped"}
{"event":"TestCaseFinished","location":"formatter-tests/features/some_scenarions_including_failing.feature:3","timestamp":-6795364578871,"status":"failed"}
{"event":"TestCaseStarted","location":"formatter-tests/features/some_scenarions_including_failing.feature:8","timestamp":-6795364578871}
{"event":"StepDefinitionFound","location":"formatter-tests/features/some_scenarions_including_failing.feature:9","definition_id":"formatters_print_test.go:77 -\u003e pendingStepDef","arguments":[]}
{"event":"TestStepStarted","location":"formatter-tests/features/some_scenarions_including_failing.feature:9","timestamp":-6795364578871}
{"event":"TestStepFinished","location":"formatter-tests/features/some_scenarions_including_failing.feature:9","timestamp":-6795364578871,"status":"pending"}
{"event":"StepDefinitionFound","location":"formatter-tests/features/some_scenarions_including_failing.feature:10","definition_id":"formatters_print_test.go:63 -\u003e passingStepDef","arguments":[]}
{"event":"TestStepStarted","location":"formatter-tests/features/some_scenarions_including_failing.feature:10","timestamp":-6795364578871}
{"event":"TestStepFinished","location":"formatter-tests/features/some_scenarions_including_failing.feature:10","timestamp":-6795364578871,"status":"skipped"}
{"event":"TestCaseFinished","location":"formatter-tests/features/some_scenarions_including_failing.feature:8","timestamp":-6795364578871,"status":"pending"}
{"event":"TestCaseStarted","location":"formatter-tests/features/some_scenarions_including_failing.feature:12","timestamp":-6795364578871}
{"event":"TestStepStarted","location":"formatter-tests/features/some_scenarions_including_failing.feature:13","timestamp":-6795364578871}
{"event":"TestStepFinished","location":"formatter-tests/features/some_scenarions_including_failing.feature:13","timestamp":-6795364578871,"status":"undefined"}
{"event":"StepDefinitionFound","location":"formatter-tests/features/some_scenarions_including_failing.feature:14","definition_id":"formatters_print_test.go:63 -\u003e passingStepDef","arguments":[]}
{"event":"TestStepStarted","location":"formatter-tests/features/some_scenarions_including_failing.feature:14","timestamp":-6795364578871}
{"event":"TestStepFinished","location":"formatter-tests/features/some_scenarions_including_failing.feature:14","timestamp":-6795364578871,"status":"skipped"}
{"event":"TestCaseFinished","location":"formatter-tests/features/some_scenarions_including_failing.feature:12","timestamp":-6795364578871,"status":"undefined"}
{"event":"TestRunFinished","status":"failed","timestamp":-6795364578871,"snippets":"You can implement step definitions for undefined steps with these snippets:\n\nfunc undefined() error {\n\treturn godog.ErrPending\n}\n\nfunc FeatureContext(s *godog.Suite) {\n\ts.Step(`^undefined$`, undefined)\n}\n","memory":""}

Просмотреть файл

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="junit" tests="0" skipped="0" failures="0" errors="0" time="0">
<testsuite name="empty feature" tests="0" skipped="0" failures="0" errors="0" time="0"></testsuite>
</testsuites>

Просмотреть файл

@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites name="junit" tests="0" skipped="0" failures="0" errors="0" time="0">
<testsuite name="empty feature" tests="0" skipped="0" failures="0" errors="0" time="0"></testsuite>
</testsuites>

Просмотреть файл

@ -1,5 +0,0 @@
<bold-white>Feature:</bold-white> empty feature
No scenarios
No steps
0s

Просмотреть файл

@ -1,8 +0,0 @@
<bold-white>Feature:</bold-white> empty feature
describes
an empty
feature
No scenarios
No steps
0s

Просмотреть файл

@ -1,38 +0,0 @@
<bold-white>Feature:</bold-white> some scenarios
<bold-white>Scenario:</bold-white> failing <bold-black># formatter-tests/features/some_scenarions_including_failing.feature:3</bold-black>
<green>Given</green> <green>passing step</green> <bold-black># formatters_print_test.go:63 -> passingStepDef</bold-black>
<red>When</red> <red>failing step</red> <bold-black># formatters_print_test.go:79 -> failingStepDef</bold-black>
<bold-red>step failed</bold-red>
<cyan>Then</cyan> <cyan>passing step</cyan> <bold-black># formatters_print_test.go:63 -> passingStepDef</bold-black>
<bold-white>Scenario:</bold-white> pending <bold-black># formatter-tests/features/some_scenarions_including_failing.feature:8</bold-black>
<yellow>When</yellow> <yellow>pending step</yellow> <bold-black># formatters_print_test.go:77 -> pendingStepDef</bold-black>
<yellow>TODO: write pending definition</yellow>
<cyan>Then</cyan> <cyan>passing step</cyan> <bold-black># formatters_print_test.go:63 -> passingStepDef</bold-black>
<bold-white>Scenario:</bold-white> undefined <bold-black># formatter-tests/features/some_scenarions_including_failing.feature:12</bold-black>
<yellow>When</yellow> <yellow>undefined</yellow>
<cyan>Then</cyan> <cyan>passing step</cyan> <bold-black># formatters_print_test.go:63 -> passingStepDef</bold-black>
--- <red>Failed steps:</red>
<red>Scenario: failing</red> <bold-black># formatter-tests/features/some_scenarions_including_failing.feature:3</bold-black>
<red>When failing step</red> <bold-black># formatter-tests/features/some_scenarions_including_failing.feature:5</bold-black>
<red>Error: </red><bold-red>step failed</bold-red>
3 scenarios (<red>1 failed</red>, <yellow>1 pending</yellow>, <yellow>1 undefined</yellow>)
7 steps (<green>1 passed</green>, <red>1 failed</red>, <yellow>1 pending</yellow>, <yellow>1 undefined</yellow>, <cyan>3 skipped</cyan>)
0s
<yellow>You can implement step definitions for undefined steps with these snippets:</yellow>
<yellow>
func undefined() error {
return godog.ErrPending
}
func FeatureContext(s *godog.Suite) {
s.Step(`^undefined$`, undefined)
}
</yellow>

Просмотреть файл

@ -1,24 +0,0 @@
<green>.</green><red>F</red><cyan>-</cyan><yellow>P</yellow><cyan>-</cyan><yellow>U</yellow><cyan>-</cyan> 7
--- <red>Failed steps:</red>
<red>Scenario: failing</red><bold-black> # formatter-tests/features/some_scenarions_including_failing.feature:3</bold-black>
<red>When failing step</red><bold-black> # formatter-tests/features/some_scenarions_including_failing.feature:5</bold-black>
<red>Error: </red><bold-red>step failed</bold-red>
3 scenarios (<red>1 failed</red>, <yellow>1 pending</yellow>, <yellow>1 undefined</yellow>)
7 steps (<green>1 passed</green>, <red>1 failed</red>, <yellow>1 pending</yellow>, <yellow>1 undefined</yellow>, <cyan>3 skipped</cyan>)
0s
<yellow>You can implement step definitions for undefined steps with these snippets:</yellow>
<yellow>
func undefined() error {
return godog.ErrPending
}
func FeatureContext(s *godog.Suite) {
s.Step(`^undefined$`, undefined)
}
</yellow>

108
formatters/fmt.go Обычный файл
Просмотреть файл

@ -0,0 +1,108 @@
package formatters
import (
"io"
"regexp"
messages "github.com/cucumber/messages/go/v21"
)
type registeredFormatter struct {
name string
description string
fmt FormatterFunc
}
var registeredFormatters []*registeredFormatter
// FindFmt searches available formatters registered
// and returns FormaterFunc matched by given
// format name or nil otherwise
func FindFmt(name string) FormatterFunc {
for _, el := range registeredFormatters {
if el.name == name {
return el.fmt
}
}
return nil
}
// Format registers a feature suite output
// formatter by given name, description and
// FormatterFunc constructor function, to initialize
// formatter with the output recorder.
func Format(name, description string, f FormatterFunc) {
registeredFormatters = append(registeredFormatters, &registeredFormatter{
name: name,
fmt: f,
description: description,
})
}
// AvailableFormatters gives a map of all
// formatters registered with their name as key
// and description as value
func AvailableFormatters() map[string]string {
fmts := make(map[string]string, len(registeredFormatters))
for _, f := range registeredFormatters {
fmts[f.name] = f.description
}
return fmts
}
// Formatter is an interface for feature runner
// output summary presentation.
//
// New formatters may be created to represent
// suite results in different ways. These new
// formatters needs to be registered with a
// godog.Format function call
type Formatter interface {
TestRunStarted()
Feature(*messages.GherkinDocument, string, []byte)
Pickle(*messages.Pickle)
Defined(*messages.Pickle, *messages.PickleStep, *StepDefinition)
Failed(*messages.Pickle, *messages.PickleStep, *StepDefinition, error)
Passed(*messages.Pickle, *messages.PickleStep, *StepDefinition)
Skipped(*messages.Pickle, *messages.PickleStep, *StepDefinition)
Undefined(*messages.Pickle, *messages.PickleStep, *StepDefinition)
Pending(*messages.Pickle, *messages.PickleStep, *StepDefinition)
Ambiguous(*messages.Pickle, *messages.PickleStep, *StepDefinition, error)
Summary()
}
// FlushFormatter is a `Formatter` but can be flushed.
type FlushFormatter interface {
Formatter
Flush()
}
// FormatterFunc builds a formatter with given
// suite name and io.Writer to record output
type FormatterFunc func(string, io.Writer) Formatter
// StepDefinition is a registered step definition
// contains a StepHandler and regexp which
// is used to match a step. Args which
// were matched by last executed step
//
// This structure is passed to the formatter
// when step is matched and is either failed
// or successful
type StepDefinition struct {
Expr *regexp.Regexp
Handler interface{}
Keyword Keyword
}
type Keyword int64
const (
Given Keyword = iota
When
Then
None
)

65
formatters/fmt_test.go Обычный файл
Просмотреть файл

@ -0,0 +1,65 @@
package formatters_test
import (
"io"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"git.golang1.ru/softonik/godog"
)
func Test_FindFmt(t *testing.T) {
cases := map[string]bool{
"cucumber": true,
"events": true,
"junit": true,
"pretty": true,
"progress": true,
"unknown": false,
"undef": false,
}
for name, expected := range cases {
t.Run(
name,
func(t *testing.T) {
actual := godog.FindFmt(name)
if expected {
assert.NotNilf(t, actual, "expected %s formatter should be available", name)
} else {
assert.Nilf(t, actual, "expected %s formatter should be available", name)
}
},
)
}
}
func Test_AvailableFormatters(t *testing.T) {
expected := map[string]string{
"cucumber": "Produces cucumber JSON format output.",
"events": "Produces JSON event stream, based on spec: 0.1.0.",
"junit": "Prints junit compatible xml to stdout",
"pretty": "Prints every feature with runtime statuses.",
"progress": "Prints a character per step.",
}
actual := godog.AvailableFormatters()
assert.Equal(t, expected, actual)
}
func Test_Format(t *testing.T) {
actual := godog.FindFmt("Test_Format")
require.Nil(t, actual)
godog.Format("Test_Format", "...", testFormatterFunc)
actual = godog.FindFmt("Test_Format")
assert.NotNil(t, actual)
}
func testFormatterFunc(suiteName string, out io.Writer) godog.Formatter {
return nil
}

Просмотреть файл

@ -1,79 +0,0 @@
package godog
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestPrintingFormatters(t *testing.T) {
features, err := parseFeatures("", []string{"formatter-tests"})
require.NoError(t, err)
var buf bytes.Buffer
out := &tagColorWriter{w: &buf}
suite := &Suite{
features: features,
}
// inlining steps to have same source code line reference
suite.Step(`^(?:a )?failing step`, failingStepDef)
suite.Step(`^(?:a )?pending step$`, pendingStepDef)
suite.Step(`^(?:a )?passing step$`, passingStepDef)
suite.Step(`^odd (\d+) and even (\d+) number$`, oddEvenStepDef)
pkg := os.Getenv("GODOG_TESTED_PACKAGE")
os.Setenv("GODOG_TESTED_PACKAGE", "github.com/cucumber/godog")
for _, feat := range features {
for name := range AvailableFormatters() {
expectOutputPath := strings.Replace(feat.Path, "features", name, 1)
expectOutputPath = strings.TrimSuffix(expectOutputPath, path.Ext(expectOutputPath))
if _, err := os.Stat(expectOutputPath); err != nil {
continue
}
buf.Reset() // flush the output
suite.fmt = FindFmt(name)(name, out) // prepare formatter
suite.features = []*feature{feat} // set the feature
expectedOutput, err := ioutil.ReadFile(expectOutputPath)
require.NoError(t, err)
suite.run()
suite.fmt.Summary()
expected := string(expectedOutput)
actual := buf.String()
assert.Equalf(t, expected, actual, "path: %s", expectOutputPath)
}
}
os.Setenv("GODOG_TESTED_PACKAGE", pkg)
}
func passingStepDef() error { return nil }
func oddEvenStepDef(odd, even int) error { return oddOrEven(odd, even) }
func oddOrEven(odd, even int) error {
if odd%2 == 0 {
return fmt.Errorf("%d is not odd", odd)
}
if even%2 != 0 {
return fmt.Errorf("%d is not even", even)
}
return nil
}
func pendingStepDef() error { return ErrPending }
func failingStepDef() error { return fmt.Errorf("step failed") }

33
go.mod
Просмотреть файл

@ -1,9 +1,32 @@
module github.com/cucumber/godog
module git.golang1.ru/softonik/godog
go 1.13
go 1.24.2
require (
github.com/cucumber/gherkin-go/v9 v9.2.0
github.com/cucumber/messages-go/v9 v9.0.3
github.com/stretchr/testify v1.4.0
git.golang1.ru/softonik/godog_and_gomega v1.0.0
github.com/cucumber/gherkin/go/v26 v26.2.0
github.com/hashicorp/go-memdb v1.3.5
github.com/onsi/gomega v1.37.0
github.com/spf13/cobra v1.7.0
github.com/spf13/pflag v1.0.6
github.com/stretchr/testify v1.10.0
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/net v0.40.0 // indirect
golang.org/x/text v0.25.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
require (
github.com/cucumber/messages/go/v21 v21.0.1
github.com/hashicorp/go-immutable-radix v1.3.1 // indirect
github.com/hashicorp/go-uuid v1.0.2 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
)

81
go.sum
Просмотреть файл

@ -1,33 +1,64 @@
github.com/aslakhellesoy/gox v1.0.100/go.mod h1:AJl542QsKKG96COVsv0N74HHzVQgDIQPceVUh1aeU2M=
github.com/cucumber/gherkin-go/v9 v9.2.0 h1:vxpzP4JtfNSDGH4s0u4TIxv+RaX533MCD+XNakz5kLY=
github.com/cucumber/gherkin-go/v9 v9.2.0/go.mod h1:W/+Z5yOowYWXRMlC6lJvM9LFDAFfsicZ1sstjPKfWWQ=
github.com/cucumber/messages-go/v9 v9.0.3 h1:xXYjyj2aUOdkakEJAQIvP+1Bn2gOQNN+pY5pCRZQZzI=
github.com/cucumber/messages-go/v9 v9.0.3/go.mod h1:TICon2O2emBWMY1eeQvog6b+zK5c+puAFO6avjzC/JA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
git.golang1.ru/softonik/godog_and_gomega v1.0.0 h1:2BhCJnuCW5mnRRFk7hN0thyz6Zj64udGhjVtVrjvmYQ=
git.golang1.ru/softonik/godog_and_gomega v1.0.0/go.mod h1:Xf4wTfJZU3W8dULgIkyou+dd36zZ8Kw2FPD3cr3dR10=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/cucumber/gherkin/go/v26 v26.2.0 h1:EgIjePLWiPeslwIWmNQ3XHcypPsWAHoMCz/YEBKP4GI=
github.com/cucumber/gherkin/go/v26 v26.2.0/go.mod h1:t2GAPnB8maCT4lkHL99BDCVNzCh1d7dBhCLt150Nr/0=
github.com/cucumber/messages/go/v21 v21.0.1 h1:wzA0LxwjlWQYZd32VTlAVDTkW6inOFmSM+RuOwHZiMI=
github.com/cucumber/messages/go/v21 v21.0.1/go.mod h1:zheH/2HS9JLVFukdrsPWoPdmUtmYQAQPLk7w5vWsk5s=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
github.com/hashicorp/go-version v1.0.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
github.com/gofrs/uuid v4.4.0+incompatible h1:3qXRTX8/NbyulANqlc0lchS1gqAVxRgsuW1YrTJupqA=
github.com/gofrs/uuid v4.4.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg=
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144=
github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc=
github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
github.com/hashicorp/go-memdb v1.3.5 h1:b3taDMxCBCBVgyRrS1AZVHO14ubMYZB++QpNhBg+Nyo=
github.com/hashicorp/go-memdb v1.3.5/go.mod h1:8IVKKBkVe+fxFgdFOYxzQQNjz+sWCyHCdIC/+5+Vy1Y=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.2 h1:cfejS+Tpcp13yd5nYHWDI6qVCny6wyX2Mt5SGur2IGE=
github.com/hashicorp/go-uuid v1.0.2/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c=
github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
github.com/onsi/ginkgo/v2 v2.23.3 h1:edHxnszytJ4lD9D5Jjc4tiDkPBZ3siDeJJkUZJJVkp0=
github.com/onsi/ginkgo/v2 v2.23.3/go.mod h1:zXTP6xIp3U8aVuXN8ENK9IXRaTjFnpVB9mGmaSRvxnM=
github.com/onsi/gomega v1.37.0 h1:CdEG8g0S133B4OswTDC/5XPSzE1OeP29QOioj2PID2Y=
github.com/onsi/gomega v1.37.0/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY=
golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

Просмотреть файл

@ -10,10 +10,11 @@ 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:
Feature: ls
In order to see the directory structure
As a UNIX user
@ -30,13 +31,13 @@ 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.
*/
package godog
// Version of package - based on Semantic Versioning 2.0.0 http://semver.org/
const Version = "v0.9.0-rc1"
var Version = "v0.0.0-dev"

Показаны не все изменённые файлы, т.к. их слишком много Показать больше