1
1
'use strict' ;
2
- var common = require ( '../common' ) ;
3
- var assert = require ( 'assert' ) ;
4
- var os = require ( 'os' ) ;
2
+ require ( '../common' ) ;
5
3
6
- var spawnSync = require ( 'child_process' ) . spawnSync ;
4
+ const assert = require ( 'assert' ) ;
7
5
8
- var msgOut = 'this is stdout' ;
9
- var msgErr = 'this is stderr' ;
6
+ const spawnSync = require ( 'child_process' ) . spawnSync ;
7
+
8
+ const msgOut = 'this is stdout' ;
9
+ const msgErr = 'this is stderr' ;
10
10
11
11
// this is actually not os.EOL?
12
- var msgOutBuf = new Buffer ( msgOut + '\n' ) ;
13
- var msgErrBuf = new Buffer ( msgErr + '\n' ) ;
12
+ const msgOutBuf = new Buffer ( msgOut + '\n' ) ;
13
+ const msgErrBuf = new Buffer ( msgErr + '\n' ) ;
14
14
15
- var args = [
15
+ const args = [
16
16
'-e' ,
17
17
`console.log("${ msgOut } "); console.error("${ msgErr } ");`
18
18
] ;
19
19
20
20
var ret ;
21
21
22
22
23
+ function checkSpawnSyncRet ( ret ) {
24
+ assert . strictEqual ( ret . status , 0 ) ;
25
+ assert . strictEqual ( ret . error , undefined ) ;
26
+ } ;
27
+
28
+ function verifyBufOutput ( ret ) {
29
+ checkSpawnSyncRet ( ret ) ;
30
+ assert . deepEqual ( ret . stdout , msgOutBuf ) ;
31
+ assert . deepEqual ( ret . stderr , msgErrBuf ) ;
32
+ }
33
+
23
34
if ( process . argv . indexOf ( 'spawnchild' ) !== - 1 ) {
24
35
switch ( process . argv [ 3 ] ) {
25
36
case '1' :
26
37
ret = spawnSync ( process . execPath , args , { stdio : 'inherit' } ) ;
27
- common . checkSpawnSyncRet ( ret ) ;
38
+ checkSpawnSyncRet ( ret ) ;
28
39
break ;
29
40
case '2' :
30
41
ret = spawnSync ( process . execPath , args , {
31
42
stdio : [ 'inherit' , 'inherit' , 'inherit' ]
32
43
} ) ;
33
- common . checkSpawnSyncRet ( ret ) ;
44
+ checkSpawnSyncRet ( ret ) ;
34
45
break ;
35
46
}
36
47
process . exit ( 0 ) ;
37
48
return ;
38
49
}
39
50
40
-
41
- function verifyBufOutput ( ret ) {
42
- common . checkSpawnSyncRet ( ret ) ;
43
- assert . deepEqual ( ret . stdout , msgOutBuf ) ;
44
- assert . deepEqual ( ret . stderr , msgErrBuf ) ;
45
- }
46
-
47
-
48
51
verifyBufOutput ( spawnSync ( process . execPath , [ __filename , 'spawnchild' , 1 ] ) ) ;
49
52
verifyBufOutput ( spawnSync ( process . execPath , [ __filename , 'spawnchild' , 2 ] ) ) ;
50
53
@@ -63,7 +66,7 @@ options = {
63
66
64
67
ret = spawnSync ( 'cat' , [ ] , options ) ;
65
68
66
- common . checkSpawnSyncRet ( ret ) ;
69
+ checkSpawnSyncRet ( ret ) ;
67
70
assert . strictEqual ( ret . stdout . toString ( 'utf8' ) , options . input ) ;
68
71
assert . strictEqual ( ret . stderr . toString ( 'utf8' ) , '' ) ;
69
72
@@ -73,15 +76,15 @@ options = {
73
76
74
77
ret = spawnSync ( 'cat' , [ ] , options ) ;
75
78
76
- common . checkSpawnSyncRet ( ret ) ;
79
+ checkSpawnSyncRet ( ret ) ;
77
80
assert . deepEqual ( ret . stdout , options . input ) ;
78
81
assert . deepEqual ( ret . stderr , new Buffer ( '' ) ) ;
79
82
80
83
verifyBufOutput ( spawnSync ( process . execPath , args ) ) ;
81
84
82
85
ret = spawnSync ( process . execPath , args , { encoding : 'utf8' } ) ;
83
86
84
- common . checkSpawnSyncRet ( ret ) ;
87
+ checkSpawnSyncRet ( ret ) ;
85
88
assert . strictEqual ( ret . stdout , msgOut + '\n' ) ;
86
89
assert . strictEqual ( ret . stderr , msgErr + '\n' ) ;
87
90
0 commit comments