mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 03:43:28 +01:00
Split result info from impl
This commit is contained in:
parent
fb386f458d
commit
ffe986d4ee
@ -11,7 +11,7 @@
|
||||
#include "catch_expression.hpp"
|
||||
#include "catch_resultinfo_builder.hpp"
|
||||
#include "catch_tostring.hpp"
|
||||
#include "catch_resultinfo.hpp"
|
||||
#include "catch_resultinfo.h"
|
||||
#include "catch_result_type.h"
|
||||
#include "catch_context.h"
|
||||
#include "catch_common.h"
|
||||
|
@ -6,9 +6,11 @@
|
||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
|
||||
// Collect all the implementation files together here
|
||||
// These are the equivalent of what would usually be cpp files
|
||||
#include "catch_registry_hub.hpp"
|
||||
#include "catch_notimplemented_exception.hpp"
|
||||
#include "catch_context_impl.hpp"
|
||||
#include "catch_console_colour_impl.hpp"
|
||||
#include "catch_generators_impl.hpp"
|
||||
// !TBD... migrate all impl headers here
|
||||
#include "catch_resultinfo.hpp"
|
||||
|
55
include/internal/catch_resultinfo.h
Normal file
55
include/internal/catch_resultinfo.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* 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_H_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_RESULT_INFO_H_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include "catch_result_type.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
class ResultInfo {
|
||||
public:
|
||||
ResultInfo();
|
||||
ResultInfo( const char* expr,
|
||||
ResultWas::OfType result,
|
||||
bool isNot,
|
||||
const SourceLineInfo& lineInfo,
|
||||
const char* macroName,
|
||||
const char* message );
|
||||
virtual ~ResultInfo();
|
||||
|
||||
bool ok() const;
|
||||
ResultWas::OfType getResultType() const;
|
||||
bool hasExpression() const;
|
||||
bool hasMessage() const;
|
||||
std::string getExpression() const;
|
||||
bool hasExpandedExpression() const;
|
||||
std::string getExpandedExpression() const;
|
||||
std::string getMessage() const;
|
||||
std::string getFilename() const;
|
||||
std::size_t getLine() const;
|
||||
std::string getTestMacroName() const;
|
||||
|
||||
protected:
|
||||
|
||||
std::string getExpandedExpressionInternal() const;
|
||||
bool isNotExpression( const char* expr );
|
||||
|
||||
protected:
|
||||
std::string m_macroName;
|
||||
SourceLineInfo m_lineInfo;
|
||||
std::string m_expr, m_lhs, m_rhs, m_op;
|
||||
std::string m_message;
|
||||
ResultWas::OfType m_result;
|
||||
bool m_isNot;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_RESULT_INFO_H_INCLUDED
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Created by Phil on 28/10/2010.
|
||||
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||
* Created by Phil on 8/8/12
|
||||
* Copyright 2012 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)
|
||||
@ -8,123 +8,109 @@
|
||||
#ifndef TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|
||||
#define TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include "catch_result_type.h"
|
||||
#include "catch_resultinfo.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
class ResultInfo {
|
||||
public:
|
||||
ResultInfo()
|
||||
: m_macroName(),
|
||||
m_expr(),
|
||||
m_lhs(),
|
||||
m_rhs(),
|
||||
m_op(),
|
||||
m_message(),
|
||||
m_result( ResultWas::Unknown ),
|
||||
m_isNot( false )
|
||||
ResultInfo::ResultInfo()
|
||||
: m_macroName(),
|
||||
m_expr(),
|
||||
m_lhs(),
|
||||
m_rhs(),
|
||||
m_op(),
|
||||
m_message(),
|
||||
m_result( ResultWas::Unknown ),
|
||||
m_isNot( false )
|
||||
{}
|
||||
|
||||
ResultInfo( const char* expr,
|
||||
ResultWas::OfType result,
|
||||
bool isNot,
|
||||
const SourceLineInfo& lineInfo,
|
||||
const char* macroName,
|
||||
const char* message )
|
||||
: m_macroName( macroName ),
|
||||
m_lineInfo( lineInfo ),
|
||||
m_expr( expr ),
|
||||
m_lhs(),
|
||||
m_rhs(),
|
||||
m_op( isNotExpression( expr ) ? "!" : "" ),
|
||||
m_message( message ),
|
||||
m_result( result ),
|
||||
m_isNot( isNot )
|
||||
|
||||
ResultInfo::ResultInfo(const char* expr,
|
||||
ResultWas::OfType result,
|
||||
bool isNot,
|
||||
const SourceLineInfo& lineInfo,
|
||||
const char* macroName,
|
||||
const char* message )
|
||||
: m_macroName( macroName ),
|
||||
m_lineInfo( lineInfo ),
|
||||
m_expr( expr ),
|
||||
m_lhs(),
|
||||
m_rhs(),
|
||||
m_op( isNotExpression( expr ) ? "!" : "" ),
|
||||
m_message( message ),
|
||||
m_result( result ),
|
||||
m_isNot( isNot )
|
||||
{
|
||||
if( isNot )
|
||||
m_expr = "!" + m_expr;
|
||||
}
|
||||
|
||||
virtual ~ResultInfo() {}
|
||||
|
||||
bool ok() const {
|
||||
return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit;
|
||||
}
|
||||
|
||||
ResultWas::OfType getResultType() const {
|
||||
return m_result;
|
||||
}
|
||||
|
||||
bool hasExpression() const {
|
||||
return !m_expr.empty();
|
||||
}
|
||||
|
||||
bool hasMessage() const {
|
||||
return !m_message.empty();
|
||||
}
|
||||
ResultInfo::~ResultInfo() {}
|
||||
|
||||
std::string getExpression() const {
|
||||
return m_expr;
|
||||
}
|
||||
bool ResultInfo::ok() const {
|
||||
return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit;
|
||||
}
|
||||
|
||||
bool hasExpandedExpression() const {
|
||||
return hasExpression() && getExpandedExpressionInternal() != m_expr;
|
||||
}
|
||||
|
||||
std::string getExpandedExpression() const {
|
||||
return hasExpression() ? getExpandedExpressionInternal() : "";
|
||||
}
|
||||
|
||||
std::string getMessage() const {
|
||||
return m_message;
|
||||
}
|
||||
|
||||
std::string getFilename() const {
|
||||
return m_lineInfo.file;
|
||||
}
|
||||
|
||||
std::size_t getLine() const {
|
||||
return m_lineInfo.line;
|
||||
}
|
||||
|
||||
std::string getTestMacroName() const {
|
||||
return m_macroName;
|
||||
}
|
||||
ResultWas::OfType ResultInfo::getResultType() const {
|
||||
return m_result;
|
||||
}
|
||||
|
||||
protected:
|
||||
bool ResultInfo::hasExpression() const {
|
||||
return !m_expr.empty();
|
||||
}
|
||||
|
||||
std::string getExpandedExpressionInternal() const {
|
||||
if( m_op == "" || m_isNot )
|
||||
return m_lhs.empty() ? m_expr : m_op + m_lhs;
|
||||
else if( m_op == "matches" )
|
||||
return m_lhs + " " + m_rhs;
|
||||
else if( m_op != "!" )
|
||||
{
|
||||
if( m_lhs.size() + m_rhs.size() < 30 )
|
||||
return m_lhs + " " + m_op + " " + m_rhs;
|
||||
else if( m_lhs.size() < 70 && m_rhs.size() < 70 )
|
||||
return "\n\t" + m_lhs + "\n\t" + m_op + "\n\t" + m_rhs;
|
||||
else
|
||||
return "\n" + m_lhs + "\n" + m_op + "\n" + m_rhs + "\n\n";
|
||||
}
|
||||
bool ResultInfo::hasMessage() const {
|
||||
return !m_message.empty();
|
||||
}
|
||||
|
||||
std::string ResultInfo::getExpression() const {
|
||||
return m_expr;
|
||||
}
|
||||
|
||||
bool ResultInfo::hasExpandedExpression() const {
|
||||
return hasExpression() && getExpandedExpressionInternal() != m_expr;
|
||||
}
|
||||
|
||||
std::string ResultInfo::getExpandedExpression() const {
|
||||
return hasExpression() ? getExpandedExpressionInternal() : "";
|
||||
}
|
||||
|
||||
std::string ResultInfo::getMessage() const {
|
||||
return m_message;
|
||||
}
|
||||
|
||||
std::string ResultInfo::getFilename() const {
|
||||
return m_lineInfo.file;
|
||||
}
|
||||
|
||||
std::size_t ResultInfo::getLine() const {
|
||||
return m_lineInfo.line;
|
||||
}
|
||||
|
||||
std::string ResultInfo::getTestMacroName() const {
|
||||
return m_macroName;
|
||||
}
|
||||
|
||||
std::string ResultInfo::getExpandedExpressionInternal() const {
|
||||
if( m_op == "" || m_isNot )
|
||||
return m_lhs.empty() ? m_expr : m_op + m_lhs;
|
||||
else if( m_op == "matches" )
|
||||
return m_lhs + " " + m_rhs;
|
||||
else if( m_op != "!" )
|
||||
{
|
||||
if( m_lhs.size() + m_rhs.size() < 30 )
|
||||
return m_lhs + " " + m_op + " " + m_rhs;
|
||||
else if( m_lhs.size() < 70 && m_rhs.size() < 70 )
|
||||
return "\n\t" + m_lhs + "\n\t" + m_op + "\n\t" + m_rhs;
|
||||
else
|
||||
return "{can't expand - use " + m_macroName + "_FALSE( " + m_expr.substr(1) + " ) instead of " + m_macroName + "( " + m_expr + " ) for better diagnostics}";
|
||||
return "\n" + m_lhs + "\n" + m_op + "\n" + m_rhs + "\n\n";
|
||||
}
|
||||
else
|
||||
return "{can't expand - use " + m_macroName + "_FALSE( " + m_expr.substr(1) + " ) instead of " + m_macroName + "( " + m_expr + " ) for better diagnostics}";
|
||||
}
|
||||
|
||||
bool ResultInfo::isNotExpression( const char* expr ) {
|
||||
return expr && expr[0] == '!';
|
||||
}
|
||||
|
||||
bool isNotExpression( const char* expr ) {
|
||||
return expr && expr[0] == '!';
|
||||
}
|
||||
|
||||
protected:
|
||||
std::string m_macroName;
|
||||
SourceLineInfo m_lineInfo;
|
||||
std::string m_expr, m_lhs, m_rhs, m_op;
|
||||
std::string m_message;
|
||||
ResultWas::OfType m_result;
|
||||
bool m_isNot;
|
||||
};
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
|
||||
|
@ -9,7 +9,7 @@
|
||||
#define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED
|
||||
|
||||
#include "catch_tostring.hpp"
|
||||
#include "catch_resultinfo.hpp"
|
||||
#include "catch_resultinfo.h"
|
||||
#include "catch_result_type.h"
|
||||
#include "catch_evaluate.hpp"
|
||||
#include "catch_common.h"
|
||||
|
@ -136,9 +136,6 @@ inline std::string toString( std::nullptr_t ) {
|
||||
#endif
|
||||
|
||||
#ifdef __OBJC__
|
||||
// inline std::string toString( NSString* const& nsstring ) {
|
||||
// return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
|
||||
// }
|
||||
inline std::string toString( NSString const * const& nsstring ) {
|
||||
return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
|
||||
}
|
||||
|
@ -78,7 +78,7 @@
|
||||
4A6D0C5A149B3E3D00DB3EAA /* catch_reporter_registrars.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; path = catch_reporter_registrars.hpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
||||
4A6D0C5B149B3E3D00DB3EAA /* catch_reporter_registry.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_reporter_registry.hpp; sourceTree = "<group>"; };
|
||||
4A6D0C5C149B3E3D00DB3EAA /* catch_result_type.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = catch_result_type.h; sourceTree = "<group>"; };
|
||||
4A6D0C5D149B3E3D00DB3EAA /* catch_resultinfo.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_resultinfo.hpp; sourceTree = "<group>"; };
|
||||
4A6D0C5D149B3E3D00DB3EAA /* catch_resultinfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = catch_resultinfo.h; sourceTree = "<group>"; };
|
||||
4A6D0C5E149B3E3D00DB3EAA /* catch_runner_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; path = catch_runner_impl.hpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; };
|
||||
4A6D0C5F149B3E3D00DB3EAA /* catch_section.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_section.hpp; sourceTree = "<group>"; };
|
||||
4A6D0C60149B3E3D00DB3EAA /* catch_stream.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_stream.hpp; sourceTree = "<group>"; };
|
||||
@ -91,6 +91,7 @@
|
||||
4A6D0C68149B3E3D00DB3EAA /* catch_reporter_xml.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_reporter_xml.hpp; sourceTree = "<group>"; };
|
||||
4A7ADB4314F631E10094FE10 /* catch_totals.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_totals.hpp; sourceTree = "<group>"; };
|
||||
4A90B59B15D0F61A00EF71BC /* catch_interfaces_generators.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = catch_interfaces_generators.h; sourceTree = "<group>"; };
|
||||
4A90B59D15D24FE900EF71BC /* catch_resultinfo.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_resultinfo.hpp; sourceTree = "<group>"; };
|
||||
4A9D84B11558FC0400FBB209 /* catch_tostring.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_tostring.hpp; sourceTree = "<group>"; };
|
||||
4A9D84B315599AC900FBB209 /* catch_resultinfo_builder.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = catch_resultinfo_builder.hpp; sourceTree = "<group>"; };
|
||||
4AB1C73514F97BDA00F31DF7 /* catch_console_colour_impl.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = catch_console_colour_impl.hpp; sourceTree = "<group>"; };
|
||||
@ -202,6 +203,7 @@
|
||||
4AC91CB4155B9EBF00DC5117 /* impl */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
4A4B0F9C15CEFA8300AE2392 /* catch_impl.hpp */,
|
||||
4A4B0F9715CE6CFB00AE2392 /* catch_registry_hub.hpp */,
|
||||
4A6D0C50149B3E3D00DB3EAA /* catch_generators_impl.hpp */,
|
||||
4A6D0C52149B3E3D00DB3EAA /* catch_context_impl.hpp */,
|
||||
@ -209,7 +211,7 @@
|
||||
4A6D0C62149B3E3D00DB3EAA /* catch_test_case_registry_impl.hpp */,
|
||||
4AB1C73514F97BDA00F31DF7 /* catch_console_colour_impl.hpp */,
|
||||
4A4B0F9B15CEF8C400AE2392 /* catch_notimplemented_exception.hpp */,
|
||||
4A4B0F9C15CEFA8300AE2392 /* catch_impl.hpp */,
|
||||
4A90B59D15D24FE900EF71BC /* catch_resultinfo.hpp */,
|
||||
);
|
||||
name = impl;
|
||||
sourceTree = "<group>";
|
||||
@ -220,7 +222,7 @@
|
||||
4A6D0C4D149B3E3D00DB3EAA /* catch_evaluate.hpp */,
|
||||
4A6D0C4F149B3E3D00DB3EAA /* catch_generators.hpp */,
|
||||
4A6D0C5C149B3E3D00DB3EAA /* catch_result_type.h */,
|
||||
4A6D0C5D149B3E3D00DB3EAA /* catch_resultinfo.hpp */,
|
||||
4A6D0C5D149B3E3D00DB3EAA /* catch_resultinfo.h */,
|
||||
4A9D84B315599AC900FBB209 /* catch_resultinfo_builder.hpp */,
|
||||
4A6D0C5F149B3E3D00DB3EAA /* catch_section.hpp */,
|
||||
4A3D7DD01503869D005F9203 /* catch_matchers.hpp */,
|
||||
|
Loading…
Reference in New Issue
Block a user