|
1 | 1 | use crate::common::util::*; |
2 | 2 |
|
| 3 | +extern crate regex; |
| 4 | +use self::regex::Regex; |
| 5 | + |
| 6 | +use std::thread::sleep; |
| 7 | +use std::time::Duration; |
| 8 | + |
| 9 | +#[cfg(not(windows))] |
| 10 | +extern crate libc; |
| 11 | +#[cfg(not(windows))] |
| 12 | +use self::libc::umask; |
| 13 | +#[cfg(not(windows))] |
| 14 | +use std::sync::Mutex; |
| 15 | + |
| 16 | +#[cfg(not(windows))] |
| 17 | +lazy_static! { |
| 18 | + static ref UMASK_MUTEX: Mutex<()> = Mutex::new(()); |
| 19 | +} |
| 20 | + |
3 | 21 | #[test] |
4 | 22 | fn test_ls_ls() { |
5 | 23 | new_ucmd!().succeeds(); |
6 | 24 | } |
7 | 25 |
|
8 | 26 | #[test] |
9 | | -fn test_ls_ls_i() { |
| 27 | +fn test_ls_i() { |
10 | 28 | new_ucmd!().arg("-i").succeeds(); |
11 | 29 | new_ucmd!().arg("-il").succeeds(); |
12 | 30 | } |
13 | 31 |
|
| 32 | +#[test] |
| 33 | +fn test_ls_a() { |
| 34 | + let scene = TestScenario::new(util_name!()); |
| 35 | + let at = &scene.fixtures; |
| 36 | + at.touch(".test-1"); |
| 37 | + |
| 38 | + let result = scene.ucmd().run(); |
| 39 | + println!("stderr = {:?}", result.stderr); |
| 40 | + println!("stdout = {:?}", result.stdout); |
| 41 | + assert!(result.success); |
| 42 | + assert!(!result.stdout.contains(".test-1")); |
| 43 | + assert!(!result.stdout.contains("..")); |
| 44 | + |
| 45 | + let result = scene.ucmd().arg("-a").run(); |
| 46 | + println!("stderr = {:?}", result.stderr); |
| 47 | + println!("stdout = {:?}", result.stdout); |
| 48 | + assert!(result.success); |
| 49 | + assert!(result.stdout.contains(".test-1")); |
| 50 | + assert!(result.stdout.contains("..")); |
| 51 | + |
| 52 | + let result = scene.ucmd().arg("-A").run(); |
| 53 | + println!("stderr = {:?}", result.stderr); |
| 54 | + println!("stdout = {:?}", result.stdout); |
| 55 | + assert!(result.success); |
| 56 | + assert!(result.stdout.contains(".test-1")); |
| 57 | + assert!(!result.stdout.contains("..")); |
| 58 | +} |
| 59 | + |
| 60 | +#[test] |
| 61 | +fn test_ls_long() { |
| 62 | + #[cfg(not(windows))] |
| 63 | + let mut last; |
| 64 | + #[cfg(not(windows))] |
| 65 | + { |
| 66 | + let _guard = UMASK_MUTEX.lock(); |
| 67 | + last = unsafe { umask(0) }; |
| 68 | + |
| 69 | + unsafe { |
| 70 | + umask(0o002); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + let (at, mut ucmd) = at_and_ucmd!(); |
| 75 | + at.touch(&at.plus_as_string("test-long")); |
| 76 | + let result = ucmd.arg("-l").arg("test-long").succeeds(); |
| 77 | + println!("stderr = {:?}", result.stderr); |
| 78 | + println!("stdout = {:?}", result.stdout); |
| 79 | + #[cfg(not(windows))] |
| 80 | + assert!(result.stdout.contains("-rw-rw-r--")); |
| 81 | + |
| 82 | + #[cfg(windows)] |
| 83 | + assert!(result.stdout.contains("---------- 1 somebody somegroup")); |
| 84 | + |
| 85 | + #[cfg(not(windows))] |
| 86 | + { |
| 87 | + unsafe { |
| 88 | + umask(last); |
| 89 | + } |
| 90 | + } |
| 91 | +} |
| 92 | + |
| 93 | +#[test] |
| 94 | +fn test_ls_deref() { |
| 95 | + let scene = TestScenario::new(util_name!()); |
| 96 | + let at = &scene.fixtures; |
| 97 | + let path_regexp = r"(.*)test-long.link -> (.*)test-long(.*)"; |
| 98 | + let re = Regex::new(path_regexp).unwrap(); |
| 99 | + |
| 100 | + at.touch(&at.plus_as_string("test-long")); |
| 101 | + at.symlink_file("test-long", "test-long.link"); |
| 102 | + assert!(at.is_symlink("test-long.link")); |
| 103 | + |
| 104 | + let result = scene |
| 105 | + .ucmd() |
| 106 | + .arg("-l") |
| 107 | + .arg("--color=never") |
| 108 | + .arg("test-long") |
| 109 | + .arg("test-long.link") |
| 110 | + .run(); |
| 111 | + println!("stderr = {:?}", result.stderr); |
| 112 | + println!("stdout = {:?}", result.stdout); |
| 113 | + assert!(result.success); |
| 114 | + assert!(re.is_match(&result.stdout.trim())); |
| 115 | + |
| 116 | + let result = scene |
| 117 | + .ucmd() |
| 118 | + .arg("-L") |
| 119 | + .arg("--color=never") |
| 120 | + .arg("test-long") |
| 121 | + .arg("test-long.link") |
| 122 | + .run(); |
| 123 | + println!("stderr = {:?}", result.stderr); |
| 124 | + println!("stdout = {:?}", result.stdout); |
| 125 | + assert!(result.success); |
| 126 | + assert!(!re.is_match(&result.stdout.trim())); |
| 127 | +} |
| 128 | + |
| 129 | +#[test] |
| 130 | +fn test_ls_order_size() { |
| 131 | + let scene = TestScenario::new(util_name!()); |
| 132 | + let at = &scene.fixtures; |
| 133 | + |
| 134 | + at.touch("test-1"); |
| 135 | + at.append("test-1", "1"); |
| 136 | + |
| 137 | + at.touch("test-2"); |
| 138 | + at.append("test-2", "22"); |
| 139 | + at.touch("test-3"); |
| 140 | + at.append("test-3", "333"); |
| 141 | + at.touch("test-4"); |
| 142 | + at.append("test-4", "4444"); |
| 143 | + |
| 144 | + let result = scene.ucmd().arg("-al").run(); |
| 145 | + println!("stderr = {:?}", result.stderr); |
| 146 | + println!("stdout = {:?}", result.stdout); |
| 147 | + assert!(result.success); |
| 148 | + |
| 149 | + let result = scene.ucmd().arg("-S").run(); |
| 150 | + println!("stderr = {:?}", result.stderr); |
| 151 | + println!("stdout = {:?}", result.stdout); |
| 152 | + assert!(result.success); |
| 153 | + #[cfg(not(windows))] |
| 154 | + assert_eq!(result.stdout, "test-4\ntest-3\ntest-2\ntest-1\n"); |
| 155 | + #[cfg(windows)] |
| 156 | + assert_eq!(result.stdout, "test-4 test-3 test-2 test-1\n"); |
| 157 | + |
| 158 | + let result = scene.ucmd().arg("-S").arg("-r").run(); |
| 159 | + println!("stderr = {:?}", result.stderr); |
| 160 | + println!("stdout = {:?}", result.stdout); |
| 161 | + assert!(result.success); |
| 162 | + #[cfg(not(windows))] |
| 163 | + assert_eq!(result.stdout, "test-1\ntest-2\ntest-3\ntest-4\n"); |
| 164 | + #[cfg(windows)] |
| 165 | + assert_eq!(result.stdout, "test-1 test-2 test-3 test-4\n"); |
| 166 | +} |
| 167 | + |
| 168 | +#[test] |
| 169 | +fn test_ls_order_creation() { |
| 170 | + let scene = TestScenario::new(util_name!()); |
| 171 | + let at = &scene.fixtures; |
| 172 | + |
| 173 | + at.touch("test-1"); |
| 174 | + at.append("test-1", "1"); |
| 175 | + sleep(Duration::from_millis(500)); |
| 176 | + at.touch("test-2"); |
| 177 | + at.append("test-2", "22"); |
| 178 | + sleep(Duration::from_millis(500)); |
| 179 | + at.touch("test-3"); |
| 180 | + at.append("test-3", "333"); |
| 181 | + sleep(Duration::from_millis(500)); |
| 182 | + at.touch("test-4"); |
| 183 | + at.append("test-4", "4444"); |
| 184 | + |
| 185 | + let result = scene.ucmd().arg("-al").run(); |
| 186 | + println!("stderr = {:?}", result.stderr); |
| 187 | + println!("stdout = {:?}", result.stdout); |
| 188 | + assert!(result.success); |
| 189 | + |
| 190 | + let result = scene.ucmd().arg("-t").run(); |
| 191 | + println!("stderr = {:?}", result.stderr); |
| 192 | + println!("stdout = {:?}", result.stdout); |
| 193 | + assert!(result.success); |
| 194 | + #[cfg(not(windows))] |
| 195 | + assert_eq!(result.stdout, "test-4\ntest-3\ntest-2\ntest-1\n"); |
| 196 | + #[cfg(windows)] |
| 197 | + assert_eq!(result.stdout, "test-4 test-3 test-2 test-1\n"); |
| 198 | + |
| 199 | + let result = scene.ucmd().arg("-t").arg("-r").run(); |
| 200 | + println!("stderr = {:?}", result.stderr); |
| 201 | + println!("stdout = {:?}", result.stdout); |
| 202 | + assert!(result.success); |
| 203 | + #[cfg(not(windows))] |
| 204 | + assert_eq!(result.stdout, "test-1\ntest-2\ntest-3\ntest-4\n"); |
| 205 | + #[cfg(windows)] |
| 206 | + assert_eq!(result.stdout, "test-1 test-2 test-3 test-4\n"); |
| 207 | +} |
| 208 | + |
14 | 209 | #[test] |
15 | 210 | fn test_ls_non_existing() { |
16 | 211 | new_ucmd!().arg("doesntexist").fails(); |
@@ -68,16 +263,46 @@ fn test_ls_recursive() { |
68 | 263 |
|
69 | 264 | println!("stderr = {:?}", result.stderr); |
70 | 265 | println!("stdout = {:?}", result.stdout); |
71 | | - if cfg!(target_os = "windows") { |
72 | | - assert!(result.stdout.contains("a\\b:\nb")); |
73 | | - } else { |
74 | | - assert!(result.stdout.contains("a/b:\nb")); |
75 | | - } |
| 266 | + assert!(result.success); |
| 267 | + #[cfg(not(windows))] |
| 268 | + assert!(result.stdout.contains("a/b:\nb")); |
| 269 | + #[cfg(windows)] |
| 270 | + assert!(result.stdout.contains("a\\b:\nb")); |
76 | 271 | } |
77 | 272 |
|
78 | 273 | #[test] |
79 | 274 | fn test_ls_ls_color() { |
80 | | - new_ucmd!().arg("--color").succeeds(); |
81 | | - new_ucmd!().arg("--color=always").succeeds(); |
82 | | - new_ucmd!().arg("--color=never").succeeds(); |
| 275 | + let scene = TestScenario::new(util_name!()); |
| 276 | + let at = &scene.fixtures; |
| 277 | + at.mkdir("a"); |
| 278 | + at.mkdir("z"); |
| 279 | + at.touch(&at.plus_as_string("a/a")); |
| 280 | + scene.ucmd().arg("--color").succeeds(); |
| 281 | + scene.ucmd().arg("--color=always").succeeds(); |
| 282 | + scene.ucmd().arg("--color=never").succeeds(); |
| 283 | + scene.ucmd().arg("--color").arg("a").succeeds(); |
| 284 | + scene.ucmd().arg("--color=always").arg("a/a").succeeds(); |
| 285 | + scene.ucmd().arg("--color=never").arg("z").succeeds(); |
| 286 | +} |
| 287 | + |
| 288 | +#[test] |
| 289 | +fn test_ls_human() { |
| 290 | + let scene = TestScenario::new(util_name!()); |
| 291 | + let at = &scene.fixtures; |
| 292 | + let file = "test_human"; |
| 293 | + let result = scene.cmd("truncate").arg("-s").arg("+1000").arg(file).run(); |
| 294 | + println!("stderr = {:?}", result.stderr); |
| 295 | + println!("stdout = {:?}", result.stdout); |
| 296 | + assert!(result.success); |
| 297 | + let result = scene.ucmd().arg("-hl").arg(file).run(); |
| 298 | + println!("stderr = {:?}", result.stderr); |
| 299 | + println!("stdout = {:?}", result.stdout); |
| 300 | + assert!(result.success); |
| 301 | + assert!(result.stdout.contains("1.00K")); |
| 302 | + let result = scene.cmd("truncate").arg("-s").arg("+1000k").arg(file).run(); |
| 303 | + let result = scene.ucmd().arg("-hl").arg(file).run(); |
| 304 | + println!("stderr = {:?}", result.stderr); |
| 305 | + println!("stdout = {:?}", result.stdout); |
| 306 | + assert!(result.success); |
| 307 | + assert!(result.stdout.contains("1.02M")); |
83 | 308 | } |
0 commit comments