Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

work like doctest for c++? #66

Open
laoshaw opened this issue Jul 4, 2021 · 3 comments
Open

work like doctest for c++? #66

laoshaw opened this issue Jul 4, 2021 · 3 comments

Comments

@laoshaw
Copy link

laoshaw commented Jul 4, 2021

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.

@laoshaw
Copy link
Author

laoshaw commented Jul 4, 2021

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.

@sheredom
Copy link
Owner

sheredom commented Jul 5, 2021

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

@yesudeep
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants