diff --git a/index.js b/index.js index c022ff0..ad43f97 100644 --- a/index.js +++ b/index.js @@ -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 @@ -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) { @@ -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] diff --git a/test/fixtures/child-extra.js b/test/fixtures/child-extra.js index a82a18a..1007865 100644 --- a/test/fixtures/child-extra.js +++ b/test/fixtures/child-extra.js @@ -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' ], @@ -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', diff --git a/test/fixtures/comment-mid-diag-postplan.js b/test/fixtures/comment-mid-diag-postplan.js new file mode 100644 index 0000000..9fa6f4c --- /dev/null +++ b/test/fixtures/comment-mid-diag-postplan.js @@ -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 } } ] ] diff --git a/test/fixtures/comment-mid-diag-postplan.tap b/test/fixtures/comment-mid-diag-postplan.tap new file mode 100644 index 0000000..03b42bd --- /dev/null +++ b/test/fixtures/comment-mid-diag-postplan.tap @@ -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 diff --git a/test/fixtures/comment-mid-diag.js b/test/fixtures/comment-mid-diag.js index 97fdd82..43556cf 100644 --- a/test/fixtures/comment-mid-diag.js +++ b/test/fixtures/comment-mid-diag.js @@ -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' ], @@ -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 } } ] ] diff --git a/test/fixtures/comment-mid-diag.tap b/test/fixtures/comment-mid-diag.tap index f30b571..6f724bd 100644 --- a/test/fixtures/comment-mid-diag.tap +++ b/test/fixtures/comment-mid-diag.tap @@ -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 @@ -8,4 +10,6 @@ not ok 1 - please keep my diags after: comment ... # after diag -# after result +# before 2 +ok 2 +# after 2 diff --git a/test/fixtures/extra-in-child.js b/test/fixtures/extra-in-child.js index 0baa0ef..6b2dbfb 100644 --- a/test/fixtures/extra-in-child.js +++ b/test/fixtures/extra-in-child.js @@ -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' ], @@ -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', diff --git a/test/fixtures/indented-stdout-noise.js b/test/fixtures/indented-stdout-noise.js index 6d4c6ec..4edec9b 100644 --- a/test/fixtures/indented-stdout-noise.js +++ b/test/fixtures/indented-stdout-noise.js @@ -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', @@ -51,8 +55,12 @@ 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' ], @@ -60,14 +68,20 @@ module.exports = [ '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' ], @@ -131,14 +145,14 @@ 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', @@ -146,11 +160,9 @@ module.exports = [ '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' ], @@ -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', @@ -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' ],