如何在cmake / ctest下告诉测试在哪里找到其输入数据...而无需更改硬编码的文件名 [英] How to tell a test under cmake/ctest where to find its input data ... without changing hard-coded file names

查看:75
本文介绍了如何在cmake / ctest下告诉测试在哪里找到其输入数据...而无需更改硬编码的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目录 prj / test 包含一些测试脚本 t01.exe t02.exe 等。其中一些需要输入数据 d01.dat 等,也在 prj / test 。这些数据文件的名称在测试中是硬编码的,我不能轻易更改它。控制文件 CMakeLists.txt 包含

Directory prj/test contains some test scripts t01.exe, t02.exe etc. Some of them need input data d01.dat etc, also provided in prj/test. The names of these data files are hard-coded in the tests, and I cannot easily change this. The control file CMakeLists.txt contains

enable_testing()
file(GLOB test_sources "t*")
foreach(test_src ${test_sources})
    string(REGEX REPLACE ".*/" "" test_name "${test_src}")
    string(REGEX REPLACE ".exe$" "" test_name "${test_name}")
    add_test(${test_name} "${test_src}")
endforeach(test_src)

我在 prj / build 子目录中构建项目。 ctest 可以正常工作...直到测试需要输入数据。显然,找不到它们是因为它们驻留在 prj / test 中,而测试在 prj / build / test 中运行。

I'm building the project in a subdirectory prj/build. ctest works fine ... until a test requires input data. Obviously, they are not found because they reside in prj/test whereas the test runs in prj/build/test.

因此我的问题:


  • 让测试找到的标准方法是什么他们的输入数据?

  • 有没有一种方法不需要复制数据(如果它们很大的话)?

  • 真的,符号链接没有无法在Windows下工作,因此不是可接受的解决方案吗?

推荐答案

add_test 命令接受 WORKING_DIRECTORY 选项。您可以将此选项设置为测试所在的目录。因此,测试将找到其数据文件:

add_test command accepts WORKING_DIRECTORY option. You can set this option to a directory where a test is located. So, the test will find its data file:

add_test(NAME ${test_name} COMMAND "${test_src}"
         WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)

这篇关于如何在cmake / ctest下告诉测试在哪里找到其输入数据...而无需更改硬编码的文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆