1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

pinky: add tests

This commit is contained in:
Knight 2016-07-26 16:43:25 +08:00
parent 6fff3a7665
commit be20d8605d
3 changed files with 81 additions and 7 deletions

View file

@ -13,13 +13,6 @@ time = "*"
libc = "^0.2" libc = "^0.2"
uucore = { path="../uucore" } uucore = { path="../uucore" }
[dependencies.clippy]
version = "*"
optional = true
[features]
default = []
[[bin]] [[bin]]
name = "pinky" name = "pinky"
path = "main.rs" path = "main.rs"

80
tests/test_pinky.rs Normal file
View file

@ -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()
}

View file

@ -29,6 +29,7 @@ unix_only! {
"chown", test_chown; "chown", test_chown;
"mv", test_mv; "mv", test_mv;
"pathchk", test_pathchk; "pathchk", test_pathchk;
"pinky", test_pinky;
"stdbuf", test_stdbuf; "stdbuf", test_stdbuf;
"touch", test_touch; "touch", test_touch;
"unlink", test_unlink; "unlink", test_unlink;