Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tree: b238874a0d
Fetching contributors…

Cannot retrieve contributors at this time

74 lines (55 sloc) 2.166 kB

CT

(Relatively) Easy Unit Testing for C

How to use

  1. Copy subdirectory ct into your project.
  2. Add some rules to your makefile. See Makefile for an example.
  3. Write some tests. See msg-test.c for an example. Test function names begin with "cttest".
  4. Run make check

Behavior

  • The test runner runs each test in a separate process, so global state from one test will not affect another.
  • Each test is run in a new process group; all processes in the group will be killed after the test finishes. This means your test can fork without having to worry about cleaning up its descendants.
  • CT participates in GNU make's jobserver protocol. If you put a + in front of the _ctcheck command (as in the sample makefile) and run make with its -jN flag, for example make -j16 check, CT will run tests concurrently (and hopefully in parallel).

Terminal Output

Running make check in the example supplied looks like this:

~/Projects/ct[master]: make -j4 check
cc -Werror -Wall   -c -o msg-test.o msg-test.c
ct/gen msg-test.o > ct/_ctcheck.c.part
mv ct/_ctcheck.c.part ct/_ctcheck.c
cc -Werror -Wall   -c -o ct/_ctcheck.o ct/_ctcheck.c
cc -Werror -Wall   -c -o ct/ct.o ct/ct.c
cc -Werror -Wall   -c -o msg.o msg.c
cc   ct/_ctcheck.o ct/ct.o msg.o msg-test.o   -o ct/_ctcheck
ct/_ctcheck
E..FEF

cttestexit: error (exit status 2)

cttestfailure: failure
msg-test.c:30: test: 1 == 2

cttestfmt: failure
msg-test.c:37: test: n == 2
msg-test.c:37: n is 1

cttestsegfault: error (signal 11)

2 failures; 2 errors.
make: *** [check] Error 1

Releases

There will be no releases of this tool. Just clone the latest source from git and copy it into your project. If you want to update, copy the newer source into your project.

History

Inspired by CUT 2.1 by Sam Falvo and Billy Tanksley. Also with ideas from the Go testing package and gotest.

Jump to Line
Something went wrong with that request. Please try again.