Why does BOOST_TEST() treat std::string as a collection?
Why does BOOST_TEST() compare std::string values as collections instead
of scalars (by default)? It's odd that the following produce different
output, for example:
BOOST_TEST(std::string("a") == "b");
BOOST_TEST(std::string("a") == std::string("b"));
This will output:
test.cc(6): error: in "test": check std::string("a") == "b" has failed
[a != b]
test.cc(7): error: in "test": check std::string("a") == std::string("b")
has failed
Note the lack of "[a != b]" on the second case. Also note that
BOOST_CHECK_EQUAL() would emit as in the first form.
This seems to be because std::string is_forward_iterable, and thus falls
into the collection_comparison_op.hpp comparators instead of the scalar
comparators. Is this intentional or an oversight?
As a simple fix, adding a condition to the partial specialization of the
collection_comparison_op.hpp comparators that specifically excludes
std::string is enough to have std::string treated as scalars. For
example, to handle std::string but not std::wstring with C++11 support:
template
Brad Spencer
Why does BOOST_TEST() compare std::string values as collections instead of scalars (by default)?
This is bug if this is the case. Feel free to submit ticket as a reminder. Gennadiy
participants (2)
-
Brad Spencer
-
Gennadiy Rozental