Skip to content

Commit 0f7e0e7

Browse files
Googlercopybara-github
authored andcommitted
Update documentation for expect_true, expect_false, assert_pred and expect_pred macros, which accept formatting args.
PiperOrigin-RevId: 737999810
1 parent a18b4d5 commit 0f7e0e7

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

googletest/src/assertions.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,29 @@ pub use verify_true;
484484
/// println!("This will print");
485485
/// }
486486
/// ```
487+
///
488+
/// One may optionally add arguments which will be formatted and appended to a
489+
/// failure message. For example:
490+
///
491+
/// ```ignore
492+
/// use googletest::prelude::*;
493+
///
494+
/// #[gtest]
495+
/// fn should_fail() {
496+
/// let extra_information = "Some additional information";
497+
/// expect_true!(false, "Test failed. Extra information: {extra_information}.");
498+
/// }
499+
/// ```
500+
///
501+
/// The output is as follows:
502+
///
503+
/// ```text
504+
/// Value of: false
505+
/// Expected: is equal to true
506+
/// Actual: false,
507+
/// which isn't equal to true
508+
/// Test failed. Extra information: Some additional information.
509+
/// ```
487510
#[macro_export]
488511
macro_rules! expect_true {
489512
($condition:expr) => {{
@@ -550,6 +573,29 @@ pub use verify_false;
550573
/// println!("This will print");
551574
/// }
552575
/// ```
576+
///
577+
/// One may optionally add arguments which will be formatted and appended to a
578+
/// failure message. For example:
579+
///
580+
/// ``` ignore
581+
/// use googletest::prelude::*;
582+
///
583+
/// #[gtest]
584+
/// fn should_fail() {
585+
/// let extra_information = "Some additional information";
586+
/// expect_false!(true, "Test failed. Extra information: {extra_information}.");
587+
/// }
588+
/// ```
589+
///
590+
/// The output is as follows:
591+
///
592+
/// ```text
593+
/// Value of: true
594+
/// Expected: is equal to false
595+
/// Actual: true,
596+
/// which isn't equal to false
597+
/// Test failed. Extra information: Some additional information.
598+
/// ```
553599
#[macro_export]
554600
macro_rules! expect_false {
555601
($condition:expr) => {{
@@ -1405,6 +1451,25 @@ pub use assert_that;
14051451
/// Asserts that the given predicate applied to the given arguments returns
14061452
/// true, panicking if it does not.
14071453
///
1454+
/// One may optionally add arguments which will be formatted and appended to a
1455+
/// failure message. For example:
1456+
///
1457+
/// ```should_panic
1458+
/// # use googletest::prelude::*;
1459+
/// # fn should_fail() {
1460+
/// let extra_information = "Some additional information";
1461+
/// assert_pred!(1 == 2, "Test failed. Extra information: {extra_information}.");
1462+
/// # }
1463+
/// # should_fail();
1464+
/// ```
1465+
///
1466+
/// The output is as follows:
1467+
///
1468+
/// ```text
1469+
/// 1 == 2 was false with
1470+
/// Test failed. Extra information: Some additional information.
1471+
/// ```
1472+
///
14081473
/// **Note for users of [GoogleTest for C++](http://google.github.io/googletest/):**
14091474
/// This differs from the `ASSERT_PRED*` family of macros in that it panics
14101475
/// rather than triggering an early return from the invoking function. To get
@@ -1536,6 +1601,26 @@ pub use expect_that;
15361601
/// ```ignore
15371602
/// verify_pred!(predicate(...)).and_log_failure()
15381603
/// ```
1604+
///
1605+
/// One may optionally add arguments which will be formatted and appended to a
1606+
/// failure message. For example:
1607+
///
1608+
/// ```ignore
1609+
/// use googletest::prelude::*;
1610+
///
1611+
/// #[gtest]
1612+
/// fn should_fail() {
1613+
/// let extra_information = "Some additional information";
1614+
/// expect_pred!(1 == 2, "Test failed. Extra information: {extra_information}.");
1615+
/// }
1616+
/// ```
1617+
///
1618+
/// The output is as follows:
1619+
///
1620+
/// ```text
1621+
/// 1 == 2 was false with
1622+
/// Test failed. Extra information: Some additional information.
1623+
/// ```
15391624
#[macro_export]
15401625
macro_rules! expect_pred {
15411626
($content:expr $(,)?) => {{

0 commit comments

Comments
 (0)