Compile the test executable returning report() to get the number of
failed tests as the status code.
Define FAILED_ONLY to see only failures.
// example.test.c
#include "example.h"
#include "../test/test.h"
void testExample() {
expectTrue(example(), "returns true");
}
int main(void) {
suite(testExample);
return report();
}
// my_struct.test.c
#include "my_struct.h" // myStruct_eql, myStruct_toString
#include "../test/test.h"
void expectEqlMyType(const MyType* a, const MyType* b, const char* name) {
char msg[256];
snprintf(msg, 256, "Expected %s to equal %s", myStruct_toString(a),
myStruct_toString(b));
expect(myStruct_eql(a, b), name, msg);
}
// define main as above
Asserts a condition and prints the result. Use it to implement custom assertions.
int a = 1;
expect(a == 1, "a is one", "Should be true");
Asserts that a condition is true.
expectTrue(2 > 1, "2 is greater than 1");
Asserts that a condition is false.
expectFalse(0, "zero is false");
Asserts that a pointer is not NULL.
int x = 5;
expectNotNull(&x, "pointer is not null");
Asserts that a pointer is NULL.
int* p = NULL;
expectNull(p, "pointer is null");
Asserts that two integers are equal.
expectEqli(3, 3, "3 equals 3");
Asserts that two integers are not equal.
expectNeqi(3, 4, "3 does not equal 4");
Asserts that two unsigned integers are equal.
expectEqlu(3, 3, "3 equals 3");
Asserts that two unsigned integers are not equal.
expectNeqlu(3, 4, "3 does not equal 4");
Asserts that two unsigned long integers are equal.
expectEqllu(3, 3, "3 equals 3");
Asserts that two unsigned long integers are equal.
expectNeqllu(3, 4, "3 does not equal 4");
Asserts that two floats are equal within a threshold.
expectEqlf(1.0f, 1.0f, "floats are equal");
Asserts that two floats are not equal within a threshold.
expectNeqf(1.0f, 2.0f, "floats are not equal");
Asserts that two doubles are equal within a threshold.
expectEqld(1.0, 1.0, "doubles are equal");
Asserts that two doubles are not equal within a threshold.
expectNeqd(1.0, 2.0, "doubles are not equal");
Asserts that two strings are equal up to max_size.
expectEqls("foo", "foo", 3, "strings are equal");
Asserts that two strings are not equal up to max_size.
expectNeqs("foo", "bar", 3, "strings are not equal");
Asserts that first string includes the second.
expectIncls("foobar", "bar", "strings are included");
Prints a summary of test results and returns the number of failed tests.
return report();
Prints the name of a test case.
test("my test");
Runs a test suite and prints its name.
suite(myTestFunction);