Skip to content

Commit

Permalink
better error messages with stack traces
Browse files Browse the repository at this point in the history
  • Loading branch information
James Halliday committed Dec 4, 2012
1 parent 37f79d2 commit 1f1fcf7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ function encodeResult (res, count) {
output += inner + 'expected: ' + ex + '\n';
output += inner + 'actual: ' + ac + '\n';
}
if (res.operator === 'error' && res.actual && res.actual.stack) {
var lines = String(res.actual.stack).split('\n');
output += inner + 'stack:\n';
output += inner + ' ' + lines[0] + '\n';
for (var i = 1; i < lines.length; i++) {
output += inner + lines[i] + '\n';
}
}

output += outer + '...\n';
}
Expand Down
2 changes: 1 addition & 1 deletion lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Test.prototype.error
= Test.prototype.iferror
= function (err, msg, extra) {
this._assert(!err, {
message : defined(msg, err.message),
message : defined(msg, String(err)),
operator : 'error',
actual : err,
extra : extra
Expand Down
2 changes: 1 addition & 1 deletion test/throw.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tap.test('throw test', function (tt) {
'TAP version 13',
'thrower',
{ id: 1, ok: true, name: 'should be equal' },
{ id: 2, ok: false, name: 'rawr' },
{ id: 2, ok: false, name: 'Error: rawr' },
'tests 2',
'pass 1',
'fail 1',
Expand Down

0 comments on commit 1f1fcf7

Please sign in to comment.