| 1 |
// This file is part of the uutils coreutils package. |
| 2 |
// |
| 3 |
// For the full copyright and license information, please view the LICENSE |
| 4 |
// file that was distributed with this source code. |
| 5 |
|
| 6 |
use regex::Regex; |
| 7 |
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] |
| 8 |
use std::fs::OpenOptions; |
| 9 |
use uutests::new_ucmd; |
| 10 |
|
| 11 |
#[test] |
| 12 |
fn test_no_args() { |
| 13 |
new_ucmd!().succeeds().no_output(); |
| 14 |
} |
| 15 |
|
| 16 |
#[test] |
| 17 |
fn test_version() { |
| 18 |
let re = Regex::new(r"^true .*\d+\.\d+\.\d+\n$").unwrap(); |
| 19 |
|
| 20 |
new_ucmd!() |
| 21 |
.args(&["--version"]) |
| 22 |
.succeeds() |
| 23 |
.stdout_matches(&re); |
| 24 |
} |
| 25 |
|
| 26 |
#[test] |
| 27 |
fn test_help() { |
| 28 |
new_ucmd!() |
| 29 |
.args(&["--help"]) |
| 30 |
.succeeds() |
| 31 |
.stdout_contains("true"); |
| 32 |
} |
| 33 |
|
| 34 |
#[test] |
| 35 |
fn test_short_options() { |
| 36 |
for option in ["-h", "-V"] { |
| 37 |
new_ucmd!().arg(option).succeeds().no_output(); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
#[test] |
| 42 |
fn test_extra_args() { |
| 43 |
for option in ["--help", "--version"] { |
| 44 |
new_ucmd!().args(&[option, "test"]).succeeds().no_output(); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
#[test] |
| 49 |
fn test_conflict() { |
| 50 |
new_ucmd!() |
| 51 |
.args(&["--help", "--version"]) |
| 52 |
.succeeds() |
| 53 |
.no_output(); |
| 54 |
} |
| 55 |
|
| 56 |
#[test] |
| 57 |
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "netbsd"))] |
| 58 |
fn test_full() { |
| 59 |
for option in ["--version", "--help"] { |
| 60 |
let dev_full = OpenOptions::new().write(true).open("/dev/full").unwrap(); |
| 61 |
|
| 62 |
new_ucmd!() |
| 63 |
.arg(option) |
| 64 |
.set_stdout(dev_full) |
| 65 |
.fails() |
| 66 |
.stderr_is("true: No space left on device\n"); |
| 67 |
} |
| 68 |
} |