1
1
'use strict' ;
2
2
3
3
const assert = require ( 'assert' ) ;
4
- const spawn = require ( 'child_process' ) . spawn ;
5
-
4
+ const execFile = require ( 'child_process' ) . execFile ;
6
5
7
6
if ( process . argv [ 2 ] === 'child' ) {
8
7
setImmediate ( function ( ) {
@@ -14,34 +13,23 @@ if (process.argv[2] === 'child') {
14
13
( function runTest ( flags ) {
15
14
var execArgv = [ flags . pop ( ) ] ;
16
15
var args = [ __filename , 'child' ] ;
17
- var child = spawn ( process . execPath , execArgv . concat ( args ) ) ;
18
- var stderr = '' ;
19
-
20
- child . stdout . on ( 'data' , function ( chunk ) {
21
- throw new Error ( 'UNREACHABLE' ) ;
22
- } ) ;
23
-
24
- child . stderr . on ( 'data' , function ( chunk ) {
25
- stderr += chunk . toString ( ) ;
26
- } ) ;
27
-
28
- child . on ( 'close' , function ( ) {
29
- var cntr1 = ( stderr . match ( / W A R N I N G / g) || [ ] ) . length ;
30
- var cntr2 = ( stderr . match ( / f s \. r e a d F i l e S y n c / g) || [ ] ) . length ;
31
- assert . equal ( cntr1 , cntr2 ) ;
32
- if ( execArgv [ 0 ] === '--trace-sync-io' ) {
33
- // Prints 4 WARNINGS for --trace-sync-io. 1 for each sync call
34
- // inside readFileSync
35
- assert . equal ( cntr1 , 4 ) ;
36
- } else if ( execArgv [ 0 ] === ' ' ) {
37
- assert . equal ( cntr1 , 0 ) ;
16
+ var cntr = 0 ;
17
+ args = execArgv . concat ( args ) ;
18
+ if ( ! args [ 0 ] ) args . shift ( ) ;
19
+ execFile ( process . execPath , args , function ( err , stdout , stderr ) {
20
+ assert . equal ( err , null ) ;
21
+ assert . equal ( stdout , '' ) ;
22
+ if ( / ^ W A R N I N G [ \s \S ] * f s \. r e a d F i l e S y n c / . test ( stderr ) )
23
+ cntr ++ ;
24
+ if ( args [ 0 ] === '--trace-sync-io' ) {
25
+ assert . equal ( cntr , 1 ) ;
26
+ } else if ( args [ 0 ] === __filename ) {
27
+ assert . equal ( cntr , 0 ) ;
38
28
} else {
39
29
throw new Error ( 'UNREACHABLE' ) ;
40
30
}
41
-
42
31
if ( flags . length > 0 )
43
32
setImmediate ( runTest , flags ) ;
44
33
} ) ;
45
- } ( [ '--trace-sync-io' , ' ' ] ) ) ;
34
+ } ( [ '--trace-sync-io' , '' ] ) ) ;
46
35
}
47
-
0 commit comments