Skip to content

Commit 3c1bebf

Browse files
hovinenbcopybara-github
authored andcommitted
Do not emit a #[test] attribute in the google_test macro if any attribute ending in test is detected.
This should eliminate problems with compatibility with most existing test libraries. It follows the same logic as used in the rstest crate; see https://github.com/la10736/rstest#inject-test-attribute. PiperOrigin-RevId: 524239595
1 parent f4ea561 commit 3c1bebf

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

googletest/integration_tests/google_test_with_rstest.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,20 @@ mod tests {
6262
fn paramterised_test_should_work_with_rstest_second(#[case] value: u32) -> Result<()> {
6363
verify_that!(value, eq(value))
6464
}
65+
66+
mod submodule {
67+
pub use rstest::rstest as test;
68+
}
69+
70+
#[google_test]
71+
#[submodule::test]
72+
fn test_should_work_with_qualified_test_annotation() -> Result<()> {
73+
verify_that!(1, eq(1))
74+
}
75+
76+
#[google_test]
77+
#[test]
78+
fn test_should_work_with_second_test_annotation() -> Result<()> {
79+
verify_that!(1, eq(1))
80+
}
6581
}

googletest/integration_tests/integration_tests.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,18 @@ mod tests {
466466
output,
467467
contains_substring("tests::test_should_work_with_rstest_second").times(eq(1))
468468
);
469-
verify_that!(
469+
expect_that!(
470470
output,
471471
contains_substring("tests::test_should_work_with_qualified_rstest_second").times(eq(1))
472+
);
473+
expect_that!(
474+
output,
475+
contains_substring("tests::test_should_work_with_qualified_test_annotation")
476+
.times(eq(1))
477+
);
478+
verify_that!(
479+
output,
480+
contains_substring("tests::test_should_work_with_second_test_annotation").times(eq(1))
472481
)
473482
}
474483

googletest_macro/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ fn is_test_attribute(attr: &Attribute) -> bool {
9292
let Some(last_segment) = attr.path().segments.last() else {
9393
return false;
9494
};
95-
first_segment.ident == "rstest"
96-
&& last_segment.ident == "rstest"
97-
&& attr.path().segments.len() <= 2
95+
last_segment.ident == "test"
96+
|| (first_segment.ident == "rstest"
97+
&& last_segment.ident == "rstest"
98+
&& attr.path().segments.len() <= 2)
9899
}

0 commit comments

Comments
 (0)