coreutils/tests/by-util/test_pinky.rs

109 lines
3.6 KiB
Rust
Raw Normal View History

// * This file is part of the uutils coreutils package.
// *
// * For the full copyright and license information, please view the LICENSE
// * file that was distributed with this source code.
2017-03-17 18:38:21 +00:00
extern crate uucore;
2016-07-26 08:43:25 +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
extern crate pinky;
pub use self::pinky::*;
2016-07-26 08:43:25 +00:00
#[test]
fn test_capitalize() {
2021-05-31 03:55:28 +00:00
assert_eq!("Zbnmasd", "zbnmasd".capitalize()); // spell-checker:disable-line
assert_eq!("Abnmasd", "Abnmasd".capitalize()); // spell-checker:disable-line
assert_eq!("1masd", "1masd".capitalize()); // spell-checker:disable-line
2016-07-26 08:43:25 +00:00
assert_eq!("", "".capitalize());
}
#[test]
fn test_long_format() {
let login = "root";
let pw: Passwd = Passwd::locate(login).unwrap();
let real_name = pw.user_info.replace('&', &pw.name.capitalize());
let ts = TestScenario::new(util_name!());
ts.ucmd().arg("-l").arg(login).succeeds().stdout_is(format!(
"Login name: {:<28}In real life: {}\nDirectory: {:<29}Shell: {}\n\n",
login, real_name, pw.user_dir, pw.user_shell
));
ts.ucmd()
.arg("-lb")
.arg(login)
.succeeds()
.stdout_is(format!(
"Login name: {:<28}In real life: {1}\n\n",
login, real_name
));
2016-07-26 08:43:25 +00:00
}
#[cfg(unix)]
#[test]
fn test_long_format_multiple_users() {
2022-02-22 22:35:16 +00:00
// multiple instances of one account we know exists,
// the account of the test runner,
// and an account that (probably) doesn't exist
let runner = match std::env::var("USER") {
Ok(user) => user,
Err(_) => "".to_string(),
};
let args = ["-l", "root", "root", "root", &runner, "no_such_user"];
let ts = TestScenario::new(util_name!());
let expect = unwrap_or_return!(expected_result(&ts, &args));
ts.ucmd()
.args(&args)
.succeeds()
.stdout_is(expect.stdout_str())
.stderr_is(expect.stderr_str());
}
#[test]
fn test_long_format_wo_user() {
// "no username specified; at least one must be specified when using -l"
2022-01-11 13:24:54 +00:00
new_ucmd!().arg("-l").fails();
}
#[cfg(unix)]
2016-07-26 08:43:25 +00:00
#[test]
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"];
let ts = TestScenario::new(util_name!());
let actual = ts.ucmd().args(&args).succeeds().stdout_move_str();
let expect = unwrap_or_return!(expected_result(&ts, &args)).stdout_move_str();
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(unix)]
#[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"];
let ts = TestScenario::new(util_name!());
let actual = ts.ucmd().args(&args).succeeds().stdout_move_str();
let expect = unwrap_or_return!(expected_result(&ts, &args)).stdout_move_str();
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(unix)]
#[test]
fn test_no_flag() {
let ts = TestScenario::new(util_name!());
let actual = ts.ucmd().succeeds().stdout_move_str();
let expect = unwrap_or_return!(expected_result(&ts, &[])).stdout_move_str();
let v_actual: Vec<&str> = actual.split_whitespace().collect();
let v_expect: Vec<&str> = expect.split_whitespace().collect();
assert_eq!(v_actual, v_expect);
}