Skip to content

Commit

Permalink
Fixes #39: Crash on syntax error output after legitimate output + go-…
Browse files Browse the repository at this point in the history
…acc compatibility
  • Loading branch information
Janos Bonic committed Apr 18, 2022
1 parent d03e223 commit 80c7114
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 0 deletions.
2 changes: 2 additions & 0 deletions parser/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ func parse(
pkgTracker.AddOutput(prevErroredPkg, "", evt.Output)
} else if !outputStarted {
prefixChannel <- string(evt.Output)
} else if strings.HasPrefix(string(evt.Output), "exit status ") {
// Ignore go-acc exit status reporting.
} else {
panic(
fmt.Errorf(
Expand Down
36 changes: 36 additions & 0 deletions testdata/go-acc.parser.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"prefix": null,
"downloads": {
"packages": null,
"failed": false,
"reason": ""
},
"packages": [
{
"name": "github.com/haveyoudebuggedit/example",
"result": "FAIL",
"duration": "0s",
"coverage": null,
"output": "nothing_test.go:7:11: expected '(', found Nothing",
"testcases": null,
"reason": "setup failed"
},
{
"name": "github.com/haveyoudebuggedit/example/second",
"result": "PASS",
"duration": "2ms",
"coverage": null,
"output": "",
"testcases": [
{
"name": "TestNothing",
"result": "PASS",
"duration": "0s",
"coverage": null,
"output": ""
}
],
"reason": ""
}
]
}
90 changes: 90 additions & 0 deletions testdata/go-acc.tokenizer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[
{
"action": "run",
"package": "github.com/haveyoudebuggedit/example/second",
"version": "",
"test": "TestNothing",
"elapsed": "0s",
"output": null,
"cached": false,
"coverage": null,
"json": true
},
{
"action": "pass",
"package": "github.com/haveyoudebuggedit/example/second",
"version": "",
"test": "TestNothing",
"elapsed": "0s",
"output": null,
"cached": false,
"coverage": null,
"json": true
},
{
"action": "pass-final",
"package": "github.com/haveyoudebuggedit/example/second",
"version": "",
"test": "",
"elapsed": "0s",
"output": null,
"cached": false,
"coverage": null,
"json": true
},
{
"action": "pass",
"package": "github.com/haveyoudebuggedit/example/second",
"version": "",
"test": "",
"elapsed": "2ms",
"output": null,
"cached": false,
"coverage": null,
"json": true
},
{
"action": "package",
"package": "github.com/haveyoudebuggedit/example",
"version": "",
"test": "",
"elapsed": "0s",
"output": null,
"cached": false,
"coverage": null,
"json": false
},
{
"action": "stdout",
"package": "",
"version": "",
"test": "",
"elapsed": "0s",
"output": "bm90aGluZ190ZXN0LmdvOjc6MTE6IGV4cGVjdGVkICcoJywgZm91bmQgTm90aGluZw==",
"cached": false,
"coverage": null,
"json": false
},
{
"action": "fail",
"package": "github.com/haveyoudebuggedit/example",
"version": "",
"test": "",
"elapsed": "0s",
"output": "c2V0dXAgZmFpbGVk",
"cached": false,
"coverage": null,
"json": false
},
{
"action": "stdout",
"package": "",
"version": "",
"test": "",
"elapsed": "0s",
"output": "ZXhpdCBzdGF0dXMgMQ==",
"cached": false,
"coverage": null,
"json": false
}
]
11 changes: 11 additions & 0 deletions testdata/go-acc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{"Time":"2021-11-27T10:23:01.309620888+01:00","Action":"run","Package":"github.com/haveyoudebuggedit/example/second","Test":"TestNothing"}
{"Time":"2021-11-27T10:23:01.309734731+01:00","Action":"output","Package":"github.com/haveyoudebuggedit/example/second","Test":"TestNothing","Output":"=== RUN TestNothing\n"}
{"Time":"2021-11-27T10:23:01.3097659+01:00","Action":"output","Package":"github.com/haveyoudebuggedit/example/second","Test":"TestNothing","Output":"--- PASS: TestNothing (0.00s)\n"}
{"Time":"2021-11-27T10:23:01.309786588+01:00","Action":"pass","Package":"github.com/haveyoudebuggedit/example/second","Test":"TestNothing","Elapsed":0}
{"Time":"2021-11-27T10:23:01.309799132+01:00","Action":"output","Package":"github.com/haveyoudebuggedit/example/second","Output":"PASS\n"}
{"Time":"2021-11-27T10:23:01.309994377+01:00","Action":"output","Package":"github.com/haveyoudebuggedit/example/second","Output":"ok \tgithub.com/haveyoudebuggedit/example/second\t0.002s\n"}
{"Time":"2021-11-27T10:23:01.310211915+01:00","Action":"pass","Package":"github.com/haveyoudebuggedit/example/second","Elapsed":0.002}
# github.com/haveyoudebuggedit/example
nothing_test.go:7:11: expected '(', found Nothing
FAIL github.com/haveyoudebuggedit/example [setup failed]
exit status 1
36 changes: 36 additions & 0 deletions testdata/multipackage-syntax-reverse.parser.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"prefix": null,
"downloads": {
"packages": null,
"failed": false,
"reason": ""
},
"packages": [
{
"name": "github.com/haveyoudebuggedit/example",
"result": "FAIL",
"duration": "0s",
"coverage": null,
"output": "nothing_test.go:7:11: expected '(', found Nothing",
"testcases": null,
"reason": "setup failed"
},
{
"name": "github.com/haveyoudebuggedit/example/second",
"result": "PASS",
"duration": "2ms",
"coverage": null,
"output": "",
"testcases": [
{
"name": "TestNothing",
"result": "PASS",
"duration": "0s",
"coverage": null,
"output": ""
}
],
"reason": ""
}
]
}
79 changes: 79 additions & 0 deletions testdata/multipackage-syntax-reverse.tokenizer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
[
{
"action": "run",
"package": "github.com/haveyoudebuggedit/example/second",
"version": "",
"test": "TestNothing",
"elapsed": "0s",
"output": null,
"cached": false,
"coverage": null,
"json": true
},
{
"action": "pass",
"package": "github.com/haveyoudebuggedit/example/second",
"version": "",
"test": "TestNothing",
"elapsed": "0s",
"output": null,
"cached": false,
"coverage": null,
"json": true
},
{
"action": "pass-final",
"package": "github.com/haveyoudebuggedit/example/second",
"version": "",
"test": "",
"elapsed": "0s",
"output": null,
"cached": false,
"coverage": null,
"json": true
},
{
"action": "pass",
"package": "github.com/haveyoudebuggedit/example/second",
"version": "",
"test": "",
"elapsed": "2ms",
"output": null,
"cached": false,
"coverage": null,
"json": true
},
{
"action": "package",
"package": "github.com/haveyoudebuggedit/example",
"version": "",
"test": "",
"elapsed": "0s",
"output": null,
"cached": false,
"coverage": null,
"json": false
},
{
"action": "stdout",
"package": "",
"version": "",
"test": "",
"elapsed": "0s",
"output": "bm90aGluZ190ZXN0LmdvOjc6MTE6IGV4cGVjdGVkICcoJywgZm91bmQgTm90aGluZw==",
"cached": false,
"coverage": null,
"json": false
},
{
"action": "fail",
"package": "github.com/haveyoudebuggedit/example",
"version": "",
"test": "",
"elapsed": "0s",
"output": "c2V0dXAgZmFpbGVk",
"cached": false,
"coverage": null,
"json": false
}
]
10 changes: 10 additions & 0 deletions testdata/multipackage-syntax-reverse.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{"Time":"2021-11-27T10:23:01.309620888+01:00","Action":"run","Package":"github.com/haveyoudebuggedit/example/second","Test":"TestNothing"}
{"Time":"2021-11-27T10:23:01.309734731+01:00","Action":"output","Package":"github.com/haveyoudebuggedit/example/second","Test":"TestNothing","Output":"=== RUN TestNothing\n"}
{"Time":"2021-11-27T10:23:01.3097659+01:00","Action":"output","Package":"github.com/haveyoudebuggedit/example/second","Test":"TestNothing","Output":"--- PASS: TestNothing (0.00s)\n"}
{"Time":"2021-11-27T10:23:01.309786588+01:00","Action":"pass","Package":"github.com/haveyoudebuggedit/example/second","Test":"TestNothing","Elapsed":0}
{"Time":"2021-11-27T10:23:01.309799132+01:00","Action":"output","Package":"github.com/haveyoudebuggedit/example/second","Output":"PASS\n"}
{"Time":"2021-11-27T10:23:01.309994377+01:00","Action":"output","Package":"github.com/haveyoudebuggedit/example/second","Output":"ok \tgithub.com/haveyoudebuggedit/example/second\t0.002s\n"}
{"Time":"2021-11-27T10:23:01.310211915+01:00","Action":"pass","Package":"github.com/haveyoudebuggedit/example/second","Elapsed":0.002}
# github.com/haveyoudebuggedit/example
nothing_test.go:7:11: expected '(', found Nothing
FAIL github.com/haveyoudebuggedit/example [setup failed]
6 changes: 6 additions & 0 deletions tokenizer/tokenizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ var stateMachine = []stateChange{
ActionPackage,
stateBetweenTests,
},
{
regexp.MustCompile(`^# (?P<Package>.*)$`),
stateBetweenTests,
ActionPackage,
stateBetweenTests,
},
{
regexp.MustCompile(`^=== RUN\s+(?P<Test>.*)$`),
stateInit,
Expand Down

0 comments on commit 80c7114

Please sign in to comment.