redis源码笔记-testhelp

testhelp.h是作者为redis量身定做的单元测试框架,对于redis这种规模的项目,就没有必要上GTEST这种大杀器了,作者18行代码搞定。

不过很遗憾,在2.4.10这个版本的版本的redis中,只有sds用了这个测试框架,不知其他代码作者是如何做测试的。我慢慢摸索,摸索到了告诉大家。

 1 #ifndef __TESTHELP_H
 2 #define __TESTHELP_H
 3 
 4 int __failed_tests = 0;            //失败的测试用例数
 5 int __test_num = 0;                //总的测试用例数
 6 #define test_cond(descr,_c) do { \
 7     __test_num++; printf("%d - %s: ", __test_num, descr); \
 8     if(_c) printf("PASSED\n"); else {printf("FAILED\n"); __failed_tests++;} \
 9 } while(0);
10 #define test_report() do { \
11     printf("%d tests, %d passed, %d failed\n", __test_num, \
12                     __test_num-__failed_tests, __failed_tests); \
13     if (__failed_tests) { \
14         printf("=== WARNING === We have failed tests here...\n"); \
15     } \
16 } while(0);
17 
18 #endif  //完全用宏实现的,一目了然,不多说了

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值