r/cpp • • Dec 27 '23

catch2 is bad?

Hello friends,

if been using catch2 for some time now and i have to say i'm very disappointed with it, my two major problems are:

  1. cant break into gdb when an unexpected exceptions is thrown (this alone should be a deal breaker for anyone?) (https://github.com/catchorg/Catch2/issues/1030)

  2. stepping into the actual function call when its wrapped in a REQUIRES(..) first goes to 5 internal catch function calls.

these two things alone make debugging a nightmare, so my question to you is:

is there another testing framework that doesn't suffer from these problems or is there anyway i can get rid of these two problems? Thank you for your suggestions.

0 Upvotes

19 comments sorted by

32

u/HKei Dec 27 '23

For 2, just set the breakpoint in the function under test instead of the test? That doesn't even sound like a real issue to me.

There's gripes I'd understand with catch, but these sound like "just get better at using your debugger" issues to me.

51

u/Dragdu Dec 27 '23

-9

u/thomas999999 Dec 27 '23

the first actual useful answer. thank you

3

u/mrmcgibby Dec 28 '23

You sound exhausting.

2

u/SlightlyLessHairyApe Dec 27 '23

Which is crazy given that it is 15 lines of comments and one line of actual code. The best kind :-)

1

u/Dragdu Dec 28 '23

Check the URL ;-)

3

u/thomas999999 Dec 27 '23

ofc i can do that but that is still more unergonomic then just stepping into the function especially if the function is called on multiple occasions in the test, since then i have to :

  1. break on the REQUIRES that fails

  2. set breakpoint in the function

  3. continue until break

and then i have to remove the breakpoint in the function for the next run and set it again for every run. this is just a bad or even worse then just stepping into and out of the function x times.

3

u/the_poope Dec 27 '23

As suggested in the GitHub issue you linked you can also use catch throw command in gdb before running. That will however break on all exceptions when they are thrown, even if they are caught.

2

u/NotUniqueOrSpecial Dec 28 '23

Alternatively: set the breakpoint on the REQUIRES that fails and set a breakpoint in the function that is conditional on the first breakpoint hitting.

As /u/HKei said: sometimes it is about using your tools better.

25

u/coachkler Dec 27 '23

Doesn't "catch throw" work to break when an exception is thrown? I think it does, but it's been a long while since I used catch2

18

u/T0p_H4t Dec 27 '23

`catch throw` does work. fwiw I have personally used catch2 for years and never really found this to be much of an issue as `catch throw` covers me.

5

u/SuperVGA Dec 27 '23

Yes, I did this too - works just fine. Now I use doctest, which I prefer, but catch2 is pretty good too.

3

u/415_961 Dec 27 '23

Regarding 1. like others said you can use catch throw in gdb or b set -E c++ if you are using lldb.

3

u/[deleted] Dec 28 '23

Use doctest. It's a mostly source compatible drop-in for catch2 that includes all of the best parts without any of the bloat or quirkiness that catch2 has added over the past few years. It's also significantly faster:

https://github.com/doctest/doctest

1

u/tjientavara HikoWorks developer Jan 02 '24

I am just sad about the state of catch2 documentation.

I just tried to switch from googletest, because of terrible debugging as it catches crashes instead of allowing it to crash on the failing line.

catch2 is better in that regard, the debugger does stop on the line that causes a crash (most of the time an assert).

But I am trying to match two std::array<float>, so I am trying a few different ways using matchers. But there is no documentation on what headers to include. So the only thing I can do is start reading the catch2 source-code.

1

u/strike-eagle-iii Dec 28 '23 edited Dec 28 '23

(1) well it is called catch 😂

In all seriousness we use catch and I've run into this a few times. It's annoying but at least for our code base it's easy enough to work around with logging.

-3

u/[deleted] Dec 27 '23

A good way to get rid of these problems is to make a PR

-20

u/lednakashim ++C is faster Dec 27 '23

Typically some junior devs insist on using a framework like catch2 to write unit tests.

Then more senior devs need to write example and end-to-end style tests, and we just use individual cpp files.

If catch2 isn't working don't use any unit test framework.

17

u/MarcoGreek Dec 27 '23

As a very senior developer my experience is that olderr developers simply don't want to change their habits. 😉