Bap*_*cht 6 testing unit-testing ctest
我正在使用CTest启动我项目的测试.我想只启动上次执行失败的测试.
使用CTest有一种简单的方法吗?
msm*_*ens 10
该--rerun-failed选项已添加到CMake 3.0中的CTest:
--rerun-failed
Run only the tests that failed previously
This option tells ctest to perform only the tests that failed
during its previous run. When this option is specified, ctest
ignores all other options intended to modify the list of tests
to run (-L, -R, -E, -LE, -I, etc). In the event that CTest runs
and no tests fail, subsequent calls to ctest with the
--rerun-failed option will run the set of tests that most
recently failed (if any).
Run Code Online (Sandbox Code Playgroud)
参考文献:
我认为简短的回答是否定的。
但是,您可以使用简单的 CMake 脚本将最后失败的测试列表转换为适合CTest-I选项的格式。
CTest 写入一个名为类似内容的文件<your build dir>/Testing/Temporary/LastTestsFailed.log,其中包含失败测试的列表。如果后续运行中所有测试都通过,则不会清除此列表。此外,如果 CTest 在仪表板模式下运行(作为 dart 客户端),日志文件名将包括文件中详细说明的时间戳<your build dir>/Testing/TAG。
下面的脚本没有考虑包括时间戳的文件名,但应该很容易扩展它来执行此操作。它读取失败测试的列表并将一个名为FailedTests.log当前构建目录的文件写入。
set(FailedFileName FailedTests.log)
if(EXISTS "Testing/Temporary/LastTestsFailed.log")
file(STRINGS "Testing/Temporary/LastTestsFailed.log" FailedTests)
string(REGEX REPLACE "([0-9]+):[^;]*" "\\1" FailedTests "${FailedTests}")
list(SORT FailedTests)
list(GET FailedTests 0 FirstTest)
set(FailedTests "${FirstTest};${FirstTest};;${FailedTests};")
string(REPLACE ";" "," FailedTests "${FailedTests}")
file(WRITE ${FailedFileName} ${FailedTests})
else()
file(WRITE ${FailedFileName} "")
endif()
Run Code Online (Sandbox Code Playgroud)
然后,您应该能够通过执行以下操作来运行失败的测试:
cmake -P <path to this script>
ctest -I FailedTests.log
Run Code Online (Sandbox Code Playgroud)