Skip to content

Commit

Permalink
consolidate path to date
Browse files Browse the repository at this point in the history
(cherry picked from commit a2ff786)
  • Loading branch information
jtmoon79 committed May 28, 2023
1 parent 1b725f7 commit 8444d22
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions tests/dateutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,22 @@ 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)]
#[cfg(not(target_os = "aix"))]
const DATE_PATH: &'static str = "/usr/bin/date";
#[allow(dead_code)]
#[cfg(target_os = "aix")]
const DATE_PATH: &'static str = "/opt/freeware/bin/date";

#[test]
#[cfg(unix)]
fn try_verify_against_date_command() {
#[cfg(not(target_os = "aix"))]
let date_path = "/usr/bin/date";
#[cfg(target_os = "aix")]
let date_path = "/opt/freeware/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;
}

Expand All @@ -75,7 +78,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::Duration::hours(1);
Expand Down Expand Up @@ -124,15 +127,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::Duration::days(55);
}
}

0 comments on commit 8444d22

Please sign in to comment.