diff --git a/src/pinky/pinky.rs b/src/pinky/pinky.rs index 783f7879a..72ccb8f5d 100644 --- a/src/pinky/pinky.rs +++ b/src/pinky/pinky.rs @@ -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(), diff --git a/src/who/who.rs b/src/who/who.rs index 3f5fa402d..29a6e7ee5 100644 --- a/src/who/who.rs +++ b/src/who/who.rs @@ -441,7 +441,7 @@ impl Who { let mut buf = vec![]; let ut_host = ut.host(); - let mut res = ut_host.split(':'); + let mut res = ut_host.splitn(2, ':'); if let Some(h) = res.next() { if self.do_lookup { buf.push(ut.canon_host().unwrap_or(h.to_owned())); diff --git a/tests/test_pinky.rs b/tests/test_pinky.rs index 816d85871..a46c131e7 100644 --- a/tests/test_pinky.rs +++ b/tests/test_pinky.rs @@ -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 = 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::>() + }) + .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")]