Hello,
within
my test application some variables are of type uint8_t which is a
typedef for unsigned char. Now, if an assertion fails the expansion
prints the character with the ASCII Code rather than the numeric value.
To overcome this issue I tried to overload the operator<< functions as follows
std::ostream & operator<<(std::ostream & os, std::uint8_t val)
{
return os << static_cast<int>(val);
}
TEST_CASE( "print unsigned char", "")
{
std::uint8_t val = 123;
std::cout << val << std::endl; // prints number 123 due to overloading operator<< --> great!
CHECK( val == 124); // expansion, however, gives corresponding ASCII character --> still bad
}
where I have declared the operator<< function before including Catch's header. The code above produces the output
123
-------------------------------------------------------------------------------
print unsigned char
-------------------------------------------------------------------------------
tests.cpp:32
...............................................................................
tests.cpp:36: FAILED:
CHECK( val == 124 )
with expansion:
'{' == 124
The problem is sill present and I don't know how to workaround it. Any suggestions? Many thanks in advance.
// Daniel Kotik