Repository navigation
headers,test: guard Test/TestSuite placeholders so include order is irrelevant - #608
simonyang08 wants to merge 1 commit into
Conversation
…rrelevant When <criterion/parameterized.h> is included before <criterion/criterion.h>, internal/parameterized.h pulls in internal/test.h which already defines Test and TestSuite with their real expansions. The subsequent include of criterion.h then unconditionally redefined Test and TestSuite to the placeholder token 'internal', because the trailing '#include "internal/test.h"' in criterion.h was a no-op thanks to its include guard. As a result TestSuite(...) expanded to the bare token 'internal', producing a cryptic compile error far from the actual cause. Wrap the placeholder definitions in criterion.h with '#ifndef Test' / '#ifndef TestSuite' so they only apply when the real definition has not yet been seen. A new samples/include-order.c sample exercises the reversed include order to lock in the fix. Fixes Snaipe#573 Signed-off-by: simonyang08 <ppt5928@gmail.com>
|
Thanks! The macros ifdefed out in this PR help all kinds of tools to show a simplified signature for the Criterion primitives (for example, IDE hints). I'm not entirely sure it's worth fixing this issue as it is documented that Let me know if you disagree or you have a better idea. |
|
Thanks for the review! I believe both concerns can coexist: with the So the IDE-hint purpose is preserved, and the header just stops producing a confusing error when the include order differs. That said, if you'd rather keep the header order-sensitive and close this as works-as-documented, I'm fine with that too — your call. |
Summary
Fixes #573.
When a translation unit includes
<criterion/parameterized.h>before<criterion/criterion.h>,internal/parameterized.htransitively pulls ininternal/test.h, which provides the real definitions ofTest(...)andTestSuite(...). The subsequent include ofcriterion.hthen unconditionally redefines both macros to the placeholder tokeninternal, because the trailing#include "internal/test.h"incriterion.his a no-op thanks to its include guard. As a resultTestSuite(suite);expands to the bare tokeninternal ;, producing the cryptic error described in the issue:Fix
Wrap the placeholder definitions in
include/criterion/criterion.hwith#ifndef Test/#ifndef TestSuite. The placeholder is now only applied when no real definition has been seen yet (i.e. whencriterion.his included in isolation). Whenparameterized.hhas already supplied the real macros, the placeholders are skipped and the guardedinternal/test.hinclude leaves the real definitions intact.Why
Theory(...)is intentionally left alone: the same placeholder pattern exists intheories.h, butinternal/theories.his the only place that#undefs and re-definesTheory, and it is reachable only throughtheories.hitself (which always defines the placeholder first) — unlikeinternal/test.h, which is reachable directly frominternal/parameterized.h. So the include-order defect cannot occur forTheory. Happy to sweep it in a follow-up if maintainers prefer consistency.Regression test
New
samples/include-order.cincludesparameterized.hfirst andcriterion.hsecond, then defines aTestSuiteand aTest, exercising the broken expansion path at compile time. Registered insamples/meson.buildand runs as part ofmeson test(like the other samples it uses--always-succeed, so it acts as a compile-time regression guard).Verification
meson compilefails on the new sample with exactly the issue'sexpected '=', ',', ';', 'asm' or '__attribute__' before '{' tokenerror.meson test49/49 OK including the new sample; both include orders compile and run.uncrustify -c .uncrustify.cfgclean on changed files.3 files, +15/-2.