diff --git a/src/pinky/Cargo.toml b/src/pinky/Cargo.toml index 768190736..0e83fbf4a 100644 --- a/src/pinky/Cargo.toml +++ b/src/pinky/Cargo.toml @@ -13,13 +13,6 @@ time = "*" libc = "^0.2" uucore = { path="../uucore" } -[dependencies.clippy] -version = "*" -optional = true - -[features] -default = [] - [[bin]] name = "pinky" path = "main.rs" diff --git a/tests/test_pinky.rs b/tests/test_pinky.rs new file mode 100644 index 000000000..35af9c777 --- /dev/null +++ b/tests/test_pinky.rs @@ -0,0 +1,80 @@ +use common::util::*; + +static UTIL_NAME: &'static str = "pinky"; + +extern crate uu_pinky; +pub use self::uu_pinky::*; + +#[test] +fn test_capitalize() { + assert_eq!("Zbnmasd", "zbnmasd".capitalize()); + assert_eq!("Abnmasd", "Abnmasd".capitalize()); + assert_eq!("1masd", "1masd".capitalize()); + assert_eq!("", "".capitalize()); +} + +#[test] +#[cfg(target_os = "linux")] +fn test_long_format() { + let (_, mut ucmd) = testing(UTIL_NAME); + ucmd.arg("-l").arg("root"); + let expected = "Login name: root In real life: root\nDirectory: /root Shell: /bin/bash\n\n"; + assert_eq!(expected, ucmd.run().stdout); + + let (_, mut ucmd) = testing(UTIL_NAME); + ucmd.arg("-lb").arg("root"); + let expected = "Login name: root In real life: root\n\n"; + assert_eq!(expected, ucmd.run().stdout); +} + +#[test] +#[cfg(target_os = "macos")] +fn test_long_format() { + let (_, mut ucmd) = testing(UTIL_NAME); + ucmd.arg("-l").arg("root"); + let expected = "Login name: root In real life: System Administrator\nDirectory: /var/root Shell: /bin/sh\n\n"; + assert_eq!(expected, ucmd.run().stdout); + + let (_, mut ucmd) = testing(UTIL_NAME); + ucmd.arg("-lb").arg("root"); + let expected = "Login name: root In real life: System Administrator\n\n"; + assert_eq!(expected, ucmd.run().stdout); +} + +#[cfg(target_os = "linux")] +#[test] +#[ignore] +fn test_short_format() { + let (_, mut ucmd) = testing(UTIL_NAME); + let args = ["-s"]; + ucmd.args(&args); + assert_eq!(expected_result(&args), ucmd.run().stdout); + + let (_, mut ucmd) = testing(UTIL_NAME); + let args = ["-f"]; + ucmd.args(&args); + assert_eq!(expected_result(&args), ucmd.run().stdout); + + let (_, mut ucmd) = testing(UTIL_NAME); + let args = ["-w"]; + ucmd.args(&args); + assert_eq!(expected_result(&args), ucmd.run().stdout); + + let (_, mut ucmd) = testing(UTIL_NAME); + let args = ["-i"]; + ucmd.args(&args); + assert_eq!(expected_result(&args), ucmd.run().stdout); + + let (_, mut ucmd) = testing(UTIL_NAME); + let args = ["-q"]; + ucmd.args(&args); + assert_eq!(expected_result(&args), ucmd.run().stdout); +} + +#[cfg(target_os = "linux")] +fn expected_result(args: &[&str]) -> String { + use std::process::Command; + + let output = Command::new(UTIL_NAME).args(args).output().unwrap(); + String::from_utf8_lossy(&output.stdout).into_owned() +} diff --git a/tests/tests.rs b/tests/tests.rs index d867a934f..cb5a755a6 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -29,6 +29,7 @@ unix_only! { "chown", test_chown; "mv", test_mv; "pathchk", test_pathchk; + "pinky", test_pinky; "stdbuf", test_stdbuf; "touch", test_touch; "unlink", test_unlink;