A single-header C testing framework.
int main() {
BEGIN_TESTING("filename.h");
TEST("describe what the test is testing") {
RETURNS_INT(func, expected_return_int, (...arguments));
RETURNS_STR(func, expected_return_str, (...arguments));
ASSERT(boolean_expression);
ASSERT_EQ(a, b);
MODIFIES_STR_ARR(func, expected_str_arr, modified_str_arr, (...arguments));
}
END_TESTING();
}
filename
: The name of the file being tested.
Prints out a startup message. Must be called before any tests are run.
Prints out a summary of the tests run.
description
: A string describing the test.
Prints out a message indicating the test being run.
func
: The function being tested. The literal name, not a string.expected_return_int
: The expected return value offunc
. Must be of typeint
.(...arguments)
: The arguments to pass tofunc
. Must be enclosed in parentheses.
Checks that func
returns expected_return_int
.
Example:
RETURNS_INT(add, 3, (1, 2));
func
: The function being tested. The literal name, not a string.expected_return_str
: The expected return value offunc
. Must be achar*
.(...arguments)
: The arguments to pass tofunc
. Must be enclosed in parentheses.
Checks that func
returns expected_return_str
.
Example:
RETURNS_STR(concat, "hello world", ("hello", " ", "world"));
func
: The function being tested. The literal name, not a string.expected_str_arr
: The expected value of themodified_str_arr
variable afterfunc
is called. Must be achar**
/char*[]
.modified_str_arr
: The variable thatfunc
modifies. Must be achar**
.(...arguments)
: The arguments to pass tofunc
. Must be enclosed in parentheses.
Checks that func
modifies modified_str_arr
to be expected_str_arr
.
Example:
char* arr[] = {"hello", "world"};
char* expected[] = {"world", "hello"};
MODIFIES_STR_ARR(reverse, expected, arr, (arr));
func
: The function being tested. The literal name, not a string.expected_str
: The expected value of themodified_str
variable afterfunc
is called. Must be achar*
.modified_str
: The variable thatfunc
modifies. Must be achar*
.(...arguments)
: The arguments to pass tofunc
. Must be enclosed in parentheses.
Checks that func
modifies modified_str
to be expected_str
.
Example:
char* str = "hello";
char* expected = "olleh";
MODIFIES_STR(reverse, expected, str, (str));
boolean_expression
: A boolean expression.
Checks that boolean_expression
is true.
Example:
ASSERT(1 == 1);
a
: A value.b
: A value.
Checks that a
is equal to b
, using the equality operator (==
).
Example:
ASSERT_EQ(1, 1);
a
: Achar*
.b
: Achar*
.
Checks that a
is equal to b
, using the strcmp
function.
Example:
ASSERT_STR_EQ("hello", "hello");