catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Recreated the single include test project and got it working after impl refactorings
- Commit
3b80af7a060e6a20b15265267a26a234777b2398- Author
- Phil Nash ·
- Parents
c436a4dac153
Changes
glueHeaders.py | 2 +- include/internal/catch_interfaces_registry_hub.h | 6 +- projects/SelfTest/catch_self_test.hpp | 5 + .../CatchSelfTest.xcodeproj/project.pbxproj | 2 +- projects/XCode4/CatchSelfTest/CatchSelfTestSingle | 1 + .../CatchSelfTestSingle.xcodeproj/project.pbxproj | 253 -- .../project.xcworkspace/contents.xcworkspacedata | 7 - single_include/catch.hpp | 3466 +++++++++++--------- 8 files changed, 1842 insertions(+), 1900 deletions(-) diff --git a/glueHeaders.py b/glueHeaders.py index f9202e63..11c1ab75 100644 --- a/glueHeaders.py +++ b/glueHeaders.py @@ -30,7 +30,7 @@ def parseFile( path, filename ): parseFile( path + headerPath + sep, headerFile ) else: parseFile( rootPath + headerPath + sep, headerFile ) - elif not guardParser.match( line ) and not commentParser1.match( line )and not commentParser2.match( line ): + elif (not guardParser.match( line ) or defineParser.match( line ) ) and not commentParser1.match( line )and not commentParser2.match( line ): if blankParser.match( line ): blanks = blanks + 1 else: diff --git a/include/internal/catch_interfaces_registry_hub.h b/include/internal/catch_interfaces_registry_hub.h index c4cbe940..e935340f 100644 --- a/include/internal/catch_interfaces_registry_hub.h +++ b/include/internal/catch_interfaces_registry_hub.h @@ -5,8 +5,8 @@ * 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_STATIC_REGISTRIES_H_INCLUDED -#define TWOBLUECUBES_CATCH_STATIC_REGISTRIES_H_INCLUDED +#ifndef TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED +#define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED #include "catch_interfaces_reporter.h" #include "catch_interfaces_config.h" @@ -43,4 +43,4 @@ namespace Catch { void cleanUp(); } -#endif // TWOBLUECUBES_CATCH_STATIC_REGISTRIES_H_INCLUDED +#endif // TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED diff --git a/projects/SelfTest/catch_self_test.hpp b/projects/SelfTest/catch_self_test.hpp index 78d10c2e..1b79a44f 100644 --- a/projects/SelfTest/catch_self_test.hpp +++ b/projects/SelfTest/catch_self_test.hpp @@ -9,7 +9,12 @@ #define TWOBLUECUBES_CATCH_SELF_TEST_HPP_INCLUDED #include "catch.hpp" + +// Use this external guard here as if we're using the single header version +// this will already be defined +#ifndef TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED #include "catch_interfaces_registry_hub.h" +#endif #include "set" diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj index 7dc83475..ac89c59a 100644 --- a/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj +++ b/projects/XCode4/CatchSelfTest/CatchSelfTest.xcodeproj/project.pbxproj @@ -43,7 +43,7 @@ 4A6D0C20149B3D3B00DB3EAA /* CatchSelfTest */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = CatchSelfTest; sourceTree = BUILT_PRODUCTS_DIR; }; 4A6D0C26149B3D3B00DB3EAA /* CatchSelfTest.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = CatchSelfTest.1; sourceTree = "<group>"; }; 4A6D0C2D149B3D9E00DB3EAA /* ApproxTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ApproxTests.cpp; path = ../../../SelfTest/ApproxTests.cpp; sourceTree = "<group>"; }; - 4A6D0C2E149B3D9E00DB3EAA /* catch_self_test.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; name = catch_self_test.hpp; path = ../../../SelfTest/catch_self_test.hpp; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.cpp; }; + 4A6D0C2E149B3D9E00DB3EAA /* catch_self_test.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; lineEnding = 0; name = catch_self_test.hpp; path = ../../../SelfTest/catch_self_test.hpp; sourceTree = "<group>"; }; 4A6D0C2F149B3D9E00DB3EAA /* ClassTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClassTests.cpp; path = ../../../SelfTest/ClassTests.cpp; sourceTree = "<group>"; }; 4A6D0C30149B3D9E00DB3EAA /* ConditionTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ConditionTests.cpp; path = ../../../SelfTest/ConditionTests.cpp; sourceTree = "<group>"; }; 4A6D0C31149B3D9E00DB3EAA /* ExceptionTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ExceptionTests.cpp; path = ../../../SelfTest/ExceptionTests.cpp; sourceTree = "<group>"; }; diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTestSingle b/projects/XCode4/CatchSelfTest/CatchSelfTestSingle new file mode 160000 index 00000000..e5537a9f --- /dev/null +++ b/projects/XCode4/CatchSelfTest/CatchSelfTestSingle @@ -0,0 +1 @@ +Subproject commit e5537a9fb952db3f16b533ea0964ed7c6ad30964 diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTestSingle.xcodeproj/project.pbxproj b/projects/XCode4/CatchSelfTest/CatchSelfTestSingle.xcodeproj/project.pbxproj deleted file mode 100644 index cc597429..00000000 --- a/projects/XCode4/CatchSelfTest/CatchSelfTestSingle.xcodeproj/project.pbxproj +++ /dev/null @@ -1,253 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 4A9D84DC155AEA2D00FBB209 /* ApproxTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A9D84D1155AEA2D00FBB209 /* ApproxTests.cpp */; }; - 4A9D84DD155AEA2D00FBB209 /* catch_self_test.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A9D84D2155AEA2D00FBB209 /* catch_self_test.cpp */; }; - 4A9D84DE155AEA2D00FBB209 /* ClassTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A9D84D4155AEA2D00FBB209 /* ClassTests.cpp */; }; - 4A9D84DF155AEA2D00FBB209 /* ConditionTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A9D84D5155AEA2D00FBB209 /* ConditionTests.cpp */; }; - 4A9D84E0155AEA2D00FBB209 /* ExceptionTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A9D84D6155AEA2D00FBB209 /* ExceptionTests.cpp */; }; - 4A9D84E1155AEA2D00FBB209 /* GeneratorTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A9D84D7155AEA2D00FBB209 /* GeneratorTests.cpp */; }; - 4A9D84E2155AEA2D00FBB209 /* MessageTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A9D84D8155AEA2D00FBB209 /* MessageTests.cpp */; }; - 4A9D84E3155AEA2D00FBB209 /* MiscTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A9D84D9155AEA2D00FBB209 /* MiscTests.cpp */; }; - 4A9D84E4155AEA2D00FBB209 /* TestMain.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A9D84DA155AEA2D00FBB209 /* TestMain.cpp */; }; - 4A9D84E5155AEA2D00FBB209 /* TrickyTests.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4A9D84DB155AEA2D00FBB209 /* TrickyTests.cpp */; }; -/* End PBXBuildFile section */ - -/* Begin PBXCopyFilesBuildPhase section */ - 4A9D84BD155AE9C200FBB209 /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = /usr/share/man/man1/; - dstSubfolderSpec = 0; - files = ( - ); - runOnlyForDeploymentPostprocessing = 1; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - 4A9D84BF155AE9C200FBB209 /* CatchSelfTestSingle */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = CatchSelfTestSingle; sourceTree = BUILT_PRODUCTS_DIR; }; - 4A9D84D1155AEA2D00FBB209 /* ApproxTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ApproxTests.cpp; path = ../../../SelfTest/ApproxTests.cpp; sourceTree = "<group>"; }; - 4A9D84D2155AEA2D00FBB209 /* catch_self_test.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = catch_self_test.cpp; path = ../../../SelfTest/catch_self_test.cpp; sourceTree = "<group>"; }; - 4A9D84D3155AEA2D00FBB209 /* catch_self_test.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = catch_self_test.hpp; path = ../../../SelfTest/catch_self_test.hpp; sourceTree = "<group>"; }; - 4A9D84D4155AEA2D00FBB209 /* ClassTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ClassTests.cpp; path = ../../../SelfTest/ClassTests.cpp; sourceTree = "<group>"; }; - 4A9D84D5155AEA2D00FBB209 /* ConditionTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ConditionTests.cpp; path = ../../../SelfTest/ConditionTests.cpp; sourceTree = "<group>"; }; - 4A9D84D6155AEA2D00FBB209 /* ExceptionTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ExceptionTests.cpp; path = ../../../SelfTest/ExceptionTests.cpp; sourceTree = "<group>"; }; - 4A9D84D7155AEA2D00FBB209 /* GeneratorTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = GeneratorTests.cpp; path = ../../../SelfTest/GeneratorTests.cpp; sourceTree = "<group>"; }; - 4A9D84D8155AEA2D00FBB209 /* MessageTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MessageTests.cpp; path = ../../../SelfTest/MessageTests.cpp; sourceTree = "<group>"; }; - 4A9D84D9155AEA2D00FBB209 /* MiscTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MiscTests.cpp; path = ../../../SelfTest/MiscTests.cpp; sourceTree = "<group>"; }; - 4A9D84DA155AEA2D00FBB209 /* TestMain.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TestMain.cpp; path = ../../../SelfTest/TestMain.cpp; sourceTree = "<group>"; }; - 4A9D84DB155AEA2D00FBB209 /* TrickyTests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TrickyTests.cpp; path = ../../../SelfTest/TrickyTests.cpp; sourceTree = "<group>"; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 4A9D84BC155AE9C200FBB209 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 4A9D84B4155AE9C200FBB209 = { - isa = PBXGroup; - children = ( - 4A9D84C2155AE9C200FBB209 /* CatchSelfTestSingle */, - 4A9D84C0155AE9C200FBB209 /* Products */, - ); - sourceTree = "<group>"; - }; - 4A9D84C0155AE9C200FBB209 /* Products */ = { - isa = PBXGroup; - children = ( - 4A9D84BF155AE9C200FBB209 /* CatchSelfTestSingle */, - ); - name = Products; - sourceTree = "<group>"; - }; - 4A9D84C2155AE9C200FBB209 /* CatchSelfTestSingle */ = { - isa = PBXGroup; - children = ( - 4A9D84D2155AEA2D00FBB209 /* catch_self_test.cpp */, - 4A9D84D3155AEA2D00FBB209 /* catch_self_test.hpp */, - 4A9D84DA155AEA2D00FBB209 /* TestMain.cpp */, - 4A9D84E6155AEA3200FBB209 /* Tests */, - ); - path = CatchSelfTestSingle; - sourceTree = "<group>"; - }; - 4A9D84E6155AEA3200FBB209 /* Tests */ = { - isa = PBXGroup; - children = ( - 4A9D84D1155AEA2D00FBB209 /* ApproxTests.cpp */, - 4A9D84D4155AEA2D00FBB209 /* ClassTests.cpp */, - 4A9D84D5155AEA2D00FBB209 /* ConditionTests.cpp */, - 4A9D84D6155AEA2D00FBB209 /* ExceptionTests.cpp */, - 4A9D84D7155AEA2D00FBB209 /* GeneratorTests.cpp */, - 4A9D84D8155AEA2D00FBB209 /* MessageTests.cpp */, - 4A9D84D9155AEA2D00FBB209 /* MiscTests.cpp */, - 4A9D84DB155AEA2D00FBB209 /* TrickyTests.cpp */, - ); - name = Tests; - sourceTree = "<group>"; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 4A9D84BE155AE9C200FBB209 /* CatchSelfTestSingle */ = { - isa = PBXNativeTarget; - buildConfigurationList = 4A9D84C9155AE9C200FBB209 /* Build configuration list for PBXNativeTarget "CatchSelfTestSingle" */; - buildPhases = ( - 4A9D84BB155AE9C200FBB209 /* Sources */, - 4A9D84BC155AE9C200FBB209 /* Frameworks */, - 4A9D84BD155AE9C200FBB209 /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = CatchSelfTestSingle; - productName = CatchSelfTestSingle; - productReference = 4A9D84BF155AE9C200FBB209 /* CatchSelfTestSingle */; - productType = "com.apple.product-type.tool"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 4A9D84B6155AE9C200FBB209 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0430; - }; - buildConfigurationList = 4A9D84B9155AE9C200FBB209 /* Build configuration list for PBXProject "CatchSelfTestSingle" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 4A9D84B4155AE9C200FBB209; - productRefGroup = 4A9D84C0155AE9C200FBB209 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 4A9D84BE155AE9C200FBB209 /* CatchSelfTestSingle */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - 4A9D84BB155AE9C200FBB209 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 4A9D84DC155AEA2D00FBB209 /* ApproxTests.cpp in Sources */, - 4A9D84DD155AEA2D00FBB209 /* catch_self_test.cpp in Sources */, - 4A9D84DE155AEA2D00FBB209 /* ClassTests.cpp in Sources */, - 4A9D84DF155AEA2D00FBB209 /* ConditionTests.cpp in Sources */, - 4A9D84E0155AEA2D00FBB209 /* ExceptionTests.cpp in Sources */, - 4A9D84E1155AEA2D00FBB209 /* GeneratorTests.cpp in Sources */, - 4A9D84E2155AEA2D00FBB209 /* MessageTests.cpp in Sources */, - 4A9D84E3155AEA2D00FBB209 /* MiscTests.cpp in Sources */, - 4A9D84E4155AEA2D00FBB209 /* TestMain.cpp in Sources */, - 4A9D84E5155AEA2D00FBB209 /* TrickyTests.cpp in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 4A9D84C7155AE9C200FBB209 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - COPY_PHASE_STRIP = NO; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_SYMBOLS_PRIVATE_EXTERN = NO; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.7; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = macosx; - }; - name = Debug; - }; - 4A9D84C8155AE9C200FBB209 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - ARCHS = "$(ARCHS_STANDARD_64_BIT)"; - COPY_PHASE_STRIP = YES; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_ENABLE_OBJC_EXCEPTIONS = YES; - GCC_VERSION = com.apple.compilers.llvm.clang.1_0; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - MACOSX_DEPLOYMENT_TARGET = 10.7; - SDKROOT = macosx; - }; - name = Release; - }; - 4A9D84CA155AE9C200FBB209 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - HEADER_SEARCH_PATHS = ../../../single_include; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Debug; - }; - 4A9D84CB155AE9C200FBB209 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - HEADER_SEARCH_PATHS = ../../../single_include; - PRODUCT_NAME = "$(TARGET_NAME)"; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 4A9D84B9155AE9C200FBB209 /* Build configuration list for PBXProject "CatchSelfTestSingle" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 4A9D84C7155AE9C200FBB209 /* Debug */, - 4A9D84C8155AE9C200FBB209 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 4A9D84C9155AE9C200FBB209 /* Build configuration list for PBXNativeTarget "CatchSelfTestSingle" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 4A9D84CA155AE9C200FBB209 /* Debug */, - 4A9D84CB155AE9C200FBB209 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 4A9D84B6155AE9C200FBB209 /* Project object */; -} diff --git a/projects/XCode4/CatchSelfTest/CatchSelfTestSingle.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/projects/XCode4/CatchSelfTest/CatchSelfTestSingle.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 4fcfc0e6..00000000 --- a/projects/XCode4/CatchSelfTest/CatchSelfTestSingle.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<Workspace - version = "1.0"> - <FileRef - location = "self:CatchSelfTestSingle.xcodeproj"> - </FileRef> -</Workspace> diff --git a/single_include/catch.hpp b/single_include/catch.hpp index 2ded49bd..c8a405a6 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -1,5 +1,5 @@ /* - * Generated: 2012-08-01 08:15:06.796335 + * Generated: 2012-08-09 07:45:58.677223 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. @@ -10,11 +10,13 @@ #ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED #define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED -// #included from: internal/catch_context.h +#define TWOBLUECUBES_CATCH_HPP_INCLUDED -// #included from: catch_interfaces_reporter.h +// #included from: internal/catch_notimplemented_exception.h +#define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED // #included from: catch_common.h +#define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) @@ -134,7 +136,37 @@ namespace Catch { #define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, __LINE__ ) //#endif +#include <ostream> + +namespace Catch { + + class NotImplementedException : public std::exception + { + public: + NotImplementedException( const SourceLineInfo& lineInfo ); + + virtual ~NotImplementedException() throw() {} + + virtual const char* what() const throw(); + + private: + std::string m_what; + SourceLineInfo m_lineInfo; + }; + +} // end namespace Catch + +/////////////////////////////////////////////////////////////////////////////// +#define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO ) + +// #included from: internal/catch_context.h +#define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED + +// #included from: catch_interfaces_reporter.h +#define TWOBLUECUBES_CATCH_IREPORTERREGISTRY_INCLUDED + // #included from: catch_totals.hpp +#define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED namespace Catch { @@ -185,6 +217,7 @@ namespace Catch { } // #included from: catch_ptr.hpp +#define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED namespace Catch { @@ -323,7 +356,6 @@ namespace Catch virtual ~IReporterRegistry() {} virtual IReporter* create( const std::string& name, const ReporterConfig& config ) const = 0; - virtual void registerReporter( const std::string& name, IReporterFactory* factory ) = 0; virtual const FactoryMap& getFactories() const = 0; }; @@ -336,6 +368,7 @@ namespace Catch } // #included from: catch_interfaces_config.h +#define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED namespace Catch { @@ -347,6 +380,30 @@ namespace Catch { }; } +// #included from: catch_interfaces_generators.h +#define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED + +#include <string> + +namespace Catch { + + struct IGeneratorInfo { + virtual ~IGeneratorInfo(){} + virtual bool moveNext() = 0; + virtual std::size_t getCurrentIndex() const = 0; + }; + + struct IGeneratorsForTest { + virtual ~IGeneratorsForTest() {} + + virtual IGeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) = 0; + virtual bool moveNext() = 0; + }; + + IGeneratorsForTest* createGeneratorsForTest(); + +} // end namespace Catch + #include <memory> #include <vector> #include <stdlib.h> @@ -355,10 +412,8 @@ namespace Catch { class TestCaseInfo; struct IResultCapture; - struct ITestCaseRegistry; struct IRunner; - struct IExceptionTranslatorRegistry; - class GeneratorsForTest; + struct IGeneratorsForTest; class StreamBufBase : public std::streambuf{}; @@ -368,9 +423,6 @@ namespace Catch { virtual IResultCapture& getResultCapture() = 0; virtual IRunner& getRunner() = 0; - virtual IReporterRegistry& getReporterRegistry() = 0; - virtual ITestCaseRegistry& getTestCaseRegistry() = 0; - virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0; virtual size_t getGeneratorIndex( const std::string& fileInfo, size_t totalSize ) = 0; virtual bool advanceGeneratorsForCurrentTest() = 0; virtual const IConfig* getConfig() const = 0; @@ -385,52 +437,16 @@ namespace Catch { IContext& getCurrentContext(); IMutableContext& getCurrentMutableContext(); + void cleanUpContext(); + std::streambuf* createStreamBuf( const std::string& streamName ); - class Context : public IMutableContext { - - Context(); - Context( const Context& ); - void operator=( const Context& ); - - public: // IContext - virtual IResultCapture& getResultCapture(); - virtual IRunner& getRunner(); - virtual IReporterRegistry& getReporterRegistry(); - virtual ITestCaseRegistry& getTestCaseRegistry(); - virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry(); - virtual size_t getGeneratorIndex( const std::string& fileInfo, size_t totalSize ); - virtual bool advanceGeneratorsForCurrentTest(); - virtual const IConfig* getConfig() const; - - public: // IMutableContext - virtual void setResultCapture( IResultCapture* resultCapture ); - virtual void setRunner( IRunner* runner ); - virtual void setConfig( const IConfig* config ); - - public: // Statics - static std::streambuf* createStreamBuf( const std::string& streamName ); - static void cleanUp(); - - friend IMutableContext& getCurrentMutableContext(); - - private: - GeneratorsForTest* findGeneratorsForCurrentTest(); - GeneratorsForTest& getGeneratorsForCurrentTest(); - - private: - std::auto_ptr<IReporterRegistry> m_reporterRegistry; - std::auto_ptr<ITestCaseRegistry> m_testCaseRegistry; - std::auto_ptr<IExceptionTranslatorRegistry> m_exceptionTranslatorRegistry; - IRunner* m_runner; - IResultCapture* m_resultCapture; - const IConfig* m_config; - std::map<std::string, GeneratorsForTest*> m_generatorsByTestName; - }; } // #included from: internal/catch_test_registry.hpp +#define TWOBLUECUBES_CATCH_REGISTRY_HPP_INCLUDED // #included from: catch_interfaces_testcase.h +#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED #include <vector> @@ -447,9 +463,8 @@ namespace Catch { struct ITestCaseRegistry { virtual ~ITestCaseRegistry(){} - virtual void registerTest( const TestCaseInfo& testInfo ) = 0; virtual const std::vector<TestCaseInfo>& getAllTests() const = 0; - virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) = 0; + virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) const = 0; }; } @@ -542,19 +557,25 @@ private: void INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ )::test() // #included from: internal/catch_capture.hpp +#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED // #included from: catch_expression_builder.hpp +#define TWOBLUECUBES_CATCH_EXPRESSION_BUILDER_HPP_INCLUDED // #included from: catch_expression.hpp +#define TWOBLUECUBES_CATCH_EXPRESSION_HPP_INCLUDED -// #included from: catch_resultinfo_builder.hpp +// #included from: catch_resultinfo_builder.h +#define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_H_INCLUDED // #included from: catch_tostring.hpp +#define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED #include <sstream> #ifdef __OBJC__ // #included from: catch_objc_arc.hpp +#define TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED #import <Foundation/Foundation.h> @@ -715,9 +736,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] + "\""; } @@ -731,10 +749,12 @@ inline std::string toString( std::nullptr_t ) { } // end namespace Catch -// #included from: catch_resultinfo.hpp +// #included from: catch_resultinfo.h +#define TWOBLUECUBES_CATCH_RESULT_INFO_H_INCLUDED #include <string> // #included from: catch_result_type.h +#define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED namespace Catch { @@ -770,106 +790,31 @@ 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( 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(); - } - - std::string getExpression() const { - return m_expr; - } - - 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; - } + 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 { - 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"; - } - else - 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 ) { - return expr && expr[0] == '!'; - } + std::string getExpandedExpressionInternal() const; + bool isNotExpression( const char* expr ); protected: std::string m_macroName; @@ -883,6 +828,7 @@ namespace Catch { } // end namespace Catch // #included from: catch_evaluate.hpp +#define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED namespace Catch { namespace Internal { @@ -1054,45 +1000,20 @@ class ResultInfoBuilder : public ResultInfo { public: - ResultInfoBuilder() {} + ResultInfoBuilder(); ResultInfoBuilder( const char* expr, bool isNot, const SourceLineInfo& lineInfo, const char* macroName, - const char* message = "" ) - : ResultInfo( expr, ResultWas::Unknown, isNot, lineInfo, macroName, message ) - {} - - void setResultType( ResultWas::OfType result ) { - // Flip bool results if isNot is set - if( m_isNot && result == ResultWas::Ok ) - m_result = ResultWas::ExpressionFailed; - else if( m_isNot && result == ResultWas::ExpressionFailed ) - m_result = ResultWas::Ok; - else - m_result = result; - } - - void setMessage( const std::string& message ) { - m_message = message; - } - - void setLineInfo( const SourceLineInfo& lineInfo ) { - m_lineInfo = lineInfo; - } - - void setLhs( const std::string& lhs ) { - m_lhs = lhs; - } - - void setRhs( const std::string& rhs ) { - m_rhs = rhs; - } + const char* message = "" ); - void setOp( const std::string& op ) { - m_op = op; - } + void setResultType( ResultWas::OfType result ); + void setMessage( const std::string& message ); + void setLineInfo( const SourceLineInfo& lineInfo ); + void setLhs( const std::string& lhs ); + void setRhs( const std::string& rhs ); + void setOp( const std::string& op ); template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || @@ -1112,12 +1033,7 @@ private: template<typename T> friend class PtrExpression; - ResultInfoBuilder& captureBoolExpression( bool result ) { - m_lhs = Catch::toString( result ); - m_op = m_isNot ? "!" : ""; - setResultType( result ? ResultWas::Ok : ResultWas::ExpressionFailed ); - return *this; - } + ResultInfoBuilder& captureBoolExpression( bool result ); template<Internal::Operator Op, typename T1, typename T2> ResultInfoBuilder& captureExpression( const T1& lhs, const T2& rhs ) { @@ -1281,6 +1197,7 @@ private: } // end namespace Catch // #included from: catch_interfaces_capture.h +#define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED #include <string> @@ -1316,6 +1233,7 @@ namespace Catch { } // #included from: catch_debugger.hpp +#define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED #include <iostream> @@ -1426,30 +1344,6 @@ namespace Catch { struct TestFailureException{}; -class NotImplementedException : public std::exception -{ -public: - NotImplementedException( const SourceLineInfo& lineInfo ) - : m_lineInfo( lineInfo ) { - std::ostringstream oss; - oss << lineInfo << "function "; - if( !lineInfo.function.empty() ) - oss << lineInfo.function << " "; - oss << "not implemented"; - m_what = oss.str(); - } - - virtual ~NotImplementedException() throw() {} - - virtual const char* what() const throw() { - return m_what.c_str(); - } - -private: - std::string m_what; - SourceLineInfo m_lineInfo; -}; - class ScopedInfo { public: ScopedInfo() : m_oss() { @@ -1495,7 +1389,7 @@ inline bool isTrue( bool value ){ return value; } } catch( Catch::TestFailureException& ) { \ throw; \ } catch( ... ) { \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, expr ); \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getRegistryHub().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, expr ); \ throw; \ } } while( Catch::isTrue( false ) ) @@ -1516,7 +1410,7 @@ inline bool isTrue( bool value ){ return value; } INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \ } \ catch( ... ) { \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getRegistryHub().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ } /////////////////////////////////////////////////////////////////////////////// @@ -1538,7 +1432,7 @@ inline bool isTrue( bool value ){ return value; } #define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, stopOnFailure, macroName ) \ INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \ catch( ... ) { \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getRegistryHub().getExceptionTranslatorRegistry() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \ } /////////////////////////////////////////////////////////////////////////////// @@ -1557,14 +1451,12 @@ inline bool isTrue( bool value ){ return value; } } catch( Catch::TestFailureException& ) { \ throw; \ } catch( ... ) { \ - INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher ) << Catch::getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, false ); \ + INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher ) << Catch::getRegistryHub().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, false ); \ throw; \ }}while( Catch::isTrue( false ) ) -/////////////////////////////////////////////////////////////////////////////// -#define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO ) - // #included from: internal/catch_section.hpp +#define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED #include <string> @@ -1602,6 +1494,7 @@ namespace Catch { if( Catch::Section INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::Section( name, desc, CATCH_INTERNAL_LINEINFO ) ) // #included from: internal/catch_generators.hpp +#define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED #include <iterator> #include <vector> @@ -1781,8 +1674,44 @@ using namespace Generators; #define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" ) // #included from: internal/catch_interfaces_exception.h +#define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTIONS_H_INCLUDED #include <string> +// #included from: catch_interfaces_registry_hub.h +#define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED + +#include <memory> +#include <vector> +#include <stdlib.h> + +namespace Catch { + + class TestCaseInfo; + struct IResultCapture; + struct ITestCaseRegistry; + struct IExceptionTranslatorRegistry; + struct IExceptionTranslator; + + struct IRegistryHub { + virtual ~IRegistryHub(){} + + virtual const IReporterRegistry& getReporterRegistry() const = 0; + virtual const ITestCaseRegistry& getTestCaseRegistry() const = 0; + virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0; + }; + + struct IMutableRegistryHub { + virtual ~IMutableRegistryHub(){} + virtual void registerReporter( const std::string& name, IReporterFactory* factory ) = 0; + virtual void registerTest( const TestCaseInfo& testInfo ) = 0; + virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; + }; + + IRegistryHub& getRegistryHub(); + IMutableRegistryHub& getMutableRegistryHub(); + void cleanUp(); +} + namespace Catch { @@ -1796,7 +1725,6 @@ namespace Catch { struct IExceptionTranslatorRegistry { virtual ~IExceptionTranslatorRegistry(){} - virtual void registerTranslator( IExceptionTranslator* translator ) = 0; virtual std::string translateActiveException() const = 0; }; @@ -1825,7 +1753,7 @@ namespace Catch { public: template<typename T> ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) { - getCurrentContext().getExceptionTranslatorRegistry().registerTranslator + getMutableRegistryHub().registerTranslator ( new ExceptionTranslator<T>( translateFunction ) ); } }; @@ -1838,6 +1766,7 @@ namespace Catch { static std::string INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator )( signature ) // #included from: internal/catch_approx.hpp +#define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED #include <cmath> #include <limits> @@ -1918,6 +1847,7 @@ inline std::string toString<Detail::Approx>( const Detail::Approx& value ) { } // end namespace Catch // #included from: internal/catch_matchers.hpp +#define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED namespace Catch { namespace Matchers { @@ -2004,6 +1934,7 @@ using namespace Matchers; // These files are included here so the single_include script doesn't put them // in the conditionally compiled sections // #included from: internal/catch_test_case_info.hpp +#define TWOBLUECUBES_CATCH_TESTCASEINFO_HPP_INCLUDED #include <map> #include <string> @@ -2122,6 +2053,7 @@ namespace Catch { } // #included from: internal/catch_interfaces_runner.h +#define TWOBLUECUBES_INTERNAL_CATCH_INTERFACES_RUNNER_H_INCLUDED #include <string> @@ -2139,6 +2071,7 @@ namespace Catch { #ifdef __OBJC__ // #included from: internal/catch_objc.hpp +#define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED #import <objc/runtime.h> @@ -2235,7 +2168,7 @@ namespace Catch { std::string name = Detail::getAnnotation( cls, "Name", testCaseName ); std::string desc = Detail::getAnnotation( cls, "Description", testCaseName ); - getCurrentContext().getTestCaseRegistry().registerTest( TestCaseInfo( new OcMethod( cls, selector ), name.c_str(), desc.c_str(), SourceLineInfo() ) ); + getMutableRegistryHub().registerTest( TestCaseInfo( new OcMethod( cls, selector ), name.c_str(), desc.c_str(), SourceLineInfo() ) ); noTestMethods++; } } @@ -2346,165 +2279,60 @@ return @ desc; \ #if defined( CATCH_CONFIG_MAIN ) || defined( CATCH_CONFIG_RUNNER ) // #included from: catch_runner.hpp +#define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED -// #included from: internal/catch_context_impl.hpp -// #included from: catch_test_case_registry_impl.hpp +// #included from: internal/catch_commandline.hpp +#define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED + +// #included from: catch_config.hpp +#define TWOBLUECUBES_CATCH_RUNNERCONFIG_HPP_INCLUDED +#include <memory> #include <vector> -#include <set> -#include <sstream> +#include <string> #include <iostream> namespace Catch { - class TestRegistry : public ITestCaseRegistry { - public: - TestRegistry() : m_unnamedCount( 0 ) {} + struct Include { enum WhichResults { + FailedOnly, + SuccessfulResults + }; }; - virtual void registerTest( const TestCaseInfo& testInfo ) { - if( testInfo.getName() == "" ) { - std::ostringstream oss; - oss << testInfo.getName() << "unnamed/" << ++m_unnamedCount; - return registerTest( TestCaseInfo( testInfo, oss.str() ) ); - } + struct List{ enum What { + None = 0, - if( m_functions.find( testInfo ) == m_functions.end() ) { - m_functions.insert( testInfo ); - m_functionsInOrder.push_back( testInfo ); - } - else { - const TestCaseInfo& prev = *m_functions.find( testInfo ); - std::cerr << "error: TEST_CASE( \"" << testInfo.getName() << "\" ) already defined.\n" - << "\tFirst seen at " << SourceLineInfo( prev.getLineInfo() ) << "\n" - << "\tRedefined at " << SourceLineInfo( testInfo.getLineInfo() ) << std::endl; - exit(1); - } - } + Reports = 1, + Tests = 2, + All = 3, - virtual const std::vector<TestCaseInfo>& getAllTests() const { - return m_functionsInOrder; - } + WhatMask = 0xf, - virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) { - TestSpec testSpec( rawTestSpec ); + AsText = 0x10, + AsXml = 0x11, - std::vector<TestCaseInfo> testList; - std::vector<TestCaseInfo>::const_iterator it = m_functionsInOrder.begin(); - std::vector<TestCaseInfo>::const_iterator itEnd = m_functionsInOrder.end(); - for(; it != itEnd; ++it ) { - if( testSpec.matches( it->getName() ) ) { - testList.push_back( *it ); - } - } - return testList; - } + AsMask = 0xf0 + }; }; - private: + struct ConfigData { + ConfigData() + : listSpec( List::None ), + shouldDebugBreak( false ), + includeWhichResults( Include::FailedOnly ), + cutoff( -1 ), + allowThrows( true ) + {} - std::set<TestCaseInfo> m_functions; - std::vector<TestCaseInfo> m_functionsInOrder; - size_t m_unnamedCount; - }; - - /////////////////////////////////////////////////////////////////////////// - - class FreeFunctionTestCase : public ITestCase { - public: - - FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {} - - virtual void invoke() const { - m_fun(); - } - - virtual ITestCase* clone() const { - return new FreeFunctionTestCase( m_fun ); - } - - virtual bool operator == ( const ITestCase& other ) const { - const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other ); - return ffOther && m_fun == ffOther->m_fun; - } - - virtual bool operator < ( const ITestCase& other ) const { - const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other ); - return ffOther && m_fun < ffOther->m_fun; - } - - private: - TestFunction m_fun; - }; - - /////////////////////////////////////////////////////////////////////////// - - AutoReg::AutoReg( TestFunction function, - const char* name, - const char* description, - const SourceLineInfo& lineInfo ) { - registerTestCase( new FreeFunctionTestCase( function ), name, description, lineInfo ); - } - - AutoReg::~AutoReg() {} - - void AutoReg::registerTestCase( ITestCase* testCase, - const char* name, - const char* description, - const SourceLineInfo& lineInfo ) { - getCurrentContext().getTestCaseRegistry().registerTest( TestCaseInfo( testCase, name, description, lineInfo ) ); - } - -} // end namespace Catch - -// #included from: catch_runner_impl.hpp - -// #included from: catch_config.hpp - -#include <memory> -#include <vector> -#include <string> -#include <iostream> - -namespace Catch { - - struct Include { enum WhichResults { - FailedOnly, - SuccessfulResults - }; }; - - struct List{ enum What { - None = 0, - - Reports = 1, - Tests = 2, - All = 3, - - WhatMask = 0xf, - - AsText = 0x10, - AsXml = 0x11, - - AsMask = 0xf0 - }; }; - - struct ConfigData { - ConfigData() - : listSpec( List::None ), - shouldDebugBreak( false ), - includeWhichResults( Include::FailedOnly ), - cutoff( -1 ), - allowThrows( true ) - {} - - std::string reporter; - std::string outputFilename; - List::What listSpec; - std::vector<std::string> testSpecs; - bool shouldDebugBreak; - std::string stream; - Include::WhichResults includeWhichResults; - std::string name; - int cutoff; - bool allowThrows; + std::string reporter; + std::string outputFilename; + List::What listSpec; + std::vector<std::string> testSpecs; + bool shouldDebugBreak; + std::string stream; + Include::WhichResults includeWhichResults; + std::string name; + int cutoff; + bool allowThrows; }; class Config : public IConfig { @@ -2574,7 +2402,7 @@ namespace Catch { } void useStream( const std::string& streamName ) { - std::streambuf* newBuf = Context::createStreamBuf( streamName ); + std::streambuf* newBuf = createStreamBuf( streamName ); setStreamBuf( newBuf ); delete m_streambuf; m_streambuf = newBuf; @@ -2606,9 +2434,14 @@ namespace Catch { } // end namespace Catch +// #included from: catch_runner_impl.hpp +#define TWOBLUECUBES_INTERNAL_CATCH_RUNNER_HPP_INCLUDED + // #included from: catch_running_test.hpp +#define TWOBLUECUBES_INTERNAL_CATCH_RUNNING_TEST_HPP_INCLUDED // #included from: catch_section_info.hpp +#define TWOBLUECUBES_INTERNAL_CATCH_SECTION_INFO_HPP_INCLUDED #include <map> #include <string> @@ -2851,7 +2684,7 @@ namespace Catch { virtual void runAll( bool runHiddenTests = false ) { m_reporter->StartGroup( "" ); - const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests(); + const std::vector<TestCaseInfo>& allTests = getRegistryHub().getTestCaseRegistry().getAllTests(); for( std::size_t i=0; i < allTests.size(); ++i ) { if( runHiddenTests || !allTests[i].isHidden() ) { if( aborting() ) { @@ -2871,7 +2704,7 @@ namespace Catch { TestSpec testSpec( rawTestSpec ); - const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests(); + const std::vector<TestCaseInfo>& allTests = getRegistryHub().getTestCaseRegistry().getAllTests(); std::size_t testsRun = 0; for( std::size_t i=0; i < allTests.size(); ++i ) { if( testSpec.matches( allTests[i].getName() ) ) { @@ -3053,7 +2886,7 @@ namespace Catch { // This just means the test was aborted due to failure } catch(...) { - acceptMessage( getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() ); + acceptMessage( getRegistryHub().getExceptionTranslatorRegistry().translateActiveException() ); acceptResult( ResultWas::ThrewException ); } m_info.clear(); @@ -3077,815 +2910,408 @@ namespace Catch { } // end namespace Catch -// #included from: catch_generators_impl.hpp - -#include <vector> -#include <string> -#include <map> - namespace Catch { - struct GeneratorInfo { + class Command { + public: + Command(){} - GeneratorInfo( std::size_t size ) - : m_size( size ), - m_currentIndex( 0 ) - {} + explicit Command( const std::string& name ) : m_name( name ) {} - bool moveNext() { - if( ++m_currentIndex == m_size ) { - m_currentIndex = 0; - return false; - } - return true; + Command& operator += ( const std::string& arg ) { + m_args.push_back( arg ); + return *this; + } + Command& operator += ( const Command& other ) { + std::copy( other.m_args.begin(), other.m_args.end(), std::back_inserter( m_args ) ); + if( m_name.empty() ) + m_name = other.m_name; + return *this; + } + Command operator + ( const Command& other ) { + Command newCommand( *this ); + newCommand += other; + return newCommand; } - std::size_t getCurrentIndex() const { - return m_currentIndex; + operator SafeBool::type() const { + return SafeBool::makeSafe( !m_name.empty() ); } - std::size_t m_size; - std::size_t m_currentIndex; - }; + std::string name() const { return m_name; } + std::string operator[]( std::size_t i ) const { return m_args[i]; } + std::size_t argsCount() const { return m_args.size(); } - /////////////////////////////////////////////////////////////////////////// + void raiseError( const std::string& message ) const { + std::ostringstream oss; + oss << "Error while parsing " << m_name << ". " << message << "."; + if( m_args.size() > 0 ) + oss << " Arguments where:"; + for( std::size_t i = 0; i < m_args.size(); ++i ) + oss << " " << m_args[i]; + throw std::domain_error( oss.str() ); + } + + private: - class GeneratorsForTest { + std::string m_name; + std::vector<std::string> m_args; + }; + class CommandParser { public: - ~GeneratorsForTest() { - deleteAll( m_generatorsInOrder ); - } + CommandParser( int argc, char const * const * argv ) : m_argc( static_cast<std::size_t>( argc ) ), m_argv( argv ) {} - GeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) { - std::map<std::string, GeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo ); - if( it == m_generatorsByName.end() ) { - GeneratorInfo* info = new GeneratorInfo( size ); - m_generatorsByName.insert( std::make_pair( fileInfo, info ) ); - m_generatorsInOrder.push_back( info ); - return *info; - } - return *it->second; + Command find( const std::string& arg1, const std::string& arg2, const std::string& arg3 ) const { + return find( arg1 ) + find( arg2 ) + find( arg3 ); } - bool moveNext() { - std::vector<GeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin(); - std::vector<GeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end(); - for(; it != itEnd; ++it ) { - if( (*it)->moveNext() ) - return true; - } - return false; + Command find( const std::string& shortArg, const std::string& longArg ) const { + return find( shortArg ) + find( longArg ); + } + Command find( const std::string& arg ) const { + for( std::size_t i = 0; i < m_argc; ++i ) + if( m_argv[i] == arg ) + return getArgs( i ); + return Command(); } private: - std::map<std::string, GeneratorInfo*> m_generatorsByName; - std::vector<GeneratorInfo*> m_generatorsInOrder; - }; + Command getArgs( std::size_t from ) const { + Command command( m_argv[from] ); + for( std::size_t i = from+1; i < m_argc && m_argv[i][0] != '-'; ++i ) + command += m_argv[i]; + return command; + } -} // end namespace Catch + std::size_t m_argc; + char const * const * m_argv; + }; -#define INTERNAL_CATCH_LINESTR2( line ) #line -#define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line ) + inline void parseIntoConfig( const CommandParser& parser, ConfigData& config ) { -#define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" ) + if( Command cmd = parser.find( "-l", "--list" ) ) { + if( cmd.argsCount() > 2 ) + cmd.raiseError( "Expected upto 2 arguments" ); -// #included from: catch_console_colour_impl.hpp + List::What listSpec = List::All; + if( cmd.argsCount() >= 1 ) { + if( cmd[0] == "tests" ) + config.listSpec = List::Tests; + else if( cmd[0] == "reporters" ) + config.listSpec = List::Reports; + else + cmd.raiseError( "Expected [tests] or [reporters]" ); + } + if( cmd.argsCount() >= 2 ) { + if( cmd[1] == "xml" ) + config.listSpec = static_cast<List::What>( listSpec | List::AsXml ); + else if( cmd[1] == "text" ) + config.listSpec = static_cast<List::What>( listSpec | List::AsText ); + else + cmd.raiseError( "Expected [xml] or [text]" ); + } + } -// #included from: catch_console_colour.hpp + if( Command cmd = parser.find( "-t", "--test" ) ) { + if( cmd.argsCount() == 0 ) + cmd.raiseError( "Expected at least one argument" ); + for( std::size_t i = 0; i < cmd.argsCount(); ++i ) + config.testSpecs.push_back( cmd[i] ); + } -namespace Catch { + if( Command cmd = parser.find( "-r", "--reporter" ) ) { + if( cmd.argsCount() != 1 ) + cmd.raiseError( "Expected one argument" ); + config.reporter = cmd[0]; + } - struct ConsoleColourImpl; + if( Command cmd = parser.find( "-o", "--out" ) ) { + if( cmd.argsCount() == 0 ) + cmd.raiseError( "Expected filename" ); + if( cmd[0][0] == '%' ) + config.stream = cmd[0].substr( 1 ); + else + config.outputFilename = cmd[0]; + } - class TextColour : NonCopyable { - public: + if( Command cmd = parser.find( "-s", "--success" ) ) { + if( cmd.argsCount() != 0 ) + cmd.raiseError( "Does not accept arguments" ); + config.includeWhichResults = Include::SuccessfulResults; + } - enum Colours { - None, + if( Command cmd = parser.find( "-b", "--break" ) ) { + if( cmd.argsCount() != 0 ) + cmd.raiseError( "Does not accept arguments" ); + config.shouldDebugBreak = true; + } - FileName, - ResultError, - ResultSuccess, - - Error, - Success, + if( Command cmd = parser.find( "-n", "--name" ) ) { + if( cmd.argsCount() != 1 ) + cmd.raiseError( "Expected a name" ); + config.name = cmd[0]; + } - OriginalExpression, - ReconstructedExpression - }; + if( Command cmd = parser.find( "-a", "--abort" ) ) { + if( cmd.argsCount() > 1 ) + cmd.raiseError( "Only accepts 0-1 arguments" ); + int threshold = 1; + if( cmd.argsCount() == 1 ) { + std::stringstream ss; + ss << cmd[0]; + ss >> threshold; + if( ss.fail() || threshold <= 0 ) + cmd.raiseError( "threshold must be a number greater than zero" ); + } + config.cutoff = threshold; + } - TextColour( Colours colour = None ); - void set( Colours colour ); - ~TextColour(); + if( Command cmd = parser.find( "-nt", "--nothrow" ) ) { + if( cmd.argsCount() != 0 ) + cmd.raiseError( "Does not accept arguments" ); + config.allowThrows = false; + } - private: - ConsoleColourImpl* m_impl; - }; + } } // end namespace Catch -#ifdef CATCH_PLATFORM_WINDOWS +// #included from: internal/catch_list.hpp +#define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED -#include <windows.h> +#include <limits> namespace Catch { + inline int List( Config& config ) { - namespace { - - WORD mapConsoleColour( TextColour::Colours colour ) { - switch( colour ) { - case TextColour::FileName: - return FOREGROUND_INTENSITY; // greyed out - case TextColour::ResultError: - return FOREGROUND_RED | FOREGROUND_INTENSITY; // bright red - case TextColour::ResultSuccess: - return FOREGROUND_GREEN | FOREGROUND_INTENSITY; // bright green - case TextColour::Error: - return FOREGROUND_RED; // dark red - case TextColour::Success: - return FOREGROUND_GREEN; // dark green - case TextColour::OriginalExpression: - return FOREGROUND_BLUE | FOREGROUND_GREEN; // turquoise - case TextColour::ReconstructedExpression: - return FOREGROUND_RED | FOREGROUND_GREEN; // greeny-yellow - default: return 0; + if( config.listWhat() & List::Reports ) { + std::cout << "Available reports:\n"; + IReporterRegistry::FactoryMap::const_iterator it = getRegistryHub().getReporterRegistry().getFactories().begin(); + IReporterRegistry::FactoryMap::const_iterator itEnd = getRegistryHub().getReporterRegistry().getFactories().end(); + for(; it != itEnd; ++it ) { + // !TBD: consider listAs() + std::cout << "\t" << it->first << "\n\t\t'" << it->second->getDescription() << "'\n"; } - } - } - - struct ConsoleColourImpl { - - ConsoleColourImpl() - : hStdout( GetStdHandle(STD_OUTPUT_HANDLE) ), - wOldColorAttrs( 0 ) - { - GetConsoleScreenBufferInfo( hStdout, &csbiInfo ); - wOldColorAttrs = csbiInfo.wAttributes; + std::cout << std::endl; } - ~ConsoleColourImpl() { - SetConsoleTextAttribute( hStdout, wOldColorAttrs ); + if( config.listWhat() & List::Tests ) { + std::cout << "Available tests:\n"; + std::vector<TestCaseInfo>::const_iterator it = getRegistryHub().getTestCaseRegistry().getAllTests().begin(); + std::vector<TestCaseInfo>::const_iterator itEnd = getRegistryHub().getTestCaseRegistry().getAllTests().end(); + for(; it != itEnd; ++it ) { + // !TBD: consider listAs() + std::cout << "\t" << it->getName() << "\n\t\t '" << it->getDescription() << "'\n"; + } + std::cout << std::endl; } - void set( TextColour::Colours colour ) { - WORD consoleColour = mapConsoleColour( colour ); - if( consoleColour > 0 ) - SetConsoleTextAttribute( hStdout, consoleColour ); + if( ( config.listWhat() & List::All ) == 0 ) { + std::cerr << "Unknown list type" << std::endl; + return (std::numeric_limits<int>::max)(); } - HANDLE hStdout; - CONSOLE_SCREEN_BUFFER_INFO csbiInfo; - WORD wOldColorAttrs; - }; - - TextColour::TextColour( Colours colour ) - : m_impl( new ConsoleColourImpl() ) - { - if( colour ) - m_impl->set( colour ); - } - - TextColour::~TextColour() { - delete m_impl; - } - - void TextColour::set( Colours colour ) { - m_impl->set( colour ); + return 0; } } // end namespace Catch -#else - -namespace Catch { - TextColour::TextColour( Colours ){} - TextColour::~TextColour(){} - void TextColour::set( Colours ){} - -} // end namespace Catch - -#endif - - -// #included from: catch_exception_translator_registry.hpp +// #included from: reporters/catch_reporter_basic.hpp +#define TWOBLUECUBES_CATCH_REPORTER_BASIC_HPP_INCLUDED -#ifdef __OBJC__ -#import "Foundation/Foundation.h" -#endif +// #included from: ../internal/catch_reporter_registrars.hpp +#define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED namespace Catch { - class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { - - ~ExceptionTranslatorRegistry() { - deleteAll( m_translators ); - } + template<typename T> + class ReporterRegistrar { - virtual void registerTranslator( IExceptionTranslator* translator ) { - m_translators.push_back( translator ); - } + class ReporterFactory : public IReporterFactory { - virtual std::string translateActiveException() const { - try { -#ifdef __OBJC__ - // In Objective-C try objective-c exceptions first - @try { - throw; - } - @catch (NSException *exception) { - return toString( [exception description] ); - } -#else - throw; -#endif - } - catch( std::exception& ex ) { - return ex.what(); - } - catch( std::string& msg ) { - return msg; - } - catch( const char* msg ) { - return msg; + virtual IReporter* create( const ReporterConfig& config ) const { + return new T( config ); } - catch(...) { - return tryTranslators( m_translators.begin() ); + + virtual std::string getDescription() const { + return T::getDescription(); } - } + }; - std::string tryTranslators( std::vector<IExceptionTranslator*>::const_iterator it ) const { - if( it == m_translators.end() ) - return "Unknown exception"; + public: - try { - return (*it)->translate(); - } - catch(...) { - return tryTranslators( it+1 ); - } + ReporterRegistrar( const std::string& name ) { + getMutableRegistryHub().registerReporter( name, new ReporterFactory() ); } - - private: - std::vector<IExceptionTranslator*> m_translators; }; } -// #included from: catch_reporter_registry.hpp +#define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \ + Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); -#include <map> +// #included from: ../internal/catch_console_colour.hpp +#define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_HPP_INCLUDED namespace Catch { - class ReporterRegistry : public IReporterRegistry { + struct ConsoleColourImpl; + class TextColour : NonCopyable { public: - ~ReporterRegistry() { - deleteAllValues( m_factories ); - } + enum Colours { + None, - virtual IReporter* create( const std::string& name, const ReporterConfig& config ) const { - FactoryMap::const_iterator it = m_factories.find( name ); - if( it == m_factories.end() ) - return NULL; - return it->second->create( config ); - } + FileName, + ResultError, + ResultSuccess, - void registerReporter( const std::string& name, IReporterFactory* factory ) { - m_factories.insert( std::make_pair( name, factory ) ); - } + Error, + Success, - const FactoryMap& getFactories() const { - return m_factories; - } + OriginalExpression, + ReconstructedExpression + }; + + TextColour( Colours colour = None ); + void set( Colours colour ); + ~TextColour(); private: - FactoryMap m_factories; + ConsoleColourImpl* m_impl; }; -} -// #included from: catch_stream.hpp - -#include <stdexcept> -#include <cstdio> +} // end namespace Catch namespace Catch { - template<typename WriterF, size_t bufferSize=256> - class StreamBufImpl : public StreamBufBase { - char data[bufferSize]; - WriterF m_writer; + struct pluralise { + pluralise( std::size_t count, const std::string& label ) + : m_count( count ), + m_label( label ) + {} - public: - StreamBufImpl() { - setp( data, data + sizeof(data) ); + friend std::ostream& operator << ( std::ostream& os, const pluralise& pluraliser ) { + os << pluraliser.m_count << " " << pluraliser.m_label; + if( pluraliser.m_count != 1 ) + os << "s"; + return os; } - ~StreamBufImpl() { - sync(); - } + std::size_t m_count; + std::string m_label; + }; - private: - int overflow( int c ) { - sync(); + class BasicReporter : public SharedImpl<IReporter> { - if( c != EOF ) { - if( pbase() == epptr() ) - m_writer( std::string( 1, static_cast<char>( c ) ) ); - else - sputc( static_cast<char>( c ) ); - } - return 0; - } - - int sync() { - if( pbase() != pptr() ) { - m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) ); - setp( pbase(), epptr() ); - } - return 0; - } - }; - - /////////////////////////////////////////////////////////////////////////// - - struct OutputDebugWriter { - - void operator()( const std::string &str ) { - writeToDebugConsole( str ); - } - }; -} - -namespace Catch { - - namespace { - Context* currentContext = NULL; - } - IMutableContext& getCurrentMutableContext() { - if( !currentContext ) - currentContext = new Context(); - return *currentContext; - } - IContext& getCurrentContext() { - return getCurrentMutableContext(); - } - - Context::Context() - : m_reporterRegistry( new ReporterRegistry ), - m_testCaseRegistry( new TestRegistry ), - m_exceptionTranslatorRegistry( new ExceptionTranslatorRegistry ), - m_config( NULL ) - {} - - void Context::cleanUp() { - delete currentContext; - currentContext = NULL; - } - - void Context::setRunner( IRunner* runner ) { - m_runner = runner; - } - - void Context::setResultCapture( IResultCapture* resultCapture ) { - m_resultCapture = resultCapture; - } - - const IConfig* Context::getConfig() const { - return m_config; - } - void Context::setConfig( const IConfig* config ) { - m_config = config; - } - - IResultCapture& Context::getResultCapture() { - return *m_resultCapture; - } - - IRunner& Context::getRunner() { - return *m_runner; - } - - IReporterRegistry& Context::getReporterRegistry() { - return *m_reporterRegistry.get(); - } - - ITestCaseRegistry& Context::getTestCaseRegistry() { - return *m_testCaseRegistry.get(); - } + struct SpanInfo { - IExceptionTranslatorRegistry& Context::getExceptionTranslatorRegistry() { - return *m_exceptionTranslatorRegistry.get(); - } + SpanInfo() + : emitted( false ) + {} - std::streambuf* Context::createStreamBuf( const std::string& streamName ) { - if( streamName == "stdout" ) return std::cout.rdbuf(); - if( streamName == "stderr" ) return std::cerr.rdbuf(); - if( streamName == "debug" ) return new StreamBufImpl<OutputDebugWriter>; + SpanInfo( const std::string& spanName ) + : name( spanName ), + emitted( false ) + {} - throw std::domain_error( "Unknown stream: " + streamName ); - } + SpanInfo( const SpanInfo& other ) + : name( other.name ), + emitted( other.emitted ) + {} - GeneratorsForTest* Context::findGeneratorsForCurrentTest() { - std::string testName = getResultCapture().getCurrentTestName(); + std::string name; + bool emitted; + }; - std::map<std::string, GeneratorsForTest*>::const_iterator it = - m_generatorsByTestName.find( testName ); - return it != m_generatorsByTestName.end() - ? it->second - : NULL; - } + public: + BasicReporter( const ReporterConfig& config ) + : m_config( config ), + m_firstSectionInTestCase( true ), + m_aborted( false ) + {} - GeneratorsForTest& Context::getGeneratorsForCurrentTest() { - GeneratorsForTest* generators = findGeneratorsForCurrentTest(); - if( !generators ) { - std::string testName = getResultCapture().getCurrentTestName(); - generators = new GeneratorsForTest(); - m_generatorsByTestName.insert( std::make_pair( testName, generators ) ); + static std::string getDescription() { + return "Reports test results as lines of text"; } - return *generators; - } - - size_t Context::getGeneratorIndex( const std::string& fileInfo, size_t totalSize ) { - return getGeneratorsForCurrentTest() - .getGeneratorInfo( fileInfo, totalSize ) - .getCurrentIndex(); - } - - bool Context::advanceGeneratorsForCurrentTest() { - GeneratorsForTest* generators = findGeneratorsForCurrentTest(); - return generators && generators->moveNext(); - } -} -// #included from: internal/catch_commandline.hpp - -namespace Catch { - - class Command { - public: - Command(){} - explicit Command( const std::string& name ) : m_name( name ) {} + private: - Command& operator += ( const std::string& arg ) { - m_args.push_back( arg ); - return *this; - } - Command& operator += ( const Command& other ) { - std::copy( other.m_args.begin(), other.m_args.end(), std::back_inserter( m_args ) ); - if( m_name.empty() ) - m_name = other.m_name; - return *this; - } - Command operator + ( const Command& other ) { - Command newCommand( *this ); - newCommand += other; - return newCommand; + void ReportCounts( const std::string& label, const Counts& counts, const std::string& allPrefix = "All " ) { + if( counts.passed ) + m_config.stream << counts.failed << " of " << counts.total() << " " << label << "s failed"; + else + m_config.stream << ( counts.failed > 1 ? allPrefix : "" ) << pluralise( counts.failed, label ) << " failed"; } - operator SafeBool::type() const { - return SafeBool::makeSafe( !m_name.empty() ); + void ReportCounts( const Totals& totals, const std::string& allPrefix = "All " ) { + if( totals.assertions.total() == 0 ) { + m_config.stream << "No tests ran"; + } + else if( totals.assertions.failed ) { + TextColour colour( TextColour::ResultError ); + ReportCounts( "test case", totals.testCases, allPrefix ); + if( totals.testCases.failed > 0 ) { + m_config.stream << " ("; + ReportCounts( "assertion", totals.assertions, allPrefix ); + m_config.stream << ")"; + } + } + else { + TextColour colour( TextColour::ResultSuccess ); + m_config.stream << allPrefix << "tests passed (" + << pluralise( totals.assertions.passed, "assertion" ) << " in " + << pluralise( totals.testCases.passed, "test case" ) << ")"; + } } - std::string name() const { return m_name; } - std::string operator[]( std::size_t i ) const { return m_args[i]; } - std::size_t argsCount() const { return m_args.size(); } + private: // IReporter - void raiseError( const std::string& message ) const { - std::ostringstream oss; - oss << "Error while parsing " << m_name << ". " << message << "."; - if( m_args.size() > 0 ) - oss << " Arguments where:"; - for( std::size_t i = 0; i < m_args.size(); ++i ) - oss << " " << m_args[i]; - throw std::domain_error( oss.str() ); + virtual bool shouldRedirectStdout() const { + return false; } - private: - - std::string m_name; - std::vector<std::string> m_args; - }; - - class CommandParser { - public: - CommandParser( int argc, char const * const * argv ) : m_argc( static_cast<std::size_t>( argc ) ), m_argv( argv ) {} - - Command find( const std::string& arg1, const std::string& arg2, const std::string& arg3 ) const { - return find( arg1 ) + find( arg2 ) + find( arg3 ); + virtual void StartTesting() { + m_testingSpan = SpanInfo(); } - Command find( const std::string& shortArg, const std::string& longArg ) const { - return find( shortArg ) + find( longArg ); - } - Command find( const std::string& arg ) const { - for( std::size_t i = 0; i < m_argc; ++i ) - if( m_argv[i] == arg ) - return getArgs( i ); - return Command(); + virtual void Aborted() { + m_aborted = true; } - private: - Command getArgs( std::size_t from ) const { - Command command( m_argv[from] ); - for( std::size_t i = from+1; i < m_argc && m_argv[i][0] != '-'; ++i ) - command += m_argv[i]; - return command; + virtual void EndTesting( const Totals& totals ) { + // Output the overall test results even if "Started Testing" was not emitted + if( m_aborted ) { + m_config.stream << "\n[Testing aborted. "; + ReportCounts( totals, "The first " ); + } + else { + m_config.stream << "\n[Testing completed. "; + ReportCounts( totals ); + } + m_config.stream << "]\n" << std::endl; } - std::size_t m_argc; - char const * const * m_argv; - }; - - inline void parseIntoConfig( const CommandParser& parser, ConfigData& config ) { - - if( Command cmd = parser.find( "-l", "--list" ) ) { - if( cmd.argsCount() > 2 ) - cmd.raiseError( "Expected upto 2 arguments" ); + virtual void StartGroup( const std::string& groupName ) { + m_groupSpan = groupName; + } - List::What listSpec = List::All; - if( cmd.argsCount() >= 1 ) { - if( cmd[0] == "tests" ) - config.listSpec = List::Tests; - else if( cmd[0] == "reporters" ) - config.listSpec = List::Reports; - else - cmd.raiseError( "Expected [tests] or [reporters]" ); - } - if( cmd.argsCount() >= 2 ) { - if( cmd[1] == "xml" ) - config.listSpec = static_cast<List::What>( listSpec | List::AsXml ); - else if( cmd[1] == "text" ) - config.listSpec = static_cast<List::What>( listSpec | List::AsText ); - else - cmd.raiseError( "Expected [xml] or [text]" ); + virtual void EndGroup( const std::string& groupName, const Totals& totals ) { + if( m_groupSpan.emitted && !groupName.empty() ) { + m_config.stream << "[End of group: '" << groupName << "'. "; + ReportCounts( totals ); + m_config.stream << "]\n" << std::endl; + m_groupSpan = SpanInfo(); } } - if( Command cmd = parser.find( "-t", "--test" ) ) { - if( cmd.argsCount() == 0 ) - cmd.raiseError( "Expected at least one argument" ); - for( std::size_t i = 0; i < cmd.argsCount(); ++i ) - config.testSpecs.push_back( cmd[i] ); + virtual void StartTestCase( const TestCaseInfo& testInfo ) { + m_testSpan = testInfo.getName(); } - if( Command cmd = parser.find( "-r", "--reporter" ) ) { - if( cmd.argsCount() != 1 ) - cmd.raiseError( "Expected one argument" ); - config.reporter = cmd[0]; - } - - if( Command cmd = parser.find( "-o", "--out" ) ) { - if( cmd.argsCount() == 0 ) - cmd.raiseError( "Expected filename" ); - if( cmd[0][0] == '%' ) - config.stream = cmd[0].substr( 1 ); - else - config.outputFilename = cmd[0]; - } - - if( Command cmd = parser.find( "-s", "--success" ) ) { - if( cmd.argsCount() != 0 ) - cmd.raiseError( "Does not accept arguments" ); - config.includeWhichResults = Include::SuccessfulResults; - } - - if( Command cmd = parser.find( "-b", "--break" ) ) { - if( cmd.argsCount() != 0 ) - cmd.raiseError( "Does not accept arguments" ); - config.shouldDebugBreak = true; - } - - if( Command cmd = parser.find( "-n", "--name" ) ) { - if( cmd.argsCount() != 1 ) - cmd.raiseError( "Expected a name" ); - config.name = cmd[0]; - } - - if( Command cmd = parser.find( "-a", "--abort" ) ) { - if( cmd.argsCount() > 1 ) - cmd.raiseError( "Only accepts 0-1 arguments" ); - int threshold = 1; - if( cmd.argsCount() == 1 ) { - std::stringstream ss; - ss << cmd[0]; - ss >> threshold; - if( ss.fail() || threshold <= 0 ) - cmd.raiseError( "threshold must be a number greater than zero" ); - } - config.cutoff = threshold; - } - - if( Command cmd = parser.find( "-nt", "--nothrow" ) ) { - if( cmd.argsCount() != 0 ) - cmd.raiseError( "Does not accept arguments" ); - config.allowThrows = false; - } - - } - -} // end namespace Catch - -// #included from: internal/catch_list.hpp - -#include <limits> - -namespace Catch { - inline int List( Config& config ) { - - IContext& context = getCurrentContext(); - if( config.listWhat() & List::Reports ) { - std::cout << "Available reports:\n"; - IReporterRegistry::FactoryMap::const_iterator it = context.getReporterRegistry().getFactories().begin(); - IReporterRegistry::FactoryMap::const_iterator itEnd = context.getReporterRegistry().getFactories().end(); - for(; it != itEnd; ++it ) { - // !TBD: consider listAs() - std::cout << "\t" << it->first << "\n\t\t'" << it->second->getDescription() << "'\n"; - } - std::cout << std::endl; - } - - if( config.listWhat() & List::Tests ) { - std::cout << "Available tests:\n"; - std::vector<TestCaseInfo>::const_iterator it = context.getTestCaseRegistry().getAllTests().begin(); - std::vector<TestCaseInfo>::const_iterator itEnd = context.getTestCaseRegistry().getAllTests().end(); - for(; it != itEnd; ++it ) { - // !TBD: consider listAs() - std::cout << "\t" << it->getName() << "\n\t\t '" << it->getDescription() << "'\n"; - } - std::cout << std::endl; - } - - if( ( config.listWhat() & List::All ) == 0 ) { - std::cerr << "Unknown list type" << std::endl; - return (std::numeric_limits<int>::max)(); - } - - return 0; - } - -} // end namespace Catch - -// #included from: reporters/catch_reporter_basic.hpp - -// #included from: ../internal/catch_reporter_registrars.hpp - -namespace Catch { - - template<typename T> - class ReporterRegistrar { - - class ReporterFactory : public IReporterFactory { - - virtual IReporter* create( const ReporterConfig& config ) const { - return new T( config ); - } - - virtual std::string getDescription() const { - return T::getDescription(); - } - }; - - public: - - ReporterRegistrar( const std::string& name ) { - getCurrentContext().getReporterRegistry().registerReporter( name, new ReporterFactory() ); - } - }; -} - -#define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \ - Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); - -namespace Catch { - - struct pluralise { - pluralise( std::size_t count, const std::string& label ) - : m_count( count ), - m_label( label ) - {} - - friend std::ostream& operator << ( std::ostream& os, const pluralise& pluraliser ) { - os << pluraliser.m_count << " " << pluraliser.m_label; - if( pluraliser.m_count != 1 ) - os << "s"; - return os; - } - - std::size_t m_count; - std::string m_label; - }; - - class BasicReporter : public SharedImpl<IReporter> { - - struct SpanInfo { - - SpanInfo() - : emitted( false ) - {} - - SpanInfo( const std::string& spanName ) - : name( spanName ), - emitted( false ) - {} - - SpanInfo( const SpanInfo& other ) - : name( other.name ), - emitted( other.emitted ) - {} - - std::string name; - bool emitted; - }; - - public: - BasicReporter( const ReporterConfig& config ) - : m_config( config ), - m_firstSectionInTestCase( true ), - m_aborted( false ) - {} - - static std::string getDescription() { - return "Reports test results as lines of text"; - } - - private: - - void ReportCounts( const std::string& label, const Counts& counts, const std::string& allPrefix = "All " ) { - if( counts.passed ) - m_config.stream << counts.failed << " of " << counts.total() << " " << label << "s failed"; - else - m_config.stream << ( counts.failed > 1 ? allPrefix : "" ) << pluralise( counts.failed, label ) << " failed"; - } - - void ReportCounts( const Totals& totals, const std::string& allPrefix = "All " ) { - if( totals.assertions.total() == 0 ) { - m_config.stream << "No tests ran"; - } - else if( totals.assertions.failed ) { - TextColour colour( TextColour::ResultError ); - ReportCounts( "test case", totals.testCases, allPrefix ); - if( totals.testCases.failed > 0 ) { - m_config.stream << " ("; - ReportCounts( "assertion", totals.assertions, allPrefix ); - m_config.stream << ")"; - } - } - else { - TextColour colour( TextColour::ResultSuccess ); - m_config.stream << allPrefix << "tests passed (" - << pluralise( totals.assertions.passed, "assertion" ) << " in " - << pluralise( totals.testCases.passed, "test case" ) << ")"; - } - } - - private: // IReporter - - virtual bool shouldRedirectStdout() const { - return false; - } - - virtual void StartTesting() { - m_testingSpan = SpanInfo(); - } - - virtual void Aborted() { - m_aborted = true; - } - - virtual void EndTesting( const Totals& totals ) { - // Output the overall test results even if "Started Testing" was not emitted - if( m_aborted ) { - m_config.stream << "\n[Testing aborted. "; - ReportCounts( totals, "The first " ); - } - else { - m_config.stream << "\n[Testing completed. "; - ReportCounts( totals ); - } - m_config.stream << "]\n" << std::endl; - } - - virtual void StartGroup( const std::string& groupName ) { - m_groupSpan = groupName; - } - - virtual void EndGroup( const std::string& groupName, const Totals& totals ) { - if( m_groupSpan.emitted && !groupName.empty() ) { - m_config.stream << "[End of group: '" << groupName << "'. "; - ReportCounts( totals ); - m_config.stream << "]\n" << std::endl; - m_groupSpan = SpanInfo(); - } - } - - virtual void StartTestCase( const TestCaseInfo& testInfo ) { - m_testSpan = testInfo.getName(); - } - - virtual void StartSection( const std::string& sectionName, const std::string& ) { - m_sectionSpans.push_back( SpanInfo( sectionName ) ); + virtual void StartSection( const std::string& sectionName, const std::string& ) { + m_sectionSpans.push_back( SpanInfo( sectionName ) ); } virtual void EndSection( const std::string& sectionName, const Counts& assertions ) { @@ -4010,743 +3436,1512 @@ namespace Catch { } } - private: // helpers + private: // helpers + + void StartSpansLazily() { + if( !m_testingSpan.emitted ) { + if( m_config.name.empty() ) + m_config.stream << "[Started testing]" << std::endl; + else + m_config.stream << "[Started testing: " << m_config.name << "]" << std::endl; + m_testingSpan.emitted = true; + } + + if( !m_groupSpan.emitted && !m_groupSpan.name.empty() ) { + m_config.stream << "[Started group: '" << m_groupSpan.name << "']" << std::endl; + m_groupSpan.emitted = true; + } + + if( !m_testSpan.emitted ) { + m_config.stream << std::endl << "[Running: " << m_testSpan.name << "]" << std::endl; + m_testSpan.emitted = true; + } + + if( !m_sectionSpans.empty() ) { + SpanInfo& sectionSpan = m_sectionSpans.back(); + if( !sectionSpan.emitted && !sectionSpan.name.empty() ) { + if( m_firstSectionInTestCase ) { + m_config.stream << "\n"; + m_firstSectionInTestCase = false; + } + std::vector<SpanInfo>::iterator it = m_sectionSpans.begin(); + std::vector<SpanInfo>::iterator itEnd = m_sectionSpans.end(); + for(; it != itEnd; ++it ) { + SpanInfo& prevSpan = *it; + if( !prevSpan.emitted && !prevSpan.name.empty() ) { + m_config.stream << "[Started section: '" << prevSpan.name << "']" << std::endl; + prevSpan.emitted = true; + } + } + } + } + } + + void streamVariableLengthText( const std::string& prefix, const std::string& text ) { + std::string trimmed = trim( text ); + if( trimmed.find_first_of( "\r\n" ) == std::string::npos ) { + m_config.stream << "[" << prefix << ": " << trimmed << "]\n"; + } + else { + m_config.stream << "\n[" << prefix << "] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" << trimmed + << "\n[end of " << prefix << "] <<<<<<<<<<<<<<<<<<<<<<<<\n"; + } + } + + private: + ReporterConfig m_config; + bool m_firstSectionInTestCase; + + SpanInfo m_testingSpan; + SpanInfo m_groupSpan; + SpanInfo m_testSpan; + std::vector<SpanInfo> m_sectionSpans; + bool m_aborted; + }; + +} // end namespace Catch + +// #included from: reporters/catch_reporter_xml.hpp +#define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED + +// #included from: ../internal/catch_xmlwriter.hpp +#define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED + +#include <sstream> +#include <string> +#include <vector> + +namespace Catch { + + class XmlWriter { + public: + + class ScopedElement { + public: + ScopedElement( XmlWriter* writer ) + : m_writer( writer ) + {} + + ScopedElement( const ScopedElement& other ) + : m_writer( other.m_writer ){ + other.m_writer = NULL; + } + + ~ScopedElement() { + if( m_writer ) + m_writer->endElement(); + } + + ScopedElement& writeText( const std::string& text ) { + m_writer->writeText( text ); + return *this; + } + + template<typename T> + ScopedElement& writeAttribute( const std::string& name, const T& attribute ) { + m_writer->writeAttribute( name, attribute ); + return *this; + } + + private: + mutable XmlWriter* m_writer; + }; + + XmlWriter() + : m_tagIsOpen( false ), + m_needsNewline( false ), + m_os( &std::cout ) + {} + + XmlWriter( std::ostream& os ) + : m_tagIsOpen( false ), + m_needsNewline( false ), + m_os( &os ) + {} + + ~XmlWriter() { + while( !m_tags.empty() ) + endElement(); + } + + XmlWriter& operator = ( const XmlWriter& other ) { + XmlWriter temp( other ); + swap( temp ); + return *this; + } + + void swap( XmlWriter& other ) { + std::swap( m_tagIsOpen, other.m_tagIsOpen ); + std::swap( m_needsNewline, other.m_needsNewline ); + std::swap( m_tags, other.m_tags ); + std::swap( m_indent, other.m_indent ); + std::swap( m_os, other.m_os ); + } + + XmlWriter& startElement( const std::string& name ) { + ensureTagClosed(); + newlineIfNecessary(); + stream() << m_indent << "<" << name; + m_tags.push_back( name ); + m_indent += " "; + m_tagIsOpen = true; + return *this; + } + + ScopedElement scopedElement( const std::string& name ) { + ScopedElement scoped( this ); + startElement( name ); + return scoped; + } + + XmlWriter& endElement() { + newlineIfNecessary(); + m_indent = m_indent.substr( 0, m_indent.size()-2 ); + if( m_tagIsOpen ) { + stream() << "/>\n"; + m_tagIsOpen = false; + } + else { + stream() << m_indent << "</" << m_tags.back() << ">\n"; + } + m_tags.pop_back(); + return *this; + } + + XmlWriter& writeAttribute( const std::string& name, const std::string& attribute ) { + if( !name.empty() && !attribute.empty() ) { + stream() << " " << name << "=\""; + writeEncodedText( attribute ); + stream() << "\""; + } + return *this; + } + + XmlWriter& writeAttribute( const std::string& name, bool attribute ) { + stream() << " " << name << "=\"" << ( attribute ? "true" : "false" ) << "\""; + return *this; + } + + template<typename T> + XmlWriter& writeAttribute( const std::string& name, const T& attribute ) { + if( !name.empty() ) + stream() << " " << name << "=\"" << attribute << "\""; + return *this; + } + + XmlWriter& writeText( const std::string& text ) { + if( !text.empty() ){ + bool tagWasOpen = m_tagIsOpen; + ensureTagClosed(); + if( tagWasOpen ) + stream() << m_indent; + writeEncodedText( text ); + m_needsNewline = true; + } + return *this; + } + + XmlWriter& writeComment( const std::string& text ) { + ensureTagClosed(); + stream() << m_indent << "<!--" << text << "-->"; + m_needsNewline = true; + return *this; + } + + XmlWriter& writeBlankLine() { + ensureTagClosed(); + stream() << "\n"; + return *this; + } + + private: + + std::ostream& stream() { + return *m_os; + } + + void ensureTagClosed() { + if( m_tagIsOpen ) { + stream() << ">\n"; + m_tagIsOpen = false; + } + } + + void newlineIfNecessary() { + if( m_needsNewline ) { + stream() << "\n"; + m_needsNewline = false; + } + } + + void writeEncodedText( const std::string& text ) { + static const char* charsToEncode = "<&\""; + std::string mtext = text; + std::string::size_type pos = mtext.find_first_of( charsToEncode ); + while( pos != std::string::npos ) { + stream() << mtext.substr( 0, pos ); + + switch( mtext[pos] ) { + case '<': + stream() << "<"; + break; + case '&': + stream() << "&"; + break; + case '\"': + stream() << """; + break; + } + mtext = mtext.substr( pos+1 ); + pos = mtext.find_first_of( charsToEncode ); + } + stream() << mtext; + } + + bool m_tagIsOpen; + bool m_needsNewline; + std::vector<std::string> m_tags; + std::string m_indent; + std::ostream* m_os; + }; + +} +namespace Catch { + class XmlReporter : public SharedImpl<IReporter> { + public: + XmlReporter( const ReporterConfig& config ) : m_config( config ) {} + + static std::string getDescription() { + return "Reports test results as an XML document"; + } + + private: // IReporter + + virtual bool shouldRedirectStdout() const { + return true; + } + + virtual void StartTesting() { + m_xml = XmlWriter( m_config.stream ); + m_xml.startElement( "Catch" ); + if( !m_config.name.empty() ) + m_xml.writeAttribute( "name", m_config.name ); + } + + virtual void EndTesting( const Totals& totals ) { + m_xml.scopedElement( "OverallResults" ) + .writeAttribute( "successes", totals.assertions.passed ) + .writeAttribute( "failures", totals.assertions.failed ); + m_xml.endElement(); + } + + virtual void StartGroup( const std::string& groupName ) { + m_xml.startElement( "Group" ) + .writeAttribute( "name", groupName ); + } + + virtual void EndGroup( const std::string&, const Totals& totals ) { + m_xml.scopedElement( "OverallResults" ) + .writeAttribute( "successes", totals.assertions.passed ) + .writeAttribute( "failures", totals.assertions.failed ); + m_xml.endElement(); + } + + virtual void StartSection( const std::string& sectionName, const std::string& description ) { + m_xml.startElement( "Section" ) + .writeAttribute( "name", sectionName ) + .writeAttribute( "description", description ); + } + + virtual void EndSection( const std::string& /*sectionName*/, const Counts& assertions ) { + m_xml.scopedElement( "OverallResults" ) + .writeAttribute( "successes", assertions.passed ) + .writeAttribute( "failures", assertions.failed ); + m_xml.endElement(); + } + + virtual void StartTestCase( const Catch::TestCaseInfo& testInfo ) { + m_xml.startElement( "TestCase" ).writeAttribute( "name", testInfo.getName() ); + m_currentTestSuccess = true; + } + + virtual void Result( const Catch::ResultInfo& resultInfo ) { + if( !m_config.includeSuccessfulResults && resultInfo.getResultType() == ResultWas::Ok ) + return; + + if( resultInfo.hasExpression() ) { + m_xml.startElement( "Expression" ) + .writeAttribute( "success", resultInfo.ok() ) + .writeAttribute( "filename", resultInfo.getFilename() ) + .writeAttribute( "line", resultInfo.getLine() ); + + m_xml.scopedElement( "Original" ) + .writeText( resultInfo.getExpression() ); + m_xml.scopedElement( "Expanded" ) + .writeText( resultInfo.getExpandedExpression() ); + m_currentTestSuccess &= resultInfo.ok(); + } + + switch( resultInfo.getResultType() ) { + case ResultWas::ThrewException: + m_xml.scopedElement( "Exception" ) + .writeAttribute( "filename", resultInfo.getFilename() ) + .writeAttribute( "line", resultInfo.getLine() ) + .writeText( resultInfo.getMessage() ); + m_currentTestSuccess = false; + break; + case ResultWas::Info: + m_xml.scopedElement( "Info" ) + .writeText( resultInfo.getMessage() ); + break; + case ResultWas::Warning: + m_xml.scopedElement( "Warning" ) + .writeText( resultInfo.getMessage() ); + break; + case ResultWas::ExplicitFailure: + m_xml.scopedElement( "Failure" ) + .writeText( resultInfo.getMessage() ); + m_currentTestSuccess = false; + break; + case ResultWas::Unknown: + case ResultWas::Ok: + case ResultWas::FailureBit: + case ResultWas::ExpressionFailed: + case ResultWas::Exception: + case ResultWas::DidntThrowException: + default: + break; + } + if( resultInfo.hasExpression() ) + m_xml.endElement(); + } + + virtual void Aborted() { + // !TBD + } + + virtual void EndTestCase( const Catch::TestCaseInfo&, const Totals&, const std::string&, const std::string& ) { + m_xml.scopedElement( "OverallResult" ).writeAttribute( "success", m_currentTestSuccess ); + m_xml.endElement(); + } + + private: + ReporterConfig m_config; + bool m_currentTestSuccess; + XmlWriter m_xml; + }; + +} // end namespace Catch + +// #included from: reporters/catch_reporter_junit.hpp +#define TWOBLUECUBES_CATCH_REPORTER_JUNIT_HPP_INCLUDED + +namespace Catch { + + class JunitReporter : public SharedImpl<IReporter> { + + struct TestStats { + std::string m_element; + std::string m_resultType; + std::string m_message; + std::string m_content; + }; + + struct TestCaseStats { + + TestCaseStats( const std::string& name = std::string() ) :m_name( name ){} + + double m_timeInSeconds; + std::string m_status; + std::string m_className; + std::string m_name; + std::vector<TestStats> m_testStats; + }; + + struct Stats { + + Stats( const std::string& name = std::string() ) + : m_testsCount( 0 ), + m_failuresCount( 0 ), + m_disabledCount( 0 ), + m_errorsCount( 0 ), + m_timeInSeconds( 0 ), + m_name( name ) + {} + + std::size_t m_testsCount; + std::size_t m_failuresCount; + std::size_t m_disabledCount; + std::size_t m_errorsCount; + double m_timeInSeconds; + std::string m_name; + + std::vector<TestCaseStats> m_testCaseStats; + }; + + public: + JunitReporter( const ReporterConfig& config ) + : m_config( config ), + m_testSuiteStats( "AllTests" ), + m_currentStats( &m_testSuiteStats ) + {} + + static std::string getDescription() { + return "Reports test results in an XML format that looks like Ant's junitreport target"; + } + + private: // IReporter + + virtual bool shouldRedirectStdout() const { + return true; + } + + virtual void StartTesting(){} + + virtual void StartGroup( const std::string& groupName ) { + m_statsForSuites.push_back( Stats( groupName ) ); + m_currentStats = &m_statsForSuites.back(); + } + + virtual void EndGroup( const std::string&, const Totals& totals ) { + m_currentStats->m_testsCount = totals.assertions.total(); + m_currentStats = &m_testSuiteStats; + } + + virtual void StartSection( const std::string&, const std::string& ){} + + virtual void EndSection( const std::string&, const Counts& ){} + + virtual void StartTestCase( const Catch::TestCaseInfo& testInfo ) { + m_currentStats->m_testCaseStats.push_back( TestCaseStats( testInfo.getName() ) ); + } + + virtual void Result( const Catch::ResultInfo& resultInfo ) { + if( resultInfo.getResultType() != ResultWas::Ok || m_config.includeSuccessfulResults ) { + TestCaseStats& testCaseStats = m_currentStats->m_testCaseStats.back(); + TestStats stats; + std::ostringstream oss; + if( !resultInfo.getMessage().empty() ) + oss << resultInfo.getMessage() << " at "; + oss << SourceLineInfo( resultInfo.getFilename(), resultInfo.getLine() ); + stats.m_content = oss.str(); + stats.m_message = resultInfo.getExpandedExpression(); + stats.m_resultType = resultInfo.getTestMacroName(); + + switch( resultInfo.getResultType() ) { + case ResultWas::ThrewException: + stats.m_element = "error"; + m_currentStats->m_errorsCount++; + break; + case ResultWas::Info: + stats.m_element = "info"; // !TBD ? + break; + case ResultWas::Warning: + stats.m_element = "warning"; // !TBD ? + break; + case ResultWas::ExplicitFailure: + stats.m_element = "failure"; + m_currentStats->m_failuresCount++; + break; + case ResultWas::ExpressionFailed: + stats.m_element = "failure"; + m_currentStats->m_failuresCount++; + break; + case ResultWas::Ok: + stats.m_element = "success"; + break; + case ResultWas::Unknown: + case ResultWas::FailureBit: + case ResultWas::Exception: + case ResultWas::DidntThrowException: + default: + stats.m_element = "unknown"; + break; + } + testCaseStats.m_testStats.push_back( stats ); + } + } + + virtual void EndTestCase( const Catch::TestCaseInfo&, const Totals&, const std::string& stdOut, const std::string& stdErr ) { + if( !stdOut.empty() ) + m_stdOut << stdOut << "\n"; + if( !stdErr.empty() ) + m_stdErr << stdErr << "\n"; + } + + virtual void Aborted() { + // !TBD + } + + virtual void EndTesting( const Totals& ) { + std::ostream& str = m_config.stream; + { + XmlWriter xml( str ); + + if( m_statsForSuites.size() > 0 ) + xml.startElement( "testsuites" ); + + std::vector<Stats>::const_iterator it = m_statsForSuites.begin(); + std::vector<Stats>::const_iterator itEnd = m_statsForSuites.end(); + + for(; it != itEnd; ++it ) { + XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" ); + xml.writeAttribute( "name", it->m_name ); + xml.writeAttribute( "errors", it->m_errorsCount ); + xml.writeAttribute( "failures", it->m_failuresCount ); + xml.writeAttribute( "tests", it->m_testsCount ); + xml.writeAttribute( "hostname", "tbd" ); + xml.writeAttribute( "time", "tbd" ); + xml.writeAttribute( "timestamp", "tbd" ); + + OutputTestCases( xml, *it ); + } + + xml.scopedElement( "system-out" ).writeText( trim( m_stdOut.str() ) ); + xml.scopedElement( "system-err" ).writeText( trim( m_stdErr.str() ) ); + } + } + + void OutputTestCases( XmlWriter& xml, const Stats& stats ) { + std::vector<TestCaseStats>::const_iterator it = stats.m_testCaseStats.begin(); + std::vector<TestCaseStats>::const_iterator itEnd = stats.m_testCaseStats.end(); + for(; it != itEnd; ++it ) { + xml.writeBlankLine(); + xml.writeComment( "Test case" ); + + XmlWriter::ScopedElement e = xml.scopedElement( "testcase" ); + xml.writeAttribute( "classname", it->m_className ); + xml.writeAttribute( "name", it->m_name ); + xml.writeAttribute( "time", "tbd" ); + + OutputTestResult( xml, *it ); + } + } + + void OutputTestResult( XmlWriter& xml, const TestCaseStats& stats ) { + std::vector<TestStats>::const_iterator it = stats.m_testStats.begin(); + std::vector<TestStats>::const_iterator itEnd = stats.m_testStats.end(); + for(; it != itEnd; ++it ) { + if( it->m_element != "success" ) { + XmlWriter::ScopedElement e = xml.scopedElement( it->m_element ); + + xml.writeAttribute( "message", it->m_message ); + xml.writeAttribute( "type", it->m_resultType ); + if( !it->m_content.empty() ) + xml.writeText( it->m_content ); + } + } + } + + private: + ReporterConfig m_config; + bool m_currentTestSuccess; + + Stats m_testSuiteStats; + Stats* m_currentStats; + std::vector<Stats> m_statsForSuites; + std::ostringstream m_stdOut; + std::ostringstream m_stdErr; + }; + +} // end namespace Catch + +#include <fstream> +#include <stdlib.h> +#include <limits> + +namespace Catch { + + INTERNAL_CATCH_REGISTER_REPORTER( "basic", BasicReporter ) + INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter ) + INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter ) + + inline int Main( Config& config ) { + + std::string reporterName = config.data().reporter.empty() + ? "basic" + : config.data().reporter; + + ReporterConfig reporterConfig( config.getName(), config.stream(), config.includeSuccessfulResults() ); + + Ptr<IReporter> reporter = getRegistryHub().getReporterRegistry().create( reporterName, reporterConfig ); + + if( !reporter ) + { + std::cerr << "No reporter registered with name: '" << reporterName << "'" << std::endl; + return (std::numeric_limits<int>::max)(); + } + + if( !config.data().stream.empty() ) { + if( config.data().stream[0] == '%' ) + config.useStream( config.data().stream.substr( 1 ) ); + else + config.setFilename( config.data().stream ); + } + + // Handle list request + if( config.listWhat() != List::None ) + return List( config ); + + // Open output file, if specified + std::ofstream ofs; + if( !config.getFilename().empty() ) { + ofs.open( config.getFilename().c_str() ); + if( ofs.fail() ) { + std::cerr << "Unable to open file: '" << config.getFilename() << "'" << std::endl; + return (std::numeric_limits<int>::max)(); + } + config.setStreamBuf( ofs.rdbuf() ); + } + + int result = 0; + + // Scope here for the Runner so it can use the context before it is cleaned-up + { + Runner runner( config, reporter ); + + // Run test specs specified on the command line - or default to all + if( !config.testsSpecified() ) { + runner.runAll(); + } + else { + // !TBD We should get all the testcases upfront, report any missing, + // then just run them + std::vector<std::string>::const_iterator it = config.getTestSpecs().begin(); + std::vector<std::string>::const_iterator itEnd = config.getTestSpecs().end(); + for(; it != itEnd; ++it ) { + if( runner.runMatching( *it ) == 0 ) { + std::cerr << "\n[No test cases matched with: " << *it << "]" << std::endl; + } + } + } + result = static_cast<int>( runner.getTotals().assertions.failed ); + } + Catch::cleanUp(); + return result; + } + + inline void showUsage( std::ostream& os ) { + os << "\t-?, -h, --help\n" + << "\t-l, --list <tests | reporters> [xml]\n" + << "\t-t, --test <testspec> [<testspec>...]\n" + << "\t-r, --reporter <reporter name>\n" + << "\t-o, --out <file name>|<%stream name>\n" + << "\t-s, --success\n" + << "\t-b, --break\n" + << "\t-n, --name <name>\n" + << "\t-a, --abort [#]\n" + << "\t-nt, --nothrow\n\n" + << "For more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line" << std::endl; + } + inline void showHelp( std::string exeName ) { + std::string::size_type pos = exeName.find_last_of( "/\\" ); + if( pos != std::string::npos ) { + exeName = exeName.substr( pos+1 ); + } + + std::cout << exeName << " is a CATCH host application. Options are as follows:\n\n"; + showUsage( std::cout ); + } - void StartSpansLazily() { - if( !m_testingSpan.emitted ) { - if( m_config.name.empty() ) - m_config.stream << "[Started testing]" << std::endl; - else - m_config.stream << "[Started testing: " << m_config.name << "]" << std::endl; - m_testingSpan.emitted = true; - } + inline int Main( int argc, char* const argv[], Config& config ) { - if( !m_groupSpan.emitted && !m_groupSpan.name.empty() ) { - m_config.stream << "[Started group: '" << m_groupSpan.name << "']" << std::endl; - m_groupSpan.emitted = true; - } + try { + CommandParser parser( argc, argv ); - if( !m_testSpan.emitted ) { - m_config.stream << std::endl << "[Running: " << m_testSpan.name << "]" << std::endl; - m_testSpan.emitted = true; - } + if( Command cmd = parser.find( "-h", "-?", "--help" ) ) { + if( cmd.argsCount() != 0 ) + cmd.raiseError( "Does not accept arguments" ); - if( !m_sectionSpans.empty() ) { - SpanInfo& sectionSpan = m_sectionSpans.back(); - if( !sectionSpan.emitted && !sectionSpan.name.empty() ) { - if( m_firstSectionInTestCase ) { - m_config.stream << "\n"; - m_firstSectionInTestCase = false; - } - std::vector<SpanInfo>::iterator it = m_sectionSpans.begin(); - std::vector<SpanInfo>::iterator itEnd = m_sectionSpans.end(); - for(; it != itEnd; ++it ) { - SpanInfo& prevSpan = *it; - if( !prevSpan.emitted && !prevSpan.name.empty() ) { - m_config.stream << "[Started section: '" << prevSpan.name << "']" << std::endl; - prevSpan.emitted = true; - } - } - } + showHelp( argv[0] ); + Catch::cleanUp(); + return 0; } - } - void streamVariableLengthText( const std::string& prefix, const std::string& text ) { - std::string trimmed = trim( text ); - if( trimmed.find_first_of( "\r\n" ) == std::string::npos ) { - m_config.stream << "[" << prefix << ": " << trimmed << "]\n"; - } - else { - m_config.stream << "\n[" << prefix << "] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" << trimmed - << "\n[end of " << prefix << "] <<<<<<<<<<<<<<<<<<<<<<<<\n"; - } + parseIntoConfig( parser, config.data() ); + } + catch( std::exception& ex ) { + std::cerr << ex.what() << "\n\nUsage: ...\n\n"; + showUsage( std::cerr ); + Catch::cleanUp(); + return (std::numeric_limits<int>::max)(); } - private: - ReporterConfig m_config; - bool m_firstSectionInTestCase; + return Main( config ); + } - SpanInfo m_testingSpan; - SpanInfo m_groupSpan; - SpanInfo m_testSpan; - std::vector<SpanInfo> m_sectionSpans; - bool m_aborted; - }; + inline int Main( int argc, char* const argv[] ) { + Config config; +// !TBD: This doesn't always work, for some reason +// if( isDebuggerActive() ) +// config.useStream( "debug" ); + return Main( argc, argv, config ); + } } // end namespace Catch -// #included from: reporters/catch_reporter_xml.hpp +// #included from: internal/catch_impl.hpp -// #included from: ../internal/catch_xmlwriter.hpp +// Collect all the implementation files together here +// These are the equivalent of what would usually be cpp files +// #included from: catch_registry_hub.hpp + +// #included from: catch_test_case_registry_impl.hpp -#include <sstream> -#include <string> #include <vector> +#include <set> +#include <sstream> +#include <iostream> namespace Catch { - class XmlWriter { + class TestRegistry : public ITestCaseRegistry { public: + TestRegistry() : m_unnamedCount( 0 ) {} - class ScopedElement { - public: - ScopedElement( XmlWriter* writer ) - : m_writer( writer ) - {} - - ScopedElement( const ScopedElement& other ) - : m_writer( other.m_writer ){ - other.m_writer = NULL; + virtual void registerTest( const TestCaseInfo& testInfo ) { + if( testInfo.getName() == "" ) { + std::ostringstream oss; + oss << testInfo.getName() << "unnamed/" << ++m_unnamedCount; + return registerTest( TestCaseInfo( testInfo, oss.str() ) ); } - ~ScopedElement() { - if( m_writer ) - m_writer->endElement(); + if( m_functions.find( testInfo ) == m_functions.end() ) { + m_functions.insert( testInfo ); + m_functionsInOrder.push_back( testInfo ); } - - ScopedElement& writeText( const std::string& text ) { - m_writer->writeText( text ); - return *this; + else { + const TestCaseInfo& prev = *m_functions.find( testInfo ); + std::cerr << "error: TEST_CASE( \"" << testInfo.getName() << "\" ) already defined.\n" + << "\tFirst seen at " << SourceLineInfo( prev.getLineInfo() ) << "\n" + << "\tRedefined at " << SourceLineInfo( testInfo.getLineInfo() ) << std::endl; + exit(1); } + } - template<typename T> - ScopedElement& writeAttribute( const std::string& name, const T& attribute ) { - m_writer->writeAttribute( name, attribute ); - return *this; + virtual const std::vector<TestCaseInfo>& getAllTests() const { + return m_functionsInOrder; + } + + virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) const { + TestSpec testSpec( rawTestSpec ); + + std::vector<TestCaseInfo> testList; + std::vector<TestCaseInfo>::const_iterator it = m_functionsInOrder.begin(); + std::vector<TestCaseInfo>::const_iterator itEnd = m_functionsInOrder.end(); + for(; it != itEnd; ++it ) { + if( testSpec.matches( it->getName() ) ) { + testList.push_back( *it ); + } } + return testList; + } - private: - mutable XmlWriter* m_writer; - }; + private: - XmlWriter() - : m_tagIsOpen( false ), - m_needsNewline( false ), - m_os( &std::cout ) - {} + std::set<TestCaseInfo> m_functions; + std::vector<TestCaseInfo> m_functionsInOrder; + size_t m_unnamedCount; + }; - XmlWriter( std::ostream& os ) - : m_tagIsOpen( false ), - m_needsNewline( false ), - m_os( &os ) - {} + /////////////////////////////////////////////////////////////////////////// - ~XmlWriter() { - while( !m_tags.empty() ) - endElement(); - } + class FreeFunctionTestCase : public ITestCase { + public: - XmlWriter& operator = ( const XmlWriter& other ) { - XmlWriter temp( other ); - swap( temp ); - return *this; - } + FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {} - void swap( XmlWriter& other ) { - std::swap( m_tagIsOpen, other.m_tagIsOpen ); - std::swap( m_needsNewline, other.m_needsNewline ); - std::swap( m_tags, other.m_tags ); - std::swap( m_indent, other.m_indent ); - std::swap( m_os, other.m_os ); + virtual void invoke() const { + m_fun(); } - XmlWriter& startElement( const std::string& name ) { - ensureTagClosed(); - newlineIfNecessary(); - stream() << m_indent << "<" << name; - m_tags.push_back( name ); - m_indent += " "; - m_tagIsOpen = true; - return *this; + virtual ITestCase* clone() const { + return new FreeFunctionTestCase( m_fun ); } - ScopedElement scopedElement( const std::string& name ) { - ScopedElement scoped( this ); - startElement( name ); - return scoped; + virtual bool operator == ( const ITestCase& other ) const { + const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other ); + return ffOther && m_fun == ffOther->m_fun; } - XmlWriter& endElement() { - newlineIfNecessary(); - m_indent = m_indent.substr( 0, m_indent.size()-2 ); - if( m_tagIsOpen ) { - stream() << "/>\n"; - m_tagIsOpen = false; - } - else { - stream() << m_indent << "</" << m_tags.back() << ">\n"; - } - m_tags.pop_back(); - return *this; + virtual bool operator < ( const ITestCase& other ) const { + const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other ); + return ffOther && m_fun < ffOther->m_fun; } - XmlWriter& writeAttribute( const std::string& name, const std::string& attribute ) { - if( !name.empty() && !attribute.empty() ) { - stream() << " " << name << "=\""; - writeEncodedText( attribute ); - stream() << "\""; - } - return *this; - } + private: + TestFunction m_fun; + }; - XmlWriter& writeAttribute( const std::string& name, bool attribute ) { - stream() << " " << name << "=\"" << ( attribute ? "true" : "false" ) << "\""; - return *this; - } + /////////////////////////////////////////////////////////////////////////// - template<typename T> - XmlWriter& writeAttribute( const std::string& name, const T& attribute ) { - if( !name.empty() ) - stream() << " " << name << "=\"" << attribute << "\""; - return *this; + AutoReg::AutoReg( TestFunction function, + const char* name, + const char* description, + const SourceLineInfo& lineInfo ) { + registerTestCase( new FreeFunctionTestCase( function ), name, description, lineInfo ); + } + + AutoReg::~AutoReg() {} + + void AutoReg::registerTestCase( ITestCase* testCase, + const char* name, + const char* description, + const SourceLineInfo& lineInfo ) { + getMutableRegistryHub().registerTest( TestCaseInfo( testCase, name, description, lineInfo ) ); + } + +} // end namespace Catch + +// #included from: catch_reporter_registry.hpp +#define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED + +#include <map> + +namespace Catch { + + class ReporterRegistry : public IReporterRegistry { + + public: + + ~ReporterRegistry() { + deleteAllValues( m_factories ); } - XmlWriter& writeText( const std::string& text ) { - if( !text.empty() ){ - bool tagWasOpen = m_tagIsOpen; - ensureTagClosed(); - if( tagWasOpen ) - stream() << m_indent; - writeEncodedText( text ); - m_needsNewline = true; - } - return *this; + virtual IReporter* create( const std::string& name, const ReporterConfig& config ) const { + FactoryMap::const_iterator it = m_factories.find( name ); + if( it == m_factories.end() ) + return NULL; + return it->second->create( config ); } - XmlWriter& writeComment( const std::string& text ) { - ensureTagClosed(); - stream() << m_indent << "<!--" << text << "-->"; - m_needsNewline = true; - return *this; + void registerReporter( const std::string& name, IReporterFactory* factory ) { + m_factories.insert( std::make_pair( name, factory ) ); } - XmlWriter& writeBlankLine() { - ensureTagClosed(); - stream() << "\n"; - return *this; + const FactoryMap& getFactories() const { + return m_factories; } private: + FactoryMap m_factories; + }; +} - std::ostream& stream() { - return *m_os; +// #included from: catch_exception_translator_registry.hpp +#define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_HPP_INCLUDED + +#ifdef __OBJC__ +#import "Foundation/Foundation.h" +#endif + +namespace Catch { + + class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { + public: + ~ExceptionTranslatorRegistry() { + deleteAll( m_translators ); } - void ensureTagClosed() { - if( m_tagIsOpen ) { - stream() << ">\n"; - m_tagIsOpen = false; - } + virtual void registerTranslator( const IExceptionTranslator* translator ) { + m_translators.push_back( translator ); } - void newlineIfNecessary() { - if( m_needsNewline ) { - stream() << "\n"; - m_needsNewline = false; + virtual std::string translateActiveException() const { + try { +#ifdef __OBJC__ + // In Objective-C try objective-c exceptions first + @try { + throw; + } + @catch (NSException *exception) { + return toString( [exception description] ); + } +#else + throw; +#endif + } + catch( std::exception& ex ) { + return ex.what(); + } + catch( std::string& msg ) { + return msg; + } + catch( const char* msg ) { + return msg; + } + catch(...) { + return tryTranslators( m_translators.begin() ); } } - void writeEncodedText( const std::string& text ) { - static const char* charsToEncode = "<&\""; - std::string mtext = text; - std::string::size_type pos = mtext.find_first_of( charsToEncode ); - while( pos != std::string::npos ) { - stream() << mtext.substr( 0, pos ); + std::string tryTranslators( std::vector<const IExceptionTranslator*>::const_iterator it ) const { + if( it == m_translators.end() ) + return "Unknown exception"; - switch( mtext[pos] ) { - case '<': - stream() << "<"; - break; - case '&': - stream() << "&"; - break; - case '\"': - stream() << """; - break; - } - mtext = mtext.substr( pos+1 ); - pos = mtext.find_first_of( charsToEncode ); + try { + return (*it)->translate(); + } + catch(...) { + return tryTranslators( it+1 ); } - stream() << mtext; } - bool m_tagIsOpen; - bool m_needsNewline; - std::vector<std::string> m_tags; - std::string m_indent; - std::ostream* m_os; + private: + std::vector<const IExceptionTranslator*> m_translators; }; - } + namespace Catch { - class XmlReporter : public SharedImpl<IReporter> { - public: - XmlReporter( const ReporterConfig& config ) : m_config( config ) {} - static std::string getDescription() { - return "Reports test results as an XML document"; - } + namespace { - private: // IReporter + class RegistryHub : public IRegistryHub, public IMutableRegistryHub { - virtual bool shouldRedirectStdout() const { - return true; - } + RegistryHub( const RegistryHub& ); + void operator=( const RegistryHub& ); - virtual void StartTesting() { - m_xml = XmlWriter( m_config.stream ); - m_xml.startElement( "Catch" ); - if( !m_config.name.empty() ) - m_xml.writeAttribute( "name", m_config.name ); - } + public: // IRegistryHub + RegistryHub() { + } + virtual const IReporterRegistry& getReporterRegistry() const { + return m_reporterRegistry; + } + virtual const ITestCaseRegistry& getTestCaseRegistry() const { + return m_testCaseRegistry; + } + virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() { + return m_exceptionTranslatorRegistry; + } - virtual void EndTesting( const Totals& totals ) { - m_xml.scopedElement( "OverallResults" ) - .writeAttribute( "successes", totals.assertions.passed ) - .writeAttribute( "failures", totals.assertions.failed ); - m_xml.endElement(); - } + public: // IMutableRegistryHub + virtual void registerReporter( const std::string& name, IReporterFactory* factory ) { + m_reporterRegistry.registerReporter( name, factory ); + } + virtual void registerTest( const TestCaseInfo& testInfo ) { + m_testCaseRegistry.registerTest( testInfo ); + } + virtual void registerTranslator( const IExceptionTranslator* translator ) { + m_exceptionTranslatorRegistry.registerTranslator( translator ); + } - virtual void StartGroup( const std::string& groupName ) { - m_xml.startElement( "Group" ) - .writeAttribute( "name", groupName ); - } + private: + TestRegistry m_testCaseRegistry; + ReporterRegistry m_reporterRegistry; + ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; + }; - virtual void EndGroup( const std::string&, const Totals& totals ) { - m_xml.scopedElement( "OverallResults" ) - .writeAttribute( "successes", totals.assertions.passed ) - .writeAttribute( "failures", totals.assertions.failed ); - m_xml.endElement(); + // Single, global, instance + inline RegistryHub*& getTheRegistryHub() { + static RegistryHub* theRegistryHub = NULL; + if( !theRegistryHub ) + theRegistryHub = new RegistryHub(); + return theRegistryHub; } + } - virtual void StartSection( const std::string& sectionName, const std::string& description ) { - m_xml.startElement( "Section" ) - .writeAttribute( "name", sectionName ) - .writeAttribute( "description", description ); - } + IRegistryHub& getRegistryHub() { + return *getTheRegistryHub(); + } + IMutableRegistryHub& getMutableRegistryHub() { + return *getTheRegistryHub(); + } + void cleanUp() { + delete getTheRegistryHub(); + getTheRegistryHub() = NULL; + cleanUpContext(); + } - virtual void EndSection( const std::string& /*sectionName*/, const Counts& assertions ) { - m_xml.scopedElement( "OverallResults" ) - .writeAttribute( "successes", assertions.passed ) - .writeAttribute( "failures", assertions.failed ); - m_xml.endElement(); - } +} // end namespace Catch +// #included from: catch_notimplemented_exception.hpp +#define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED - virtual void StartTestCase( const Catch::TestCaseInfo& testInfo ) { - m_xml.startElement( "TestCase" ).writeAttribute( "name", testInfo.getName() ); - m_currentTestSuccess = true; - } +#include <ostream> - virtual void Result( const Catch::ResultInfo& resultInfo ) { - if( !m_config.includeSuccessfulResults && resultInfo.getResultType() == ResultWas::Ok ) - return; +namespace Catch { - if( resultInfo.hasExpression() ) { - m_xml.startElement( "Expression" ) - .writeAttribute( "success", resultInfo.ok() ) - .writeAttribute( "filename", resultInfo.getFilename() ) - .writeAttribute( "line", resultInfo.getLine() ); + NotImplementedException::NotImplementedException( const SourceLineInfo& lineInfo ) + : m_lineInfo( lineInfo ) { + std::ostringstream oss; + oss << lineInfo << "function "; + if( !lineInfo.function.empty() ) + oss << lineInfo.function << " "; + oss << "not implemented"; + m_what = oss.str(); + } - m_xml.scopedElement( "Original" ) - .writeText( resultInfo.getExpression() ); - m_xml.scopedElement( "Expanded" ) - .writeText( resultInfo.getExpandedExpression() ); - m_currentTestSuccess &= resultInfo.ok(); - } + const char* NotImplementedException::what() const throw() { + return m_what.c_str(); + } - switch( resultInfo.getResultType() ) { - case ResultWas::ThrewException: - m_xml.scopedElement( "Exception" ) - .writeAttribute( "filename", resultInfo.getFilename() ) - .writeAttribute( "line", resultInfo.getLine() ) - .writeText( resultInfo.getMessage() ); - m_currentTestSuccess = false; - break; - case ResultWas::Info: - m_xml.scopedElement( "Info" ) - .writeText( resultInfo.getMessage() ); - break; - case ResultWas::Warning: - m_xml.scopedElement( "Warning" ) - .writeText( resultInfo.getMessage() ); - break; - case ResultWas::ExplicitFailure: - m_xml.scopedElement( "Failure" ) - .writeText( resultInfo.getMessage() ); - m_currentTestSuccess = false; - break; - case ResultWas::Unknown: - case ResultWas::Ok: - case ResultWas::FailureBit: - case ResultWas::ExpressionFailed: - case ResultWas::Exception: - case ResultWas::DidntThrowException: - default: - break; - } - if( resultInfo.hasExpression() ) - m_xml.endElement(); +} // end namespace Catch + +// #included from: catch_context_impl.hpp + +// #included from: catch_stream.hpp +#define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED + +#include <stdexcept> +#include <cstdio> + +namespace Catch { + + template<typename WriterF, size_t bufferSize=256> + class StreamBufImpl : public StreamBufBase { + char data[bufferSize]; + WriterF m_writer; + + public: + StreamBufImpl() { + setp( data, data + sizeof(data) ); } - virtual void Aborted() { - // !TBD + ~StreamBufImpl() { + sync(); } - virtual void EndTestCase( const Catch::TestCaseInfo&, const Totals&, const std::string&, const std::string& ) { - m_xml.scopedElement( "OverallResult" ).writeAttribute( "success", m_currentTestSuccess ); - m_xml.endElement(); + private: + int overflow( int c ) { + sync(); + + if( c != EOF ) { + if( pbase() == epptr() ) + m_writer( std::string( 1, static_cast<char>( c ) ) ); + else + sputc( static_cast<char>( c ) ); + } + return 0; } - private: - ReporterConfig m_config; - bool m_currentTestSuccess; - XmlWriter m_xml; + int sync() { + if( pbase() != pptr() ) { + m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) ); + setp( pbase(), epptr() ); + } + return 0; + } }; -} // end namespace Catch + /////////////////////////////////////////////////////////////////////////// -// #included from: reporters/catch_reporter_junit.hpp + struct OutputDebugWriter { + + void operator()( const std::string &str ) { + writeToDebugConsole( str ); + } + }; +} namespace Catch { - class JunitReporter : public SharedImpl<IReporter> { + class Context : public IMutableContext { - struct TestStats { - std::string m_element; - std::string m_resultType; - std::string m_message; - std::string m_content; - }; + Context() : m_config( NULL ) {} + Context( const Context& ); + void operator=( const Context& ); - struct TestCaseStats { + public: // IContext + virtual IResultCapture& getResultCapture() { + return *m_resultCapture; + } + virtual IRunner& getRunner() { + return *m_runner; + } + virtual size_t getGeneratorIndex( const std::string& fileInfo, size_t totalSize ) { + return getGeneratorsForCurrentTest() + .getGeneratorInfo( fileInfo, totalSize ) + .getCurrentIndex(); + } + virtual bool advanceGeneratorsForCurrentTest() { + IGeneratorsForTest* generators = findGeneratorsForCurrentTest(); + return generators && generators->moveNext(); + } - TestCaseStats( const std::string& name = std::string() ) :m_name( name ){} + virtual const IConfig* getConfig() const { + return m_config; + } - double m_timeInSeconds; - std::string m_status; - std::string m_className; - std::string m_name; - std::vector<TestStats> m_testStats; - }; + public: // IMutableContext + virtual void setResultCapture( IResultCapture* resultCapture ) { + m_resultCapture = resultCapture; + } + virtual void setRunner( IRunner* runner ) { + m_runner = runner; + } + virtual void setConfig( const IConfig* config ) { + m_config = config; + } - struct Stats { + friend IMutableContext& getCurrentMutableContext(); - Stats( const std::string& name = std::string() ) - : m_testsCount( 0 ), - m_failuresCount( 0 ), - m_disabledCount( 0 ), - m_errorsCount( 0 ), - m_timeInSeconds( 0 ), - m_name( name ) - {} + private: + IGeneratorsForTest* findGeneratorsForCurrentTest() { + std::string testName = getResultCapture().getCurrentTestName(); - std::size_t m_testsCount; - std::size_t m_failuresCount; - std::size_t m_disabledCount; - std::size_t m_errorsCount; - double m_timeInSeconds; - std::string m_name; + std::map<std::string, IGeneratorsForTest*>::const_iterator it = + m_generatorsByTestName.find( testName ); + return it != m_generatorsByTestName.end() + ? it->second + : NULL; + } - std::vector<TestCaseStats> m_testCaseStats; - }; + IGeneratorsForTest& getGeneratorsForCurrentTest() { + IGeneratorsForTest* generators = findGeneratorsForCurrentTest(); + if( !generators ) { + std::string testName = getResultCapture().getCurrentTestName(); + generators = createGeneratorsForTest(); + m_generatorsByTestName.insert( std::make_pair( testName, generators ) ); + } + return *generators; + } - public: - JunitReporter( const ReporterConfig& config ) - : m_config( config ), - m_testSuiteStats( "AllTests" ), - m_currentStats( &m_testSuiteStats ) - {} + private: + IRunner* m_runner; + IResultCapture* m_resultCapture; + const IConfig* m_config; + std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName; + }; - static std::string getDescription() { - return "Reports test results in an XML format that looks like Ant's junitreport target"; - } + namespace { + Context* currentContext = NULL; + } + IMutableContext& getCurrentMutableContext() { + if( !currentContext ) + currentContext = new Context(); + return *currentContext; + } + IContext& getCurrentContext() { + return getCurrentMutableContext(); + } - private: // IReporter + std::streambuf* createStreamBuf( const std::string& streamName ) { + if( streamName == "stdout" ) return std::cout.rdbuf(); + if( streamName == "stderr" ) return std::cerr.rdbuf(); + if( streamName == "debug" ) return new StreamBufImpl<OutputDebugWriter>; - virtual bool shouldRedirectStdout() const { - return true; + throw std::domain_error( "Unknown stream: " + streamName ); + } + + void cleanUpContext() { + delete currentContext; + currentContext = NULL; + } +} +// #included from: catch_console_colour_impl.hpp +#define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED + +#ifdef CATCH_PLATFORM_WINDOWS + +#include <windows.h> + +namespace Catch { + + namespace { + + WORD mapConsoleColour( TextColour::Colours colour ) { + switch( colour ) { + case TextColour::FileName: + return FOREGROUND_INTENSITY; // greyed out + case TextColour::ResultError: + return FOREGROUND_RED | FOREGROUND_INTENSITY; // bright red + case TextColour::ResultSuccess: + return FOREGROUND_GREEN | FOREGROUND_INTENSITY; // bright green + case TextColour::Error: + return FOREGROUND_RED; // dark red + case TextColour::Success: + return FOREGROUND_GREEN; // dark green + case TextColour::OriginalExpression: + return FOREGROUND_BLUE | FOREGROUND_GREEN; // turquoise + case TextColour::ReconstructedExpression: + return FOREGROUND_RED | FOREGROUND_GREEN; // greeny-yellow + default: return 0; + } } + } - virtual void StartTesting(){} + struct ConsoleColourImpl { - virtual void StartGroup( const std::string& groupName ) { - m_statsForSuites.push_back( Stats( groupName ) ); - m_currentStats = &m_statsForSuites.back(); + ConsoleColourImpl() + : hStdout( GetStdHandle(STD_OUTPUT_HANDLE) ), + wOldColorAttrs( 0 ) + { + GetConsoleScreenBufferInfo( hStdout, &csbiInfo ); + wOldColorAttrs = csbiInfo.wAttributes; } - virtual void EndGroup( const std::string&, const Totals& totals ) { - m_currentStats->m_testsCount = totals.assertions.total(); - m_currentStats = &m_testSuiteStats; + ~ConsoleColourImpl() { + SetConsoleTextAttribute( hStdout, wOldColorAttrs ); } - virtual void StartSection( const std::string&, const std::string& ){} + void set( TextColour::Colours colour ) { + WORD consoleColour = mapConsoleColour( colour ); + if( consoleColour > 0 ) + SetConsoleTextAttribute( hStdout, consoleColour ); + } - virtual void EndSection( const std::string&, const Counts& ){} + HANDLE hStdout; + CONSOLE_SCREEN_BUFFER_INFO csbiInfo; + WORD wOldColorAttrs; + }; - virtual void StartTestCase( const Catch::TestCaseInfo& testInfo ) { - m_currentStats->m_testCaseStats.push_back( TestCaseStats( testInfo.getName() ) ); - } + TextColour::TextColour( Colours colour ) + : m_impl( new ConsoleColourImpl() ) + { + if( colour ) + m_impl->set( colour ); + } - virtual void Result( const Catch::ResultInfo& resultInfo ) { - if( resultInfo.getResultType() != ResultWas::Ok || m_config.includeSuccessfulResults ) { - TestCaseStats& testCaseStats = m_currentStats->m_testCaseStats.back(); - TestStats stats; - std::ostringstream oss; - if( !resultInfo.getMessage().empty() ) - oss << resultInfo.getMessage() << " at "; - oss << SourceLineInfo( resultInfo.getFilename(), resultInfo.getLine() ); - stats.m_content = oss.str(); - stats.m_message = resultInfo.getExpandedExpression(); - stats.m_resultType = resultInfo.getTestMacroName(); + TextColour::~TextColour() { + delete m_impl; + } - switch( resultInfo.getResultType() ) { - case ResultWas::ThrewException: - stats.m_element = "error"; - m_currentStats->m_errorsCount++; - break; - case ResultWas::Info: - stats.m_element = "info"; // !TBD ? - break; - case ResultWas::Warning: - stats.m_element = "warning"; // !TBD ? - break; - case ResultWas::ExplicitFailure: - stats.m_element = "failure"; - m_currentStats->m_failuresCount++; - break; - case ResultWas::ExpressionFailed: - stats.m_element = "failure"; - m_currentStats->m_failuresCount++; - break; - case ResultWas::Ok: - stats.m_element = "success"; - break; - case ResultWas::Unknown: - case ResultWas::FailureBit: - case ResultWas::Exception: - case ResultWas::DidntThrowException: - default: - stats.m_element = "unknown"; - break; - } - testCaseStats.m_testStats.push_back( stats ); - } - } + void TextColour::set( Colours colour ) { + m_impl->set( colour ); + } + +} // end namespace Catch + +#else + +namespace Catch { + TextColour::TextColour( Colours ){} + TextColour::~TextColour(){} + void TextColour::set( Colours ){} - virtual void EndTestCase( const Catch::TestCaseInfo&, const Totals&, const std::string& stdOut, const std::string& stdErr ) { - if( !stdOut.empty() ) - m_stdOut << stdOut << "\n"; - if( !stdErr.empty() ) - m_stdErr << stdErr << "\n"; - } +} // end namespace Catch - virtual void Aborted() { - // !TBD - } +#endif - virtual void EndTesting( const Totals& ) { - std::ostream& str = m_config.stream; - { - XmlWriter xml( str ); +// #included from: catch_generators_impl.hpp +#define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED - if( m_statsForSuites.size() > 0 ) - xml.startElement( "testsuites" ); +#include <vector> +#include <string> +#include <map> - std::vector<Stats>::const_iterator it = m_statsForSuites.begin(); - std::vector<Stats>::const_iterator itEnd = m_statsForSuites.end(); +namespace Catch { - for(; it != itEnd; ++it ) { - XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" ); - xml.writeAttribute( "name", it->m_name ); - xml.writeAttribute( "errors", it->m_errorsCount ); - xml.writeAttribute( "failures", it->m_failuresCount ); - xml.writeAttribute( "tests", it->m_testsCount ); - xml.writeAttribute( "hostname", "tbd" ); - xml.writeAttribute( "time", "tbd" ); - xml.writeAttribute( "timestamp", "tbd" ); + struct GeneratorInfo : IGeneratorInfo { - OutputTestCases( xml, *it ); - } + GeneratorInfo( std::size_t size ) + : m_size( size ), + m_currentIndex( 0 ) + {} - xml.scopedElement( "system-out" ).writeText( trim( m_stdOut.str() ) ); - xml.scopedElement( "system-err" ).writeText( trim( m_stdErr.str() ) ); + bool moveNext() { + if( ++m_currentIndex == m_size ) { + m_currentIndex = 0; + return false; } + return true; } - void OutputTestCases( XmlWriter& xml, const Stats& stats ) { - std::vector<TestCaseStats>::const_iterator it = stats.m_testCaseStats.begin(); - std::vector<TestCaseStats>::const_iterator itEnd = stats.m_testCaseStats.end(); - for(; it != itEnd; ++it ) { - xml.writeBlankLine(); - xml.writeComment( "Test case" ); + std::size_t getCurrentIndex() const { + return m_currentIndex; + } - XmlWriter::ScopedElement e = xml.scopedElement( "testcase" ); - xml.writeAttribute( "classname", it->m_className ); - xml.writeAttribute( "name", it->m_name ); - xml.writeAttribute( "time", "tbd" ); + std::size_t m_size; + std::size_t m_currentIndex; + }; - OutputTestResult( xml, *it ); + /////////////////////////////////////////////////////////////////////////// + + class GeneratorsForTest : public IGeneratorsForTest { + + public: + ~GeneratorsForTest() { + deleteAll( m_generatorsInOrder ); + } + + IGeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) { + std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo ); + if( it == m_generatorsByName.end() ) { + IGeneratorInfo* info = new GeneratorInfo( size ); + m_generatorsByName.insert( std::make_pair( fileInfo, info ) ); + m_generatorsInOrder.push_back( info ); + return *info; } + return *it->second; } - void OutputTestResult( XmlWriter& xml, const TestCaseStats& stats ) { - std::vector<TestStats>::const_iterator it = stats.m_testStats.begin(); - std::vector<TestStats>::const_iterator itEnd = stats.m_testStats.end(); + bool moveNext() { + std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin(); + std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end(); for(; it != itEnd; ++it ) { - if( it->m_element != "success" ) { - XmlWriter::ScopedElement e = xml.scopedElement( it->m_element ); - - xml.writeAttribute( "message", it->m_message ); - xml.writeAttribute( "type", it->m_resultType ); - if( !it->m_content.empty() ) - xml.writeText( it->m_content ); - } + if( (*it)->moveNext() ) + return true; } + return false; } private: - ReporterConfig m_config; - bool m_currentTestSuccess; - - Stats m_testSuiteStats; - Stats* m_currentStats; - std::vector<Stats> m_statsForSuites; - std::ostringstream m_stdOut; - std::ostringstream m_stdErr; + std::map<std::string, IGeneratorInfo*> m_generatorsByName; + std::vector<IGeneratorInfo*> m_generatorsInOrder; }; + IGeneratorsForTest* createGeneratorsForTest() + { + return new GeneratorsForTest(); + } + } // end namespace Catch -#include <fstream> -#include <stdlib.h> -#include <limits> +// #included from: catch_resultinfo.hpp +#define TWOBLUECUBES_CATCH_RESULT_INFO_HPP_INCLUDED namespace Catch { - INTERNAL_CATCH_REGISTER_REPORTER( "basic", BasicReporter ) - INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter ) - INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter ) + ResultInfo::ResultInfo() + : m_macroName(), + m_expr(), + m_lhs(), + m_rhs(), + m_op(), + m_message(), + m_result( ResultWas::Unknown ), + m_isNot( false ) + {} - inline int Main( Config& config ) { + 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; + } - std::string reporterName = config.data().reporter.empty() - ? "basic" - : config.data().reporter; + ResultInfo::~ResultInfo() {} - ReporterConfig reporterConfig( config.getName(), config.stream(), config.includeSuccessfulResults() ); + bool ResultInfo::ok() const { + return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit; + } - Ptr<IReporter> reporter = getCurrentContext().getReporterRegistry().create( reporterName, reporterConfig ); + ResultWas::OfType ResultInfo::getResultType() const { + return m_result; + } - if( !reporter ) - { - std::cerr << "No reporter registered with name: " << reporterName << "'" << std::endl; - return (std::numeric_limits<int>::max)(); - } + bool ResultInfo::hasExpression() const { + return !m_expr.empty(); + } - if( !config.data().stream.empty() ) { - if( config.data().stream[0] == '%' ) - config.useStream( config.data().stream.substr( 1 ) ); - else - config.setFilename( config.data().stream ); - } + bool ResultInfo::hasMessage() const { + return !m_message.empty(); + } - // Handle list request - if( config.listWhat() != List::None ) - return List( config ); + std::string ResultInfo::getExpression() const { + return m_expr; + } - // Open output file, if specified - std::ofstream ofs; - if( !config.getFilename().empty() ) { - ofs.open( config.getFilename().c_str() ); - if( ofs.fail() ) { - std::cerr << "Unable to open file: '" << config.getFilename() << "'" << std::endl; - return (std::numeric_limits<int>::max)(); - } - config.setStreamBuf( ofs.rdbuf() ); - } + bool ResultInfo::hasExpandedExpression() const { + return hasExpression() && getExpandedExpressionInternal() != m_expr; + } - int result = 0; + std::string ResultInfo::getExpandedExpression() const { + return hasExpression() ? getExpandedExpressionInternal() : ""; + } - // Scope here for the Runner so it can use the context before it is cleaned-up - { - Runner runner( config, reporter ); + std::string ResultInfo::getMessage() const { + return m_message; + } - // Run test specs specified on the command line - or default to all - if( !config.testsSpecified() ) { - runner.runAll(); - } - else { - // !TBD We should get all the testcases upfront, report any missing, - // then just run them - std::vector<std::string>::const_iterator it = config.getTestSpecs().begin(); - std::vector<std::string>::const_iterator itEnd = config.getTestSpecs().end(); - for(; it != itEnd; ++it ) { - if( runner.runMatching( *it ) == 0 ) { - std::cerr << "\n[No test cases matched with: " << *it << "]" << std::endl; - } - } - } - result = static_cast<int>( runner.getTotals().assertions.failed ); - } - Catch::Context::cleanUp(); - return result; + std::string ResultInfo::getFilename() const { + return m_lineInfo.file; } - inline void showUsage( std::ostream& os ) { - os << "\t-?, -h, --help\n" - << "\t-l, --list <tests | reporters> [xml]\n" - << "\t-t, --test <testspec> [<testspec>...]\n" - << "\t-r, --reporter <reporter name>\n" - << "\t-o, --out <file name>|<%stream name>\n" - << "\t-s, --success\n" - << "\t-b, --break\n" - << "\t-n, --name <name>\n" - << "\t-a, --abort [#]\n" - << "\t-nt, --nothrow\n\n" - << "For more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line" << std::endl; + std::size_t ResultInfo::getLine() const { + return m_lineInfo.line; } - inline void showHelp( std::string exeName ) { - std::string::size_type pos = exeName.find_last_of( "/\\" ); - if( pos != std::string::npos ) { - exeName = exeName.substr( pos+1 ); + + 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 "\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}"; + } - std::cout << exeName << " is a CATCH host application. Options are as follows:\n\n"; - showUsage( std::cout ); + bool ResultInfo::isNotExpression( const char* expr ) { + return expr && expr[0] == '!'; } - inline int Main( int argc, char* const argv[], Config& config ) { +} // end namespace Catch - try { - CommandParser parser( argc, argv ); +// #included from: catch_resultinfo_builder.hpp +#define TWOBLUECUBES_CATCH_RESULTINFO_BUILDER_HPP_INCLUDED - if( Command cmd = parser.find( "-h", "-?", "--help" ) ) { - if( cmd.argsCount() != 0 ) - cmd.raiseError( "Does not accept arguments" ); +namespace Catch { - showHelp( argv[0] ); - Catch::Context::cleanUp(); - return 0; - } + ResultInfoBuilder::ResultInfoBuilder() {} - parseIntoConfig( parser, config.data() ); - } - catch( std::exception& ex ) { - std::cerr << ex.what() << "\n\nUsage: ...\n\n"; - showUsage( std::cerr ); - Catch::Context::cleanUp(); - return (std::numeric_limits<int>::max)(); - } + ResultInfoBuilder::ResultInfoBuilder( const char* expr, + bool isNot, + const SourceLineInfo& lineInfo, + const char* macroName, + const char* message ) + : ResultInfo( expr, ResultWas::Unknown, isNot, lineInfo, macroName, message ) + {} - return Main( config ); + void ResultInfoBuilder::setResultType( ResultWas::OfType result ) { + // Flip bool results if isNot is set + if( m_isNot && result == ResultWas::Ok ) + m_result = ResultWas::ExpressionFailed; + else if( m_isNot && result == ResultWas::ExpressionFailed ) + m_result = ResultWas::Ok; + else + m_result = result; } - inline int Main( int argc, char* const argv[] ) { - Config config; -// !TBD: This doesn't always work, for some reason -// if( isDebuggerActive() ) -// config.useStream( "debug" ); - return Main( argc, argv, config ); + void ResultInfoBuilder::setMessage( const std::string& message ) { + m_message = message; + } + + void ResultInfoBuilder::setLineInfo( const SourceLineInfo& lineInfo ) { + m_lineInfo = lineInfo; + } + + void ResultInfoBuilder::setLhs( const std::string& lhs ) { + m_lhs = lhs; + } + + void ResultInfoBuilder::setRhs( const std::string& rhs ) { + m_rhs = rhs; + } + + void ResultInfoBuilder::setOp( const std::string& op ) { + m_op = op; + } + + ResultInfoBuilder& ResultInfoBuilder::captureBoolExpression( bool result ) { + m_lhs = Catch::toString( result ); + m_op = m_isNot ? "!" : ""; + setResultType( result ? ResultWas::Ok : ResultWas::ExpressionFailed ); + return *this; } } // end namespace Catch @@ -4755,6 +4950,7 @@ namespace Catch { #ifdef CATCH_CONFIG_MAIN // #included from: internal/catch_default_main.hpp +#define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED #ifndef __OBJC__