0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/abort/test-abort-backtrace.js
Rich Trott df57d8bdcc test: improve test-abort-backtrace
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: https://github.com/nodejs/node/pull/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>
2017-08-26 16:30:31 -07:00

29 lines
932 B
JavaScript

'use strict';
const common = require('../common');
if (common.isWindows)
common.skip('Backtraces unimplemented on Windows.');
const assert = require('assert');
const cp = require('child_process');
if (process.argv[2] === 'child') {
process.abort();
} else {
const child = cp.spawnSync(`${process.execPath}`, [`${__filename}`, 'child']);
const stderr = child.stderr.toString();
assert.strictEqual(child.stdout.toString(), '');
// 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}`);
}
}
}