kyclark / command-line-rust

Code for Command-Line Rust (O'Reilly, 2024, ISBN 9781098109417)
https://learning.oreilly.com/library/view/command-line-rust/9781098109424/
MIT License
1.55k stars 252 forks source link

[catr] tests unreliable? #11

Closed florianhumblot closed 1 year ago

florianhumblot commented 1 year ago

Hey there, I'm following along the examples in the book and I can't seem to get the tests for catr to pass... image

When I use the debugger to get some idea it seems that the test doesn't read the expected outputs correctly: image

But if I do a hex-dump of the file contents it seems to be just fine? image I tried re-generating the outputs with the script in this repository but that doens't seem to help. Anyone have an idea?

The code is from the tests itself, unmodified:

fn run(args: &[&str], expected_file: &str) -> TestResult {
    let expected = fs::read_to_string(expected_file)?;
    Command::cargo_bin(PRG)?
        .args(args)
        .assert()
        .success()
        .stdout(expected);
    Ok(())
}
richo225 commented 1 year ago

Hey @florianhumblot , I had exactly the same issue and the test output is super confusing. What fixed it for me was adding final line breaks to all the input files in my editor and regenerating the expected directory:

Screenshot 2023-05-15 at 02 01 12 Screenshot 2023-05-15 at 02 01 00

florianhumblot commented 1 year ago

@richo225 thanks for the hint! I already added line breaks to the end of file, but changing the line endings to LF rather than CRLF seems to have fixed it. Kind of a weird issue to have lol