tap-parser
Advanced tools
Comparing version 4.2.4 to 5.0.0
130
index.js
@@ -123,2 +123,4 @@ // Transforms a stream of TAP into a stream of result objects | ||
this.results = null | ||
this.braceLevel = null | ||
this.parent = options.parent || null | ||
@@ -161,3 +163,5 @@ this.failures = [] | ||
Parser.prototype.tapError = function (error) { | ||
Parser.prototype.tapError = function (error, line) { | ||
if (line) | ||
this.emit('line', line) | ||
this.ok = false | ||
@@ -173,3 +177,3 @@ this.fail ++ | ||
Parser.prototype.parseTestPoint = function (testPoint) { | ||
Parser.prototype.parseTestPoint = function (testPoint, line) { | ||
this.emitResult() | ||
@@ -179,2 +183,3 @@ if (this.bailedOut) | ||
this.emit('line', line) | ||
var res = new Result(testPoint, this.count) | ||
@@ -220,2 +225,11 @@ if (this.planStart !== -1) { | ||
// emit each line, then the extra as a whole | ||
data.split('\n').slice(0, -1).forEach(function (line) { | ||
line += '\n' | ||
if (this.current || this.extraQueue.length) | ||
this.extraQueue.push(['line', line]) | ||
else | ||
this.emit('line', line) | ||
}, this) | ||
if (this.current || this.extraQueue.length) | ||
@@ -253,3 +267,3 @@ this.extraQueue.push(['extra', data]) | ||
} | ||
}) | ||
}, line) | ||
else | ||
@@ -273,2 +287,3 @@ this.nonTap(line) | ||
this.emit('line', line) | ||
this.emit('plan', p) | ||
@@ -312,16 +327,4 @@ } | ||
this.current.diag = diags | ||
// we still don't emit the result here yet, to support: | ||
// | ||
// ok 1 - child | ||
// --- | ||
// some: diags | ||
// ... | ||
// { | ||
// 1..1 | ||
// ok | ||
// } | ||
// unless it's failure, and we're going to bail anyway. | ||
if (!this.current.ok && this.bail) { | ||
this.emitResult() | ||
} | ||
// we still don't emit the result here yet, to support diags | ||
// that come ahead of buffered subtests. | ||
} | ||
@@ -348,3 +351,3 @@ | ||
this.buffer = this.buffer.substr(match[0].length) | ||
this._parse(match[0]) | ||
this.parse(match[0]) | ||
} while (this.buffer.length) | ||
@@ -414,9 +417,14 @@ | ||
var final = new FinalResults(!!skipAll, this) | ||
this.emitComplete(skipAll) | ||
this.emit('complete', final) | ||
Writable.prototype.end.call(this, null, null, cb) | ||
} | ||
Parser.prototype.emitComplete = function (skipAll) { | ||
if (!this.results) { | ||
this.results = new FinalResults(!!skipAll, this) | ||
this.emit('complete', this.results) | ||
} | ||
} | ||
function FinalResults (skipAll, self) { | ||
@@ -444,5 +452,9 @@ this.ok = self.ok | ||
// If version is specified, must be at the very beginning. | ||
if (version >= 13 && this.planStart === -1 && this.count === 0) | ||
if (version >= 13 && | ||
this.planStart === -1 && | ||
this.count === 0 && | ||
!this.current) { | ||
this.emit('line', line) | ||
this.emit('version', version) | ||
else | ||
} else | ||
this.nonTap(line) | ||
@@ -466,2 +478,3 @@ } | ||
this.pragmas[key] = value | ||
this.emit('line', line) | ||
this.emit('pragma', key, value) | ||
@@ -480,6 +493,18 @@ } | ||
this.emitResult() | ||
if (!synthetic) | ||
this.emitResult() | ||
else | ||
this.current = null | ||
this.bailedOut = this.bailingOut | ||
this.ok = false | ||
if (!synthetic) { | ||
// synthetic bailouts get emitted on end | ||
var line = 'Bail out!' | ||
if (reason) | ||
line += ' ' + reason | ||
this.emit('line', line + '\n') | ||
} | ||
this.emit('bailout', reason) | ||
this.emitComplete(false) | ||
if (this.parent) | ||
@@ -538,3 +563,3 @@ this.parent.bailout(reason, true) | ||
var bailName = res.name ? ' # ' + res.name : '' | ||
p._parse(ind + 'Bail out!' + bailName + '\n') | ||
p.parse(ind + 'Bail out!' + bailName + '\n') | ||
} | ||
@@ -615,15 +640,22 @@ this.clearExtraQueue() | ||
this.emit('child', this.child) | ||
this.child.emitComment(subtestComment) | ||
if (!this.child.buffered) | ||
this.emit('line', subtestComment) | ||
this.child.emitComment(subtestComment, true) | ||
if (line) | ||
this.child._parse(line) | ||
this.child.parse(line) | ||
} | ||
Parser.prototype.emitComment = function (line) { | ||
if (this.current || this.extraQueue.length) | ||
Parser.prototype.emitComment = function (line, skipLine) { | ||
if (this.current || this.extraQueue.length) { | ||
// no way to get here with skipLine being true | ||
this.extraQueue.push(['line', line]) | ||
this.extraQueue.push(['comment', line]) | ||
else | ||
} else { | ||
if (!skipLine) | ||
this.emit('line', line) | ||
this.emit('comment', line) | ||
} | ||
} | ||
Parser.prototype._parse = function (line) { | ||
Parser.prototype.parse = function (line) { | ||
// normalize line endings | ||
@@ -643,4 +675,13 @@ line = line.replace(/\r\n$/, '\n') | ||
// end of a buffered child test. Anything else should be ignored. | ||
if (this.bailingOut && !/^\s*}\n$/.test(line)) | ||
return | ||
// But! if we're bailing out a nested child, and ANOTHER nested child | ||
// comes after that one, then we don't want the second child's } to | ||
// also show up, or it looks weird. | ||
if (this.bailingOut) { | ||
if (!/^\s*}\n$/.test(line)) | ||
return | ||
else if (!this.braceLevel || line.length < this.braceLevel) | ||
this.braceLevel = line.length | ||
else | ||
return | ||
} | ||
@@ -661,12 +702,12 @@ // This allows omitting even parsing the version if the test is | ||
// this is a line we are processing, so emit it | ||
var validLine = this.preserveWhitespace || line.trim() || this.yind | ||
if (validLine) | ||
this.emit('line', line) | ||
// In any case where we're going to emitResult, that can trigger | ||
// a bailout, so we need to only emit the line once we know that | ||
// isn't happening, to prevent cases where there's a bailout, and | ||
// then one more line of output. That'll also prevent the case | ||
// where the test point is emitted AFTER the line that follows it. | ||
if (line === '\n') | ||
return | ||
// buffered subtests must end with a } | ||
if (this.child && this.child.buffered && line === '}\n') { | ||
this.endChild() | ||
this.emit('line', line) | ||
this.emitResult() | ||
@@ -676,2 +717,7 @@ return | ||
// just a \n, emit only if we care about whitespace | ||
var validLine = this.preserveWhitespace || line.trim() || this.yind | ||
if (line === '\n') | ||
return validLine && this.emit('line', line) | ||
// buffered subtest with diagnostics | ||
@@ -681,2 +727,3 @@ if (this.current && line === '{\n' && | ||
!this.child) { | ||
this.emit('line', line) | ||
this.current.buffered = true | ||
@@ -743,3 +790,2 @@ return | ||
// streamed subtests will end when this test point is emitted | ||
@@ -757,3 +803,3 @@ if (type[0] === 'testPoint') { | ||
// rewrite, so I'm allowing it as it currently is. | ||
this.parseTestPoint(type[1]) | ||
this.parseTestPoint(type[1], line) | ||
return | ||
@@ -760,0 +806,0 @@ } |
{ | ||
"name": "tap-parser", | ||
"version": "4.2.4", | ||
"version": "5.0.0", | ||
"description": "parse the test anything protocol", | ||
@@ -15,3 +15,3 @@ "main": "index.js", | ||
"glob": "^7.0.5", | ||
"tap": "^8.0.1" | ||
"tap": "^9.0.3" | ||
}, | ||
@@ -18,0 +18,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
891
39296
328