@@ -24,35 +24,86 @@ var child_process = require('child_process');
24
24
var spawn = child_process . spawn ;
25
25
var fork = child_process . fork ;
26
26
var execFile = child_process . execFile ;
27
- var cmd = ( process . platform === 'win32' ) ? 'dir ' : 'ls' ;
27
+ var cmd = ( process . platform === 'win32' ) ? 'rundll32 ' : 'ls' ;
28
28
var empty = require ( '../common' ) . fixturesDir + '/empty.js' ;
29
29
30
+ // Argument types for combinatorics
31
+ var a = [ ] , o = { } , c = ( function callback ( ) { } ) , s = 'string' , u = undefined , n = null ;
30
32
31
- // verify that args argument must be an array
32
- assert . throws ( function ( ) {
33
- spawn ( cmd , 'this is not an array' ) ;
34
- } , TypeError ) ;
33
+ // function spawn(file=f [,args=a] [, options=o]) has valid combinations:
34
+ // (f)
35
+ // (f, a)
36
+ // (f, a, o)
37
+ // (f, o)
38
+ assert . doesNotThrow ( function ( ) { spawn ( cmd ) ; } ) ;
39
+ assert . doesNotThrow ( function ( ) { spawn ( cmd , a ) ; } ) ;
40
+ assert . doesNotThrow ( function ( ) { spawn ( cmd , a , o ) ; } ) ;
41
+ assert . doesNotThrow ( function ( ) { spawn ( cmd , o ) ; } ) ;
35
42
36
- // verify that args argument is optional
37
- assert . doesNotThrow ( function ( ) {
38
- spawn ( cmd , { } ) ;
39
- } ) ;
43
+ // Variants of undefined as explicit 'no argument' at a position
44
+ assert . doesNotThrow ( function ( ) { execFile ( empty , u , o ) ; } ) ;
45
+ assert . doesNotThrow ( function ( ) { execFile ( empty , a , u ) ; } ) ;
46
+ assert . doesNotThrow ( function ( ) { execFile ( empty , n , o ) ; } ) ;
47
+ assert . doesNotThrow ( function ( ) { execFile ( empty , a , n ) ; } ) ;
48
+
49
+ assert . throws ( function ( ) { spawn ( cmd , s ) ; } , TypeError ) ;
50
+ assert . doesNotThrow ( function ( ) { spawn ( cmd , a , s ) ; } , TypeError ) ;
40
51
41
52
42
53
// verify that execFile has same argument parsing behaviour as spawn
43
- assert . throws ( function ( ) {
44
- execFile ( cmd , 'this is not an array' ) ;
45
- } , TypeError ) ;
54
+ //
55
+ // function execFile(file=f [,args=a] [, options=o] [, callback=c]) has valid
56
+ // combinations:
57
+ // (f)
58
+ // (f, a)
59
+ // (f, a, o)
60
+ // (f, a, o, c)
61
+ // (f, a, c)
62
+ // (f, o)
63
+ // (f, o, c)
64
+ // (f, c)
65
+ assert . doesNotThrow ( function ( ) { execFile ( cmd ) ; } ) ;
66
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , a ) ; } ) ;
67
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , a , o ) ; } ) ;
68
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , a , o , c ) ; } ) ;
69
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , a , c ) ; } ) ;
70
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , o ) ; } ) ;
71
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , o , c ) ; } ) ;
72
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , c ) ; } ) ;
73
+
74
+ // Variants of undefined as explicit 'no argument' at a position
75
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , u , o , c ) ; } ) ;
76
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , a , u , c ) ; } ) ;
77
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , a , o , u ) ; } ) ;
78
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , n , o , c ) ; } ) ;
79
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , a , n , c ) ; } ) ;
80
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , a , o , n ) ; } ) ;
81
+
82
+ // string is invalid in arg position (this may seem strange, but is
83
+ // consistent across node API, cf. `net.createServer('not options', 'not
84
+ // callback')`
85
+ assert . throws ( function ( ) { execFile ( cmd , s , o , c ) ; } , TypeError ) ;
86
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , a , s , c ) ; } ) ;
87
+ assert . doesNotThrow ( function ( ) { execFile ( cmd , a , o , s ) ; } ) ;
46
88
47
- assert . doesNotThrow ( function ( ) {
48
- execFile ( cmd , { } ) ;
49
- } ) ;
50
89
51
90
// verify that fork has same argument parsing behaviour as spawn
52
- assert . throws ( function ( ) {
53
- fork ( empty , 'this is not an array' ) ;
54
- } , TypeError ) ;
91
+ //
92
+ // function fork(file=f [,args=a] [, options=o]) has valid combinations:
93
+ // (f)
94
+ // (f, a)
95
+ // (f, a, o)
96
+ // (f, o)
97
+ assert . doesNotThrow ( function ( ) { fork ( empty ) ; } ) ;
98
+ assert . doesNotThrow ( function ( ) { fork ( empty , a ) ; } ) ;
99
+ assert . doesNotThrow ( function ( ) { fork ( empty , a , o ) ; } ) ;
100
+ assert . doesNotThrow ( function ( ) { fork ( empty , o ) ; } ) ;
101
+
102
+ // Variants of undefined as explicit 'no argument' at a position
103
+ assert . doesNotThrow ( function ( ) { execFile ( empty , u , o ) ; } ) ;
104
+ assert . doesNotThrow ( function ( ) { execFile ( empty , a , u ) ; } ) ;
105
+ assert . doesNotThrow ( function ( ) { execFile ( empty , n , o ) ; } ) ;
106
+ assert . doesNotThrow ( function ( ) { execFile ( empty , a , n ) ; } ) ;
55
107
56
- assert . doesNotThrow ( function ( ) {
57
- execFile ( empty , { } ) ;
58
- } ) ;
108
+ assert . throws ( function ( ) { fork ( empty , s ) ; } , TypeError ) ;
109
+ assert . doesNotThrow ( function ( ) { fork ( empty , a , s ) ; } , TypeError ) ;
0 commit comments