@@ -18,15 +18,29 @@ function unix() {
1818 return process . platform !== 'win32' ;
1919}
2020
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+
2138describe ( 'proxy' , function describeproxy ( ) {
2239 this . timeout ( 10000 ) ; // shell.exec() is slow
23- let delVarName ;
2440
2541 before ( ( ) => {
2642 // Configure shell variables so that we can use basic commands for testing
2743 // without using the ShellJS builtin
28- shell . env . del = unix ( ) ? 'rm' : 'del' ;
29- delVarName = unix ( ) ? '$del' : '%del%' ;
3044 shell . env . output = 'echo' ;
3145 shell . config . silent = true ;
3246 } ) ;
@@ -101,20 +115,6 @@ describe('proxy', function describeproxy() {
101115 } ) ;
102116
103117 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-
118118 it ( 'runs whoami' , ( ) => {
119119 if ( shell . which ( 'whoami' ) ) {
120120 const ret1 = shell . whoami ( ) ;
@@ -198,15 +198,14 @@ describe('proxy', function describeproxy() {
198198 } ) ;
199199
200200 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- }
207201 shell . touch ( 'file.txt' ) ;
208202 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+ }
210209 // TODO(nfischer): this fails on Windows
211210 fs . existsSync ( 'file.txt' ) . should . equal ( false ) ;
212211 done ( ) ;
@@ -224,7 +223,7 @@ describe('proxy', function describeproxy() {
224223 it ( 'can use subcommands with options' , ( done ) => {
225224 fs . existsSync ( 'package.json' ) . should . equal ( true ) ;
226225
227- // dont' actually remove this file, but do a dry run
226+ // don't actually remove this file, but do a dry run
228227 const ret = shell . git . rm ( '-qrnf' , 'package.json' ) ;
229228 ret . code . should . equal ( 0 ) ;
230229 ret . stdout . should . equal ( '' ) ;
@@ -233,8 +232,7 @@ describe('proxy', function describeproxy() {
233232 } ) ;
234233
235234 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' ) ;
238236 ret . stdout . should . equal ( 'one two three four five six seven\n' ) ;
239237 ret . stderr . should . equal ( '' ) ;
240238 ret . code . should . equal ( 0 ) ;
@@ -244,23 +242,26 @@ describe('proxy', function describeproxy() {
244242
245243 describe ( 'security' , ( ) => {
246244 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- }
253245 const fa = 'a.txt' ;
254246 const fb = 'b.txt' ;
255247 const fname = `${ fa } ;${ fb } ` ;
256248 shell . exec ( 'echo hello world' ) . to ( fa ) ;
257249 shell . exec ( 'echo hello world' ) . to ( fb ) ;
258250 shell . exec ( 'echo hello world' ) . to ( fname ) ;
259251
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+ }
261262 // 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}`);
264265
265266 // These files are still ok
266267 fs . existsSync ( fa ) . should . equal ( true ) ;
@@ -269,19 +270,16 @@ describe('proxy', function describeproxy() {
269270 } ) ;
270271
271272 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- }
278273 const fa = 'a.txt' ;
279274 const fglob = '*.txt' ;
280275 shell . exec ( 'echo hello world' ) . to ( fa ) ;
281276 shell . exec ( 'echo hello world' ) . to ( fglob ) ;
282277
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+ }
285283 fs . existsSync ( fglob ) . should . equal ( false ) ;
286284 shell . cat ( fa ) . toString ( ) . should . equal ( `hello world${ os . EOL } ` ) ;
287285
@@ -302,7 +300,11 @@ describe('proxy', function describeproxy() {
302300 const fquote = 'thisHas"Quotes.txt' ;
303301 shell . exec ( 'echo hello world' ) . to ( fquote ) ;
304302 fs . existsSync ( fquote ) . should . equal ( true ) ;
305- shell [ delVarName ] ( fquote ) ;
303+ if ( unix ( ) ) {
304+ nativeRm ( fquote ) ;
305+ } else {
306+ shell . del ( fquote ) ;
307+ }
306308 fs . existsSync ( fquote ) . should . equal ( false ) ;
307309 done ( ) ;
308310 } ) ;
0 commit comments