From 23cb9541e7aad442fa0c62c8ce219487c4c598eb Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Thu, 4 Jun 2015 00:04:37 -0400 Subject: [PATCH] Add initial tests for realpath. --- Makefile | 1 + test/realpath.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 test/realpath.rs diff --git a/Makefile b/Makefile index b4e463020..a15425d91 100644 --- a/Makefile +++ b/Makefile @@ -178,6 +178,7 @@ TEST_PROGS := \ ptx \ pwd \ readlink \ + realpath \ rm \ seq \ sort \ diff --git a/test/realpath.rs b/test/realpath.rs new file mode 100644 index 000000000..53cd539da --- /dev/null +++ b/test/realpath.rs @@ -0,0 +1,46 @@ +use std::process::Command; +use std::str; +use util::*; + +static PROGNAME: &'static str = "./realpath"; + +#[path = "common/util.rs"] +#[macro_use] +mod util; + +#[test] +fn test_current_directory() { + let po = Command::new(PROGNAME) + .arg(".") + .output() + .unwrap_or_else(|err| panic!("{}", err)); + + let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right(); + assert_eq!(out, current_directory()); +} + +#[test] +fn test_long_redirection_to_current_dir() { + // Create a 256-character path to current directory + let dir = repeat_str("./", 128); + 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, current_directory()); +} + +#[test] +fn test_long_redirection_to_root() { + // Create a 255-character path to root + let dir = repeat_str("../", 85); + 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, "/"); +}