11'use strict' ;
2- var common = require ( '../common' ) ;
3- var assert = require ( 'assert' ) ;
4- var os = require ( 'os' ) ;
2+ require ( '../common' ) ;
53
6- var spawnSync = require ( 'child_process' ) . spawnSync ;
4+ const assert = require ( 'assert' ) ;
75
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' ;
1010
1111// 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' ) ;
1414
15- var args = [
15+ const args = [
1616 '-e' ,
1717 `console.log("${ msgOut } "); console.error("${ msgErr } ");`
1818] ;
1919
2020var ret ;
2121
2222
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+
2334if ( process . argv . indexOf ( 'spawnchild' ) !== - 1 ) {
2435 switch ( process . argv [ 3 ] ) {
2536 case '1' :
2637 ret = spawnSync ( process . execPath , args , { stdio : 'inherit' } ) ;
27- common . checkSpawnSyncRet ( ret ) ;
38+ checkSpawnSyncRet ( ret ) ;
2839 break ;
2940 case '2' :
3041 ret = spawnSync ( process . execPath , args , {
3142 stdio : [ 'inherit' , 'inherit' , 'inherit' ]
3243 } ) ;
33- common . checkSpawnSyncRet ( ret ) ;
44+ checkSpawnSyncRet ( ret ) ;
3445 break ;
3546 }
3647 process . exit ( 0 ) ;
3748 return ;
3849}
3950
40-
41- function verifyBufOutput ( ret ) {
42- common . checkSpawnSyncRet ( ret ) ;
43- assert . deepEqual ( ret . stdout , msgOutBuf ) ;
44- assert . deepEqual ( ret . stderr , msgErrBuf ) ;
45- }
46-
47-
4851verifyBufOutput ( spawnSync ( process . execPath , [ __filename , 'spawnchild' , 1 ] ) ) ;
4952verifyBufOutput ( spawnSync ( process . execPath , [ __filename , 'spawnchild' , 2 ] ) ) ;
5053
@@ -63,7 +66,7 @@ options = {
6366
6467ret = spawnSync ( 'cat' , [ ] , options ) ;
6568
66- common . checkSpawnSyncRet ( ret ) ;
69+ checkSpawnSyncRet ( ret ) ;
6770assert . strictEqual ( ret . stdout . toString ( 'utf8' ) , options . input ) ;
6871assert . strictEqual ( ret . stderr . toString ( 'utf8' ) , '' ) ;
6972
@@ -73,15 +76,15 @@ options = {
7376
7477ret = spawnSync ( 'cat' , [ ] , options ) ;
7578
76- common . checkSpawnSyncRet ( ret ) ;
79+ checkSpawnSyncRet ( ret ) ;
7780assert . deepEqual ( ret . stdout , options . input ) ;
7881assert . deepEqual ( ret . stderr , new Buffer ( '' ) ) ;
7982
8083verifyBufOutput ( spawnSync ( process . execPath , args ) ) ;
8184
8285ret = spawnSync ( process . execPath , args , { encoding : 'utf8' } ) ;
8386
84- common . checkSpawnSyncRet ( ret ) ;
87+ checkSpawnSyncRet ( ret ) ;
8588assert . strictEqual ( ret . stdout , msgOut + '\n' ) ;
8689assert . strictEqual ( ret . stderr , msgErr + '\n' ) ;
8790
0 commit comments