Split result info from impl

This commit is contained in:
Phil Nash 2012-08-08 08:50:38 +01:00
parent fb386f458d
commit ffe986d4ee
7 changed files with 154 additions and 112 deletions

View File

@ -11,7 +11,7 @@
#include "catch_expression.hpp" #include "catch_expression.hpp"
#include "catch_resultinfo_builder.hpp" #include "catch_resultinfo_builder.hpp"
#include "catch_tostring.hpp" #include "catch_tostring.hpp"
#include "catch_resultinfo.hpp" #include "catch_resultinfo.h"
#include "catch_result_type.h" #include "catch_result_type.h"
#include "catch_context.h" #include "catch_context.h"
#include "catch_common.h" #include "catch_common.h"

View File

@ -6,9 +6,11 @@
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) * 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_registry_hub.hpp"
#include "catch_notimplemented_exception.hpp" #include "catch_notimplemented_exception.hpp"
#include "catch_context_impl.hpp" #include "catch_context_impl.hpp"
#include "catch_console_colour_impl.hpp" #include "catch_console_colour_impl.hpp"
#include "catch_generators_impl.hpp" #include "catch_generators_impl.hpp"
// !TBD... migrate all impl headers here #include "catch_resultinfo.hpp"

View 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

View File

@ -1,6 +1,6 @@
/* /*
* Created by Phil on 28/10/2010. * Created by Phil on 8/8/12
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved. * Copyright 2012 Two Blue Cubes Ltd. All rights reserved.
* *
* Distributed under the Boost Software License, Version 1.0. (See accompanying * 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) * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@ -8,14 +8,11 @@
#ifndef TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED #define TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED
#include <string> #include "catch_resultinfo.h"
#include "catch_result_type.h"
namespace Catch { namespace Catch {
class ResultInfo { ResultInfo::ResultInfo()
public:
ResultInfo()
: m_macroName(), : m_macroName(),
m_expr(), m_expr(),
m_lhs(), m_lhs(),
@ -26,7 +23,7 @@ namespace Catch {
m_isNot( false ) m_isNot( false )
{} {}
ResultInfo( const char* expr, ResultInfo::ResultInfo(const char* expr,
ResultWas::OfType result, ResultWas::OfType result,
bool isNot, bool isNot,
const SourceLineInfo& lineInfo, const SourceLineInfo& lineInfo,
@ -46,55 +43,53 @@ namespace Catch {
m_expr = "!" + m_expr; m_expr = "!" + m_expr;
} }
virtual ~ResultInfo() {} ResultInfo::~ResultInfo() {}
bool ok() const { bool ResultInfo::ok() const {
return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit; return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit;
} }
ResultWas::OfType getResultType() const { ResultWas::OfType ResultInfo::getResultType() const {
return m_result; return m_result;
} }
bool hasExpression() const { bool ResultInfo::hasExpression() const {
return !m_expr.empty(); return !m_expr.empty();
} }
bool hasMessage() const { bool ResultInfo::hasMessage() const {
return !m_message.empty(); return !m_message.empty();
} }
std::string getExpression() const { std::string ResultInfo::getExpression() const {
return m_expr; return m_expr;
} }
bool hasExpandedExpression() const { bool ResultInfo::hasExpandedExpression() const {
return hasExpression() && getExpandedExpressionInternal() != m_expr; return hasExpression() && getExpandedExpressionInternal() != m_expr;
} }
std::string getExpandedExpression() const { std::string ResultInfo::getExpandedExpression() const {
return hasExpression() ? getExpandedExpressionInternal() : ""; return hasExpression() ? getExpandedExpressionInternal() : "";
} }
std::string getMessage() const { std::string ResultInfo::getMessage() const {
return m_message; return m_message;
} }
std::string getFilename() const { std::string ResultInfo::getFilename() const {
return m_lineInfo.file; return m_lineInfo.file;
} }
std::size_t getLine() const { std::size_t ResultInfo::getLine() const {
return m_lineInfo.line; return m_lineInfo.line;
} }
std::string getTestMacroName() const { std::string ResultInfo::getTestMacroName() const {
return m_macroName; return m_macroName;
} }
protected: std::string ResultInfo::getExpandedExpressionInternal() const {
std::string getExpandedExpressionInternal() const {
if( m_op == "" || m_isNot ) if( m_op == "" || m_isNot )
return m_lhs.empty() ? m_expr : m_op + m_lhs; return m_lhs.empty() ? m_expr : m_op + m_lhs;
else if( m_op == "matches" ) else if( m_op == "matches" )
@ -112,19 +107,10 @@ namespace Catch {
return "{can't expand - use " + m_macroName + "_FALSE( " + m_expr.substr(1) + " ) instead of " + m_macroName + "( " + m_expr + " ) for better diagnostics}"; return "{can't expand - use " + m_macroName + "_FALSE( " + m_expr.substr(1) + " ) instead of " + m_macroName + "( " + m_expr + " ) for better diagnostics}";
} }
bool isNotExpression( const char* expr ) { bool ResultInfo::isNotExpression( const char* expr ) {
return expr && expr[0] == '!'; 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 } // end namespace Catch
#endif // TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED #endif // TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED

View File

@ -9,7 +9,7 @@
#define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED #define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED
#include "catch_tostring.hpp" #include "catch_tostring.hpp"
#include "catch_resultinfo.hpp" #include "catch_resultinfo.h"
#include "catch_result_type.h" #include "catch_result_type.h"
#include "catch_evaluate.hpp" #include "catch_evaluate.hpp"
#include "catch_common.h" #include "catch_common.h"

View File

@ -136,9 +136,6 @@ inline std::string toString( std::nullptr_t ) {
#endif #endif
#ifdef __OBJC__ #ifdef __OBJC__
// inline std::string toString( NSString* const& nsstring ) {
// return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
// }
inline std::string toString( NSString const * const& nsstring ) { inline std::string toString( NSString const * const& nsstring ) {
return std::string( "@\"" ) + [nsstring UTF8String] + "\""; return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
} }

View File

@ -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; }; 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>"; }; 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>"; }; 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; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; 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>"; }; 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 */ = { 4AC91CB4155B9EBF00DC5117 /* impl */ = {
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
4A4B0F9C15CEFA8300AE2392 /* catch_impl.hpp */,
4A4B0F9715CE6CFB00AE2392 /* catch_registry_hub.hpp */, 4A4B0F9715CE6CFB00AE2392 /* catch_registry_hub.hpp */,
4A6D0C50149B3E3D00DB3EAA /* catch_generators_impl.hpp */, 4A6D0C50149B3E3D00DB3EAA /* catch_generators_impl.hpp */,
4A6D0C52149B3E3D00DB3EAA /* catch_context_impl.hpp */, 4A6D0C52149B3E3D00DB3EAA /* catch_context_impl.hpp */,
@ -209,7 +211,7 @@
4A6D0C62149B3E3D00DB3EAA /* catch_test_case_registry_impl.hpp */, 4A6D0C62149B3E3D00DB3EAA /* catch_test_case_registry_impl.hpp */,
4AB1C73514F97BDA00F31DF7 /* catch_console_colour_impl.hpp */, 4AB1C73514F97BDA00F31DF7 /* catch_console_colour_impl.hpp */,
4A4B0F9B15CEF8C400AE2392 /* catch_notimplemented_exception.hpp */, 4A4B0F9B15CEF8C400AE2392 /* catch_notimplemented_exception.hpp */,
4A4B0F9C15CEFA8300AE2392 /* catch_impl.hpp */, 4A90B59D15D24FE900EF71BC /* catch_resultinfo.hpp */,
); );
name = impl; name = impl;
sourceTree = "<group>"; sourceTree = "<group>";
@ -220,7 +222,7 @@
4A6D0C4D149B3E3D00DB3EAA /* catch_evaluate.hpp */, 4A6D0C4D149B3E3D00DB3EAA /* catch_evaluate.hpp */,
4A6D0C4F149B3E3D00DB3EAA /* catch_generators.hpp */, 4A6D0C4F149B3E3D00DB3EAA /* catch_generators.hpp */,
4A6D0C5C149B3E3D00DB3EAA /* catch_result_type.h */, 4A6D0C5C149B3E3D00DB3EAA /* catch_result_type.h */,
4A6D0C5D149B3E3D00DB3EAA /* catch_resultinfo.hpp */, 4A6D0C5D149B3E3D00DB3EAA /* catch_resultinfo.h */,
4A9D84B315599AC900FBB209 /* catch_resultinfo_builder.hpp */, 4A9D84B315599AC900FBB209 /* catch_resultinfo_builder.hpp */,
4A6D0C5F149B3E3D00DB3EAA /* catch_section.hpp */, 4A6D0C5F149B3E3D00DB3EAA /* catch_section.hpp */,
4A3D7DD01503869D005F9203 /* catch_matchers.hpp */, 4A3D7DD01503869D005F9203 /* catch_matchers.hpp */,