[01579ad] | 1 | PCUT: Plain C Unit Testing mini-framework
|
---|
| 2 | =========================================
|
---|
| 3 |
|
---|
| 4 | PCUT is a very simple framework for unit testing of C code.
|
---|
| 5 | Unlike many other frameworks where you need to specify manually which
|
---|
| 6 | functions belong to a particular test, PCUT provides several smart
|
---|
| 7 | macros that hides this and lets you focus on the most important
|
---|
| 8 | part of testing only: that is, coding the test cases.
|
---|
| 9 |
|
---|
| 10 | This mini-framework is definitely not complete but it offers the basic
|
---|
| 11 | functionality needed for writing unit tests.
|
---|
| 12 | This includes the possibility to group tests into test suites, optionally
|
---|
| 13 | having set-up and tear-down functions.
|
---|
| 14 | There are several assert macros for evaluating the results, their highlight
|
---|
| 15 | is very detailed information about the problem.
|
---|
| 16 |
|
---|
| 17 | The output of the test can come in two forms: either as an XML output suited
|
---|
| 18 | for later processing or in the form of Test-Anything-Protocol.
|
---|
| 19 | PCUT is able to capture standard output and display it together with test
|
---|
| 20 | results.
|
---|
| 21 | And by running each test in a separate process, the whole framework is pretty
|
---|
| 22 | safe against unexpected crashes, such as null pointer dereference.
|
---|
| 23 |
|
---|
[134ac5d] | 24 | More details can be found on PCUT wiki on GitHub:
|
---|
| 25 | https://github.com/vhotspur/pcut/wiki
|
---|
[01579ad] | 26 |
|
---|
| 27 |
|
---|
[134ac5d] | 28 | Quick-start example
|
---|
| 29 | -------------------
|
---|
[01579ad] | 30 |
|
---|
[134ac5d] | 31 | The following code tests the standard ``atoi`` function::
|
---|
[01579ad] | 32 |
|
---|
[134ac5d] | 33 | #include <pcut/pcut.h>
|
---|
| 34 | #include <stdlib.h>
|
---|
[f1380b7] | 35 |
|
---|
[01579ad] | 36 | PCUT_INIT
|
---|
[f1380b7] | 37 |
|
---|
[134ac5d] | 38 | PCUT_TEST(atoi_zero) {
|
---|
| 39 | PCUT_ASSERT_INT_EQUALS(0, atoi("0"));
|
---|
[01579ad] | 40 | }
|
---|
[f1380b7] | 41 |
|
---|
[134ac5d] | 42 | PCUT_TEST(atoi_positive) {
|
---|
| 43 | PCUT_ASSERT_INT_EQUALS(42, atoi("42"));
|
---|
[01579ad] | 44 | }
|
---|
[f1380b7] | 45 |
|
---|
[134ac5d] | 46 | PCUT_TEST(atoi_negative) {
|
---|
| 47 | PCUT_ASSERT_INT_EQUALS(-273, atoi("-273"));
|
---|
[01579ad] | 48 | }
|
---|
[f1380b7] | 49 |
|
---|
[01579ad] | 50 | PCUT_MAIN()
|
---|
| 51 |
|
---|
[134ac5d] | 52 | As you can see, there is no manual listing of tests that form the test
|
---|
| 53 | suite etc, only the tests and ``PCUT_INIT`` at the beginning and
|
---|
| 54 | ``PCUT_MAIN`` at the end.
|
---|
[01579ad] | 55 |
|
---|
[134ac5d] | 56 | This code has to be linked with ``libpcut`` to get an executable that runs
|
---|
| 57 | the tests and reports the results.
|
---|
[01579ad] | 58 |
|
---|
| 59 | More examples, in the form of self-tests, are available in the ``tests/``
|
---|
| 60 | subdirectory.
|
---|
[134ac5d] | 61 | Other examples can be found on the Wiki.
|
---|
[01579ad] | 62 |
|
---|
| 63 |
|
---|
| 64 | Building and installing
|
---|
| 65 | -----------------------
|
---|
| 66 |
|
---|
[8db09e4] | 67 | PCUT uses CMake (http://www.cmake.org/).
|
---|
| 68 | On Unix systems, following commands build the library and execute the
|
---|
| 69 | built-in tests::
|
---|
| 70 |
|
---|
| 71 | mkdir build
|
---|
| 72 | cd build
|
---|
| 73 | cmake .. && make all test
|
---|
[01579ad] | 74 |
|
---|
| 75 | More details can be found on https://github.com/vhotspur/pcut/wiki/Building.
|
---|