catchorg / Catch2

A modern, C++-native, test framework for unit-tests, TDD and BDD - using C++14, C++17 and later (C++11 support is in v2.x branch, and C++03 on the Catch1.x branch)
https://discord.gg/4CWS9zD
Boost Software License 1.0
18.78k stars 3.06k forks source link

CHECK/REQUIRE macros to accept file, line as parameters #91

Closed mKlus closed 12 years ago

mKlus commented 12 years ago

Would it be possible to add CHECK/REQUIRE macros that we can pass file, line and possibly custom expression description as parameters?

define CHECK_DFL( expr, exprDesc, file, line ) INTERNAL_CATCH_TEST_DFL( expr, false, false, "CHECK", exprDesc, file, line )

define INTERNAL_CATCH_TEST_DFL( expr, isNot, stopOnFailure, macroName, exprDesc, file, line ) \

do{ try{ \
    INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO_FL(file,line), macroName, exprDesc, isNot )->*expr ), stopOnFailure, expr ); \
}catch( Catch::TestFailureException& ){ \
    throw; \
} catch( ... ){ \
    INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ResultBuilder( CATCH_INTERNAL_LINEINFO_FL(file,line), macroName, exprDesc ) << Catch::Context::getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, expr ); \
    throw; \
}}while( Catch::isTrue( false ) )

philsquared commented 12 years ago

I'm not quite sure what you want to achieve here. CHECK & REQUIRE already capture FILE and LINE internally, which are used when reporting the results. Do you want to be able to pass different values for these? If so why? As for the expression definition - usually the captured form of the expression is enough. If you do want more custom context you can preceed the assertion with INFO( message expression ), which is only logged in the event of a subsequent failure.

mKlus commented 12 years ago

Hi Phil,

thanks for your comment. I tried to explain why I need the macro in #92. I haven't thought about using INFO before. Maybe that can solve my problem.

Thanks, Marek

philsquared commented 12 years ago

I'm going to close this as I don't think it's an issue with CATCH. You are welcome to continue the dialog if you email me directly on my philnash.me domain (put anything before the @)