@@ -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
} ) ;
@@ -101,20 +115,6 @@ describe('proxy', function describeproxy() {
101
115
} ) ;
102
116
103
117
describe ( 'commands' , ( ) => {
104
- it . skip ( 'runs tr' , ( ) => {
105
- if ( shell . which ( 'tr' ) ) {
106
- shell . ShellString ( 'hello world' ) . to ( 'file.txt' ) ;
107
- const ret1 = shell . cat ( 'file.txt' ) . tr ( '-d' , 'l' ) ;
108
- const ret2 = shell . cat ( 'file.txt' ) . exec ( 'tr -d "l"' ) ;
109
- assertShellStringEqual ( ret1 , ret2 ) ;
110
- ret2 . stdout . should . equal ( 'heo word' ) ;
111
- ret2 . stderr . should . equal ( '' ) ;
112
- ret2 . code . should . equal ( 0 ) ;
113
- } else {
114
- console . log ( 'skipping test' ) ;
115
- }
116
- } ) ;
117
-
118
118
it ( 'runs whoami' , ( ) => {
119
119
if ( shell . which ( 'whoami' ) ) {
120
120
const ret1 = shell . whoami ( ) ;
@@ -198,15 +198,14 @@ describe('proxy', function describeproxy() {
198
198
} ) ;
199
199
200
200
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
201
shell . touch ( 'file.txt' ) ;
208
202
fs . existsSync ( 'file.txt' ) . should . equal ( true ) ;
209
- shell [ delVarName ] ( shell . ShellString ( 'file.txt' ) ) ;
203
+ if ( unix ( ) ) {
204
+ nativeRm ( shell . ShellString ( 'file.txt' ) ) ;
205
+ } else {
206
+ // shell.del(shell.ShellString('file.txt'));
207
+ shell . rm ( 'file.txt' ) ;
208
+ }
210
209
// TODO(nfischer): this fails on Windows
211
210
fs . existsSync ( 'file.txt' ) . should . equal ( false ) ;
212
211
done ( ) ;
@@ -224,7 +223,7 @@ describe('proxy', function describeproxy() {
224
223
it ( 'can use subcommands with options' , ( done ) => {
225
224
fs . existsSync ( 'package.json' ) . should . equal ( true ) ;
226
225
227
- // dont' actually remove this file, but do a dry run
226
+ // don't actually remove this file, but do a dry run
228
227
const ret = shell . git . rm ( '-qrnf' , 'package.json' ) ;
229
228
ret . code . should . equal ( 0 ) ;
230
229
ret . stdout . should . equal ( '' ) ;
@@ -233,8 +232,7 @@ describe('proxy', function describeproxy() {
233
232
} ) ;
234
233
235
234
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' ) ;
235
+ const ret = nativeEcho . one . two . three . four . five . six ( 'seven' ) ;
238
236
ret . stdout . should . equal ( 'one two three four five six seven\n' ) ;
239
237
ret . stderr . should . equal ( '' ) ;
240
238
ret . code . should . equal ( 0 ) ;
@@ -244,23 +242,26 @@ describe('proxy', function describeproxy() {
244
242
245
243
describe ( 'security' , ( ) => {
246
244
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
245
const fa = 'a.txt' ;
254
246
const fb = 'b.txt' ;
255
247
const fname = `${ fa } ;${ fb } ` ;
256
248
shell . exec ( 'echo hello world' ) . to ( fa ) ;
257
249
shell . exec ( 'echo hello world' ) . to ( fb ) ;
258
250
shell . exec ( 'echo hello world' ) . to ( fname ) ;
259
251
260
- shell [ delVarName ] ( fname ) ;
252
+ // All three files should exist at this point.
253
+ fs . existsSync ( fname ) . should . equal ( true ) ;
254
+ fs . existsSync ( fa ) . should . equal ( true ) ;
255
+ fs . existsSync ( fb ) . should . equal ( true ) ;
256
+
257
+ if ( unix ( ) ) {
258
+ nativeRm ( fname ) ;
259
+ } else {
260
+ shell . del ( fname ) ;
261
+ }
261
262
// 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 } ` ) ;
263
+ // fs.existsSync(fname).should.equal(false);
264
+ // shell.cat(fa).toString().should.equal(`hello world${os.EOL}`);
264
265
265
266
// These files are still ok
266
267
fs . existsSync ( fa ) . should . equal ( true ) ;
@@ -269,19 +270,16 @@ describe('proxy', function describeproxy() {
269
270
} ) ;
270
271
271
272
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
273
const fa = 'a.txt' ;
279
274
const fglob = '*.txt' ;
280
275
shell . exec ( 'echo hello world' ) . to ( fa ) ;
281
276
shell . exec ( 'echo hello world' ) . to ( fglob ) ;
282
277
283
- shell [ delVarName ] ( fglob ) ;
284
- // TODO(nfischer): this line fails on Windows
278
+ if ( unix ( ) ) {
279
+ nativeRm ( fglob ) ;
280
+ } else {
281
+ shell . del ( fglob ) ;
282
+ }
285
283
fs . existsSync ( fglob ) . should . equal ( false ) ;
286
284
shell . cat ( fa ) . toString ( ) . should . equal ( `hello world${ os . EOL } ` ) ;
287
285
@@ -302,7 +300,11 @@ describe('proxy', function describeproxy() {
302
300
const fquote = 'thisHas"Quotes.txt' ;
303
301
shell . exec ( 'echo hello world' ) . to ( fquote ) ;
304
302
fs . existsSync ( fquote ) . should . equal ( true ) ;
305
- shell [ delVarName ] ( fquote ) ;
303
+ if ( unix ( ) ) {
304
+ nativeRm ( fquote ) ;
305
+ } else {
306
+ shell . del ( fquote ) ;
307
+ }
306
308
fs . existsSync ( fquote ) . should . equal ( false ) ;
307
309
done ( ) ;
308
310
} ) ;
0 commit comments