Skip to content

Commit 16bf4f5

Browse files
author
Thomas Etter
committed
Simplify if else as suggested in PR feedback
1 parent 48a86e0 commit 16bf4f5

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

src/libtest/test_result.rs

+16-20
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,25 @@ pub fn calc_result<'a>(
4242
.map(|e| &**e)
4343
.or_else(|| err.downcast_ref::<&'static str>().map(|e| *e));
4444

45-
if maybe_panic_str
46-
.map(|e| e.contains(msg))
47-
.unwrap_or(false)
48-
{
45+
if maybe_panic_str.map(|e| e.contains(msg)).unwrap_or(false) {
4946
TestResult::TrOk
50-
} else {
51-
if desc.allow_fail {
52-
TestResult::TrAllowedFail
53-
} else {
54-
if let Some(panic_str) = maybe_panic_str{
55-
TestResult::TrFailedMsg(
56-
format!(r#"panic did not contain expected string
47+
} else if desc.allow_fail {
48+
TestResult::TrAllowedFail
49+
} else if let Some(panic_str) = maybe_panic_str {
50+
TestResult::TrFailedMsg(format!(
51+
r#"panic did not contain expected string
5752
panic message: `{:?}`,
58-
expected substring: `{:?}`"#, panic_str, &*msg)
59-
)
60-
} else {
61-
TestResult::TrFailedMsg(
62-
format!(r#"expected panic with string value,
53+
expected substring: `{:?}`"#,
54+
panic_str, msg
55+
))
56+
} else {
57+
TestResult::TrFailedMsg(format!(
58+
r#"expected panic with string value,
6359
found non-string value: `{:?}`
64-
expected substring: `{:?}`"#, (**err).type_id(), &*msg)
65-
)
66-
}
67-
}
60+
expected substring: `{:?}`"#,
61+
(**err).type_id(),
62+
msg
63+
))
6864
}
6965
}
7066
(&ShouldPanic::Yes, Ok(())) => {

0 commit comments

Comments
 (0)