From 646285f68406456c51d6b9e2aa3bb8dd5db2ecd1 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Sat, 9 May 2015 13:32:47 -0400 Subject: [PATCH] Add initial tests for basename. --- Makefile | 1 + test/basename.rs | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 test/basename.rs diff --git a/Makefile b/Makefile index 953999e2e..520dc41f1 100644 --- a/Makefile +++ b/Makefile @@ -158,6 +158,7 @@ endif # Programs with usable tests TEST_PROGS := \ + basename \ cat \ cp \ env \ diff --git a/test/basename.rs b/test/basename.rs new file mode 100644 index 000000000..6ecf224c0 --- /dev/null +++ b/test/basename.rs @@ -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"); +}