Add TESTUTILS_ASSERT_LIKE macro

This commit is contained in:
Martchus 2018-07-02 23:09:52 +02:00
parent 236309971d
commit d029b33a19
1 changed files with 15 additions and 3 deletions

View File

@ -201,13 +201,25 @@ template <typename T, Traits::DisableIf<std::is_integral<T>> * = nullptr> const
return value; return value;
} }
#ifndef TESTUTILS_ASSERT_EXEC
/*! /*!
* \brief Asserts successful execution of application via TestApplication::execApp(). Output is stored in stdout and stderr. * \brief Asserts successful execution of the application with the specified CLI \a args.
*
* The application is executed via TestApplication::execApp(). Output is stored in the std::string variables stdout
* and stderr.
*
* \remarks Requires cppunit. * \remarks Requires cppunit.
*/ */
#define TESTUTILS_ASSERT_EXEC(args) CPPUNIT_ASSERT_EQUAL(0, execApp(args, stdout, stderr)) #define TESTUTILS_ASSERT_EXEC(args) CPPUNIT_ASSERT_EQUAL(0, execApp(args, stdout, stderr))
#endif
/*!
* \brief Asserts whether the specified \a string matches the specified \a regex.
* \remarks Requires cppunit.
*/
#define TESTUTILS_ASSERT_LIKE(message, expectedRegex, actualString) \
(CPPUNIT_NS::Asserter::failIf(!(std::regex_match(actualString, std::regex(expectedRegex))), \
CPPUNIT_NS::Message(ConversionUtilities::argsToString('\"', actualString, "\"\n not like\n\"", expectedRegex, '\"'), \
"Expression: " #actualString, message), \
CPPUNIT_SOURCELINE()))
/*! /*!
* \brief Allows printing pairs so key/values of maps/hashes can be asserted using CPPUNIT_ASSERT_EQUAL. * \brief Allows printing pairs so key/values of maps/hashes can be asserted using CPPUNIT_ASSERT_EQUAL.