|
2 | 2 | //
|
3 | 3 | // For the full copyright and license information, please view the LICENSE
|
4 | 4 | // file that was distributed with this source code.
|
| 5 | + |
| 6 | +// spell-checker:ignore (ToDO) unwritable |
5 | 7 | use crate::common::util::TestScenario;
|
6 | 8 |
|
7 | 9 | #[test]
|
@@ -199,6 +201,79 @@ fn test_head_count() {
|
199 | 201 | );
|
200 | 202 | }
|
201 | 203 |
|
| 204 | +#[test] |
| 205 | +fn test_zero_head_count_pipe() { |
| 206 | + let result = new_ucmd!().arg("-n0").pipe_in(vec![]).succeeds(); |
| 207 | + // Output must be completely empty, not even a newline! |
| 208 | + result.no_output(); |
| 209 | +} |
| 210 | + |
| 211 | +#[test] |
| 212 | +fn test_zero_head_count_pipe_explicit() { |
| 213 | + let result = new_ucmd!().arg("-n0").arg("-").pipe_in(vec![]).succeeds(); |
| 214 | + result.no_output(); |
| 215 | +} |
| 216 | + |
| 217 | +#[test] |
| 218 | +fn test_zero_head_count_file_unreadable() { |
| 219 | + new_ucmd!() |
| 220 | + .arg("-n0") |
| 221 | + .arg("/invalid/unreadable") |
| 222 | + .pipe_in(vec![]) |
| 223 | + .succeeds() |
| 224 | + .no_output(); |
| 225 | +} |
| 226 | + |
| 227 | +#[test] |
| 228 | +fn test_zero_head_count_file_touch_output_negative() { |
| 229 | + new_ucmd!() |
| 230 | + .arg("-n0") |
| 231 | + .arg("-o") |
| 232 | + .arg("/invalid/unwritable") |
| 233 | + .pipe_in(vec![]) |
| 234 | + .fails() |
| 235 | + .stderr_contains("failed to open '/invalid/unwritable' for writing:"); |
| 236 | +} |
| 237 | + |
| 238 | +#[test] |
| 239 | +fn test_zero_head_count_file_touch_output_positive_new() { |
| 240 | + let (at, mut ucmd) = at_and_ucmd!(); |
| 241 | + ucmd.args(&["-n0", "-o", "file"]).succeeds().no_output(); |
| 242 | + assert_eq!( |
| 243 | + at.read_bytes("file"), |
| 244 | + Vec::new(), |
| 245 | + "Output file must exist and be completely empty" |
| 246 | + ); |
| 247 | +} |
| 248 | + |
| 249 | +#[test] |
| 250 | +fn test_zero_head_count_file_touch_output_positive_existing() { |
| 251 | + let (at, mut ucmd) = at_and_ucmd!(); |
| 252 | + at.touch("file"); |
| 253 | + ucmd.args(&["-n0", "-o", "file"]).succeeds().no_output(); |
| 254 | + assert_eq!( |
| 255 | + at.read_bytes("file"), |
| 256 | + Vec::new(), |
| 257 | + "Output file must exist and be completely empty" |
| 258 | + ); |
| 259 | +} |
| 260 | + |
| 261 | +#[test] |
| 262 | +fn test_zero_head_count_echo() { |
| 263 | + new_ucmd!() |
| 264 | + .arg("-n0") |
| 265 | + .arg("-e") |
| 266 | + .arg("hello") |
| 267 | + .pipe_in(vec![]) |
| 268 | + .succeeds() |
| 269 | + .no_output(); |
| 270 | +} |
| 271 | + |
| 272 | +#[test] |
| 273 | +fn test_zero_head_count_range() { |
| 274 | + new_ucmd!().arg("-n0").arg("-i4-8").succeeds().no_output(); |
| 275 | +} |
| 276 | + |
202 | 277 | #[test]
|
203 | 278 | fn test_head_count_multi_big_then_small() {
|
204 | 279 | let repeat_limit = 5;
|
|
0 commit comments