summaryrefslogtreecommitdiffstats
path: root/vendor/chrono/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/chrono/tests
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/chrono/tests')
-rw-r--r--vendor/chrono/tests/dateutils.rs68
1 files changed, 55 insertions, 13 deletions
diff --git a/vendor/chrono/tests/dateutils.rs b/vendor/chrono/tests/dateutils.rs
index dec6bfe11..d671ecca8 100644
--- a/vendor/chrono/tests/dateutils.rs
+++ b/vendor/chrono/tests/dateutils.rs
@@ -1,7 +1,11 @@
+#[cfg(unix)]
use chrono::offset::TimeZone;
+#[cfg(unix)]
use chrono::Local;
+#[cfg(unix)]
use chrono::{Datelike, NaiveDate, NaiveDateTime, Timelike};
+#[cfg(unix)]
use std::{path, process};
#[cfg(unix)]
@@ -48,31 +52,68 @@ 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";
+
+#[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() {
- let date_path = "/usr/bin/date";
-
- 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.
+ if !path::Path::new(DATE_PATH).exists() {
+ 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();
+ eprintln!(
+ "Run command {:?} for every hour from {} to 2077, skipping some years...",
+ DATE_PATH,
+ date.year()
+ );
+ let mut count: u64 = 0;
+ let mut year_at = date.year();
while date.year() < 2078 {
if (1975..=1977).contains(&date.year())
|| (2020..=2022).contains(&date.year())
|| (2073..=2077).contains(&date.year())
{
- verify_against_date_command_local(date_path, date);
+ if date.year() != year_at {
+ eprintln!("at year {}...", date.year());
+ year_at = date.year();
+ }
+ verify_against_date_command_local(DATE_PATH, date);
+ count += 1;
}
date += chrono::Duration::hours(1);
}
+ eprintln!("Command {:?} was run {} times", DATE_PATH, count);
}
#[cfg(target_os = "linux")]
@@ -91,6 +132,7 @@ fn verify_against_date_command_format_local(path: &'static str, dt: NaiveDateTim
// Z%Z - too many ways to represent it, will most likely fail
let output = process::Command::new(path)
+ .env("LANG", "c")
.arg("-d")
.arg(format!(
"{}-{:02}-{:02} {:02}:{:02}:{:02}",
@@ -117,15 +159,15 @@ 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() {
- // date command not found, skipping
+ if !path::Path::new(DATE_PATH).exists() {
+ 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);
+ verify_against_date_command_format_local(DATE_PATH, date);
date += chrono::Duration::days(55);
}
}