Commit a5ee5505 authored by isaacs's avatar isaacs

emit trailing prove-style comments

The better to read the output.  don't emit if they're already present, tho.
parent 979aa696
......@@ -120,6 +120,7 @@ function Parser (options, onComplete) {
if (onComplete)
this.on('complete', onComplete)
this.comments = []
this.results = null
this.braceLevel = null
this.parent = options.parent || null
......@@ -416,7 +417,26 @@ Parser.prototype.end = function (chunk, encoding, cb) {
Parser.prototype.emitComplete = function (skipAll) {
if (!this.results) {
this.results = new FinalResults(!!skipAll, this)
var res = this.results = new FinalResults(!!skipAll, this)
// comment a bit at the end so we know what happened.
// but don't repeat these comments if they're already present.
if (res.plan.end !== res.count && !res.bailout)
this.emitComment('test count(' + res.count +
') != plan(' + res.plan.end + ')', false, true)
if (res.fail > 0 && !res.ok)
this.emitComment('failed ' + res.fail +
(res.count > 1 ? ' of ' + res.count + ' tests'
: ' test'),
false, true)
if (res.todo > 0)
this.emitComment('todo: ' + res.todo, false, true)
if (res.skip > 0)
this.emitComment('skip: ' + res.skip, false, true)
this.emit('complete', this.results)
}
}
......@@ -676,7 +696,17 @@ Parser.prototype.abort = function (message, extra) {
this.end()
}
Parser.prototype.emitComment = function (line, skipLine) {
Parser.prototype.emitComment = function (line, skipLine, noDuplicate) {
if (line.trim().charAt(0) !== '#')
line = '# ' + line
if (line.slice(-1) !== '\n')
line += '\n'
if (noDuplicate && this.comments.indexOf(line) !== -1)
return
this.comments.push(line)
if (this.current || this.extraQueue.length) {
// no way to get here with skipLine being true
this.extraQueue.push(['line', line])
......
......@@ -29,7 +29,7 @@ ok 5 - pass after async kid
1..5
*/}.toString().split('\n').slice(1, -1).join('\n') + '\n'
t.test('bufferd abort', function (t) {
t.test('buffered abort', function (t) {
t.test('with diags', bufferedTest({some: 'diags'}))
t.test('empty diags', bufferedTest({}))
t.test('no diags', bufferedTest())
......@@ -93,7 +93,11 @@ function bufferedTest (d) { return function (t) {
}
]
}
p.on('line', lines.push.bind(lines))
p.on('line', function (line) {
if (line.trim().match(/^# [^S]/))
return
lines.push(line)
})
p.on('complete', function (results) {
t.same(lines, expectLines)
t.same(results, expectResults)
......@@ -150,7 +154,11 @@ function unbufferedTest (d) { return function (t) {
}
]
}
p.on('line', lines.push.bind(lines))
p.on('line', function (line) {
if (line.trim().match(/^# [^S]/))
return
lines.push(line)
})
p.on('complete', function (results) {
t.same(lines, expectLines)
t.same(results, expectResults)
......
......@@ -39,6 +39,10 @@ var expect = [
"bailout",
"# saw that coming"
],
[
"comment",
"# failed 1 of 2 tests\n"
],
[
"complete",
{
......
......@@ -29,6 +29,14 @@
"bailout",
""
],
[
"line",
"# failed 1 test\n"
],
[
"comment",
"# failed 1 test\n"
],
[
"complete",
{
......
......@@ -29,6 +29,14 @@
"bailout",
""
],
[
"line",
"# failed 1 test\n"
],
[
"comment",
"# failed 1 test\n"
],
[
"complete",
{
......
......@@ -29,6 +29,14 @@
"bailout",
""
],
[
"line",
"# failed 1 test\n"
],
[
"comment",
"# failed 1 test\n"
],
[
"complete",
{
......
......@@ -29,6 +29,14 @@
"bailout",
""
],
[
"line",
"# failed 1 test\n"
],
[
"comment",
"# failed 1 test\n"
],
[
"complete",
{
......
......@@ -65,6 +65,22 @@
"id": 5
}
],
[
"line",
"# test count(5) != plan(6)\n"
],
[
"comment",
"# test count(5) != plan(6)\n"
],
[
"line",
"# failed 2 of 5 tests\n"
],
[
"comment",
"# failed 2 of 5 tests\n"
],
[
"complete",
{
......
......@@ -65,6 +65,22 @@
"id": 5
}
],
[
"line",
"# test count(5) != plan(6)\n"
],
[
"comment",
"# test count(5) != plan(6)\n"
],
[
"line",
"# failed 2 of 5 tests\n"
],
[
"comment",
"# failed 2 of 5 tests\n"
],
[
"complete",
{
......
......@@ -65,6 +65,22 @@
"id": 5
}
],
[
"line",
"# test count(5) != plan(6)\n"
],
[
"comment",
"# test count(5) != plan(6)\n"
],
[
"line",
"# failed 2 of 5 tests\n"
],
[
"comment",
"# failed 2 of 5 tests\n"
],
[
"complete",
{
......
......@@ -65,6 +65,22 @@
"id": 5
}
],
[
"line",
"# test count(5) != plan(6)\n"
],
[
"comment",
"# test count(5) != plan(6)\n"
],
[
"line",
"# failed 2 of 5 tests\n"
],
[
"comment",
"# failed 2 of 5 tests\n"
],
[
"complete",
{
......
......@@ -70,6 +70,14 @@
}
}
],
[
"line",
"# failed 1 of 5 tests\n"
],
[
"comment",
"# failed 1 of 5 tests\n"
],
[
"complete",
{
......
......@@ -70,6 +70,14 @@
}
}
],
[
"line",
"# failed 1 of 5 tests\n"
],
[
"comment",
"# failed 1 of 5 tests\n"
],
[
"complete",
{
......
......@@ -78,6 +78,14 @@
}
}
],
[
"line",
"# failed 1 of 5 tests\n"
],
[
"comment",
"# failed 1 of 5 tests\n"
],
[
"complete",
{
......
......@@ -78,6 +78,14 @@
}
}
],
[
"line",
"# failed 1 of 5 tests\n"
],
[
"comment",
"# failed 1 of 5 tests\n"
],
[
"complete",
{
......
......@@ -70,6 +70,14 @@
}
}
],
[
"line",
"# failed 1 of 5 tests\n"
],
[
"comment",
"# failed 1 of 5 tests\n"
],
[
"complete",
{
......
......@@ -70,6 +70,14 @@
}
}
],
[
"line",
"# failed 1 of 5 tests\n"
],
[
"comment",
"# failed 1 of 5 tests\n"
],
[
"complete",
{
......
......@@ -78,6 +78,14 @@
}
}
],
[
"line",
"# failed 1 of 5 tests\n"
],
[
"comment",
"# failed 1 of 5 tests\n"
],
[
"complete",
{
......
......@@ -78,6 +78,14 @@
}
}
],
[
"line",
"# failed 1 of 5 tests\n"
],
[
"comment",
"# failed 1 of 5 tests\n"
],
[
"complete",
{
......
......@@ -64,6 +64,22 @@
}
}
],
[
"line",
"# test count(4) != plan(2)\n"
],
[
"comment",
"# test count(4) != plan(2)\n"
],
[
"line",
"# failed 2 of 4 tests\n"
],
[
"comment",
"# failed 2 of 4 tests\n"
],
[
"complete",
{
......
......@@ -64,6 +64,22 @@
}
}
],
[
"line",
"# test count(4) != plan(2)\n"
],
[
"comment",
"# test count(4) != plan(2)\n"
],
[
"line",
"# failed 2 of 4 tests\n"
],
[
"comment",
"# failed 2 of 4 tests\n"
],
[
"complete",
{
......