Skip to content

Commit 4acb873

Browse files
gribozavrcopybara-github
authored andcommitted
Rename googletest::test to googletest::gtest, and make test an alias for gtest
As we were adopting Googletest Rust within Google, we received feedback that `#[googletest::test]` is too long, inconvenient to type, that it repeats the word "test" twice, or that it is too much detail for a user to care about. Thus, we decided to rename `#[googletest::test]` to `#[gtest]`, also adding it to the prelude. This is consistent with existing practice in other Rust crates that enhance the testing experience, for example, `#[rstest]`. This commit starts a multi-commit chain. We are not deprecating `#[googletest::test]`, because this spelling is useful for compatibility with the rstest crate. PiperOrigin-RevId: 660991306
1 parent a23b0c5 commit 4acb873

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

googletest/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub mod prelude {
5858
};
5959
}
6060

61+
pub use googletest_macro::gtest;
6162
pub use googletest_macro::test;
6263

6364
use internal::test_outcome::{TestAssertionFailure, TestOutcome};

googletest_macro/src/lib.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use syn::{parse_macro_input, Attribute, DeriveInput, ItemFn, ReturnType};
6868
///
6969
/// [`googletest::Result`]: type.Result.html
7070
#[proc_macro_attribute]
71-
pub fn test(
71+
pub fn gtest(
7272
_args: proc_macro::TokenStream,
7373
input: proc_macro::TokenStream,
7474
) -> proc_macro::TokenStream {
@@ -149,6 +149,31 @@ pub fn test(
149149
output.into()
150150
}
151151

152+
/// Alias for [`googletest::gtest`].
153+
///
154+
/// Generally, prefer using `#[gtest]` to mark googletest-based tests.
155+
///
156+
/// Use `#[googletest::test]` instead of `#[gtest]` to satisfy compatibility
157+
/// requirements. For example, the rstest crate can be composed with other test
158+
/// attributes but it requires the attribute to be named `test`.
159+
///
160+
/// ```ignore
161+
/// #[rstest]
162+
/// #[googletest::test]
163+
/// fn rstest_with_googletest() -> Result<()> {
164+
/// verify_that!(1, eq(1))
165+
/// }
166+
/// ```
167+
///
168+
/// [`googletest::gtest`]: attr.gtest.html
169+
#[proc_macro_attribute]
170+
pub fn test(
171+
args: proc_macro::TokenStream,
172+
input: proc_macro::TokenStream,
173+
) -> proc_macro::TokenStream {
174+
gtest(args, input)
175+
}
176+
152177
fn is_test_attribute(attr: &Attribute) -> bool {
153178
let first_segment = match attr.path().segments.first() {
154179
Some(first_segment) => first_segment,

0 commit comments

Comments
 (0)