1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 03:57:44 +00:00

Add initial tests for basename.

This commit is contained in:
Joseph Crail 2015-05-09 13:32:47 -04:00
parent 234c81311f
commit 646285f684
2 changed files with 55 additions and 0 deletions

View file

@ -158,6 +158,7 @@ endif
# Programs with usable tests
TEST_PROGS := \
basename \
cat \
cp \
env \

54
test/basename.rs Normal file
View file

@ -0,0 +1,54 @@
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");
}