command-line-rust icon indicating copy to clipboard operation
command-line-rust copied to clipboard

cargo test fails for hello1 and hello2 cases in 02_echor

Open Rkobuki opened this issue 1 year ago • 3 comments

Issue Description:

When running cargo test for the hello1 and hello2 cases in the 02_echor code, the tests fail with the following error:

---- hello2 stdout ----
thread 'hello2' panicked at 'Unexpected stdout, failed diff original var
├── original: Hello there
├── diff:
└── var as str: Hello there

thread 'hello1' panicked at 'Unexpected stdout, failed diff original var
├── original: Hello there
├── diff:
└── var as str: Hello there

Rkobuki avatar Jan 30 '24 13:01 Rkobuki

I've been improving the test output by using "pretty_assertions::assert_eq". Switch to one of the "clap_v4*" branches and use those tests. Note you will need to update Cargo.toml to use this crate.

kyclark avatar Feb 06 '24 17:02 kyclark

If youre using a windows device and it happend while following the chapter (of an older version of the book) you could edit print!("{}{}", text.join(" "), if omit_newline { "" } else { "\n" }); and change it to print!("{}{}", text.join(" "), if omit_newline { "" } else { "\r\n" }); within the main function. That sorted it out for me while following the chapter.

haraldo1337 avatar May 17 '24 06:05 haraldo1337

In case someone else runs into this issue, I have the version of the book that follows clap v2 and using a mac, I was running into the same issue but realized my mistake. I traced it back to the code in src/main.rs. Instead of print!(...), I mistyped println!(...), causing an additional \n character to be added to the standard output.

cyberbeast avatar Aug 02 '24 02:08 cyberbeast