assert使用

来源:互联网 发布:阿里域名服务器地址 编辑:程序博客网 时间:2024/05/12 03:35

多用assert,能很好找到程序出错位置。



测试
1、输入参数个数不等于2时
yuan@yuan:~/work/test> ./assert test
this is a test for assert,by yuanzhenhai
***ERROR***(argc != 3): "argc == 3" must be true, __funtion__:main(),  __file__:assert.c,  __line__:42

2、输入参数个数等于2,但两个参数字符串不相等时
yuan@yuan:~/work/test> ./assert test testtt
this is a test for assert,by yuanzhenhai
***ERROR***(the two string isn't equal): "!strcmp(str1,str2)" must be true, __funtion__:fun(),  __file__:assert.c,  __line__:32

3、输入参数个数等于2,两个参数字符串也相等时
yuan@yuan:~/work/test> ./assert test test
this is a test for assert,by yuanzhenhai
the two strings that you input is equal,successful!