Skip to content

Commit 2ed6355

Browse files
committed
Move all bailOnFail and version parsing to the parser
1 parent c40ed06 commit 2ed6355

9 files changed

+27
-72
lines changed

lib/test.js

+11-35
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,11 @@ Test.prototype.stdin = function (name, extra, deferred) {
681681
this.comment('Subtest: ' + name)
682682
this._currentChild = stdin
683683
var start = process.hrtime()
684-
var parser = new Parser({ preserveWhitespace: true })
684+
var parser = new Parser({
685+
preserveWhitespace: true,
686+
bail: this._bail,
687+
omitVersion: true
688+
})
685689
var self = this
686690

687691
childStream(self, stdin, parser)
@@ -737,24 +741,14 @@ function childStream (self, child, parser) {
737741
var emitter = parser || child
738742

739743
if (parser) {
740-
if (self._bail) {
741-
bailOnFail(self, child, parser)
742-
}
743-
744744
child.pipe(parser)
745745
}
746746

747747
emitter.on('bailout', function (reason) {
748748
rootBail(self, reason)
749749
})
750750

751-
var sawVersion = false
752751
emitter.on('line', function onEmitterLine (line) {
753-
if (!sawVersion && line.match(/^TAP version \d+\n$/)) {
754-
sawVersion = true
755-
return
756-
}
757-
758752
line = ' ' + line
759753
self.push(line)
760754
})
@@ -863,20 +857,19 @@ Test.prototype.spawn = function spawnTest (cmd, args, options, name, extra, defe
863857
child.kill('SIGKILL')
864858
}.bind(this))
865859

866-
var parser = new Parser({ preserveWhitespace: true })
860+
var parser = new Parser({
861+
preserveWhitespace: true,
862+
bail: this._bail,
863+
omitVersion: true
864+
})
867865
var self = this
868866
if (!extra.buffered) {
869867
this.comment('Subtest: ' + name)
870868
childStream(self, child.stdout, parser)
871869
} else {
872870
var buffer = ''
873-
var sawVersion = false
874871
child.stdout.pipe(parser)
875872
parser.on('line', function (line) {
876-
if (!sawVersion && line.match(/^TAP version \d+\n$/)) {
877-
sawVersion = true
878-
return
879-
}
880873
buffer += line
881874
})
882875
}
@@ -925,7 +918,7 @@ Test.prototype.spawn = function spawnTest (cmd, args, options, name, extra, defe
925918
results.ok = false
926919
}
927920

928-
if (results && results.count === 0 && !signal && !code) {
921+
if (results && results.count === 0 && !signal && !code && !results.bailout) {
929922
extra.skip = 'No tests found'
930923
if (results.plan && results.plan.skipReason) {
931924
extra.skip = results.plan.skipReason
@@ -1006,23 +999,6 @@ function reportTimeout (stream, parser, extra, ind) {
1006999
}
10071000
}
10081001

1009-
function bailOnFail (self, stream, parser, root) {
1010-
root = root || parser
1011-
1012-
parser.on('child', function (c) {
1013-
bailOnFail(self, stream, c, root)
1014-
})
1015-
1016-
parser.on('assert', function (res) {
1017-
if (!res.todo && !res.skip && !res.ok && res.name.slice(-1) !== '{') {
1018-
var ind = new Array(parser.level + 1).join(' ')
1019-
var line = ind + 'Bail out! # ' + res.name.trim() + '\n'
1020-
root.buffer = ''
1021-
root.write(line)
1022-
}
1023-
})
1024-
}
1025-
10261002
Test.prototype.done = Test.prototype.end = function end (implicit) {
10271003
if (this._bailedOut) {
10281004
return

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"signal-exit": "^3.0.0",
3030
"stack-utils": "^0.4.0",
3131
"tap-mocha-reporter": "^3.0.0",
32-
"tap-parser": "^3.0.5",
32+
"tap-parser": "^4.1.0",
3333
"tmatch": "^3.0.0"
3434
},
3535
"keywords": [

test/test/bail-fail-spawn-bail-buffer.tap

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ not ok 1 - bail fail {
1919
Bail out! # nested failure
2020
}
2121
}
22-
2322
Bail out! # nested failure
2423
}
2524
}

test/test/bail-fail-spawn-buffer.tap

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ not ok 1 - bail fail {
1919
Bail out! # nested failure
2020
}
2121
}
22-
2322
Bail out! # nested failure
2423
}
2524
}

test/test/child-text-buffer-bail-buffer.tap

+4-8
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,12 @@ not ok 1 - ___/.*/~~~child-text-buffer.js buffer {
66
ok 1 - this is fine
77
not ok 2 - burn
88
1..2
9-
# failed 1 of 2 tests
9+
Bail out! # burn
1010
}
11-
1..1
12-
# failed 1 of 1 tests
1311
}
14-
1..1
15-
# failed 1 of 1 tests
1612
}
17-
1..1
18-
# failed 1 of 1 tests
13+
Bail out! # burn
1914
}
20-
Bail out! # ___/.*/~~~child-text-buffer.js buffer
15+
16+
Bail out! # burn
2117

test/test/child-text-indentsub-bail-buffer.tap

+4-11
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,9 @@ not ok 1 - ___/.*/~~~child-text-indentsub.js indentsub {
66
ok 1 - this is fine
77
not ok 2 - burn
88
1..2
9-
# failed 1 of 2 tests
10-
not ok 1 - grandchild
11-
1..1
12-
# failed 1 of 1 tests
13-
not ok 1 - child
14-
1..1
15-
# failed 1 of 1 tests
16-
not ok 1 - parent
17-
1..1
18-
# failed 1 of 1 tests
9+
Bail out! # burn
10+
Bail out! # burn
1911
}
20-
Bail out! # ___/.*/~~~child-text-indentsub.js indentsub
12+
13+
Bail out! # burn
2114

test/test/child-text-sub-bail-buffer.tap

+4-11
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,9 @@ not ok 1 - ___/.*/~~~child-text-sub.js sub {
66
ok 1 - this is fine
77
not ok 2 - burn
88
1..2
9-
# failed 1 of 2 tests
10-
not ok 1 - grandchild
11-
1..1
12-
# failed 1 of 1 tests
13-
not ok 1 - child
14-
1..1
15-
# failed 1 of 1 tests
16-
not ok 1 - parent
17-
1..1
18-
# failed 1 of 1 tests
9+
Bail out! # burn
10+
Bail out! # burn
1911
}
20-
Bail out! # ___/.*/~~~child-text-sub.js sub
12+
13+
Bail out! # burn
2114

test/test/spawn-bail-buffer.tap

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ not ok 1 - ___/.*/~~~spawn.js child {
1818
Bail out! # nested failure
1919
}
2020
}
21-
2221
Bail out! # nested failure
2322
}
2423

test/test/timeout-via-runner-ignore-sigterm-bail-buffer.tap

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ not ok 1 - child {
99
---
1010
{"at":{"column":5,"file":"test/test/timeout-via-runner-ignore-sigterm.js","line":19},"failure":"timeout","timeout":1000}
1111
...
12-
13-
1..4 # timeout
12+
Bail out! # timeout
1413
}
15-
Bail out! # child
14+
15+
Bail out! # timeout
1616

0 commit comments

Comments
 (0)