Re: [RFC PATCH 1/2] Add C TAP harness

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jun 26, 2023 at 02:15:39PM +0100, Phillip Wood wrote:
On 21/06/2023 16:57, Linus Arver wrote:
- Make the 'TEST' macro accept the test description first. Or, keep the
   'TEST' macro but also name a new macro 'IT' that accepts the
   description first, to encourage usage that reads in a
   behavior-driven-development (BDD) style, like 'IT("should accept foo",
   t_bar(...))'. I find some test descriptions easier to write this way.

The test description is a printf style format string followed by arguments. This allows parameterized tests to include the parameter values in the description to aid debugging but it means the test function must be the first parameter. We could have IT("should accept %d", t(), i) but that would be a bit weird.

with some minor preprocessor magic [1], you could make that

  IT(("should accept %d", i), t(i))

which would be somewhat more noisy, but arguably even somewhat clearer.
notably,

  IT("should accept foo", t())

would still work with the same macro.

[1] https://stackoverflow.com/a/62984543/3685191

somewhat on a tangent: it's also possible to overload macros on argument count [2], which may also come in handy.

[2] https://stackoverflow.com/a/24028231/3685191

regards,
ossi



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux