silentbicycle / greatest

A C testing library in 1 file. No dependencies, no dynamic allocation. ISC licensed.
ISC License
1.48k stars 108 forks source link

Parametric suites #60

Open silentbicycle opened 7 years ago

silentbicycle commented 7 years ago

There should be RUN_SUITE1/RUN_SUITEp macros for suites that take argument(s), such as a random number seed, verbosity setting, or iteration limit.

Because the existing syntax for defining/calling suites is SUITE(suitename), this will be a breaking API change.

/* previous style */
SUITE(suite);

/* new style */
SUITE suite(void);
SUITE suite1(void *some_arg);
SUITE suite_multi(size_t apple, void *banana, int carrot);

SUITE suite(void) {}

RUN_SUITE(suite);   /* no change */

RUN_SUITE1(suite1, arg);  /* suite with 1 argument */

/* suite with multiple arguments (C99 and later standards only) */
RUN_SUITEp(suite_multi, 1, NULL, 2);
tekknolagi commented 4 years ago

Would this pass the argument to a suite? Is it possible to have something like this that passes the arguments to every test? I am thinking of a setup/teardown configuration for every test in a suite.

silentbicycle commented 4 years ago

It would pass an argument to the suite, which could pass it to any test(s) that need it. You can already pass arguments to tests, and there are already setup/teardown hooks, which once set will be called around all the following tests in the suite.

Functionally, it's not a complicated change, but it will be a breaking change to a long-stable interface, so I want to be very thoughtful of the new interface and wait until a new major release to merge it.