mirror of
https://github.com/uutils/coreutils
synced 2024-11-16 17:58:06 +00:00
tests/fix ~ (stat) refactor '%w' and '%W' tests due to stat
limitations
- allow actual outputs to differ from expected (ie, `stat`) if `stat` is reporting "unknown" creation time .# [why] For many *nix flavors, `stat` is unable to detect birth/creation date for directories/files. The information is available via the `statx()` system call (for linux kernels >= v4.11), and rust supplies that information via fs::MetadataExt for v1.40+. So, for rust v1.40+, there will likely be a mismatch between the output of the system `stat` and this ('uutils') `stat`. * ref: <https://askubuntu.com/questions/470134/how-do-i-find-the-creation-time-of-a-file> @@ <https://archive.is/IsEAJ>
This commit is contained in:
parent
14c3f3aa17
commit
823fc17c2c
1 changed files with 45 additions and 4 deletions
|
@ -1,3 +1,5 @@
|
|||
extern crate regex;
|
||||
|
||||
use common::util::*;
|
||||
|
||||
extern crate uu_stat;
|
||||
|
@ -144,7 +146,7 @@ fn test_invalid_option() {
|
|||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
const NORMAL_FMTSTR: &'static str = "%a %A %b %B %d %D %f %F %g %G %h %i %m %n %o %s %u %U %w %W %x %X %y %Y %z %Z";
|
||||
const NORMAL_FMTSTR: &'static str = "%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
|
||||
#[cfg(target_os = "linux")]
|
||||
const DEV_FMTSTR: &'static str = "%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";
|
||||
#[cfg(target_os = "linux")]
|
||||
|
@ -171,10 +173,49 @@ fn test_fs_format() {
|
|||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_terse_normal_format() {
|
||||
// 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
|
||||
let args = ["-t", "/"];
|
||||
new_ucmd!().args(&args)
|
||||
.run()
|
||||
.stdout_is(expected_result(&args));
|
||||
let actual = new_ucmd!().args(&args).run().stdout;
|
||||
let expect = expected_result(&args);
|
||||
println!("actual: {:?}", actual);
|
||||
println!("expect: {:?}", expect);
|
||||
let v_actual: Vec<&str> = actual.split(' ').collect();
|
||||
let v_expect: Vec<&str> = expect.split(' ').collect();
|
||||
// * allow for inequality if `stat` (aka, expect) returns "0" (unknown value)
|
||||
assert!(v_actual.iter().zip(v_expect.iter()).all(|(a,e)| a == e || *e == "0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_format_created_time() {
|
||||
let args = ["-c", "%w", "/boot"];
|
||||
let actual = new_ucmd!().args(&args).run().stdout;
|
||||
let expect = expected_result(&args);
|
||||
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();
|
||||
// * allow for inequality if `stat` (aka, expect) returns "-" (unknown value)
|
||||
assert!(v_actual.iter().zip(v_expect.iter()).all(|(a,e)| a == e || *e == "-"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(target_os = "linux")]
|
||||
fn test_format_created_seconds() {
|
||||
let args = ["-c", "%W", "/boot"];
|
||||
let actual = new_ucmd!().args(&args).run().stdout;
|
||||
let expect = expected_result(&args);
|
||||
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();
|
||||
// * allow for inequality if `stat` (aka, expect) returns "0" (unknown value)
|
||||
assert!(v_actual.iter().zip(v_expect.iter()).all(|(a,e)| a == e || *e == "0"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue