From 5ed11e49272207cc9bbb35f3aa3da48b75acfce1 Mon Sep 17 00:00:00 2001 From: Janos Bonic <86970079+janosdebugs@users.noreply.github.com> Date: Thu, 11 Nov 2021 16:24:22 +0100 Subject: [PATCH] Fixes #2: Incorrect parsing of Testify output (#3) * Fixes #2: Incorrect parsing of Testify output * Added artifact build * Added non-verbose self-test * Longer buffering --- .github/workflows/build.yaml | 11 ++- _testsource/testify/go.mod | 7 ++ _testsource/testify/go.sum | 10 ++ _testsource/testify/testify.go | 1 + _testsource/testify/testify_test.go | 12 +++ _testsource/testifymultipackage/go.mod | 7 ++ _testsource/testifymultipackage/go.sum | 10 ++ .../subpackage1/testify.go | 1 + .../subpackage1/testify_test.go | 12 +++ .../subpackage2/testify.go | 1 + .../subpackage2/testify_test.go | 11 +++ parser/parse.go | 53 +++++++--- testdata/coverage-nostatements.tokenizer.json | 2 +- testdata/coverage.tokenizer.json | 2 +- testdata/gotestfmt.parser.json | 63 ++++++++++++ testdata/gotestfmt.tokenizer.json | 72 ++++++++++++++ testdata/gotestfmt.txt | 6 ++ testdata/mod-download.tokenizer.json | 2 +- testdata/parallel.tokenizer.json | 2 +- .../single-package-verbose.tokenizer.json | 2 +- testdata/subtest.tokenizer.json | 4 +- testdata/syntax-error.tokenizer.json | 2 +- testdata/testify.parser.json | 26 +++++ testdata/testify.tokenizer.json | 98 +++++++++++++++++++ testdata/testify.txt | 10 ++ testdata/testifymultipackage.parser.json | 35 +++++++ testdata/testifymultipackage.tokenizer.json | 98 +++++++++++++++++++ testdata/testifymultipackage.txt | 11 +++ tokenizer/action.go | 6 ++ tokenizer/tokenizer.go | 32 +++++- 30 files changed, 581 insertions(+), 28 deletions(-) create mode 100644 _testsource/testify/go.mod create mode 100644 _testsource/testify/go.sum create mode 100644 _testsource/testify/testify.go create mode 100644 _testsource/testify/testify_test.go create mode 100644 _testsource/testifymultipackage/go.mod create mode 100644 _testsource/testifymultipackage/go.sum create mode 100644 _testsource/testifymultipackage/subpackage1/testify.go create mode 100644 _testsource/testifymultipackage/subpackage1/testify_test.go create mode 100644 _testsource/testifymultipackage/subpackage2/testify.go create mode 100644 _testsource/testifymultipackage/subpackage2/testify_test.go create mode 100644 testdata/gotestfmt.parser.json create mode 100644 testdata/gotestfmt.tokenizer.json create mode 100644 testdata/gotestfmt.txt create mode 100644 testdata/testify.parser.json create mode 100644 testdata/testify.tokenizer.json create mode 100644 testdata/testify.txt create mode 100644 testdata/testifymultipackage.parser.json create mode 100644 testdata/testifymultipackage.tokenizer.json create mode 100644 testdata/testifymultipackage.txt diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 8e3a590..3e34002 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -97,7 +97,11 @@ jobs: - name: Run self-test run: | set -euo pipefail - go test -v ./... 2>&1 | tee /tmp/gotest.log | go run ./cmd/gotestfmt + go test ./... 2>&1 | tee /tmp/gotest.log | go run ./cmd/gotestfmt + - name: Run self-test (verbose) + run: | + set -euo pipefail + go test -v ./... 2>&1 | tee /tmp/gotest-verbose.log | go run ./cmd/gotestfmt - name: Upload test log uses: actions/upload-artifact@v2 with: @@ -132,3 +136,8 @@ jobs: args: release --rm-dist env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: binaries + path: dist \ No newline at end of file diff --git a/_testsource/testify/go.mod b/_testsource/testify/go.mod new file mode 100644 index 0000000..354032c --- /dev/null +++ b/_testsource/testify/go.mod @@ -0,0 +1,7 @@ +module "github.com/haveyoudebuggedit/example" + +go 1.16 + +require ( + github.com/stretchr/testify v1.7.0 +) \ No newline at end of file diff --git a/_testsource/testify/go.sum b/_testsource/testify/go.sum new file mode 100644 index 0000000..b380ae4 --- /dev/null +++ b/_testsource/testify/go.sum @@ -0,0 +1,10 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +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.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/_testsource/testify/testify.go b/_testsource/testify/testify.go new file mode 100644 index 0000000..c992e35 --- /dev/null +++ b/_testsource/testify/testify.go @@ -0,0 +1 @@ +package testify diff --git a/_testsource/testify/testify_test.go b/_testsource/testify/testify_test.go new file mode 100644 index 0000000..77abcd9 --- /dev/null +++ b/_testsource/testify/testify_test.go @@ -0,0 +1,12 @@ +package testify + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestTestify(t *testing.T) { + assert.Equal(t, 50, 48) + +} diff --git a/_testsource/testifymultipackage/go.mod b/_testsource/testifymultipackage/go.mod new file mode 100644 index 0000000..354032c --- /dev/null +++ b/_testsource/testifymultipackage/go.mod @@ -0,0 +1,7 @@ +module "github.com/haveyoudebuggedit/example" + +go 1.16 + +require ( + github.com/stretchr/testify v1.7.0 +) \ No newline at end of file diff --git a/_testsource/testifymultipackage/go.sum b/_testsource/testifymultipackage/go.sum new file mode 100644 index 0000000..b380ae4 --- /dev/null +++ b/_testsource/testifymultipackage/go.sum @@ -0,0 +1,10 @@ +github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +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.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/_testsource/testifymultipackage/subpackage1/testify.go b/_testsource/testifymultipackage/subpackage1/testify.go new file mode 100644 index 0000000..ba7e137 --- /dev/null +++ b/_testsource/testifymultipackage/subpackage1/testify.go @@ -0,0 +1 @@ +package subpackage1 diff --git a/_testsource/testifymultipackage/subpackage1/testify_test.go b/_testsource/testifymultipackage/subpackage1/testify_test.go new file mode 100644 index 0000000..4ac95ad --- /dev/null +++ b/_testsource/testifymultipackage/subpackage1/testify_test.go @@ -0,0 +1,12 @@ +package subpackage1 + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestTestify(t *testing.T) { + assert.Equal(t, 50, 50) + +} diff --git a/_testsource/testifymultipackage/subpackage2/testify.go b/_testsource/testifymultipackage/subpackage2/testify.go new file mode 100644 index 0000000..ba7e137 --- /dev/null +++ b/_testsource/testifymultipackage/subpackage2/testify.go @@ -0,0 +1 @@ +package subpackage1 diff --git a/_testsource/testifymultipackage/subpackage2/testify_test.go b/_testsource/testifymultipackage/subpackage2/testify_test.go new file mode 100644 index 0000000..16df3fe --- /dev/null +++ b/_testsource/testifymultipackage/subpackage2/testify_test.go @@ -0,0 +1,11 @@ +package subpackage1 + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestTestify(t *testing.T) { + assert.Equal(t, 50, 48) +} diff --git a/parser/parse.go b/parser/parse.go index 54429f8..bfcaf29 100644 --- a/parser/parse.go +++ b/parser/parse.go @@ -39,6 +39,8 @@ func parse( } pkgTracker := &packageTracker{ currentPackage: nil, + packageList: []*Package{}, + packages: map[string]*Package{}, testCases: nil, lastTestCase: nil, testCasesByName: map[string]*TestCase{}, @@ -142,16 +144,24 @@ func parse( } case tokenizer.ActionRun: fallthrough + case tokenizer.ActionPass: + fallthrough + case tokenizer.ActionFail: + fallthrough + case tokenizer.ActionSkip: + fallthrough case tokenizer.ActionCont: lastTestCase := pkgTracker.GetLastTestCase() - if lastTestCase.Output == "" { - lastTestCase.Output = string(evt.Output) - } else { - lastTestCase.Output = fmt.Sprintf( - "%s\n%s", - lastTestCase.Output, - string(evt.Output), - ) + if lastTestCase != nil && len(evt.Output) > 0 { + if lastTestCase.Output == "" { + lastTestCase.Output = string(evt.Output) + } else { + lastTestCase.Output = fmt.Sprintf( + "%s\n%s", + lastTestCase.Output, + string(evt.Output), + ) + } } case tokenizer.ActionPackage: lastPackage := pkgTracker.GetPackage() @@ -164,6 +174,12 @@ func parse( string(evt.Output), ) } + case tokenizer.ActionFailFinal: + fallthrough + case tokenizer.ActionPassFinal: + fallthrough + case tokenizer.ActionSkipFinal: + pkgTracker.Write() default: if len(evt.Output) > 0 { panic(fmt.Errorf("unexpected output after %s event: %s", lastAction, evt.Output)) @@ -194,28 +210,32 @@ func finish(evt tokenizer.Event, pkgTracker *packageTracker, result Result) { Coverage: evt.Coverage, }, ) - pkgTracker.Write() } } type packageTracker struct { currentPackage *Package + packages map[string]*Package testCases []*TestCase lastTestCase *TestCase testCasesByName map[string]*TestCase target chan<- *Package + packageList []*Package } func (p *packageTracker) SetPackage(pkg *Package) { if p.currentPackage == nil { pkg.TestCases = p.testCases p.currentPackage = pkg + if _, ok := p.packages[pkg.Name]; !ok { + p.packageList = append(p.packageList, pkg) + p.packages[pkg.Name] = pkg + } + p.testCases = nil return } else if p.currentPackage.Name != pkg.Name { - // Write the current package - p.Write() - p.currentPackage = nil + p.currentPackage = p.packages[pkg.Name] } if pkg.Result != "" { @@ -260,10 +280,13 @@ func (p *packageTracker) Write() { } } p.testCases = nil - } else { - p.target <- p.currentPackage - p.currentPackage = nil } + for _, pkg := range p.packageList { + p.target <- pkg + } + p.packages = map[string]*Package{} + p.packageList = []*Package{} + p.currentPackage = nil p.testCasesByName = map[string]*TestCase{} } diff --git a/testdata/coverage-nostatements.tokenizer.json b/testdata/coverage-nostatements.tokenizer.json index 14b9249..88a8db4 100644 --- a/testdata/coverage-nostatements.tokenizer.json +++ b/testdata/coverage-nostatements.tokenizer.json @@ -8,7 +8,7 @@ "test": "TestNothing" }, { - "action": "pass" + "action": "pass-final" }, { "action": "coverage_nostatements" diff --git a/testdata/coverage.tokenizer.json b/testdata/coverage.tokenizer.json index f832369..7c08637 100644 --- a/testdata/coverage.tokenizer.json +++ b/testdata/coverage.tokenizer.json @@ -8,7 +8,7 @@ "test": "TestNothing" }, { - "action": "pass" + "action": "pass-final" }, { "action": "coverage", diff --git a/testdata/gotestfmt.parser.json b/testdata/gotestfmt.parser.json new file mode 100644 index 0000000..4a3765a --- /dev/null +++ b/testdata/gotestfmt.parser.json @@ -0,0 +1,63 @@ +{ + "prefix": null, + "downloads": { + "packages": null, + "failed": false + }, + "packages": [ + { + "name": "github.com/haveyoudebuggedit/gotestfmt", + "result": "SKIP", + "duration": "0s", + "coverage": null, + "output": "", + "testcases": null, + "reason": "no test files" + }, + { + "name": "github.com/haveyoudebuggedit/gotestfmt/cmd/gotestfmt", + "result": "SKIP", + "duration": "0s", + "coverage": null, + "output": "", + "testcases": null, + "reason": "no test files" + }, + { + "name": "github.com/haveyoudebuggedit/gotestfmt/parser", + "result": "PASS", + "duration": "0s", + "coverage": null, + "output": "", + "testcases": null, + "reason": "" + }, + { + "name": "github.com/haveyoudebuggedit/gotestfmt/renderer", + "result": "SKIP", + "duration": "0s", + "coverage": null, + "output": "", + "testcases": null, + "reason": "no test files" + }, + { + "name": "github.com/haveyoudebuggedit/gotestfmt/testutil", + "result": "SKIP", + "duration": "0s", + "coverage": null, + "output": "", + "testcases": null, + "reason": "no test files" + }, + { + "name": "github.com/haveyoudebuggedit/gotestfmt/tokenizer", + "result": "PASS", + "duration": "0s", + "coverage": null, + "output": "", + "testcases": null, + "reason": "" + } + ] +} \ No newline at end of file diff --git a/testdata/gotestfmt.tokenizer.json b/testdata/gotestfmt.tokenizer.json new file mode 100644 index 0000000..d6c248c --- /dev/null +++ b/testdata/gotestfmt.tokenizer.json @@ -0,0 +1,72 @@ +[ + { + "action": "skip", + "package": "github.com/haveyoudebuggedit/gotestfmt", + "version": "", + "test": "", + "elapsed": "0s", + "output": "bm8gdGVzdCBmaWxlcw==", + "cached": false, + "coverage": null + }, + { + "action": "skip", + "package": "github.com/haveyoudebuggedit/gotestfmt/cmd/gotestfmt", + "version": "", + "test": "", + "elapsed": "0s", + "output": "bm8gdGVzdCBmaWxlcw==", + "cached": false, + "coverage": null + }, + { + "action": "pass", + "package": "github.com/haveyoudebuggedit/gotestfmt/parser", + "version": "", + "test": "", + "elapsed": "0s", + "output": null, + "cached": true, + "coverage": null + }, + { + "action": "skip", + "package": "github.com/haveyoudebuggedit/gotestfmt/renderer", + "version": "", + "test": "", + "elapsed": "0s", + "output": "bm8gdGVzdCBmaWxlcw==", + "cached": false, + "coverage": null + }, + { + "action": "skip", + "package": "github.com/haveyoudebuggedit/gotestfmt/testutil", + "version": "", + "test": "", + "elapsed": "0s", + "output": "bm8gdGVzdCBmaWxlcw==", + "cached": false, + "coverage": null + }, + { + "action": "pass", + "package": "github.com/haveyoudebuggedit/gotestfmt/tokenizer", + "version": "", + "test": "", + "elapsed": "0s", + "output": null, + "cached": true, + "coverage": null + }, + { + "action": "stdout", + "package": "", + "version": "", + "test": "", + "elapsed": "0s", + "output": "", + "cached": false, + "coverage": null + } +] \ No newline at end of file diff --git a/testdata/gotestfmt.txt b/testdata/gotestfmt.txt new file mode 100644 index 0000000..9dbe69c --- /dev/null +++ b/testdata/gotestfmt.txt @@ -0,0 +1,6 @@ +? github.com/haveyoudebuggedit/gotestfmt [no test files] +? github.com/haveyoudebuggedit/gotestfmt/cmd/gotestfmt [no test files] +ok github.com/haveyoudebuggedit/gotestfmt/parser (cached) +? github.com/haveyoudebuggedit/gotestfmt/renderer [no test files] +? github.com/haveyoudebuggedit/gotestfmt/testutil [no test files] +ok github.com/haveyoudebuggedit/gotestfmt/tokenizer (cached) diff --git a/testdata/mod-download.tokenizer.json b/testdata/mod-download.tokenizer.json index fdab595..8a472bb 100644 --- a/testdata/mod-download.tokenizer.json +++ b/testdata/mod-download.tokenizer.json @@ -28,7 +28,7 @@ "test": "TestNothing" }, { - "action": "pass" + "action": "pass-final" }, { "action": "pass", diff --git a/testdata/parallel.tokenizer.json b/testdata/parallel.tokenizer.json index dd193ed..e5b4f7e 100644 --- a/testdata/parallel.tokenizer.json +++ b/testdata/parallel.tokenizer.json @@ -58,7 +58,7 @@ "elapsed": "10.020s" }, { - "action": "pass" + "action": "pass-final" }, { "action": "pass", diff --git a/testdata/single-package-verbose.tokenizer.json b/testdata/single-package-verbose.tokenizer.json index c7331b3..625b5e2 100644 --- a/testdata/single-package-verbose.tokenizer.json +++ b/testdata/single-package-verbose.tokenizer.json @@ -8,7 +8,7 @@ "test": "TestNothing" }, { - "action": "pass" + "action": "pass-final" }, { "action": "pass", diff --git a/testdata/subtest.tokenizer.json b/testdata/subtest.tokenizer.json index 31241d5..e927f9c 100644 --- a/testdata/subtest.tokenizer.json +++ b/testdata/subtest.tokenizer.json @@ -44,7 +44,7 @@ "test": "TestSubtest/test3" }, { - "action": "fail" + "action": "fail-final" }, { "action": "fail", @@ -52,6 +52,6 @@ "elapsed": "0.020s" }, { - "action": "fail" + "action": "fail-final" } ] \ No newline at end of file diff --git a/testdata/syntax-error.tokenizer.json b/testdata/syntax-error.tokenizer.json index 236666d..788458c 100644 --- a/testdata/syntax-error.tokenizer.json +++ b/testdata/syntax-error.tokenizer.json @@ -13,6 +13,6 @@ "output": "c2V0dXAgZmFpbGVk" }, { - "action": "fail" + "action": "fail-final" } ] \ No newline at end of file diff --git a/testdata/testify.parser.json b/testdata/testify.parser.json new file mode 100644 index 0000000..5fd32c1 --- /dev/null +++ b/testdata/testify.parser.json @@ -0,0 +1,26 @@ +{ + "prefix": null, + "downloads": { + "packages": null, + "failed": false + }, + "packages": [ + { + "name": "github.com/haveyoudebuggedit/example", + "result": "FAIL", + "duration": "71ms", + "coverage": null, + "output": "", + "testcases": [ + { + "name": "TestTestify", + "result": "FAIL", + "duration": "0s", + "coverage": null, + "output": " testify_test.go:10:\n Error Trace: testify_test.go:10\n Error: Not equal:\n expected: 50\n actual : 48\n Test: TestTestify" + } + ], + "reason": "" + } + ] +} \ No newline at end of file diff --git a/testdata/testify.tokenizer.json b/testdata/testify.tokenizer.json new file mode 100644 index 0000000..2689c11 --- /dev/null +++ b/testdata/testify.tokenizer.json @@ -0,0 +1,98 @@ +[ + { + "action": "fail", + "package": "", + "version": "", + "test": "TestTestify", + "elapsed": "0s", + "output": null, + "cached": false, + "coverage": null + }, + { + "action": "stdout", + "package": "", + "version": "", + "test": "", + "elapsed": "0s", + "output": "ICAgIHRlc3RpZnlfdGVzdC5nbzoxMDo=", + "cached": false, + "coverage": null + }, + { + "action": "stdout", + "package": "", + "version": "", + "test": "", + "elapsed": "0s", + "output": "ICAgICAgICAgICAgICAgIEVycm9yIFRyYWNlOiAgICB0ZXN0aWZ5X3Rlc3QuZ286MTA=", + "cached": false, + "coverage": null + }, + { + "action": "stdout", + "package": "", + "version": "", + "test": "", + "elapsed": "0s", + "output": "ICAgICAgICAgICAgICAgIEVycm9yOiAgICAgICAgICBOb3QgZXF1YWw6", + "cached": false, + "coverage": null + }, + { + "action": "stdout", + "package": "", + "version": "", + "test": "", + "elapsed": "0s", + "output": "ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBleHBlY3RlZDogNTA=", + "cached": false, + "coverage": null + }, + { + "action": "stdout", + "package": "", + "version": "", + "test": "", + "elapsed": "0s", + "output": "ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhY3R1YWwgIDogNDg=", + "cached": false, + "coverage": null + }, + { + "action": "stdout", + "package": "", + "version": "", + "test": "", + "elapsed": "0s", + "output": "ICAgICAgICAgICAgICAgIFRlc3Q6ICAgICAgICAgICBUZXN0VGVzdGlmeQ==", + "cached": false, + "coverage": null + }, + { + "action": "fail-final" + }, + { + "action": "fail", + "package": "github.com/haveyoudebuggedit/example", + "version": "", + "test": "", + "elapsed": "71ms", + "output": null, + "cached": false, + "coverage": null + }, + { + "action": "fail-final" + }, + { + "action": "stdout", + "package": "", + "version": "", + "test": "", + "elapsed": "0s", + "output": "", + "cached": false, + "coverage": null + } +] \ No newline at end of file diff --git a/testdata/testify.txt b/testdata/testify.txt new file mode 100644 index 0000000..5c5e95b --- /dev/null +++ b/testdata/testify.txt @@ -0,0 +1,10 @@ +--- FAIL: TestTestify (0.00s) + testify_test.go:10: + Error Trace: testify_test.go:10 + Error: Not equal: + expected: 50 + actual : 48 + Test: TestTestify +FAIL +FAIL github.com/haveyoudebuggedit/example 0.071s +FAIL diff --git a/testdata/testifymultipackage.parser.json b/testdata/testifymultipackage.parser.json new file mode 100644 index 0000000..c440f4a --- /dev/null +++ b/testdata/testifymultipackage.parser.json @@ -0,0 +1,35 @@ +{ + "prefix": null, + "downloads": { + "packages": null, + "failed": false + }, + "packages": [ + { + "name": "github.com/haveyoudebuggedit/example/subpackage1", + "result": "PASS", + "duration": "75ms", + "coverage": null, + "output": "", + "testcases": [ + { + "name": "TestTestify", + "result": "FAIL", + "duration": "0s", + "coverage": null, + "output": " testify_test.go:10:\n Error Trace: testify_test.go:10\n Error: Not equal:\n expected: 50\n actual : 48\n Test: TestTestify" + } + ], + "reason": "" + }, + { + "name": "github.com/haveyoudebuggedit/example/subpackage2", + "result": "FAIL", + "duration": "75ms", + "coverage": null, + "output": "", + "testcases": null, + "reason": "" + } + ] +} \ No newline at end of file diff --git a/testdata/testifymultipackage.tokenizer.json b/testdata/testifymultipackage.tokenizer.json new file mode 100644 index 0000000..b727551 --- /dev/null +++ b/testdata/testifymultipackage.tokenizer.json @@ -0,0 +1,98 @@ +[ + { + "action": "pass", + "package": "github.com/haveyoudebuggedit/example/subpackage1", + "version": "", + "test": "", + "elapsed": "75ms", + "output": null, + "cached": false, + "coverage": null + }, + { + "action": "fail", + "package": "", + "version": "", + "test": "TestTestify", + "elapsed": "0s", + "output": null, + "cached": false, + "coverage": null + }, + { + "action": "stdout", + "package": "", + "version": "", + "test": "", + "elapsed": "0s", + "output": "ICAgIHRlc3RpZnlfdGVzdC5nbzoxMDo=", + "cached": false, + "coverage": null + }, + { + "action": "stdout", + "package": "", + "version": "", + "test": "", + "elapsed": "0s", + "output": "ICAgICAgICAgICAgICAgIEVycm9yIFRyYWNlOiAgICB0ZXN0aWZ5X3Rlc3QuZ286MTA=", + "cached": false, + "coverage": null + }, + { + "action": "stdout", + "package": "", + "version": "", + "test": "", + "elapsed": "0s", + "output": "ICAgICAgICAgICAgICAgIEVycm9yOiAgICAgICAgICBOb3QgZXF1YWw6", + "cached": false, + "coverage": null + }, + { + "action": "stdout", + "package": "", + "version": "", + "test": "", + "elapsed": "0s", + "output": "ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBleHBlY3RlZDogNTA=", + "cached": false, + "coverage": null + }, + { + "action": "stdout", + "package": "", + "version": "", + "test": "", + "elapsed": "0s", + "output": "ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBhY3R1YWwgIDogNDg=", + "cached": false, + "coverage": null + }, + { + "action": "stdout", + "package": "", + "version": "", + "test": "", + "elapsed": "0s", + "output": "ICAgICAgICAgICAgICAgIFRlc3Q6ICAgICAgICAgICBUZXN0VGVzdGlmeQ==", + "cached": false, + "coverage": null + }, + { + "action": "fail-final" + }, + { + "action": "fail", + "package": "github.com/haveyoudebuggedit/example/subpackage2", + "version": "", + "test": "", + "elapsed": "75ms", + "output": null, + "cached": false, + "coverage": null + }, + { + "action": "fail-final" + } +] \ No newline at end of file diff --git a/testdata/testifymultipackage.txt b/testdata/testifymultipackage.txt new file mode 100644 index 0000000..f93902e --- /dev/null +++ b/testdata/testifymultipackage.txt @@ -0,0 +1,11 @@ +ok github.com/haveyoudebuggedit/example/subpackage1 0.075s +--- FAIL: TestTestify (0.00s) + testify_test.go:10: + Error Trace: testify_test.go:10 + Error: Not equal: + expected: 50 + actual : 48 + Test: TestTestify +FAIL +FAIL github.com/haveyoudebuggedit/example/subpackage2 0.075s +FAIL \ No newline at end of file diff --git a/tokenizer/action.go b/tokenizer/action.go index 41a8f28..d425f85 100644 --- a/tokenizer/action.go +++ b/tokenizer/action.go @@ -29,4 +29,10 @@ const ( ActionCoverage Action = "coverage" // ActionCoverageNoStatements indicates that there were no code statements to cover. ActionCoverageNoStatements Action = "coverage_nostatements" + // ActionPassFinal is a final PASS line to indicate the entire package has passed. + ActionPassFinal Action = "pass-final" + // ActionFailFinal is a final FAIL line to indicate the entire package has failed. + ActionFailFinal Action = "fail-final" + // ActionSkipFinal is a final SKIP line to indicate the entire package has failed. + ActionSkipFinal Action = "skip-final" ) diff --git a/tokenizer/tokenizer.go b/tokenizer/tokenizer.go index f28d008..72482a0 100644 --- a/tokenizer/tokenizer.go +++ b/tokenizer/tokenizer.go @@ -94,6 +94,12 @@ var stateMachine = []stateChange{ ActionCont, stateRun, }, + { + regexp.MustCompile(`^\s*--- FAIL:\s+(?P[^\s]+) \(((?Pcached)|(?P[^\s]*))\)$`), + stateInit, + ActionFail, + stateBetweenTests, + }, { regexp.MustCompile(`^\s*--- FAIL:\s+(?P[^\s]+) \(((?Pcached)|(?P[^\s]*))\)$`), stateRun, @@ -106,6 +112,12 @@ var stateMachine = []stateChange{ ActionFail, stateBetweenTests, }, + { + regexp.MustCompile(`^\s*--- PASS:\s+(?P[^\s]+) \(((?Pcached)|(?P[^\s]*))\)$`), + stateInit, + ActionPass, + stateBetweenTests, + }, { regexp.MustCompile(`^\s*--- PASS:\s+(?P[^\s]+) \(((?Pcached)|(?P[^\s]*))\)$`), stateRun, @@ -211,25 +223,37 @@ var stateMachine = []stateChange{ { regexp.MustCompile(`^FAIL$`), stateInit, - ActionFail, + ActionFailFinal, stateBetweenTests, }, { regexp.MustCompile(`^FAIL$`), stateBetweenTests, - ActionFail, + ActionFailFinal, stateBetweenTests, }, { regexp.MustCompile(`^PASS$`), stateInit, - ActionPass, + ActionPassFinal, stateBetweenTests, }, { regexp.MustCompile(`^PASS$`), stateBetweenTests, - ActionPass, + ActionPassFinal, + stateBetweenTests, + }, + { + regexp.MustCompile(`^SKIP$`), + stateInit, + ActionSkipFinal, + stateBetweenTests, + }, + { + regexp.MustCompile(`^SKIP$`), + stateBetweenTests, + ActionSkipFinal, stateBetweenTests, }, {