README
1Unit tests
2==========
3
4The goal is to add tests for *ALL* functions in libcurl. If functions are too
5big and complicated, we should split them into smaller and testable ones.
6
7Build Unit Tests
8================
9
10'./configure --enable-debug' is required for the unit tests to build. To
11enable unit tests, there will be a separate static libcurl built that will be
12used exclusively for linking unit test programs. Just build everything as
13normal, and then you can run the unit test cases as well.
14
15Run Unit Tests
16==============
17
18Unit tests are run as part of the regular test suite. If you have built
19everything to run unit tests, to can do 'make test' at the root level. Or you
20can 'cd tests' and 'make' and then invoke individual unit tests with
21./runtests.pl NNNN where NNNN is the specific test number.
22
23Debug Unit Tests
24================
25
26If a specific test fails you will get told. The test case then has output left
27in the log/ subdirectory, but most importantly you can re-run the test again
28using gdb by doing ./runtests.pl -g NNNN. That is, add a -g to make it start
29up gdb and run the same case using that.
30
31Write Unit Tests
32================
33
34We put tests that focus on an area or a specific function into a single C
35source file. The source file should be named 'unitNNNN.c' where NNNN is a
36number that starts with 1300 and you can pick the next free number.
37
38Add your test to tests/unit/Makefile.inc (if it is a unit test).
39Add your test data to tests/data/Makefile.inc
40
41You also need a separate file called tests/data/testNNNN (using the same
42number) that describes your test case. See the test1300 file for inspiration
43and the tests/FILEFORMAT documentation.
44
45For the actual C file, here's a very simple example:
46
47----------------------- start -------------------------------
48#include "curlcheck.h"
49
50#include "a libcurl header.h" /* from the lib dir */
51
52static CURLcode unit_setup( void )
53{
54 /* whatever you want done first */
55 return CURLE_OK;
56}
57
58static void unit_stop( void )
59{
60 /* done before shutting down and exiting */
61}
62
63UNITTEST_START
64
65 /* here you start doing things and checking that the results are good */
66
67 fail_unless( size == 0 , "initial size should be zero" );
68 fail_if( head == NULL , "head should not be initiated to NULL" );
69
70 /* you end the test code like this: */
71
72UNITTEST_STOP
73
74----------------------- end -------------------------------
75