Live data from Hacker News

Catch: A modern, C++-native, header-only, framework for unit tests

github.com

11–20 of 31 posts

Re: Catch: A modern, C++-native, header-only, framework for unit tests

#11
post #3
post #2

This looks hella good, I particularly am intrigued by the nested setup/teardown system. The natural assert syntax is interesting, too, amazing what macros can accomplish. Appropriately, the first question that came to mind was, "what's the catch?" :)

Yup. I found it interesting after a co-worker pointed it out to me because it looks and works kind of like RSpec. We are currently considering using it for a new project and it seems mature enough to give it a go. I'm currently toying with writing a JSONReporter so we can use that as an additional test result output format and I agree, so far it seems to be a really well done project.

FWIW I've been using Catch for a few years now, and I find it mature enough for real world usage.

Re: Catch: A modern, C++-native, header-only, framework for unit tests

#12
post #2

This looks hella good, I particularly am intrigued by the nested setup/teardown system. The natural assert syntax is interesting, too, amazing what macros can accomplish. Appropriately, the first question that came to mind was, "what's the catch?" :)

The macro trick is at https://github.com/philsquared/Catch/blob/785db43bb2cd64bfe7...: planting the tested expression to the right of an operator ->*, which is overloadable and allows for changing the type of the left hand side in the comparison. The rest is a "simple matter of programming". Clever but probably a bit cute - errors would look weird if the expression isn't set up as expected.

Re: Catch: A modern, C++-native, header-only, framework for unit tests

#13
This looks really good. Do you plan to include BeforeEach and AfterEach? I'll try this out and maybe move my projects to this.

I started working on something similar[1] a few days ago just as a proof of concept.

[1] https://github.com/cEhlen/CUT/blob/master/example.cpp

Re: Catch: A modern, C++-native, header-only, framework for unit tests

#17
post #2

This looks hella good, I particularly am intrigued by the nested setup/teardown system. The natural assert syntax is interesting, too, amazing what macros can accomplish. Appropriately, the first question that came to mind was, "what's the catch?" :)

The macro trick is at https://github.com/philsquared/Catch/blob/785db43bb2cd64bfe7... : planting the tested expression to the right of an operator ->*, which is overloadable and allows for changing the type of the left hand side in the comparison. The rest is a "simple matter of programming". Clever but probably a bit cute - errors would look weird if the expression isn't set up as expected.

Also uses template to overload operator ->*

https://github.com/philsquared/Catch/blob/785db43bb2cd64bfe7...

Re: Catch: A modern, C++-native, header-only, framework for unit tests

#18

Great work. I love the fact that this encourages writing tests that are readable/documenting. Definitely gonna give this a try. Any recommended test runner to go with it?

There's a test runner included as a macro that defines main

Re: Catch: A modern, C++-native, header-only, framework for unit tests

#19
post #11
post #3

Earlier quoted context omitted.

Yup. I found it interesting after a co-worker pointed it out to me because it looks and works kind of like RSpec. We are currently considering using it for a new project and it seems mature enough to give it a go. I'm currently toying with writing a JSONReporter so we can use that as an additional test result output format and I agree, so far it seems to be a really well done project.

FWIW I've been using Catch for a few years now, and I find it mature enough for real world usage.

Good to know, thanks!
Post reply on HN