catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Start adding tests for string manip functions
- Commit
b77ab74b723cbd55ee12883562e22c7e467dbcb1- Author
- Martin Hořeňovský ·
- Parents
4038ee6bc6d9
Changes
projects/CMakeLists.txt | 1 + .../SelfTest/Baselines/compact.sw.approved.txt | 12 ++++++ .../SelfTest/Baselines/console.std.approved.txt | 4 +- .../SelfTest/Baselines/console.sw.approved.txt | 38 ++++++++++++++++- projects/SelfTest/Baselines/junit.sw.approved.txt | 3 +- projects/SelfTest/Baselines/xml.sw.approved.txt | 47 +++++++++++++++++++++- .../IntrospectiveTests/StringManip.tests.cpp | 18 +++++++++ 7 files changed, 116 insertions(+), 7 deletions(-) diff --git a/projects/CMakeLists.txt b/projects/CMakeLists.txt index 1f84ba09..3e506847 100644 --- a/projects/CMakeLists.txt +++ b/projects/CMakeLists.txt @@ -23,6 +23,7 @@ set(TEST_SOURCES ${SELF_TEST_DIR}/IntrospectiveTests/PartTracker.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Tag.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/String.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/StringManip.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/Xml.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/ToString.tests.cpp ${SELF_TEST_DIR}/UsageTests/Approx.tests.cpp diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 1765707b..b872265f 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -1299,6 +1299,18 @@ PartTracker.tests.cpp:<line number>: passed: s1.isComplete() == false for: false PartTracker.tests.cpp:<line number>: passed: s1.isComplete() for: true PartTracker.tests.cpp:<line number>: passed: testCase.isComplete() == false for: false == false PartTracker.tests.cpp:<line number>: passed: testCase.isComplete() for: true +StringManip.tests.cpp:<line number>: passed: trim(std::string(no_whitespace)) == no_whitespace for: "There is no extra whitespace here" +== +"There is no extra whitespace here" +StringManip.tests.cpp:<line number>: passed: trim(std::string(leading_whitespace)) == no_whitespace for: "There is no extra whitespace here" +== +"There is no extra whitespace here" +StringManip.tests.cpp:<line number>: passed: trim(std::string(trailing_whitespace)) == no_whitespace for: "There is no extra whitespace here" +== +"There is no extra whitespace here" +StringManip.tests.cpp:<line number>: passed: trim(std::string(whitespace_at_both_ends)) == no_whitespace for: "There is no extra whitespace here" +== +"There is no extra whitespace here" Exception.tests.cpp:<line number>: failed: unexpected exception with message: '3.14' Approx.tests.cpp:<line number>: passed: d == approx( 1.23 ) for: 1.23 == Approx( 1.23 ) Approx.tests.cpp:<line number>: passed: d == approx( 1.22 ) for: 1.23 == Approx( 1.22 ) diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 28fd8eb5..a52bb9a5 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1380,6 +1380,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 299 | 225 passed | 70 failed | 4 failed as expected -assertions: 1554 | 1402 passed | 131 failed | 21 failed as expected +test cases: 300 | 226 passed | 70 failed | 4 failed as expected +assertions: 1558 | 1406 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 9885193a..8b03e232 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -9779,6 +9779,40 @@ PartTracker.tests.cpp:<line number>: PASSED: with expansion: true +------------------------------------------------------------------------------- +Trim strings +------------------------------------------------------------------------------- +StringManip.tests.cpp:<line number> +............................................................................... + +StringManip.tests.cpp:<line number>: PASSED: + REQUIRE( trim(std::string(no_whitespace)) == no_whitespace ) +with expansion: + "There is no extra whitespace here" + == + "There is no extra whitespace here" + +StringManip.tests.cpp:<line number>: PASSED: + REQUIRE( trim(std::string(leading_whitespace)) == no_whitespace ) +with expansion: + "There is no extra whitespace here" + == + "There is no extra whitespace here" + +StringManip.tests.cpp:<line number>: PASSED: + REQUIRE( trim(std::string(trailing_whitespace)) == no_whitespace ) +with expansion: + "There is no extra whitespace here" + == + "There is no extra whitespace here" + +StringManip.tests.cpp:<line number>: PASSED: + REQUIRE( trim(std::string(whitespace_at_both_ends)) == no_whitespace ) +with expansion: + "There is no extra whitespace here" + == + "There is no extra whitespace here" + ------------------------------------------------------------------------------- Unexpected exceptions can be translated ------------------------------------------------------------------------------- @@ -12421,6 +12455,6 @@ Misc.tests.cpp:<line number> Misc.tests.cpp:<line number>: PASSED: =============================================================================== -test cases: 299 | 209 passed | 86 failed | 4 failed as expected -assertions: 1571 | 1402 passed | 148 failed | 21 failed as expected +test cases: 300 | 210 passed | 86 failed | 4 failed as expected +assertions: 1575 | 1406 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 5ad04f55..da7853d3 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <testsuitesloose text artifact > - <testsuite name="<exe-name>" errors="17" failures="132" tests="1572" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> + <testsuite name="<exe-name>" errors="17" failures="132" tests="1576" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <properties> <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/> <property name="random-seed" value="1"/> @@ -825,6 +825,7 @@ Exception.tests.cpp:<line number> <testcase classname="<exe-name>.global" name="Tracker/successfully close one section, then find another/Re-enter - skips S1 and enters S2/Successfully close S2" time="{duration}"/> <testcase classname="<exe-name>.global" name="Tracker/successfully close one section, then find another/Re-enter - skips S1 and enters S2/fail S2" time="{duration}"/> <testcase classname="<exe-name>.global" name="Tracker/open a nested section" time="{duration}"/> + <testcase classname="<exe-name>.global" name="Trim strings" time="{duration}"/> <testcase classname="<exe-name>.global" name="Unexpected exceptions can be translated" time="{duration}"> <error type="TEST_CASE"> 3.14 diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 177fa01a..9032dd52 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -11813,6 +11813,49 @@ Message from section two </Section> <OverallResult success="true"/> </TestCase> + <TestCase name="Trim strings" tags="[string-manip]" filename="projects/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + trim(std::string(no_whitespace)) == no_whitespace + </Original> + <Expanded> + "There is no extra whitespace here" +== +"There is no extra whitespace here" + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + trim(std::string(leading_whitespace)) == no_whitespace + </Original> + <Expanded> + "There is no extra whitespace here" +== +"There is no extra whitespace here" + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + trim(std::string(trailing_whitespace)) == no_whitespace + </Original> + <Expanded> + "There is no extra whitespace here" +== +"There is no extra whitespace here" + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/IntrospectiveTests/StringManip.tests.cpp" > + <Original> + trim(std::string(whitespace_at_both_ends)) == no_whitespace + </Original> + <Expanded> + "There is no extra whitespace here" +== +"There is no extra whitespace here" + </Expanded> + </Expression> + <OverallResult success="true"/> + </TestCase> <TestCase name="Unexpected exceptions can be translated" tags="[!throws][.][failing]" filename="projects/<exe-name>/UsageTests/Exception.tests.cpp" > <Exception filename="projects/<exe-name>/UsageTests/Exception.tests.cpp" > 3.14 @@ -14778,7 +14821,7 @@ loose text artifact </Section> <OverallResult success="true"/> </TestCase> - <OverallResults successes="1402" failures="149" expectedFailures="21"/> + <OverallResults successes="1406" failures="149" expectedFailures="21"/> </Group> - <OverallResults successes="1402" failures="148" expectedFailures="21"/> + <OverallResults successes="1406" failures="148" expectedFailures="21"/> </Catch> diff --git a/projects/SelfTest/IntrospectiveTests/StringManip.tests.cpp b/projects/SelfTest/IntrospectiveTests/StringManip.tests.cpp new file mode 100644 index 00000000..31b5c6ce --- /dev/null +++ b/projects/SelfTest/IntrospectiveTests/StringManip.tests.cpp @@ -0,0 +1,18 @@ +#include "internal/catch_string_manip.h" + +#include "catch.hpp" + +static const char * const no_whitespace = "There is no extra whitespace here"; +static const char * const leading_whitespace = " \r \t\n There is no extra whitespace here"; +static const char * const trailing_whitespace = "There is no extra whitespace here \t \n \r "; +static const char * const whitespace_at_both_ends = " \r\n \t There is no extra whitespace here \t\t\t \n"; + +TEST_CASE("Trim strings", "[string-manip]") { + using Catch::trim; using Catch::StringRef; + static_assert(std::is_same<std::string, decltype(trim(std::string{}))>::value, "Trimming std::string should return std::string"); + + REQUIRE(trim(std::string(no_whitespace)) == no_whitespace); + REQUIRE(trim(std::string(leading_whitespace)) == no_whitespace); + REQUIRE(trim(std::string(trailing_whitespace)) == no_whitespace); + REQUIRE(trim(std::string(whitespace_at_both_ends)) == no_whitespace); +}