mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
basename: in tests, assert error-free in usage
This commit is contained in:
parent
962fcd7183
commit
21cee1556b
1 changed files with 12 additions and 18 deletions
|
@ -5,40 +5,34 @@ use common::util::*;
|
||||||
|
|
||||||
static UTIL_NAME: &'static str = "basename";
|
static UTIL_NAME: &'static str = "basename";
|
||||||
|
|
||||||
|
fn expect_successful_stdout(input: Vec<&str>, expected: &str) {
|
||||||
|
let (_, mut ucmd) = testing(UTIL_NAME);
|
||||||
|
let results = ucmd.args(&input).run();
|
||||||
|
assert_empty_stderr!(results);
|
||||||
|
assert!(results.success);
|
||||||
|
assert_eq!(expected, results.stdout.trim_right());
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_directory() {
|
fn test_directory() {
|
||||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
|
||||||
let dir = "/root/alpha/beta/gamma/delta/epsilon/omega/";
|
let dir = "/root/alpha/beta/gamma/delta/epsilon/omega/";
|
||||||
ucmd.arg(dir);
|
expect_successful_stdout(vec![dir], "omega");
|
||||||
|
|
||||||
assert_eq!(ucmd.run().stdout.trim_right(), "omega");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_file() {
|
fn test_file() {
|
||||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
|
||||||
let file = "/etc/passwd";
|
let file = "/etc/passwd";
|
||||||
ucmd.arg(file);
|
expect_successful_stdout(vec![file], "passwd");
|
||||||
|
|
||||||
assert_eq!(ucmd.run().stdout.trim_right(), "passwd");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_remove_suffix() {
|
fn test_remove_suffix() {
|
||||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
|
||||||
let path = "/usr/local/bin/reallylongexecutable.exe";
|
let path = "/usr/local/bin/reallylongexecutable.exe";
|
||||||
ucmd.arg(path)
|
expect_successful_stdout(vec![path, ".exe"], "reallylongexecutable");
|
||||||
.arg(".exe");
|
|
||||||
|
|
||||||
assert_eq!(ucmd.run().stdout.trim_right(), "reallylongexecutable");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_dont_remove_suffix() {
|
fn test_dont_remove_suffix() {
|
||||||
let (_, mut ucmd) = testing(UTIL_NAME);
|
|
||||||
let path = "/foo/bar/baz";
|
let path = "/foo/bar/baz";
|
||||||
ucmd.arg(path)
|
expect_successful_stdout(vec![path, "baz"], "baz");
|
||||||
.arg("baz");
|
|
||||||
|
|
||||||
assert_eq!(ucmd.run().stdout.trim_right(), "baz");
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue