@@ -35,11 +35,14 @@ test('file does not exist', t => {
35
35
t . is ( result . stderr , 'rm: no such file or directory: asdfasdf' ) ;
36
36
} ) ;
37
37
38
- test ( 'cannot delete a directoy without recursive flag' , t => {
38
+ test ( 'cannot delete a directory without recursive flag' , t => {
39
39
const result = shell . rm ( `${ t . context . tmp } /rm` ) ;
40
40
t . truthy ( shell . error ( ) ) ;
41
41
t . is ( result . code , 1 ) ;
42
42
t . is ( result . stderr , 'rm: path is a directory' ) ;
43
+ t . truthy ( fs . existsSync ( `${ t . context . tmp } /rm` ) ) ;
44
+ const contents = fs . readdirSync ( t . context . tmp ) ;
45
+ t . true ( contents . length > 0 ) ;
43
46
} ) ;
44
47
45
48
test ( 'only an option' , t => {
@@ -57,16 +60,23 @@ test('invalid option', t => {
57
60
t . is ( result . stderr , 'rm: option not recognized: @' ) ;
58
61
} ) ;
59
62
60
- test ( 'remove symbolic link to a dir without -r fails' , t => {
61
- utils . skipOnWin ( t , ( ) => {
62
- const result = shell . rm ( `${ t . context . tmp } /rm/link_to_a_dir/` ) ;
63
- t . truthy ( shell . error ( ) ) ;
64
- t . is ( result . code , 1 ) ;
65
- t . is ( result . stderr , 'rm: path is a directory' ) ;
66
- t . truthy ( fs . existsSync ( `${ t . context . tmp } /rm/link_to_a_dir` ) ) ;
67
- t . truthy ( fs . existsSync ( `${ t . context . tmp } /rm/a_dir` ) ) ;
68
- } ) ;
69
- } ) ;
63
+ test (
64
+ 'cannot remove a symbolic link to a directory with trailing slash without -r flag' ,
65
+ t => {
66
+ utils . skipOnWin ( t , ( ) => {
67
+ // the trailing slash signifies that we want to delete the source
68
+ // directory and its contents, which can only be done with the -r flag
69
+ const result = shell . rm ( `${ t . context . tmp } /rm/link_to_a_dir/` ) ;
70
+ t . truthy ( shell . error ( ) ) ;
71
+ t . is ( result . code , 1 ) ;
72
+ t . is ( result . stderr , 'rm: path is a directory' ) ;
73
+ t . truthy ( fs . existsSync ( `${ t . context . tmp } /rm/link_to_a_dir` ) ) ;
74
+ t . truthy ( fs . existsSync ( `${ t . context . tmp } /rm/a_dir` ) ) ;
75
+ const contents = fs . readdirSync ( `${ t . context . tmp } /rm/a_dir` ) ;
76
+ t . true ( contents . length > 0 ) ;
77
+ } ) ;
78
+ }
79
+ ) ;
70
80
71
81
//
72
82
// Valids
@@ -290,19 +300,54 @@ test('remove symbolic link to a dir', t => {
290
300
t . truthy ( fs . existsSync ( `${ t . context . tmp } /rm/a_dir` ) ) ;
291
301
} ) ;
292
302
293
- test ( 'rm -rf on a symbolic link to a dir deletes its contents' , t => {
303
+ test ( 'rm -r, symlink to a dir, trailing slash' , t => {
304
+ utils . skipOnWin ( t , ( ) => {
305
+ const result = shell . rm ( '-r' , `${ t . context . tmp } /rm/link_to_a_dir/` ) ;
306
+ t . truthy ( shell . error ( ) ) ;
307
+ t . is ( result . code , 1 ) ;
308
+ // Both the link and original dir should remain, but contents are deleted
309
+ t . truthy ( fs . existsSync ( `${ t . context . tmp } /rm/link_to_a_dir` ) ) ;
310
+ t . truthy ( fs . existsSync ( `${ t . context . tmp } /rm/a_dir` ) ) ;
311
+ t . falsy ( fs . existsSync ( `${ t . context . tmp } /rm/a_dir/a_file` ) ) ;
312
+ } ) ;
313
+ } ) ;
314
+
315
+ test ( 'rm -rf, symlink to a dir, trailing slash' , t => {
294
316
utils . skipOnWin ( t , ( ) => {
295
317
const result = shell . rm ( '-rf' , `${ t . context . tmp } /rm/link_to_a_dir/` ) ;
296
318
t . falsy ( shell . error ( ) ) ;
297
319
t . is ( result . code , 0 ) ;
298
-
299
320
// Both the link and original dir should remain, but contents are deleted
300
321
t . truthy ( fs . existsSync ( `${ t . context . tmp } /rm/link_to_a_dir` ) ) ;
301
322
t . truthy ( fs . existsSync ( `${ t . context . tmp } /rm/a_dir` ) ) ;
302
323
t . falsy ( fs . existsSync ( `${ t . context . tmp } /rm/a_dir/a_file` ) ) ;
303
324
} ) ;
304
325
} ) ;
305
326
327
+ test ( 'rm -r, symlink to a dir, no trailing slash' , t => {
328
+ utils . skipOnWin ( t , ( ) => {
329
+ const result = shell . rm ( '-rf' , `${ t . context . tmp } /rm/link_to_a_dir` ) ;
330
+ t . falsy ( shell . error ( ) ) ;
331
+ t . is ( result . code , 0 ) ;
332
+ // The link should be deleted, but the dir and contents remain
333
+ t . falsy ( fs . existsSync ( `${ t . context . tmp } /rm/link_to_a_dir` ) ) ;
334
+ t . truthy ( fs . existsSync ( `${ t . context . tmp } /rm/a_dir` ) ) ;
335
+ t . truthy ( fs . existsSync ( `${ t . context . tmp } /rm/a_dir/a_file` ) ) ;
336
+ } ) ;
337
+ } ) ;
338
+
339
+ test ( 'rm -rf, symlink to a dir, no trailing slash' , t => {
340
+ utils . skipOnWin ( t , ( ) => {
341
+ const result = shell . rm ( '-rf' , `${ t . context . tmp } /rm/link_to_a_dir` ) ;
342
+ t . falsy ( shell . error ( ) ) ;
343
+ t . is ( result . code , 0 ) ;
344
+ // The link should be deleted, but the dir and contents remain
345
+ t . falsy ( fs . existsSync ( `${ t . context . tmp } /rm/link_to_a_dir` ) ) ;
346
+ t . truthy ( fs . existsSync ( `${ t . context . tmp } /rm/a_dir` ) ) ;
347
+ t . truthy ( fs . existsSync ( `${ t . context . tmp } /rm/a_dir/a_file` ) ) ;
348
+ } ) ;
349
+ } ) ;
350
+
306
351
test ( 'remove broken symbolic link' , t => {
307
352
utils . skipOnWin ( t , ( ) => {
308
353
t . truthy ( shell . test ( '-L' , `${ t . context . tmp } /rm/fake.lnk` ) ) ;
0 commit comments