Skip to content
This repository has been archived by the owner on Aug 31, 2018. It is now read-only.

Commit

Permalink
test: improve test-abort-backtrace
Browse files Browse the repository at this point in the history
Improve error message by showing output when frames output does not meet
expectations.

Since we can't tell at runtime if we have the correct libc for
backtraces, allow an empty backtrace and run the test on all platforms.

PR-URL: nodejs/node#14013
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
Trott authored and Olivia Hugger committed Aug 30, 2017
1 parent a5d7a44 commit 2e43d5b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions test/abort/test-abort-backtrace.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ if (process.argv[2] === 'child') {
process.abort();
} else {
const child = cp.spawnSync(`${process.execPath}`, [`${__filename}`, 'child']);
const frames =
child.stderr.toString().trimRight().split('\n').map((s) => s.trim());
const stderr = child.stderr.toString();

assert.strictEqual(child.stdout.toString(), '');
assert.ok(frames.length > 0);
// All frames should start with a frame number.
assert.ok(frames.every((frame, index) => frame.startsWith(`${index + 1}:`)));
// At least some of the frames should include the binary name.
assert.ok(frames.some((frame) => frame.includes(`[${process.execPath}]`)));
// stderr will be empty for systems that don't support backtraces.
if (stderr !== '') {
const frames = stderr.trimRight().split('\n').map((s) => s.trim());

if (!frames.every((frame, index) => frame.startsWith(`${index + 1}:`))) {
assert.fail(`Each frame should start with a frame number:\n${stderr}`);
}

if (!frames.some((frame) => frame.includes(`[${process.execPath}]`))) {
assert.fail(`Some frames should include the binary name:\n${stderr}`);
}
}
}

0 comments on commit 2e43d5b

Please sign in to comment.