TIPS:单独运行单元测试成功,但是ctest却显示失败

现象:单独运行单元测试是成功的,但是ctest却告诉我失败了
原因:单元测试程序退出时没有返回 0。

过程:

我给 miniob 的github action上增加了单测,每次提交PR到main分支就会执行单测。
有次提交代码单测运行显示是通过的,但是github action中看到的结果总是失败的。在本地单独运行测试每次都是成功的,百思不得姐。后来执行 make test(或者ctest)可以重现github action的错误。百思不得姐的事情又变成看起来测试是成功的,但是ctest告诉我失败了,就像下面的结果:

miniob/build_release [83] $ ctest --rerun-failed --output-on-failure -C Debug
Test project /data/wangyunlai.wyl/project/github/miniob-me/build_release
    Start 8: test_clog.test_clog
1/1 Test #8: test_clog.test_clog ..............***Failed    0.12 sec
Note: Google Test filter = test_clog.test_clog
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from test_clog
[ RUN      ] test_clog.test_clog
[       OK ] test_clog.test_clog (4 ms)
[----------] 1 test from test_clog (4 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (4 ms total)
[  PASSED  ] 1 test.


0% tests passed, 1 tests failed out of 1

Total Test time (real) =   0.12 sec

The following tests FAILED:
	  8 - test_clog.test_clog (Failed)
Errors while running CTest

让我突然间醒悟的是,clog_test 这个测试程序执行完成时返回值不是0,在终端上运行 echo $? 可以看到,结果是8,突然又醒悟了。
我是在编译时增加了asan相关的选项,这个测试相关的代码有一些内存泄露,后来把内存泄露问题解决了,通过echo $? 查看返回值是0,再运行ctest就成功了。

miniob/build_release [83] $ ctest --rerun-failed --output-on-failure
Test project /data/wangyunlai.wyl/project/github/miniob-me/build_release
    Start 8: test_clog.test_clog
1/1 Test #8: test_clog.test_clog ..............   Passed    0.02 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.03 sec
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值