17 #ifndef COM_BORA_SOFTWARE__BALAU_TESTING__ASSERTIONS 18 #define COM_BORA_SOFTWARE__BALAU_TESTING__ASSERTIONS 21 #include <Balau/Type/SourceCodeLocation.hpp> 35 inline void assertFail(
const std::string & failMessage) {
44 template <
typename A,
typename E,
typename C,
typename V,
typename F>
45 inline void assertThat(
const SourceCodeLocation & location,
const std::string & failMessage,
const A & actual,
const ExpectedValue<E, C, V, F> & expected) {
46 MatcherFunction<A, E, V, C> matcherFunction(expected.value());
48 if (!matcherFunction.matches(actual, expected.expected)) {
61 template <
typename A,
typename E,
typename C,
typename V,
typename F>
62 inline void assertThat(
const std::string & failMessage,
const A & actual,
const ExpectedValue<E, C, V, F> & expected) {
63 MatcherFunction<A, E, V, C> matcherFunction(expected.value());
65 if (!matcherFunction.matches(actual, expected.expected)) {
76 template <
typename A,
typename E,
typename C,
typename V,
typename F>
84 template <
typename A,
typename E,
typename C,
typename V,
typename F>
85 inline void assertThat(
const A & actual,
const ExpectedValue<E, C, V, F> & expected) {
97 template <
typename A,
typename E,
typename C,
typename V,
typename F>
98 inline void assertThatNP(
const SourceCodeLocation & location,
const std::string & failMessage,
const A & actual,
const ExpectedValue<E, C, V, F> & expected) {
99 MatcherFunction<A, E, V, C> matcherFunction(expected.value());
101 if (!matcherFunction.matches(actual, expected.expected)) {
114 template <
typename A,
typename E,
typename C,
typename V,
typename F>
115 inline void assertThatNP(
const std::string & failMessage,
const A & actual,
const ExpectedValue<E, C, V, F> & expected) {
116 MatcherFunction<A, E, V, C> matcherFunction(expected.value());
118 if (!matcherFunction.matches(actual, expected.expected)) {
129 template <
typename A,
typename E,
typename C,
typename V,
typename F>
140 template <
typename A,
typename E,
typename C,
typename V,
typename F>
141 inline void assertThatNP(
const A & actual,
const ExpectedValue<E, C, V, F> & expected) {
150 template <
typename A,
typename T>
152 if (!dynamic_cast<const T *>(&actual)) {
155 ,
toString(location) +
" - " + failMessage +
"\nIncompatible types: " + boost::core::demangle(
typeid(actual).name()) +
" is not a " + boost::core::demangle(
typeid(T).name())
165 template <
typename A,
typename T>
166 inline void assertThat(
const std::string & failMessage,
const A & actual,
const IsAExpectation<T> & ) {
167 if (!dynamic_cast<const T *>(&actual)) {
170 , failMessage +
"\nIncompatible types: " + boost::core::demangle(
typeid(actual).name()) +
" is not a " + boost::core::demangle(
typeid(T).name())
178 template <
typename A,
typename T>
186 template <
typename A,
typename T>
187 inline void assertThat(
const A & actual,
const IsAExpectation<T> & expected) {
199 template <
typename A,
typename T>
201 if (!dynamic_cast<const T *>(&actual)) {
214 template <
typename A,
typename T>
215 inline void assertThatNP(
const std::string & failMessage,
const A & actual,
const IsAExpectation<T> & ) {
216 if (!dynamic_cast<const T *>(&actual)) {
227 template <
typename A,
typename T>
238 template <
typename A,
typename T>
239 inline void assertThatNP(
const A & actual,
const IsAExpectation<T> & expected) {
252 template <
typename F,
typename E>
256 }
catch (
const E & actualException) {
257 assertThat(location, failMessage, actualException,
is(e.e));
259 }
catch (
const std::exception & actualException) {
262 ,
toString(location) +
" - " + failMessage +
"\nA different standard exception was thrown: " + actualException.what()
268 ,
toString(location) +
" - " + failMessage +
"\nThe expected exception was not thrown." 281 template <
typename F,
typename E>
282 inline void assertThat(
const std::string & failMessage, F
function,
const ThrowExpectation<E> & e) {
285 }
catch (
const E & actualException) {
288 }
catch (
const std::exception & actualException) {
291 , failMessage +
"\nA different standard exception was thrown: " + actualException.what()
297 , failMessage +
"\nThe expected exception was not thrown." 310 template <
typename F,
typename E,
typename C>
311 inline void assertThat(
const SourceCodeLocation & location,
const std::string & failMessage, F
function,
const ThrowExpectationWithFunction<E, C> & e) {
314 }
catch (
const E & actualException) {
315 if (!e.compare(actualException)) {
322 ,
"\nThe exception's state was not identical to the supplied exception: " 331 }
catch (
const std::exception & actualException) {
334 ,
toString(location) +
" - " + failMessage +
"\nA different standard exception was thrown: " + actualException.what()
340 ,
toString(location) +
" - " + failMessage +
"\nThe expected exception was not thrown." 352 template <
typename F,
typename E>
353 inline void assertThat(
const SourceCodeLocation & location,
const std::string & failMessage, F
function,
const ThrowExpectationWithPredicate<E> & predicate) {
356 }
catch (
const E & actualException) {
357 if (!predicate.compare(actualException)) {
364 ,
"\nThe exception's state was unexpected: " 371 }
catch (
const std::exception & actualException) {
374 ,
toString(location) +
" - " + failMessage +
"\nA different standard exception was thrown: " + actualException.what()
380 ,
toString(location) +
" - " + failMessage +
"\nThe expected exception was not thrown." 393 template <
typename F,
typename E,
typename C>
394 inline void assertThat(
const std::string & failMessage, F
function,
const ThrowExpectationWithFunction<E, C> & e) {
397 }
catch (
const E & actualException) {
398 if (!e.compare(actualException)) {
403 ,
"\nThe exception's state was not identical to the supplied exception: " 412 }
catch (
const std::exception & actualException) {
415 , failMessage +
"\nA different standard exception was thrown: " + actualException.what()
421 , failMessage +
"\nThe expected exception was not thrown." 433 template <
typename F,
typename E>
434 inline void assertThat(
const std::string & failMessage, F
function,
const ThrowExpectationWithPredicate<E> & predicate) {
437 }
catch (
const E & actualException) {
438 if (!predicate.compare(actualException)) {
443 ,
"\nThe exception's state was unexpected: " 450 }
catch (
const std::exception & actualException) {
453 , failMessage +
"\nA different standard exception was thrown: " + actualException.what()
459 , failMessage +
"\nThe expected exception was not thrown." 471 template <
typename F,
typename E>
475 }
catch (
const E & actualException) {
478 }
catch (
const std::exception & actualException) {
481 ,
toString(location) +
" - " + failMessage +
"\nA different standard exception was thrown: " + actualException.what()
487 ,
toString(location) +
" - " + failMessage +
"\nThe expected exception was not thrown." 499 template <
typename F,
typename E>
500 inline void assertThat(
const std::string & failMessage, F
function,
const ThrowTypeExpectation<E> &) {
503 }
catch (
const E & actualException) {
506 }
catch (
const std::exception & actualException) {
509 , failMessage +
"\nA different standard exception was thrown: " + actualException.what()
515 , failMessage +
"\nThe expected exception was not thrown." 527 template <
typename F,
typename E>
529 assertThat(location,
"",
function, expectedException);
540 template <
typename F,
typename E>
541 inline void assertThat(F
function,
const ThrowExpectation<E> & expectedException) {
553 template <
typename F,
typename E,
typename C>
555 assertThat(location,
"",
function, expectedException);
564 template <
typename F,
typename E>
566 assertThat(location,
"",
function, predicate);
577 template <
typename F,
typename E,
typename C>
578 inline void assertThat(F
function,
const ThrowExpectationWithFunction<E, C> & expectedException) {
588 template <
typename F,
typename E>
589 inline void assertThat(F
function,
const ThrowExpectationWithPredicate<E> & predicate) {
599 template <
typename F,
typename E>
601 assertThat(location,
"",
function, expectedExceptionType);
610 template <
typename F,
typename E>
611 inline void assertThat(F
function,
const ThrowTypeExpectation<E> & expectedExceptionType) {
612 assertThat(
"",
function, expectedExceptionType);
620 #define AssertFail(...) ::Balau::Testing::assertFail(::Balau::SourceCodeLocation(__FILE__, __LINE__), __VA_ARGS__) 625 #define AssertThat(...) ::Balau::Testing::assertThat(::Balau::SourceCodeLocation(__FILE__, __LINE__), __VA_ARGS__) 630 #define AssertThatNP(...) ::Balau::Testing::assertThatNP(::Balau::SourceCodeLocation(__FILE__, __LINE__), __VA_ARGS__) 632 #endif // COM_BORA_SOFTWARE__BALAU_TESTING__ASSERTIONS #define ThrowBalauException(ExceptionClass,...)
Throw a Balau style exception, with implicit file and line number, and optional stacktrace.
Definition: BalauException.hpp:45
std::string render(const ContainerA< char > &actual, const ContainerE< char > &expected)
Overload for rendering char containers as hex values.
Definition: HexCharRenderer.hpp:28
The exception thrown by the test runner when an assertion fails.
Definition: TestExceptions.hpp:27
void assertThat(const SourceCodeLocation &location, const std::string &failMessage, const A &actual, const ExpectedValue< E, C, V, F > &expected)
Assert that the actual value supplied matches that in the matcher.
Definition: Assertions.hpp:45
A type used to representing a source code file and line number pair, obtained via the FILE and LINE m...
Definition: SourceCodeLocation.hpp:27
Matcher functions for test assertions.
ExpectedValue< E, MatcherCompareEquals, EvNotUsed, EvNotUsed > is(const E &expected)
Is the actual value equal to the supplied expected value?
Definition: Matchers.hpp:28
The test runner and test assertion functions.
Definition: Assertions.hpp:23
Balau::U8String< AllocatorT > toString(ExecutionModel model)
Print the execution model value as a UTF-8 string.
Definition: ExecutionModel.hpp:92
void assertThatNP(const SourceCodeLocation &location, const std::string &failMessage, const A &actual, const ExpectedValue< E, C, V, F > &expected)
Assertion without printing a failure rendering.
Definition: Assertions.hpp:98
void assertFail(const SourceCodeLocation &location, const std::string &failMessage)
Cause an assertion failure with a message.
Definition: Assertions.hpp:28