From e700e0d2f47b4c58cf452ed4d9e322f0100b4511 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Sat, 9 May 2015 15:16:45 -0400 Subject: [PATCH] Add initial tests for dirname. --- Makefile | 1 + test/dirname.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/dirname.rs 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"); +}