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

Commit

Permalink
Keep comments in child tests with child test
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed May 31, 2015
1 parent f4429e5 commit c676015
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 37 deletions.
28 changes: 14 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,13 +350,6 @@ Parser.prototype._parse = function (line) {

this.emit('line', line)

// comment, but let "# Subtest:" comments start a child
var c = line.match(/^(\s+)?#(.*)/)
if (c && !(c[1] && /^ Subtest: /.test(c[2]))) {
this.emitComment(line)
return
}

var bailout = line.match(/^bail out!(.*)\n$/i)
if (bailout) {
this.sawValidTap = true
Expand All @@ -375,13 +368,6 @@ Parser.prototype._parse = function (line) {
return
}

// if we got a plan at the end, or a 1..0 plan, then we can't
// have any more results, yamlish, or child sets.
if (this.postPlan) {
this.emit('extra', line)
return
}

// still belongs to the child.
if (this.child) {
if (line.indexOf(this.child.indent) === 0) {
Expand All @@ -397,6 +383,20 @@ Parser.prototype._parse = function (line) {
}
}

// comment, but let "# Subtest:" comments start a child
var c = line.match(/^(\s+)?#(.*)/)
if (c && !(c[1] && /^ Subtest: /.test(c[2]))) {
this.emitComment(line)
return
}

// if we got a plan at the end, or a 1..0 plan, then we can't
// have any more results, yamlish, or child sets.
if (this.postPlan) {
this.emit('extra', line)
return
}

var indent = line.match(/^[ \t]+/)
if (indent) {
indent = indent[0]
Expand Down
12 changes: 8 additions & 4 deletions test/fixtures/child-extra.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@ module.exports =
[ 'comment', '# Subtest: test/debug-test.js\n' ],
[ 'line', 'TAP version 13\n' ],
[ 'version', '13' ],
[ 'line', '# debug test\n' ],
[ 'comment', '# debug test\n' ],
[ 'line', 'ok 1 Should output debugger message\n' ],
[ 'line', '1..1\n' ],
[ 'assert',
{ ok: true, id: 1, name: 'Should output debugger message' } ],
[ 'plan', { start: 1, end: 1 } ],
[ 'line', '# tests 1\n' ],
[ 'comment', '# tests 1\n' ],
[ 'line', '# pass 1\n' ],
[ 'comment', '# pass 1\n' ],
[ 'line', '# ok\n' ],
[ 'comment', '# ok\n' ],
[ 'complete',
{ ok: true, count: 1, pass: 1, plan: { start: 1, end: 1 } } ] ] ],
[ 'line', 'debug test\n' ],
Expand All @@ -22,17 +30,13 @@ module.exports =
[ 'extra', '\'Debugger listening on port 5858\\n\'\n' ],
[ 'line', ' TAP version 13\n' ],
[ 'line', ' # debug test\n' ],
[ 'comment', ' # debug test\n' ],
[ 'line', ' ok 1 Should output debugger message\n' ],
[ 'line', ' \n' ],
[ 'line', ' 1..1\n' ],
[ 'line', ' # tests 1\n' ],
[ 'comment', ' # tests 1\n' ],
[ 'line', ' # pass 1\n' ],
[ 'comment', ' # pass 1\n' ],
[ 'line', ' \n' ],
[ 'line', ' # ok\n' ],
[ 'comment', ' # ok\n' ],
[ 'line', 'ok 1 - test/debug-test.js # time=537.383ms\n' ],
[ 'line', '1..1\n' ],
[ 'assert',
Expand Down
59 changes: 59 additions & 0 deletions test/fixtures/comment-mid-diag-postplan.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module.exports =
[ [ 'line', '# before version\n' ],
[ 'comment', '# before version\n' ],
[ 'line', 'TAP version 13\n' ],
[ 'version', '13' ],
[ 'line', '# after version, before result\n' ],
[ 'comment', '# after version, before result\n' ],
[ 'line', 'not ok 1 - please keep my diags\n' ],
[ 'line', ' # before diag\n' ],
[ 'line', ' ---\n' ],
[ 'line', ' # mid diag\n' ],
[ 'line', ' after: comment\n' ],
[ 'line', ' ...\n' ],
[ 'assert',
{ ok: false,
id: 1,
name: 'please keep my diags',
diag: { after: 'comment' } } ],
[ 'comment', ' # before diag\n' ],
[ 'comment', ' # mid diag\n' ],
[ 'line', ' # after diag\n' ],
[ 'comment', ' # after diag\n' ],
[ 'line', ' # Subtest: child\n' ],
[ 'child',
[ [ 'line', '# Subtest: child\n' ],
[ 'comment', '# Subtest: child\n' ],
[ 'line', '1..2\n' ],
[ 'plan', { start: 1, end: 2 } ],
[ 'line', '# before 1\n' ],
[ 'comment', '# before 1\n' ],
[ 'line', 'ok 1\n' ],
[ 'line', '# before 2\n' ],
[ 'line', 'ok 2\n' ],
[ 'assert', { ok: true, id: 1 } ],
[ 'comment', '# before 2\n' ],
[ 'assert', { ok: true, id: 2 } ],
[ 'complete',
{ ok: true, count: 2, pass: 2, plan: { start: 1, end: 2 } } ] ] ],
[ 'line', ' 1..2\n' ],
[ 'line', ' # before 1\n' ],
[ 'line', ' ok 1\n' ],
[ 'line', ' # before 2\n' ],
[ 'line', ' ok 2\n' ],
[ 'line', '# before 2\n' ],
[ 'extra', '# before 2\n' ],
[ 'line', 'ok 2 - child\n' ],
[ 'line', '# after 2, brefore plan\n' ],
[ 'line', '1..2\n' ],
[ 'assert', { ok: true, id: 2, name: 'child' } ],
[ 'comment', '# after 2, brefore plan\n' ],
[ 'plan', { start: 1, end: 2 } ],
[ 'line', '# after plan\n' ],
[ 'comment', '# after plan\n' ],
[ 'complete',
{ ok: false,
count: 2,
pass: 1,
fail: 1,
plan: { start: 1, end: 2 } } ] ]
21 changes: 21 additions & 0 deletions test/fixtures/comment-mid-diag-postplan.tap
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# before version
TAP version 13
# after version, before result
not ok 1 - please keep my diags
# before diag
---
# mid diag
after: comment
...
# after diag
# Subtest: child
1..2
# before 1
ok 1
# before 2
ok 2
# before 2
ok 2 - child
# after 2, brefore plan
1..2
# after plan
24 changes: 16 additions & 8 deletions test/fixtures/comment-mid-diag.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
module.exports =
[ [ 'line', 'TAP version 13\n' ],
[ [ 'line', '# before version\n' ],
[ 'comment', '# before version\n' ],
[ 'line', 'TAP version 13\n' ],
[ 'version', '13' ],
[ 'line', '1..1\n' ],
[ 'plan', { start: 1, end: 1 } ],
[ 'line', '# after version, before plan\n' ],
[ 'comment', '# after version, before plan\n' ],
[ 'line', '1..2\n' ],
[ 'plan', { start: 1, end: 2 } ],
[ 'line', '# before result\n' ],
[ 'comment', '# before result\n' ],
[ 'line', 'not ok 1 - please keep my diags\n' ],
Expand All @@ -20,11 +24,15 @@ module.exports =
[ 'comment', ' # mid diag\n' ],
[ 'line', ' # after diag\n' ],
[ 'comment', ' # after diag\n' ],
[ 'line', '# after result\n' ],
[ 'comment', '# after result\n' ],
[ 'line', '# before 2\n' ],
[ 'comment', '# before 2\n' ],
[ 'line', 'ok 2\n' ],
[ 'line', '# after 2\n' ],
[ 'assert', { ok: true, id: 2 } ],
[ 'comment', '# after 2\n' ],
[ 'complete',
{ ok: false,
count: 1,
pass: 0,
count: 2,
pass: 1,
fail: 1,
plan: { start: 1, end: 1 } } ] ]
plan: { start: 1, end: 2 } } ] ]
8 changes: 6 additions & 2 deletions test/fixtures/comment-mid-diag.tap
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# before version
TAP version 13
1..1
# after version, before plan
1..2
# before result
not ok 1 - please keep my diags
# before diag
Expand All @@ -8,4 +10,6 @@ not ok 1 - please keep my diags
after: comment
...
# after diag
# after result
# before 2
ok 2
# after 2
3 changes: 2 additions & 1 deletion test/fixtures/extra-in-child.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ module.exports =
[ 'assert',
{ ok: true, id: 2, time: 24.16, name: 'update email' } ],
[ 'plan', { start: 1, end: 2 } ],
[ 'line', '# time=174.236ms\n' ],
[ 'comment', '# time=174.236ms\n' ],
[ 'complete',
{ ok: true, count: 2, pass: 2, plan: { start: 1, end: 2 } } ] ] ],
[ 'line', ' TAP version 13\n' ],
Expand Down Expand Up @@ -146,7 +148,6 @@ module.exports =
[ 'line', ' ok 2 - update email # time=24.16ms\n' ],
[ 'line', ' 1..2\n' ],
[ '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',
Expand Down
24 changes: 16 additions & 8 deletions test/fixtures/indented-stdout-noise.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ module.exports =
count: 0,
pass: 0,
plan: { start: 1, end: 0, skipAll: true } } ] ] ],
[ 'line', '# package - Easy package.json exports.\n' ],
[ 'comment', '# package - Easy package.json exports.\n' ],
[ 'line', '## Intro\n' ],
[ 'comment', '## Intro\n' ],
[ 'line',
'This module provides an easy way to export package.json data.\n' ],
[ 'extra',
Expand All @@ -51,23 +55,33 @@ module.exports =
'find your package.json file automatically. Cool, ugh?\n' ],
[ 'extra',
'find your package.json file automatically. Cool, ugh?\n' ],
[ 'line', '## Installation\n' ],
[ 'comment', '## Installation\n' ],
[ 'line', ' # Subtest: npm install package line\n' ],
[ 'line', ' $ npm install package\n' ],
[ 'line', '## Usage\n' ],
[ 'comment', '## Usage\n' ],
[ 'line',
' var package = require(\'package\')(); // contains package.json data.\n' ],
[ 'line', ' \n' ],
[ 'line', ' var yourAwesomeModule = {};\n' ],
[ 'line', ' \n' ],
[ 'line',
' yourAwesomeModule.version = package.version;\n' ],
[ 'line', '## Contribution\n' ],
[ 'comment', '## Contribution\n' ],
[ 'line', 'Bug fixes and features are welcomed.\n' ],
[ 'extra', 'Bug fixes and features are welcomed.\n' ],
[ 'line', '## Other similar modules\n' ],
[ 'comment', '## Other similar modules\n' ],
[ 'line',
'- pkginfo (https://github.com/indexzero/node-pkginfo) by indexzero.\n' ],
[ 'extra',
'- pkginfo (https://github.com/indexzero/node-pkginfo) by indexzero.\n' ],
[ 'line', '- JSON.parse + fs.readFile\n' ],
[ 'extra', '- JSON.parse + fs.readFile\n' ],
[ 'line', '## License\n' ],
[ 'comment', '## License\n' ],
[ 'line', 'MIT License\n' ],
[ 'extra', 'MIT License\n' ],
[ 'line', 'Copyright (C) 2011 Veselin Todorov\n' ],
Expand Down Expand Up @@ -131,26 +145,24 @@ module.exports =
[ 'line', '1..1\n' ],
[ 'assert', { ok: true, id: 1, time: 5.26, name: 'boom' } ],
[ 'plan', { start: 1, end: 1 } ],
[ 'line', '# time=12.555ms\n' ],
[ 'comment', '# time=12.555ms\n' ],
[ 'complete',
{ ok: true, count: 1, pass: 1, plan: { start: 1, end: 1 } } ] ] ],
[ 'line', ' TAP version 13\n' ],
[ 'line', ' # Subtest: boom\n' ],
[ 'line', ' # package - Easy package.json exports.\n' ],
[ 'comment', ' # package - Easy package.json exports.\n' ],
[ 'line', ' ## Intro\n' ],
[ 'comment', ' ## Intro\n' ],
[ 'line',
' This module provides an easy way to export package.json data.\n' ],
[ 'line',
' It contains auto-discovery functionality, which means that it will\n' ],
[ 'line',
' find your package.json file automatically. Cool, ugh?\n' ],
[ 'line', ' ## Installation\n' ],
[ 'comment', ' ## Installation\n' ],
[ 'line', ' # Subtest: npm install package line\n' ],
[ 'line', ' $ npm install package\n' ],
[ 'line', ' ## Usage\n' ],
[ 'comment', ' ## Usage\n' ],
[ 'line',
' var package = require(\'package\')(); // contains package.json data.\n' ],
[ 'line', ' \n' ],
Expand All @@ -159,15 +171,12 @@ module.exports =
[ 'line',
' yourAwesomeModule.version = package.version;\n' ],
[ 'line', ' ## Contribution\n' ],
[ 'comment', ' ## Contribution\n' ],
[ 'line', ' Bug fixes and features are welcomed.\n' ],
[ 'line', ' ## Other similar modules\n' ],
[ 'comment', ' ## Other similar modules\n' ],
[ 'line',
' - pkginfo (https://github.com/indexzero/node-pkginfo) by indexzero.\n' ],
[ 'line', ' - JSON.parse + fs.readFile\n' ],
[ 'line', ' ## License\n' ],
[ 'comment', ' ## License\n' ],
[ 'line', ' MIT License\n' ],
[ 'line', ' Copyright (C) 2011 Veselin Todorov\n' ],
[ 'line',
Expand Down Expand Up @@ -202,7 +211,6 @@ module.exports =
[ 'line', ' ok 1 - boom # time=5.26ms\n' ],
[ 'line', ' 1..1\n' ],
[ 'line', ' # time=12.555ms\n' ],
[ 'comment', ' # time=12.555ms\n' ],
[ 'line', 'not ok 1 - index.js # time=201.609ms\n' ],
[ 'line', ' ---\n' ],
[ 'line', ' arguments:\n' ],
Expand Down

0 comments on commit c676015

Please sign in to comment.