tts v2.3.0
The Tiny Test System
 
Loading...
Searching...
No Matches

◆ as_string()

template<typename T >
std::string tts::as_string ( T const &  e)

Value-to-string conversion.

When displaying the data required to understand a test's failures, TTS may need to print out value of various types. as_string provides a centralized way to perform such a task by handling most common types including:

  • types supporting std::to_string
  • types supporting stream insertion
  • types supporting unqualified call to to_string
  • sequences of such types

as_string takes care of applying any command-line options related to formatting to the value printed.

Examples

#define TTS_MAIN
#include <tts/tts.hpp>
namespace space
{
struct some_type { int i; };
struct some_other_type { int i; };
std::ostream& operator<<(std::ostream& os, some_other_type const& s)
{
return os << "[[" << s.i << "]]";
}
std::string to_string( some_type const& s ) { return "some_type[" + tts::as_string(s.i) + "]"; }
}
TTS_CASE( "Check display of type with specific to_string" )
{
TTS_EQUAL(tts::as_string( space::some_type{42} ) , "some_type[42]" );
TTS_EQUAL(tts::as_string( space::some_other_type{63} ), "[[63]]" );
};
#define TTS_CASE(ID)
Introduces a new test scenario and registers it into the current test driver.
Definition: case.hpp:147
std::string as_string(T const &e)
Value-to-string conversion.
Definition: as_string.hpp:61
#define TTS_EQUAL(LHS, RHS,...)
Performs equality comparison between two expressions.
Definition: relation.hpp:90
Parameters
eValue to convert to a string
Returns
the formatted string containing a representation of the value of e