From 9cba65922e88fe16e092ca0b22e35b51b97a6f53 Mon Sep 17 00:00:00 2001 From: isaacs Date: Sat, 18 Feb 2017 01:36:20 -0800 Subject: [PATCH] don't let an occupied test slip past endAll Also, don't autoend if already occupied --- lib/test.js | 35 ++++++++++++++------ test/test/before-after-each-raise--bail.tap | 3 ++ test/test/before-after-each-throw--bail.tap | 3 ++ test/test/unfinished-empty--bail--buffer.tap | 14 ++++++++ test/test/unfinished-empty--bail.tap | 12 +++++++ test/test/unfinished-empty--buffer.tap | 21 ++++++++++++ test/test/unfinished-empty.js | 9 +++++ test/test/unfinished-empty.tap | 21 ++++++++++++ 8 files changed, 107 insertions(+), 11 deletions(-) create mode 100644 test/test/unfinished-empty--bail--buffer.tap create mode 100644 test/test/unfinished-empty--bail.tap create mode 100644 test/test/unfinished-empty--buffer.tap create mode 100644 test/test/unfinished-empty.js create mode 100644 test/test/unfinished-empty.tap diff --git a/lib/test.js b/lib/test.js index 4e94fed4f..63666570a 100644 --- a/lib/test.js +++ b/lib/test.js @@ -561,7 +561,7 @@ Test.prototype.done = Test.prototype.end = function (implicit) { // beyond here we have to be actually done with things, or else // the semantic checks on counts and such will be off. - if (this.queue.length || this.occupied) { + if (!queueEmpty(this) || this.occupied) { if (!this.pushedEnd) this.queue.push(['end', implicit]) this.pushedEnd = true @@ -661,7 +661,8 @@ Test.prototype.shouldAutoend = function () { var should = ( this.options.autoend && !this.ended && - !this.queue.length && + !this.occupied && + queueEmpty(this) && !this.pool.length && !this.subtests.length && this.planEnd === -1 @@ -702,6 +703,11 @@ function endAllQueue (queue) { queue.push(['end', IMPLICIT]) } +function queueEmpty (t) { + return t.queue.length === 0 || + t.queue.length === 1 && t.queue[0] === 'TAP version 13\n' +} + Test.prototype.endAll = function (sub) { this.processing = true if (this.occupied) { @@ -711,18 +717,25 @@ Test.prototype.endAll = function (sub) { else { p.parser.abort('test unfinished') } - } else if (sub && !this.queue.length) { - var options = Object.keys(this.options).reduce(function (o, k) { - o[k] = this.options[k] - return o - }.bind(this), {}) - this.options.at = null - this.options.stack = '' - options.test = this.name - this.fail('test unfinished', options) + } else if (sub) { + this.process() + if (queueEmpty(this)) { + var options = Object.keys(this.options).reduce(function (o, k) { + o[k] = this.options[k] + return o + }.bind(this), {}) + this.options.at = null + this.options.stack = '' + options.test = this.name + this.fail('test unfinished', options) + } } if (this.promise && this.promise.tapAbortPromise) this.promise.tapAbortPromise() + if (this.occupied) { + this.queue.unshift(this.occupied) + this.occupied = null + } endAllQueue(this.queue) this.processing = false this.process() diff --git a/test/test/before-after-each-raise--bail.tap b/test/test/before-after-each-raise--bail.tap index 146801647..693d38c15 100644 --- a/test/test/before-after-each-raise--bail.tap +++ b/test/test/before-after-each-raise--bail.tap @@ -15,5 +15,8 @@ after 2 grandchild ... Bail out! # this is fine +after 2 child +after 1 child +after 1 parent Bail out! # this is fine diff --git a/test/test/before-after-each-throw--bail.tap b/test/test/before-after-each-throw--bail.tap index ca6654650..f660e1a5d 100644 --- a/test/test/before-after-each-throw--bail.tap +++ b/test/test/before-after-each-throw--bail.tap @@ -15,5 +15,8 @@ after 2 grandchild ... Bail out! # this is fine +after 2 child +after 1 child +after 1 parent Bail out! # this is fine diff --git a/test/test/unfinished-empty--bail--buffer.tap b/test/test/unfinished-empty--bail--buffer.tap new file mode 100644 index 000000000..b33f51782 --- /dev/null +++ b/test/test/unfinished-empty--bail--buffer.tap @@ -0,0 +1,14 @@ +TAP version 13 +not ok 1 - a ___/# time=[0-9.]+(ms)?/~~~ { + not ok 1 - b ___/# time=[0-9.]+(ms)?/~~~ { + not ok 1 - test unfinished + --- + {"at":{"column":5,"file":"test/test/unfinished-empty.js","line":6},"source":"t.test('b', t => {\n","test":"b"} + ... + + Bail out! # test unfinished + } +} +Bail out! # test unfinished +ok + diff --git a/test/test/unfinished-empty--bail.tap b/test/test/unfinished-empty--bail.tap new file mode 100644 index 000000000..0bd111f5c --- /dev/null +++ b/test/test/unfinished-empty--bail.tap @@ -0,0 +1,12 @@ +TAP version 13 +# Subtest: a + # Subtest: b + not ok 1 - test unfinished + --- + {"at":{"column":5,"file":"test/test/unfinished-empty.js","line":6},"source":"t.test('b', t => {\n","test":"b"} + ... + + Bail out! # test unfinished +Bail out! # test unfinished +ok + diff --git a/test/test/unfinished-empty--buffer.tap b/test/test/unfinished-empty--buffer.tap new file mode 100644 index 000000000..a0d62164c --- /dev/null +++ b/test/test/unfinished-empty--buffer.tap @@ -0,0 +1,21 @@ +TAP version 13 +not ok 1 - a ___/# time=[0-9.]+(ms)?/~~~ { + not ok 1 - b ___/# time=[0-9.]+(ms)?/~~~ { + not ok 1 - test unfinished + --- + {"at":{"column":5,"file":"test/test/unfinished-empty.js","line":6},"source":"t.test('b', t => {\n","test":"b"} + ... + + 1..1 + # failed 1 test + } + + 1..1 + # failed 1 test +} + +1..1 +# failed 1 test +___/# time=[0-9.]+(ms)?/~~~ +ok + diff --git a/test/test/unfinished-empty.js b/test/test/unfinished-empty.js new file mode 100644 index 000000000..f55608773 --- /dev/null +++ b/test/test/unfinished-empty.js @@ -0,0 +1,9 @@ +var t = require('tap') + +t.teardown(() => console.log('ok')) + +t.test('a', t => { + t.test('b', t => { + // t.pass('ok') + }) +}) diff --git a/test/test/unfinished-empty.tap b/test/test/unfinished-empty.tap new file mode 100644 index 000000000..4598de9b2 --- /dev/null +++ b/test/test/unfinished-empty.tap @@ -0,0 +1,21 @@ +TAP version 13 +# Subtest: a + # Subtest: b + not ok 1 - test unfinished + --- + {"at":{"column":5,"file":"test/test/unfinished-empty.js","line":6},"source":"t.test('b', t => {\n","test":"b"} + ... + + 1..1 + # failed 1 test + not ok 1 - b ___/# time=[0-9.]+(ms)?/~~~ + + 1..1 + # failed 1 test +not ok 1 - a ___/# time=[0-9.]+(ms)?/~~~ + +1..1 +# failed 1 test +___/# time=[0-9.]+(ms)?/~~~ +ok +