These are chat archives for Snaipe/Criterion

17th
Mar 2017
Jakob Klepp
@truh
Mar 17 2017 09:35
Currently planning for my first bigger C project for college and considering to do some unit testing (it's not required but it seems like a good idea in a team project). Problem is I have not the slightest clue how to make it work with CMake. Could someone point towards a simple project written in C or C++ that uses CMake as a build system and Criterion for testing? Thanks.
Franklin Mathieu
@Snaipe
Mar 17 2017 09:37
I don't have one at the top of my head, but let me write a quick one
Jakob Klepp
@truh
Mar 17 2017 10:42
Do you have to basically configure a second executable with add_executable?
Franklin Mathieu
@Snaipe
Mar 17 2017 10:43
Well, you have to add a new executable for the tests, and then call add_test on it
Jakob Klepp
@truh
Mar 17 2017 10:43
Where the second executable doesn't contain your normal main function but instead the test suite?
Franklin Mathieu
@Snaipe
Mar 17 2017 10:44
pretty much, although you have to be careful about what you include in the second executable
a cleaner way would be to put your "common" sources in a static/shared lib, and then link that library to your main executable & your tests
if you want to only deal with two executable, you'll have to build your sources twice (once for your main executable, and the other for the tests)
which is going to take some more time
Jakob Klepp
@truh
Mar 17 2017 10:47
Does CMake compile stuff twice if it is used by two executables?
Franklin Mathieu
@Snaipe
Mar 17 2017 10:47
if you build your executables with the same sources, it probably will
although it could be smart and decide the object files are the same, provided you build both executables in the same directory
Jakob Klepp
@truh
Mar 17 2017 10:50
Is it just me or is cmake.org down?
Franklin Mathieu
@Snaipe
Mar 17 2017 10:51
seems to ping, but take a long time to load a page
Jakob Klepp
@truh
Mar 17 2017 10:52
I get a redirect on http and no response on https.
Franklin Mathieu
@Snaipe
Mar 17 2017 11:00
@truh here's a small cmake skeleton with a static lib and some tests: https://github.com/Snaipe/Criterion/tree/bleeding/dev/cmake
Jakob Klepp
@truh
Mar 17 2017 11:03
Is there a test runner (main function) inside the criterion lib?
Franklin Mathieu
@Snaipe
Mar 17 2017 11:03
Yep
Jakob Klepp
@truh
Mar 17 2017 11:03
Thank you a lot for your help.
Franklin Mathieu
@Snaipe
Mar 17 2017 11:04
You're welcome! Don't hesitate to ask if you need more help.