Skip to content

Commit

Permalink
consolidate path to date
Browse files Browse the repository at this point in the history
  • Loading branch information
jtmoon79 committed Mar 28, 2023
1 parent b1ef0f4 commit 0ed0140
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions tests/dateutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 0ed0140

Please sign in to comment.