Skip to content

Commit 96438f2

Browse files
committed
test_du: Fix --time=ctime test
It turns out `du` used to test for the wrong thing, `ctime` is the change timestamp, not creation time. We have to rely on a regex again, as the change timestamp is the current time.
1 parent 8913108 commit 96438f2

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

tests/by-util/test_du.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,8 @@ fn test_du_h_precision() {
594594
#[cfg(feature = "touch")]
595595
#[test]
596596
fn test_du_time() {
597+
use regex::Regex;
598+
597599
let ts = TestScenario::new(util_name!());
598600

599601
// du --time formats the timestamp according to the local timezone. We set the TZ
@@ -634,21 +636,15 @@ fn test_du_time() {
634636
result.stdout_only("0\t2015-05-15 00:00\tdate_test\n");
635637
}
636638

637-
let result = ts
638-
.ucmd()
639-
.env("TZ", "UTC")
640-
.arg("--time=ctime")
641-
.arg("date_test")
642-
.succeeds();
643-
result.stdout_only("0\t2016-06-16 00:00\tdate_test\n");
639+
// Change (and birth) times can't be easily modified, so we just do a regex
640+
let re_change_birth =
641+
Regex::new(r"0\t[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}\tdate_test").unwrap();
642+
let result = ts.ucmd().arg("--time=ctime").arg("date_test").succeeds();
643+
result.stdout_matches(&re_change_birth);
644644

645645
if birth_supported() {
646-
use regex::Regex;
647-
648-
let re_birth =
649-
Regex::new(r"0\t[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}\tdate_test").unwrap();
650646
let result = ts.ucmd().arg("--time=birth").arg("date_test").succeeds();
651-
result.stdout_matches(&re_birth);
647+
result.stdout_matches(&re_change_birth);
652648
}
653649
}
654650

0 commit comments

Comments
 (0)