Home | Libraries | People | FAQ | More |
The predicate_result
class combines a boolean result
from a predicate with a detailed context message for a failed predicate
evaluation. Usually this class is only used in the internal implementation
of the test framework, but a user can define their own custom predicates
that return a predicate_result
to support detailed failure
messages when an assertion fails.
predicate_result
is constructable and assignable from
bool
. The message()
method returns
an output string stream that can be used to build up a context message.
namespace boost { namespace test_tools { class BOOST_TEST_DECL predicate_result { public: // Constructor predicate_result( bool pv_ ) : p_predicate_value( pv_ ) {} template<typename BoolConvertable> predicate_result( BoolConvertable const& pv_ ) : p_predicate_value( !!pv_ ) {} // Access methods bool operator!() const { return !p_predicate_value; } void operator=( bool pv_ ) { p_predicate_value.value = pv_; } operator safe_bool() const { return !!p_predicate_value ? &dummy::nonnull : 0; } // Public properties BOOST_READONLY_PROPERTY( bool, (predicate_result) ) p_predicate_value; // Access methods bool has_empty_message() const { return !m_message; } wrap_stringstream& message() const_string message() const { return !m_message ? const_string() : const_string( m_message->str() ); } }; } }
See BOOST_REQUIRE_MESSAGE
for an example using predicate_result
.