aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2024-02-02 10:15:57 +0100
committerJeff Vander Stoep <jeffv@google.com>2024-02-02 10:15:57 +0100
commit2240758781a0511a766b558da64f325cdb40bdc5 (patch)
tree7d8d58bae08c7c988425421c564e108cea2bc232
parent07a878819413a910ed2c3606da7080a6cbb7aa1a (diff)
downloadgoogletest_macro-2240758781a0511a766b558da64f325cdb40bdc5.tar.gz
Upgrade googletest_macro to 0.11.0
This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update external/rust/crates/googletest_macro For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md Test: TreeHugger Change-Id: I91ab76c427a5517e7d7e2842355e5ac63046b3ce
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--Android.bp2
-rw-r--r--Cargo.toml7
-rw-r--r--Cargo.toml.orig34
-rw-r--r--METADATA21
-rw-r--r--src/lib.rs41
6 files changed, 91 insertions, 16 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 6a70fdf..1c435c6 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "6e5405db2217d37006720c101beb1b91199a3a26"
+ "sha1": "91a15f5eb416cbf97cd8b6d8831263f2c861b859"
},
"path_in_vcs": "googletest_macro"
} \ No newline at end of file
diff --git a/Android.bp b/Android.bp
index b0585b0..452ffd0 100644
--- a/Android.bp
+++ b/Android.bp
@@ -5,7 +5,7 @@ rust_proc_macro {
name: "libgoogletest_macro",
crate_name: "googletest_macro",
cargo_env_compat: true,
- cargo_pkg_version: "0.10.0",
+ cargo_pkg_version: "0.11.0",
srcs: ["src/lib.rs"],
edition: "2021",
rustlibs: [
diff --git a/Cargo.toml b/Cargo.toml
index 92d0de1..13d4783 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -12,7 +12,7 @@
[package]
edition = "2021"
name = "googletest_macro"
-version = "0.10.0"
+version = "0.11.0"
authors = ["Bradford Hovinen <hovinen@google.com>"]
description = "Procedural macros for GoogleTest Rust"
readme = "README.md"
@@ -28,15 +28,14 @@ categories = [
]
license = "Apache-2.0"
repository = "https://github.com/google/googletest-rust"
-resolver = "1"
[lib]
name = "googletest_macro"
proc-macro = true
[dependencies.quote]
-version = "1.0.21"
+version = "1.0.33"
[dependencies.syn]
-version = "2.0.10"
+version = "2.0.39"
features = ["full"]
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
new file mode 100644
index 0000000..77b6925
--- /dev/null
+++ b/Cargo.toml.orig
@@ -0,0 +1,34 @@
+# Copyright 2022 Google LLC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+[package]
+name = "googletest_macro"
+version = "0.11.0"
+keywords = ["unit", "matcher", "testing", "assertions"]
+categories = ["development-tools", "development-tools::testing"]
+description = "Procedural macros for GoogleTest Rust"
+repository = "https://github.com/google/googletest-rust"
+license = "Apache-2.0"
+edition = "2021"
+authors = [
+ "Bradford Hovinen <hovinen@google.com>",
+]
+
+[dependencies]
+quote = "1.0.33"
+syn = {version = "2.0.39", features = ["full"]}
+
+[lib]
+name = "googletest_macro"
+proc-macro = true
diff --git a/METADATA b/METADATA
index cf14f5e..a025fb9 100644
--- a/METADATA
+++ b/METADATA
@@ -1,19 +1,24 @@
+# This project was upgraded with external_updater.
+# Usage: tools/external_updater/updater.sh update external/rust/crates/googletest_macro
+# For more info, check https://cs.android.com/android/platform/superproject/+/main:tools/external_updater/README.md
+
name: "googletest_macro"
description: "Procedural macros for GoogleTest Rust"
third_party {
+ license_type: NOTICE
+ last_upgrade_date {
+ year: 2024
+ month: 2
+ day: 2
+ }
identifier {
type: "crates.io"
- value: "https://crates.io/crates/googletest_macro"
+ value: "https://static.crates.io/crates/googletest_macro/googletest_macro-0.11.0.crate"
+ version: "0.10.0"
}
identifier {
type: "Archive"
value: "https://static.crates.io/crates/googletest_macro/googletest_macro-0.10.0.crate"
- }
- version: "0.10.0"
- license_type: NOTICE
- last_upgrade_date {
- year: 2023
- month: 9
- day: 1
+ version: "0.11.0"
}
}
diff --git a/src/lib.rs b/src/lib.rs
index 87628ba..1f9a258 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -40,6 +40,32 @@ use syn::{parse_macro_input, Attribute, ItemFn, ReturnType};
/// }
/// ```
///
+/// This macro can be used with `#[should_panic]` to indicate that the test is
+/// expected to panic. For example:
+///
+/// ```ignore
+/// #[googletest::test]
+/// #[should_panic]
+/// fn passes_due_to_should_panic() {
+/// let value = 2;
+/// expect_that!(value, gt(0));
+/// panic!("This panics");
+/// }
+/// ```
+///
+/// Using `#[should_panic]` modifies the behaviour of `#[googletest::test]` so
+/// that the test panics (and passes) if any non-fatal assertion occurs.
+/// For example, the following test passes:
+///
+/// ```ignore
+/// #[googletest::test]
+/// #[should_panic]
+/// fn passes_due_to_should_panic_and_failing_assertion() {
+/// let value = 2;
+/// expect_that!(value, eq(0));
+/// }
+/// ```
+///
/// [`googletest::Result`]: type.Result.html
#[proc_macro_attribute]
pub fn test(
@@ -49,6 +75,15 @@ pub fn test(
let mut parsed_fn = parse_macro_input!(input as ItemFn);
let attrs = parsed_fn.attrs.drain(..).collect::<Vec<_>>();
let (mut sig, block) = (parsed_fn.sig, parsed_fn.block);
+ let (outer_return_type, trailer) =
+ if attrs.iter().any(|attr| attr.path().is_ident("should_panic")) {
+ (quote! { () }, quote! { .unwrap(); })
+ } else {
+ (
+ quote! { std::result::Result<(), googletest::internal::test_outcome::TestFailure> },
+ quote! {},
+ )
+ };
let output_type = match sig.output.clone() {
ReturnType::Type(_, output_type) => Some(output_type),
ReturnType::Default => None,
@@ -81,23 +116,25 @@ pub fn test(
let function = if let Some(output_type) = output_type {
quote! {
#(#attrs)*
- #sig -> std::result::Result<(), googletest::internal::test_outcome::TestFailure> {
+ #sig -> #outer_return_type {
#maybe_closure
use googletest::internal::test_outcome::TestOutcome;
TestOutcome::init_current_test_outcome();
let result: #output_type = #invocation;
TestOutcome::close_current_test_outcome(result)
+ #trailer
}
}
} else {
quote! {
#(#attrs)*
- #sig -> std::result::Result<(), googletest::internal::test_outcome::TestFailure> {
+ #sig -> #outer_return_type {
#maybe_closure
use googletest::internal::test_outcome::TestOutcome;
TestOutcome::init_current_test_outcome();
#invocation;
TestOutcome::close_current_test_outcome(googletest::Result::Ok(()))
+ #trailer
}
}
};