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

C++ unit test framework with Catch #1019

Merged
merged 12 commits into from
Sep 7, 2015

Conversation

dcoeurjo
Copy link
Member

@dcoeurjo dcoeurjo commented Jun 9, 2015

Enables catch unit test system (https://github.com/philsquared/Catch) in DGtal.
The idea is to simplify unit test design in DGtal with a "single-header" but complete framework.

For instance, a REQUIRE( a == b); in a test case section checks that a equals b. If the test fails, the values of a and b are traced out with neat messages.

Basically it would replace what we usually do:

 trace.info() << "Checking if "<<a<< " equals "<<b<<std::endl;
 nbok += (a == b) ? 1 : 0; 
 nb++;
 trace.info() << "(" << nbok << "/" << nb << ") "
               << "(a == b) returns true" << std::endl;

Catch also allows test case filtering and timing...

Please have a look to testPointVector-catch.cpp which is a catch version of testPointVector.cpp

@dcoeurjo dcoeurjo added this to the 0.9 milestone Jun 9, 2015
@dcoeurjo
Copy link
Member Author

dcoeurjo commented Jun 9, 2015

BTW, rewriting the point vector unit test allows me to detect an issue in PointVector::getNormalized() 😄

:octocat:

@dcoeurjo
Copy link
Member Author

dcoeurjo commented Jun 9, 2015

Run testPointVector-catch -h to get the (automatic) command line arguments.
E.g.
testPointVector-catch -s -d shows you the successful tests with timings


/**
* Description of test_trace' <p>
* Aim: simple test of \ref MeasureOfStraighLines

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess you mean "catch functionnalities" here.

@dcoeurjo
Copy link
Member Author

thx. done.

@JacquesOlivierLachaud
Copy link
Member

Sinon, dans catch, ils spécifient qu'il faut mettre le #define and
#include catch que dans un seul fichier, puis mettre les tests dans
d'autres fichiers. cf
https://github.com/philsquared/Catch/blob/master/docs/slow-compiles.md

On fait comme ça, où on remettra #define et #include catch dans chacun
des tests à venir ?

Le 28/08/2015 14:30, David Coeurjolly a écrit :

thx. done.


Reply to this email directly or view it on GitHub
#1019 (comment).

@dcoeurjo
Copy link
Member Author

We could easily create a DGtalCatch.hwith the #define and #include "catch.h" and force all catch-enabled test in the template to include this file. I'll try this.

@dcoeurjo
Copy link
Member Author

dcoeurjo commented Sep 1, 2015

Done.

@JacquesOlivierLachaud
Copy link
Member

According to the pointed doc, it seems the define main+include sould be in one source code only, not a header. Then, we only do the include at other places. Have I misunderstood something ?

@dcoeurjo
Copy link
Member Author

dcoeurjo commented Sep 1, 2015

Yes but we don't want to collect all unit tests into a unique executable...

@dcoeurjo
Copy link
Member Author

dcoeurjo commented Sep 1, 2015

I don't see any better solution..

@JacquesOlivierLachaud
Copy link
Member

I was just wondering if the catch source should be compiled within DGtal library (then we can still split tests). The problem is that we don't want to add sources to the library (in fact, we would like to get rid of all cpp, no ?). Perhaps it would be better to have a DGtalTest library. What do you think ?

@dcoeurjo
Copy link
Member Author

dcoeurjo commented Sep 7, 2015

The problem is more related to the magical #define CATCH_CONFIG_MAIN it has to be placed before the #include "catch.hpp" and generates a single main.

Unless we want to gather all unit tests into a single exe (and using the filter features to focus on the API we want to test), I think there is nothing we can do (beside the #pragma thing that could speed up the build on modern compilers).

@JacquesOlivierLachaud
Copy link
Member

Ok. We just have to watch the compilation time when there will be many "catchy" tests.
I merge.

JacquesOlivierLachaud added a commit that referenced this pull request Sep 7, 2015
C++ unit test framework with Catch
@JacquesOlivierLachaud JacquesOlivierLachaud merged commit f504b24 into DGtal-team:master Sep 7, 2015
@dcoeurjo dcoeurjo modified the milestones: 0.9, 0.9.2 Jan 24, 2016
@dcoeurjo dcoeurjo deleted the catch branch October 7, 2021 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants