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
cjihrig 64edd064b8 test: add abort test for backtrace validation
This commit adds a test that validates backtraces which are
printed on fatal errors.

PR-URL: https://github.com/nodejs/node/pull/6734
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-06-29 13:50:22 +02:00

25 lines
811 B
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const cp = require('child_process');
if (common.isWindows) {
common.skip('Backtraces unimplemented on Windows.');
return;
}
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());
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}]`)));
}