Skip to content

Commit

Permalink
Merge pull request #341 from google:support-trailing-comma-in-top-lev…
Browse files Browse the repository at this point in the history
…el-macros

PiperOrigin-RevId: 591831810
  • Loading branch information
copybara-github committed Dec 18, 2023
2 parents 1fb0652 + 0a13b0a commit 41127ca
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
6 changes: 3 additions & 3 deletions googletest/src/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ macro_rules! verify_that {
$crate::internal::source_location::SourceLocation::new(file!(), line!(), column!()),
)
};
($actual:expr, $expected:expr) => {
($actual:expr, $expected:expr $(,)?) => {
$crate::assertions::internal::check_matcher(
&$actual,
$expected,
Expand Down Expand Up @@ -351,7 +351,7 @@ macro_rules! fail {
/// equivalent to `ASSERT_THAT`, use [`verify_that!`] with the `?` operator.
#[macro_export]
macro_rules! assert_that {
($actual:expr, $expected:expr) => {
($actual:expr, $expected:expr $(,)?) => {
match $crate::verify_that!($actual, $expected) {
Ok(_) => {}
Err(e) => {
Expand Down Expand Up @@ -442,7 +442,7 @@ macro_rules! assert_pred {
/// ```
#[macro_export]
macro_rules! expect_that {
($actual:expr, $expected:expr) => {{
($actual:expr, $expected:expr $(,)?) => {{
use $crate::GoogleTestSupport;
$crate::verify_that!($actual, $expected).and_log_failure();
}};
Expand Down
33 changes: 31 additions & 2 deletions integration_tests/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ mod tests {
verify_that!(value, eq(2))
}

#[test]
fn verify_that_supports_trailing_comma() -> Result<()> {
let value = 2;
verify_that!(value, eq(2),)
}

#[test]
fn should_pass_with_omitted_elements_are() -> Result<()> {
verify_that!(vec![1, 2], [eq(1), eq(2)])
Expand All @@ -48,10 +54,21 @@ mod tests {
}

#[test]
fn should_pass_with_assert_that() -> Result<()> {
fn should_pass_with_assert_that() {
let value = 2;
assert_that!(value, eq(2));
Ok(())
}

#[test]
fn assert_that_supports_trailing_comma() {
let value = 2;
assert_that!(value, eq(2),);
}

#[test]
fn assert_that_with_custom_failure_message_supports_trailing_comma() {
let value = 2;
assert_that!(value, eq(2), "A custom error message",);
}

#[googletest::test]
Expand All @@ -67,6 +84,18 @@ mod tests {
expect_that!(value, eq(2));
}

#[googletest::test]
fn expect_that_supports_trailing_comma() {
let value = 2;
expect_that!(value, eq(2),);
}

#[googletest::test]
fn expect_that_with_custom_failure_message_supports_trailing_comma() {
let value = 2;
expect_that!(value, eq(2), "A custom error message",);
}

#[test]
fn should_fail_on_assertion_failure() -> Result<()> {
let status = run_external_process("simple_assertion_failure").status()?;
Expand Down

0 comments on commit 41127ca

Please sign in to comment.