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.
|
|
|
|
|
2019-12-24 23:35:17 +00:00
|
|
|
extern crate regex;
|
|
|
|
|
2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2016-06-04 05:27:32 +00:00
|
|
|
|
2020-05-04 06:25:36 +00:00
|
|
|
extern crate stat;
|
|
|
|
pub use self::stat::*;
|
2016-06-17 08:15:50 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-05-30 05:10:54 +00:00
|
|
|
fn test_scanners() {
|
2016-06-17 08:15:50 +00:00
|
|
|
assert_eq!(Some((-5, 2)), "-5zxc".scan_num::<i32>());
|
|
|
|
assert_eq!(Some((51, 2)), "51zxc".scan_num::<u32>());
|
|
|
|
assert_eq!(Some((192, 4)), "+192zxc".scan_num::<i32>());
|
|
|
|
assert_eq!(None, "z192zxc".scan_num::<i32>());
|
|
|
|
|
|
|
|
assert_eq!(Some(('a', 3)), "141zxc".scan_char(8));
|
2021-05-31 03:55:28 +00:00
|
|
|
assert_eq!(Some(('\n', 2)), "12qzxc".scan_char(8)); // spell-checker:disable-line
|
|
|
|
assert_eq!(Some(('\r', 1)), "dqzxc".scan_char(16)); // spell-checker:disable-line
|
|
|
|
assert_eq!(None, "z2qzxc".scan_char(8)); // spell-checker:disable-line
|
2016-06-17 08:15:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-05-30 05:10:54 +00:00
|
|
|
fn test_group_num() {
|
2016-06-17 08:15:50 +00:00
|
|
|
assert_eq!("12,379,821,234", group_num("12379821234"));
|
|
|
|
assert_eq!("21,234", group_num("21234"));
|
|
|
|
assert_eq!("821,234", group_num("821234"));
|
|
|
|
assert_eq!("1,821,234", group_num("1821234"));
|
|
|
|
assert_eq!("1,234", group_num("1234"));
|
|
|
|
assert_eq!("234", group_num("234"));
|
|
|
|
assert_eq!("24", group_num("24"));
|
|
|
|
assert_eq!("4", group_num("4"));
|
|
|
|
assert_eq!("", group_num(""));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod test_generate_tokens {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn normal_format() {
|
|
|
|
let s = "%'010.2ac%-#5.w\n";
|
2020-04-13 18:36:03 +00:00
|
|
|
let expected = vec![
|
|
|
|
Token::Directive {
|
|
|
|
flag: F_GROUP | F_ZERO,
|
|
|
|
width: 10,
|
|
|
|
precision: 2,
|
|
|
|
format: 'a',
|
|
|
|
},
|
|
|
|
Token::Char('c'),
|
|
|
|
Token::Directive {
|
|
|
|
flag: F_LEFT | F_ALTER,
|
|
|
|
width: 5,
|
|
|
|
precision: 0,
|
|
|
|
format: 'w',
|
|
|
|
},
|
|
|
|
Token::Char('\n'),
|
|
|
|
];
|
2016-06-17 08:15:50 +00:00
|
|
|
assert_eq!(&expected, &Stater::generate_tokens(s, false).unwrap());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn printf_format() {
|
|
|
|
let s = "%-# 15a\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.-23w\\x12\\167\\132\\112\\n";
|
2020-04-13 18:36:03 +00:00
|
|
|
let expected = vec![
|
|
|
|
Token::Directive {
|
|
|
|
flag: F_LEFT | F_ALTER | F_SPACE,
|
|
|
|
width: 15,
|
|
|
|
precision: -1,
|
|
|
|
format: 'a',
|
|
|
|
},
|
|
|
|
Token::Char('\r'),
|
|
|
|
Token::Char('"'),
|
|
|
|
Token::Char('\\'),
|
|
|
|
Token::Char('\x07'),
|
|
|
|
Token::Char('\x08'),
|
|
|
|
Token::Char('\x1B'),
|
|
|
|
Token::Char('\x0C'),
|
|
|
|
Token::Char('\x0B'),
|
|
|
|
Token::Directive {
|
|
|
|
flag: F_SIGN | F_ZERO,
|
|
|
|
width: 20,
|
|
|
|
precision: -1,
|
|
|
|
format: 'w',
|
|
|
|
},
|
|
|
|
Token::Char('\x12'),
|
|
|
|
Token::Char('w'),
|
|
|
|
Token::Char('Z'),
|
|
|
|
Token::Char('J'),
|
|
|
|
Token::Char('\n'),
|
|
|
|
];
|
2016-06-17 08:15:50 +00:00
|
|
|
assert_eq!(&expected, &Stater::generate_tokens(s, true).unwrap());
|
|
|
|
}
|
|
|
|
}
|
2016-06-04 05:27:32 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_invalid_option() {
|
2020-04-13 18:36:03 +00:00
|
|
|
new_ucmd!().arg("-w").arg("-q").arg("/").fails();
|
2016-06-04 05:27:32 +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
|
|
|
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
|
2021-05-30 05:10:54 +00:00
|
|
|
const NORMAL_FORMAT_STR: &str =
|
2020-04-13 18:36:03 +00:00
|
|
|
"%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s %u %U %x %X %y %Y %z %Z"; // avoid "%w %W" (birth/creation) due to `stat` limitations and linux kernel & rust version capability variations
|
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
|
|
|
#[cfg(any(target_os = "linux"))]
|
2021-05-30 05:10:54 +00:00
|
|
|
const DEV_FORMAT_STR: &str =
|
2020-04-13 18:36:03 +00:00
|
|
|
"%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s (%t/%T) %u %U %w %W %x %X %y %Y %z %Z";
|
2016-07-29 13:19:52 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
2021-05-30 05:10:54 +00:00
|
|
|
const FS_FORMAT_STR: &str = "%b %c %i %l %n %s %S %t %T"; // avoid "%a %d %f" which can cause test failure due to race conditions
|
2016-06-17 08:15:50 +00:00
|
|
|
|
2016-06-04 05:27:32 +00:00
|
|
|
#[test]
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
fn test_terse_fs_format() {
|
|
|
|
let args = ["-f", "-t", "/proc"];
|
2021-07-07 20:46:16 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let expected_stdout = unwrap_or_return!(expected_result(&ts, &args)).stdout_move_str();
|
|
|
|
ts.ucmd().args(&args).run().stdout_is(expected_stdout);
|
2016-06-04 05:27:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
fn test_fs_format() {
|
2021-05-30 05:10:54 +00:00
|
|
|
let args = ["-f", "-c", FS_FORMAT_STR, "/dev/shm"];
|
2021-07-07 20:46:16 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let expected_stdout = unwrap_or_return!(expected_result(&ts, &args)).stdout_move_str();
|
|
|
|
ts.ucmd().args(&args).run().stdout_is(expected_stdout);
|
2016-06-04 05:27:32 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 13:54:03 +00:00
|
|
|
#[cfg(unix)]
|
2016-06-04 05:27:32 +00:00
|
|
|
#[test]
|
|
|
|
fn test_terse_normal_format() {
|
2019-12-24 23:35:17 +00:00
|
|
|
// note: contains birth/creation date which increases test fragility
|
|
|
|
// * results may vary due to built-in `stat` limitations as well as linux kernel and rust version capability variations
|
2016-06-04 05:27:32 +00:00
|
|
|
let args = ["-t", "/"];
|
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();
|
2019-12-24 23:35:17 +00:00
|
|
|
println!("actual: {:?}", actual);
|
|
|
|
println!("expect: {:?}", expect);
|
2021-05-03 21:09:45 +00:00
|
|
|
let v_actual: Vec<&str> = actual.trim().split(' ').collect();
|
|
|
|
let mut v_expect: Vec<&str> = expect.trim().split(' ').collect();
|
2020-05-24 03:43:00 +00:00
|
|
|
assert!(!v_expect.is_empty());
|
2021-05-03 21:09:45 +00:00
|
|
|
|
|
|
|
// uu_stat does not support selinux
|
2021-05-29 12:32:35 +00:00
|
|
|
if v_actual.len() == v_expect.len() - 1 && v_expect[v_expect.len() - 1].contains(':') {
|
2021-05-03 21:09:45 +00:00
|
|
|
// assume last element contains: `SELinux security context string`
|
|
|
|
v_expect.pop();
|
|
|
|
}
|
|
|
|
|
2019-12-24 23:35:17 +00:00
|
|
|
// * allow for inequality if `stat` (aka, expect) returns "0" (unknown value)
|
2020-05-24 03:43:00 +00:00
|
|
|
assert!(
|
|
|
|
expect == "0"
|
|
|
|
|| expect == "0\n"
|
|
|
|
|| v_actual
|
|
|
|
.iter()
|
|
|
|
.zip(v_expect.iter())
|
|
|
|
.all(|(a, e)| a == e || *e == "0" || *e == "0\n")
|
|
|
|
);
|
2019-12-24 23:35:17 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 13:54:03 +00:00
|
|
|
#[cfg(unix)]
|
2019-12-24 23:35:17 +00:00
|
|
|
#[test]
|
|
|
|
fn test_format_created_time() {
|
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
|
|
|
let args = ["-c", "%w", "/bin"];
|
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();
|
2019-12-24 23:35:17 +00:00
|
|
|
println!("actual: {:?}", actual);
|
|
|
|
println!("expect: {:?}", expect);
|
|
|
|
// note: using a regex instead of `split_whitespace()` in order to detect whitespace differences
|
|
|
|
let re = regex::Regex::new(r"\s").unwrap();
|
|
|
|
let v_actual: Vec<&str> = re.split(&actual).collect();
|
|
|
|
let v_expect: Vec<&str> = re.split(&expect).collect();
|
2020-05-24 03:43:00 +00:00
|
|
|
assert!(!v_expect.is_empty());
|
2019-12-24 23:35:17 +00:00
|
|
|
// * allow for inequality if `stat` (aka, expect) returns "-" (unknown value)
|
2020-05-24 03:43:00 +00:00
|
|
|
assert!(
|
|
|
|
expect == "-"
|
|
|
|
|| expect == "-\n"
|
|
|
|
|| v_actual
|
|
|
|
.iter()
|
|
|
|
.zip(v_expect.iter())
|
|
|
|
.all(|(a, e)| a == e || *e == "-" || *e == "-\n")
|
|
|
|
);
|
2019-12-24 23:35:17 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 13:54:03 +00:00
|
|
|
#[cfg(unix)]
|
2019-12-24 23:35:17 +00:00
|
|
|
#[test]
|
|
|
|
fn test_format_created_seconds() {
|
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
|
|
|
let args = ["-c", "%W", "/bin"];
|
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();
|
2019-12-24 23:35:17 +00:00
|
|
|
println!("actual: {:?}", actual);
|
|
|
|
println!("expect: {:?}", expect);
|
|
|
|
// note: using a regex instead of `split_whitespace()` in order to detect whitespace differences
|
|
|
|
let re = regex::Regex::new(r"\s").unwrap();
|
|
|
|
let v_actual: Vec<&str> = re.split(&actual).collect();
|
|
|
|
let v_expect: Vec<&str> = re.split(&expect).collect();
|
2020-05-24 03:43:00 +00:00
|
|
|
assert!(!v_expect.is_empty());
|
2019-12-24 23:35:17 +00:00
|
|
|
// * allow for inequality if `stat` (aka, expect) returns "0" (unknown value)
|
2020-05-24 03:43:00 +00:00
|
|
|
assert!(
|
|
|
|
expect == "0"
|
|
|
|
|| expect == "0\n"
|
|
|
|
|| v_actual
|
|
|
|
.iter()
|
|
|
|
.zip(v_expect.iter())
|
|
|
|
.all(|(a, e)| a == e || *e == "0" || *e == "0\n")
|
|
|
|
);
|
2016-06-04 05:27:32 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 13:54:03 +00:00
|
|
|
#[cfg(unix)]
|
2016-06-04 05:27:32 +00:00
|
|
|
#[test]
|
|
|
|
fn test_normal_format() {
|
2021-05-30 05:10:54 +00:00
|
|
|
let args = ["-c", NORMAL_FORMAT_STR, "/bin"];
|
2021-07-07 20:46:16 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let expected_stdout = unwrap_or_return!(expected_result(&ts, &args)).stdout_move_str();
|
|
|
|
ts.ucmd().args(&args).succeeds().stdout_is(expected_stdout);
|
2016-06-04 05:27:32 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 13:54:03 +00:00
|
|
|
#[cfg(unix)]
|
2016-06-04 05:27:32 +00:00
|
|
|
#[test]
|
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
|
|
|
fn test_symlinks() {
|
2021-07-07 20:46:16 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let at = &ts.fixtures;
|
2016-06-04 05:27:32 +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
|
|
|
let mut tested: bool = false;
|
|
|
|
// arbitrarily chosen symlinks with hope that the CI environment provides at least one of them
|
2021-05-29 12:32:35 +00:00
|
|
|
for file in &[
|
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
|
|
|
"/bin/sh",
|
|
|
|
"/bin/sudoedit",
|
|
|
|
"/usr/bin/ex",
|
|
|
|
"/etc/localtime",
|
|
|
|
"/etc/aliases",
|
|
|
|
] {
|
|
|
|
if at.file_exists(file) && at.is_symlink(file) {
|
|
|
|
tested = true;
|
2021-05-30 05:10:54 +00:00
|
|
|
let args = ["-c", NORMAL_FORMAT_STR, file];
|
2021-07-07 20:46:16 +00:00
|
|
|
let expected_stdout = unwrap_or_return!(expected_result(&ts, &args)).stdout_move_str();
|
|
|
|
ts.ucmd().args(&args).succeeds().stdout_is(expected_stdout);
|
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
|
|
|
// -L, --dereference follow links
|
2021-05-30 05:10:54 +00:00
|
|
|
let args = ["-L", "-c", NORMAL_FORMAT_STR, file];
|
2021-07-07 20:46:16 +00:00
|
|
|
let expected_stdout = unwrap_or_return!(expected_result(&ts, &args)).stdout_move_str();
|
|
|
|
ts.ucmd().args(&args).succeeds().stdout_is(expected_stdout);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
if !tested {
|
|
|
|
panic!("No symlink found to test in this environment");
|
|
|
|
}
|
2016-06-04 05:27:32 +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
|
|
|
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
|
2016-06-04 05:27:32 +00:00
|
|
|
#[test]
|
|
|
|
fn test_char() {
|
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
|
|
|
// TODO: "(%t) (%x) (%w)" deviate from GNU stat for `character special file` on macOS
|
|
|
|
// Diff < left / right > :
|
|
|
|
// <"(f0000) (2021-05-20 23:08:03.442555000 +0200) (1970-01-01 01:00:00.000000000 +0100)\n"
|
|
|
|
// >"(f) (2021-05-20 23:08:03.455598000 +0200) (-)\n"
|
|
|
|
let args = [
|
|
|
|
"-c",
|
|
|
|
#[cfg(target_os = "linux")]
|
2021-05-30 05:10:54 +00:00
|
|
|
DEV_FORMAT_STR,
|
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
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
"/dev/pts/ptmx",
|
|
|
|
#[cfg(any(target_vendor = "apple"))]
|
|
|
|
"%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s (/%T) %u %U %W %X %y %Y %z %Z",
|
|
|
|
#[cfg(any(target_vendor = "apple"))]
|
|
|
|
"/dev/ptmx",
|
|
|
|
];
|
2021-07-07 20:46:16 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let expected_stdout = unwrap_or_return!(expected_result(&ts, &args)).stdout_move_str();
|
|
|
|
ts.ucmd().args(&args).succeeds().stdout_is(expected_stdout);
|
2016-06-04 05:27:32 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 13:54:03 +00:00
|
|
|
#[cfg(unix)]
|
2016-06-04 05:27:32 +00:00
|
|
|
#[test]
|
|
|
|
fn test_multi_files() {
|
2020-04-13 18:36:03 +00:00
|
|
|
let args = [
|
|
|
|
"-c",
|
2021-05-30 05:10:54 +00:00
|
|
|
NORMAL_FORMAT_STR,
|
2020-04-13 18:36:03 +00:00
|
|
|
"/dev",
|
|
|
|
"/usr/lib",
|
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
|
|
|
#[cfg(target_os = "linux")]
|
2020-04-13 18:36:03 +00:00
|
|
|
"/etc/fstab",
|
|
|
|
"/var",
|
|
|
|
];
|
2021-07-07 20:46:16 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let expected_stdout = unwrap_or_return!(expected_result(&ts, &args)).stdout_move_str();
|
|
|
|
ts.ucmd().args(&args).succeeds().stdout_is(expected_stdout);
|
2021-05-03 20:30:56 +00:00
|
|
|
}
|
|
|
|
|
2021-07-07 13:54:03 +00:00
|
|
|
#[cfg(unix)]
|
2016-06-04 05:27:32 +00:00
|
|
|
#[test]
|
|
|
|
fn test_printf() {
|
2020-04-13 18:36:03 +00:00
|
|
|
let args = [
|
|
|
|
"--printf=123%-# 15q\\r\\\"\\\\\\a\\b\\e\\f\\v%+020.23m\\x12\\167\\132\\112\\n",
|
|
|
|
"/",
|
|
|
|
];
|
2021-07-07 20:46:16 +00:00
|
|
|
let ts = TestScenario::new(util_name!());
|
|
|
|
let expected_stdout = unwrap_or_return!(expected_result(&ts, &args)).stdout_move_str();
|
|
|
|
ts.ucmd().args(&args).succeeds().stdout_is(expected_stdout);
|
2016-06-04 05:27:32 +00:00
|
|
|
}
|