Skip to content

Commit 50f8d0b

Browse files
sylvestrecakebaker
authored andcommitted
touch: add regression test for pre-epoch date on 32-bit
1 parent 717140a commit 50f8d0b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/by-util/test_touch.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,25 @@ fn test_touch_set_date7() {
622622
assert_eq!(mtime, expected);
623623
}
624624

625+
/// Regression test for https://github.com/uutils/coreutils/issues/11804
626+
///
627+
/// Setting a pre-epoch date like `0000-01-01` used to panic on 32-bit targets
628+
/// because the i64 Unix timestamp (~-62 billion) overflowed the i32 `tv_sec`
629+
/// expected by the old nix-based implementation. After switching to rustix
630+
/// (which uses i64 `tv_sec` natively), this should succeed on all targets.
631+
#[test]
632+
#[cfg(target_os = "linux")]
633+
fn test_touch_set_date_year_zero() {
634+
let (at, mut ucmd) = at_and_ucmd!();
635+
let file = "test_touch_year_zero";
636+
637+
ucmd.args(&["-d", "0000-01-01", file])
638+
.succeeds()
639+
.no_stderr();
640+
641+
assert!(at.file_exists(file));
642+
}
643+
625644
/// Test for setting the date by a relative time unit.
626645
#[test]
627646
fn test_touch_set_date_relative_smoke() {

0 commit comments

Comments
 (0)