source: mainline/uspace/lib/pcut/README.rst@ 01579ad

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

Start work on PCUT integration

PCUT is a simple library for (hopefully) easier unit testing.
See https://github.com/vhotspur/pcut for more details.

  • Property mode set to 100644
File size: 3.1 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.
25
26 https://github.com/vhotspur/pcut/wiki
27
28
29Main goal - simple to use
30-------------------------
31
32Let's illustrate how PCUT aims to be simple when creating unit tests for
33function ``intmin`` that ought to return smaller of its two arguments.::
34
35 int intmin(int a, int b) {
36 return a > b ? b : a;
37 }
38
39Individual test-cases for such method could cover following cases: getting
40minimal of
41
42- two same numbers
43- negative and positive number
44- two negative numbers
45- two positive numbers
46- "corner case" numbers, such as minimal and maximal represented number
47
48In PCUT, that would be translated to the following code:::
49
50 #include <pcut/test.h>
51 #include <limits.h>
52 /* Other include to have declaration of intmin */
53
54 PCUT_INIT
55
56 PCUT_TEST_SUITE(intmin_tests);
57
58 PCUT_TEST(same_number) {
59 PCUT_ASSERT_INT_EQUALS(719, intmin(719, 719) );
60 PCUT_ASSERT_INT_EQUALS(-4589, intmin(-4589, -4589) );
61 }
62
63 PCUT_TEST(positive_and_negative) {
64 PCUT_ASSERT_INT_EQUALS(-5, intmin(-5, 71) );
65 PCUT_ASSERT_INT_EQUALS(-17, intmin(423, -17) );
66 }
67
68 PCUT_TEST(same_sign) {
69 PCUT_ASSERT_INT_EQUALS(22, intmin(129, 22) );
70 PCUT_ASSERT_INT_EQUALS(-37, intmin(-37, -1) );
71 }
72
73 PCUT_TEST(corner_cases) {
74 PCUT_ASSERT_INT_EQUALS(INT_MIN, intmin(INT_MIN, -1234) );
75 PCUT_ASSERT_INT_EQUALS(9876, intmin(9876, INT_MAX) );
76 }
77
78 PCUT_MAIN()
79
80And that's all.
81You do not need to manually specify which tests to run etc.,
82everything is done magically via the ``PCUT_INIT``, ``PCUT_MAIN`` and
83``PCUT_TEST`` macros.
84All you need to do is to compile this code and link it with ``libpcut``.
85Result of the linking would be an executable that runs the tests and
86reports the results.
87
88
89Examples
90--------
91
92More examples, in the form of self-tests, are available in the ``tests/``
93subdirectory.
94
95
96Building and installing
97-----------------------
98
99On Unix systems, running ``make`` and ``make install`` shall do the job.
100
101More details can be found on https://github.com/vhotspur/pcut/wiki/Building.
Note: See TracBrowser for help on using the repository browser.