From b1729f3a9b17e242509329d202d9923926bc814d Mon Sep 17 00:00:00 2001 From: jtmoon79 <815261+jtmoon79@users.noreply.github.com> Date: Sat, 27 May 2023 21:48:25 -0700 Subject: [PATCH] try_verify_against_date sanity check date command Sanity check `date` command used in tests `try_verify_against_date_command` and `try_verify_against_date_command_format`. Make sure it's the kind of `data` command expected (accepts `--version`). Also, it's just good to print this for debugging purposes. --- tests/dateutils.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/dateutils.rs b/tests/dateutils.rs index 3c473e7045..f8f89e3528 100644 --- a/tests/dateutils.rs +++ b/tests/dateutils.rs @@ -63,6 +63,23 @@ const DATE_PATH: &'static str = "/usr/bin/date"; #[cfg(target_os = "aix")] const DATE_PATH: &'static str = "/opt/freeware/bin/date"; +#[cfg(test)] +/// test helper to sanity check the date command behaves as expected +/// asserts the command succeeded +fn assert_run_date_version() { + // note environment variable `LANG` + match std::env::var_os("LANG") { + Some(lang) => eprintln!("LANG: {:?}", lang), + None => eprintln!("LANG not set"), + } + let out = process::Command::new(DATE_PATH).arg("--version").output().unwrap(); + let stdout = String::from_utf8(out.stdout).unwrap(); + let stderr = String::from_utf8(out.stderr).unwrap(); + // note the `date` binary version + eprintln!("command: {:?} --version\nstdout: {:?}\nstderr: {:?}", DATE_PATH, stdout, stderr); + assert!(out.status.success(), "command failed: {:?} --version", DATE_PATH); +} + #[test] #[cfg(unix)] fn try_verify_against_date_command() { @@ -71,6 +88,7 @@ fn try_verify_against_date_command() { eprintln!("date command {:?} not found, skipping", DATE_PATH); return; } + assert_run_date_version(); let mut date = NaiveDate::from_ymd_opt(1975, 1, 1).unwrap().and_hms_opt(0, 0, 0).unwrap(); @@ -133,6 +151,8 @@ fn try_verify_against_date_command_format() { eprintln!("date command {:?} not found, skipping", DATE_PATH); return; } + assert_run_date_version(); + 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);