How to work with sections to avoid duplicating code

77 views
Skip to first unread message

Loïc Joly

unread,
Jul 19, 2016, 5:36:30 AM7/19/16
to CATCH
Hello, I would like to have a test structure that looks like the following:

//Test setup
SECTION
("1")
{
 
// Do something
 
// Check some values
}
SECTION
("2")
{
 
// Do something else, that should be equivalent
 
// Perform exactly the same checks as before
}


My issue is that I would like not to repeat the checking code.
I tried to put it in a helper function, but apparently, REQUIRE does not work in helper functions. I moved the checking test after the two SECTIONs, but then, when a test fails, I don't know which path led to the error.

Do you have any idea of how to solve this cleanly?

---
Loïc

Phil Nash

unread,
Jul 21, 2016, 2:22:56 AM7/21/16
to CATCH
What has lead you to believe that "REQUIRE does not work in helper functions". It certainly does and that is how I usually solve the same problem in my code.
So I'm wondering if you're encountering a more specific issue that's preventing it from achieving your goal?

Loïc Joly

unread,
Jul 21, 2016, 5:44:08 PM7/21/16
to CATCH

Le jeudi 21 juillet 2016 08:22:56 UTC+2, Phil Nash a écrit :
What has lead you to believe that "REQUIRE does not work in helper functions". It certainly does and that is how I usually solve the same problem in my code.
So I'm wondering if you're encountering a more specific issue that's preventing it from achieving your goal?

In fact, I tried it, and it failed to compile. But today I tried again, and it worked like a charm. I don't know what I did wrong, and I feel really sorry for having disturbed you...

---
Loïc

Reply all
Reply to author
Forward
0 new messages