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

pinky: correct the test

This commit is contained in:
Knight 2016-08-20 19:50:31 +08:00
parent d0b5b9a9fd
commit 34d2224098
2 changed files with 28 additions and 24 deletions

View file

@ -244,7 +244,7 @@ impl Pinky {
if self.include_where && !ut.host().is_empty() {
let ut_host = ut.host();
let mut res = ut_host.split(':');
let mut res = ut_host.splitn(2, ':');
let host = match res.next() {
Some(_) => ut.canon_host().unwrap_or(ut_host.clone()),
None => ut_host.clone(),

View file

@ -5,6 +5,21 @@ fn new_ucmd() -> UCommand {
TestScenario::new(UTIL_NAME).ucmd()
}
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();
}
extern crate uu_pinky;
pub use self::uu_pinky::*;
@ -17,31 +32,20 @@ fn test_capitalize() {
}
#[test]
#[cfg(target_os = "linux")]
fn test_long_format() {
new_ucmd()
.arg("-l").arg("root")
.run()
.stdout_is("Login name: root In real life: root\nDirectory: /root Shell: /bin/bash\n\n");
PASSWD.with(|v| {
let gecos = v[4].replace("&", &v[4].capitalize());
new_ucmd()
.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]));
new_ucmd()
.arg("-lb").arg("root")
.run()
.stdout_is("Login name: root In real life: root\n\n");
}
#[test]
#[cfg(target_os = "macos")]
fn test_long_format() {
new_ucmd()
.arg("-l").arg("root")
.run()
.stdout_is("Login name: root In real life: System Administrator\nDirectory: /var/root Shell: /bin/sh\n\n");
new_ucmd()
.arg("-lb").arg("root")
.run()
.stdout_is("Login name: root In real life: System Administrator\n\n");
new_ucmd()
.arg("-lb")
.arg("root")
.run()
.stdout_is(format!("Login name: {:<28}In real life: {1}\n\n", v[0], gecos));
})
}
#[cfg(target_os = "linux")]