2017-03-17 18:38:21 +00:00
|
|
|
extern crate uucore;
|
2016-07-26 08:43:25 +00:00
|
|
|
|
2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2016-08-20 11:50:31 +00:00
|
|
|
|
2017-03-17 18:38:21 +00:00
|
|
|
use self::uucore::entries::{Locate, Passwd};
|
2016-08-20 11:50:31 +00:00
|
|
|
|
2020-05-04 06:25:36 +00:00
|
|
|
extern crate pinky;
|
|
|
|
pub use self::pinky::*;
|
2016-07-26 08:43:25 +00:00
|
|
|
|
|
|
|
#[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() {
|
2017-03-17 18:38:21 +00:00
|
|
|
let ulogin = "root";
|
|
|
|
let pw: Passwd = Passwd::locate(ulogin).unwrap();
|
|
|
|
let real_name = pw.user_info().replace("&", &pw.name().capitalize());
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!().arg("-l").arg(ulogin).run().stdout_is(format!(
|
|
|
|
"Login name: {:<28}In real life: {}\nDirectory: {:<29}Shell: {}\n\n",
|
|
|
|
ulogin,
|
|
|
|
real_name,
|
|
|
|
pw.user_dir(),
|
|
|
|
pw.user_shell()
|
|
|
|
));
|
2017-03-17 18:38:21 +00:00
|
|
|
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!().arg("-lb").arg(ulogin).run().stdout_is(format!(
|
|
|
|
"Login name: {:<28}In real life: {1}\n\n",
|
|
|
|
ulogin, real_name
|
|
|
|
));
|
2016-07-26 08:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
2020-01-01 23:07:25 +00:00
|
|
|
fn test_short_format_i() {
|
|
|
|
// allow whitespace variation
|
|
|
|
// * minor whitespace differences occur between platform built-in outputs; specifically, the number of trailing TABs may be variant
|
2016-07-26 08:43:25 +00:00
|
|
|
let args = ["-i"];
|
2020-04-13 18:36:03 +00:00
|
|
|
let actual = TestScenario::new(util_name!())
|
|
|
|
.ucmd()
|
|
|
|
.args(&args)
|
2021-04-17 12:14:49 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_move_str();
|
2020-01-01 23:07:25 +00:00
|
|
|
let expect = expected_result(&args);
|
|
|
|
let v_actual: Vec<&str> = actual.split_whitespace().collect();
|
|
|
|
let v_expect: Vec<&str> = expect.split_whitespace().collect();
|
|
|
|
assert_eq!(v_actual, v_expect);
|
|
|
|
}
|
2016-07-26 08:43:25 +00:00
|
|
|
|
2020-01-01 23:07:25 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[test]
|
|
|
|
fn test_short_format_q() {
|
|
|
|
// allow whitespace variation
|
|
|
|
// * minor whitespace differences occur between platform built-in outputs; specifically, the number of trailing TABs may be variant
|
2016-07-26 08:43:25 +00:00
|
|
|
let args = ["-q"];
|
2020-04-13 18:36:03 +00:00
|
|
|
let actual = TestScenario::new(util_name!())
|
|
|
|
.ucmd()
|
|
|
|
.args(&args)
|
2021-04-17 12:14:49 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_move_str();
|
2020-01-01 23:07:25 +00:00
|
|
|
let expect = expected_result(&args);
|
|
|
|
let v_actual: Vec<&str> = actual.split_whitespace().collect();
|
|
|
|
let v_expect: Vec<&str> = expect.split_whitespace().collect();
|
|
|
|
assert_eq!(v_actual, v_expect);
|
2016-07-26 08:43:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
fn expected_result(args: &[&str]) -> String {
|
2020-04-13 18:36:03 +00:00
|
|
|
TestScenario::new(util_name!())
|
|
|
|
.cmd_keepenv(util_name!())
|
|
|
|
.env("LANGUAGE", "C")
|
|
|
|
.args(args)
|
|
|
|
.run()
|
2021-04-17 23:28:06 +00:00
|
|
|
.stdout_move_str()
|
2016-07-26 08:43:25 +00:00
|
|
|
}
|