Example project showing a simple test harness for small projects in C http://akkartik.name/post/four-repos
Kartik Agaram 71474f7cd3 license | il y a 2 ans | |
---|---|---|
LICENSE.txt | il y a 2 ans | |
README.md | il y a 5 ans | |
build | il y a 5 ans | |
clean | il y a 5 ans | |
makefile | il y a 5 ans | |
test.c | il y a 6 ans | |
test.h | il y a 6 ans | |
x.c | il y a 6 ans |
Example project showing a simple test harness for small projects in C.
Call run_tests()
through main somehow, after doing your own argument
parsing.
Call run_single_test()
through main somehow, based on your argument
parsing.
Put 'setup' code you want to run before each test into a function called
reset()
.
Write each test in a function whose first line has the rigid form:
void test_...(void) {
The entire prototype must fit on a single line, with the opening curly brace 'cuddled' on the same line. (This form allows us to easily autogenerate prototypes for functions, so that you can define your functions and tests in any order in any .c file.)
Read test.h for more details.
First build the project, using either (preferred):
./build
or (more conventional):
make
Then try running tests.
$ ./a.out # run some example tests
.. # emits one dot per passing test
$ ./a.out test_2 # run a single test
. # single dot for single test