fix(stat): Collection of fixes for stat(1)
This PR fixes #9071, #9072, as well as a few bugs found along the way.
CodSpeed Performance Report
Merging #9078 will not alter performance
Comparing Alonely0:stat_fix (55eee3e) with main (aaa0610)
Summary
✅ 127 untouched
⏩ 6 skipped[^skipped]
[^skipped]: 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.
I mean, that's not my fault lol.
GNU testsuite comparison:
Skipping an intermittent issue tests/tail/overlay-headers (passes in this run but fails in the 'main' branch)
I think it'd be better to add tests for the device number and the percent escape issues as well.
For the percent escape issue, I propose the following addition to test_stat.rs:
#[test]
fn test_double_percent() {
let ts = TestScenario::new(util_name!());
let result = ts.ucmd().args(&["-c", "%%m", "/"]).succeeds();
let output = result.stdout_str().trim();
assert!(!output.is_empty(), "Escaped percent should be present");
assert_eq!(output, "%m");
}
For the device number format issue, I'd add %Hd %Ld %r %R %Hr %Lr to one of NORMAL_FORMAT_STR, DEV_FORMAT_STR, or FS_FORMAT_STR in test_stat.rs, but I'm not familiar enough with the purpose of each of those to suggest which one(s) they should be added to.
Yeah I agree, I'll add a few tests :). Ngl, I was trying to cut that corner cuz tomorrow I got an exam, but it should be quick enough.
Testing the value of these flags (%Hd %Ld %r %R %Hr %Lr) is actually correct is quite difficult without bringing in the machine's stat as a reference, because their output is not trivial. Rn, in CI it's probably either GNU or busybox, but knowing Ubuntu's switched to uutils we might as well be testing against an older version of uutils in the future. This is why I'm choosing against including that test, and only one about percent escaping. Maintainers, lmk if you would like me to include it nevertheless (it's already written lol).
GNU testsuite comparison:
Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)
Those CI fails are still not my fault :) Also, I'll probably be opening a few PRs with perf improvements, passes of clippy nightly, and I'll probably refactor stat's format parser so it's less spaghetti-y; iirc stat is not the only coreutil that does use percent escaping (ls, date, du and printf come to my mind) so I feel strongly like adding a general impl to uu_core or common and refactoring these other coreutils. If you approve, I'll have it done by the end of next week (I'm done w/ my exams on Wednesday :) )
GNU testsuite comparison:
Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/cksum/b2sum is no longer failing!
GNU testsuite comparison:
Skip an intermittent issue tests/tail/overlay-headers (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/cksum/b2sum is no longer failing!