提升测试无法找到自定义打印
boost test fails to find custom print
由于某些原因boost::test
无法编译以下代码
#define BOOST_TEST_MODULE EPUTests
#include <iostream>
#include <boost/test/unit_test.hpp>
using epu8 = uint8_t __attribute__((vector_size(16)));
std::ostream &operator<<(std::ostream &stream, epu8 const &term) {
stream << "[" << unsigned(term[0]);
for (unsigned i = 1; i < 16; ++i)
stream << "," << unsigned(term[i]);
stream << "]";
return stream;
}
bool failtest(epu8 x) { return false; }
//****************************************************************************//
BOOST_AUTO_TEST_SUITE(EPU8_test)
BOOST_AUTO_TEST_CASE(EPU8_equal) {
epu8 x {};
BOOST_CHECK_PREDICATE(failtest, (x));
}
BOOST_AUTO_TEST_SUITE_END()
//****************************************************************************//
错误信息是
In file included from /usr/include/boost/test/tools/floating_point_comparison.hpp:21:0,
from /usr/include/boost/test/tools/old/impl.hpp:21,
from /usr/include/boost/test/test_tools.hpp:46,
from /usr/include/boost/test/unit_test.hpp:18,
from boost_test_epu.cpp:4:
/usr/include/boost/test/tools/detail/print_helper.hpp: In instantiation of 'struct boost::test_tools::tt_detail::print_log_value<__vector(16) unsigned char>':
/usr/include/boost/test/tools/detail/print_helper.hpp:178:5: required from 'std::ostream& boost::test_tools::tt_detail::operator<<(std::ostream&, const boost::test_tools::tt_detail::print_helper_t<T>&) [with T = __vector(16) unsigned char; std::ostream = std::basic_ostream<char>]'
/usr/include/boost/test/utils/lazy_ostream.hpp:66:29: required from 'std::ostream& boost::unit_test::lazy_ostream_impl<PrevType, T, StorageT>::operator()(std::ostream&) const [with PrevType = boost::unit_test::lazy_ostream; T = boost::test_tools::tt_detail::print_helper_t<__vector(16) unsigned char>; StorageT = const boost::test_tools::tt_detail::print_helper_t<__vector(16) unsigned char>&; std::ostream = std::basic_ostream<char>]'
boost_test_epu.cpp:29:1: required from here
/usr/include/boost/test/tools/detail/print_helper.hpp:47:5: error: static assertion failed: Type has to implement operator<< to be printable
BOOST_STATIC_ASSERT_MSG( (boost::has_left_shift<std::ostream,T>::value),
我知道 g++ 抱怨我的 epu8
类型不可打印。但是我知道这是因为改变
BOOST_CHECK_PREDICATE(failtest, (x));
来自
std::cout << x << std::endl;
BOOST_CHECK(failtest(x));
按预期工作并按矢量变量正确打印。
各种版本的clang++和g++都报同样的错误
我做错了什么?
BOOST::test 要求控制台输出 operator<< 在 std 命名空间中
namespace std
{
ostream &operator<<(...)
...
}
由于某些原因boost::test
无法编译以下代码
#define BOOST_TEST_MODULE EPUTests
#include <iostream>
#include <boost/test/unit_test.hpp>
using epu8 = uint8_t __attribute__((vector_size(16)));
std::ostream &operator<<(std::ostream &stream, epu8 const &term) {
stream << "[" << unsigned(term[0]);
for (unsigned i = 1; i < 16; ++i)
stream << "," << unsigned(term[i]);
stream << "]";
return stream;
}
bool failtest(epu8 x) { return false; }
//****************************************************************************//
BOOST_AUTO_TEST_SUITE(EPU8_test)
BOOST_AUTO_TEST_CASE(EPU8_equal) {
epu8 x {};
BOOST_CHECK_PREDICATE(failtest, (x));
}
BOOST_AUTO_TEST_SUITE_END()
//****************************************************************************//
错误信息是
In file included from /usr/include/boost/test/tools/floating_point_comparison.hpp:21:0,
from /usr/include/boost/test/tools/old/impl.hpp:21,
from /usr/include/boost/test/test_tools.hpp:46,
from /usr/include/boost/test/unit_test.hpp:18,
from boost_test_epu.cpp:4:
/usr/include/boost/test/tools/detail/print_helper.hpp: In instantiation of 'struct boost::test_tools::tt_detail::print_log_value<__vector(16) unsigned char>':
/usr/include/boost/test/tools/detail/print_helper.hpp:178:5: required from 'std::ostream& boost::test_tools::tt_detail::operator<<(std::ostream&, const boost::test_tools::tt_detail::print_helper_t<T>&) [with T = __vector(16) unsigned char; std::ostream = std::basic_ostream<char>]'
/usr/include/boost/test/utils/lazy_ostream.hpp:66:29: required from 'std::ostream& boost::unit_test::lazy_ostream_impl<PrevType, T, StorageT>::operator()(std::ostream&) const [with PrevType = boost::unit_test::lazy_ostream; T = boost::test_tools::tt_detail::print_helper_t<__vector(16) unsigned char>; StorageT = const boost::test_tools::tt_detail::print_helper_t<__vector(16) unsigned char>&; std::ostream = std::basic_ostream<char>]'
boost_test_epu.cpp:29:1: required from here
/usr/include/boost/test/tools/detail/print_helper.hpp:47:5: error: static assertion failed: Type has to implement operator<< to be printable
BOOST_STATIC_ASSERT_MSG( (boost::has_left_shift<std::ostream,T>::value),
我知道 g++ 抱怨我的 epu8
类型不可打印。但是我知道这是因为改变
BOOST_CHECK_PREDICATE(failtest, (x));
来自
std::cout << x << std::endl;
BOOST_CHECK(failtest(x));
按预期工作并按矢量变量正确打印。
各种版本的clang++和g++都报同样的错误
我做错了什么?
BOOST::test 要求控制台输出 operator<< 在 std 命名空间中
namespace std
{
ostream &operator<<(...)
...
}