Skip to content

[test] Check content of error message #2582

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tests/rendered_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,8 @@ fn failure_on_missing_theme_directory() {
let md = MDBook::load(temp.path()).unwrap();
let got = md.build();
assert!(got.is_err());
let error_message = got.err().unwrap().to_string();
assert_eq!(error_message, "Rendering failed");
Comment on lines 734 to +736
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do find it a little offsetting that you check the string literal within the message, meaning that if someone happens to change a single char there in the future the test would fail.
Also, and that one is more of a matter of personal taste, you might get a more informative test (and a slightly cleaner one) if you wrote it like:

match got{
    Err(e) => { assert_eq1(e.to_string(), "Rendering failed"); },
    Ok(content) => { panic!("Expected an error but got an Ok with content: {:?}", content); }
}

}

#[cfg(feature = "search")]
Expand Down