christophercrouzet / rexo

Neat single-file cross-platform unit testing framework for C/C++.
The Unlicense
28 stars 6 forks source link

Eliminate RX_ test code with a single define #21

Closed midjji closed 1 year ago

midjji commented 1 year ago

I guess this will require a change from RX_TEST(suit, name){... } to RX_TEST(suit, name,{... }) or did I miss something?

christophercrouzet commented 1 year ago

Are you saying that you would like to be able to define a macro like #define RX_DISABLE_TESTS 1 that would skip compiling the tests?

midjji commented 1 year ago

Yes,

On Sat, Dec 3, 2022, 04:48 Christopher Crouzet @.***> wrote:

Are you saying that you would like to be able to define a macro like #define RX_DISABLE_TESTS 1 that would skip compiling the tests?

— Reply to this email directly, view it on GitHub https://github.com/christophercrouzet/rexo/issues/21#issuecomment-1336036036, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJQYJMOHGF7TMNCLNTSVDDWLK7KDANCNFSM6AAAAAASSBKFO4 . You are receiving this because you authored the thread.Message ID: @.***>

christophercrouzet commented 1 year ago

I believe that this kind of functionality is best handled on a per-case basis directly by the users.

For example, most of the time, unit tests are isolated in dedicated folders (or files) and can be skipped altogether by the building system (e.g. CMake).

If instead you are writing unit tests directly within your source files, then it'd be as simple as wrapping the tests in a #ifdef macro like this:

int foo(int bar)
{
    return bar * bar;
}

#if RUN_TESTS
#include <rexo.h>

RX_TEST_CASE(foo, bar)
{
    RX_INT_REQUIRE_EQUAL(foo(5), 25);
}

int
main(int argc, const char **argv)
{
    return rx_main(0, NULL, argc, argv) == RX_SUCCESS ? 0 : 1;
}
#endif

Does that make sense?

midjji commented 1 year ago

I see you point and i have somewhat argued for it, but no test code leaking into the binaries despite user carelessness is a requirement from on high in my case.

On Sun, Dec 4, 2022, 00:15 Christopher Crouzet @.***> wrote:

I believe that this kind of functionality is best handled on a per-case basis directly by the users.

For example, most of the time, unit tests are isolated in dedicated folders (or files) and can be skipped altogether by the building system (e.g. CMake).

If instead you are writing unit tests directly within your source files, then it'd be as simple as wrapping the tests in a #ifdef macro like this:

int foo(int bar) { return bar * bar; }

if RUN_TESTS

include

RX_TEST_CASE(foo, bar) { RX_INT_REQUIRE_EQUAL(foo(5), 25); } intmain(int argc, const char **argv) { return rx_main(0, NULL, argc, argv) == RX_SUCCESS ? 0 : 1; }

endif

Does that make sense?

— Reply to this email directly, view it on GitHub https://github.com/christophercrouzet/rexo/issues/21#issuecomment-1336276225, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJQYJOT5WDFAACBXNIVDQLWLPH7VANCNFSM6AAAAAASSBKFO4 . You are receiving this because you authored the thread.Message ID: @.***>

christophercrouzet commented 1 year ago

What would prevent careless users to forget setting the RX_DISABLE_TESTS macro to 1 then? 😄

I'm sorry but this kind of feature is beyond the scope that I'm envisioning for this library—this is IMO best handled by users, and I'd encourage you to used dedicated test files to avoid any issue.