|
| 1 | +mod sys_common; |
| 2 | + |
1 | 3 | use cap_fs_ext::DirExt;
|
2 | 4 | use cap_tempfile::TempDir;
|
3 | 5 |
|
4 |
| -use sys_common::{io::tmpdir, symlink_supported}; |
| 6 | +use sys_common::symlink_supported; |
5 | 7 |
|
6 |
| - #[test] |
7 |
| - fn remove_file() { |
8 |
| - let tempdir = unsafe { TempDir::new() }.expect("create tempdir"); |
9 |
| - let file = tempdir.create("file").expect("create file to delete"); |
10 |
| - drop(file); |
11 |
| - tempdir.remove_file_or_symlink("file").expect("delete file"); |
12 |
| - assert!(!tempdir.exists("file"), "deletion worked"); |
13 |
| - } |
| 8 | +#[test] |
| 9 | +fn remove_file() { |
| 10 | + let tempdir = unsafe { TempDir::new() }.expect("create tempdir"); |
| 11 | + let file = tempdir.create("file").expect("create file to delete"); |
| 12 | + drop(file); |
| 13 | + tempdir.remove_file_or_symlink("file").expect("delete file"); |
| 14 | + assert!(!tempdir.exists("file"), "deletion worked"); |
| 15 | +} |
14 | 16 |
|
15 |
| - #[test] |
16 |
| - fn remove_symlink_to_file() { |
17 |
| - if !symlink_supported() { |
18 |
| - return; |
19 |
| - } |
20 |
| - |
21 |
| - let tempdir = unsafe { TempDir::new() }.expect("create tempdir"); |
22 |
| - let target = tempdir.create("target").expect("create target file"); |
23 |
| - drop(target); |
24 |
| - tempdir.symlink("target", "link").expect("create symlink"); |
25 |
| - assert!(tempdir.exists("link"), "link exists"); |
26 |
| - tempdir |
27 |
| - .remove_file_or_symlink("link") |
28 |
| - .expect("delete symlink"); |
29 |
| - assert!(!tempdir.exists("link"), "link deleted"); |
30 |
| - assert!(tempdir.exists("target"), "target not deleted"); |
| 17 | +#[test] |
| 18 | +fn remove_symlink_to_file() { |
| 19 | + if !symlink_supported() { |
| 20 | + return; |
31 | 21 | }
|
32 | 22 |
|
33 |
| - #[test] |
34 |
| - fn remove_symlink_to_dir() { |
35 |
| - if !symlink_supported() { |
36 |
| - return; |
37 |
| - } |
38 |
| - |
39 |
| - let tempdir = unsafe { TempDir::new() }.expect("create tempdir"); |
40 |
| - let target = tempdir.create_dir("target").expect("create target dir"); |
41 |
| - drop(target); |
42 |
| - tempdir.symlink("target", "link").expect("create symlink"); |
43 |
| - assert!(tempdir.exists("link"), "link exists"); |
44 |
| - tempdir |
45 |
| - .remove_file_or_symlink("link") |
46 |
| - .expect("delete symlink"); |
47 |
| - assert!(!tempdir.exists("link"), "link deleted"); |
48 |
| - assert!(tempdir.exists("target"), "target not deleted"); |
49 |
| - } |
| 23 | + let tempdir = unsafe { TempDir::new() }.expect("create tempdir"); |
| 24 | + let target = tempdir.create("target").expect("create target file"); |
| 25 | + drop(target); |
| 26 | + tempdir.symlink("target", "link").expect("create symlink"); |
| 27 | + assert!(tempdir.exists("link"), "link exists"); |
| 28 | + tempdir |
| 29 | + .remove_file_or_symlink("link") |
| 30 | + .expect("delete symlink"); |
| 31 | + assert!(!tempdir.exists("link"), "link deleted"); |
| 32 | + assert!(tempdir.exists("target"), "target not deleted"); |
| 33 | +} |
50 | 34 |
|
51 |
| - #[test] |
52 |
| - fn do_not_remove_dir() { |
53 |
| - let tempdir = unsafe { TempDir::new() }.expect("create tempdir"); |
54 |
| - let subdir = tempdir.create_dir("subdir").expect("create dir"); |
55 |
| - drop(subdir); |
56 |
| - assert!(tempdir.exists("subdir"), "subdir created"); |
57 |
| - tempdir |
58 |
| - .remove_file_or_symlink("subdir") |
59 |
| - .expect_err("should not delete empty directory"); |
60 |
| - assert!(tempdir.exists("subdir"), "subdir not deleted"); |
| 35 | +#[test] |
| 36 | +fn remove_symlink_to_dir() { |
| 37 | + if !symlink_supported() { |
| 38 | + return; |
61 | 39 | }
|
| 40 | + |
| 41 | + let tempdir = unsafe { TempDir::new() }.expect("create tempdir"); |
| 42 | + let target = tempdir.create_dir("target").expect("create target dir"); |
| 43 | + drop(target); |
| 44 | + tempdir.symlink("target", "link").expect("create symlink"); |
| 45 | + assert!(tempdir.exists("link"), "link exists"); |
| 46 | + tempdir |
| 47 | + .remove_file_or_symlink("link") |
| 48 | + .expect("delete symlink"); |
| 49 | + assert!(!tempdir.exists("link"), "link deleted"); |
| 50 | + assert!(tempdir.exists("target"), "target not deleted"); |
| 51 | +} |
| 52 | + |
| 53 | +#[test] |
| 54 | +fn do_not_remove_dir() { |
| 55 | + let tempdir = unsafe { TempDir::new() }.expect("create tempdir"); |
| 56 | + let subdir = tempdir.create_dir("subdir").expect("create dir"); |
| 57 | + drop(subdir); |
| 58 | + assert!(tempdir.exists("subdir"), "subdir created"); |
| 59 | + tempdir |
| 60 | + .remove_file_or_symlink("subdir") |
| 61 | + .expect_err("should not delete empty directory"); |
| 62 | + assert!(tempdir.exists("subdir"), "subdir not deleted"); |
| 63 | +} |
0 commit comments