SPDX-License-Identifier: MIT Make the uutils test suite pass on OpenBSD. Tests that rely on the filesystem denying access are skipped when running as root, in case the suite is run with root privileges, matching the GNU coreutils test suite. Never let the suite reset the system clock: the `date --set` examples call clock_settime(2), which needs root and changes the date for every process on the machine, including the rest of this test run and any later port tests. Require an explicit opt-in (UUTILS_TEST_SET_SYSTEM_DATE) for those examples, in case the suite is run as root. Index: tests/by-util/test_date.rs --- tests/by-util/test_date.rs.orig +++ tests/by-util/test_date.rs @@ -511,10 +511,19 @@ new_ucmd!().arg("+%%N").succeeds().stdout_is("%N\n"); } +/// Setting the system clock requires root and would leave every process on the +/// machine -- including the rest of this test run -- with a wrong date. If the +/// suite is run as root, the `date --set` tests that call `clock_settime` are +/// skipped unless the operator explicitly opts in. +#[cfg(all(unix, not(target_vendor = "apple")))] +fn date_set_is_allowed() -> bool { + std::env::var_os("UUTILS_TEST_SET_SYSTEM_DATE").is_some() +} + #[test] #[cfg(all(unix, not(target_vendor = "apple")))] fn test_date_set_valid() { - if geteuid().is_root() { + if geteuid().is_root() && date_set_is_allowed() { new_ucmd!() .arg("--set") .arg("2020-03-12 13:30:00+08:00") @@ -582,7 +591,7 @@ #[test] #[cfg(all(unix, not(target_vendor = "apple")))] fn test_date_set_valid_2() { - if geteuid().is_root() { + if geteuid().is_root() && date_set_is_allowed() { new_ucmd!() .arg("--set") .arg("Sat 20 Mar 2021 14:53:01 AWST") // spell-checker:disable-line @@ -604,6 +613,10 @@ #[test] #[cfg(unix)] fn test_date_for_no_permission_file() { + if uutests::util::is_root() { + // The filesystem permission checks are bypassed when running as root. + return; + } use std::os::unix::fs::PermissionsExt; const FILE: &str = "file-no-perm-1"; @@ -731,7 +744,7 @@ #[test] #[cfg(all(unix, not(target_vendor = "apple")))] fn test_date_set_valid_3() { - if geteuid().is_root() { + if geteuid().is_root() && date_set_is_allowed() { new_ucmd!() .arg("--set") .arg("Sat 20 Mar 2021 14:53:01") // Local timezone @@ -743,7 +756,7 @@ #[test] #[cfg(all(unix, not(target_vendor = "apple")))] fn test_date_set_valid_4() { - if geteuid().is_root() { + if geteuid().is_root() && date_set_is_allowed() { new_ucmd!() .arg("--set") .arg("2020-03-11 21:45:00") // Local timezone