【问题标题】:How to pass quoted parameters to add_test in cmake?如何将带引号的参数传递给cmake中的add_test?
【发布时间】:2013-06-23 20:14:17
【问题描述】:

我正在尝试从 cmake 将参数传递给 gtest 测试套件:

add_test(NAME craft_test
         COMMAND craft --gtest_output='xml:report.xml')

问题是这些参数是用引号括起来的,为什么?好像是个bug,有什么好的方法可以避免吗?

$ ctest -V
UpdateCTestConfiguration  from :/usr/local/src/craft/build-analyze/DartConfiguration.tcl
UpdateCTestConfiguration  from :/usr/local/src/craft/build-analyze/DartConfiguration.tcl
Test project /usr/local/src/craft/build-analyze
Constructing a list of tests
Done constructing a list of tests
Checking test dependency graph...
Checking test dependency graph end
test 1
    Start 1: craft_test

1: Test command: /usr/local/src/craft/build-analyze/craft "--gtest_output='xml:report.xml'"
1: Test timeout computed to be: 9.99988e+06
1: WARNING: unrecognized output format "'xml" ignored.
1: [==========] Running 1 test from 1 test case.
1: [----------] Global test environment set-up.
1: [----------] 1 test from best_answer_test
1: [ RUN      ] best_answer_test.test_sample
1: [       OK ] best_answer_test.test_sample (0 ms)
1: [----------] 1 test from best_answer_test (0 ms total)
1: 
1: [----------] Global test environment tear-down
1: [==========] 1 test from 1 test case ran. (0 ms total)
1: [  PASSED  ] 1 test.
1/1 Test #1: craft_test .......................   Passed    0.00 sec

100% tests passed, 0 tests failed out of 1

Total Test time (real) =   0.00 sec

【问题讨论】:

    标签: cmake googletest ctest


    【解决方案1】:

    这里的问题不是 CMake 添加的引号; 'xml:report.xml' 中的单引号有问题。

    你应该这样做:

    add_test(NAME craft_test
         COMMAND craft --gtest_output=xml:report.xml)
    

    【讨论】:

    • 这可以解决问题,尽管在 ctest 之外运行测试时,我使用单引号或双引号传递了 args 并且它工作正常(可以检查 herehere。恐怕当我出于某种原因需要使用它们时,我可能会偶然发现这样的引用问题。
    • 我同意引号转义在 CMake 中有点痛苦,但我认为在这种情况下你应该没问题。我可以看到您需要引号的唯一原因是您的文件名或路径是否包含空格,然后您可以使用 COMMAND craft "--gtest_output=xml:rep ort.xml" 我认为。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-11
    • 2015-10-29
    • 1970-01-01
    • 2011-12-29
    • 2020-03-05
    • 1970-01-01
    相关资源
    最近更新 更多