|
1 | 1 | 'use strict';
|
2 | 2 | const common = require('../common');
|
3 | 3 | const assert = require('assert');
|
4 |
| -const { spawnSync, fork } = require('child_process'); |
| 4 | +const { spawnSync } = require('child_process'); |
5 | 5 | const async_hooks = require('async_hooks');
|
6 | 6 | const initHooks = require('./init-hooks');
|
7 | 7 |
|
@@ -58,39 +58,31 @@ assert.ok(!arg);
|
58 | 58 | {
|
59 | 59 | console.log('start case 3');
|
60 | 60 | console.time('end case 3');
|
61 |
| - const opts = { |
62 |
| - execArgv: ['--abort-on-uncaught-exception'], |
63 |
| - silent: true |
64 |
| - }; |
65 |
| - const child = fork(__filename, ['test_callback_abort'], opts); |
66 |
| - |
67 |
| - let stdout = ''; |
68 |
| - child.stdout.on('data', (data) => { |
69 |
| - stdout += data; |
70 |
| - }); |
71 |
| - |
72 |
| - let stderr = ''; |
73 |
| - child.stderr.on('data', (data) => { |
74 |
| - stderr += data; |
75 |
| - }); |
76 |
| - |
77 |
| - child.on('close', (code, signal) => { |
78 |
| - if (common.isWindows) { |
79 |
| - assert.strictEqual(code, 134); |
80 |
| - assert.strictEqual(signal, null); |
81 |
| - } else { |
82 |
| - assert.strictEqual(code, null); |
83 |
| - // Most posix systems will show 'SIGABRT', but alpine34 does not |
84 |
| - if (signal !== 'SIGABRT') { |
85 |
| - console.log(`parent received signal ${signal}\nchild's stderr:`); |
86 |
| - console.log(stderr); |
87 |
| - process.exit(1); |
88 |
| - } |
89 |
| - assert.strictEqual(signal, 'SIGABRT'); |
| 61 | + let program = process.execPath; |
| 62 | + let args = [ |
| 63 | + '--abort-on-uncaught-exception', __filename, 'test_callback_abort' ]; |
| 64 | + const options = { encoding: 'utf8' }; |
| 65 | + if (!common.isWindows) { |
| 66 | + program = `ulimit -c 0 && exec ${program} ${args.join(' ')}`; |
| 67 | + args = []; |
| 68 | + options.shell = true; |
| 69 | + } |
| 70 | + const child = spawnSync(program, args, options); |
| 71 | + if (common.isWindows) { |
| 72 | + assert.strictEqual(child.status, 134); |
| 73 | + assert.strictEqual(child.signal, null); |
| 74 | + } else { |
| 75 | + assert.strictEqual(child.status, null); |
| 76 | + // Most posix systems will show 'SIGABRT', but alpine34 does not |
| 77 | + if (child.signal !== 'SIGABRT') { |
| 78 | + console.log(`parent received signal ${child.signal}\nchild's stderr:`); |
| 79 | + console.log(child.stderr); |
| 80 | + process.exit(1); |
90 | 81 | }
|
91 |
| - assert.strictEqual(stdout, ''); |
92 |
| - const firstLineStderr = stderr.split(/[\r\n]+/g)[0].trim(); |
93 |
| - assert.strictEqual(firstLineStderr, 'Error: test_callback_abort'); |
94 |
| - }); |
| 82 | + assert.strictEqual(child.signal, 'SIGABRT'); |
| 83 | + } |
| 84 | + assert.strictEqual(child.stdout, ''); |
| 85 | + const firstLineStderr = child.stderr.split(/[\r\n]+/g)[0].trim(); |
| 86 | + assert.strictEqual(firstLineStderr, 'Error: test_callback_abort'); |
95 | 87 | console.timeEnd('end case 3');
|
96 | 88 | }
|
0 commit comments