Boost logo

Boost Users :

From: Mateusz Loskot (mateusz_at_[hidden])
Date: 2020-03-08 00:51:10


On Sun, 8 Mar 2020 at 01:06, Leo Carreon via Boost-users
<boost-users_at_[hidden]> wrote:
>
> Hi Boost.Users,
>
> I’m using Boost.Test from Boost 1.72.0 and I’m getting a failure when I perform the following test:
>
> auto string_1 = u8”value”s;
> auto string_2 = u8”value”s;
> BOOST_TEST(string_1 == string_2);

If you are getting a failure, tell what is the failure (crystal
spheres not always work ;))

I suspect you are hitting two issues:
1. std::u8string is not "eligible for string comparison"
     https://www.boost.org/libs/test/doc/html/boost_test/testing_tools/extended_comparison/strings.html
2. reporting of char8_t falls into reporting of user-defined type
     https://www.boost.org/libs/test/doc/html/boost_test/test_output/test_tools_support_for_logging/testing_tool_output_disable.html

A possible hack to work around these two could be

namespace std {
std::ostream& boost_test_print_type(std::ostream& os, char8_t const& c)
{
    // convert c
    return os;
}
}
BOOST_TEST(string_1 == string_2, boost::test_tools::per_element());

> However, the problem goes away when I change the test line to:
>
> BOOST_TEST((string_1 == string_2));
>
> What is the reason why Boost.Test is failing without the double parentheses?

It disables (de)constructing of the expression from macro input, see
https://www.boost.org/libs/test/doc/html/boost_test/testing_tools/internal_details.html
https://www.boost.org/libs/test/doc/html/boost_test/testing_tools/boost_test_universal_macro.html

Best regards,

-- 
Mateusz Loskot, http://mateusz.loskot.net

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net