• Home
Name Date Size #Lines LOC

..--

.gitignoreD12-May-202421 21

CMakeLists.txtD12-May-20242.1 KiB7064

Makefile.amD12-May-20242.8 KiB8035

Makefile.incD12-May-20244.8 KiB16396

README.mdD12-May-20242.1 KiB6746

curlcheck.hD12-May-20245.3 KiB11274

unit1300.cD12-May-20247.3 KiB22297

unit1301.cD12-May-20241.8 KiB5521

unit1302.cD12-May-20245.8 KiB168117

unit1303.cD12-May-20245.3 KiB15286

unit1304.cD12-May-20248.1 KiB211141

unit1305.cD12-May-20243.4 KiB13789

unit1307.cD12-May-202414.6 KiB324257

unit1308.cD12-May-20243 KiB9648

unit1309.cD12-May-20243.6 KiB14391

unit1323.cD12-May-20241.9 KiB6738

unit1330.cD12-May-20241.2 KiB4213

unit1394.cD12-May-20244.6 KiB132100

unit1395.cD12-May-20242.6 KiB9561

unit1396.cD12-May-20243.2 KiB11678

unit1397.cD12-May-20243 KiB8042

unit1398.cD12-May-20243.1 KiB9142

unit1399.cD12-May-20244.1 KiB11868

unit1600.cD12-May-20242.5 KiB7438

unit1601.cD12-May-20241.7 KiB5723

unit1602.cD12-May-20242.1 KiB7943

unit1603.cD12-May-20245.9 KiB15192

unit1604.cD12-May-202411.4 KiB357312

unit1605.cD12-May-20241.6 KiB5827

unit1606.cD12-May-20242.6 KiB9257

unit1607.cD12-May-20246.5 KiB234169

unit1608.cD12-May-20242.1 KiB7539

unit1609.cD12-May-20246.3 KiB219126

unit1610.cD12-May-20242 KiB6127

unit1611.cD12-May-20241.8 KiB5925

unit1612.cD12-May-20242 KiB6733

unit1620.cD12-May-20242.7 KiB8949

unit1621.cD12-May-20242.5 KiB9259

unit1650.cD12-May-20249.2 KiB296234

unit1651.cD12-May-202425.8 KiB384346

unit1652.cD12-May-20244.3 KiB14079

unit1653.cD12-May-20246 KiB209155

unit1654.cD12-May-20244.2 KiB141103

unit1655.cD12-May-20246.8 KiB191128

unit1660.cD12-May-20245.4 KiB178122

unit1661.cD12-May-20243.2 KiB11450

README.md

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