2021-07-07 14:19:58 +00:00
|
|
|
// * 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
|
|
|
|
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() {
|
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() {
|
2021-05-30 05:10:54 +00:00
|
|
|
let login = "root";
|
|
|
|
let pw: Passwd = Passwd::locate(login).unwrap();
|
2022-02-17 05:58:34 +00:00
|
|
|
let user_info = pw.user_info.unwrap_or_default();
|
|
|
|
let user_dir = pw.user_dir.unwrap_or_default();
|
|
|
|
let user_shell = pw.user_shell.unwrap_or_default();
|
|
|
|
let real_name = user_info.replace('&', &pw.name.capitalize());
|
2021-07-07 20:46:16 +00:00
|
|
|
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",
|
2022-02-17 05:58:34 +00:00
|
|
|
login, real_name, user_dir, user_shell
|
2021-07-07 20:46:16 +00:00
|
|
|
));
|
who/stat/pinky: adjust tests to be compatible with running on macOS
A lot of tests depend on GNU's coreutils to be installed in order
to obtain reference values during testing.
In these cases testing is limited to `target_os = linux`.
This PR installs GNU's coreutils on "github actions" and adjusts the
tests for `who`, `stat` and `pinky` in order to be compatible with macOS.
* `brew install coreutils` (prefix is 'g', e.g. `gwho`, `gstat`, etc.
* switch paths for testing to something that's available on both OSs,
e.g. `/boot` -> `/bin`, etc.
* switch paths for testing to the macOS equivalent,
e.g. `/dev/pts/ptmx` -> `/dev/ptmx`, etc.
* exclude paths when no equivalent is available,
e.g. `/proc`, `/etc/fstab`, etc.
* refactor tests to make better use of the testing API
* fix a warning in utmpx.rs to print to stderr instead of stdout
* fix long_usage text in `who`
* fix minor output formatting in `stat`
* the `expected_result` function should be refactored
to reduce duplicate code
* more tests should be adjusted to not only run on `target_os = linux`
2021-05-20 21:11:40 +00:00
|
|
|
|
2021-07-07 20:46:16 +00:00
|
|
|
ts.ucmd()
|
who/stat/pinky: adjust tests to be compatible with running on macOS
A lot of tests depend on GNU's coreutils to be installed in order
to obtain reference values during testing.
In these cases testing is limited to `target_os = linux`.
This PR installs GNU's coreutils on "github actions" and adjusts the
tests for `who`, `stat` and `pinky` in order to be compatible with macOS.
* `brew install coreutils` (prefix is 'g', e.g. `gwho`, `gstat`, etc.
* switch paths for testing to something that's available on both OSs,
e.g. `/boot` -> `/bin`, etc.
* switch paths for testing to the macOS equivalent,
e.g. `/dev/pts/ptmx` -> `/dev/ptmx`, etc.
* exclude paths when no equivalent is available,
e.g. `/proc`, `/etc/fstab`, etc.
* refactor tests to make better use of the testing API
* fix a warning in utmpx.rs to print to stderr instead of stdout
* fix long_usage text in `who`
* fix minor output formatting in `stat`
* the `expected_result` function should be refactored
to reduce duplicate code
* more tests should be adjusted to not only run on `target_os = linux`
2021-05-20 21:11:40 +00:00
|
|
|
.arg("-lb")
|
2021-05-30 05:10:54 +00:00
|
|
|
.arg(login)
|
who/stat/pinky: adjust tests to be compatible with running on macOS
A lot of tests depend on GNU's coreutils to be installed in order
to obtain reference values during testing.
In these cases testing is limited to `target_os = linux`.
This PR installs GNU's coreutils on "github actions" and adjusts the
tests for `who`, `stat` and `pinky` in order to be compatible with macOS.
* `brew install coreutils` (prefix is 'g', e.g. `gwho`, `gstat`, etc.
* switch paths for testing to something that's available on both OSs,
e.g. `/boot` -> `/bin`, etc.
* switch paths for testing to the macOS equivalent,
e.g. `/dev/pts/ptmx` -> `/dev/ptmx`, etc.
* exclude paths when no equivalent is available,
e.g. `/proc`, `/etc/fstab`, etc.
* refactor tests to make better use of the testing API
* fix a warning in utmpx.rs to print to stderr instead of stdout
* fix long_usage text in `who`
* fix minor output formatting in `stat`
* the `expected_result` function should be refactored
to reduce duplicate code
* more tests should be adjusted to not only run on `target_os = linux`
2021-05-20 21:11:40 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_is(format!(
|
|
|
|
"Login name: {:<28}In real life: {1}\n\n",
|
2021-05-30 05:10:54 +00:00
|
|
|
login, real_name
|
who/stat/pinky: adjust tests to be compatible with running on macOS
A lot of tests depend on GNU's coreutils to be installed in order
to obtain reference values during testing.
In these cases testing is limited to `target_os = linux`.
This PR installs GNU's coreutils on "github actions" and adjusts the
tests for `who`, `stat` and `pinky` in order to be compatible with macOS.
* `brew install coreutils` (prefix is 'g', e.g. `gwho`, `gstat`, etc.
* switch paths for testing to something that's available on both OSs,
e.g. `/boot` -> `/bin`, etc.
* switch paths for testing to the macOS equivalent,
e.g. `/dev/pts/ptmx` -> `/dev/ptmx`, etc.
* exclude paths when no equivalent is available,
e.g. `/proc`, `/etc/fstab`, etc.
* refactor tests to make better use of the testing API
* fix a warning in utmpx.rs to print to stderr instead of stdout
* fix long_usage text in `who`
* fix minor output formatting in `stat`
* the `expected_result` function should be refactored
to reduce duplicate code
* more tests should be adjusted to not only run on `target_os = linux`
2021-05-20 21:11:40 +00:00
|
|
|
));
|
2016-07-26 08:43:25 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 13:53:46 +00:00
|
|
|
#[cfg(unix)]
|
2021-04-30 13:23:54 +00:00
|
|
|
#[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"];
|
2021-07-07 20:46:16 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let expect = unwrap_or_return!(expected_result(&ts, &args));
|
2021-04-30 13:23:54 +00:00
|
|
|
|
2021-07-07 20:46:16 +00:00
|
|
|
ts.ucmd()
|
who/stat/pinky: adjust tests to be compatible with running on macOS
A lot of tests depend on GNU's coreutils to be installed in order
to obtain reference values during testing.
In these cases testing is limited to `target_os = linux`.
This PR installs GNU's coreutils on "github actions" and adjusts the
tests for `who`, `stat` and `pinky` in order to be compatible with macOS.
* `brew install coreutils` (prefix is 'g', e.g. `gwho`, `gstat`, etc.
* switch paths for testing to something that's available on both OSs,
e.g. `/boot` -> `/bin`, etc.
* switch paths for testing to the macOS equivalent,
e.g. `/dev/pts/ptmx` -> `/dev/ptmx`, etc.
* exclude paths when no equivalent is available,
e.g. `/proc`, `/etc/fstab`, etc.
* refactor tests to make better use of the testing API
* fix a warning in utmpx.rs to print to stderr instead of stdout
* fix long_usage text in `who`
* fix minor output formatting in `stat`
* the `expected_result` function should be refactored
to reduce duplicate code
* more tests should be adjusted to not only run on `target_os = linux`
2021-05-20 21:11:40 +00:00
|
|
|
.args(&args)
|
2021-04-30 13:23:54 +00:00
|
|
|
.succeeds()
|
2021-07-07 13:53:46 +00:00
|
|
|
.stdout_is(expect.stdout_str())
|
|
|
|
.stderr_is(expect.stderr_str());
|
2021-04-30 13:23:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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();
|
2021-04-30 13:23:54 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 13:53:46 +00:00
|
|
|
#[cfg(unix)]
|
2016-07-26 08:43:25 +00:00
|
|
|
#[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"];
|
2021-07-07 20:46:16 +00:00
|
|
|
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();
|
2020-01-01 23:07:25 +00:00
|
|
|
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
|
|
|
|
2021-07-07 13:53:46 +00:00
|
|
|
#[cfg(unix)]
|
2020-01-01 23:07:25 +00:00
|
|
|
#[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"];
|
2021-07-07 20:46:16 +00:00
|
|
|
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();
|
2020-01-01 23:07:25 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-07-07 13:53:46 +00:00
|
|
|
#[cfg(unix)]
|
2021-05-13 08:17:57 +00:00
|
|
|
#[test]
|
|
|
|
fn test_no_flag() {
|
2021-07-07 20:46:16 +00:00
|
|
|
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();
|
2021-05-13 08:17:57 +00:00
|
|
|
let v_actual: Vec<&str> = actual.split_whitespace().collect();
|
|
|
|
let v_expect: Vec<&str> = expect.split_whitespace().collect();
|
|
|
|
assert_eq!(v_actual, v_expect);
|
|
|
|
}
|