coreutils
coreutils copied to clipboard
Tests failing on a clean repository clone
Replicate -
- Run
git clone https://github.com/uutils/coreutils && cd coreutils && cargo test - Read message returned by
cargo test
Host specs -
- Windows 11 64-bit Latest (as of 3rd August 2023)
- AMD Ryzen 5 3600x
- 16GB 3800MHz RAM
- Used PowerShell in VS Code
What is the message from cargo test? (I don't have access to a windows machine at the moment)
Note that stderr only reports compiles, module runs and test rerun message ; hence not included in the text file.
Right, so touch is consistently 10800 seconds (3 hours) off from the expected value? Are you in a timezone that's a 3 hour offset from UTC?
I'm in India, which has the IST time zone. It is UTC + 5:30
Here is a screenshot from windows settings -
Oh very interesting, I guess it might not be timezone-related then or maybe it is, but in some more complicated way 🤔
The problem may be with chrono getting the incorrect time for whatever reason. Would you like me to run some code that would allow us to rule chrono out?
That would be great! I was thinkin the culprit could be the conversion from chrono to filetime. But yeah, let's rule chrono out first.
I'm not familiar with the crate but I ran this code -
use chrono::prelude::*;
fn main() {
let local = Local::now();
println!("{:?}", local);
}
Using chrono v0.4.26.
Output -
This seems to be correct
A little reading later, I think I understand how to test if chrono to filetime is an issue.
Here is the code -
use chrono::prelude::*;
use filetime::FileTime;
use std::time::{SystemTime, UNIX_EPOCH};
fn main() {
let ftime = datetime_to_filetime(&Local::now()).unix_seconds();
let stime = SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs();
println!("{}\t{}", ftime, stime);
}
fn datetime_to_filetime<T: TimeZone>(dt: &DateTime<T>) -> FileTime {
FileTime::from_unix_time(dt.timestamp(), dt.timestamp_subsec_nanos())
}
Prints the following -
1691056504 1691056504
Note that it is 15:25 3rd August 2023
So that's correct? Just as a sanity check, could you run one of the failing test cases manually in the terminal and check whether the time is correct? It might be an issue with the tests, instead of an issue with touch.
Executing command -
coreutils pr --pages=3:5 --column=3 -a -n ".\tests\fixtures\pr\column.log" > pr.txt
Test - test_pr::test_with_column_across_option
Times seem to be wrong.
pr.txt
Running the command again a few minutes later displayed the time as following (in the output) Aug 03 13:18 2023
Whereas it should be Aug 03 15:44 2023
Strange, we don't do much in pr, just formatting the last modified time. Could you maybe try a small program that just gets a system time, converts it to DateTime<Local> and formats it (like pr does)?
Maybe the conversion from system time to chrono is wrong?
Yes,
use chrono::prelude::*;
use filetime::FileTime;
use std::time::SystemTime;
const DATE_TIME_FORMAT: &str = "%b %d %H:%M %Y";
fn main() {
let time: DateTime<Local> = SystemTime::now().into();
println!("{}", time.format(DATE_TIME_FORMAT));
}
outputs
Aug 03 18:12 2023
Which is correct
Any idea why this was failing? I'd love to test this again tomorrow and close this issue.
I'm still not sure to be honest