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

Merge pull request #974 from knight42/fix-bugs

Fix bugs of `pinky` and `who`
This commit is contained in:
Michael Gehring 2016-08-20 15:16:19 +02:00 committed by GitHub
commit dcefbd54c6
3 changed files with 29 additions and 25 deletions

View file

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

View file

@ -441,7 +441,7 @@ impl Who {
let mut buf = vec![]; let mut buf = vec![];
let ut_host = ut.host(); 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 let Some(h) = res.next() {
if self.do_lookup { if self.do_lookup {
buf.push(ut.canon_host().unwrap_or(h.to_owned())); buf.push(ut.canon_host().unwrap_or(h.to_owned()));

View file

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