diff --git a/tests/dateutils.rs b/tests/dateutils.rs index aabab29a78..e213d64e2c 100644 --- a/tests/dateutils.rs +++ b/tests/dateutils.rs @@ -48,16 +48,18 @@ fn verify_against_date_command_local(path: &'static str, dt: NaiveDateTime) { } } +/// path to Unix `date` command. Should work on most Linux and Unixes. Not the +/// path for MacOS (/bin/date) which uses a different version of `date` with +/// different arguments (so it won't run which is okay). +/// for testing only +#[allow(dead_code)] +const DATE_PATH: &'static str = "/usr/bin/date"; + #[test] #[cfg(unix)] fn try_verify_against_date_command() { - let date_path = "/usr/bin/date"; - - if !path::Path::new(date_path).exists() { + if !path::Path::new(DATE_PATH).exists() { // date command not found, skipping - // avoid running this on macOS, which has path /bin/date - // as the required CLI arguments are not present in the - // macOS build. return; } @@ -68,7 +70,7 @@ fn try_verify_against_date_command() { || (2020..=2022).contains(&date.year()) || (2073..=2077).contains(&date.year()) { - verify_against_date_command_local(date_path, date); + verify_against_date_command_local(DATE_PATH, date); } date += chrono::TimeDelta::hours(1); @@ -117,15 +119,13 @@ fn verify_against_date_command_format_local(path: &'static str, dt: NaiveDateTim #[test] #[cfg(target_os = "linux")] fn try_verify_against_date_command_format() { - let date_path = "/usr/bin/date"; - - if !path::Path::new(date_path).exists() { + if !path::Path::new(DATE_PATH).exists() { // date command not found, skipping return; } let mut date = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap().and_hms_opt(12, 11, 13).unwrap(); while date.year() < 2008 { - verify_against_date_command_format_local(date_path, date); + verify_against_date_command_format_local(DATE_PATH, date); date += chrono::TimeDelta::days(55); } }