Skip to content

Make result_of explain the inner matcher failure #539

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
36 changes: 20 additions & 16 deletions googletest/src/matchers/result_of_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ pub mod internal {

fn explain_match(&self, actual: I) -> Description {
let actual_result = (self.callable)(actual);
Description::new()
.text(format!("which, results into {actual_result:?}",))
.nested(self.describe(self.matches(actual)))
Description::new().text(format!("which, results into {actual_result:?}")).nested(
Description::new()
.text(format!("by applying {},", self.callable_description))
.nested(self.inner_matcher.explain_match(actual_result)),
)
}
}

Expand Down Expand Up @@ -154,9 +156,11 @@ pub mod internal {

fn explain_match(&self, actual: I) -> Description {
let actual_result = (self.callable)(actual);
Description::new()
.text(format!("which, results into {actual_result:?}",))
.nested(self.describe(self.matches(actual)))
Description::new().text(format!("which, results into {actual_result:?}")).nested(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you add a test that demonstrates the new behavior?

Description::new()
.text(format!("by applying {},", self.callable_description))
.nested(self.inner_matcher.explain_match(&actual_result)),
)
}
}
}
Expand Down Expand Up @@ -192,7 +196,7 @@ mod tests {
Actual: 0,
which, results into -1
by applying |value| value - 1,
isn't equal to 2
which isn't equal to 2
"
))))
)
Expand All @@ -211,7 +215,7 @@ mod tests {
Actual: 0,
which, results into -1
by applying |value| { value - 1 },
isn't equal to 2
which isn't equal to 2
"
))))
)
Expand Down Expand Up @@ -240,7 +244,7 @@ mod tests {
Actual: 0,
which, results into -2
by applying |value| { let dec = value - 1; let inc = dec + 1; inc - 2 },
isn't equal to 2
which isn't equal to 2
"
))))
)
Expand All @@ -262,7 +266,7 @@ mod tests {
Actual: 0,
which, results into -1
by applying dec_by_one,
isn't equal to 2
which isn't equal to 2
"
))))
)
Expand Down Expand Up @@ -299,7 +303,7 @@ mod tests {
Actual: "world",
which, results into "WORLD"
by applying |s: &str| s.to_uppercase(),
isn't equal to "HELLO""#
which isn't equal to "HELLO""#
))))
)
}
Expand All @@ -318,7 +322,7 @@ mod tests {
Actual: "world",
which, results into "WORLD"
by applying |s: &str| { s.to_uppercase() },
isn't equal to "HELLO"
which isn't equal to "HELLO"
"#
))))
)
Expand All @@ -340,7 +344,7 @@ mod tests {
Actual: "world",
which, results into "WORLD"
by applying to_upper_case,
isn't equal to "HELLO"
which isn't equal to "HELLO"
"#
))))
)
Expand All @@ -360,7 +364,7 @@ mod tests {
Actual: "world",
which, results into "WORLD"
by applying to_upper_case,
isn't equal to "HELLO"
which isn't equal to "HELLO"
"#
))))
)
Expand All @@ -379,7 +383,7 @@ mod tests {
Actual: "world",
which, results into "WORLD"
by applying str::to_uppercase,
isn't equal to "HELLO"
which isn't equal to "HELLO"
"#
))))
)
Expand All @@ -401,7 +405,7 @@ mod tests {
Actual: "world",
which, results into "WORLD"
by applying upper_case(),
isn't equal to "HELLO"
which isn't equal to "HELLO"
"#
))))
)
Expand Down