Skip to content

Commit

Permalink
Move all bailOnFail and version parsing to the parser
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jan 5, 2017
1 parent c40ed06 commit 2ed6355
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 72 deletions.
46 changes: 11 additions & 35 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,11 @@ Test.prototype.stdin = function (name, extra, deferred) {
this.comment('Subtest: ' + name)
this._currentChild = stdin
var start = process.hrtime()
var parser = new Parser({ preserveWhitespace: true })
var parser = new Parser({
preserveWhitespace: true,
bail: this._bail,
omitVersion: true
})
var self = this

childStream(self, stdin, parser)
Expand Down Expand Up @@ -737,24 +741,14 @@ function childStream (self, child, parser) {
var emitter = parser || child

if (parser) {
if (self._bail) {
bailOnFail(self, child, parser)
}

child.pipe(parser)
}

emitter.on('bailout', function (reason) {
rootBail(self, reason)
})

var sawVersion = false
emitter.on('line', function onEmitterLine (line) {
if (!sawVersion && line.match(/^TAP version \d+\n$/)) {
sawVersion = true
return
}

line = ' ' + line
self.push(line)
})
Expand Down Expand Up @@ -863,20 +857,19 @@ Test.prototype.spawn = function spawnTest (cmd, args, options, name, extra, defe
child.kill('SIGKILL')
}.bind(this))

var parser = new Parser({ preserveWhitespace: true })
var parser = new Parser({
preserveWhitespace: true,
bail: this._bail,
omitVersion: true
})
var self = this
if (!extra.buffered) {
this.comment('Subtest: ' + name)
childStream(self, child.stdout, parser)
} else {
var buffer = ''
var sawVersion = false
child.stdout.pipe(parser)
parser.on('line', function (line) {
if (!sawVersion && line.match(/^TAP version \d+\n$/)) {
sawVersion = true
return
}
buffer += line
})
}
Expand Down Expand Up @@ -925,7 +918,7 @@ Test.prototype.spawn = function spawnTest (cmd, args, options, name, extra, defe
results.ok = false
}

if (results && results.count === 0 && !signal && !code) {
if (results && results.count === 0 && !signal && !code && !results.bailout) {
extra.skip = 'No tests found'
if (results.plan && results.plan.skipReason) {
extra.skip = results.plan.skipReason
Expand Down Expand Up @@ -1006,23 +999,6 @@ function reportTimeout (stream, parser, extra, ind) {
}
}

function bailOnFail (self, stream, parser, root) {
root = root || parser

parser.on('child', function (c) {
bailOnFail(self, stream, c, root)
})

parser.on('assert', function (res) {
if (!res.todo && !res.skip && !res.ok && res.name.slice(-1) !== '{') {
var ind = new Array(parser.level + 1).join(' ')
var line = ind + 'Bail out! # ' + res.name.trim() + '\n'
root.buffer = ''
root.write(line)
}
})
}

Test.prototype.done = Test.prototype.end = function end (implicit) {
if (this._bailedOut) {
return
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"signal-exit": "^3.0.0",
"stack-utils": "^0.4.0",
"tap-mocha-reporter": "^3.0.0",
"tap-parser": "^3.0.5",
"tap-parser": "^4.1.0",
"tmatch": "^3.0.0"
},
"keywords": [
Expand Down
1 change: 0 additions & 1 deletion test/test/bail-fail-spawn-bail-buffer.tap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ not ok 1 - bail fail {
Bail out! # nested failure
}
}

Bail out! # nested failure
}
}
Expand Down
1 change: 0 additions & 1 deletion test/test/bail-fail-spawn-buffer.tap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ not ok 1 - bail fail {
Bail out! # nested failure
}
}

Bail out! # nested failure
}
}
Expand Down
12 changes: 4 additions & 8 deletions test/test/child-text-buffer-bail-buffer.tap
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ not ok 1 - ___/.*/~~~child-text-buffer.js buffer {
ok 1 - this is fine
not ok 2 - burn
1..2
# failed 1 of 2 tests
Bail out! # burn
}
1..1
# failed 1 of 1 tests
}
1..1
# failed 1 of 1 tests
}
1..1
# failed 1 of 1 tests
Bail out! # burn
}
Bail out! # ___/.*/~~~child-text-buffer.js buffer

Bail out! # burn

15 changes: 4 additions & 11 deletions test/test/child-text-indentsub-bail-buffer.tap
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@ not ok 1 - ___/.*/~~~child-text-indentsub.js indentsub {
ok 1 - this is fine
not ok 2 - burn
1..2
# failed 1 of 2 tests
not ok 1 - grandchild
1..1
# failed 1 of 1 tests
not ok 1 - child
1..1
# failed 1 of 1 tests
not ok 1 - parent
1..1
# failed 1 of 1 tests
Bail out! # burn
Bail out! # burn
}
Bail out! # ___/.*/~~~child-text-indentsub.js indentsub

Bail out! # burn

15 changes: 4 additions & 11 deletions test/test/child-text-sub-bail-buffer.tap
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@ not ok 1 - ___/.*/~~~child-text-sub.js sub {
ok 1 - this is fine
not ok 2 - burn
1..2
# failed 1 of 2 tests
not ok 1 - grandchild
1..1
# failed 1 of 1 tests
not ok 1 - child
1..1
# failed 1 of 1 tests
not ok 1 - parent
1..1
# failed 1 of 1 tests
Bail out! # burn
Bail out! # burn
}
Bail out! # ___/.*/~~~child-text-sub.js sub

Bail out! # burn

1 change: 0 additions & 1 deletion test/test/spawn-bail-buffer.tap
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ not ok 1 - ___/.*/~~~spawn.js child {
Bail out! # nested failure
}
}

Bail out! # nested failure
}

Expand Down
6 changes: 3 additions & 3 deletions test/test/timeout-via-runner-ignore-sigterm-bail-buffer.tap
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ not ok 1 - child {
---
{"at":{"column":5,"file":"test/test/timeout-via-runner-ignore-sigterm.js","line":19},"failure":"timeout","timeout":1000}
...

1..4 # timeout
Bail out! # timeout
}
Bail out! # child

Bail out! # timeout

0 comments on commit 2ed6355

Please sign in to comment.