- Operators
- Expect Assertions
- Basic Assertions
- Pointer Assertions
- Array Assertions
- Exit & Signal Assertions
- Mocking
The same as the standrd C operators:
==
- Requires actual to be equal to expected.
!=
- Requires actual to not be equal to expected.
>
- Requires actual to be greater than to expected.
<
- Requires actual to be less than to expected.
>=
- Requires actual to be greater than or equal to expected.
<=
- Requires actual to be less than or equal to expected.
Only defined for strings and array elements.
in
- Requires actual to be in expected.
not in
- Inverse of above: requires actual to not be in expected.
Examples:
EXPECT_STR("abc", in, "abcdef")
EXPECT_INT_ARRAY_ELEMENT(1, in, {1, 2, 3})
Only defined for strings.
match
- Requires actual to match expected.
not match
- Inverse of above: requires actual to not match expected.
Examples:
EXPECT_STR("abc", match, "abc")
EXPECT_STR("a a char", match, "a $c char")
EXPECT_STR("a 123 number", match, "a $i number")
EXPECT_STR("abc", not match, "def")
- See sample tests for more
Match specifiers are specified with $
:
$i
,$d
= match a integer (0-9)$c
= match a single character$f
= match a float (0-9, a single . allowed)$a
= match alpha-chars (a-z and A-Z)$w
= match a word (matches anything non-whitespace)$s
= match a string (at least 1 character)$$
= a literal $- Anything else = literal match
- Note: Supports backtracing so
abc
will match$s$s
buta
won't
Equivalent to EXPECT_BOOL(expr, ==, true)
.
A good drop in replacement for assert
.
For example: EXPECT(1 + 2 == 2)
. See sample tests.
The inverse of EXPECT
.
Equivalent to EXPECT_BOOL(expr, ==, false)
.
For example: EXPECT_NOT(6 * 9 != 42)
. See sample tests.
Compare two ptrs' addresses.
For example: EXPECT_PTR((void*) 0x3, !=, (void*) 0x2)
. See sample tests.
Compare two bools.
For example: EXPECT_BOOL(true, !=, false)
. See sample tests.
Compare two chars.
For example: EXPECT_CHAR('a', !=, 'b')
. See sample tests.
Compare two ints.
For example: EXPECT_INT(4, >, 3)
. See sample tests.
Compare two strings.
For example: EXPECT_STRING("abc", !=, "def")
. See sample tests.
First, checks for NULL
, then dereferences and compares two ptrs' addresses.
First, checks for NULL
, then dereferences and compares two bools.
First, checks for NULL
, then dereferences and compares two chars.
First, checks for NULL
, then dereferences and compares two ints.
First, checks for NULL
, then dereferences and compares two strings.
Compare two arrays of ptrs' addresses. Length of expected array is required.
Inequality operators like >
are matched between each pair of elements.
For example: EXPECT_PTR_ARRAY({(void*) 0x3, (void*) 0x2}, !=, {(void*) 0x4, (void*) 0x5}, 3)
. See sample tests.
Compare two arrays of bools. Length of expected array is required.
Inequality operators like >
are matched between each pair of elements.
For example: EXPECT_BOOL_ARRAY({true, false}, !=, {false, false}, 2)
. See sample tests.
Compare two arrays of chars. Length of expected array is required.
Inequality operators like >
are matched between each pair of elements.
If the arrays are '\0'
terminated, a length of -1
may be used.
For example: EXPECT_CHAR_ARRAY({'a', 'w'}, !=, {'b', 'x'}, 2)
. See sample tests.
Compare two arrays of ints. Length of expected array is required.
Inequality operators like >
are matched between each pair of elements.
For example: EXPECT_INT_ARRAY({1, 2}, !=, {4, 5}, 2)
. See sample tests.
Compare two arrays of strings. Length of expected array is required.
If the arrays are NULL
terminated, a length of -1
may be used.
For example: EXPECT_STRING_ARRAY({"abc", "def"}, !=, {"wow", "cool"}, 2)
. See sample tests.
Expects the code contained to exit with a certain status.
Note: internally uses fork to make this possible. If your system does not support fork, this will not work.
Expects the code contained to exit with a certain signal.
Note: internally uses fork to make this possible. If your system does not support fork, this will not work.
Redirects reads from stdin to read from the input string instead.
Can be restored & read using RESTORE_STDIN()
.
Undos stdin mock from MOCK_STDIN()
. Should be used AFTER stdin has been read.
Redirects anything output to stdout
(printf
, puts
, etc.) into a mock.
Can be restored & read using char* RESTORE_STDOUT()
.
Undos stdout mock from MOCK_STDOUT()
, and returns a string of everything redirected into the mock.
Note: the returned string is allocated and must be free'd.