coreutils/tests/test_pinky.rs

63 lines
1.6 KiB
Rust
Raw Normal View History

2016-07-26 08:43:25 +00:00
use common::util::*;
2016-08-20 11:50:31 +00:00
use ::std::fs::File;
use ::std::io::BufReader;
use ::std::io::BufRead;
thread_local! {
static PASSWD: Vec<String> = BufReader::new(File::open("/etc/passwd").unwrap())
.lines()
.filter_map(|l| l.ok())
.filter(|l| l.starts_with("root:"))
.map(|l| {
l.split(':').map(|s| s.to_owned()).collect::<Vec<_>>()
})
.next().unwrap();
}
2016-07-26 08:43:25 +00:00
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]
fn test_long_format() {
2016-08-20 11:50:31 +00:00
PASSWD.with(|v| {
let gecos = v[4].replace("&", &v[4].capitalize());
new_ucmd!()
2016-08-20 11:50:31 +00:00
.arg("-l").arg("root")
.run()
.stdout_is(format!("Login name: {:<28}In real life: {}\nDirectory: {:<29}Shell: {}\n", v[0], gecos, v[5], v[6]));
2016-07-26 08:43:25 +00:00
new_ucmd!()
2016-08-20 11:50:31 +00:00
.arg("-lb")
.arg("root")
.run()
.stdout_is(format!("Login name: {:<28}In real life: {1}\n\n", v[0], gecos));
})
2016-07-26 08:43:25 +00:00
}
#[cfg(target_os = "linux")]
#[test]
fn test_short_format() {
let scene = TestScenario::new(util_name!());
2016-07-26 08:43:25 +00:00
let args = ["-i"];
scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
2016-07-26 08:43:25 +00:00
let args = ["-q"];
scene.ucmd().args(&args).run().stdout_is(expected_result(&args));
2016-07-26 08:43:25 +00:00
}
#[cfg(target_os = "linux")]
fn expected_result(args: &[&str]) -> String {
TestScenario::new(util_name!()).cmd_keepenv(util_name!()).args(args).run().stdout
2016-07-26 08:43:25 +00:00
}