如何使用 CMake 和 CTest 提供参数?

发布于 2024-08-03 09:03:16 字数 187 浏览 1 评论 0原文

在我想要使用 CTest 运行的测试中,我应该使用以下命令添加我想要运行的测试:

add_test(TestName ExeName)

问题是,如果我想向 TestName 提供参数,我应该把它放在哪里? 在这种情况下,如何在 unix 命令行中单独运行 ctest 而无需使用 cmake?

In the test that I want to run using CTest I should be adding the test that I want to run, with the following command:

add_test(TestName ExeName)

The problem is what if I want to supply an argument to the TestName, where do I put it?
How do I run ctest individually without cmake in unix command line in this context?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

森林很绿却致人迷途 2024-08-10 09:03:16

在 CMakeLists.txt 文件中插入以下命令:

ENABLE_TESTING()

接下来添加测试:

add_test(testname Executable args)

要确定可用的测试,您始终可以运行:

ctest -N

指定测试的第二种方法是使用显式测试编号选项 -I:

ctest -I 3

将运行测试3号。

Insert the following command in the CMakeLists.txt file:

ENABLE_TESTING()

Next add the test(s):

add_test(testname Executable args)

To determine what tests are available, you can always run:

ctest -N

The second way of specifying tests is using explicit test number option -I:

ctest -I 3

will run the test number 3.

酷到爆炸 2024-08-10 09:03:16

就像在命令行中一样,参数在可执行文件名称之后传递。

enable_testing()

add_test(FirstTest app.exe 100)
add_test(SecondTest app.exe 200)
add_test(ThirdTest app.exe 300)

可以使用 -I 选项根据测试的“索引”运行测试。

ctest -I 2,3

也可以使用 -R 选项根据测试名称运行特定测试。

ctest -R "Second"

Arguments are passed after the executable name just like in the command line.

enable_testing()

add_test(FirstTest app.exe 100)
add_test(SecondTest app.exe 200)
add_test(ThirdTest app.exe 300)

Tests can be run based on the "index" of the test with the -I option.

ctest -I 2,3

Specific tests can be run based on the test name too with the -R option.

ctest -R "Second"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文