@@ -3,12 +3,11 @@ const common = require('../common');
3
3
const assert = require ( 'assert' ) ;
4
4
const cp = require ( 'child_process' ) ;
5
5
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 ) ;
12
11
}
13
12
14
13
{
@@ -25,21 +24,39 @@ function checkFactory(streamName) {
25
24
{
26
25
const cmd = 'echo "hello world"' ;
27
26
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
+ ) ;
29
34
}
30
35
31
36
const unicode = '中文测试' ; // length = 4, byte length = 12
32
37
33
38
{
34
39
const cmd = `"${ process . execPath } " -e "console.log('${ unicode } ');"` ;
35
40
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
+ ) ;
37
48
}
38
49
39
50
{
40
51
const cmd = `"${ process . execPath } " -e "console.error('${ unicode } ');"` ;
41
52
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
+ ) ;
43
60
}
44
61
45
62
{
@@ -48,7 +65,10 @@ const unicode = '中文测试'; // length = 4, byte length = 12
48
65
const child = cp . exec (
49
66
cmd ,
50
67
{ encoding : null , maxBuffer : 10 } ,
51
- checkFactory ( 'stdout' ) ) ;
68
+ common . mustCall ( ( err , stdout , stderr ) => {
69
+ runChecks ( err , { stdout, stderr } , 'stdout' , '' ) ;
70
+ } )
71
+ ) ;
52
72
53
73
child . stdout . setEncoding ( 'utf-8' ) ;
54
74
}
@@ -58,8 +78,11 @@ const unicode = '中文测试'; // length = 4, byte length = 12
58
78
59
79
const child = cp . exec (
60
80
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
+ ) ;
63
86
64
87
child . stderr . setEncoding ( 'utf-8' ) ;
65
88
}
0 commit comments