sheredom / utest.h

🧪 single header unit testing framework for C and C++

Home Page:https://www.duskborn.com/utest_h/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

work like doctest for c++?

laoshaw opened this issue · comments

doctest has one definition flag(DOCTEST_CONFIG_DISABLE) that can toggle testcase code(e.g. like NDEBUG) and can let me mix test code with production code easily, can utest.h do that? that is, all unit tests code are right in the production code(instead of in separate test source files), and I can turn them off for a release build.

that make all test code just like the NDEBUG controlled assert, I can turn on and off easily, and can put testcases with the real production code together, in the same file.

however doctest does not work for c, utest.h can, so I wonder if utest.h can do the same.

just checked utest.h and it does not have such a flag, but it would be nice to have if possible. The use scenario is like: when I cmake Debug build it will use UTEST_MAIN() and run all the test cases, if I cmake the Release build it will turn off all the testcases(e.g. -DDISABLE_UTEST_H) and use a separate main.c/main.cpp for release build.

That should be doable in theory - I don't have any bandwidth to commit to doing it in the near term though.

I've been thinking about this and have solved it partially for my workflow.

It may not be obvious, but literate programming can allow one to place code right next to the test code while tangling them to separate auto-generated files. Here is an example literate program to demonstrate:

https://ferret-lang.org/#outline-container-sec-3

Source: https://github.com/nakkaya/ferret/blob/master/ferret.org

Tests can be shipped with source code/packaging, so not sure what the advantage is in putting the test code into the binary?