mirror of
https://github.com/uutils/coreutils
synced 2024-12-17 00:23:18 +00:00
54 lines
1.3 KiB
Rust
54 lines
1.3 KiB
Rust
use std::process::Command;
|
|
use std::str;
|
|
|
|
static PROGNAME: &'static str = "./basename";
|
|
|
|
#[test]
|
|
fn test_directory() {
|
|
let dir = "/root/alpha/beta/gamma/delta/epsilon/omega/";
|
|
let po = Command::new(PROGNAME)
|
|
.arg(dir)
|
|
.output()
|
|
.unwrap_or_else(|err| panic!("{}", err));
|
|
|
|
let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right();
|
|
assert_eq!(out, "omega");
|
|
}
|
|
|
|
#[test]
|
|
fn test_file() {
|
|
let file = "/etc/passwd";
|
|
let po = Command::new(PROGNAME)
|
|
.arg(file)
|
|
.output()
|
|
.unwrap_or_else(|err| panic!("{}", err));
|
|
|
|
let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right();
|
|
assert_eq!(out, "passwd");
|
|
}
|
|
|
|
#[test]
|
|
fn test_remove_suffix() {
|
|
let path = "/usr/local/bin/reallylongexecutable.exe";
|
|
let po = Command::new(PROGNAME)
|
|
.arg(path)
|
|
.arg(".exe")
|
|
.output()
|
|
.unwrap_or_else(|err| panic!("{}", err));
|
|
|
|
let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right();
|
|
assert_eq!(out, "reallylongexecutable");
|
|
}
|
|
|
|
#[test]
|
|
fn test_dont_remove_suffix() {
|
|
let path = "/foo/bar/baz";
|
|
let po = Command::new(PROGNAME)
|
|
.arg(path)
|
|
.arg("baz")
|
|
.output()
|
|
.unwrap_or_else(|err| panic!("{}", err));
|
|
|
|
let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right();
|
|
assert_eq!(out, "baz");
|
|
}
|