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: https://github.com/nodejs/node/pull/24951 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net>
This commit is contained in:
parent
b1a4e41006
commit
5f866821ad
@ -3,12 +3,11 @@ const common = require('../common');
|
|||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const cp = require('child_process');
|
const cp = require('child_process');
|
||||||
|
|
||||||
function checkFactory(streamName) {
|
function runChecks(err, stdio, streamName, expected) {
|
||||||
return common.mustCall((err) => {
|
assert.strictEqual(err.message, `${streamName} maxBuffer length exceeded`);
|
||||||
assert.strictEqual(err.message, `${streamName} maxBuffer length exceeded`);
|
assert(err instanceof RangeError);
|
||||||
assert(err instanceof RangeError);
|
assert.strictEqual(err.code, 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER');
|
||||||
assert.strictEqual(err.code, 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER');
|
assert.deepStrictEqual(stdio[streamName], expected);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -25,7 +24,13 @@ function checkFactory(streamName) {
|
|||||||
{
|
{
|
||||||
const cmd = 'echo "hello world"';
|
const cmd = 'echo "hello world"';
|
||||||
|
|
||||||
cp.exec(cmd, { maxBuffer: 5 }, checkFactory('stdout'));
|
cp.exec(
|
||||||
|
cmd,
|
||||||
|
{ maxBuffer: 5 },
|
||||||
|
common.mustCall((err, stdout, stderr) => {
|
||||||
|
runChecks(err, { stdout, stderr }, 'stdout', '');
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const unicode = '中文测试'; // length = 4, byte length = 12
|
const unicode = '中文测试'; // length = 4, byte length = 12
|
||||||
@ -33,13 +38,25 @@ const unicode = '中文测试'; // length = 4, byte length = 12
|
|||||||
{
|
{
|
||||||
const cmd = `"${process.execPath}" -e "console.log('${unicode}');"`;
|
const cmd = `"${process.execPath}" -e "console.log('${unicode}');"`;
|
||||||
|
|
||||||
cp.exec(cmd, { maxBuffer: 10 }, checkFactory('stdout'));
|
cp.exec(
|
||||||
|
cmd,
|
||||||
|
{ maxBuffer: 10 },
|
||||||
|
common.mustCall((err, stdout, stderr) => {
|
||||||
|
runChecks(err, { stdout, stderr }, 'stdout', '');
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
const cmd = `"${process.execPath}" -e "console.error('${unicode}');"`;
|
const cmd = `"${process.execPath}" -e "console.error('${unicode}');"`;
|
||||||
|
|
||||||
cp.exec(cmd, { maxBuffer: 10 }, checkFactory('stderr'));
|
cp.exec(
|
||||||
|
cmd,
|
||||||
|
{ maxBuffer: 3 },
|
||||||
|
common.mustCall((err, stdout, stderr) => {
|
||||||
|
runChecks(err, { stdout, stderr }, 'stderr', '');
|
||||||
|
})
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -48,7 +65,10 @@ const unicode = '中文测试'; // length = 4, byte length = 12
|
|||||||
const child = cp.exec(
|
const child = cp.exec(
|
||||||
cmd,
|
cmd,
|
||||||
{ encoding: null, maxBuffer: 10 },
|
{ encoding: null, maxBuffer: 10 },
|
||||||
checkFactory('stdout'));
|
common.mustCall((err, stdout, stderr) => {
|
||||||
|
runChecks(err, { stdout, stderr }, 'stdout', '');
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
child.stdout.setEncoding('utf-8');
|
child.stdout.setEncoding('utf-8');
|
||||||
}
|
}
|
||||||
@ -58,8 +78,11 @@ const unicode = '中文测试'; // length = 4, byte length = 12
|
|||||||
|
|
||||||
const child = cp.exec(
|
const child = cp.exec(
|
||||||
cmd,
|
cmd,
|
||||||
{ encoding: null, maxBuffer: 10 },
|
{ encoding: null, maxBuffer: 3 },
|
||||||
checkFactory('stderr'));
|
common.mustCall((err, stdout, stderr) => {
|
||||||
|
runChecks(err, { stdout, stderr }, 'stderr', '');
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
child.stderr.setEncoding('utf-8');
|
child.stderr.setEncoding('utf-8');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user