diff --git a/Makefile b/Makefile index 8f8e68a9b..9c034c2f6 100644 --- a/Makefile +++ b/Makefile @@ -161,6 +161,7 @@ TEST_PROGS := \ cat \ cp \ env \ + dirname \ factor \ fold \ mkdir \ diff --git a/test/dirname.rs b/test/dirname.rs new file mode 100644 index 000000000..f0309ce9e --- /dev/null +++ b/test/dirname.rs @@ -0,0 +1,28 @@ +use std::process::Command; +use std::str; + +static PROGNAME: &'static str = "./dirname"; + +#[test] +fn test_path_with_trailing_slashes() { + 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, "/root/alpha/beta/gamma/delta/epsilon"); +} + +#[test] +fn test_path_without_trailing_slashes() { + 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, "/root/alpha/beta/gamma/delta/epsilon"); +}