diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-02-02 23:53:10 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2024-02-02 23:53:10 +0000 |
commit | bea22aded6066d736c576a38c47fe1a661af8162 (patch) | |
tree | 7d8d58bae08c7c988425421c564e108cea2bc232 | |
parent | 6b2cd5ee9c97ecc271dc277c190ffc21ffbba852 (diff) | |
parent | 2240758781a0511a766b558da64f325cdb40bdc5 (diff) | |
download | googletest_macro-simpleperf-release.tar.gz |
Snap for 11400057 from 2240758781a0511a766b558da64f325cdb40bdc5 to simpleperf-releasesimpleperf-release
Change-Id: Ic8eaf343f0b77212b98782d8cc10e7276a7cd2ed
-rw-r--r-- | .cargo_vcs_info.json | 2 | ||||
-rw-r--r-- | Android.bp | 2 | ||||
-rw-r--r-- | Cargo.toml | 7 | ||||
-rw-r--r-- | Cargo.toml.orig | 34 | ||||
-rw-r--r-- | METADATA | 21 | ||||
-rw-r--r-- | src/lib.rs | 41 |
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 @@ -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: [ @@ -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 @@ -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" } } @@ -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 } } }; |