Skip to content

Commit 90a64ab

Browse files
Fishrock123targos
authored andcommitted
test: add stdio checks to cp-exec-maxBuffer
Expands this test case to check what happens to stdout/stderr when maxBuffer is exceeded. Also changes how cases are checked so that assertion stacks are tracable to their test case, aka 'make it actually debuggable'. PR-URL: #24951 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
1 parent 5fab92c commit 90a64ab

File tree

1 file changed

+35
-12
lines changed

1 file changed

+35
-12
lines changed

test/parallel/test-child-process-exec-maxBuffer.js

+35-12
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@ const common = require('../common');
33
const assert = require('assert');
44
const cp = require('child_process');
55

6-
function checkFactory(streamName) {
7-
return common.mustCall((err) => {
8-
assert.strictEqual(err.message, `${streamName} maxBuffer length exceeded`);
9-
assert(err instanceof RangeError);
10-
assert.strictEqual(err.code, 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER');
11-
});
6+
function runChecks(err, stdio, streamName, expected) {
7+
assert.strictEqual(err.message, `${streamName} maxBuffer length exceeded`);
8+
assert(err instanceof RangeError);
9+
assert.strictEqual(err.code, 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER');
10+
assert.deepStrictEqual(stdio[streamName], expected);
1211
}
1312

1413
{
@@ -25,21 +24,39 @@ function checkFactory(streamName) {
2524
{
2625
const cmd = 'echo "hello world"';
2726

28-
cp.exec(cmd, { maxBuffer: 5 }, checkFactory('stdout'));
27+
cp.exec(
28+
cmd,
29+
{ maxBuffer: 5 },
30+
common.mustCall((err, stdout, stderr) => {
31+
runChecks(err, { stdout, stderr }, 'stdout', '');
32+
})
33+
);
2934
}
3035

3136
const unicode = '中文测试'; // length = 4, byte length = 12
3237

3338
{
3439
const cmd = `"${process.execPath}" -e "console.log('${unicode}');"`;
3540

36-
cp.exec(cmd, { maxBuffer: 10 }, checkFactory('stdout'));
41+
cp.exec(
42+
cmd,
43+
{ maxBuffer: 10 },
44+
common.mustCall((err, stdout, stderr) => {
45+
runChecks(err, { stdout, stderr }, 'stdout', '');
46+
})
47+
);
3748
}
3849

3950
{
4051
const cmd = `"${process.execPath}" -e "console.error('${unicode}');"`;
4152

42-
cp.exec(cmd, { maxBuffer: 10 }, checkFactory('stderr'));
53+
cp.exec(
54+
cmd,
55+
{ maxBuffer: 3 },
56+
common.mustCall((err, stdout, stderr) => {
57+
runChecks(err, { stdout, stderr }, 'stderr', '');
58+
})
59+
);
4360
}
4461

4562
{
@@ -48,7 +65,10 @@ const unicode = '中文测试'; // length = 4, byte length = 12
4865
const child = cp.exec(
4966
cmd,
5067
{ encoding: null, maxBuffer: 10 },
51-
checkFactory('stdout'));
68+
common.mustCall((err, stdout, stderr) => {
69+
runChecks(err, { stdout, stderr }, 'stdout', '');
70+
})
71+
);
5272

5373
child.stdout.setEncoding('utf-8');
5474
}
@@ -58,8 +78,11 @@ const unicode = '中文测试'; // length = 4, byte length = 12
5878

5979
const child = cp.exec(
6080
cmd,
61-
{ encoding: null, maxBuffer: 10 },
62-
checkFactory('stderr'));
81+
{ encoding: null, maxBuffer: 3 },
82+
common.mustCall((err, stdout, stderr) => {
83+
runChecks(err, { stdout, stderr }, 'stderr', '');
84+
})
85+
);
6386

6487
child.stderr.setEncoding('utf-8');
6588
}

0 commit comments

Comments
 (0)