-
Notifications
You must be signed in to change notification settings - Fork 2
Home
PCUT is a very simple library (framework) for unit testing of C code. PCUT itself is written in plain C and the main target when writing the library was easiness of use.
Briefly, the library provides the test running/evaluating framework and macros to simplify writing the tests: basically just functions with asserts. Following functionality is available:
- grouping tests into test-suites
- set-up and tear-down functions for the whole suite
- assert-like functions for comparing common types with detailed messages
- Test-Anything-Protocol output
- standard output capturing
- pretty safe against crashing tests (such as null pointer dereference)
The library is developed on Linux but it shall run in any decent environment with standard C library. Running under Windows was tested through MinGW only.
Short example follows, if you want to learn more, following pages might help you.
- Few notes how to build PCUT
- Short tutorial to help you start using PCUT
- Available assert macros for the tests
- Creating test-suites
- Splitting the tests into more files
- Testing PCUT: description of tests provided with the framework
Below is complete source code for a test checking (lamely) the function atoi()
.
#include <pcut/pcut.h>
#include <stdlib.h>
PCUT_INIT
PCUT_TEST(atoi_zero) {
PCUT_ASSERT_INT_EQUALS(0, atoi("0"));
}
PCUT_TEST(atoi_positive) {
PCUT_ASSERT_INT_EQUALS(42, atoi("42"));
}
PCUT_TEST(atoi_negative) {
PCUT_ASSERT_INT_EQUALS(-273, atoi("-273"));
}
PCUT_MAIN()
There is no need to preprocess this source code. Just compile/link it against libpcut
and it would produce executable that would run these 3 tests. The output produced would look like this.
1..3
#> Starting suite Default.
ok 1 atoi_zero
ok 2 atoi_positive
ok 3 atoi_negative
#> Finished suite Default (failed 0 of 3).