@@ -3,12 +3,11 @@ const common = require('../common');
33const assert = require ( 'assert' ) ;
44const 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
3136const 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