• Home
Name Date Size #Lines LOC

..--

.gitignoreD03-May-2024119 64

CMakeLists.txtD03-May-20242.2 KiB5147

Makefile.amD03-May-20244.4 KiB15871

Makefile.incD03-May-20241.6 KiB4314

README.mdD03-May-20242.3 KiB7446

curlcheck.hD03-May-20245.4 KiB11474

unit1300.cD03-May-20247.3 KiB22497

unit1302.cD03-May-20246.6 KiB192134

unit1303.cD03-May-20245.4 KiB15486

unit1304.cD03-May-20246.9 KiB196124

unit1305.cD03-May-20243.4 KiB13383

unit1307.cD03-May-202414.6 KiB322254

unit1308.cD03-May-20243.1 KiB9949

unit1309.cD03-May-20243.6 KiB14591

unit1323.cD03-May-20241.9 KiB6938

unit1330.cD03-May-20241.2 KiB4413

unit1394.cD03-May-20244.6 KiB134100

unit1395.cD03-May-20243 KiB10669

unit1396.cD03-May-20243.2 KiB11878

unit1397.cD03-May-20243.9 KiB9555

unit1398.cD03-May-20243.3 KiB9744

unit1399.cD03-May-20244.1 KiB12068

unit1600.cD03-May-20242.5 KiB7638

unit1601.cD03-May-20241.8 KiB5923

unit1602.cD03-May-20242.2 KiB8244

unit1603.cD03-May-20245.9 KiB15493

unit1604.cD03-May-202411.4 KiB359312

unit1605.cD03-May-20241.7 KiB6027

unit1606.cD03-May-20242.6 KiB9457

unit1607.cD03-May-20246.5 KiB236169

unit1608.cD03-May-20242.1 KiB7739

unit1609.cD03-May-20246.3 KiB221126

unit1610.cD03-May-20242.1 KiB6530

unit1611.cD03-May-20241.8 KiB6125

unit1612.cD03-May-20242.1 KiB6933

unit1614.cD03-May-20246.3 KiB165134

unit1620.cD03-May-20242.8 KiB9452

unit1621.cD03-May-20242.5 KiB9156

unit1650.cD03-May-20249.2 KiB298234

unit1651.cD03-May-202426.1 KiB394352

unit1652.cD03-May-20244.4 KiB14279

unit1653.cD03-May-20246.6 KiB233175

unit1654.cD03-May-20243.8 KiB11474

unit1655.cD03-May-20246.8 KiB193128

unit1660.cD03-May-20245.4 KiB180122

unit1661.cD03-May-20243.2 KiB11650

unit2600.cD03-May-202412.5 KiB414313

unit3200.cD03-May-20244.7 KiB165115

README.md

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