From 87e7cc9b44c351a1db9d336043a6684d32ff7dcf Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Sat, 9 May 2015 15:17:01 -0400 Subject: [PATCH] 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"); +}