Skip to content

Commit

Permalink
don't let an occupied test slip past endAll
Browse files Browse the repository at this point in the history
Also, don't autoend if already occupied
  • Loading branch information
isaacs committed Feb 18, 2017
1 parent 29156e4 commit 9cba659
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 11 deletions.
35 changes: 24 additions & 11 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand All @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions test/test/before-after-each-raise--bail.tap
Original file line number Diff line number Diff line change
Expand Up @@ -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

3 changes: 3 additions & 0 deletions test/test/before-after-each-throw--bail.tap
Original file line number Diff line number Diff line change
Expand Up @@ -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

14 changes: 14 additions & 0 deletions test/test/unfinished-empty--bail--buffer.tap
Original file line number Diff line number Diff line change
@@ -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

12 changes: 12 additions & 0 deletions test/test/unfinished-empty--bail.tap
Original file line number Diff line number Diff line change
@@ -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

21 changes: 21 additions & 0 deletions test/test/unfinished-empty--buffer.tap
Original file line number Diff line number Diff line change
@@ -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

9 changes: 9 additions & 0 deletions test/test/unfinished-empty.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var t = require('tap')

t.teardown(() => console.log('ok'))

t.test('a', t => {
t.test('b', t => {
// t.pass('ok')
})
})
21 changes: 21 additions & 0 deletions test/test/unfinished-empty.tap
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9cba659

Please sign in to comment.