Сравнить коммиты
338 коммитов
v0.9.0-rc1
...
main
Автор | SHA1 | Дата | |
---|---|---|---|
![]() |
6087fc101c | ||
![]() |
f5ec4cadce | ||
![]() |
ccc4a42649 | ||
![]() |
59344caf33 | ||
![]() |
56522e757a | ||
![]() |
bda4071975 | ||
![]() |
af6027bad2 | ||
![]() |
9ad168ae70 | ||
![]() |
4a15650887 | ||
![]() |
6f2a5fef98 | ||
![]() |
4e3e82b79e | ||
![]() |
26dafa0117 | ||
![]() |
3b25e9eb02 | ||
![]() |
78bab577c5 | ||
![]() |
0c030e0a6c | ||
![]() |
1b9806b25b | ||
![]() |
d2686eb13d | ||
![]() |
f0399fda41 | ||
![]() |
13639e7df7 | ||
![]() |
60442133fc | ||
![]() |
74fa488023 | ||
![]() |
4a4fd8ab3a | ||
![]() |
e03da742a5 | ||
![]() |
14fe127e3d | ||
![]() |
e55eab64f7 | ||
![]() |
da4633a421 | ||
![]() |
c5a88f62c2 | ||
![]() |
9b699ff9a8 | ||
![]() |
dc6950b1e3 | ||
![]() |
ecd2dfebbd | ||
![]() |
223efc3b14 | ||
![]() |
8edde7f30c | ||
![]() |
1e7c45eb78 | ||
![]() |
6e4f452389 | ||
![]() |
9b51734429 | ||
![]() |
901da7fa3d | ||
![]() |
bcf6bce793 | ||
![]() |
3abb346b28 | ||
![]() |
9558224cce | ||
![]() |
f85def32ee | ||
![]() |
201e526078 | ||
![]() |
4ade3314e8 | ||
![]() |
c3756d1aa2 | ||
![]() |
095a19b85d | ||
![]() |
7017c73ef8 | ||
![]() |
10407bc5a9 | ||
![]() |
fd3e0d5f9c | ||
![]() |
18088dfc91 | ||
![]() |
da57dd0766 | ||
![]() |
153db4eacb | ||
![]() |
27ad3c245e | ||
![]() |
244de8274a | ||
![]() |
757988328b | ||
![]() |
250d69ab63 | ||
![]() |
5a5631a758 | ||
![]() |
592f1cdb71 | ||
![]() |
888fe3f294 | ||
![]() |
25274b0291 | ||
![]() |
c61a93931d | ||
![]() |
76039dc0d2 | ||
![]() |
4550862450 | ||
![]() |
a37ff90667 | ||
![]() |
6b96d47e70 | ||
![]() |
d3aec7142e | ||
![]() |
75d5cab90d | ||
![]() |
3e0f9026f3 | ||
![]() |
51d164ff57 | ||
![]() |
72db47c519 | ||
![]() |
ea50e4bdfc | ||
![]() |
7f75c5d4ee | ||
![]() |
35820ff9fe | ||
![]() |
3eae6c0437 | ||
![]() |
561cb85371 | ||
![]() |
0dcbfef9be | ||
![]() |
472ea2735d | ||
![]() |
aba6a689a4 | ||
![]() |
dc8c9c4378 | ||
![]() |
6ce2b8696b | ||
![]() |
3bd9e9ca4f | ||
![]() |
17f07d243a | ||
![]() |
bcffb1c829 | ||
![]() |
d4d18646f6 | ||
![]() |
5368ee0229 | ||
![]() |
62d84eedbc | ||
![]() |
c035051d94 | ||
![]() |
0892aced88 | ||
![]() |
0fd767543f | ||
![]() |
2e91c32e91 | ||
![]() |
70b4f7fecb | ||
![]() |
3918bda77b | ||
![]() |
8cd8a8014a | ||
![]() |
714af882bf | ||
![]() |
fca3075757 | ||
![]() |
48af591c17 | ||
![]() |
63d4b1be52 | ||
![]() |
802c8978a2 | ||
![]() |
d7e1e95c04 | ||
![]() |
2264a0037b | ||
![]() |
9007f1f26d | ||
![]() |
c35ea0b236 | ||
![]() |
202882807b | ||
![]() |
fd5b6a1034 | ||
![]() |
6f3e792c52 | ||
![]() |
d45a9aaaa3 | ||
![]() |
b2672bb933 | ||
![]() |
5e176da433 | ||
![]() |
b5400809cd | ||
![]() |
5d705e5b8e | ||
![]() |
c5a86a4e56 | ||
![]() |
99655f7e7e | ||
![]() |
d52a4d3f4d | ||
![]() |
5793a95e1c | ||
![]() |
4ca5ec040b | ||
![]() |
1a795f1dde | ||
![]() |
237a855127 | ||
![]() |
4f2140a09a | ||
![]() |
d77238eef3 | ||
![]() |
6f877d6b03 | ||
![]() |
5efecbaf10 | ||
![]() |
c95871f3ce | ||
![]() |
1c91e6f9ea | ||
![]() |
2695c3f359 | ||
![]() |
1f7231cb42 | ||
![]() |
5001c4f4fe | ||
![]() |
30de46da25 | ||
![]() |
9baac0fdfa | ||
![]() |
a6fef3f171 | ||
![]() |
95278dfd39 | ||
![]() |
1dcc44f35b | ||
![]() |
4d9b548d61 | ||
![]() |
b850b44b48 | ||
![]() |
82bcce7bdc | ||
![]() |
df294698f5 | ||
![]() |
1532a1ceba | ||
![]() |
07b9e82910 | ||
![]() |
477135d2fe | ||
![]() |
86a56351ef | ||
![]() |
239a42468a | ||
![]() |
953acd5d90 | ||
![]() |
dfe99eadf5 | ||
![]() |
7d984effb3 | ||
![]() |
afaebf26c1 | ||
![]() |
d074262d59 | ||
![]() |
92ea38e7ce | ||
![]() |
61730298a5 | ||
![]() |
c6c2a0885b | ||
![]() |
ad7feb3298 | ||
![]() |
8cf3f415b3 | ||
![]() |
f1ca5dc00e | ||
![]() |
09d7d85abf | ||
![]() |
6fb74a5334 | ||
![]() |
b1728ff551 | ||
![]() |
7d343d4e35 | ||
![]() |
15358d20e7 | ||
![]() |
cdbb0ac3f3 | ||
![]() |
48c0e0dd77 | ||
![]() |
17a562ca79 | ||
![]() |
8860b17e67 | ||
![]() |
5566c15759 | ||
![]() |
63fd657a22 | ||
![]() |
fca39e4e89 | ||
![]() |
fbed999ad8 | ||
![]() |
3de6fb09f3 | ||
![]() |
9a335aed22 | ||
![]() |
885805bfd3 | ||
![]() |
15ab3cd84f | ||
![]() |
bd397253a4 | ||
![]() |
f42c85989f | ||
![]() |
8af91e50f6 | ||
![]() |
c6e9cd0e19 | ||
![]() |
ee7ab9c52b | ||
![]() |
f34f37dfd2 | ||
![]() |
d4c6c236b1 | ||
![]() |
7cadaeffdb | ||
![]() |
df8c6e49b4 | ||
![]() |
7547f42e11 | ||
![]() |
5414f3c5da | ||
![]() |
707025de28 | ||
![]() |
9d4b221f7a | ||
![]() |
cdf3bfc099 | ||
![]() |
60e2e2f4df | ||
![]() |
5ac22c454c | ||
![]() |
2b6c9dc82e | ||
![]() |
3bdc35e28e | ||
![]() |
3589a9b1bf | ||
![]() |
1548642333 | ||
![]() |
2b426f8969 | ||
![]() |
2fc2995149 | ||
![]() |
adfc936dd7 | ||
![]() |
74698e52fa | ||
![]() |
59cd5d8e3f | ||
![]() |
69162a0d82 | ||
![]() |
2f80d08545 | ||
![]() |
8ef630bed7 | ||
![]() |
e56f454291 | ||
![]() |
c4aea2e999 | ||
![]() |
d4c18852f0 | ||
![]() |
d4190b06d8 | ||
![]() |
7014a10e2f | ||
![]() |
027a1abf0e | ||
![]() |
ae808ea89b | ||
![]() |
5e994943b3 | ||
![]() |
66793de350 | ||
![]() |
c99a04ca90 | ||
![]() |
41ff4b4a16 | ||
![]() |
daa36b6922 | ||
![]() |
2fa3b9f08c | ||
![]() |
ce8036f79d | ||
![]() |
d0991c8488 | ||
![]() |
722d97bc48 | ||
![]() |
e6223baaff | ||
![]() |
eb6779c4ac | ||
![]() |
6d3da7a27b | ||
![]() |
813312606f | ||
![]() |
783f5e40a3 | ||
![]() |
150c400163 | ||
![]() |
28ad994ad1 | ||
![]() |
99723f8220 | ||
![]() |
4da375f4c0 | ||
![]() |
e38c6ed719 | ||
![]() |
183de20e80 | ||
![]() |
dbd8cdf723 | ||
![]() |
c7d739336b | ||
![]() |
51a387469c | ||
![]() |
cff1e2f197 | ||
![]() |
fc084134a0 | ||
![]() |
2cc5a5548a | ||
![]() |
b7dd08770f | ||
![]() |
7df9dadeb9 | ||
![]() |
1033ce083b | ||
![]() |
376280cfc6 | ||
![]() |
9795588012 | ||
![]() |
46c8dbcbcb | ||
![]() |
0ef3d6d5e1 | ||
![]() |
d9e0ff7489 | ||
![]() |
1d724e2107 | ||
![]() |
6e01c51e3d | ||
![]() |
39940f55bc | ||
![]() |
57422f2015 | ||
![]() |
b717039e16 | ||
![]() |
a03a1b8d2c | ||
![]() |
e61d3558c6 | ||
![]() |
849e8e499b | ||
![]() |
25b1915272 | ||
![]() |
a57f082852 | ||
![]() |
b1a69ae142 | ||
![]() |
18a045f989 | ||
![]() |
cd7663fccf | ||
![]() |
f50bd30ec0 | ||
![]() |
0bd3a0e729 | ||
![]() |
12a387ec46 | ||
![]() |
4356addf9f | ||
![]() |
055f87f731 | ||
![]() |
df3ce739e8 | ||
![]() |
c5a0a58123 | ||
![]() |
0b6b3a7b06 | ||
![]() |
7f46bb3b36 | ||
![]() |
6b2e72016b | ||
![]() |
678c3ae733 | ||
![]() |
f08bd7c463 | ||
![]() |
1deee1058e | ||
![]() |
d0a345e507 | ||
![]() |
55d43e1b59 | ||
![]() |
84e064bd56 | ||
![]() |
43844be3e9 | ||
![]() |
13acd2d219 | ||
![]() |
b0f295dc28 | ||
![]() |
10728fac0b | ||
![]() |
abdd8685e5 | ||
![]() |
a1152ca1c9 | ||
![]() |
3ca7156650 | ||
![]() |
e6227a2e0f | ||
![]() |
7568b291e4 | ||
![]() |
86229dbbf9 | ||
![]() |
0f354e867a | ||
![]() |
45e0973e60 | ||
![]() |
27fc1bb031 | ||
![]() |
d0a28b5a94 | ||
![]() |
700c90b3f0 | ||
![]() |
521a9688b9 | ||
![]() |
bfee72ddec | ||
![]() |
075d624710 | ||
![]() |
8fb7cd9769 | ||
![]() |
0c864f1400 | ||
![]() |
64ede2d482 | ||
![]() |
68d94c03b8 | ||
![]() |
eb36b99512 | ||
![]() |
edfd2a1c3a | ||
![]() |
4da503aab2 | ||
![]() |
d6f491a3dc | ||
![]() |
b8863f42ea | ||
![]() |
172b91ea58 | ||
![]() |
8cd177247a | ||
![]() |
2deda99861 | ||
![]() |
c9206b43f6 | ||
![]() |
11f28803ec | ||
![]() |
4d5024dc24 | ||
![]() |
5afad4dee9 | ||
![]() |
0d1fb60ba0 | ||
![]() |
4871754e06 | ||
![]() |
5d351e86c4 | ||
![]() |
11dde19cd3 | ||
![]() |
7e432e13ed | ||
![]() |
d56cf10d0d | ||
![]() |
e6e66731b5 | ||
![]() |
93abaf53bc | ||
![]() |
0180f9304e | ||
![]() |
ec88ee5226 | ||
![]() |
f8287cd48c | ||
![]() |
d5c7a25361 | ||
![]() |
12946b55d6 | ||
![]() |
315f9e96d8 | ||
![]() |
1b471d62c4 | ||
![]() |
732eff4c29 | ||
![]() |
05db4cc9a9 | ||
![]() |
4bef0c945a | ||
![]() |
3a53f6f6bf | ||
![]() |
1c38b5b245 | ||
![]() |
c64517055d | ||
![]() |
0c0ce69ce5 | ||
![]() |
8a7bb1dc02 | ||
![]() |
5cef7b6577 | ||
![]() |
1b1efd4a3b | ||
![]() |
58bcac6a61 | ||
![]() |
f045623fcf | ||
![]() |
0ab3e09327 | ||
![]() |
568d966cd4 | ||
![]() |
cc800f1231 | ||
![]() |
9d238731cf | ||
![]() |
f3c9737402 | ||
![]() |
b6e87e0655 | ||
![]() |
591e055a38 | ||
![]() |
fe2a967670 | ||
![]() |
32741b9662 | ||
![]() |
6e9459c454 | ||
![]() |
2a5f53a04e | ||
![]() |
d76374bf14 | ||
![]() |
eb75d692bd |
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
предоставленный
Обычный файл
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
предоставленный
Обычный файл
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
предоставленный
Обычный файл
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
предоставленный
Обычный файл
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
предоставленный
8
.gitignore
предоставленный
|
@ -4,4 +4,10 @@
|
|||
Gopkg.lock
|
||||
Gopkg.toml
|
||||
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
.idea
|
||||
.vscode
|
||||
|
||||
_artifacts
|
||||
|
||||
vendor
|
||||
|
|
295
CHANGELOG.md
295
CHANGELOG.md
|
@ -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
Обычный файл
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
Обычный файл
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 \
|
||||
'`)
|
||||
}
|
59
Makefile
59
Makefile
|
@ -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
640
README.md
|
@ -1,92 +1,81 @@
|
|||
[](https://circleci.com/gh/cucumber/godog/tree/master)
|
||||
[](https://godoc.org/github.com/cucumber/godog)
|
||||
[](https://github.com/cucumber/godog/actions?query=branch%main+workflow%3Atest)
|
||||
[](https://pkg.go.dev/github.com/cucumber/godog)
|
||||
[](https://codecov.io/gh/cucumber/godog)
|
||||
[](https://oselvar.com/github/cucumber/oselvar-github-metrics/main/cucumber/godog)
|
||||
[](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:
|
||||
|
||||

|
||||
|
||||
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:
|
||||
|
||||

|
||||
|
||||
If you copy the snippets into our test file and run godog again. We should
|
||||
see the step definition is now pending:
|
||||
|
||||

|
||||
|
||||
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.
|
||||
|
||||

|
||||
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
Обычный файл
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.
|
||||
|
||||

|
||||

|
||||
|
||||
### 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`
|
||||
|
||||

|
||||

|
||||
|
||||
### 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
Двоичные данные
_examples/api/screenshots/passed.png
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 75 КиБ После Ширина: | Высота: | Размер: 39 КиБ |
Двоичные данные
_examples/api/screenshots/undefined.png
Двоичные данные
_examples/api/screenshots/undefined.png
Двоичный файл не отображается.
До Ширина: | Высота: | Размер: 99 КиБ После Ширина: | Высота: | Размер: 58 КиБ |
15
_examples/assert-godogs/features/godogs.feature
Обычный файл
15
_examples/assert-godogs/features/godogs.feature
Обычный файл
|
@ -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
Обычный файл
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
Обычный файл
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
Обычный файл
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
Обычный файл
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
|
||||
})
|
||||
}
|
7
_examples/attachments/features/attachments.feature
Обычный файл
7
_examples/attachments/features/attachments.feature
Обычный файл
|
@ -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
Обычный файл
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:
|
||||
|
||||

|
122
_examples/custom-formatter/emoji.go
Обычный файл
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)
|
||||
}
|
||||
}
|
26
_examples/custom-formatter/features/emoji.feature
Обычный файл
26
_examples/custom-formatter/features/emoji.feature
Обычный файл
|
@ -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
Обычный файл
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
Обычный файл
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
Обычный файл
Двоичные данные
_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
Обычный файл
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
Обычный файл
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
Обычный файл
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)
|
||||
}
|
||||
|
|
6
_examples/incorrect-project-structure/README.md
Обычный файл
6
_examples/incorrect-project-structure/README.md
Обычный файл
|
@ -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
|
7
_examples/incorrect-project-structure/go.mod
Обычный файл
7
_examples/incorrect-project-structure/go.mod
Обычный файл
|
@ -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 => ../../
|
71
_examples/incorrect-project-structure/go.sum
Обычный файл
71
_examples/incorrect-project-structure/go.sum
Обычный файл
|
@ -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=
|
7
_examples/incorrect-project-structure/main.go
Обычный файл
7
_examples/incorrect-project-structure/main.go
Обычный файл
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "git.golang1.ru/softonik/godog"
|
||||
|
||||
func InitializeScenario(ctx *godog.ScenarioContext) {
|
||||
|
||||
}
|
28
attachment_test.go
Обычный файл
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)
|
||||
}
|
354
builder.go
354
builder.go
|
@ -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)
|
||||
}
|
||||
}
|
357
builder_test.go
357
builder_test.go
|
@ -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
Обычный файл
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
Обычный файл
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
Обычный файл
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
Обычный файл
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
Обычный файл
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
Обычный файл
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
Обычный файл
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
Обычный файл
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
|
70
flags.go
70
flags.go
|
@ -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
Обычный файл
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
Обычный файл
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
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, ®isteredFormatter{
|
||||
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
|
||||
|
|
310
fmt_cucumber.go
310
fmt_cucumber.go
|
@ -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
|
||||
}
|
254
fmt_events.go
254
fmt_events.go
|
@ -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())
|
||||
}
|
468
fmt_pretty.go
468
fmt_pretty.go
|
@ -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)
|
||||
}
|
148
fmt_progress.go
148
fmt_progress.go
|
@ -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)
|
||||
}
|
72
fmt_test.go
72
fmt_test.go
|
@ -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
Обычный файл
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, ®isteredFormatter{
|
||||
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
Обычный файл
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
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
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=
|
||||
|
|
11
godog.go
11
godog.go
|
@ -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 you’re 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, 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.
|
||||
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"
|
||||
|
|
Показаны не все изменённые файлы, т.к. их слишком много Показать больше
Загрузка…
Создание таблицы
Сослаться в новой задаче