After having learnt way too much of the C family shennanigans, I don't think a test framework can comprehend all the possible hacks and must make assumptions about the context enforced via (user) macros. C trades a very weak formal model for a huge class of semantics code may have (via macros).
Experiments with C, testing and abi.
Minimal, simple, fast and composable testing framework.
wip.
Goals:
- Tooling(Examples): User configurable. Most common things. (Compiler flags, Diagnostics, Valgrind)
- Portability: Types and behavior can be checked for all targets.
- Clarity and explicity: User provides compiler flags from examples.
- Minimal dependencies: No unnecessary things.
- Follow standards, if good practice and dont, if not good practice.
- Test framework must work with
-Weverything
and all common tools.
Nongoals:
- Hack around compiler problems.
- Silence any warnings.
- For near future: Floating point checks.
Assumptions:
- Integers have 2s complement.
- Little endian.
- false == 0, true == 1, ie (0 != 0) => 0, (0 == 0) => 1.
- User writes necessary defines and checks for types from examples
- C standard does not maintain an architecture list with types + sizes
- Assumptions of code how to deal with implemention defined behavior must be done by author
- string.h uses char, which may be signed or unsigned
- C integer data types are only defined by their minimum size
- C float data types are completely unspecified
- Machine accuracy could be relevant (IEEE float or SIMD without assumptions)
Assertions:
- 1 Byte represents 8 Bit.
- char has 1 Byte size.
- User or platform provided limits.h types have correct size and signedness (if specified).
typedefs
- can not be introspected, ie via macros
- are less annoying for multiline types (no \ before end of line necessary)
- prevent logic errors, ie for long MACRO => long
long int
- conclusion
- use macros, if you want simple reflection from external code
- this can be often useful in headers
- otherwise, especially for scoped symbols (in source files), use typedefs, if possible