source: mainline/uspace/lib/pcut/README.rst@ f77c1c9

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since f77c1c9 was 8db09e4, checked in by Vojtech Horky <vojtechhorky@…>, 11 years ago

Update PCUT to newest version

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