From e700e0d2f47b4c58cf452ed4d9e322f0100b4511 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Sat, 9 May 2015 15:16:45 -0400 Subject: [PATCH 1/4] 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"); +} From 87e7cc9b44c351a1db9d336043a6684d32ff7dcf Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Sat, 9 May 2015 15:17:01 -0400 Subject: [PATCH 2/4] Add initial tests for echo. --- Makefile | 1 + test/echo.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 test/echo.rs diff --git a/Makefile b/Makefile index 9c034c2f6..2caacbdab 100644 --- a/Makefile +++ b/Makefile @@ -162,6 +162,7 @@ TEST_PROGS := \ cp \ env \ dirname \ + echo \ factor \ fold \ mkdir \ diff --git a/test/echo.rs b/test/echo.rs new file mode 100644 index 000000000..b107fd4c4 --- /dev/null +++ b/test/echo.rs @@ -0,0 +1,50 @@ +use std::process::Command; +use std::str; + +static PROGNAME: &'static str = "./echo"; + +#[test] +fn test_default() { + let po = Command::new(PROGNAME) + .output() + .unwrap_or_else(|err| panic!("{}", err)); + + let out = str::from_utf8(&po.stdout[..]).unwrap(); + assert_eq!(out, "\n"); +} + +#[test] +fn test_no_trailing_newline() { + let po = Command::new(PROGNAME) + .arg("-n") + .arg("hello_world") + .output() + .unwrap_or_else(|err| panic!("{}", err)); + + let out = str::from_utf8(&po.stdout[..]).unwrap(); + assert_eq!(out, "hello_world"); +} + +#[test] +fn test_enable_escapes() { + let po = Command::new(PROGNAME) + .arg("-e") + .arg("\\\\\\t\\r") + .output() + .unwrap_or_else(|err| panic!("{}", err)); + + let out = str::from_utf8(&po.stdout[..]).unwrap(); + assert_eq!(out, "\\\t\r\n"); +} + +#[test] +fn test_disable_escapes() { + let po = Command::new(PROGNAME) + .arg("-E") + .arg("\\b\\c\\e") + .output() + .unwrap_or_else(|err| panic!("{}", err)); + + let out = str::from_utf8(&po.stdout[..]).unwrap(); + assert_eq!(out, "\\b\\c\\e\n"); +} From 9172bb9bd88529d95f628bc80e95618e9fef72cd Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Sat, 9 May 2015 15:17:16 -0400 Subject: [PATCH 3/4] Add initial tests for false/true. --- Makefile | 2 ++ test/false.rs | 9 +++++++++ test/true.rs | 9 +++++++++ 3 files changed, 20 insertions(+) create mode 100644 test/false.rs create mode 100644 test/true.rs diff --git a/Makefile b/Makefile index 2caacbdab..ad6009ec7 100644 --- a/Makefile +++ b/Makefile @@ -164,6 +164,7 @@ TEST_PROGS := \ dirname \ echo \ factor \ + false \ fold \ mkdir \ mv \ @@ -173,6 +174,7 @@ TEST_PROGS := \ sort \ test \ tr \ + true \ truncate \ unexpand diff --git a/test/false.rs b/test/false.rs new file mode 100644 index 000000000..2cd6a327d --- /dev/null +++ b/test/false.rs @@ -0,0 +1,9 @@ +use std::process::Command; + +static PROGNAME: &'static str = "./false"; + +#[test] +fn test_exit_code() { + let exit_status = Command::new(PROGNAME).status().unwrap().success(); + assert_eq!(exit_status, false); +} diff --git a/test/true.rs b/test/true.rs new file mode 100644 index 000000000..fba9fff36 --- /dev/null +++ b/test/true.rs @@ -0,0 +1,9 @@ +use std::process::Command; + +static PROGNAME: &'static str = "./true"; + +#[test] +fn test_exit_code() { + let exit_status = Command::new(PROGNAME).status().unwrap().success(); + assert_eq!(exit_status, true); +} From 08aea6d549a3ea7006a05686a99f4839c1255db6 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Sat, 9 May 2015 15:17:26 -0400 Subject: [PATCH 4/4] Add initial test for pwd. --- Makefile | 1 + test/pwd.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/pwd.rs diff --git a/Makefile b/Makefile index ad6009ec7..e382b534a 100644 --- a/Makefile +++ b/Makefile @@ -170,6 +170,7 @@ TEST_PROGS := \ mv \ nl \ paste \ + pwd \ seq \ sort \ test \ diff --git a/test/pwd.rs b/test/pwd.rs new file mode 100644 index 000000000..0800b3ae4 --- /dev/null +++ b/test/pwd.rs @@ -0,0 +1,16 @@ +use std::env; +use std::process::Command; +use std::str; + +static PROGNAME: &'static str = "./pwd"; + +#[test] +fn test_default() { + let po = Command::new(PROGNAME) + .output() + .unwrap_or_else(|err| panic!("{}", err)); + + let out = str::from_utf8(&po.stdout[..]).unwrap().trim_right(); + let expected = env::current_dir().unwrap().into_os_string().into_string().unwrap(); + assert_eq!(out, expected); +}