catch2/internal/catch_resultinfo.hpp

180 lines
4.9 KiB
C++
Raw Normal View History

2010-11-10 00:24:00 +01: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 10:13:31 +01:00
#include "catch_result_type.h"
2010-11-10 00:24:00 +01:00
namespace Catch
{
class ResultInfo
{
public:
2011-01-11 20:48:48 +01:00
///////////////////////////////////////////////////////////////////////////
2011-01-28 19:56:26 +01:00
ResultInfo
()
: m_line( 0 ),
m_result( ResultWas::Unknown ),
2010-11-10 00:24:00 +01:00
m_isNot( false ),
m_expressionIncomplete( false )
2010-11-10 00:24:00 +01:00
{}
2011-01-11 20:48:48 +01:00
///////////////////////////////////////////////////////////////////////////
ResultInfo
(
const char* expr,
ResultWas::OfType result,
bool isNot,
const char* filename,
std::size_t line,
const char* macroName
)
: m_macroName( macroName ),
m_filename( filename ),
m_line( line ),
m_expr( expr ),
m_op( isNotExpression( expr ) ? "!" : "" ),
2010-11-10 00:24:00 +01:00
m_result( result ),
m_isNot( isNot ),
m_expressionIncomplete( false )
2010-11-10 00:24:00 +01:00
{
if( isNot )
m_expr = "!" + m_expr;
2010-11-10 00:24:00 +01:00
}
2011-01-11 20:48:48 +01:00
///////////////////////////////////////////////////////////////////////////
2011-01-28 19:56:26 +01:00
bool ok
()
const
2010-11-10 00:24:00 +01:00
{
return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit;
2010-11-10 00:24:00 +01:00
}
2011-01-11 20:48:48 +01:00
///////////////////////////////////////////////////////////////////////////
2011-01-28 19:56:26 +01:00
ResultWas::OfType getResultType
()
const
2010-11-10 00:24:00 +01:00
{
return m_result;
}
2011-01-11 20:48:48 +01:00
///////////////////////////////////////////////////////////////////////////
2011-01-28 19:56:26 +01:00
bool hasExpression
()
const
2010-11-10 00:24:00 +01:00
{
return !m_expr.empty();
}
2011-01-11 20:48:48 +01:00
///////////////////////////////////////////////////////////////////////////
2011-01-28 19:56:26 +01:00
bool hasMessage
()
const
2010-11-10 00:24:00 +01:00
{
return !m_message.empty();
}
2011-01-11 20:48:48 +01:00
///////////////////////////////////////////////////////////////////////////
2011-01-28 19:56:26 +01:00
std::string getExpression
()
const
2010-11-10 00:24:00 +01:00
{
return m_expr;
}
2011-01-11 20:48:48 +01:00
///////////////////////////////////////////////////////////////////////////
2011-01-28 19:56:26 +01:00
std::string getExpandedExpression
()
const
2010-11-10 00:24:00 +01:00
{
2010-12-10 09:01:42 +01:00
if( !hasExpression() )
return "";
return m_expressionIncomplete
? getExpandedExpressionInternal() + " {can't expand the rest of the expression - consider rewriting it}"
: getExpandedExpressionInternal();
2010-11-10 00:24:00 +01:00
}
2011-01-11 20:48:48 +01:00
///////////////////////////////////////////////////////////////////////////
2011-01-28 19:56:26 +01:00
std::string getMessage
()
const
2010-11-10 00:24:00 +01:00
{
return m_message;
}
2011-01-11 20:48:48 +01:00
///////////////////////////////////////////////////////////////////////////
2011-01-28 19:56:26 +01:00
std::string getFilename
()
const
2010-11-10 00:24:00 +01:00
{
return m_filename;
}
2011-01-11 20:48:48 +01:00
///////////////////////////////////////////////////////////////////////////
2011-01-28 19:56:26 +01:00
std::size_t getLine
()
const
2010-11-10 00:24:00 +01:00
{
return m_line;
}
2011-01-11 20:48:48 +01:00
///////////////////////////////////////////////////////////////////////////
2011-01-28 19:56:26 +01:00
std::string getTestMacroName
()
const
2010-11-10 00:24:00 +01:00
{
return m_macroName;
}
protected:
2011-01-11 20:48:48 +01:00
///////////////////////////////////////////////////////////////////////////
2011-01-28 19:56:26 +01:00
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}";
}
///////////////////////////////////////////////////////////////////////////
bool isNotExpression
(
const char* expr
)
{
return expr && expr[0] == '!';
}
2010-11-10 00:24:00 +01:00
protected:
std::string m_macroName;
std::string m_filename;
std::size_t m_line;
2010-11-10 00:24:00 +01:00
std::string m_expr, m_lhs, m_rhs, m_op;
std::string m_message;
ResultWas::OfType m_result;
bool m_isNot;
bool m_expressionIncomplete;
2010-11-10 00:24:00 +01:00
};
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED