Catch2:从向量生成

问题描述

我有一个测试用例,其中包含大量输入/模式排列,并希望使用 GENERATE 来避免写出每个用例。我已将每个测试的细节封装在 TestCase 结构向量中(其中包含测试的所有相关信息)。根据我对文档的理解,我可以依靠 IteratorGenerator

struct TestCase {
    Format format;
    Codec codec;
    const char* in_file;
    const char* ref_file;
    int channels;
};

TEST_CASE("PNG") {
    std::vector<TestCase> subtests {
         // excluded for brevity
    }

    auto subtest = GENERATE(subtests.begin(),subtests.end());
    REQUIRE(do_test(subtest)) // excluded for brevity
}

这给了我错误“'subtests' is not capture”,显然这个宏的重载需要一个 lamdba 参数。如果我将其修改为:

,我会得到相同的结果
auto subtest = GENERATE(from_range(subtests));

我的问题是,是否可以以这种方式(即从容器)使用 catch 生成测试部分,如果可以,正确的语法是什么?似乎没有任何可用的示例。

使用 gcc 4.8.5 和 catch2 2.17 在 centos7.7 上编译

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)