Skip to content

Commit

Permalink
Fix Windows path support in error messages
Browse files Browse the repository at this point in the history
Supersede tape-testing#221. Fix tape-testing#220. Generally makes tape support more kinds of stacktrace formats.
  • Loading branch information
Hugo Wood committed Jul 12, 2016
1 parent fb600ee commit dd8c5f2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 32 deletions.
34 changes: 10 additions & 24 deletions lib/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,36 +217,22 @@ Test.prototype._assert = function assert (ok, opts) {
if (!ok) {
var e = new Error('exception');
var err = (e.stack || '').split('\n');
var dir = path.dirname(__dirname) + '/';
var dir = path.dirname(__dirname) + path.sep;

for (var i = 0; i < err.length; i++) {
var m = /^[^\s]*\s*\bat\s+(.+)/.exec(err[i]);
if (!m) {
continue;
}

var s = m[1].split(/\s+/);
var filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[1]);
if (!filem) {
filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[2]);

if (!filem) {
filem = /(\/[^:\s]+:(\d+)(?::(\d+))?)/.exec(s[3]);

if (!filem) {
continue;
}
}
}
// regex taken from https://github.com/errwischt/stacktrace-parser/blob/fb58c13ba19dd9aa12b8480d8e9b938524953921/lib/stacktrace-parser.js#L13
// and edited to have a matching group around everything after the 'at'
var traceRegex = /^\s*at ((?:((?:\[object object\])?\S+(?: \[as \S+\])?) )?\(?(.*?):(\d+)(?::(\d+))?\)?\s*)$/

if (filem[1].slice(0, dir.length) === dir) {
var m = traceRegex.exec(err[i]);
if (!m || m[3].slice(0, dir.length) === dir) {
continue;
}

res.functionName = s[0];
res.file = filem[1];
res.line = Number(filem[2]);
if (filem[3]) res.column = filem[3];
res.functionName = m[2];
res.file = m[3];
res.line = Number(m[4]);
if (m[5]) res.column = m[5];

res.at = m[1];
break;
Expand Down
1 change: 1 addition & 0 deletions test/circular-things.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tap.test('circular test', function (assert) {
+ ' {}\n'
+ ' actual: |-\n'
+ ' { circular: [Circular] }\n'
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
Expand Down
21 changes: 15 additions & 6 deletions test/deep-equal-failure.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ tap.test('deep equal failure', function (assert) {
+ ' { b: 2 }\n'
+ ' actual: |-\n'
+ ' { a: 1 }\n'
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
Expand All @@ -34,7 +35,8 @@ tap.test('deep equal failure', function (assert) {
assert.deepEqual(getDiag(body), {
operator: 'equal',
expected: '{ b: 2 }',
actual: '{ a: 1 }'
actual: '{ a: 1 }',
at: 'tryOnImmediate (timers.js:543:15)'
});
}));

Expand All @@ -46,7 +48,8 @@ tap.test('deep equal failure', function (assert) {
diag: {
operator: 'equal',
expected: '{ b: 2 }',
actual: '{ a: 1 }'
actual: '{ a: 1 }',
at: 'tryOnImmediate (timers.js:543:15)'
}
});
});
Expand Down Expand Up @@ -76,6 +79,7 @@ tap.test('deep equal failure, depth 6, with option', function (assert) {
+ ' { a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }\n'
+ ' actual: |-\n'
+ ' { a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }\n'
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
Expand All @@ -87,7 +91,8 @@ tap.test('deep equal failure, depth 6, with option', function (assert) {
assert.deepEqual(getDiag(body), {
operator: 'equal',
expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }',
actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }'
actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }',
at: 'tryOnImmediate (timers.js:543:15)'
});
}));

Expand All @@ -99,7 +104,8 @@ tap.test('deep equal failure, depth 6, with option', function (assert) {
diag: {
operator: 'equal',
expected: '{ a: { a1: { a2: { a3: { a4: { a5: 2 } } } } } }',
actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }'
actual: '{ a: { a1: { a2: { a3: { a4: { a5: 1 } } } } } }',
at: 'tryOnImmediate (timers.js:543:15)'
}
});
});
Expand Down Expand Up @@ -129,6 +135,7 @@ tap.test('deep equal failure, depth 6, without option', function (assert) {
+ ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n'
+ ' actual: |-\n'
+ ' { a: { a1: { a2: { a3: { a4: [Object] } } } } }\n'
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
Expand All @@ -140,7 +147,8 @@ tap.test('deep equal failure, depth 6, without option', function (assert) {
assert.deepEqual(getDiag(body), {
operator: 'equal',
expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }',
actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }'
actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }',
at: 'tryOnImmediate (timers.js:543:15)'
});
}));

Expand All @@ -152,7 +160,8 @@ tap.test('deep equal failure, depth 6, without option', function (assert) {
diag: {
operator: 'equal',
expected: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }',
actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }'
actual: '{ a: { a1: { a2: { a3: { a4: [Object] } } } } }',
at: 'tryOnImmediate (timers.js:543:15)'
}
});
});
Expand Down
1 change: 1 addition & 0 deletions test/double_end.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test(function (t) {
'not ok 2 .end() called twice',
' ---',
' operator: fail',
' at: tryOnTimeout (timers.js:224:11)',
' ...',
'',
'1..2',
Expand Down
7 changes: 5 additions & 2 deletions test/stackTrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ tap.test('preserves stack trace with newlines', function (tt) {
stack: stackTrace,
operator: 'error',
expected: 'undefined',
actual: '[Error: Preserve stack]'
actual: '[Error: Preserve stack]',
at: 'tryOnImmediate (timers.js:543:15)'
}
});
});
Expand All @@ -39,6 +40,7 @@ tap.test('preserves stack trace with newlines', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ ' [Error: Preserve stack]\n'
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' stack: |-\n'
+ ' foo\n'
+ ' bar\n'
Expand All @@ -54,7 +56,8 @@ tap.test('preserves stack trace with newlines', function (tt) {
stack: stackTrace,
operator: 'error',
expected: 'undefined',
actual: '[Error: Preserve stack]'
actual: '[Error: Preserve stack]',
at: 'tryOnImmediate (timers.js:543:15)'
});
}));

Expand Down
9 changes: 9 additions & 0 deletions test/throws.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage() + "] message: '" + getNonFunctionMessage() + "' }\n"
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' ...\n'
+ 'not ok 2 should throw\n'
+ ' ---\n'
Expand All @@ -56,6 +57,7 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage(null) + "] message: '" + getNonFunctionMessage(null) + "' }\n"
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' ...\n'
+ 'not ok 3 should throw\n'
+ ' ---\n'
Expand All @@ -64,6 +66,7 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage(true) + "] message: '" + getNonFunctionMessage(true) + "' }\n"
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' ...\n'
+ 'not ok 4 should throw\n'
+ ' ---\n'
Expand All @@ -72,6 +75,7 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage(false) + "] message: '" + getNonFunctionMessage(false) + "' }\n"
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' ...\n'
+ 'not ok 5 should throw\n'
+ ' ---\n'
Expand All @@ -80,6 +84,7 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage('abc') + "] message: '" + getNonFunctionMessage('abc') + "' }\n"
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' ...\n'
+ 'not ok 6 should throw\n'
+ ' ---\n'
Expand All @@ -88,6 +93,7 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage(/a/g) + "] message: '" + getNonFunctionMessage(/a/g) + "' }\n"
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' ...\n'
+ 'not ok 7 should throw\n'
+ ' ---\n'
Expand All @@ -96,6 +102,7 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage([]) + "] message: '" + getNonFunctionMessage([]) + "' }\n"
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' ...\n'
+ 'not ok 8 should throw\n'
+ ' ---\n'
Expand All @@ -104,13 +111,15 @@ tap.test('failures', function (tt) {
+ ' undefined\n'
+ ' actual: |-\n'
+ " { [TypeError: " + getNonFunctionMessage({}) + "] message: '" + getNonFunctionMessage({}) + "' }\n"
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' ...\n'
+ '# function\n'
+ 'not ok 9 should throw\n'
+ ' ---\n'
+ ' operator: throws\n'
+ ' expected: undefined\n'
+ ' actual: undefined\n'
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' ...\n\n'
+ '1..9\n'
+ '# tests 9\n'
Expand Down
1 change: 1 addition & 0 deletions test/undef.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ tap.test('array test', function (tt) {
+ ' { beep: undefined }\n'
+ ' actual: |-\n'
+ ' {}\n'
+ ' at: tryOnImmediate (timers.js:543:15)\n'
+ ' ...\n'
+ '\n'
+ '1..1\n'
Expand Down

0 comments on commit dd8c5f2

Please sign in to comment.