/
example.c
44 lines (37 loc) · 1.11 KB
/
example.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <check.h>
int main() {
describe("A Test Suite using check.c", {
describe("check() and checkm()", {
context("passing tests", {
it("uses expression as message when using check()", {
check(1 + 2 == 3);
check(1);
});
it("custom message when using checkm()", {
checkm(2 * 2 == 4, "two times two equals four");
});
});
context("failing tests", {
it("shows a message in red color", {
check(1 > 2);
});
it("skips the rest of the tests (in the same block) after one fails", {
checkm(1, "this passes");
checkm(0, "this fails");
checkm(1, "this gets skipped");
});
});
});
describe("passed, failed, and skipped counters", {
it("work correctly", {
check(check_passed == 4);
check(check_failed == 2);
check(check_skipped == 1);
});
});
});
// Print number of assertions, passed, skipped, and failed counts.
check_print_stats();
// Exit successfully if exactly 2 tests failed.
return check_failed == 2 ? 0 : 1;
}