CMake: PASS_REGULAR_EXPRESSION for标准错误



我希望PASS_REGULAR_EXPRESSION也检查stderr。这可能吗?我尝试了以下操作:

add_test(NAME test COMMAND executable)
set_tests_properties(test PROPERTIES
  WILL_FAIL true
  PASS_REGULAR_EXPRESSION "I was printed to stderr"
)

,但它不工作,因为PASS_REGULAR_EXPRESSION只检查stdout。我试图将stderr重定向到stdout:

add_test(NAME test COMMAND executable 2>&1)

但它似乎也不起作用。

PASS_REGULAR_EXPRESSION确实检查了stderr,但是这会导致退出代码被忽略。因此,由于WILL_FAIL,您的示例失败了:CTest找到了正则表达式,但它不希望找到,因此将测试标记为失败。删除WILL_FAIL后,测试通过:

// main.c
#include <stdio.h>
int main(void) {
  fprintf(stderr, "I was printed to stderrn");
}
# CMakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(SO_74340897)
add_executable(executable main.c)
enable_testing()
add_test(NAME test COMMAND executable)
set_tests_properties(test PROPERTIES
  #WILL_FAIL true
  PASS_REGULAR_EXPRESSION "I was printed to stderr"
)

运行如下测试:

$ ctest
Test project /home/jschulze/tmp/stackoverflow74340897/build
    Start 1: test
1/1 Test #1: test .............................   Passed    0.00 sec
100% tests passed, 0 tests failed out of 1
Total Test time (real) =   0.00 sec

相关内容

  • 没有找到相关文章

最新更新