1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 03:27:44 +00:00

tests: define default env vars for test commands

We now run each command with TZ=UTC and LC_ALL=C to ensure consistent
behavior independent from external timezone and locale settings. These
can still be overridden with other values if necessary.
This commit is contained in:
Terts Diepraam 2023-03-23 18:15:05 +01:00
parent 7853d3707b
commit 4dd88680eb
3 changed files with 29 additions and 21 deletions

View file

@ -18,11 +18,7 @@ fn file_last_modified_time(ucmd: &UCommand, path: &str) -> String {
i.modified()
.map(|x| {
let date_time: OffsetDateTime = x.into();
let offset = OffsetDateTime::now_local().unwrap().offset();
date_time
.to_offset(offset)
.format(&DATE_TIME_FORMAT)
.unwrap()
date_time.format(&DATE_TIME_FORMAT).unwrap()
})
.unwrap_or_default()
})
@ -42,7 +38,7 @@ fn all_minutes(from: OffsetDateTime, to: OffsetDateTime) -> Vec<String> {
}
fn valid_last_modified_template_vars(from: OffsetDateTime) -> Vec<Vec<(String, String)>> {
all_minutes(from, OffsetDateTime::now_local().unwrap())
all_minutes(from, OffsetDateTime::now_utc())
.into_iter()
.map(|time| vec![("{last_modified_time}".to_string(), time)])
.collect()
@ -258,7 +254,7 @@ fn test_with_suppress_error_option() {
fn test_with_stdin() {
let expected_file_path = "stdin.log.expected";
let mut scenario = new_ucmd!();
let start = OffsetDateTime::now_local().unwrap();
let start = OffsetDateTime::now_utc();
scenario
.pipe_in_fixture("stdin.log")
.args(&["--pages=1:2", "-n", "-"])
@ -321,7 +317,7 @@ fn test_with_mpr() {
let expected_test_file_path = "mpr.log.expected";
let expected_test_file_path1 = "mpr1.log.expected";
let expected_test_file_path2 = "mpr2.log.expected";
let start = OffsetDateTime::now_local().unwrap();
let start = OffsetDateTime::now_utc();
new_ucmd!()
.args(&["--pages=1:2", "-m", "-n", test_file_path, test_file_path1])
.succeeds()
@ -330,7 +326,7 @@ fn test_with_mpr() {
&valid_last_modified_template_vars(start),
);
let start = OffsetDateTime::now_local().unwrap();
let start = OffsetDateTime::now_utc();
new_ucmd!()
.args(&["--pages=2:4", "-m", "-n", test_file_path, test_file_path1])
.succeeds()
@ -339,7 +335,7 @@ fn test_with_mpr() {
&valid_last_modified_template_vars(start),
);
let start = OffsetDateTime::now_local().unwrap();
let start = OffsetDateTime::now_utc();
new_ucmd!()
.args(&[
"--pages=1:2",
@ -446,7 +442,7 @@ fn test_with_join_lines_option() {
let test_file_2 = "test.log";
let expected_file_path = "joined.log.expected";
let mut scenario = new_ucmd!();
let start = OffsetDateTime::now_local().unwrap();
let start = OffsetDateTime::now_utc();
scenario
.args(&["+1:2", "-J", "-m", test_file_1, test_file_2])
.run()