Skip to content

Commit df57d8b

Browse files
committed
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: nodejs#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>
1 parent acdf558 commit df57d8b

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

test/abort/test-abort-backtrace.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ if (process.argv[2] === 'child') {
1010
process.abort();
1111
} else {
1212
const child = cp.spawnSync(`${process.execPath}`, [`${__filename}`, 'child']);
13-
const frames =
14-
child.stderr.toString().trimRight().split('\n').map((s) => s.trim());
13+
const stderr = child.stderr.toString();
1514

1615
assert.strictEqual(child.stdout.toString(), '');
17-
assert.ok(frames.length > 0);
18-
// All frames should start with a frame number.
19-
assert.ok(frames.every((frame, index) => frame.startsWith(`${index + 1}:`)));
20-
// At least some of the frames should include the binary name.
21-
assert.ok(frames.some((frame) => frame.includes(`[${process.execPath}]`)));
16+
// stderr will be empty for systems that don't support backtraces.
17+
if (stderr !== '') {
18+
const frames = stderr.trimRight().split('\n').map((s) => s.trim());
19+
20+
if (!frames.every((frame, index) => frame.startsWith(`${index + 1}:`))) {
21+
assert.fail(`Each frame should start with a frame number:\n${stderr}`);
22+
}
23+
24+
if (!frames.some((frame) => frame.includes(`[${process.execPath}]`))) {
25+
assert.fail(`Some frames should include the binary name:\n${stderr}`);
26+
}
27+
}
2228
}

0 commit comments

Comments
 (0)