Skip to content

Commit fcb8b20

Browse files
hovinenbcopybara-github
authored andcommitted
Rename the atribute macro google_test to just test.
This changes the canonical way to use the attribute macro from: ``` #[google_test] fn should_work() -> Result<()> {...} ``` to ``` #[googletest::test] fn should_work() -> Result<()> {...} ``` This is more in line with other test libraries such as Tokio et al., and aligns with the expectations of libraries like rstest; see https://github.com/la10736/rstest#inject-test-attribute. Thus the test will not be registered twice even if `#[googletest::test]` appears after `#[rstest]`. In particular, this addresses the remainder of #77. This also adjusts the generated output of `#[googletest::test]` to refer explicitly to `::core::prelude::v1::test`, so that it still compiles when the test directly imports `googletest::test`. Since this is a potentially more serious breaking change, the name `googletest::google_test` is retained as an alias for `googletest::test`. So it is not necessary to port existing downstream uses of the library. PiperOrigin-RevId: 524774178
1 parent cc72baf commit fcb8b20

File tree

5 files changed

+94
-80
lines changed

5 files changed

+94
-80
lines changed

README.md

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,13 @@ failed, but execution continues until the test completes or otherwise aborts.
182182
This is analogous to the `EXPECT_*` family of macros in GoogleTest.
183183

184184
To make a non-fatal assertion, use the macro [`expect_that!`]. The test must
185-
also be marked with [`google_test`] instead of the Rust-standard `#[test]`. It
186-
must return [`Result<()>`].
185+
also be marked with [`googletest::test`] instead of the Rust-standard `#[test]`.
186+
It must return [`Result<()>`].
187187

188188
```rust
189-
use googletest::{
190-
expect_that, google_test, matchers::eq, Result
191-
};
189+
use googletest::{expect_that, matchers::eq, Result};
192190

193-
#[google_test]
191+
#[googletest::test]
194192
fn more_than_one_failure() -> Result<()> {
195193
let value = 2;
196194
expect_that!(value, eq(3)); // Just marks the test as having failed.
@@ -201,12 +199,12 @@ fn more_than_one_failure() -> Result<()> {
201199

202200
### Interoperability
203201

204-
You can use the `#[google_test]` macro together with many other libraries such
205-
as [rstest](https://crates.io/crates/rstest). Just apply both attribute macros
206-
to the test:
202+
You can use the `#[googletest::test]` macro together with many other libraries
203+
such as [rstest](https://crates.io/crates/rstest). Just apply both attribute
204+
macros to the test:
207205

208206
```rust
209-
#[google_test]
207+
#[googletest::test]
210208
#[rstest]
211209
#[case(1)]
212210
#[case(2)]
@@ -216,16 +214,16 @@ fn rstest_works_with_google_test(#[case] value: u32) -> Result<()> {
216214
}
217215
```
218216

219-
Make sure to put `#[google_test]` *before* `#[rstest]`. Otherwise the annotated
220-
test will run twice, since both macros will attempt to register a test with the
221-
Rust test harness.
217+
Make sure to put `#[googletest::test]` *before* `#[rstest]`. Otherwise the
218+
annotated test will run twice, since both macros will attempt to register a test
219+
with the Rust test harness.
222220

223221
The macro also works together with
224222
[async tests with Tokio](https://docs.rs/tokio/latest/tokio/attr.test.html) in
225223
the same way:
226224

227225
```rust
228-
#[google_test]
226+
#[googletest::test]
229227
#[tokio::test]
230228
async fn should_work_with_tokio() -> Result<()> {
231229
verify_that!(3, gt(0))
@@ -289,7 +287,7 @@ to this project.
289287
[`expect_pred!`]: https://docs.rs/googletest/*/googletest/macro.expect_pred.html
290288
[`expect_that!`]: https://docs.rs/googletest/*/googletest/macro.expect_that.html
291289
[`fail!`]: https://docs.rs/googletest/*/googletest/macro.fail.html
292-
[`google_test`]: https://docs.rs/googletest/*/googletest/attr.google_test.html
290+
[`googletest::test`]: https://docs.rs/googletest/*/googletest/attr.test.html
293291
[`matches_pattern!`]: https://docs.rs/googletest/*/googletest/macro.matches_pattern.html
294292
[`verify_pred!`]: https://docs.rs/googletest/*/googletest/macro.verify_pred.html
295293
[`verify_that!`]: https://docs.rs/googletest/*/googletest/macro.verify_that.html

googletest/integration_tests/google_test_with_rstest.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,49 +14,49 @@
1414

1515
fn main() {}
1616

17-
// Mixing rstest and google_test should not result in any compiler warnings. The
17+
// Mixing rstest and googletest::test should not result in any compiler warnings. The
1818
// fact that this successfully compiles is part of the test.
1919
#[deny(warnings)]
2020
#[cfg(test)]
2121
mod tests {
2222
#[cfg(not(google3))]
2323
use googletest::matchers;
24-
use googletest::{google_test, verify_that, Result};
24+
use googletest::{verify_that, Result};
2525
use matchers::eq;
2626
use rstest::rstest;
2727

2828
#[rstest]
29-
#[google_test]
29+
#[googletest::test]
3030
fn test_should_work_with_rstest_first() -> Result<()> {
3131
verify_that!(1, eq(1))
3232
}
3333

3434
#[rstest::rstest]
35-
#[google_test]
35+
#[googletest::test]
3636
fn test_should_work_with_qualified_rstest_first() -> Result<()> {
3737
verify_that!(1, eq(1))
3838
}
3939

40-
#[google_test]
40+
#[googletest::test]
4141
#[rstest]
4242
fn test_should_work_with_rstest_second() -> Result<()> {
4343
verify_that!(1, eq(1))
4444
}
4545

46-
#[google_test]
46+
#[googletest::test]
4747
#[rstest::rstest]
4848
fn test_should_work_with_qualified_rstest_second() -> Result<()> {
4949
verify_that!(1, eq(1))
5050
}
5151

5252
#[rstest]
5353
#[case(1)]
54-
#[google_test]
54+
#[googletest::test]
5555
fn paramterised_test_should_work_with_rstest_first(#[case] value: u32) -> Result<()> {
5656
verify_that!(value, eq(value))
5757
}
5858

59-
#[google_test]
59+
#[googletest::test]
6060
#[rstest]
6161
#[case(1)]
6262
fn paramterised_test_should_work_with_rstest_second(#[case] value: u32) -> Result<()> {
@@ -67,13 +67,13 @@ mod tests {
6767
pub use rstest::rstest as test;
6868
}
6969

70-
#[google_test]
70+
#[googletest::test]
7171
#[submodule::test]
7272
fn test_should_work_with_qualified_test_annotation() -> Result<()> {
7373
verify_that!(1, eq(1))
7474
}
7575

76-
#[google_test]
76+
#[googletest::test]
7777
#[test]
7878
fn test_should_work_with_second_test_annotation() -> Result<()> {
7979
verify_that!(1, eq(1))

0 commit comments

Comments
 (0)