Changeset 134ac5d in mainline for uspace/lib/pcut/README.rst


Ignore:
Timestamp:
2014-06-06T07:54:24Z (11 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8db09e4
Parents:
eeb23f2d
Message:

Update PCUT to newest version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/pcut/README.rst

    reeb23f2d r134ac5d  
    2222safe against unexpected crashes, such as null pointer dereference.
    2323
    24 More details can be found on PCUT wiki on GitHub.
    25 
    26                                         https://github.com/vhotspur/pcut/wiki
     24More details can be found on PCUT wiki on GitHub:
     25https://github.com/vhotspur/pcut/wiki
    2726
    2827
    29 Main goal - simple to use
    30 -------------------------
     28Quick-start example
     29-------------------
    3130
    32 Let's illustrate how PCUT aims to be simple when creating unit tests for
    33 function ``intmin`` that ought to return smaller of its two arguments.::
     31The following code tests the standard ``atoi`` function::
    3432
    35         int intmin(int a, int b) {
    36                 return a > b ? b : a;
     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"));
    3740        }
    3841       
    39 Individual test-cases for such method could cover following cases: getting
    40 minimal 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 
    48 In 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) );
     42        PCUT_TEST(atoi_positive) {
     43            PCUT_ASSERT_INT_EQUALS(42, atoi("42"));
    6144        }
    6245       
    63         PCUT_TEST(positive_and_negative) {
    64                 PCUT_ASSERT_INT_EQUALS(-5, intmin(-5, 71) );
    65                 PCUT_ASSERT_INT_EQUALS(-17, intmin(423, -17) );
     46        PCUT_TEST(atoi_negative) {
     47            PCUT_ASSERT_INT_EQUALS(-273, atoi("-273"));
    6648        }
    6749       
    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 
    7850        PCUT_MAIN()
    7951
    80 And that's all.
    81 You do not need to manually specify which tests to run etc.,
    82 everything is done magically via the ``PCUT_INIT``, ``PCUT_MAIN`` and
    83 ``PCUT_TEST`` macros.
    84 All you need to do is to compile this code and link it with ``libpcut``.
    85 Result of the linking would be an executable that runs the tests and
    86 reports the results.
     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.
    8755
    88 
    89 Examples
    90 --------
     56This code has to be linked with ``libpcut`` to get an executable that runs
     57the tests and reports the results.
    9158
    9259More examples, in the form of self-tests, are available in the ``tests/``
    9360subdirectory.
     61Other examples can be found on the Wiki.
    9462
    9563
Note: See TracChangeset for help on using the changeset viewer.