代码拉取完成,页面将自动刷新
This project is inspired by MinUnit, which is a minimal unit testing framework for C. MiniUnit provides more flexible assertions and presents test results with better readability, including display the file name and line number in color text.
MiniUnit is
mu_assert(expr)
assertion fail if expr
falsemu_assert(expr, message)
assertion with messagemu_assert(expr, message, args...)
assertion and message with no more than 16 argsA test is a function without parameters and return int
. It return 0
only if all assertions passed. For example,
int test_something()
{
mu_assert(1 + 1 == 2);
return 0; // 0 表示测试通过
}
mu_run_test(test)
to run a test function int test()
which return 0
if passedmu_test_results()
to display the test results#define MU_NOCOLOR
if ANSI escape code not supported#define MU_NOCOLOR
#include "miniunit.h"
For example,
#include "miniunit.h"
int test_one()
{
mu_assert(2 + 2 == 4);
return 0; // 0 means test passed
}
int test_two()
{
int a = 3, b = 5;
mu_assert(a == 3);
mu_assert(b == 5, "b is 5");
mu_assert(a + b == 7, "should be %d", a + b); // fail
return 0;
}
int main()
{
mu_run_test(test_one);
mu_run_test(test_two);
mu_test_results();
return 0;
}
Output in color mode:
Output in no-color mode:
|- test_one ./mu_example.c:21 ... ✔
|- test_two ./mu_example.c:22 ... ✘
|\_[FAIL] at ./mu_example.c:15 for 'a + b == 7' ✘ should be 8
\_________________________________
1 ✔ and 1 ✘ in 2 TEST(S)
#### 1 TEST(S) FAILED ####
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。