Add contains option to checks. (#620)
* Add contains otion to checks.
* Add test for teh contains option of CHECK_THROWS_WITH.
* Adress comments Saalvage: move compare function to Contains, add operator== and make m_exception_string a union."
* Add new tests.
* Attempt to fix windows specific warning about unions.
* Attempt 2 to fix windows specific warning about unions.
* Attempt 3 to fix windows specific warning about unions.
* Attempt 4 to fix windows specific warning about unions.
* Return union to a struct.
* Fixing and refactoring
* Docs
Co-authored-by: Salvage <29021710+Saalvage@users.noreply.github.com>
diff --git a/examples/all_features/assertion_macros.cpp b/examples/all_features/assertion_macros.cpp
index f0fbe9b..959a9c3 100644
--- a/examples/all_features/assertion_macros.cpp
+++ b/examples/all_features/assertion_macros.cpp
@@ -38,8 +38,11 @@
CHECK_THROWS_AS(throw_if(false, 0), int); // fails
CHECK_THROWS_WITH(throw_if(true, "whops!"), "whops! no match!"); // fails
+ CHECK_THROWS_WITH(throw_if(true, "whops! does it match?"), doctest::Contains("whops!"));
+ CHECK_THROWS_WITH(throw_if(true, "whops! does it match?"), doctest::Contains("whops! no match!")); // fails
CHECK_THROWS_WITH_AS(throw_if(true, "whops!"), "whops! no match!", bool); // fails
CHECK_THROWS_WITH_AS(throw_if(true, "whops!"), "whops!", int); // fails
+ CHECK_THROWS_WITH_AS(throw_if(true, "whops! does it match?"), doctest::Contains("whops! no match!"), int); // fails
CHECK_NOTHROW(throw_if(true, 0)); // fails
CHECK_NOTHROW(throw_if(false, 0));
@@ -73,6 +76,10 @@
WARN_NOTHROW(throw_if(true, 0));
WARN_EQ(1, 0);
+ doctest::String myStr = doctest::String("Hello world, how are you doing? Well, nice to meet you, Goodbye!");
+ WARN_EQ(myStr, doctest::Contains("Hello"));
+ WARN(myStr == doctest::Contains("Goodbye"));
+ WARN(myStr != doctest::Contains("goodbye"));
WARN_UNARY(0);
WARN_UNARY_FALSE(1);
}
@@ -88,6 +95,10 @@
CHECK_NOTHROW(throw_if(true, 0));
CHECK_EQ(1, 0);
+ doctest::String myStr = doctest::String("Hello world, how are you doing? Well, nice to meet you, Goodbye!");
+ CHECK_EQ(myStr, doctest::Contains("Hello"));
+ CHECK(myStr == doctest::Contains("Goodbye"));
+ CHECK(myStr != doctest::Contains("goodbye"));
CHECK_UNARY(0);
CHECK_UNARY_FALSE(1);