You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Lowering the barrier to writing test cases even further (especially for the initial stages of (or small) projects, which is exactly where writing tests is often "postponed", even though simple, quick early smoke testing could save a lot of wasted effort) conflicts with the need for coming up with nice, unique, descriptive case names (especially when they are already thematically grouped in some test runner file), which could be a hindrance.
It would be nice to start with no name, and then add one later, as things (like terminology) take shape (and if the test case actually turns out to be kept at all, which is often not what happens).
E.g. for compilers, which support __COUNTER__ (i.e. all?), this is what I've done:
#define STRINGIFY_2(a) #a
#define STRINGIFY(a) STRINGIFY_2(a)
#define CONCAT_2(a, b) a##b
#define CONCAT(a, b) CONCAT_2(a, b)
#define FIRST(x, ...) x
#ifndef STD_CONFORMANT_PREPROCESSOR
#error Conformant C++ preprocessor is required for optional test case names!
#endif
#define CASE(...) DOCTEST_TEST_CASE( FIRST(__VA_ARGS__ __VA_OPT__(,) STRINGIFY(CONCAT(test_case_,__COUNTER__))) )
(Failure reports still include line numbers, so identifying nameless cases is not really a problem, especially if you have IDE support for locating the offending lines. And if you land there, you might then actually add a name, if you feel like. The point is you are not forced to.)
(BTW, that "conformant checking" placeholder in the code is not for __COUNTER__ -- that's still not standardized, unfortunately, but for __VA_OPT__, which is standardized, but the default (i.e. legacy) MSVC preprocessor merrily ignores even with -std:c++infinity. (-Zc:preprocessor enables their conformant version, in case anyone was wondering.))
The text was updated successfully, but these errors were encountered:
Unfortunately __VA_OPT__ forces you to C20 / C++20, so that would likely be a no-go. One option would be to add a macro that introduces a unique name into scope for you, like...
Description
Lowering the barrier to writing test cases even further (especially for the initial stages of (or small) projects, which is exactly where writing tests is often "postponed", even though simple, quick early smoke testing could save a lot of wasted effort) conflicts with the need for coming up with nice, unique, descriptive case names (especially when they are already thematically grouped in some test runner file), which could be a hindrance.
It would be nice to start with no name, and then add one later, as things (like terminology) take shape (and if the test case actually turns out to be kept at all, which is often not what happens).
E.g. for compilers, which support
__COUNTER__
(i.e. all?), this is what I've done:(Failure reports still include line numbers, so identifying nameless cases is not really a problem, especially if you have IDE support for locating the offending lines. And if you land there, you might then actually add a name, if you feel like. The point is you are not forced to.)
(BTW, that "conformant checking" placeholder in the code is not for
__COUNTER__
-- that's still not standardized, unfortunately, but for__VA_OPT__
, which is standardized, but the default (i.e. legacy) MSVC preprocessor merrily ignores even with-std:c++infinity
. (-Zc:preprocessor
enables their conformant version, in case anyone was wondering.))The text was updated successfully, but these errors were encountered: