@@ -25,14 +25,27 @@ var exec = require('child_process').exec;
25
25
var async = require ( 'async' ) ;
26
26
var jsdiff = require ( 'diff' ) ;
27
27
28
+ var _which = require ( 'which' ) . sync ;
29
+ function which ( command ) {
30
+ try {
31
+ return _which ( command ) ;
32
+ } catch ( err ) {
33
+ return false ;
34
+ }
35
+ }
36
+
37
+ // Look for grep first (any OS). If not found (but on Windows) look for find,
38
+ // which is Windows' horribly crippled grep alternative.
39
+ var grep = which ( 'grep' ) || process . platform === 'win32' && which ( 'find' ) ;
40
+
28
41
function run ( command , options , callback ) {
29
42
if ( typeof options === 'function' ) {
30
43
callback = options ;
31
44
options = { } ;
32
45
}
33
46
command += ' 2>&1' ;
34
47
if ( options . pipe ) {
35
- command += ' | ' + ( process . platform === 'win32' ? 'find' : ' grep' ) + ' "std"' ;
48
+ command += ' | ' + grep + ' "std"' ;
36
49
}
37
50
exec ( command , function ( error , stdout ) {
38
51
callback ( command , error ? error . code : 0 , stdout ) ;
@@ -69,6 +82,12 @@ exports['exit'] = {
69
82
process . chdir ( this . origCwd ) ;
70
83
done ( ) ;
71
84
} ,
85
+ 'grep' : function ( test ) {
86
+ test . expect ( 1 ) ;
87
+ // Many unit tests depend on this.
88
+ test . ok ( grep , 'A suitable "grep" or "find" program was not found in the PATH.' ) ;
89
+ test . done ( ) ;
90
+ } ,
72
91
'stdout stderr' : function ( test ) {
73
92
var counts = [ 10 , 100 , 1000 ] ;
74
93
test . expect ( counts . length ) ;
0 commit comments