Skip to content

Commit b407f3b

Browse files
gribozavrcopybara-github
authored andcommitted
Replace usages of #[googletest::test] with #[gtest]
There are only a few tests left that use `#[googletest::test]`. They verify compatibility of Googletest Rust with `#[rstest]`, which requires the third-party testing attribute to be called literally `test`. PiperOrigin-RevId: 661241123
1 parent 5ace091 commit b407f3b

File tree

52 files changed

+210
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+210
-210
lines changed

README.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ To make an assertion using a matcher, GoogleTest offers three macros:
5454
* [`assert_that!`] panics if the assertion fails, aborting the test.
5555
* [`expect_that!`] logs an assertion failure, marking the test as having
5656
failed, but allows the test to continue running (called a _non-fatal
57-
assertion_). It requires the use of the [`googletest::test`] attribute macro
57+
assertion_). It requires the use of the [`gtest`] attribute macro
5858
on the test itself.
5959
* [`verify_that!`] has no side effects and evaluates to a [`Result<()>`] whose
6060
`Err` variant describes the assertion failure, if there is one. In
@@ -74,7 +74,7 @@ fn fails_and_panics() {
7474
assert_that!(value, eq(4));
7575
}
7676

77-
#[googletest::test]
77+
#[gtest]
7878
fn two_logged_failures() {
7979
let value = 2;
8080
expect_that!(value, eq(4)); // Test now failed, but continues executing.
@@ -107,7 +107,7 @@ Matchers are composable:
107107
```rust
108108
use googletest::prelude::*;
109109

110-
#[googletest::test]
110+
#[gtest]
111111
fn contains_at_least_one_item_at_least_3() {
112112
let value = vec![1, 2, 3];
113113
expect_that!(value, contains(ge(3)));
@@ -119,7 +119,7 @@ They can also be logically combined:
119119
```rust
120120
use googletest::prelude::*;
121121

122-
#[googletest::test]
122+
#[gtest]
123123
fn strictly_between_9_and_11() {
124124
let value = 10;
125125
expect_that!(value, gt(9).and(not(ge(11))));
@@ -194,7 +194,7 @@ pub fn eq_my_way<T: PartialEq + Debug>(expected: T) -> impl Matcher<T> {
194194
The new matcher can then be used in the assertion macros:
195195

196196
```rust
197-
#[googletest::test]
197+
#[gtest]
198198
fn should_be_equal_by_my_definition() {
199199
expect_that!(10, eq_my_way(10));
200200
}
@@ -209,12 +209,12 @@ failed, but execution continues until the test completes or otherwise aborts.
209209
This is analogous to the `EXPECT_*` family of macros in GoogleTest.
210210

211211
To make a non-fatal assertion, use the macro [`expect_that!`]. The test must
212-
also be marked with [`googletest::test`] instead of the Rust-standard `#[test]`.
212+
also be marked with [`gtest`] instead of the Rust-standard `#[test]`.
213213

214214
```rust
215215
use googletest::prelude::*;
216216

217-
#[googletest::test]
217+
#[gtest]
218218
fn three_non_fatal_assertions() {
219219
let value = 2;
220220
expect_that!(value, eq(2)); // Passes; test still considered passing.
@@ -229,7 +229,7 @@ function must also return [`Result<()>`]:
229229
```rust
230230
use googletest::prelude::*;
231231

232-
#[googletest::test]
232+
#[gtest]
233233
fn failing_non_fatal_assertion() -> Result<()> {
234234
let value = 2;
235235
expect_that!(value, eq(3)); // Just marks the test as having failed.
@@ -242,7 +242,7 @@ fn failing_non_fatal_assertion() -> Result<()> {
242242
```rust
243243
use googletest::prelude::*;
244244

245-
#[googletest::test]
245+
#[gtest]
246246
fn failing_fatal_assertion_after_non_fatal_assertion() -> Result<()> {
247247
let value = 2;
248248
verify_that!(value, eq(3))?; // Fails and aborts the test.
@@ -253,12 +253,12 @@ fn failing_fatal_assertion_after_non_fatal_assertion() -> Result<()> {
253253

254254
### Interoperability
255255

256-
You can use the `#[googletest::test]` macro together with many other libraries
256+
You can use the `#[gtest]` macro together with many other libraries
257257
such as [rstest](https://crates.io/crates/rstest). Just apply both attribute
258258
macros to the test:
259259

260260
```rust
261-
#[googletest::test]
261+
#[gtest]
262262
#[rstest]
263263
#[case(1)]
264264
#[case(2)]
@@ -268,16 +268,16 @@ fn rstest_works_with_google_test(#[case] value: u32) -> Result<()> {
268268
}
269269
```
270270

271-
Make sure to put `#[googletest::test]` *before* `#[rstest]`. Otherwise the
271+
Make sure to put `#[gtest]` *before* `#[rstest]`. Otherwise the
272272
annotated test will run twice, since both macros will attempt to register a test
273273
with the Rust test harness.
274274

275275
The macro also works together with
276-
[async tests with Tokio](https://docs.rs/tokio/latest/tokio/attr.test.html) in
276+
[async tests with Tokio](https://docs.rs/tokio/latest/tokio/attr.gtest.html) in
277277
the same way:
278278

279279
```rust
280-
#[googletest::test]
280+
#[gtest]
281281
#[tokio::test]
282282
async fn should_work_with_tokio() -> Result<()> {
283283
verify_that!(3, gt(0))
@@ -355,7 +355,7 @@ to this project.
355355
[`expect_pred!`]: https://docs.rs/googletest/*/googletest/macro.expect_pred.html
356356
[`expect_that!`]: https://docs.rs/googletest/*/googletest/macro.expect_that.html
357357
[`fail!`]: https://docs.rs/googletest/*/googletest/macro.fail.html
358-
[`googletest::test`]: https://docs.rs/googletest/*/googletest/attr.test.html
358+
[`gtest`]: https://docs.rs/googletest/*/googletest/attr.gtest.html
359359
[`matches_pattern!`]: https://docs.rs/googletest/*/googletest/macro.matches_pattern.html
360360
[`verify_pred!`]: https://docs.rs/googletest/*/googletest/macro.verify_pred.html
361361
[`verify_that!`]: https://docs.rs/googletest/*/googletest/macro.verify_that.html

googletest/crate_docs.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ To make an assertion using a matcher, GoogleTest offers three macros:
2626
* [`assert_that!`] panics if the assertion fails, aborting the test.
2727
* [`expect_that!`] logs an assertion failure, marking the test as having
2828
failed, but allows the test to continue running (called a _non-fatal
29-
assertion_). It requires the use of the [`googletest::test`][crate::test]
29+
assertion_). It requires the use of the [`gtest`]
3030
attribute macro on the test itself.
3131
* [`verify_that!`] has no side effects and evaluates to a [`Result`] whose
3232
`Err` variant describes the assertion failure, if there is one. In
@@ -49,7 +49,7 @@ fn fails_and_panics() {
4949
}
5050
5151
# /* The attribute macro would prevent the function from being compiled in a doctest.
52-
#[googletest::test]
52+
#[gtest]
5353
# */
5454
fn two_logged_failures() {
5555
let value = 2;
@@ -82,7 +82,7 @@ Matchers are composable:
8282
use googletest::prelude::*;
8383
8484
# /* The attribute macro would prevent the function from being compiled in a doctest.
85-
#[googletest::test]
85+
#[gtest]
8686
# */
8787
fn contains_at_least_one_item_at_least_3() {
8888
# googletest::internal::test_outcome::TestOutcome::init_current_test_outcome();
@@ -100,7 +100,7 @@ They can also be logically combined, with methods from [`MatcherBase`]:
100100
use googletest::prelude::*;
101101
102102
# /* The attribute macro would prevent the function from being compiled in a doctest.
103-
#[googletest::test]
103+
#[gtest]
104104
# */
105105
fn strictly_between_9_and_11() {
106106
# googletest::internal::test_outcome::TestOutcome::init_current_test_outcome();
@@ -319,7 +319,7 @@ impl<T: PartialEq + Debug + Copy> Matcher<T> for MyEqMatcher<T> {
319319
# MyEqMatcher { expected }
320320
# }
321321
# /* The attribute macro would prevent the function from being compiled in a doctest.
322-
#[googletest::test]
322+
#[gtest]
323323
# */
324324
fn should_be_equal_by_my_definition() {
325325
# googletest::internal::test_outcome::TestOutcome::init_current_test_outcome();
@@ -338,13 +338,12 @@ having failed, but execution continues until the test completes or otherwise
338338
aborts.
339339

340340
To make a non-fatal assertion, use the macro [`expect_that!`]. The test must
341-
also be marked with [`googletest::test`][crate::test] instead of the
342-
Rust-standard `#[test]`.
341+
also be marked with [`gtest`] instead of the Rust-standard `#[test]`.
343342

344343
```no_run
345344
use googletest::prelude::*;
346345
347-
#[googletest::test]
346+
#[gtest]
348347
fn three_non_fatal_assertions() {
349348
let value = 2;
350349
expect_that!(value, eq(2)); // Passes; test still considered passing.
@@ -360,7 +359,7 @@ function must also return [`Result<()>`]:
360359
use googletest::prelude::*;
361360
362361
# /* Make sure this also compiles as a doctest.
363-
#[googletest::test]
362+
#[gtest]
364363
# */
365364
fn failing_non_fatal_assertion() -> Result<()> {
366365
let value = 2;
@@ -374,7 +373,7 @@ fn failing_non_fatal_assertion() -> Result<()> {
374373
```no_run
375374
use googletest::prelude::*;
376375
377-
#[googletest::test]
376+
#[gtest]
378377
fn failing_fatal_assertion_after_non_fatal_assertion() -> Result<()> {
379378
let value = 2;
380379
expect_that!(value, eq(2)); // Passes; test still considered passing.
@@ -491,7 +490,7 @@ impl PngImage {
491490
}
492491
493492
# /* The attribute macro would prevent the function from being compiled in a doctest.
494-
#[googletest::test]
493+
#[gtest]
495494
# */
496495
fn test_png_image_binary() -> googletest::Result<()> {
497496
// Arrange
@@ -508,7 +507,7 @@ impl PngImage {
508507
}
509508
510509
# /* The attribute macro would prevent the function from being compiled in a doctest.
511-
#[googletest::test]
510+
#[gtest]
512511
# */
513512
fn test_png_from_cache() -> googletest::Result<()> {
514513
// Arrange

0 commit comments

Comments
 (0)