2010-11-09 18:24:00 -05:00
|
|
|
/*
|
|
|
|
* catch_resultinfo.hpp
|
|
|
|
* Catch
|
|
|
|
*
|
|
|
|
* Created by Phil on 28/10/2010.
|
|
|
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#ifndef TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|
|
|
|
|
|
|
|
#include <string>
|
2011-01-11 04:13:31 -05:00
|
|
|
#include "catch_result_type.h"
|
2010-11-09 18:24:00 -05:00
|
|
|
|
|
|
|
namespace Catch
|
|
|
|
{
|
|
|
|
class ResultInfo
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
ResultInfo()
|
2010-12-28 09:17:27 -05:00
|
|
|
: m_line( 0 ),
|
|
|
|
m_result( ResultWas::Unknown ),
|
2010-11-09 18:24:00 -05:00
|
|
|
m_isNot( false ),
|
2010-11-11 02:21:57 -05:00
|
|
|
m_expressionIncomplete( false )
|
2010-11-09 18:24:00 -05:00
|
|
|
{}
|
|
|
|
|
2011-01-07 04:38:32 -05:00
|
|
|
ResultInfo( const char* expr, ResultWas::OfType result, bool isNot, const char* filename, std::size_t line, const char* macroName )
|
2010-12-28 09:17:27 -05:00
|
|
|
: m_macroName( macroName ),
|
|
|
|
m_filename( filename ),
|
|
|
|
m_line( line ),
|
|
|
|
m_expr( expr ),
|
|
|
|
m_op( m_expr[0] == '!' ? "!" : "" ),
|
2010-11-09 18:24:00 -05:00
|
|
|
m_result( result ),
|
|
|
|
m_isNot( isNot ),
|
2010-11-11 02:21:57 -05:00
|
|
|
m_expressionIncomplete( false )
|
2010-11-09 18:24:00 -05:00
|
|
|
{
|
2011-01-07 04:38:32 -05:00
|
|
|
if( isNot )
|
|
|
|
m_expr = "!" + m_expr;
|
2010-11-09 18:24:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ok() const
|
|
|
|
{
|
2010-11-29 14:40:44 -05:00
|
|
|
return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit;
|
2010-11-09 18:24:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
ResultWas::OfType getResultType() const
|
|
|
|
{
|
|
|
|
return m_result;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasExpression() const
|
|
|
|
{
|
|
|
|
return !m_expr.empty();
|
|
|
|
}
|
|
|
|
bool hasMessage() const
|
|
|
|
{
|
|
|
|
return !m_message.empty();
|
|
|
|
}
|
|
|
|
std::string getExpression() const
|
|
|
|
{
|
|
|
|
return m_expr;
|
|
|
|
}
|
|
|
|
std::string getExpandedExpression() const
|
|
|
|
{
|
2010-12-10 03:01:42 -05:00
|
|
|
if( !hasExpression() )
|
|
|
|
return "";
|
|
|
|
|
2010-11-11 02:21:57 -05:00
|
|
|
return m_expressionIncomplete
|
|
|
|
? getExpandedExpressionInternal() + " {can't expand the rest of the expression - consider rewriting it}"
|
|
|
|
: getExpandedExpressionInternal();
|
2010-11-09 18:24:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string getMessage() const
|
|
|
|
{
|
|
|
|
return m_message;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getFilename() const
|
|
|
|
{
|
|
|
|
return m_filename;
|
|
|
|
}
|
|
|
|
|
2010-11-11 15:56:38 -05:00
|
|
|
std::size_t getLine() const
|
2010-11-09 18:24:00 -05:00
|
|
|
{
|
|
|
|
return m_line;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string getTestMacroName() const
|
|
|
|
{
|
|
|
|
return m_macroName;
|
|
|
|
}
|
2010-11-11 02:21:57 -05:00
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string getExpandedExpressionInternal() const
|
|
|
|
{
|
|
|
|
if( m_op == "" || m_isNot )
|
|
|
|
return m_lhs.empty() ? m_expr : m_op + m_lhs;
|
|
|
|
else if( m_op != "!" )
|
|
|
|
return m_lhs + " " + m_op + " " + m_rhs;
|
|
|
|
else
|
|
|
|
return "{can't expand - use " + m_macroName + "_NOT( " + m_expr.substr(1) + " ) instead of " + m_macroName + "( " + m_expr + " ) for better diagnostics}";
|
|
|
|
}
|
2010-11-09 18:24:00 -05:00
|
|
|
|
|
|
|
protected:
|
|
|
|
std::string m_macroName;
|
|
|
|
std::string m_filename;
|
2010-11-11 15:56:38 -05:00
|
|
|
std::size_t m_line;
|
2010-11-09 18:24:00 -05:00
|
|
|
std::string m_expr, m_lhs, m_rhs, m_op;
|
|
|
|
std::string m_message;
|
|
|
|
ResultWas::OfType m_result;
|
|
|
|
bool m_isNot;
|
2010-11-11 02:21:57 -05:00
|
|
|
bool m_expressionIncomplete;
|
2010-11-09 18:24:00 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end namespace Catch
|
|
|
|
|
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|