Skip to content

Commit

Permalink
Prune some excessive diagnostic output
Browse files Browse the repository at this point in the history
Also, move the code around a little bit so that it'll be more
straightforward to have yaml diagnostics ahead of buffered child test
output once that's supported by the parser.
  • Loading branch information
isaacs committed Jan 7, 2017
1 parent 8aeb886 commit 55c23c5
Show file tree
Hide file tree
Showing 33 changed files with 59 additions and 263 deletions.
83 changes: 49 additions & 34 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,14 @@ function loop (self, arr, cb, i) {
}
}

function childExtra (extra, results) {
if (results && results.failures) {
extra.failures = results.failures
}
extra.at = null
delete extra.stack
}

Test.prototype._runChild = function runChild (child, name, extra, cb) {
var self = this
var results
Expand All @@ -562,7 +570,7 @@ Test.prototype._runChild = function runChild (child, name, extra, cb) {
})
child.on('end', function () {
ended = true
extra.results = results
childExtra(extra, results)
self._currentChild = null
var time = results ? '# time=' + results.time + 'ms' : ''
if (extra.buffered) {
Expand All @@ -573,10 +581,9 @@ Test.prototype._runChild = function runChild (child, name, extra, cb) {
}

// if the child already bailed, then don't _also_ bail for this
self.ok(child._ok, child._name, {
_tapChildBuffer: child._buffer,
_tapChildBailed: child._bailedOut
})
extra._tapChildBuffer = child._buffer
extra._tapChildBailed = child._bailedOut
self.ok(child._ok, child._name, extra)

if (endThis) {
self._ending = false
Expand Down Expand Up @@ -901,7 +908,8 @@ Test.prototype.spawn = function spawnTest (cmd, args, options, name, extra, defe
child.on('close', function onclose (code, signal) {
clearTimeout(timer)
self._currentChild = null
extra.results = results
childExtra(extra, results)

var dur = process.hrtime(start)
var time = Math.round(dur[0] * 1e6 + dur[1] / 1e3) / 1e3
time = '# time=' + time + 'ms'
Expand All @@ -918,7 +926,8 @@ Test.prototype.spawn = function spawnTest (cmd, args, options, name, extra, defe
results.ok = false
}

if (results && results.count === 0 && !signal && !code && !results.bailout) {
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 @@ -1337,6 +1346,7 @@ Test.prototype.printResult = function printResult (ok, message, extra) {
var bailed = false
if (extra._tapChildBuffer) {
buffer = extra._tapChildBuffer
extra.buffered = true
delete extra._tapChildBuffer
if (extra._tapChildBailed) {
bailed = true
Expand Down Expand Up @@ -1393,8 +1403,34 @@ Test.prototype.printResult = function printResult (ok, message, extra) {
}
}

var diagnostic = process.env.TAP_DIAG === '1'
if (!ok) {
diagnostic = true
}
if (extra.skip) {
diagnostic = false
}
if (process.env.TAP_DIAG === '0') {
diagnostic = false
}
if (typeof extra.diagnostic === 'boolean') {
diagnostic = extra.diagnostic
}
if (buffer) {
this.push(' {')
// XXX remove when parser can handle diags along with buffer
diagnostic = false
}
if (diagnostic) {
diagnostic = this.writeDiags(extra)
}

// If we're skipping, no need for diags.
// Also, never print diags if there's a child buffer to show
if (buffer) {
if (!diagnostic) {
this.push(' ')
}
this.push('{')
}

if (!ok && !extra.todo && !extra.skip) {
Expand All @@ -1403,28 +1439,9 @@ Test.prototype.printResult = function printResult (ok, message, extra) {

this.push('\n')

// If we're skipping, no need for diags.
// Also, never print diags if there's a child buffer to show
if (buffer) {
var b = buffer.trim().split('\n').join('\n ') + '\n'
this.push(' ' + b + '}\n')
} else {
var diagnostic = process.env.TAP_DIAG === '1'
if (!ok) {
diagnostic = true
}
if (extra.skip) {
diagnostic = false
}
if (process.env.TAP_DIAG === '0') {
diagnostic = false
}
if (typeof extra.diagnostic === 'boolean') {
diagnostic = extra.diagnostic
}
if (diagnostic) {
this.writeDiags(extra)
}
}

if (this._bail && !ok && !extra.skip && !extra.todo && !bailed) {
Expand All @@ -1449,10 +1466,12 @@ function yamlFilter (propertyName, isRoot, source, target) {
}

return !(propertyName === 'todo' ||
propertyName === '_tapChildBuffer' ||
propertyName === '_tapChildBailed' ||
propertyName === 'skip' ||
propertyName === 'diagnostic' ||
propertyName === 'buffered' ||
(propertyName === 'at' && !source[propertyName]))
(propertyName === 'at' && !source.at))
}

Test.prototype.writeDiags = function (extra) {
Expand All @@ -1479,19 +1498,15 @@ Test.prototype.writeDiags = function (extra) {
}
}

if (extra.buffered === true || extra.buffered === false) {
delete extra.buffered
}

// some objects are not suitable for yaml.
var obj = cleanYamlObject(extra, yamlFilter)

if (obj && typeof obj === 'object' && Object.keys(obj).length) {
var y = yaml.safeDump(obj).split('\n').map(function (l) {
return l.trim() ? ' ' + l : l.trim()
}).join('\n')
y = ' ---\n' + y + ' ...\n'
this.push(y)
y = ' ---\n' + y + ' ...'
this.push('\n' + y)
}
}

Expand Down
3 changes: 0 additions & 3 deletions test/test/assert-at.tap
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ TAP version 13
1..4
# failed 4 of 4 tests
not ok 1 - foo ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":3,"file":"test/test/assert-at.js","line":33},"results":{"count":4,"fail":4,"ok":false,"pass":0,"plan":{"end":4,"start":1}},"source":"t.test(foo)\n"}
...

1..1
# failed 1 of 1 tests
Expand Down
9 changes: 0 additions & 9 deletions test/test/before-after-each-promise.tap
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,17 @@ after 2 undefined
1..2
# failed 1 of 2 tests
not ok 1 - grandchild ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":7,"file":"test/test/before-after-each-promise.js","line":35},"results":{"count":2,"fail":1,"ok":false,"pass":1,"plan":{"end":2,"start":1}},"source":"t.test('grandchild', function (t) {\n"}
...

after 2 undefined
after 1 child
1..1
# failed 1 of 1 tests
not ok 1 - child ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":5,"file":"test/test/before-after-each-promise.js","line":34},"results":{"count":1,"fail":1,"ok":false,"pass":0,"plan":{"end":1,"start":1}},"source":"t.test('child', function (t) {\n"}
...

after 1 parent
1..1
# failed 1 of 1 tests
not ok 1 - parent ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":3,"file":"test/test/before-after-each-promise.js","line":17},"results":{"count":1,"fail":1,"ok":false,"pass":0,"plan":{"end":1,"start":1}},"source":"t.test('parent', function (t) {\n"}
...

1..1
# failed 1 of 1 tests
Expand Down
9 changes: 0 additions & 9 deletions test/test/before-after-each-raise.tap
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,17 @@ after 2 grandchild
1..2
# failed 1 of 2 tests
not ok 1 - grandchild ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":7,"file":"test/test/before-after-each-raise.js","line":28},"results":{"count":2,"fail":1,"ok":false,"pass":1,"plan":{"end":2,"start":1}},"source":"t.test('grandchild', function (t) {\n"}
...

after 2 child
after 1 child
1..1
# failed 1 of 1 tests
not ok 1 - child ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":5,"file":"test/test/before-after-each-raise.js","line":27},"results":{"count":1,"fail":1,"ok":false,"pass":0,"plan":{"end":1,"start":1}},"source":"t.test('child', function (t) {\n"}
...

after 1 parent
1..1
# failed 1 of 1 tests
not ok 1 - parent ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":3,"file":"test/test/before-after-each-raise.js","line":13},"results":{"count":1,"fail":1,"ok":false,"pass":0,"plan":{"end":1,"start":1}},"source":"t.test('parent', function (t) {\n"}
...

done
1..1
Expand Down
9 changes: 0 additions & 9 deletions test/test/before-after-each-throw.tap
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,17 @@ after 2 grandchild
1..2
# failed 1 of 2 tests
not ok 1 - grandchild ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":7,"file":"test/test/before-after-each-throw.js","line":30},"results":{"count":2,"fail":1,"ok":false,"pass":1,"plan":{"end":2,"start":1}},"source":"t.test('grandchild', function (t) {\n"}
...

after 2 child
after 1 child
1..1
# failed 1 of 1 tests
not ok 1 - child ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":5,"file":"test/test/before-after-each-throw.js","line":29},"results":{"count":1,"fail":1,"ok":false,"pass":0,"plan":{"end":1,"start":1}},"source":"t.test('child', function (t) {\n"}
...

after 1 parent
1..1
# failed 1 of 1 tests
not ok 1 - parent ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":3,"file":"test/test/before-after-each-throw.js","line":13},"results":{"count":1,"fail":1,"ok":false,"pass":0,"plan":{"end":1,"start":1}},"source":"t.test('parent', function (t) {\n"}
...

done
1..1
Expand Down
3 changes: 0 additions & 3 deletions test/test/equivalent.tap
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ TAP version 13
1..6
# failed 6 of 6 tests
not ok 1 - child test ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":3,"file":"test/test/equivalent.js","line":2},"results":{"count":6,"fail":6,"ok":false,"pass":0,"plan":{"end":6,"start":1}},"source":"t.test('child test', function (t) {\n"}
...

1..1
# failed 1 of 1 tests
Expand Down
15 changes: 0 additions & 15 deletions test/test/mochalike.tap
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ ok 4 - reasonably indented things ___/# time=[0-9.]+(ms)?/~~~
# failed 1 of 2 tests
# todo: 2
not ok 1 - first subset ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":3,"file":"test/test/mochalike.js","line":52},"results":{"count":2,"fail":1,"ok":false,"pass":1,"plan":{"end":2,"start":1},"todo":2},"source":"describe('first subset', function () {\n"}
...

# Subtest: second subset
not ok 1 - AssertionError: objectify the truthiness
Expand All @@ -64,16 +61,10 @@ ok 4 - reasonably indented things ___/# time=[0-9.]+(ms)?/~~~
1..1
# failed 1 of 1 tests
not ok 2 - second subset ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":3,"file":"test/test/mochalike.js","line":59},"results":{"count":1,"fail":1,"ok":false,"pass":0,"plan":{"end":1,"start":1}},"source":"describe('second subset', function () {\n"}
...

1..2
# failed 2 of 2 tests
not ok 5 - failing indented things ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":1,"file":"test/test/mochalike.js","line":51},"results":{"count":2,"fail":2,"ok":false,"pass":0,"plan":{"end":2,"start":1}},"source":"describe('failing indented things', function () {\n"}
...

# Subtest: a test passing an error to done() callback
# Subtest: is marked as failed
Expand All @@ -84,16 +75,10 @@ not ok 5 - failing indented things ___/# time=[0-9.]+(ms)?/~~~
1..1
# failed 1 of 1 tests
not ok 1 - is marked as failed ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":3,"file":"test/test/mochalike.js","line":66},"results":{"count":1,"fail":1,"ok":false,"pass":0,"plan":{"end":1,"start":1}},"source":"it('is marked as failed', function (done) {\n"}
...

1..1
# failed 1 of 1 tests
not ok 6 - a test passing an error to done() callback ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":1,"file":"test/test/mochalike.js","line":65},"results":{"count":1,"fail":1,"ok":false,"pass":0,"plan":{"end":1,"start":1}},"source":"describe('a test passing an error to done() callback', function () {\n"}
...

1..6
# failed 2 of 6 tests
Expand Down
9 changes: 0 additions & 9 deletions test/test/nesting.tap
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,9 @@ TAP version 13
1..3
# failed 1 of 3 tests
not ok 2 - second ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":5,"file":"test/test/nesting.js","line":10},"results":{"count":3,"fail":1,"ok":false,"pass":2,"plan":{"end":3,"start":1}},"source":"t.test('second', function (tt) {\n"}
...

# failed 1 of 2 tests
not ok 1 - nesting ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":3,"file":"test/test/nesting.js","line":3},"results":{"count":2,"fail":1,"ok":false,"pass":1,"plan":{"end":2,"start":1}},"source":"t.test('nesting', function (t) {\n"}
...

ok 2 - this passes
not ok 3 - this fails
Expand All @@ -41,9 +35,6 @@ not ok 3 - this fails
...
# failed 1 of 2 tests
not ok 4 - async kid ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":3,"file":"test/test/nesting.js","line":30},"results":{"count":2,"fail":1,"ok":false,"pass":1,"plan":{"end":2,"start":1}},"source":"t.test('async kid', function (t) {\n"}
...

ok 5 - pass after async kid
1..5
Expand Down
6 changes: 0 additions & 6 deletions test/test/not-ok-nested.tap
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,9 @@ TAP version 13
...
# failed 1 of 1 tests
not ok 1 - parent ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":5,"file":"test/test/not-ok-nested.js","line":5},"results":{"count":1,"fail":1,"ok":false,"pass":0,"plan":{"end":1,"start":1}},"source":"t.test('parent', function (t) {\n"}
...

# failed 1 of 1 tests
not ok 1 - gp ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":3,"file":"test/test/not-ok-nested.js","line":3},"results":{"count":1,"fail":1,"ok":false,"pass":0,"plan":{"end":1,"start":1}},"source":"t.test('gp', function (t) {\n"}
...

1..1
# failed 1 of 1 tests
Expand Down
3 changes: 0 additions & 3 deletions test/test/ok-diags--bail.tap
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ ok 1 - this is fine
1..1
ok 1 - this is fine
ok 2 - child ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":3,"file":"test/test/ok-diags.js","line":10},"results":{"count":1,"ok":true,"pass":1,"plan":{"end":1,"start":1}},"source":"t.test('child', { diagnostic: true }, function (t) {\n"}
...

1..2
___/# time=[0-9.]+(ms)?/~~~
Expand Down
3 changes: 0 additions & 3 deletions test/test/ok-diags.tap
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ ok 1 - this is fine
1..1
ok 1 - this is fine
ok 2 - child ___/# time=[0-9.]+(ms)?/~~~
---
{"at":{"column":3,"file":"test/test/ok-diags.js","line":10},"results":{"count":1,"ok":true,"pass":1,"plan":{"end":1,"start":1}},"source":"t.test('child', { diagnostic: true }, function (t) {\n"}
...

1..2
___/# time=[0-9.]+(ms)?/~~~
Expand Down
2 changes: 1 addition & 1 deletion test/test/pending-handles.tap
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TAP version 13
___/# time=[0-9.]+(ms)?/~~~
not ok 1 - ___/.*/~~~pending-handles.js child ___/# time=[0-9.]+(ms)?/~~~
---
{"arguments":["___/.*/~~~pending-handles.js","child"],"at":{"column":5,"file":"test/test/pending-handles.js","line":7},"command":"___/.*(node|iojs)(.exe)?/~~~","failure":"timeout","results":{"bailout":false,"count":2,"fail":1,"ok":false,"pass":1,"plan":{"comment":"","end":2,"skipAll":false,"skipReason":"","start":1},"skip":0,"todo":0},"signal":"SIGTERM","source":"t.spawn(process.execPath, [__filename, 'child'], {}, '', {\n","timeout":900}
{"arguments":["___/.*/~~~pending-handles.js","child"],"command":"___/.*(node|iojs)(.exe)?/~~~","failure":"timeout","signal":"SIGTERM","timeout":900}
...

1..1
Expand Down
Loading

0 comments on commit 55c23c5

Please sign in to comment.