1

使用 boost::mpl 时,测试用例模板没有运行(我假设是因为逗号)。

该代码在 boost 1.55 中工作,因为正在使用的测试用例名称是模板的错位名称。但是升级到 boost 1.64 的 demangled 名称现在被用作测试用例名称 IE:

test_case<foo<A,B>>

代码使用这个模板

template <bool arg1, typename arg2>
    struct test_template: public arg2
    {
        static const bool isEnabled = arg1;
    };

代码现在声明了一个包含两个实例化模板的 mpl 容器。

using test_templates = boost::mpl::vector<
        test_template<true, SPECIALIZED>,
        test_template<false, GENERIC>> ;

该代码使用 BOOST_AUTO_TEST_CASE_TEMPLATE 自动注册测试用例。

BOOST_AUTO_TEST_CASE_TEMPLATE(my_test, T, test_templates )
{
    BOOST_TEST( sizeof(T) == (unsigned)4 ); 
    //This will fail but this test case will not run at all in this example.
}

现在测试用例将被命名:

   my_test<test_template<true,_SPECIALIZED>>
   my_test<test_template<false,_GENERIC>>

由于测试用例名称中包含逗号,因此 boost.test 遇到了问题。

这段代码在 boost 1.55 中可以正常工作,因为 boost 使用实例化模板的错位名称分配了测试用例名称(这是一个长而奇怪的名称,但没有逗号)

有任何想法吗?我查看了 boost 文档,似乎没有任何关于在 mpl 中使用多个参数模板进行 boost 测试的消息。

4

0 回答 0