Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Fix assert event position #20

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,21 @@ Parser.prototype._parse = function (line) {
if (line === '\n')
return

// assert from previous line
if (this.current) {
var indent = line.match(/^[ \t]+/)
if (indent) {
indent = indent[0]
// not beginning of yamlish, and not already in yamlish
if (line !== indent + '---\n' && !this.yind && !this.yamlish) {
this.emitResult()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fails to parse valid tap.

TAP version 13
1..1
not ok 1 - please keep my diags
  # the diags are coming
  ---
  after: comment
  ...

This will cause it to lose the diags and emit them as "extra" lines.

}
// single line assert
} else {
this.emitResult()
}
}

// After a bailout, everything is ignored
if (this.bailedOut)
return
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ module.exports =
[ [ 'line', '1..6\n' ],
[ 'plan', { start: 1, end: 6 } ],
[ 'line', 'not ok\n' ],
[ 'line', 'ok\n' ],
[ 'assert', { ok: false, id: 1 } ],
[ 'line', 'not ok\n' ],
[ 'assert', { ok: true, id: 2 } ],
[ 'line', 'ok\n' ],
[ 'assert', { ok: true, id: 2 } ],
[ 'line', 'not ok\n' ],
[ 'assert', { ok: false, id: 3 } ],
[ 'line', 'ok\n' ],
[ 'assert', { ok: true, id: 4 } ],
[ 'line', 'ok\n' ],
[ 'assert', { ok: true, id: 5 } ],
[ 'complete',
{ ok: false,
Expand Down
4 changes: 2 additions & 2 deletions test/fixtures/broken-yamlish-looks-like-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module.exports =
[ [ 'line', '1..3\n' ],
[ 'plan', { start: 1, end: 3 } ],
[ 'line', 'ok 1 - callback happened\n' ],
[ 'assert', { ok: true, id: 1, name: 'callback happened' } ],
[ 'line', ' ok:\n' ],
[ 'extra', ' ok:\n' ],
[ 'line', ' - I wished for a bailout!\n' ],
Expand All @@ -13,9 +14,8 @@ module.exports =
[ 'line', ' ...\n' ],
[ 'extra', ' ...\n' ],
[ 'line', 'ok 2 - child test\n' ],
[ 'assert', { ok: true, id: 1, name: 'callback happened' } ],
[ 'line', 'ok 3 - should come last\n' ],
[ 'assert', { ok: true, id: 2, name: 'child test' } ],
[ 'line', 'ok 3 - should come last\n' ],
[ 'assert', { ok: true, id: 3, name: 'should come last' } ],
[ 'complete',
{ ok: true, count: 3, pass: 3, plan: { start: 1, end: 3 } } ] ]
4 changes: 2 additions & 2 deletions test/fixtures/child-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ module.exports =
[ 'line', 'TAP version 13\n' ],
[ 'version', '13' ],
[ 'line', 'ok 1 Should output debugger message\n' ],
[ 'line', '1..1\n' ],
[ 'assert',
{ ok: true, id: 1, name: 'Should output debugger message' } ],
[ 'line', '1..1\n' ],
[ 'plan', { start: 1, end: 1 } ],
[ 'complete',
{ ok: true, count: 1, pass: 1, plan: { start: 1, end: 1 } } ] ] ],
Expand All @@ -34,9 +34,9 @@ module.exports =
[ 'line', ' # ok\n' ],
[ 'comment', ' # ok\n' ],
[ 'line', 'ok 1 - test/debug-test.js # time=537.383ms\n' ],
[ 'line', '1..1\n' ],
[ 'assert',
{ ok: true, id: 1, time: 537.383, name: 'test/debug-test.js' } ],
[ 'line', '1..1\n' ],
[ 'plan', { start: 1, end: 1 } ],
[ 'line', '# time=543.783ms\n' ],
[ 'comment', '# time=543.783ms\n' ],
Expand Down
10 changes: 5 additions & 5 deletions test/fixtures/common-with-explanation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ module.exports =
[ 'line', '#\n' ],
[ 'comment', '#\n' ],
[ 'line', 'ok 1 - The object isa Board\n' ],
[ 'line', 'ok 2 - Board size is zero\n' ],
[ 'assert', { ok: true, id: 1, name: 'The object isa Board' } ],
[ 'line', 'ok 3 - The object isa Tile\n' ],
[ 'line', 'ok 2 - Board size is zero\n' ],
[ 'assert', { ok: true, id: 2, name: 'Board size is zero' } ],
[ 'line', 'ok 4 - Get possible places to put the Tile\n' ],
[ 'line', 'ok 3 - The object isa Tile\n' ],
[ 'assert', { ok: true, id: 3, name: 'The object isa Tile' } ],
[ 'line', 'ok 5 - Placing the tile produces no error\n' ],
[ 'line', 'ok 4 - Get possible places to put the Tile\n' ],
[ 'assert',
{ ok: true, id: 4, name: 'Get possible places to put the Tile' } ],
[ 'line', 'ok 6 - Board size is 1\n' ],
[ 'line', 'ok 5 - Placing the tile produces no error\n' ],
[ 'assert',
{ ok: true, id: 5, name: 'Placing the tile produces no error' } ],
[ 'line', 'ok 6 - Board size is 1\n' ],
[ 'assert', { ok: true, id: 6, name: 'Board size is 1' } ],
[ 'complete',
{ ok: true, count: 6, pass: 6, plan: { start: 1, end: 6 } } ] ]
4 changes: 2 additions & 2 deletions test/fixtures/creative-liberties.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module.exports =
[ [ 'line', 'TAP version 13\n' ],
[ 'version', '13' ],
[ 'line', 'ok - created Board\n' ],
[ 'line', 'ok\n' ],
[ 'assert', { ok: true, id: 1, name: 'created Board' } ],
[ 'line', 'ok\n' ],
[ 'assert', { ok: true, id: 2 } ],
Expand All @@ -16,6 +15,7 @@ module.exports =
[ 'assert', { ok: true, id: 6 } ],
[ 'line', 'ok\n' ],
[ 'assert', { ok: true, id: 7 } ],
[ 'line', 'ok\n' ],
[ 'line', ' ---\n' ],
[ 'line', ' message: "Board layout"\n' ],
[ 'line', ' severity: comment\n' ],
Expand Down Expand Up @@ -49,9 +49,9 @@ module.exports =
' G A G G N R R N R ',
' G R G ' ] } } } ],
[ 'line', 'ok - board has 7 tiles + starter tile\n' ],
[ 'line', '1..9\n' ],
[ 'assert',
{ ok: true, id: 9, name: 'board has 7 tiles + starter tile' } ],
[ 'line', '1..9\n' ],
[ 'plan', { start: 1, end: 9 } ],
[ 'complete',
{ ok: true, count: 9, pass: 9, plan: { start: 1, end: 9 } } ] ]
12 changes: 6 additions & 6 deletions test/fixtures/extra-in-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ module.exports =
[ [ 'line', '# Subtest: update profile\n' ],
[ 'comment', '# Subtest: update profile\n' ],
[ 'line', 'ok 1 - should be equivalent\n' ],
[ 'line', 'ok 2 - should be equivalent\n' ],
[ 'assert', { ok: true, id: 1, name: 'should be equivalent' } ],
[ 'line', '1..2\n' ],
[ 'line', 'ok 2 - should be equivalent\n' ],
[ 'assert', { ok: true, id: 2, name: 'should be equivalent' } ],
[ 'line', '1..2\n' ],
[ 'plan', { start: 1, end: 2 } ],
[ 'complete',
{ ok: true, count: 2, pass: 2, plan: { start: 1, end: 2 } } ] ] ],
[ 'line', ' ok 1 - should be equivalent\n' ],
[ 'line', ' ok 2 - should be equivalent\n' ],
[ 'line', ' 1..2\n' ],
[ 'line', 'ok 1 - update profile # time=43.094ms\n' ],
[ 'line', ' # Subtest: update email\n' ],
[ 'assert',
{ ok: true, id: 1, time: 43.094, name: 'update profile' } ],
[ 'line', ' # Subtest: update email\n' ],
[ 'child',
[ [ 'line', '# Subtest: update email\n' ],
[ 'comment', '# Subtest: update email\n' ],
[ 'line', 'ok 1 - should be equivalent\n' ],
[ 'line', '1..1\n' ],
[ 'assert', { ok: true, id: 1, name: 'should be equivalent' } ],
[ 'line', '1..1\n' ],
[ 'plan', { start: 1, end: 1 } ],
[ 'complete',
{ ok: true, count: 1, pass: 1, plan: { start: 1, end: 1 } } ] ] ],
Expand Down Expand Up @@ -96,9 +96,9 @@ module.exports =
[ 'line', ' ok 1 - should be equivalent\n' ],
[ 'line', ' 1..1\n' ],
[ 'line', 'ok 2 - update email # time=24.16ms\n' ],
[ 'line', '1..2\n' ],
[ 'assert',
{ ok: true, id: 2, time: 24.16, name: 'update email' } ],
[ 'line', '1..2\n' ],
[ 'plan', { start: 1, end: 2 } ],
[ 'complete',
{ ok: true, count: 2, pass: 2, plan: { start: 1, end: 2 } } ] ] ],
Expand Down Expand Up @@ -148,12 +148,12 @@ module.exports =
[ 'line', ' # time=174.236ms\n' ],
[ 'comment', ' # time=174.236ms\n' ],
[ 'line', 'ok 1 - test/01c-user-updates.js # time=339.14ms\n' ],
[ 'line', '1..1\n' ],
[ 'assert',
{ ok: true,
id: 1,
time: 339.14,
name: 'test/01c-user-updates.js' } ],
[ 'line', '1..1\n' ],
[ 'plan', { start: 1, end: 1 } ],
[ 'line', '# time=343.487ms\n' ],
[ 'comment', '# time=343.487ms\n' ],
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/giving-up.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ module.exports =
[ 'line', '1..573\n' ],
[ 'plan', { start: 1, end: 573 } ],
[ 'line', 'not ok 1 - database handle\n' ],
[ 'assert', { ok: false, id: 1, name: 'database handle' } ],
[ 'line', 'Bail out! Couldn\'t connect to database.\n' ],
[ 'bailout', 'Couldn\'t connect to database.' ],
[ 'assert', { ok: false, id: 1, name: 'database handle' } ],
[ 'complete',
{ ok: false,
count: 1,
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/got-spare-tuits.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ module.exports =
[ 'line', '1..4\n' ],
[ 'plan', { start: 1, end: 4 } ],
[ 'line', 'ok 1 - Creating test program\n' ],
[ 'line', 'ok 2 - Test program runs, no error\n' ],
[ 'assert', { ok: true, id: 1, name: 'Creating test program' } ],
[ 'line',
'not ok 3 - infinite loop # TODO halting problem unsolved\n' ],
[ 'line', 'ok 2 - Test program runs, no error\n' ],
[ 'assert',
{ ok: true, id: 2, name: 'Test program runs, no error' } ],
[ 'line',
'not ok 4 - infinite loop 2 # TODO halting problem unsolved\n' ],
'not ok 3 - infinite loop # TODO halting problem unsolved\n' ],
[ 'assert',
{ ok: false,
id: 3,
todo: 'halting problem unsolved',
name: 'infinite loop' } ],
[ 'line',
'not ok 4 - infinite loop 2 # TODO halting problem unsolved\n' ],
[ 'assert',
{ ok: false,
id: 4,
Expand Down
8 changes: 4 additions & 4 deletions test/fixtures/implicit-counter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ module.exports =
[ 'line', '# beep\n' ],
[ 'comment', '# beep\n' ],
[ 'line', 'ok should be equal\n' ],
[ 'line', 'ok should be equivalent\n' ],
[ 'assert', { ok: true, id: 1, name: 'should be equal' } ],
[ 'line', 'ok should be equivalent\n' ],
[ 'assert', { ok: true, id: 2, name: 'should be equivalent' } ],
[ 'line', '# boop\n' ],
[ 'comment', '# boop\n' ],
[ 'line', 'ok should be equal\n' ],
[ 'assert', { ok: true, id: 2, name: 'should be equivalent' } ],
[ 'line', 'ok (unnamed assert)\n' ],
[ 'assert', { ok: true, id: 3, name: 'should be equal' } ],
[ 'line', '1..4\n' ],
[ 'line', 'ok (unnamed assert)\n' ],
[ 'assert', { ok: true, id: 4, name: '(unnamed assert)' } ],
[ 'line', '1..4\n' ],
[ 'plan', { start: 1, end: 4 } ],
[ 'line', '# tests 4\n' ],
[ 'comment', '# tests 4\n' ],
Expand Down
10 changes: 5 additions & 5 deletions test/fixtures/indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ module.exports =
[ 'line', '1..2\n' ],
[ 'plan', { start: 1, end: 2 } ],
[ 'line', 'ok 1 - true is ok # time=1.234ms\n' ],
[ 'line', 'ok 2 - doag is also okay # time=1.234ms\n' ],
[ 'assert',
{ ok: true, id: 1, time: 1.234, name: 'true is ok' } ],
[ 'line', 'ok 2 - doag is also okay # time=1.234ms\n' ],
[ 'assert',
{ ok: true, id: 2, time: 1.234, name: 'doag is also okay' } ],
[ 'complete',
Expand All @@ -23,23 +23,23 @@ module.exports =
[ 'line', ' ok 1 - true is ok # time=1.234ms\n' ],
[ 'line', ' ok 2 - doag is also okay # time=1.234ms\n' ],
[ 'line', 'ok 1 - first # time=2.589ms\n' ],
[ 'line', ' # Subtest: second\n' ],
[ 'assert', { ok: true, id: 1, time: 2.589, name: 'first' } ],
[ 'line', ' # Subtest: second\n' ],
[ 'child',
[ [ 'line', '# Subtest: second\n' ],
[ 'comment', '# Subtest: second\n' ],
[ 'line', 'ok 1 - no plan # time=1.001ms\n' ],
[ 'line', ' # Subtest: this passes\n' ],
[ 'assert', { ok: true, id: 1, time: 1.001, name: 'no plan' } ],
[ 'line', ' # Subtest: this passes\n' ],
[ 'child',
[ [ 'line', '# Subtest: this passes\n' ],
[ 'comment', '# Subtest: this passes\n' ],
[ 'line', '1..3\n' ],
[ 'plan', { start: 1, end: 3 } ],
[ 'line', 'not ok granddaughter # SKIP for no raisin\n' ],
[ 'line', 'ok grandson # time=1.001ms\n' ],
[ 'assert',
{ ok: false, id: 1, skip: 'for no raisin', name: 'granddaughter' } ],
[ 'line', 'ok grandson # time=1.001ms\n' ],
[ 'line', ' ---\n' ],
[ 'line', ' ok: 1\n' ],
[ 'line', ' this: is not tap\n' ],
Expand Down Expand Up @@ -82,9 +82,9 @@ module.exports =
[ 'line', ' this: is not tap or yaml\n' ],
[ 'line', ' it: is garbage\n' ],
[ 'line', 'ok 2 - this passes # time=1.200ms\n' ],
[ 'line', '1..2\n' ],
[ 'assert',
{ ok: true, id: 2, time: 1.2, name: 'this passes' } ],
[ 'line', '1..2\n' ],
[ 'plan', { start: 1, end: 2 } ],
[ 'complete',
{ ok: true, count: 2, pass: 2, plan: { start: 1, end: 2 } } ] ] ],
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/indented-stdout-noise.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ module.exports =
[ 'extra', 'SOFTWARE.\n' ],
[ 'line', ' 1..0\n' ],
[ 'line', 'ok 1 - boom # time=5.26ms\n' ],
[ 'line', '1..1\n' ],
[ 'assert', { ok: true, id: 1, time: 5.26, name: 'boom' } ],
[ 'line', '1..1\n' ],
[ 'plan', { start: 1, end: 1 } ],
[ 'complete',
{ ok: true, count: 1, pass: 1, plan: { start: 1, end: 1 } } ] ] ],
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/missing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ module.exports =
[ 'line', '1..6\n' ],
[ 'plan', { start: 1, end: 6 } ],
[ 'line', 'ok\n' ],
[ 'line', 'ok\n' ],
[ 'assert', { ok: true, id: 1 } ],
[ 'line', 'ok\n' ],
[ 'assert', { ok: true, id: 2 } ],
[ 'line', 'ok\n' ],
[ 'assert', { ok: true, id: 3 } ],
[ 'line', 'ok\n' ],
[ 'assert', { ok: true, id: 4 } ],
[ 'line', 'ok\n' ],
[ 'assert', { ok: true, id: 5 } ],
[ 'complete',
{ ok: false, count: 5, pass: 5, plan: { start: 1, end: 6 } } ] ]
4 changes: 2 additions & 2 deletions test/fixtures/no-numbers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ module.exports =
[ [ 'line', '1..3\n' ],
[ 'plan', { start: 1, end: 3 } ],
[ 'line', 'ok we are good\n' ],
[ 'line', 'not ok 2 we are bad\n' ],
[ 'assert', { ok: true, id: 1, name: 'we are good' } ],
[ 'line', 'ok we are zesty!\n' ],
[ 'line', 'not ok 2 we are bad\n' ],
[ 'assert', { ok: false, id: 2, name: 'we are bad' } ],
[ 'line', 'ok we are zesty!\n' ],
[ 'assert', { ok: true, id: 3, name: 'we are zesty!' } ],
[ 'complete',
{ ok: false,
Expand Down
6 changes: 3 additions & 3 deletions test/fixtures/no-plan.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module.exports =
[ 'line', '# beep\n' ],
[ 'comment', '# beep\n' ],
[ 'line', 'ok 1 should be equal\n' ],
[ 'line', 'ok 2 should be equivalent\n' ],
[ 'assert', { ok: true, id: 1, name: 'should be equal' } ],
[ 'line', 'ok 2 should be equivalent\n' ],
[ 'assert', { ok: true, id: 2, name: 'should be equivalent' } ],
[ 'line', '# boop\n' ],
[ 'comment', '# boop\n' ],
[ 'line', 'ok 3 should be equal\n' ],
[ 'assert', { ok: true, id: 2, name: 'should be equivalent' } ],
[ 'line', 'ok 4 (unnamed assert)\n' ],
[ 'assert', { ok: true, id: 3, name: 'should be equal' } ],
[ 'line', 'ok 4 (unnamed assert)\n' ],
[ 'assert', { ok: true, id: 4, name: '(unnamed assert)' } ],
[ 'complete', { ok: false, count: 4, pass: 4 } ] ]
8 changes: 4 additions & 4 deletions test/fixtures/not-enough.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ module.exports =
[ 'line', '# beep\n' ],
[ 'comment', '# beep\n' ],
[ 'line', 'ok 1 should be equal\n' ],
[ 'line', 'ok 2 should be equivalent\n' ],
[ 'assert', { ok: true, id: 1, name: 'should be equal' } ],
[ 'line', 'ok 2 should be equivalent\n' ],
[ 'assert', { ok: true, id: 2, name: 'should be equivalent' } ],
[ 'line', '# boop\n' ],
[ 'comment', '# boop\n' ],
[ 'line', 'ok 3 should be equal\n' ],
[ 'assert', { ok: true, id: 2, name: 'should be equivalent' } ],
[ 'line', 'ok 4 (unnamed assert)\n' ],
[ 'assert', { ok: true, id: 3, name: 'should be equal' } ],
[ 'line', '1..5\n' ],
[ 'line', 'ok 4 (unnamed assert)\n' ],
[ 'assert', { ok: true, id: 4, name: '(unnamed assert)' } ],
[ 'line', '1..5\n' ],
[ 'plan', { start: 1, end: 5 } ],
[ 'line', '# tests 4\n' ],
[ 'comment', '# tests 4\n' ],
Expand Down
12 changes: 6 additions & 6 deletions test/fixtures/not-ok-todo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ module.exports =
[ [ 'line', '# TAP emitted by Test::More 0.98\n' ],
[ 'comment', '# TAP emitted by Test::More 0.98\n' ],
[ 'line', 'ok 1 - should be equal\n' ],
[ 'assert', { ok: true, id: 1, name: 'should be equal' } ],
[ 'line',
'not ok 2 - should be equivalent # TODO but we will fix it later\n' ],
[ 'assert', { ok: true, id: 1, name: 'should be equal' } ],
[ 'line', '# boop\n' ],
[ 'comment', '# boop\n' ],
[ 'line', 'ok 3 - should be equal\n' ],
[ 'assert',
{ ok: false,
id: 2,
todo: 'but we will fix it later',
name: 'should be equivalent' } ],
[ 'line', 'ok 4 - (unnamed assert)\n' ],
[ 'line', '# boop\n' ],
[ 'comment', '# boop\n' ],
[ 'line', 'ok 3 - should be equal\n' ],
[ 'assert', { ok: true, id: 3, name: 'should be equal' } ],
[ 'line', '1..4\n' ],
[ 'line', 'ok 4 - (unnamed assert)\n' ],
[ 'assert', { ok: true, id: 4, name: '(unnamed assert)' } ],
[ 'line', '1..4\n' ],
[ 'plan', { start: 1, end: 4 } ],
[ 'line', '# Looks like you failed 1 test of 4.\n' ],
[ 'comment', '# Looks like you failed 1 test of 4.\n' ],
Expand Down
Loading