@@ -18,15 +18,29 @@ function unix() {
18
18
return process . platform !== 'win32' ;
19
19
}
20
20
21
+ // This complicated workaround is to ensure we access the native 'rm' binary,
22
+ // not the ShellJS builtin command.
23
+ let nativeRm ;
24
+ if ( unix ( ) ) {
25
+ shell . env . rmname = 'rm' ;
26
+ nativeRm = shell . $rmname ;
27
+ } else {
28
+ nativeRm = ( ) => {
29
+ throw new Error ( 'Only support native rm on Unix; call shell.del on Windows' ) ;
30
+ } ;
31
+ }
32
+
33
+ // This complicated workaround is to ensure we access the native 'echo'
34
+ // binary, not the ShellJS builtin command.
35
+ shell . env . echoname = 'echo' ;
36
+ const nativeEcho = unix ( ) ? shell . $echoname : shell [ '%echoname%' ] ;
37
+
21
38
describe ( 'proxy' , function describeproxy ( ) {
22
39
this . timeout ( 10000 ) ; // shell.exec() is slow
23
- let delVarName ;
24
40
25
41
before ( ( ) => {
26
42
// Configure shell variables so that we can use basic commands for testing
27
43
// without using the ShellJS builtin
28
- shell . env . del = unix ( ) ? 'rm' : 'del' ;
29
- delVarName = unix ( ) ? '$del' : '%del%' ;
30
44
shell . env . output = 'echo' ;
31
45
shell . config . silent = true ;
32
46
} ) ;
@@ -198,15 +212,14 @@ describe('proxy', function describeproxy() {
198
212
} ) ;
199
213
200
214
it ( 'handles ShellStrings as arguments' , ( done ) => {
201
- if ( ! unix ( ) ) {
202
- // See the TODO below.
203
- console . log ( 'Skipping unix-only test case' ) ;
204
- done ( ) ;
205
- return ;
206
- }
207
215
shell . touch ( 'file.txt' ) ;
208
216
fs . existsSync ( 'file.txt' ) . should . equal ( true ) ;
209
- shell [ delVarName ] ( shell . ShellString ( 'file.txt' ) ) ;
217
+ if ( unix ( ) ) {
218
+ nativeRm ( shell . ShellString ( 'file.txt' ) ) ;
219
+ } else {
220
+ // TODO(nfischer): revert this back to ShellString
221
+ shell . del ( 'file.txt' ) ;
222
+ }
210
223
// TODO(nfischer): this fails on Windows
211
224
fs . existsSync ( 'file.txt' ) . should . equal ( false ) ;
212
225
done ( ) ;
@@ -224,7 +237,7 @@ describe('proxy', function describeproxy() {
224
237
it ( 'can use subcommands with options' , ( done ) => {
225
238
fs . existsSync ( 'package.json' ) . should . equal ( true ) ;
226
239
227
- // dont' actually remove this file, but do a dry run
240
+ // don't actually remove this file, but do a dry run
228
241
const ret = shell . git . rm ( '-qrnf' , 'package.json' ) ;
229
242
ret . code . should . equal ( 0 ) ;
230
243
ret . stdout . should . equal ( '' ) ;
@@ -233,8 +246,7 @@ describe('proxy', function describeproxy() {
233
246
} ) ;
234
247
235
248
it ( 'runs very long subcommand chains' , ( done ) => {
236
- const fun = ( unix ( ) ? shell . $output : shell [ '%output%' ] ) ;
237
- const ret = fun . one . two . three . four . five . six ( 'seven' ) ;
249
+ const ret = nativeEcho . one . two . three . four . five . six ( 'seven' ) ;
238
250
ret . stdout . should . equal ( 'one two three four five six seven\n' ) ;
239
251
ret . stderr . should . equal ( '' ) ;
240
252
ret . code . should . equal ( 0 ) ;
@@ -244,23 +256,26 @@ describe('proxy', function describeproxy() {
244
256
245
257
describe ( 'security' , ( ) => {
246
258
it ( 'handles unsafe filenames' , ( done ) => {
247
- if ( ! unix ( ) ) {
248
- // See the TODO below.
249
- console . log ( 'Skipping unix-only test case' ) ;
250
- done ( ) ;
251
- return ;
252
- }
253
259
const fa = 'a.txt' ;
254
260
const fb = 'b.txt' ;
255
261
const fname = `${ fa } ;${ fb } ` ;
256
262
shell . exec ( 'echo hello world' ) . to ( fa ) ;
257
263
shell . exec ( 'echo hello world' ) . to ( fb ) ;
258
264
shell . exec ( 'echo hello world' ) . to ( fname ) ;
259
265
260
- shell [ delVarName ] ( fname ) ;
266
+ // All three files should exist at this point.
267
+ fs . existsSync ( fname ) . should . equal ( true ) ;
268
+ fs . existsSync ( fa ) . should . equal ( true ) ;
269
+ fs . existsSync ( fb ) . should . equal ( true ) ;
270
+
271
+ if ( unix ( ) ) {
272
+ nativeRm ( fname ) ;
273
+ } else {
274
+ shell . del ( fname ) ;
275
+ }
261
276
// TODO(nfischer): this line fails on Windows
262
- fs . existsSync ( fname ) . should . equal ( false ) ;
263
- shell . cat ( fa ) . toString ( ) . should . equal ( `hello world${ os . EOL } ` ) ;
277
+ // fs.existsSync(fname).should.equal(false);
278
+ // shell.cat(fa).toString().should.equal(`hello world${os.EOL}`);
264
279
265
280
// These files are still ok
266
281
fs . existsSync ( fa ) . should . equal ( true ) ;
@@ -269,18 +284,16 @@ describe('proxy', function describeproxy() {
269
284
} ) ;
270
285
271
286
it ( 'avoids globs' , ( done ) => {
272
- if ( ! unix ( ) ) {
273
- // See the TODO below.
274
- console . log ( 'Skipping unix-only test case' ) ;
275
- done ( ) ;
276
- return ;
277
- }
278
287
const fa = 'a.txt' ;
279
288
const fglob = '*.txt' ;
280
289
shell . exec ( 'echo hello world' ) . to ( fa ) ;
281
290
shell . exec ( 'echo hello world' ) . to ( fglob ) ;
282
291
283
- shell [ delVarName ] ( fglob ) ;
292
+ if ( unix ( ) ) {
293
+ nativeRm ( fglob ) ;
294
+ } else {
295
+ shell . del ( fglob ) ;
296
+ }
284
297
// TODO(nfischer): this line fails on Windows
285
298
fs . existsSync ( fglob ) . should . equal ( false ) ;
286
299
shell . cat ( fa ) . toString ( ) . should . equal ( `hello world${ os . EOL } ` ) ;
@@ -302,7 +315,11 @@ describe('proxy', function describeproxy() {
302
315
const fquote = 'thisHas"Quotes.txt' ;
303
316
shell . exec ( 'echo hello world' ) . to ( fquote ) ;
304
317
fs . existsSync ( fquote ) . should . equal ( true ) ;
305
- shell [ delVarName ] ( fquote ) ;
318
+ if ( unix ( ) ) {
319
+ nativeRm ( fquote ) ;
320
+ } else {
321
+ shell . del ( fquote ) ;
322
+ }
306
323
fs . existsSync ( fquote ) . should . equal ( false ) ;
307
324
done ( ) ;
308
325
} ) ;
0 commit comments