Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update documentation for expect_true, expect_false, assert_pred and expect_pred macros, which accept formatting args. #617

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions googletest/src/assertions.rs
Original file line number Diff line number Diff line change
@@ -484,6 +484,29 @@ pub use verify_true;
/// println!("This will print");
/// }
/// ```
///
/// One may optionally add arguments which will be formatted and appended to a
/// failure message. For example:
///
/// ```ignore
/// use googletest::prelude::*;
///
/// #[gtest]
/// fn should_fail() {
/// let extra_information = "Some additional information";
/// expect_true!(false, "Test failed. Extra information: {extra_information}.");
/// }
/// ```
///
/// The output is as follows:
///
/// ```text
/// Value of: false
/// Expected: is equal to true
/// Actual: false,
/// which isn't equal to true
/// Test failed. Extra information: Some additional information.
/// ```
#[macro_export]
macro_rules! expect_true {
($condition:expr) => {{
@@ -550,6 +573,29 @@ pub use verify_false;
/// println!("This will print");
/// }
/// ```
///
/// One may optionally add arguments which will be formatted and appended to a
/// failure message. For example:
///
/// ``` ignore
/// use googletest::prelude::*;
///
/// #[gtest]
/// fn should_fail() {
/// let extra_information = "Some additional information";
/// expect_false!(true, "Test failed. Extra information: {extra_information}.");
/// }
/// ```
///
/// The output is as follows:
///
/// ```text
/// Value of: true
/// Expected: is equal to false
/// Actual: true,
/// which isn't equal to false
/// Test failed. Extra information: Some additional information.
/// ```
#[macro_export]
macro_rules! expect_false {
($condition:expr) => {{
@@ -1405,6 +1451,25 @@ pub use assert_that;
/// Asserts that the given predicate applied to the given arguments returns
/// true, panicking if it does not.
///
/// One may optionally add arguments which will be formatted and appended to a
/// failure message. For example:
///
/// ```should_panic
/// # use googletest::prelude::*;
/// # fn should_fail() {
/// let extra_information = "Some additional information";
/// assert_pred!(1 == 2, "Test failed. Extra information: {extra_information}.");
/// # }
/// # should_fail();
/// ```
///
/// The output is as follows:
///
/// ```text
/// 1 == 2 was false with
/// Test failed. Extra information: Some additional information.
/// ```
///
/// **Note for users of [GoogleTest for C++](http://google.github.io/googletest/):**
/// This differs from the `ASSERT_PRED*` family of macros in that it panics
/// rather than triggering an early return from the invoking function. To get
@@ -1536,6 +1601,26 @@ pub use expect_that;
/// ```ignore
/// verify_pred!(predicate(...)).and_log_failure()
/// ```
///
/// One may optionally add arguments which will be formatted and appended to a
/// failure message. For example:
///
/// ```ignore
/// use googletest::prelude::*;
///
/// #[gtest]
/// fn should_fail() {
/// let extra_information = "Some additional information";
/// expect_pred!(1 == 2, "Test failed. Extra information: {extra_information}.");
/// }
/// ```
///
/// The output is as follows:
///
/// ```text
/// 1 == 2 was false with
/// Test failed. Extra information: Some additional information.
/// ```
#[macro_export]
macro_rules! expect_pred {
($content:expr $(,)?) => {{
Loading