【发布时间】:2021-10-26 18:41:43
【问题描述】:
使用 CMake 我尝试使用 CTest 执行一个简单的测试。我在一个目录中都有这个配置(${CMAKE_SOURCE_DIR}):
~$ cat hello.cpp
#include <iostream>
int main() {
std::cout << "hello world\n";
return(0);
}
~$ cat CMakeLists.txt
cmake_minimum_required(VERSION 3.18)
project(TEST_CTEST)
enable_testing()
add_executable(test_ctest hello.cpp)
add_test(my_test ./build/test_ctest)
然后我执行:
~$ rm -rf Testing/ build/
~$ cmake -S . -B build
~$ cmake --build build
~$ ./build/test_ctest
hello world
~$ ctest
*********************************
No test configuration file found!
*********************************
Usage
ctest [options]
我在其他问答中发现的唯一提示是将enable_testing() 放入根CMakeLists.txt。我觉得我只是错过了一点东西,但我找不到什么。
如何使用 CTest 运行测试?
【问题讨论】:
-
你需要从 build 目录调用
ctest。正是这个目录包含了ctest想要读取的配置文件。 -
@Tsyvarev 我担心这只是一件小事......请让您的评论成为答案。我会接受的。