mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 12:07:46 +00:00
Add initial tests for basename.
This commit is contained in:
parent
234c81311f
commit
646285f684
2 changed files with 55 additions and 0 deletions
1
Makefile
1
Makefile
|
@ -158,6 +158,7 @@ endif
|
|||
|
||||
# Programs with usable tests
|
||||
TEST_PROGS := \
|
||||
basename \
|
||||
cat \
|
||||
cp \
|
||||
env \
|
||||
|
|
54
test/basename.rs
Normal file
54
test/basename.rs
Normal 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");
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue