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
dev build 4
- Commit
bd46f66754f11b5644913f6eb8a1900971f3e0ad- Author
- Phil Nash ·
- Parents
e9f0773f37e8
Changes
conanfile.py | 2 +- include/internal/catch_version.cpp | 2 +- single_include/catch.hpp | 5703 ++++++++++++++++++------------------ test_package/conanfile.py | 2 +- 4 files changed, 2912 insertions(+), 2797 deletions(-) diff --git a/conanfile.py b/conanfile.py index 506235ae..d1dfa81d 100644 --- a/conanfile.py +++ b/conanfile.py @@ -4,7 +4,7 @@ from conans import ConanFile class CatchConan(ConanFile): name = "Catch" - version = "2.0.0-develop.3" + version = "2.0.0-develop.4" description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD" author = "philsquared" generators = "cmake" diff --git a/include/internal/catch_version.cpp b/include/internal/catch_version.cpp index 36f58e22..b635800b 100644 --- a/include/internal/catch_version.cpp +++ b/include/internal/catch_version.cpp @@ -37,7 +37,7 @@ namespace Catch { } Version const& libraryVersion() { - static Version version( 2, 0, 0, "develop", 3 ); + static Version version( 2, 0, 0, "develop", 4 ); return version; } diff --git a/single_include/catch.hpp b/single_include/catch.hpp index c775b8db..e5ae6198 100644 --- a/single_include/catch.hpp +++ b/single_include/catch.hpp @@ -1,6 +1,6 @@ /* - * Catch v2.0.0-develop.3 - * Generated: 2017-08-30 12:15:54.096665 + * Catch v2.0.0-develop.4 + * Generated: 2017-09-19 17:37:34.480115 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2017 Two Blue Cubes Ltd. All rights reserved. @@ -47,6 +47,9 @@ #if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) # define CATCH_IMPL # define CATCH_CONFIG_EXTERNAL_INTERFACES +# if defined(CATCH_CONFIG_DISABLE_MATCHERS) +# undef CATCH_CONFIG_DISABLE_MATCHERS +# endif #endif // start catch_platform.h @@ -106,10 +109,11 @@ #ifdef __clang__ -# define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ _Pragma( "clang diagnostic push" ) \ - _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) -# define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ + _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") +# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ _Pragma( "clang diagnostic pop" ) # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ @@ -149,7 +153,13 @@ // Visual C++ #ifdef _MSC_VER -#define CATCH_INTERNAL_CONFIG_WINDOWS_SEH +// Universal Windows platform does not support SEH +// Or console colours (or console at all...) +# if (WINAPI_FAMILY == WINAPI_FAMILY_APP) +# define CATCH_CONFIG_COLOUR_NONE +# else +# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH +# endif #endif // _MSC_VER @@ -179,9 +189,9 @@ # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS #endif -#if !defined(CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS) -# define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS -# define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS +#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS +# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS #endif // end catch_compiler_capabilities.h @@ -193,17 +203,12 @@ # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) #endif -#define INTERNAL_CATCH_STRINGIFY2( expr ) #expr -#define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr ) - #include <iosfwd> #include <string> #include <cstdint> namespace Catch { - struct IConfig; - struct CaseSensitive { enum Choice { Yes, No @@ -216,7 +221,7 @@ namespace Catch { NonCopyable& operator = ( NonCopyable && ) = delete; protected: - NonCopyable() {} + NonCopyable(); virtual ~NonCopyable(); }; @@ -245,9 +250,6 @@ namespace Catch { bool alwaysTrue(); bool alwaysFalse(); - void seedRng( IConfig const& config ); - unsigned int rngSeed(); - // Use this in variadic streaming macros to allow // >> +StreamEndStop // as well as @@ -276,7 +278,7 @@ namespace Catch { #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } // end catch_tag_alias_autoregistrar.h -// start catch_test_registry.hpp +// start catch_test_registry.h // start catch_interfaces_testcase.h @@ -330,7 +332,7 @@ namespace Catch { class StringRef { friend struct StringRefTestAccess; - using size_type = size_t; + using size_type = std::size_t; char const* m_start; size_type m_size; @@ -412,7 +414,7 @@ struct NameAndTags { struct AutoReg : NonCopyable { AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef classOrMethod, NameAndTags const& nameAndTags ) noexcept; - ~AutoReg() = default; + ~AutoReg(); }; } // end namespace Catch @@ -433,40 +435,40 @@ struct AutoReg : NonCopyable { /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \ static void TestName(); \ - CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \ - CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ static void TestName() #define INTERNAL_CATCH_TESTCASE( ... ) \ INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ ) /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \ - CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \ - CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\ - CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ namespace{ \ struct TestName : ClassName{ \ void test(); \ }; \ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ } \ - CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ void TestName::test() #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \ INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ ) /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \ - CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ - CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS -// end catch_test_registry.hpp +// end catch_test_registry.h // start catch_capture.hpp // start catch_assertionhandler.h @@ -528,6 +530,11 @@ inline id performOptionalSelector( id obj, SEL sel ) { // end catch_objc_arc.hpp #endif +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless +#endif + // We need a dummy global operator<< so we can bring it into Catch namespace later struct Catch_global_namespace_dummy; std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); @@ -801,20 +808,33 @@ namespace Catch { #ifdef __OBJC__ template<> struct StringMaker<NSString*> { - static std::string convert(NSString* nsstring); - }; - template<> - struct StringMaker<NSString* CATCH_ARC_STRONG> { - static std::string convert(NSString * CATCH_ARC_STRONG nsstring); + static std::string convert(NSString * nsstring) { + if (!nsstring) + return "nil"; + return std::string("@") + [nsstring UTF8String]; + } }; template<> - struct StringMaker<NSObject *> { - static std::string convert(NSObject* nsObject); + struct StringMaker<NSObject*> { + static std::string convert(NSObject* nsObject) { + return ::Catch::Detail::stringify([nsObject description]); + } + }; -#endif + namespace Detail { + inline std::string stringify( NSString* nsstring ) { + return StringMaker<NSString*>::convert( nsstring ); + } + + } // namespace Detail +#endif // __OBJC__ } // namespace Catch +#ifdef _MSC_VER +#pragma warning(pop) +#endif + // end catch_tostring.h #include <ostream> @@ -823,6 +843,7 @@ namespace Catch { #pragma warning(disable:4389) // '==' : signed/unsigned mismatch #pragma warning(disable:4018) // more "signed/unsigned mismatch" #pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform) +#pragma warning(disable:4180) // qualifier applied to function type has no meaning #endif namespace Catch { @@ -834,16 +855,16 @@ namespace Catch { // We don't actually need a virtual destructore, but many static analysers // complain if it's not here :-( - virtual ~ITransientExpression() = default; + virtual ~ITransientExpression(); }; - void formatReconstructedExpression( std::ostream &os, std::string const& lhs, std::string const& op, std::string const& rhs ); + void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ); template<typename LhsT, typename RhsT> class BinaryExpr : public ITransientExpression { bool m_result; LhsT m_lhs; - std::string m_op; + StringRef m_op; RhsT m_rhs; auto isBinaryExpression() const -> bool override { return true; } @@ -855,8 +876,8 @@ namespace Catch { } public: - BinaryExpr( bool comparisionResult, LhsT lhs, StringRef op, RhsT rhs ) - : m_result( comparisionResult ), + BinaryExpr( bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs ) + : m_result( comparisonResult ), m_lhs( lhs ), m_op( op ), m_rhs( rhs ) @@ -880,26 +901,26 @@ namespace Catch { // Specialised comparison functions to handle equality comparisons between ints and pointers (NULL deduces as an int) template<typename LhsT, typename RhsT> - auto compareEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return const_cast<LhsT&>( lhs ) == rhs; }; + auto compareEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return lhs == rhs; }; template<typename T> - auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }; + auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); } template<typename T> - auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }; + auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); } template<typename T> - auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }; + auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; } template<typename T> - auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }; + auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; } template<typename LhsT, typename RhsT> - auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return const_cast<LhsT&>( lhs ) != rhs; }; + auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return lhs != rhs; }; template<typename T> - auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }; + auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); } template<typename T> - auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }; + auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); } template<typename T> - auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }; + auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; } template<typename T> - auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }; + auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; } template<typename LhsT> class ExprLhs { @@ -953,10 +974,6 @@ namespace Catch { } struct Decomposer { - template<typename T> - auto operator <= ( T& lhs ) -> ExprLhs<T&> { - return ExprLhs<T&>( lhs ); - } template<typename T> auto operator <= ( T const& lhs ) -> ExprLhs<T const&> { return ExprLhs<T const&>( lhs ); @@ -968,10 +985,6 @@ namespace Catch { } // end namespace Catch -#ifdef _MSC_VER -#pragma warning(pop) -#endif - // end catch_decomposer.h // start catch_assertioninfo.h @@ -1111,9 +1124,9 @@ namespace Catch { ResultWas::OfType _type ); std::string macroName; + std::string message; SourceLineInfo lineInfo; ResultWas::OfType type; - std::string message; unsigned int sequence; bool operator == ( MessageInfo const& other ) const; @@ -1165,13 +1178,11 @@ namespace Catch { namespace Catch { - class TestCase; class AssertionResult; struct AssertionInfo; struct SectionInfo; struct SectionEndInfo; struct MessageInfo; - class ScopedMessageBuilder; struct Counts; struct BenchmarkInfo; struct BenchmarkStats; @@ -1198,7 +1209,7 @@ namespace Catch { virtual void exceptionEarlyReported() = 0; - virtual void handleFatalErrorCondition( std::string const& message ) = 0; + virtual void handleFatalErrorCondition( StringRef message ) = 0; virtual bool lastAssertionPassed() = 0; virtual void assertionPassed() = 0; @@ -1209,32 +1220,6 @@ namespace Catch { } // end catch_interfaces_capture.h -#if !defined(CATCH_CONFIG_DISABLE) - -#if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION) - #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__ -#else - #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION" -#endif - -#if defined(CATCH_CONFIG_FAST_COMPILE) -/////////////////////////////////////////////////////////////////////////////// -// We can speedup compilation significantly by breaking into debugger lower in -// the callstack, because then we don't have to expand CATCH_BREAK_INTO_DEBUGGER -// macro in each assertion -#define INTERNAL_CATCH_REACT( handler ) \ - handler.reactWithDebugBreak(); - -/////////////////////////////////////////////////////////////////////////////// -// Another way to speed-up compilation is to omit local try-catch for REQUIRE* -// macros. -// This can potentially cause false negative, if the test code catches -// the exception before it propagates back up to the runner. -#define INTERNAL_CATCH_TRY( capturer ) capturer.setExceptionGuard(); -#define INTERNAL_CATCH_CATCH( capturer ) capturer.unsetExceptionGuard(); - -#else // CATCH_CONFIG_FAST_COMPILE - // start catch_debugger.h namespace Catch { @@ -1270,6 +1255,32 @@ namespace Catch { #endif // end catch_debugger.h +#if !defined(CATCH_CONFIG_DISABLE) + +#if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION) + #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__ +#else + #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION" +#endif + +#if defined(CATCH_CONFIG_FAST_COMPILE) +/////////////////////////////////////////////////////////////////////////////// +// We can speedup compilation significantly by breaking into debugger lower in +// the callstack, because then we don't have to expand CATCH_BREAK_INTO_DEBUGGER +// macro in each assertion +#define INTERNAL_CATCH_REACT( handler ) \ + handler.reactWithDebugBreak(); + +/////////////////////////////////////////////////////////////////////////////// +// Another way to speed-up compilation is to omit local try-catch for REQUIRE* +// macros. +// This can potentially cause false negative, if the test code catches +// the exception before it propagates back up to the runner. +#define INTERNAL_CATCH_TRY( capturer ) capturer.setExceptionGuard(); +#define INTERNAL_CATCH_CATCH( capturer ) capturer.unsetExceptionGuard(); + +#else // CATCH_CONFIG_FAST_COMPILE + /////////////////////////////////////////////////////////////////////////////// // In the event of a failure works out if the debugger needs to be invoked // and/or an exception thrown and takes appropriate action. @@ -1395,7 +1406,7 @@ namespace Catch { // start catch_section_info.h -// start catch_totals.hpp +// start catch_totals.h #include <cstddef> @@ -1426,7 +1437,7 @@ namespace Catch { }; } -// end catch_totals.hpp +// end catch_totals.h #include <string> namespace Catch { @@ -1512,8 +1523,8 @@ namespace Catch { class BenchmarkLooper { std::string m_name; - size_t m_count = 0; - size_t m_iterationsToRun = 1; + std::size_t m_count = 0; + std::size_t m_iterationsToRun = 1; uint64_t m_resolution; Timer m_timer; @@ -1666,7 +1677,7 @@ namespace Catch { #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) // end catch_interfaces_exception.h -// start catch_approx.hpp +// start catch_approx.h #include <cmath> @@ -1777,31 +1788,39 @@ struct StringMaker<Catch::Detail::Approx> { } // end namespace Catch -// end catch_approx.hpp -// start catch_interfaces_tag_alias_registry.h +// end catch_approx.h +// start catch_string_manip.h #include <string> +#include <iosfwd> namespace Catch { - struct TagAlias; + bool startsWith( std::string const& s, std::string const& prefix ); + bool startsWith( std::string const& s, char prefix ); + bool endsWith( std::string const& s, std::string const& suffix ); + bool endsWith( std::string const& s, char suffix ); + bool contains( std::string const& s, std::string const& infix ); + void toLowerInPlace( std::string& s ); + std::string toLower( std::string const& s ); + std::string trim( std::string const& str ); + bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); - struct ITagAliasRegistry { - virtual ~ITagAliasRegistry(); - // Nullptr if not present - virtual TagAlias const* find( std::string const& alias ) const = 0; - virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0; + struct pluralise { + pluralise( std::size_t count, std::string const& label ); - static ITagAliasRegistry const& get(); - }; + friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); -} // end namespace Catch + std::size_t m_count; + std::string m_label; + }; +} -// end catch_interfaces_tag_alias_registry.h +// end catch_string_manip.h #ifndef CATCH_CONFIG_DISABLE_MATCHERS // start catch_capture_matchers.h -// start catch_matchers.hpp +// start catch_matchers.h #include <string> #include <vector> @@ -1822,7 +1841,7 @@ namespace Matchers { std::string toString() const; protected: - virtual ~MatcherUntypedBase() = default; + virtual ~MatcherUntypedBase(); virtual std::string describe() const = 0; mutable std::string m_cachedToString; }; @@ -1940,30 +1959,6 @@ namespace Matchers { } // namespace Impl - // The following functions create the actual matcher objects. - // This allows the types to be inferred - // - deprecated: prefer ||, && and ! - template<typename T> - Impl::MatchNotOf<T> Not( Impl::MatcherBase<T> const& underlyingMatcher ) { - return Impl::MatchNotOf<T>( underlyingMatcher ); - } - template<typename T> - Impl::MatchAllOf<T> AllOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2 ) { - return Impl::MatchAllOf<T>() && m1 && m2; - } - template<typename T> - Impl::MatchAllOf<T> AllOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2, Impl::MatcherBase<T> const& m3 ) { - return Impl::MatchAllOf<T>() && m1 && m2 && m3; - } - template<typename T> - Impl::MatchAnyOf<T> AnyOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2 ) { - return Impl::MatchAnyOf<T>() || m1 || m2; - } - template<typename T> - Impl::MatchAnyOf<T> AnyOf( Impl::MatcherBase<T> const& m1, Impl::MatcherBase<T> const& m2, Impl::MatcherBase<T> const& m3 ) { - return Impl::MatchAnyOf<T>() || m1 || m2 || m3; - } - } // namespace Matchers using namespace Matchers; @@ -1971,7 +1966,7 @@ using Matchers::Impl::MatcherBase; } // namespace Catch -// end catch_matchers.hpp +// end catch_matchers.h // start catch_matchers_string.h #include <string> @@ -2100,7 +2095,7 @@ namespace Matchers { // - then just call that directly if (m_comparator.size() != v.size()) return false; - for (size_t i = 0; i < v.size(); ++i) + for (std::size_t i = 0; i < v.size(); ++i) if (m_comparator[i] != v[i]) return false; return true; @@ -2293,7 +2288,6 @@ namespace Catch { // start catch_interfaces_runner.h namespace Catch { - class TestCase; struct IRunner { virtual ~IRunner(); @@ -2364,8 +2358,8 @@ namespace Catch { } } - inline size_t registerTestMethods() { - size_t noTestMethods = 0; + inline std::size_t registerTestMethods() { + std::size_t noTestMethods = 0; int noClasses = objc_getClassList( nullptr, 0 ); Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses); @@ -2385,7 +2379,7 @@ namespace Catch { std::string desc = Detail::getAnnotation( cls, "Description", testCaseName ); const char* className = class_getName( cls ); - getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo() ) ); + getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo("",0) ) ); noTestMethods++; } } @@ -2412,7 +2406,7 @@ namespace Catch { return false; } - NSString* m_substr; + NSString* CATCH_ARC_STRONG m_substr; }; struct Equals : StringHolder { @@ -2424,7 +2418,7 @@ namespace Catch { } std::string describe() const override { - return "equals string: " + Catch::toString( m_substr ); + return "equals string: " + Catch::Detail::stringify( m_substr ); } }; @@ -2437,7 +2431,7 @@ namespace Catch { } std::string describe() const override { - return "contains string: " + Catch::toString( m_substr ); + return "contains string: " + Catch::Detail::stringify( m_substr ); } }; @@ -2450,7 +2444,7 @@ namespace Catch { } std::string describe() const override { - return "starts with: " + Catch::toString( m_substr ); + return "starts with: " + Catch::Detail::stringify( m_substr ); } }; struct EndsWith : StringHolder { @@ -2462,7 +2456,7 @@ namespace Catch { } std::string describe() const override { - return "ends with: " + Catch::toString( m_substr ); + return "ends with: " + Catch::Detail::stringify( m_substr ); } }; @@ -2490,16 +2484,19 @@ namespace Catch { } // namespace Catch /////////////////////////////////////////////////////////////////////////////// -#define OC_TEST_CASE( name, desc )\ -+(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \ -{\ +#define OC_MAKE_UNIQUE_NAME( root, uniqueSuffix ) root##uniqueSuffix +#define OC_TEST_CASE2( name, desc, uniqueSuffix ) \ ++(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Name_test_, uniqueSuffix ) \ +{ \ return @ name; \ -}\ -+(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \ +} \ ++(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Description_test_, uniqueSuffix ) \ { \ return @ desc; \ } \ --(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test ) +-(void) OC_MAKE_UNIQUE_NAME( Catch_TestCase_test_, uniqueSuffix ) + +#define OC_TEST_CASE( name, desc ) OC_TEST_CASE2( name, desc, __LINE__ ) // end catch_objc.hpp #endif @@ -2528,21 +2525,21 @@ return @ desc; \ // start catch_config.hpp -// start catch_test_spec_parser.hpp +// start catch_test_spec_parser.h #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wpadded" #endif -// start catch_test_spec.hpp +// start catch_test_spec.h #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wpadded" #endif -// start catch_wildcard_pattern.hpp +// start catch_wildcard_pattern.h namespace Catch { @@ -2568,7 +2565,7 @@ namespace Catch }; } -// end catch_wildcard_pattern.hpp +// end catch_wildcard_pattern.h #include <string> #include <vector> #include <memory> @@ -2577,7 +2574,7 @@ namespace Catch { class TestSpec { struct Pattern { - virtual ~Pattern() = default; + virtual ~Pattern(); virtual bool matches( TestCaseInfo const& testCase ) const = 0; }; using PatternPtr = std::shared_ptr<Pattern>; @@ -2585,7 +2582,7 @@ namespace Catch { class NamePattern : public Pattern { public: NamePattern( std::string const& name ); - virtual ~NamePattern() = default; + virtual ~NamePattern(); virtual bool matches( TestCaseInfo const& testCase ) const override; private: WildcardPattern m_wildcardPattern; @@ -2594,7 +2591,7 @@ namespace Catch { class TagPattern : public Pattern { public: TagPattern( std::string const& tag ); - virtual ~TagPattern() = default; + virtual ~TagPattern(); virtual bool matches( TestCaseInfo const& testCase ) const override; private: std::string m_tag; @@ -2603,7 +2600,7 @@ namespace Catch { class ExcludedPattern : public Pattern { public: ExcludedPattern( PatternPtr const& underlyingPattern ); - virtual ~ExcludedPattern() = default; + virtual ~ExcludedPattern(); virtual bool matches( TestCaseInfo const& testCase ) const override; private: PatternPtr m_underlyingPattern; @@ -2630,35 +2627,27 @@ namespace Catch { #pragma clang diagnostic pop #endif -// end catch_test_spec.hpp -// start catch_string_manip.h +// end catch_test_spec.h +// start catch_interfaces_tag_alias_registry.h #include <string> -#include <iosfwd> namespace Catch { - bool startsWith( std::string const& s, std::string const& prefix ); - bool startsWith( std::string const& s, char prefix ); - bool endsWith( std::string const& s, std::string const& suffix ); - bool endsWith( std::string const& s, char suffix ); - bool contains( std::string const& s, std::string const& infix ); - void toLowerInPlace( std::string& s ); - std::string toLower( std::string const& s ); - std::string trim( std::string const& str ); - bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); - - struct pluralise { - pluralise( std::size_t count, std::string const& label ); + struct TagAlias; - friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); + struct ITagAliasRegistry { + virtual ~ITagAliasRegistry(); + // Nullptr if not present + virtual TagAlias const* find( std::string const& alias ) const = 0; + virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0; - std::size_t m_count; - std::string m_label; + static ITagAliasRegistry const& get(); }; -} -// end catch_string_manip.h +} // end namespace Catch + +// end catch_interfaces_tag_alias_registry.h namespace Catch { class TestSpecParser { @@ -2687,7 +2676,7 @@ namespace Catch { template<typename T> void addPattern() { std::string token = subString(); - for( size_t i = 0; i < m_escapeChars.size(); ++i ) + for( std::size_t i = 0; i < m_escapeChars.size(); ++i ) token = token.substr( 0, m_escapeChars[i]-m_start-i ) + token.substr( m_escapeChars[i]-m_start-i+1 ); m_escapeChars.clear(); if( startsWith( token, "exclude:" ) ) { @@ -2714,7 +2703,7 @@ namespace Catch { #pragma clang diagnostic pop #endif -// end catch_test_spec_parser.hpp +// end catch_test_spec_parser.h // start catch_interfaces_config.h #include <iosfwd> @@ -2785,6 +2774,71 @@ namespace Catch { } // end catch_interfaces_config.h +// Libstdc++ doesn't like incomplete classes for unique_ptr +// start catch_stream.h + +// start catch_streambuf.h + +#include <streambuf> + +namespace Catch { + + class StreamBufBase : public std::streambuf { + public: + virtual ~StreamBufBase(); + }; +} + +// end catch_streambuf.h +#include <streambuf> +#include <ostream> +#include <fstream> +#include <memory> + +namespace Catch { + + std::ostream& cout(); + std::ostream& cerr(); + std::ostream& clog(); + + struct IStream { + virtual ~IStream(); + virtual std::ostream& stream() const = 0; + }; + + class FileStream : public IStream { + mutable std::ofstream m_ofs; + public: + FileStream( std::string const& filename ); + ~FileStream() override = default; + public: // IStream + std::ostream& stream() const override; + }; + + class CoutStream : public IStream { + mutable std::ostream m_os; + public: + CoutStream(); + ~CoutStream() override = default; + + public: // IStream + std::ostream& stream() const override; + }; + + class DebugOutStream : public IStream { + std::unique_ptr<StreamBufBase> m_streamBuf; + mutable std::ostream m_os; + public: + DebugOutStream(); + ~DebugOutStream() override = default; + + public: // IStream + std::ostream& stream() const override; + }; +} + +// end catch_stream.h + #include <memory> #include <vector> #include <string> @@ -2832,7 +2886,6 @@ namespace Catch { }; class Config : public IConfig { - virtual void dummy(); public: Config() = default; @@ -2895,13 +2948,12 @@ namespace Catch { AssertionResultData( ResultWas::OfType _resultType, LazyExpression const& _lazyExpression ); - ResultWas::OfType resultType = ResultWas::Unknown; std::string message; - + mutable std::string reconstructedExpression; LazyExpression lazyExpression; + ResultWas::OfType resultType; std::string reconstructExpression() const; - mutable std::string reconstructedExpression; }; class AssertionResult { @@ -3057,7 +3109,7 @@ namespace Catch { AssertionStats( AssertionStats && ) = default; AssertionStats& operator = ( AssertionStats const& ) = default; AssertionStats& operator = ( AssertionStats && ) = default; - virtual ~AssertionStats() = default; + virtual ~AssertionStats(); AssertionResult assertionResult; std::vector<MessageInfo> infoMessages; @@ -3073,7 +3125,7 @@ namespace Catch { SectionStats( SectionStats && ) = default; SectionStats& operator = ( SectionStats const& ) = default; SectionStats& operator = ( SectionStats && ) = default; - virtual ~SectionStats() = default; + virtual ~SectionStats(); SectionInfo sectionInfo; Counts assertions; @@ -3092,7 +3144,7 @@ namespace Catch { TestCaseStats( TestCaseStats && ) = default; TestCaseStats& operator = ( TestCaseStats const& ) = default; TestCaseStats& operator = ( TestCaseStats && ) = default; - virtual ~TestCaseStats() = default; + virtual ~TestCaseStats(); TestCaseInfo testInfo; Totals totals; @@ -3111,7 +3163,7 @@ namespace Catch { TestGroupStats( TestGroupStats && ) = default; TestGroupStats& operator = ( TestGroupStats const& ) = default; TestGroupStats& operator = ( TestGroupStats && ) = default; - virtual ~TestGroupStats() = default; + virtual ~TestGroupStats(); GroupInfo groupInfo; Totals totals; @@ -3127,7 +3179,7 @@ namespace Catch { TestRunStats( TestRunStats && ) = default; TestRunStats& operator = ( TestRunStats const& ) = default; TestRunStats& operator = ( TestRunStats && ) = default; - virtual ~TestRunStats() = default; + virtual ~TestRunStats(); TestRunInfo runInfo; Totals totals; @@ -3139,10 +3191,9 @@ namespace Catch { }; struct BenchmarkStats { BenchmarkInfo info; - size_t iterations; + std::size_t iterations; uint64_t elapsedTimeInNanoseconds; }; - class MultipleReporters; struct IStreamingReporter { virtual ~IStreamingReporter() = default; @@ -3179,12 +3230,15 @@ namespace Catch { virtual void skipTest( TestCaseInfo const& testInfo ) = 0; + // Default empty implementation provided + virtual void fatalErrorEncountered( StringRef name ); + virtual bool isMulti() const; }; using IStreamingReporterPtr = std::unique_ptr<IStreamingReporter>; struct IReporterFactory { - virtual ~IReporterFactory() = default; + virtual ~IReporterFactory(); virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0; virtual std::string getDescription() const = 0; }; @@ -3194,7 +3248,7 @@ namespace Catch { using FactoryMap = std::map<std::string, IReporterFactoryPtr>; using Listeners = std::vector<IReporterFactoryPtr>; - virtual ~IReporterRegistry() = default; + virtual ~IReporterRegistry(); virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0; virtual FactoryMap const& getFactories() const = 0; virtual Listeners const& getListeners() const = 0; @@ -3462,26 +3516,84 @@ namespace Catch { } // end namespace Catch // end catch_reporter_bases.hpp -// start catch_reporter_registrars.hpp - +// start catch_console_colour.h namespace Catch { - template<typename T> - class ReporterRegistrar { + struct Colour { + enum Code { + None = 0, - class ReporterFactory : public IReporterFactory { + White, + Red, + Green, + Blue, + Cyan, + Yellow, + Grey, - virtual IStreamingReporterPtr create( ReporterConfig const& config ) const override { - return std::unique_ptr<T>( new T( config ) ); - } + Bright = 0x10, - virtual std::string getDescription() const override { - return T::getDescription(); - } - }; + BrightRed = Bright | Red, + BrightGreen = Bright | Green, + LightGrey = Bright | Grey, + BrightWhite = Bright | White, - public: + // By intention + FileName = LightGrey, + Warning = Yellow, + ResultError = BrightRed, + ResultSuccess = BrightGreen, + ResultExpectedFailure = Warning, + + Error = BrightRed, + Success = Green, + + OriginalExpression = Cyan, + ReconstructedExpression = Yellow, + + SecondaryText = LightGrey, + Headers = White + }; + + // Use constructed object for RAII guard + Colour( Code _colourCode ); + Colour( Colour&& other ) noexcept; + Colour& operator=( Colour&& other ) noexcept; + ~Colour(); + + // Use static method for one-shot changes + static void use( Code _colourCode ); + + private: + bool m_moved = false; + }; + + std::ostream& operator << ( std::ostream& os, Colour const& ); + +} // end namespace Catch + +// end catch_console_colour.h +// start catch_reporter_registrars.hpp + + +namespace Catch { + + template<typename T> + class ReporterRegistrar { + + class ReporterFactory : public IReporterFactory { + + virtual IStreamingReporterPtr create( ReporterConfig const& config ) const override { + return std::unique_ptr<T>( new T( config ) ); + } + + virtual std::string getDescription() const override { + return T::getDescription(); + } + }; + + public: ReporterRegistrar( std::string const& name ) { getMutableRegistryHub().registerReporter( name, std::make_shared<ReporterFactory>() ); @@ -3512,11 +3624,14 @@ namespace Catch { #if !defined(CATCH_CONFIG_DISABLE) #define CATCH_REGISTER_REPORTER( name, reporterType ) \ - namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } \ + CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS #define CATCH_REGISTER_LISTENER( listenerType ) \ - namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } - + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS #else // CATCH_CONFIG_DISABLE #define CATCH_REGISTER_REPORTER(name, reporterType) @@ -3531,2488 +3646,1788 @@ namespace Catch { #ifdef CATCH_IMPL // start catch_impl.hpp -// Collect all the implementation files together here -// These are the equivalent of what would usually be cpp files - #ifdef __clang__ #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wweak-vtables" #endif -// start catch_notimplemented_exception.h +// Keep these here for external reporters +// start catch_test_case_tracker.h -#include <exception> +#include <string> +#include <vector> +#include <memory> namespace Catch { +namespace TestCaseTracking { - class NotImplementedException : public std::exception - { - public: - NotImplementedException( SourceLineInfo const& lineInfo ); + struct NameAndLocation { + std::string name; + SourceLineInfo location; - virtual ~NotImplementedException() noexcept = default; + NameAndLocation( std::string const& _name, SourceLineInfo const& _location ); + }; - virtual const char* what() const noexcept override; + struct ITracker; - private: - std::string m_what; - }; + using ITrackerPtr = std::shared_ptr<ITracker>; -} // end namespace Catch + struct ITracker { + virtual ~ITracker(); -/////////////////////////////////////////////////////////////////////////////// -#define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO ) + // static queries + virtual NameAndLocation const& nameAndLocation() const = 0; -// end catch_notimplemented_exception.h -// Temporary hack to fix separately provided reporters -// + // dynamic queries + virtual bool isComplete() const = 0; // Successfully completed or failed + virtual bool isSuccessfullyCompleted() const = 0; + virtual bool isOpen() const = 0; // Started but not complete + virtual bool hasChildren() const = 0; -// start catch_leak_detector.h + virtual ITracker& parent() = 0; -namespace Catch { + // actions + virtual void close() = 0; // Successfully complete + virtual void fail() = 0; + virtual void markAsNeedingAnotherRun() = 0; - struct LeakDetector { - LeakDetector(); + virtual void addChild( ITrackerPtr const& child ) = 0; + virtual ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) = 0; + virtual void openChild() = 0; + + // Debug/ checking + virtual bool isSectionTracker() const = 0; + virtual bool isIndexTracker() const = 0; }; -} -// end catch_leak_detector.h -// start catch_session.hpp + class TrackerContext { -// start catch_commandline.hpp + enum RunState { + NotStarted, + Executing, + CompletedCycle + }; -// start catch_clara.h + ITrackerPtr m_rootTracker; + ITracker* m_currentTracker = nullptr; + RunState m_runState = NotStarted; -// Use Catch's value for console width (store Clara's off to the side, if present) -#ifdef CLARA_CONFIG_CONSOLE_WIDTH -#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH -#undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH -#endif -#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH-1 + public: -// start clara.hpp -// v1.0 -// See https://github.com/philsquared/Clara + static TrackerContext& instance(); + ITracker& startRun(); + void endRun(); -#ifndef CATCH_CLARA_CONFIG_CONSOLE_WIDTH -#define CATCH_CLARA_CONFIG_CONSOLE_WIDTH 80 -#endif + void startCycle(); + void completeCycle(); -// ----------- #included from clara_textflow.hpp ----------- + bool completedCycle() const; + ITracker& currentTracker(); + void setCurrentTracker( ITracker* tracker ); + }; -// TextFlowCpp -// -// A single-header library for wrapping and laying out basic text, by Phil Nash -// -// This work is licensed under the BSD 2-Clause license. -// See the accompanying LICENSE file, or the one at https://opensource.org/licenses/BSD-2-Clause -// -// This project is hosted at https://github.com/philsquared/textflowcpp + class TrackerBase : public ITracker { + protected: + enum CycleState { + NotStarted, + Executing, + ExecutingChildren, + NeedsAnotherRun, + CompletedSuccessfully, + Failed + }; + class TrackerHasName { + NameAndLocation m_nameAndLocation; + public: + TrackerHasName( NameAndLocation const& nameAndLocation ); + bool operator ()( ITrackerPtr const& tracker ) const; + }; -#include <cassert> -#include <ostream> -#include <sstream> -#include <vector> + using Children = std::vector<ITrackerPtr>; + NameAndLocation m_nameAndLocation; + TrackerContext& m_ctx; + ITracker* m_parent; + Children m_children; + CycleState m_runState = NotStarted; -#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH -#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH 80 -#endif + public: + TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); -namespace Catch { namespace clara { namespace TextFlow { + NameAndLocation const& nameAndLocation() const override; + bool isComplete() const override; + bool isSuccessfullyCompleted() const override; + bool isOpen() const override; + bool hasChildren() const override; - inline auto isWhitespace( char c ) -> bool { - static std::string chars = " \t\n\r"; - return chars.find( c ) != std::string::npos; - } - inline auto isBreakableBefore( char c ) -> bool { - static std::string chars = "[({<|"; - return chars.find( c ) != std::string::npos; - } - inline auto isBreakableAfter( char c ) -> bool { - static std::string chars = "])}>.,:;*+-=&/\\"; - return chars.find( c ) != std::string::npos; - } + void addChild( ITrackerPtr const& child ) override; - class Columns; + ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) override; + ITracker& parent() override; - class Column { - std::vector<std::string> m_strings; - size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH; - size_t m_indent = 0; - size_t m_initialIndent = std::string::npos; + void openChild() override; - public: - class iterator { - friend Column; + bool isSectionTracker() const override; + bool isIndexTracker() const override; - Column const& m_column; - size_t m_stringIndex = 0; - size_t m_pos = 0; + void open(); - size_t m_len = 0; - size_t m_end = 0; - bool m_suffix = false; + void close() override; + void fail() override; + void markAsNeedingAnotherRun() override; - iterator( Column const& column, size_t stringIndex ) - : m_column( column ), - m_stringIndex( stringIndex ) - {} + private: + void moveToParent(); + void moveToThis(); + }; - auto line() const -> std::string const& { return m_column.m_strings[m_stringIndex]; } + class SectionTracker : public TrackerBase { + std::vector<std::string> m_filters; + public: + SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); - auto isBoundary( size_t at ) const -> bool { - assert( at > 0 ); - assert( at <= line().size() ); + bool isSectionTracker() const override; - return at == line().size() || - ( isWhitespace( line()[at] ) && !isWhitespace( line()[at-1] ) ) || - isBreakableBefore( line()[at] ) || - isBreakableAfter( line()[at-1] ); - } + static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ); - void calcLength() { - assert( m_stringIndex < m_column.m_strings.size() ); + void tryOpen(); - m_suffix = false; - auto width = m_column.m_width-indent(); - m_end = m_pos; - while( m_end < line().size() && line()[m_end] != '\n' ) - ++m_end; - - if( m_end < m_pos + width ) { - m_len = m_end - m_pos; - } - else { - size_t len = width; - while (len > 0 && !isBoundary(m_pos + len)) - --len; - while (len > 0 && isWhitespace( line()[m_pos + len - 1] )) - --len; - - if (len > 0) { - m_len = len; - } else { - m_suffix = true; - m_len = width - 1; - } - } - } - - auto indent() const -> size_t { - auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos; - return initial == std::string::npos ? m_column.m_indent : initial; - } - - auto addIndentAndSuffix(std::string const &plain) const -> std::string { - return std::string( indent(), ' ' ) + (m_suffix ? plain + "-" : plain); - } - - public: - explicit iterator( Column const& column ) : m_column( column ) { - assert( m_column.m_width > m_column.m_indent ); - assert( m_column.m_initialIndent == std::string::npos || m_column.m_width > m_column.m_initialIndent ); - calcLength(); - if( m_len == 0 ) - m_stringIndex++; // Empty string - } - - auto operator *() const -> std::string { - assert( m_stringIndex < m_column.m_strings.size() ); - assert( m_pos < m_end ); - if( m_pos + m_column.m_width < m_end ) - return addIndentAndSuffix(line().substr(m_pos, m_len)); - else - return addIndentAndSuffix(line().substr(m_pos, m_end - m_pos)); - } - - auto operator ++() -> iterator& { - m_pos += m_len; - if( m_pos < line().size() && line()[m_pos] == '\n' ) - m_pos += 1; - else - while( m_pos < line().size() && isWhitespace( line()[m_pos] ) ) - ++m_pos; - - if( m_pos == line().size() ) { - m_pos = 0; - ++m_stringIndex; - } - if( m_stringIndex < m_column.m_strings.size() ) - calcLength(); - return *this; - } - auto operator ++(int) -> iterator { - iterator prev( *this ); - operator++(); - return prev; - } - - auto operator ==( iterator const& other ) const -> bool { - return - m_pos == other.m_pos && - m_stringIndex == other.m_stringIndex && - &m_column == &other.m_column; - } - auto operator !=( iterator const& other ) const -> bool { - return !operator==( other ); - } - }; - using const_iterator = iterator; - - explicit Column( std::string const& text ) { m_strings.push_back( text ); } - - auto width( size_t newWidth ) -> Column& { - assert( newWidth > 0 ); - m_width = newWidth; - return *this; - } - auto indent( size_t newIndent ) -> Column& { - m_indent = newIndent; - return *this; - } - auto initialIndent( size_t newIndent ) -> Column& { - m_initialIndent = newIndent; - return *this; - } - - auto width() const -> size_t { return m_width; } - auto begin() const -> iterator { return iterator( *this ); } - auto end() const -> iterator { return { *this, m_strings.size() }; } - - inline friend std::ostream& operator << ( std::ostream& os, Column const& col ) { - bool first = true; - for( auto line : col ) { - if( first ) - first = false; - else - os << "\n"; - os << line; - } - return os; - } - - auto operator + ( Column const& other ) -> Columns; - - auto toString() const -> std::string { - std::ostringstream oss; - oss << *this; - return oss.str(); - } - }; - - class Spacer : public Column { - - public: - explicit Spacer( size_t spaceWidth ) : Column( "" ) { - width( spaceWidth ); - } - }; - - class Columns { - std::vector<Column> m_columns; - - public: - - class iterator { - friend Columns; - struct EndTag {}; - - std::vector<Column> const& m_columns; - std::vector<Column::iterator> m_iterators; - size_t m_activeIterators; - - iterator( Columns const& columns, EndTag ) - : m_columns( columns.m_columns ), - m_activeIterators( 0 ) - { - m_iterators.reserve( m_columns.size() ); - - for( auto const& col : m_columns ) - m_iterators.push_back( col.end() ); - } - - public: - explicit iterator( Columns const& columns ) - : m_columns( columns.m_columns ), - m_activeIterators( m_columns.size() ) - { - m_iterators.reserve( m_columns.size() ); - - for( auto const& col : m_columns ) - m_iterators.push_back( col.begin() ); - } - - auto operator ==( iterator const& other ) const -> bool { - return m_iterators == other.m_iterators; - } - auto operator !=( iterator const& other ) const -> bool { - return m_iterators != other.m_iterators; - } - auto operator *() const -> std::string { - std::string row, padding; - - for( size_t i = 0; i < m_columns.size(); ++i ) { - auto width = m_columns[i].width(); - if( m_iterators[i] != m_columns[i].end() ) { - std::string col = *m_iterators[i]; - row += padding + col; - if( col.size() < width ) - padding = std::string( width - col.size(), ' ' ); - else - padding = ""; - } - else { - padding += std::string( width, ' ' ); - } - } - return row; - } - auto operator ++() -> iterator& { - for( size_t i = 0; i < m_columns.size(); ++i ) { - if (m_iterators[i] != m_columns[i].end()) - ++m_iterators[i]; - } - return *this; - } - auto operator ++(int) -> iterator { - iterator prev( *this ); - operator++(); - return prev; - } - }; - using const_iterator = iterator; - - auto begin() const -> iterator { return iterator( *this ); } - auto end() const -> iterator { return { *this, iterator::EndTag() }; } - - auto operator += ( Column const& col ) -> Columns& { - m_columns.push_back( col ); - return *this; - } - auto operator + ( Column const& col ) -> Columns { - Columns combined = *this; - combined += col; - return combined; - } - - inline friend std::ostream& operator << ( std::ostream& os, Columns const& cols ) { - - bool first = true; - for( auto line : cols ) { - if( first ) - first = false; - else - os << "\n"; - os << line; - } - return os; - } - - auto toString() const -> std::string { - std::ostringstream oss; - oss << *this; - return oss.str(); - } - }; - - inline auto Column::operator + ( Column const& other ) -> Columns { - Columns cols; - cols += *this; - cols += other; - return cols; - } -}}} // namespace Catch::clara::TextFlow - -// ----------- end of #include from clara_textflow.hpp ----------- -// ........... back in clara.hpp - -#include <memory> -#include <set> -#include <algorithm> - -#if !defined(CLARA_PLATFORM_WINDOWS) && ( defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) ) -#define CLARA_PLATFORM_WINDOWS - -#endif - -namespace Catch { namespace clara { -namespace detail { - - // Traits for extracting arg and return type of lambdas (for single argument lambdas) - template<typename L> - struct UnaryLambdaTraits : UnaryLambdaTraits<decltype(&L::operator())> {}; - - template<typename ClassT, typename ReturnT, typename... Args> - struct UnaryLambdaTraits<ReturnT(ClassT::*)(Args...) const> { - static const bool isValid = false; - }; - - template<typename ClassT, typename ReturnT, typename ArgT> - struct UnaryLambdaTraits<ReturnT(ClassT::*)(ArgT) const> { - static const bool isValid = true; - using ArgType = typename std::remove_const<typename std::remove_reference<ArgT>::type>::type;; - using ReturnType = ReturnT; - }; - - class TokenStream; - - // Transport for raw args (copied from main args, or supplied via init list for testing) - class Args { - friend TokenStream; - std::string m_exeName; - std::vector<std::string> m_args; - - public: - Args(int argc, char *argv[]) { - m_exeName = argv[0]; - for (int i = 1; i < argc; ++i) - m_args.push_back(argv[i]); - } - - Args(std::initializer_list<std::string> args) - : m_exeName( *args.begin() ), - m_args( args.begin()+1, args.end() ) - {} - - auto exeName() const -> std::string { - return m_exeName; - } - }; - - // Wraps a token coming from a token stream. These may not directly correspond to strings as a single string - // may encode an option + its argument if the : or = form is used - enum class TokenType { - Option, Argument - }; - struct Token { - TokenType type; - std::string token; - }; - - // Abstracts iterators into args as a stream of tokens, with option arguments uniformly handled - class TokenStream { - using Iterator = std::vector<std::string>::const_iterator; - Iterator it; - Iterator itEnd; - std::vector<Token> m_tokenBuffer; - - void loadBuffer() { - m_tokenBuffer.resize(0); - - // Skip any empty strings - while (it != itEnd && it->empty()) - ++it; - - if (it != itEnd) { - auto const &next = *it; - if (next[0] == '-' || next[0] == '/') { - auto delimiterPos = next.find_first_of(" :="); - if (delimiterPos != std::string::npos) { - m_tokenBuffer.push_back({TokenType::Option, next.substr(0, delimiterPos)}); - m_tokenBuffer.push_back({TokenType::Argument, next.substr(delimiterPos + 1)}); - } else { - if (next[1] != '-' && next.size() > 2) { - std::string opt = "- "; - for (size_t i = 1; i < next.size(); ++i) { - opt[1] = next[i]; - m_tokenBuffer.push_back({TokenType::Option, opt}); - } - } else { - m_tokenBuffer.push_back({TokenType::Option, next}); - } - } - } else { - m_tokenBuffer.push_back({TokenType::Argument, next}); - } - } - } - - public: - explicit TokenStream(Args const &args) : TokenStream(args.m_args.begin(), args.m_args.end()) {} - - TokenStream(Iterator it, Iterator itEnd) : it(it), itEnd(itEnd) { - loadBuffer(); - } - - explicit operator bool() const { - return !m_tokenBuffer.empty() || it != itEnd; - } - - auto count() const -> size_t { return m_tokenBuffer.size() + (itEnd - it); } - - auto operator*() const -> Token { - assert(!m_tokenBuffer.empty()); - return m_tokenBuffer.front(); - } - - auto operator->() const -> Token const * { - assert(!m_tokenBuffer.empty()); - return &m_tokenBuffer.front(); - } - - auto operator++() -> TokenStream & { - if (m_tokenBuffer.size() >= 2) { - m_tokenBuffer.erase(m_tokenBuffer.begin()); - } else { - if (it != itEnd) - ++it; - loadBuffer(); - } - return *this; - } - }; - - class ResultBase { - public: - enum Type { - Ok, LogicError, RuntimeError - }; - - protected: - ResultBase(Type type) : m_type(type) {} - virtual ~ResultBase() = default; - - virtual void enforceOk() const = 0; - - Type m_type; - }; - - template<typename T> - class ResultValueBase : public ResultBase { - public: - auto value() const -> T const & { - enforceOk(); - return m_value; - } - - protected: - ResultValueBase(Type type) : ResultBase(type) {} - - ResultValueBase(ResultValueBase const &other) : ResultBase(other) { - if (m_type == ResultBase::Ok) - new(&m_value) T(other.m_value); - } - - ResultValueBase(Type, T const &value) : ResultBase(Ok) { - new(&m_value) T(value); - } - - auto operator=(ResultValueBase const &other) -> ResultValueBase & { - if (m_type == ResultBase::Ok) - m_value.~T(); - ResultBase::operator=(other); - if (m_type == ResultBase::Ok) - new(&m_value) T(other.m_value); - return *this; - } - - ~ResultValueBase() { - if (m_type == Ok) - m_value.~T(); - } - - union { - T m_value; - }; - }; - - template<> - class ResultValueBase<void> : public ResultBase { - protected: - using ResultBase::ResultBase; - }; - - template<typename T = void> - class BasicResult : public ResultValueBase<T> { - public: - template<typename U> - explicit BasicResult(BasicResult<U> const &other) - : ResultValueBase<T>(other.type()), - m_errorMessage(other.errorMessage()) { - assert(type() != ResultBase::Ok); - } - - static auto ok() -> BasicResult { return {ResultBase::Ok}; } - - template<typename U> - static auto ok(U const &value) -> BasicResult { return {ResultBase::Ok, value}; } - - static auto logicError(std::string const &message) -> BasicResult { return {ResultBase::LogicError, message}; } - - static auto runtimeError(std::string const &message) -> BasicResult { - return {ResultBase::RuntimeError, message}; - } - - explicit operator bool() const { return m_type == ResultBase::Ok; } - - auto type() const -> ResultBase::Type { return m_type; } - - auto errorMessage() const -> std::string { return m_errorMessage; } - - protected: - virtual void enforceOk() const { - // !TBD: If no exceptions, std::terminate here or something - switch (m_type) { - case ResultBase::LogicError: - throw std::logic_error(m_errorMessage); - case ResultBase::RuntimeError: - throw std::runtime_error(m_errorMessage); - case ResultBase::Ok: - break; - } - } - - std::string m_errorMessage; // Only populated if resultType is an error - - BasicResult(ResultBase::Type type, std::string const &message) - : ResultValueBase<T>(type), - m_errorMessage(message) { - assert(m_type != ResultBase::Ok); - } - - using ResultValueBase<T>::ResultValueBase; - using ResultBase::m_type; - }; - - enum class ParseResultType { - Matched, NoMatch, ShortCircuitAll, ShortCircuitSame - }; - - class ParseState { - public: - - ParseState(ParseResultType type, TokenStream const &remainingTokens) - : m_type(type), - m_remainingTokens(remainingTokens) {} - - auto type() const -> ParseResultType { return m_type; } - - auto remainingTokens() const -> TokenStream { return m_remainingTokens; } - - private: - ParseResultType m_type; - TokenStream m_remainingTokens; - }; - - using Result = BasicResult<void>; - using ParserResult = BasicResult<ParseResultType>; - using InternalParseResult = BasicResult<ParseState>; - - struct HelpColumns { - std::string left; - std::string right; - }; - - template<typename T> - inline auto convertInto(std::string const &source, T& target) -> ParserResult { - std::stringstream ss; - ss << source; - ss >> target; - if (ss.fail()) - return ParserResult::runtimeError("Unable to convert '" + source + "' to destination type"); - else - return ParserResult::ok(ParseResultType::Matched); - } - inline auto convertInto(std::string const &source, std::string& target) -> ParserResult { - target = source; - return ParserResult::ok(ParseResultType::Matched); - } - inline auto convertInto(std::string const &source, bool &target) -> ParserResult { - std::string srcLC = source; - std::transform(srcLC.begin(), srcLC.end(), srcLC.begin(), [](char c) { return static_cast<char>( ::tolower(c) ); } ); - if (srcLC == "y" || srcLC == "1" || srcLC == "true" || srcLC == "yes" || srcLC == "on") - target = true; - else if (srcLC == "n" || srcLC == "0" || srcLC == "false" || srcLC == "no" || srcLC == "off") - target = false; - else - return ParserResult::runtimeError("Expected a boolean value but did not recognise: '" + source + "'"); - return ParserResult::ok(ParseResultType::Matched); - } - - struct BoundRefBase { - BoundRefBase() = default; - - BoundRefBase(BoundRefBase const &) = delete; - - BoundRefBase(BoundRefBase &&) = delete; - - BoundRefBase &operator=(BoundRefBase const &) = delete; - - BoundRefBase &operator=(BoundRefBase &&) = delete; - - virtual ~BoundRefBase() = default; - - virtual auto isFlag() const -> bool = 0; - - virtual auto isContainer() const -> bool { return false; } - - virtual auto setValue(std::string const &arg) -> ParserResult = 0; - - virtual auto setFlag(bool flag) -> ParserResult = 0; - }; - - struct BoundValueRefBase : BoundRefBase { - auto isFlag() const -> bool override { return false; } - - auto setFlag(bool) -> ParserResult override { - return ParserResult::logicError("Flags can only be set on boolean fields"); - } - }; - - struct BoundFlagRefBase : BoundRefBase { - auto isFlag() const -> bool override { return true; } - - auto setValue(std::string const &arg) -> ParserResult override { - bool flag; - auto result = convertInto(arg, flag); - if (result) - setFlag(flag); - return result; - } - }; - - template<typename T> - struct BoundRef : BoundValueRefBase { - T &m_ref; - - explicit BoundRef(T &ref) : m_ref(ref) {} - - auto setValue(std::string const &arg) -> ParserResult override { - return convertInto(arg, m_ref); - } - }; - - template<typename T> - struct BoundRef<std::vector<T>> : BoundValueRefBase { - std::vector<T> &m_ref; - - explicit BoundRef(std::vector<T> &ref) : m_ref(ref) {} - - auto isContainer() const -> bool override { return true; } - - auto setValue(std::string const &arg) -> ParserResult override { - T temp; - auto result = convertInto(arg, temp); - if (result) - m_ref.push_back(temp); - return result; - } - }; - - struct BoundFlagRef : BoundFlagRefBase { - bool &m_ref; - - explicit BoundFlagRef(bool &ref) : m_ref(ref) {} - - auto setFlag(bool flag) -> ParserResult override { - m_ref = flag; - return ParserResult::ok(ParseResultType::Matched); - } - }; - - template<typename ReturnType> - struct LambdaInvoker { - static_assert(std::is_same<ReturnType, ParserResult>::value, "Lambda must return void or clara::ParserResult"); - - template<typename L, typename ArgType> - static auto invoke(L const &lambda, ArgType const &arg) -> ParserResult { - return lambda(arg); - } - }; - - template<> - struct LambdaInvoker<void> { - template<typename L, typename ArgType> - static auto invoke(L const &lambda, ArgType const &arg) -> ParserResult { - lambda(arg); - return ParserResult::ok(ParseResultType::Matched); - } - }; - - template<typename ArgType, typename L> - inline auto invokeLambda(L const &lambda, std::string const &arg) -> ParserResult { - ArgType temp; - auto result = convertInto(arg, temp); - return !result - ? result - : LambdaInvoker<typename UnaryLambdaTraits<L>::ReturnType>::invoke(lambda, temp); - }; - - template<typename L> - struct BoundLambda : BoundValueRefBase { - L m_lambda; - - static_assert( UnaryLambdaTraits<L>::isValid, "Supplied lambda must take exactly one argument" ); - explicit BoundLambda(L const &lambda) : m_lambda(lambda) {} - - auto setValue(std::string const &arg) -> ParserResult override { - return invokeLambda<typename UnaryLambdaTraits<L>::ArgType>(m_lambda, arg); - } - }; - - template<typename L> - struct BoundFlagLambda : BoundFlagRefBase { - L m_lambda; - - static_assert( UnaryLambdaTraits<L>::isValid, "Supplied lambda must take exactly one argument" ); - static_assert( std::is_same<typename UnaryLambdaTraits<L>::ArgType, bool>::value, "flags must be boolean" ); - - explicit BoundFlagLambda(L const &lambda) : m_lambda(lambda) {} - - auto setFlag(bool flag) -> ParserResult override { - return LambdaInvoker<typename UnaryLambdaTraits<L>::ReturnType>::invoke(m_lambda, flag); - } - }; - - enum class Optionality { - Optional, Required - }; - - struct Parser; - - class ParserBase { - public: - virtual ~ParserBase() = default; - virtual auto validate() const -> Result { return Result::ok(); } - virtual auto parse( std::string const& exeName, TokenStream const &tokens) const -> InternalParseResult = 0; - virtual auto cardinality() const -> size_t { return 1; } - - auto parse(Args const &args) const -> InternalParseResult { - return parse( args.exeName(), TokenStream(args)); - } - }; - - template<typename DerivedT> - class ComposableParserImpl : public ParserBase { - public: - template<typename T> - auto operator+(T const &other) const -> Parser; - }; - - // Common code and state for Args and Opts - template<typename DerivedT> - class ParserRefImpl : public ComposableParserImpl<DerivedT> { - protected: - Optionality m_optionality = Optionality::Optional; - std::shared_ptr<BoundRefBase> m_ref; - std::string m_hint; - std::string m_description; - - explicit ParserRefImpl(std::shared_ptr<BoundRefBase> const &ref) : m_ref(ref) {} - - public: - template<typename T> - ParserRefImpl(T &ref, std::string const &hint) : m_ref(std::make_shared<BoundRef<T>>(ref)), m_hint(hint) {} - - template<typename LambdaT> - ParserRefImpl(LambdaT const &ref, std::string const &hint) : m_ref(std::make_shared<BoundLambda<LambdaT>>(ref)), - m_hint(hint) {} - - auto operator()(std::string const &description) -> DerivedT & { - m_description = description; - return static_cast<DerivedT &>( *this ); - } - - auto optional() -> DerivedT & { - m_optionality = Optionality::Optional; - return static_cast<DerivedT &>( *this ); - }; - - auto required() -> DerivedT & { - m_optionality = Optionality::Required; - return static_cast<DerivedT &>( *this ); - }; - - auto isOptional() const -> bool { - return m_optionality == Optionality::Optional; - } - - auto cardinality() const -> size_t override { - if (m_ref->isContainer()) - return 0; - else - return 1; - } - - auto hint() const -> std::string { return m_hint; } - }; - - class ExeName : public ComposableParserImpl<ExeName> { - std::shared_ptr<std::string> m_name; - std::shared_ptr<BoundRefBase> m_ref; - - template<typename LambdaT> - static auto makeRef(LambdaT const &lambda) -> std::shared_ptr<BoundRefBase> { - return std::make_shared<BoundLambda<LambdaT>>(lambda); - } - - public: - ExeName() : m_name(std::make_shared<std::string>("<executable>")) {} - - explicit ExeName(std::string &ref) : ExeName() { - m_ref = std::make_shared<BoundRef<std::string>>( ref ); - } - - template<typename LambdaT> - explicit ExeName( LambdaT const& lambda ) : ExeName() { - m_ref = std::make_shared<BoundLambda<LambdaT>>( lambda ); - } - - // The exe name is not parsed out of the normal tokens, but is handled specially - auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { - return InternalParseResult::ok(ParseState(ParseResultType::NoMatch, tokens)); - } - - auto name() const -> std::string { return *m_name; } - auto set( std::string const& newName ) -> ParserResult { - - auto lastSlash = newName.find_last_of( "\\/" ); - auto filename = (lastSlash == std::string::npos) - ? newName - : newName.substr( lastSlash+1 ); - - *m_name = filename; - if( m_ref ) - return m_ref->setValue( filename ); - else - return ParserResult::ok( ParseResultType::Matched ); - } - }; - - class Arg : public ParserRefImpl<Arg> { - public: - using ParserRefImpl::ParserRefImpl; - - auto parse(std::string const &, TokenStream const &tokens) const -> InternalParseResult override { - auto validationResult = validate(); - if (!validationResult) - return InternalParseResult(validationResult); - - auto remainingTokens = tokens; - auto const &token = *remainingTokens; - if (token.type != TokenType::Argument) - return InternalParseResult::ok(ParseState(ParseResultType::NoMatch, remainingTokens)); - - auto result = m_ref->setValue(remainingTokens->token); - if (!result) - return InternalParseResult(result); - else - return InternalParseResult::ok(ParseState(ParseResultType::Matched, ++remainingTokens)); - } - }; - - inline auto normaliseOpt(std::string const &optName) -> std::string { - if (optName[0] == '/') - return "-" + optName.substr(1); - else - return optName; - } - - class Opt : public ParserRefImpl<Opt> { - protected: - std::vector<std::string> m_optNames; + void addInitialFilters( std::vector<std::string> const& filters ); + void addNextFilters( std::vector<std::string> const& filters ); + }; + class IndexTracker : public TrackerBase { + int m_size; + int m_index = -1; public: - template<typename LambdaT> - explicit Opt( LambdaT const &ref ) : ParserRefImpl(std::make_shared<BoundFlagLambda<LambdaT>>(ref)) {} - - explicit Opt( bool &ref ) : ParserRefImpl(std::make_shared<BoundFlagRef>(ref)) {} - - template<typename LambdaT> - Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} - - template<typename T> - Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} - - auto operator[](std::string const &optName) -> Opt & { - m_optNames.push_back(optName); - return *this; - } - - auto getHelpColumns() const -> std::vector<HelpColumns> { - std::ostringstream oss; - bool first = true; - for (auto const &opt : m_optNames) { - if (first) - first = false; - else - oss << ", "; - oss << opt; - } - if (!m_hint.empty()) - oss << " <" << m_hint << ">"; - return {{oss.str(), m_description}}; - } - - auto isMatch(std::string const &optToken) const -> bool { -#ifdef CLARA_PLATFORM_WINDOWS - auto normalisedToken = normaliseOpt( optToken ); -#else - auto const &normalisedToken = optToken; -#endif - for (auto const &name : m_optNames) { - if (normaliseOpt(name) == normalisedToken) - return true; - } - return false; - } - - using ParserBase::parse; - - auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { - auto validationResult = validate(); - if (!validationResult) - return InternalParseResult(validationResult); - - auto remainingTokens = tokens; - if (remainingTokens && remainingTokens->type == TokenType::Option) { - auto const &token = *remainingTokens; - if (isMatch(token.token)) { - if (m_ref->isFlag()) { - auto result = m_ref->setFlag(true); - if (!result) - return InternalParseResult(result); - if (result.value() == ParseResultType::ShortCircuitAll) - return InternalParseResult::ok(ParseState(result.value(), remainingTokens)); - } else { - ++remainingTokens; - if (!remainingTokens) - return InternalParseResult::runtimeError("Expected argument following " + token.token); - auto const &argToken = *remainingTokens; - if (argToken.type != TokenType::Argument) - return InternalParseResult::runtimeError("Expected argument following " + token.token); - auto result = m_ref->setValue(argToken.token); - if (!result) - return InternalParseResult(result); - if (result.value() == ParseResultType::ShortCircuitAll) - return InternalParseResult::ok(ParseState(result.value(), remainingTokens)); - } - return InternalParseResult::ok(ParseState(ParseResultType::Matched, ++remainingTokens)); - } - } - return InternalParseResult::ok(ParseState(ParseResultType::NoMatch, remainingTokens)); - } - - auto validate() const -> Result override { - if (m_optNames.empty()) - return Result::logicError("No options supplied to Opt"); - for (auto const &name : m_optNames) { - if (name.empty()) - return Result::logicError("Option name cannot be empty"); - if (name[0] != '-' && name[0] != '/') - return Result::logicError("Option name must begin with '-' or '/'"); - } - return ParserRefImpl::validate(); - } - }; - - struct Help : Opt { - Help( bool &showHelpFlag ) - : Opt([&]( bool flag ) { - showHelpFlag = flag; - return ParserResult::ok(ParseResultType::ShortCircuitAll); - }) - { - static_cast<Opt &>(*this) - ("display usage information") - ["-?"]["-h"]["--help"] - .optional(); - } - }; - - struct Parser : ParserBase { - - mutable ExeName m_exeName; - std::vector<Opt> m_options; - std::vector<Arg> m_args; - - auto operator+=(ExeName const &exeName) -> Parser & { - m_exeName = exeName; - return *this; - } - - auto operator+=(Arg const &arg) -> Parser & { - m_args.push_back(arg); - return *this; - } - - auto operator+=(Opt const &opt) -> Parser & { - m_options.push_back(opt); - return *this; - } - - auto operator+=(Parser const &other) -> Parser & { - m_options.insert(m_options.end(), other.m_options.begin(), other.m_options.end()); - m_args.insert(m_args.end(), other.m_args.begin(), other.m_args.end()); - return *this; - } - - template<typename T> - auto operator+(T const &other) const -> Parser { - return Parser(*this) += other; - } - - auto getHelpColumns() const -> std::vector<HelpColumns> { - std::vector<HelpColumns> cols; - for (auto const &o : m_options) { - auto childCols = o.getHelpColumns(); - cols.insert(cols.end(), childCols.begin(), childCols.end()); - } - return cols; - } - - void writeToStream(std::ostream &os) const { - if (!m_exeName.name().empty()) { - os << "usage:\n" << " " << m_exeName.name() << " "; - bool required = true, first = true; - for (auto const &arg : m_args) { - if (first) - first = false; - else - os << " "; - if (arg.isOptional() && required) { - os << "["; - required = false; - } - os << "<" << arg.hint() << ">"; - if (arg.cardinality() == 0) - os << " ... "; - } - if (!required) - os << "]"; - if (!m_options.empty()) - os << " options"; - os << "\n\nwhere options are:" << std::endl; - } - - auto rows = getHelpColumns(); - size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; - size_t optWidth = 0; - for (auto const &cols : rows) - optWidth = std::max(optWidth, cols.left.size() + 2); - - for (auto const &cols : rows) { - auto row = - TextFlow::Column(cols.left).width(optWidth).indent(2) + - TextFlow::Spacer(4) + - TextFlow::Column(cols.right).width(consoleWidth - 7 - optWidth); - os << row << std::endl; - } - } - - friend auto operator<<(std::ostream &os, Parser const &parser) -> std::ostream & { - parser.writeToStream(os); - return os; - } - - auto validate() const -> Result override { - for (auto const &opt : m_options) { - auto result = opt.validate(); - if (!result) - return result; - } - for (auto const &arg : m_args) { - auto result = arg.validate(); - if (!result) - return result; - } - return Result::ok(); - } - - using ParserBase::parse; - - auto parse( std::string const& exeName, TokenStream const &tokens) const -> InternalParseResult override { - std::vector<ParserBase const *> allParsers; - allParsers.reserve(m_args.size() + m_options.size()); - std::set<ParserBase const *> requiredParsers; - - for (auto const &opt : m_options) { - allParsers.push_back(&opt); - if (!opt.isOptional()) - requiredParsers.insert(&opt); - } - - size_t optionalArgs = 0; - for (auto const &arg : m_args) { - allParsers.push_back(&arg); - if (!arg.isOptional()) { - if (optionalArgs > 0) - return InternalParseResult::logicError( - "Required arguments must preceed any optional arguments"); - else - ++optionalArgs; - requiredParsers.insert(&arg); - } - } + IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size ); - m_exeName.set( exeName ); + bool isIndexTracker() const override; + void close() override; - auto result = InternalParseResult::ok(ParseState(ParseResultType::NoMatch, tokens)); - while (result.value().remainingTokens()) { - auto remainingTokenCount = result.value().remainingTokens().count(); - for (auto parser : allParsers) { - result = parser->parse( exeName, result.value().remainingTokens() ); - if (!result || result.value().type() != ParseResultType::NoMatch) { - if (parser->cardinality() == 1) - allParsers.erase(std::remove(allParsers.begin(), allParsers.end(), parser), - allParsers.end()); - requiredParsers.erase(parser); - break; - } - } - if (!result || remainingTokenCount == result.value().remainingTokens().count()) - return result; - } - // !TBD Check missing required options - return result; - } - }; + static IndexTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size ); - template<typename DerivedT> - template<typename T> - auto ComposableParserImpl<DerivedT>::operator+(T const &other) const -> Parser { - return Parser() + static_cast<DerivedT const &>( *this ) + other; - } -} // namespace detail + int index() const; -// A Combined parser -using detail::Parser; + void moveNext(); + }; -// A parser for options -using detail::Opt; +} // namespace TestCaseTracking -// A parser for arguments -using detail::Arg; +using TestCaseTracking::ITracker; +using TestCaseTracking::TrackerContext; +using TestCaseTracking::SectionTracker; +using TestCaseTracking::IndexTracker; -// Wrapper for argc, argv from main() -using detail::Args; +} // namespace Catch -// Specifies the name of the executable -using detail::ExeName; +// end catch_test_case_tracker.h -// Convenience wrapper for option parser that specifies the help option -using detail::Help; +// start catch_leak_detector.h -// enum of result types from a parse -using detail::ParseResultType; +namespace Catch { -// Result type for parser operation -using detail::ParserResult; + struct LeakDetector { + LeakDetector(); + }; -}} // namespace Catch::clara +} +// end catch_leak_detector.h +// Cpp files will be included in the single-header file here +// start catch_approx.cpp -// end clara.hpp -// Restore Clara's value for console width, if present -#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH -#endif +#include <limits> -// end catch_clara.h namespace Catch { +namespace Detail { - clara::Parser makeCommandLineParser( ConfigData& config ); - -} // end namespace Catch + double max(double lhs, double rhs) { + if (lhs < rhs) { + return rhs; + } + return lhs; + } -// end catch_commandline.hpp -// start catch_console_colour.hpp + Approx::Approx ( double value ) + : m_epsilon( std::numeric_limits<float>::epsilon()*100 ), + m_margin( 0.0 ), + m_scale( 1.0 ), + m_value( value ) + {} -namespace Catch { + Approx Approx::custom() { + return Approx( 0 ); + } - struct Colour { - enum Code { - None = 0, + std::string Approx::toString() const { + std::ostringstream oss; + oss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )"; + return oss.str(); + } - White, - Red, - Green, - Blue, - Cyan, - Yellow, - Grey, +} // end namespace Detail - Bright = 0x10, +std::string StringMaker<Catch::Detail::Approx>::convert(Catch::Detail::Approx const& value) { + return value.toString(); +} - BrightRed = Bright | Red, - BrightGreen = Bright | Green, - LightGrey = Bright | Grey, - BrightWhite = Bright | White, +} // end namespace Catch +// end catch_approx.cpp +// start catch_assertionhandler.cpp - // By intention - FileName = LightGrey, - Warning = Yellow, - ResultError = BrightRed, - ResultSuccess = BrightGreen, - ResultExpectedFailure = Warning, +// start catch_context.h - Error = BrightRed, - Success = Green, +#include <memory> - OriginalExpression = Cyan, - ReconstructedExpression = Yellow, +namespace Catch { - SecondaryText = LightGrey, - Headers = White - }; + struct IResultCapture; + struct IRunner; + struct IConfig; - // Use constructed object for RAII guard - Colour( Code _colourCode ); - Colour( Colour&& other ) noexcept; - Colour& operator=( Colour&& other ) noexcept; - ~Colour(); + using IConfigPtr = std::shared_ptr<IConfig const>; - // Use static method for one-shot changes - static void use( Code _colourCode ); + struct IContext + { + virtual ~IContext(); - private: - bool m_moved = false; + virtual IResultCapture* getResultCapture() = 0; + virtual IRunner* getRunner() = 0; + virtual IConfigPtr getConfig() const = 0; }; - std::ostream& operator << ( std::ostream& os, Colour const& ); - -} // end namespace Catch + struct IMutableContext : IContext + { + virtual ~IMutableContext(); + virtual void setResultCapture( IResultCapture* resultCapture ) = 0; + virtual void setRunner( IRunner* runner ) = 0; + virtual void setConfig( IConfigPtr const& config ) = 0; + }; -// end catch_console_colour.hpp -// start catch_list.h + IContext& getCurrentContext(); + IMutableContext& getCurrentMutableContext(); + void cleanUpContext(); +} -#include <set> +// end catch_context.h +#include <cassert> namespace Catch { - std::size_t listTests( Config const& config ); - - std::size_t listTestsNamesOnly( Config const& config ); + auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& { + expr.streamReconstructedExpression( os ); + return os; + } - struct TagInfo { - void add( std::string const& spelling ); - std::string all() const; + LazyExpression::LazyExpression( bool isNegated ) + : m_isNegated( isNegated ) + {} - std::set<std::string> spellings; - std::size_t count = 0; - }; + LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {} - std::size_t listTags( Config const& config ); + LazyExpression::operator bool() const { + return m_transientExpression != nullptr; + } - std::size_t listReporters( Config const& /*config*/ ); + auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& { + if( lazyExpr.m_isNegated ) + os << "!"; - Option<std::size_t> list( Config const& config ); + if( lazyExpr ) { + if( lazyExpr.m_isNegated && lazyExpr.m_transientExpression->isBinaryExpression() ) + os << "(" << *lazyExpr.m_transientExpression << ")"; + else + os << *lazyExpr.m_transientExpression; + } + else { + os << "{** error - unchecked empty expression requested **}"; + } + return os; + } -} // end namespace Catch + AssertionHandler::AssertionHandler + ( StringRef macroName, + SourceLineInfo const& lineInfo, + StringRef capturedExpression, + ResultDisposition::Flags resultDisposition ) + : m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition } + { + getCurrentContext().getResultCapture()->assertionStarting( m_assertionInfo ); + } + AssertionHandler::~AssertionHandler() { + if ( m_inExceptionGuard ) { + handle( ResultWas::ThrewException, "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE" ); + getCurrentContext().getResultCapture()->exceptionEarlyReported(); + } + } -// end catch_list.h -// start catch_run_context.hpp + void AssertionHandler::handle( ITransientExpression const& expr ) { -// start catch_test_case_tracker.hpp + bool negated = isFalseTest( m_assertionInfo.resultDisposition ); + bool result = expr.getResult() != negated; -#include <string> -#include <vector> -#include <memory> + handle( result ? ResultWas::Ok : ResultWas::ExpressionFailed, &expr, negated ); + } + void AssertionHandler::handle( ResultWas::OfType resultType ) { + handle( resultType, nullptr, false ); + } + void AssertionHandler::handle( ResultWas::OfType resultType, StringRef const& message ) { + AssertionResultData data( resultType, LazyExpression( false ) ); + data.message = message; + handle( data, nullptr ); + } + void AssertionHandler::handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated ) { + AssertionResultData data( resultType, LazyExpression( negated ) ); + handle( data, expr ); + } + void AssertionHandler::handle( AssertionResultData const& resultData, ITransientExpression const* expr ) { -CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS + getResultCapture().assertionRun(); -namespace Catch { -namespace TestCaseTracking { + AssertionResult assertionResult{ m_assertionInfo, resultData }; + assertionResult.m_resultData.lazyExpression.m_transientExpression = expr; - struct NameAndLocation { - std::string name; - SourceLineInfo location; + getResultCapture().assertionEnded( assertionResult ); - NameAndLocation( std::string const& _name, SourceLineInfo const& _location ); - }; + if( !assertionResult.isOk() ) { + m_shouldDebugBreak = getCurrentContext().getConfig()->shouldDebugBreak(); + m_shouldThrow = + getCurrentContext().getRunner()->aborting() || + (m_assertionInfo.resultDisposition & ResultDisposition::Normal); + } + } - struct ITracker; + auto AssertionHandler::allowThrows() const -> bool { + return getCurrentContext().getConfig()->allowThrows(); + } - using ITrackerPtr = std::shared_ptr<ITracker>; + auto AssertionHandler::shouldDebugBreak() const -> bool { + return m_shouldDebugBreak; + } + void AssertionHandler::reactWithDebugBreak() const { + if (m_shouldDebugBreak) { + /////////////////////////////////////////////////////////////////// + // To inspect the state during test, you need to go one level up the callstack + // To go back to the test and change execution, jump over the reactWithoutDebugBreak() call + /////////////////////////////////////////////////////////////////// + CATCH_BREAK_INTO_DEBUGGER(); + } + reactWithoutDebugBreak(); + } + void AssertionHandler::reactWithoutDebugBreak() const { + if( m_shouldThrow ) + throw Catch::TestFailureException(); + } - struct ITracker { - virtual ~ITracker() = default; + void AssertionHandler::useActiveException() { + handle( ResultWas::ThrewException, Catch::translateActiveException() ); + } - // static queries - virtual NameAndLocation const& nameAndLocation() const = 0; + void AssertionHandler::setExceptionGuard() { + assert( m_inExceptionGuard == false ); + m_inExceptionGuard = true; + } + void AssertionHandler::unsetExceptionGuard() { + assert( m_inExceptionGuard == true ); + m_inExceptionGuard = false; + } - // dynamic queries - virtual bool isComplete() const = 0; // Successfully completed or failed - virtual bool isSuccessfullyCompleted() const = 0; - virtual bool isOpen() const = 0; // Started but not complete - virtual bool hasChildren() const = 0; + // This is the overload that takes a string and infers the Equals matcher from it + // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp + void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ) { + handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString ); + } - virtual ITracker& parent() = 0; +} // namespace Catch +// end catch_assertionhandler.cpp +// start catch_assertionresult.cpp - // actions - virtual void close() = 0; // Successfully complete - virtual void fail() = 0; - virtual void markAsNeedingAnotherRun() = 0; +namespace Catch { + AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression): + lazyExpression(_lazyExpression), + resultType(_resultType) {} - virtual void addChild( ITrackerPtr const& child ) = 0; - virtual ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) = 0; - virtual void openChild() = 0; + std::string AssertionResultData::reconstructExpression() const { - // Debug/ checking - virtual bool isSectionTracker() const = 0; - virtual bool isIndexTracker() const = 0; - }; + if( reconstructedExpression.empty() ) { + if( lazyExpression ) { + // !TBD Use stringstream for now, but rework above to pass stream in + std::ostringstream oss; + oss << lazyExpression; + reconstructedExpression = oss.str(); + } + } + return reconstructedExpression; + } - class TrackerContext { + AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) + : m_info( info ), + m_resultData( data ) + {} - enum RunState { - NotStarted, - Executing, - CompletedCycle - }; + // Result was a success + bool AssertionResult::succeeded() const { + return Catch::isOk( m_resultData.resultType ); + } - ITrackerPtr m_rootTracker; - ITracker* m_currentTracker = nullptr; - RunState m_runState = NotStarted; + // Result was a success, or failure is suppressed + bool AssertionResult::isOk() const { + return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition ); + } - public: + ResultWas::OfType AssertionResult::getResultType() const { + return m_resultData.resultType; + } - static TrackerContext& instance(); + bool AssertionResult::hasExpression() const { + return m_info.capturedExpression[0] != 0; + } - ITracker& startRun(); - void endRun(); + bool AssertionResult::hasMessage() const { + return !m_resultData.message.empty(); + } - void startCycle(); - void completeCycle(); + std::string AssertionResult::getExpression() const { + if (isFalseTest(m_info.resultDisposition)) + return '!' + std::string(m_info.capturedExpression); + else + return m_info.capturedExpression; + } - bool completedCycle() const; - ITracker& currentTracker(); - void setCurrentTracker( ITracker* tracker ); - }; + std::string AssertionResult::getExpressionInMacro() const { + std::string expr; + if( m_info.macroName[0] == 0 ) + expr = m_info.capturedExpression; + else { + expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 ); + expr += m_info.macroName; + expr += "( "; + expr += m_info.capturedExpression; + expr += " )"; + } + return expr; + } - class TrackerBase : public ITracker { - protected: - enum CycleState { - NotStarted, - Executing, - ExecutingChildren, - NeedsAnotherRun, - CompletedSuccessfully, - Failed - }; + bool AssertionResult::hasExpandedExpression() const { + return hasExpression() && getExpandedExpression() != getExpression(); + } - class TrackerHasName { - NameAndLocation m_nameAndLocation; - public: - TrackerHasName( NameAndLocation const& nameAndLocation ); - bool operator ()( ITrackerPtr const& tracker ) const; - }; + std::string AssertionResult::getExpandedExpression() const { + std::string expr = m_resultData.reconstructExpression(); + return expr.empty() + ? getExpression() + : expr; + } - using Children = std::vector<ITrackerPtr>; - NameAndLocation m_nameAndLocation; - TrackerContext& m_ctx; - ITracker* m_parent; - Children m_children; - CycleState m_runState = NotStarted; + std::string AssertionResult::getMessage() const { + return m_resultData.message; + } + SourceLineInfo AssertionResult::getSourceInfo() const { + return m_info.lineInfo; + } - public: - TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); + std::string AssertionResult::getTestMacroName() const { + return m_info.macroName; + } - NameAndLocation const& nameAndLocation() const override; - bool isComplete() const override; - bool isSuccessfullyCompleted() const override; - bool isOpen() const override; - bool hasChildren() const override; +} // end namespace Catch +// end catch_assertionresult.cpp +// start catch_benchmark.cpp - void addChild( ITrackerPtr const& child ) override; +namespace Catch { - ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) override; - ITracker& parent() override; + auto BenchmarkLooper::getResolution() -> uint64_t { + return getEstimatedClockResolution() * getCurrentContext().getConfig()->benchmarkResolutionMultiple(); + } - void openChild() override; + void BenchmarkLooper::reportStart() { + getResultCapture().benchmarkStarting( { m_name } ); + } + auto BenchmarkLooper::needsMoreIterations() -> bool { + auto elapsed = m_timer.getElapsedNanoseconds(); - bool isSectionTracker() const override; - bool isIndexTracker() const override; + // Exponentially increasing iterations until we're confident in our timer resolution + if( elapsed < m_resolution ) { + m_iterationsToRun *= 10; + return true; + } - void open(); + getResultCapture().benchmarkEnded( { { m_name }, m_count, elapsed } ); + return false; + } - void close() override; - void fail() override; - void markAsNeedingAnotherRun() override; +} // end namespace Catch +// end catch_benchmark.cpp +// start catch_capture_matchers.cpp - private: - void moveToParent(); - void moveToThis(); - }; +namespace Catch { - class SectionTracker : public TrackerBase { - std::vector<std::string> m_filters; - public: - SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ); + using StringMatcher = Matchers::Impl::MatcherBase<std::string>; - bool isSectionTracker() const override; + // This is the general overload that takes a any string matcher + // There is another overload, in catch_assertinhandler.h/.cpp, that only takes a string and infers + // the Equals matcher (so the header does not mention matchers) + void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ) { + std::string exceptionMessage = Catch::translateActiveException(); + MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString ); + handler.handle( expr ); + } - static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation ); +} // namespace Catch +// end catch_capture_matchers.cpp +// start catch_commandline.cpp - void tryOpen(); +// start catch_commandline.h - void addInitialFilters( std::vector<std::string> const& filters ); - void addNextFilters( std::vector<std::string> const& filters ); - }; +// start catch_clara.h - class IndexTracker : public TrackerBase { - int m_size; - int m_index = -1; - public: - IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size ); +// Use Catch's value for console width (store Clara's off to the side, if present) +#ifdef CLARA_CONFIG_CONSOLE_WIDTH +#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#endif +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH-1 - bool isIndexTracker() const override; - void close() override; +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wweak-vtables" +#pragma clang diagnostic ignored "-Wexit-time-destructors" +#pragma clang diagnostic ignored "-Wshadow" +#endif - static IndexTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size ); +// start clara.hpp +// v1.0 +// See https://github.com/philsquared/Clara - int index() const; - void moveNext(); - }; +#ifndef CATCH_CLARA_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_CONFIG_CONSOLE_WIDTH 80 +#endif -} // namespace TestCaseTracking +// ----------- #included from clara_textflow.hpp ----------- -using TestCaseTracking::ITracker; -using TestCaseTracking::TrackerContext; -using TestCaseTracking::SectionTracker; -using TestCaseTracking::IndexTracker; +// TextFlowCpp +// +// A single-header library for wrapping and laying out basic text, by Phil Nash +// +// This work is licensed under the BSD 2-Clause license. +// See the accompanying LICENSE file, or the one at https://opensource.org/licenses/BSD-2-Clause +// +// This project is hosted at https://github.com/philsquared/textflowcpp -} // namespace Catch -CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS +#include <cassert> +#include <ostream> +#include <sstream> +#include <vector> -// end catch_test_case_tracker.hpp -// start catch_fatal_condition.h +#ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH 80 +#endif -#include <string> +namespace Catch { namespace clara { namespace TextFlow { -namespace Catch { + inline auto isWhitespace( char c ) -> bool { + static std::string chars = " \t\n\r"; + return chars.find( c ) != std::string::npos; + } + inline auto isBreakableBefore( char c ) -> bool { + static std::string chars = "[({<|"; + return chars.find( c ) != std::string::npos; + } + inline auto isBreakableAfter( char c ) -> bool { + static std::string chars = "])}>.,:;*+-=&/\\"; + return chars.find( c ) != std::string::npos; + } - // Report the error condition - void reportFatal( std::string const& message ); + class Columns; -} // namespace Catch + class Column { + std::vector<std::string> m_strings; + size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH; + size_t m_indent = 0; + size_t m_initialIndent = std::string::npos; -#if defined ( CATCH_PLATFORM_WINDOWS ) ///////////////////////////////////////// -// start catch_windows_h_proxy.h + public: + class iterator { + friend Column; + Column const& m_column; + size_t m_stringIndex = 0; + size_t m_pos = 0; -#if defined(CATCH_PLATFORM_WINDOWS) -# if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX) -# define CATCH_DEFINED_NOMINMAX -# define NOMINMAX -# endif -# if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN) -# define CATCH_DEFINED_WIN32_LEAN_AND_MEAN -# define WIN32_LEAN_AND_MEAN -# endif -#endif + size_t m_len = 0; + size_t m_end = 0; + bool m_suffix = false; -#ifdef __AFXDLL -#include <AfxWin.h> -#else -#include <windows.h> -#endif + iterator( Column const& column, size_t stringIndex ) + : m_column( column ), + m_stringIndex( stringIndex ) + {} -#ifdef CATCH_DEFINED_NOMINMAX -# undef NOMINMAX -#endif -#ifdef CATCH_DEFINED_WIN32_LEAN_AND_MEAN -# undef WIN32_LEAN_AND_MEAN -#endif + auto line() const -> std::string const& { return m_column.m_strings[m_stringIndex]; } -// end catch_windows_h_proxy.h + auto isBoundary( size_t at ) const -> bool { + assert( at > 0 ); + assert( at <= line().size() ); -# if !defined ( CATCH_CONFIG_WINDOWS_SEH ) + return at == line().size() || + ( isWhitespace( line()[at] ) && !isWhitespace( line()[at-1] ) ) || + isBreakableBefore( line()[at] ) || + isBreakableAfter( line()[at-1] ); + } -namespace Catch { - struct FatalConditionHandler { - void reset(); - }; -} + void calcLength() { + assert( m_stringIndex < m_column.m_strings.size() ); -# else // CATCH_CONFIG_WINDOWS_SEH is defined + m_suffix = false; + auto width = m_column.m_width-indent(); + m_end = m_pos; + while( m_end < line().size() && line()[m_end] != '\n' ) + ++m_end; -namespace Catch { + if( m_end < m_pos + width ) { + m_len = m_end - m_pos; + } + else { + size_t len = width; + while (len > 0 && !isBoundary(m_pos + len)) + --len; + while (len > 0 && isWhitespace( line()[m_pos + len - 1] )) + --len; - struct FatalConditionHandler { + if (len > 0) { + m_len = len; + } else { + m_suffix = true; + m_len = width - 1; + } + } + } - static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo); - FatalConditionHandler(); - static void reset(); - ~FatalConditionHandler(); + auto indent() const -> size_t { + auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos; + return initial == std::string::npos ? m_column.m_indent : initial; + } - private: - static bool isSet; - static ULONG guaranteeSize; - static PVOID exceptionHandlerHandle; - }; + auto addIndentAndSuffix(std::string const &plain) const -> std::string { + return std::string( indent(), ' ' ) + (m_suffix ? plain + "-" : plain); + } -} // namespace Catch + public: + explicit iterator( Column const& column ) : m_column( column ) { + assert( m_column.m_width > m_column.m_indent ); + assert( m_column.m_initialIndent == std::string::npos || m_column.m_width > m_column.m_initialIndent ); + calcLength(); + if( m_len == 0 ) + m_stringIndex++; // Empty string + } -# endif // CATCH_CONFIG_WINDOWS_SEH + auto operator *() const -> std::string { + assert( m_stringIndex < m_column.m_strings.size() ); + assert( m_pos <= m_end ); + if( m_pos + m_column.m_width < m_end ) + return addIndentAndSuffix(line().substr(m_pos, m_len)); + else + return addIndentAndSuffix(line().substr(m_pos, m_end - m_pos)); + } -#else // Not Windows - assumed to be POSIX compatible ////////////////////////// + auto operator ++() -> iterator& { + m_pos += m_len; + if( m_pos < line().size() && line()[m_pos] == '\n' ) + m_pos += 1; + else + while( m_pos < line().size() && isWhitespace( line()[m_pos] ) ) + ++m_pos; -# if !defined(CATCH_CONFIG_POSIX_SIGNALS) + if( m_pos == line().size() ) { + m_pos = 0; + ++m_stringIndex; + } + if( m_stringIndex < m_column.m_strings.size() ) + calcLength(); + return *this; + } + auto operator ++(int) -> iterator { + iterator prev( *this ); + operator++(); + return prev; + } -namespace Catch { - struct FatalConditionHandler { - void reset(); - }; -} + auto operator ==( iterator const& other ) const -> bool { + return + m_pos == other.m_pos && + m_stringIndex == other.m_stringIndex && + &m_column == &other.m_column; + } + auto operator !=( iterator const& other ) const -> bool { + return !operator==( other ); + } + }; + using const_iterator = iterator; -# else // CATCH_CONFIG_POSIX_SIGNALS is defined + explicit Column( std::string const& text ) { m_strings.push_back( text ); } -#include <signal.h> + auto width( size_t newWidth ) -> Column& { + assert( newWidth > 0 ); + m_width = newWidth; + return *this; + } + auto indent( size_t newIndent ) -> Column& { + m_indent = newIndent; + return *this; + } + auto initialIndent( size_t newIndent ) -> Column& { + m_initialIndent = newIndent; + return *this; + } -namespace Catch { + auto width() const -> size_t { return m_width; } + auto begin() const -> iterator { return iterator( *this ); } + auto end() const -> iterator { return { *this, m_strings.size() }; } - struct FatalConditionHandler { + inline friend std::ostream& operator << ( std::ostream& os, Column const& col ) { + bool first = true; + for( auto line : col ) { + if( first ) + first = false; + else + os << "\n"; + os << line; + } + return os; + } - static bool isSet; - static struct sigaction oldSigActions[];// [sizeof(signalDefs) / sizeof(SignalDefs)]; - static stack_t oldSigStack; - static char altStackMem[]; + auto operator + ( Column const& other ) -> Columns; + + auto toString() const -> std::string { + std::ostringstream oss; + oss << *this; + return oss.str(); + } + }; - static void handleSignal( int sig ); + class Spacer : public Column { - FatalConditionHandler(); - ~FatalConditionHandler(); - static void reset(); + public: + explicit Spacer( size_t spaceWidth ) : Column( "" ) { + width( spaceWidth ); + } }; -} // namespace Catch + class Columns { + std::vector<Column> m_columns; -# endif // CATCH_CONFIG_POSIX_SIGNALS + public: -#endif // not Windows + class iterator { + friend Columns; + struct EndTag {}; -// end catch_fatal_condition.h -#include <string> + std::vector<Column> const& m_columns; + std::vector<Column::iterator> m_iterators; + size_t m_activeIterators; -namespace Catch { + iterator( Columns const& columns, EndTag ) + : m_columns( columns.m_columns ), + m_activeIterators( 0 ) + { + m_iterators.reserve( m_columns.size() ); - struct IMutableContext; + for( auto const& col : m_columns ) + m_iterators.push_back( col.end() ); + } - class StreamRedirect { + public: + explicit iterator( Columns const& columns ) + : m_columns( columns.m_columns ), + m_activeIterators( m_columns.size() ) + { + m_iterators.reserve( m_columns.size() ); - public: - StreamRedirect(std::ostream& stream, std::string& targetString); + for( auto const& col : m_columns ) + m_iterators.push_back( col.begin() ); + } - ~StreamRedirect(); + auto operator ==( iterator const& other ) const -> bool { + return m_iterators == other.m_iterators; + } + auto operator !=( iterator const& other ) const -> bool { + return m_iterators != other.m_iterators; + } + auto operator *() const -> std::string { + std::string row, padding; - private: - std::ostream& m_stream; - std::streambuf* m_prevBuf; - std::ostringstream m_oss; - std::string& m_targetString; - }; + for( size_t i = 0; i < m_columns.size(); ++i ) { + auto width = m_columns[i].width(); + if( m_iterators[i] != m_columns[i].end() ) { + std::string col = *m_iterators[i]; + row += padding + col; + if( col.size() < width ) + padding = std::string( width - col.size(), ' ' ); + else + padding = ""; + } + else { + padding += std::string( width, ' ' ); + } + } + return row; + } + auto operator ++() -> iterator& { + for( size_t i = 0; i < m_columns.size(); ++i ) { + if (m_iterators[i] != m_columns[i].end()) + ++m_iterators[i]; + } + return *this; + } + auto operator ++(int) -> iterator { + iterator prev( *this ); + operator++(); + return prev; + } + }; + using const_iterator = iterator; - // StdErr has two constituent streams in C++, std::cerr and std::clog - // This means that we need to redirect 2 streams into 1 to keep proper - // order of writes and cannot use StreamRedirect on its own - class StdErrRedirect { - public: - StdErrRedirect(std::string& targetString); - ~StdErrRedirect(); - private: - std::streambuf* m_cerrBuf; - std::streambuf* m_clogBuf; - std::ostringstream m_oss; - std::string& m_targetString; - }; + auto begin() const -> iterator { return iterator( *this ); } + auto end() const -> iterator { return { *this, iterator::EndTag() }; } - /////////////////////////////////////////////////////////////////////////// + auto operator += ( Column const& col ) -> Columns& { + m_columns.push_back( col ); + return *this; + } + auto operator + ( Column const& col ) -> Columns { + Columns combined = *this; + combined += col; + return combined; + } - class RunContext : public IResultCapture, public IRunner { + inline friend std::ostream& operator << ( std::ostream& os, Columns const& cols ) { - public: - RunContext( RunContext const& ) = delete; - RunContext& operator =( RunContext const& ) = delete; + bool first = true; + for( auto line : cols ) { + if( first ) + first = false; + else + os << "\n"; + os << line; + } + return os; + } - explicit RunContext(IConfigPtr const& _config, IStreamingReporterPtr&& reporter); + auto toString() const -> std::string { + std::ostringstream oss; + oss << *this; + return oss.str(); + } + }; - virtual ~RunContext(); + inline auto Column::operator + ( Column const& other ) -> Columns { + Columns cols; + cols += *this; + cols += other; + return cols; + } +}}} // namespace Catch::clara::TextFlow - void testGroupStarting(std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount); - void testGroupEnded(std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount); +// ----------- end of #include from clara_textflow.hpp ----------- +// ........... back in clara.hpp - Totals runTest(TestCase const& testCase); +#include <memory> +#include <set> +#include <algorithm> - IConfigPtr config() const; - IStreamingReporter& reporter() const; +#if !defined(CLARA_PLATFORM_WINDOWS) && ( defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) ) +#define CLARA_PLATFORM_WINDOWS - private: // IResultCapture +#endif - void assertionStarting(AssertionInfo const& info) override; - void assertionEnded(AssertionResult const& result) override; +namespace Catch { namespace clara { +namespace detail { - bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override; - bool testForMissingAssertions(Counts& assertions); + // Traits for extracting arg and return type of lambdas (for single argument lambdas) + template<typename L> + struct UnaryLambdaTraits : UnaryLambdaTraits<decltype(&L::operator())> {}; - void sectionEnded(SectionEndInfo const& endInfo) override; - void sectionEndedEarly(SectionEndInfo const& endInfo) override; + template<typename ClassT, typename ReturnT, typename... Args> + struct UnaryLambdaTraits<ReturnT(ClassT::*)(Args...) const> { + static const bool isValid = false; + }; - void benchmarkStarting( BenchmarkInfo const& info ) override; - void benchmarkEnded( BenchmarkStats const& stats ) override; + template<typename ClassT, typename ReturnT, typename ArgT> + struct UnaryLambdaTraits<ReturnT(ClassT::*)(ArgT) const> { + static const bool isValid = true; + using ArgType = typename std::remove_const<typename std::remove_reference<ArgT>::type>::type;; + using ReturnType = ReturnT; + }; - void pushScopedMessage(MessageInfo const& message) override; - void popScopedMessage(MessageInfo const& message) override; + class TokenStream; - std::string getCurrentTestName() const override; + // Transport for raw args (copied from main args, or supplied via init list for testing) + class Args { + friend TokenStream; + std::string m_exeName; + std::vector<std::string> m_args; - const AssertionResult* getLastResult() const override; + public: + Args(int argc, char *argv[]) { + m_exeName = argv[0]; + for (int i = 1; i < argc; ++i) + m_args.push_back(argv[i]); + } - void exceptionEarlyReported() override; + Args(std::initializer_list<std::string> args) + : m_exeName( *args.begin() ), + m_args( args.begin()+1, args.end() ) + {} - void handleFatalErrorCondition(std::string const& message) override; + auto exeName() const -> std::string { + return m_exeName; + } + }; - bool lastAssertionPassed() override; + // Wraps a token coming from a token stream. These may not directly correspond to strings as a single string + // may encode an option + its argument if the : or = form is used + enum class TokenType { + Option, Argument + }; + struct Token { + TokenType type; + std::string token; + }; - void assertionPassed() override; + // Abstracts iterators into args as a stream of tokens, with option arguments uniformly handled + class TokenStream { + using Iterator = std::vector<std::string>::const_iterator; + Iterator it; + Iterator itEnd; + std::vector<Token> m_tokenBuffer; - void assertionRun() override; + void loadBuffer() { + m_tokenBuffer.resize(0); + + // Skip any empty strings + while (it != itEnd && it->empty()) + ++it; + + if (it != itEnd) { + auto const &next = *it; + if (next[0] == '-' || next[0] == '/') { + auto delimiterPos = next.find_first_of(" :="); + if (delimiterPos != std::string::npos) { + m_tokenBuffer.push_back({TokenType::Option, next.substr(0, delimiterPos)}); + m_tokenBuffer.push_back({TokenType::Argument, next.substr(delimiterPos + 1)}); + } else { + if (next[1] != '-' && next.size() > 2) { + std::string opt = "- "; + for (size_t i = 1; i < next.size(); ++i) { + opt[1] = next[i]; + m_tokenBuffer.push_back({TokenType::Option, opt}); + } + } else { + m_tokenBuffer.push_back({TokenType::Option, next}); + } + } + } else { + m_tokenBuffer.push_back({TokenType::Argument, next}); + } + } + } public: - // !TBD We need to do this another way! - bool aborting() const override; + explicit TokenStream(Args const &args) : TokenStream(args.m_args.begin(), args.m_args.end()) {} - private: + TokenStream(Iterator it, Iterator itEnd) : it(it), itEnd(itEnd) { + loadBuffer(); + } - void runCurrentTest(std::string& redirectedCout, std::string& redirectedCerr); - void invokeActiveTestCase(); + explicit operator bool() const { + return !m_tokenBuffer.empty() || it != itEnd; + } - private: + auto count() const -> size_t { return m_tokenBuffer.size() + (itEnd - it); } - void handleUnfinishedSections(); + auto operator*() const -> Token { + assert(!m_tokenBuffer.empty()); + return m_tokenBuffer.front(); + } - TestRunInfo m_runInfo; - IMutableContext& m_context; - TestCase const* m_activeTestCase = nullptr; - ITracker* m_testCaseTracker; - Option<AssertionResult> m_lastResult; + auto operator->() const -> Token const * { + assert(!m_tokenBuffer.empty()); + return &m_tokenBuffer.front(); + } - IConfigPtr m_config; - Totals m_totals; - IStreamingReporterPtr m_reporter; - std::vector<MessageInfo> m_messages; - AssertionInfo m_lastAssertionInfo; - std::vector<SectionEndInfo> m_unfinishedSections; - std::vector<ITracker*> m_activeSections; - TrackerContext m_trackerContext; - size_t m_prevPassed = 0; - bool m_shouldReportUnexpected = true; + auto operator++() -> TokenStream & { + if (m_tokenBuffer.size() >= 2) { + m_tokenBuffer.erase(m_tokenBuffer.begin()); + } else { + if (it != itEnd) + ++it; + loadBuffer(); + } + return *this; + } }; - IResultCapture& getResultCapture(); + class ResultBase { + public: + enum Type { + Ok, LogicError, RuntimeError + }; -} // end namespace Catch + protected: + ResultBase(Type type) : m_type(type) {} + virtual ~ResultBase() = default; -// end catch_run_context.hpp -// start catch_stream.h + virtual void enforceOk() const = 0; -// start catch_streambuf.h + Type m_type; + }; -#include <streambuf> + template<typename T> + class ResultValueBase : public ResultBase { + public: + auto value() const -> T const & { + enforceOk(); + return m_value; + } -namespace Catch { + protected: + ResultValueBase(Type type) : ResultBase(type) {} - class StreamBufBase : public std::streambuf { - public: - virtual ~StreamBufBase() noexcept; - }; -} + ResultValueBase(ResultValueBase const &other) : ResultBase(other) { + if (m_type == ResultBase::Ok) + new(&m_value) T(other.m_value); + } -// end catch_streambuf.h -#include <streambuf> -#include <ostream> -#include <fstream> -#include <memory> + ResultValueBase(Type, T const &value) : ResultBase(Ok) { + new(&m_value) T(value); + } -namespace Catch { + auto operator=(ResultValueBase const &other) -> ResultValueBase & { + if (m_type == ResultBase::Ok) + m_value.~T(); + ResultBase::operator=(other); + if (m_type == ResultBase::Ok) + new(&m_value) T(other.m_value); + return *this; + } - std::ostream& cout(); - std::ostream& cerr(); - std::ostream& clog(); + ~ResultValueBase() { + if (m_type == Ok) + m_value.~T(); + } - struct IStream { - virtual ~IStream() noexcept; - virtual std::ostream& stream() const = 0; + union { + T m_value; + }; }; - class FileStream : public IStream { - mutable std::ofstream m_ofs; - public: - FileStream( std::string const& filename ); - ~FileStream() noexcept override; - public: // IStream - std::ostream& stream() const override; + template<> + class ResultValueBase<void> : public ResultBase { + protected: + using ResultBase::ResultBase; }; - class CoutStream : public IStream { - mutable std::ostream m_os; + template<typename T = void> + class BasicResult : public ResultValueBase<T> { public: - CoutStream(); - ~CoutStream() noexcept override; + template<typename U> + explicit BasicResult(BasicResult<U> const &other) + : ResultValueBase<T>(other.type()), + m_errorMessage(other.errorMessage()) { + assert(type() != ResultBase::Ok); + } - public: // IStream - std::ostream& stream() const override; - }; + static auto ok() -> BasicResult { return {ResultBase::Ok}; } - class DebugOutStream : public IStream { - std::unique_ptr<StreamBufBase> m_streamBuf; - mutable std::ostream m_os; - public: - DebugOutStream(); - ~DebugOutStream() noexcept override; + template<typename U> + static auto ok(U const &value) -> BasicResult { return {ResultBase::Ok, value}; } - public: // IStream - std::ostream& stream() const override; - }; -} + static auto logicError(std::string const &message) -> BasicResult { return {ResultBase::LogicError, message}; } -// end catch_stream.h -// start catch_version.h + static auto runtimeError(std::string const &message) -> BasicResult { + return {ResultBase::RuntimeError, message}; + } -#include <iosfwd> + explicit operator bool() const { return m_type == ResultBase::Ok; } -namespace Catch { + auto type() const -> ResultBase::Type { return m_type; } - // Versioning information - struct Version { - Version( Version const& ) = delete; - Version& operator=( Version const& ) = delete; - Version( unsigned int _majorVersion, - unsigned int _minorVersion, - unsigned int _patchNumber, - char const * const _branchName, - unsigned int _buildNumber ); + auto errorMessage() const -> std::string { return m_errorMessage; } - unsigned int const majorVersion; - unsigned int const minorVersion; - unsigned int const patchNumber; + protected: + virtual void enforceOk() const { + // !TBD: If no exceptions, std::terminate here or something + switch (m_type) { + case ResultBase::LogicError: + throw std::logic_error(m_errorMessage); + case ResultBase::RuntimeError: + throw std::runtime_error(m_errorMessage); + case ResultBase::Ok: + break; + } + } - // buildNumber is only used if branchName is not null - char const * const branchName; - unsigned int const buildNumber; + std::string m_errorMessage; // Only populated if resultType is an error - friend std::ostream& operator << ( std::ostream& os, Version const& version ); + BasicResult(ResultBase::Type type, std::string const &message) + : ResultValueBase<T>(type), + m_errorMessage(message) { + assert(m_type != ResultBase::Ok); + } + + using ResultValueBase<T>::ResultValueBase; + using ResultBase::m_type; }; - Version const& libraryVersion(); -} + enum class ParseResultType { + Matched, NoMatch, ShortCircuitAll, ShortCircuitSame + }; -// end catch_version.h -// start catch_startup_exception_registry.h + class ParseState { + public: -#include <vector> -#include <exception> + ParseState(ParseResultType type, TokenStream const &remainingTokens) + : m_type(type), + m_remainingTokens(remainingTokens) {} -namespace Catch { + auto type() const -> ParseResultType { return m_type; } + + auto remainingTokens() const -> TokenStream { return m_remainingTokens; } - class StartupExceptionRegistry { - public: - void add(std::exception_ptr const& exception) noexcept; - std::vector<std::exception_ptr> const& getExceptions() const noexcept; private: - std::vector<std::exception_ptr> m_exceptions; + ParseResultType m_type; + TokenStream m_remainingTokens; }; -} // end namespace Catch + using Result = BasicResult<void>; + using ParserResult = BasicResult<ParseResultType>; + using InternalParseResult = BasicResult<ParseState>; + + struct HelpColumns { + std::string left; + std::string right; + }; + + template<typename T> + inline auto convertInto(std::string const &source, T& target) -> ParserResult { + std::stringstream ss; + ss << source; + ss >> target; + if (ss.fail()) + return ParserResult::runtimeError("Unable to convert '" + source + "' to destination type"); + else + return ParserResult::ok(ParseResultType::Matched); + } + inline auto convertInto(std::string const &source, std::string& target) -> ParserResult { + target = source; + return ParserResult::ok(ParseResultType::Matched); + } + inline auto convertInto(std::string const &source, bool &target) -> ParserResult { + std::string srcLC = source; + std::transform(srcLC.begin(), srcLC.end(), srcLC.begin(), [](char c) { return static_cast<char>( ::tolower(c) ); } ); + if (srcLC == "y" || srcLC == "1" || srcLC == "true" || srcLC == "yes" || srcLC == "on") + target = true; + else if (srcLC == "n" || srcLC == "0" || srcLC == "false" || srcLC == "no" || srcLC == "off") + target = false; + else + return ParserResult::runtimeError("Expected a boolean value but did not recognise: '" + source + "'"); + return ParserResult::ok(ParseResultType::Matched); + } + + struct BoundRefBase { + BoundRefBase() = default; -// end catch_startup_exception_registry.h -// start catch_text.h + BoundRefBase(BoundRefBase const &) = delete; -namespace Catch { - using namespace clara::TextFlow; -} + BoundRefBase(BoundRefBase &&) = delete; -// end catch_text.h -#include <fstream> -#include <cstdlib> -#include <limits> -#include <iomanip> + BoundRefBase &operator=(BoundRefBase const &) = delete; -namespace Catch { + BoundRefBase &operator=(BoundRefBase &&) = delete; - IStreamingReporterPtr createReporter( std::string const& reporterName, IConfigPtr const& config ) { - auto reporter = getRegistryHub().getReporterRegistry().create( reporterName, config ); - CATCH_ENFORCE( reporter, "No reporter registered with name: '" << reporterName << "'" ); + virtual ~BoundRefBase() = default; - return reporter; - } + virtual auto isFlag() const -> bool = 0; -#ifndef CATCH_CONFIG_DEFAULT_REPORTER -#define CATCH_CONFIG_DEFAULT_REPORTER "console" -#endif + virtual auto isContainer() const -> bool { return false; } - IStreamingReporterPtr makeReporter( std::shared_ptr<Config> const& config ) { - auto const& reporterNames = config->getReporterNames(); - if( reporterNames.empty() ) - return createReporter(CATCH_CONFIG_DEFAULT_REPORTER, config ); + virtual auto setValue(std::string const &arg) -> ParserResult = 0; - IStreamingReporterPtr reporter; - for( auto const& name : reporterNames ) - addReporter( reporter, createReporter( name, config ) ); - return reporter; - } - void addListeners( IStreamingReporterPtr& reporters, IConfigPtr const& config ) { - auto const& listeners = getRegistryHub().getReporterRegistry().getListeners(); - for( auto const& listener : listeners ) - addReporter(reporters, listener->create( ReporterConfig( config ) ) ); - } + virtual auto setFlag(bool flag) -> ParserResult = 0; + }; - Totals runTests( std::shared_ptr<Config> const& config ) { + struct BoundValueRefBase : BoundRefBase { + auto isFlag() const -> bool override { return false; } - IStreamingReporterPtr reporter = makeReporter( config ); - addListeners( reporter, config ); + auto setFlag(bool) -> ParserResult override { + return ParserResult::logicError("Flags can only be set on boolean fields"); + } + }; - RunContext context( config, std::move( reporter ) ); + struct BoundFlagRefBase : BoundRefBase { + auto isFlag() const -> bool override { return true; } - Totals totals; + auto setValue(std::string const &arg) -> ParserResult override { + bool flag; + auto result = convertInto(arg, flag); + if (result) + setFlag(flag); + return result; + } + }; - context.testGroupStarting( config->name(), 1, 1 ); + template<typename T> + struct BoundRef : BoundValueRefBase { + T &m_ref; - TestSpec testSpec = config->testSpec(); - if( !testSpec.hasFilters() ) - testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests + explicit BoundRef(T &ref) : m_ref(ref) {} - std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *config ); - for( auto const& testCase : allTestCases ) { - if( !context.aborting() && matchTest( testCase, testSpec, *config ) ) - totals += context.runTest( testCase ); - else - context.reporter().skipTest( testCase ); + auto setValue(std::string const &arg) -> ParserResult override { + return convertInto(arg, m_ref); } + }; - context.testGroupEnded( config->name(), totals, 1, 1 ); - return totals; - } - - void applyFilenamesAsTags( IConfig const& config ) { - auto& tests = const_cast<std::vector<TestCase>&>( getAllTestCasesSorted( config ) ); - for( auto& testCase : tests ) { - auto tags = testCase.tags; + template<typename T> + struct BoundRef<std::vector<T>> : BoundValueRefBase { + std::vector<T> &m_ref; - std::string filename = testCase.lineInfo.file; - std::string::size_type lastSlash = filename.find_last_of( "\\/" ); - if( lastSlash != std::string::npos ) - filename = filename.substr( lastSlash+1 ); + explicit BoundRef(std::vector<T> &ref) : m_ref(ref) {} - std::string::size_type lastDot = filename.find_last_of( '.' ); - if( lastDot != std::string::npos ) - filename = filename.substr( 0, lastDot ); + auto isContainer() const -> bool override { return true; } - tags.push_back( '#' + filename ); - setTags( testCase, tags ); + auto setValue(std::string const &arg) -> ParserResult override { + T temp; + auto result = convertInto(arg, temp); + if (result) + m_ref.push_back(temp); + return result; } - } + }; - class Session : NonCopyable { - static const int MaxExitCode; - public: + struct BoundFlagRef : BoundFlagRefBase { + bool &m_ref; - Session() { - static bool alreadyInstantiated = false; - if( alreadyInstantiated ) - CATCH_INTERNAL_ERROR( "Only one instance of Catch::Session can ever be used" ); - alreadyInstantiated = true; - m_cli = makeCommandLineParser( m_configData ); - } - ~Session() override { - Catch::cleanUp(); - } + explicit BoundFlagRef(bool &ref) : m_ref(ref) {} - void showHelp() const { - Catch::cout() - << "\nCatch v" << libraryVersion() << "\n" - << m_cli << std::endl - << "For more detailed usage please see the project docs\n" << std::endl; - } - void libIdentify() { - Catch::cout() - << std::left << std::setw(16) << "description: " << "A Catch test executable\n" - << std::left << std::setw(16) << "category: " << "testframework\n" - << std::left << std::setw(16) << "framework: " << "Catch Test\n" - << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl; - } - - int applyCommandLine( int argc, char* argv[] ) { - auto result = m_cli.parse( clara::Args( argc, argv ) ); - if( !result ) { - Catch::cerr() - << Colour( Colour::Red ) - << "\nError(s) in input:\n" - << Column( result.errorMessage() ).indent( 2 ) - << "\n\n"; - Catch::cerr() << "Run with -? for usage\n" << std::endl; - return MaxExitCode; - } - - if( m_configData.showHelp ) - showHelp(); - if( m_configData.libIdentify ) - libIdentify(); - m_config.reset(); - return 0; + auto setFlag(bool flag) -> ParserResult override { + m_ref = flag; + return ParserResult::ok(ParseResultType::Matched); } + }; - void useConfigData( ConfigData const& configData ) { - m_configData = configData; - m_config.reset(); - } + template<typename ReturnType> + struct LambdaInvoker { + static_assert(std::is_same<ReturnType, ParserResult>::value, "Lambda must return void or clara::ParserResult"); - int run( int argc, char* argv[] ) { - const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions(); - if ( !exceptions.empty() ) { - Catch::cerr() << "Errors occured during startup!" << '\n'; - // iterate over all exceptions and notify user - for ( const auto& ex_ptr : exceptions ) { - try { - std::rethrow_exception(ex_ptr); - } catch ( std::exception const& ex ) { - Catch::cerr() << ex.what() << '\n'; - } - } - return 1; - } - int returnCode = applyCommandLine( argc, argv ); - if( returnCode == 0 ) - returnCode = run(); - return returnCode; + template<typename L, typename ArgType> + static auto invoke(L const &lambda, ArgType const &arg) -> ParserResult { + return lambda(arg); } + }; - #if defined(WIN32) && defined(UNICODE) - int run( int argc, wchar_t* const argv[] ) { - - char **utf8Argv = new char *[ argc ]; + template<> + struct LambdaInvoker<void> { + template<typename L, typename ArgType> + static auto invoke(L const &lambda, ArgType const &arg) -> ParserResult { + lambda(arg); + return ParserResult::ok(ParseResultType::Matched); + } + }; - for ( int i = 0; i < argc; ++i ) { - int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, NULL, 0, NULL, NULL ); + template<typename ArgType, typename L> + inline auto invokeLambda(L const &lambda, std::string const &arg) -> ParserResult { + ArgType temp; + auto result = convertInto(arg, temp); + return !result + ? result + : LambdaInvoker<typename UnaryLambdaTraits<L>::ReturnType>::invoke(lambda, temp); + }; - utf8Argv[ i ] = new char[ bufSize ]; + template<typename L> + struct BoundLambda : BoundValueRefBase { + L m_lambda; - WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, NULL, NULL ); - } + static_assert( UnaryLambdaTraits<L>::isValid, "Supplied lambda must take exactly one argument" ); + explicit BoundLambda(L const &lambda) : m_lambda(lambda) {} - int returnCode = run( argc, utf8Argv ); + auto setValue(std::string const &arg) -> ParserResult override { + return invokeLambda<typename UnaryLambdaTraits<L>::ArgType>(m_lambda, arg); + } + }; - for ( int i = 0; i < argc; ++i ) - delete [] utf8Argv[ i ]; + template<typename L> + struct BoundFlagLambda : BoundFlagRefBase { + L m_lambda; - delete [] utf8Argv; + static_assert( UnaryLambdaTraits<L>::isValid, "Supplied lambda must take exactly one argument" ); + static_assert( std::is_same<typename UnaryLambdaTraits<L>::ArgType, bool>::value, "flags must be boolean" ); - return returnCode; - } - #endif - int run() { - if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) { - Catch::cout() << "...waiting for enter/ return before starting" << std::endl; - static_cast<void>(std::getchar()); - } - int exitCode = runInternal(); - if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) { - Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl; - static_cast<void>(std::getchar()); - } - return exitCode; - } + explicit BoundFlagLambda(L const &lambda) : m_lambda(lambda) {} - clara::Parser const& cli() const { - return m_cli; - } - void cli( clara::Parser const& newParser ) { - m_cli = newParser; - } - ConfigData& configData() { - return m_configData; - } - Config& config() { - if( !m_config ) - m_config = std::make_shared<Config>( m_configData ); - return *m_config; + auto setFlag(bool flag) -> ParserResult override { + return LambdaInvoker<typename UnaryLambdaTraits<L>::ReturnType>::invoke(m_lambda, flag); } - private: - int runInternal() { - if( m_configData.showHelp || m_configData.libIdentify ) - return 0; - - try - { - config(); // Force config to be constructed + }; - seedRng( *m_config ); + enum class Optionality { + Optional, Required + }; - if( m_configData.filenamesAsTags ) - applyFilenamesAsTags( *m_config ); + struct Parser; - // Handle list request - if( Option<std::size_t> listed = list( config() ) ) - return static_cast<int>( *listed ); + class ParserBase { + public: + virtual ~ParserBase() = default; + virtual auto validate() const -> Result { return Result::ok(); } + virtual auto parse( std::string const& exeName, TokenStream const &tokens) const -> InternalParseResult = 0; + virtual auto cardinality() const -> size_t { return 1; } - return (std::min)( MaxExitCode, static_cast<int>( runTests( m_config ).assertions.failed ) ); - } - catch( std::exception& ex ) { - Catch::cerr() << ex.what() << std::endl; - return MaxExitCode; - } + auto parse(Args const &args) const -> InternalParseResult { + return parse( args.exeName(), TokenStream(args)); } - - clara::Parser m_cli; - ConfigData m_configData; - std::shared_ptr<Config> m_config; }; - const int Session::MaxExitCode = 255; + template<typename DerivedT> + class ComposableParserImpl : public ParserBase { + public: + template<typename T> + auto operator+(T const &other) const -> Parser; + }; -} // end namespace Catch + // Common code and state for Args and Opts + template<typename DerivedT> + class ParserRefImpl : public ComposableParserImpl<DerivedT> { + protected: + Optionality m_optionality = Optionality::Optional; + std::shared_ptr<BoundRefBase> m_ref; + std::string m_hint; + std::string m_description; -// end catch_session.hpp -// Cpp files will be included in the single-header file here -// start catch_approx.cpp + explicit ParserRefImpl(std::shared_ptr<BoundRefBase> const &ref) : m_ref(ref) {} -#include <limits> + public: + template<typename T> + ParserRefImpl(T &ref, std::string const &hint) : m_ref(std::make_shared<BoundRef<T>>(ref)), m_hint(hint) {} -namespace Catch { -namespace Detail { + template<typename LambdaT> + ParserRefImpl(LambdaT const &ref, std::string const &hint) : m_ref(std::make_shared<BoundLambda<LambdaT>>(ref)), + m_hint(hint) {} - double max(double lhs, double rhs) { - if (lhs < rhs) { - return rhs; + auto operator()(std::string const &description) -> DerivedT & { + m_description = description; + return static_cast<DerivedT &>( *this ); } - return lhs; - } - Approx::Approx ( double value ) - : m_epsilon( std::numeric_limits<float>::epsilon()*100 ), - m_margin( 0.0 ), - m_scale( 1.0 ), - m_value( value ) - {} + auto optional() -> DerivedT & { + m_optionality = Optionality::Optional; + return static_cast<DerivedT &>( *this ); + }; - Approx Approx::custom() { - return Approx( 0 ); - } + auto required() -> DerivedT & { + m_optionality = Optionality::Required; + return static_cast<DerivedT &>( *this ); + }; - std::string Approx::toString() const { - std::ostringstream oss; - oss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )"; - return oss.str(); - } + auto isOptional() const -> bool { + return m_optionality == Optionality::Optional; + } -} // end namespace Detail + auto cardinality() const -> size_t override { + if (m_ref->isContainer()) + return 0; + else + return 1; + } -std::string StringMaker<Catch::Detail::Approx>::convert(Catch::Detail::Approx const& value) { - return value.toString(); -} + auto hint() const -> std::string { return m_hint; } + }; -} // end namespace Catch -// end catch_approx.cpp -// start catch_assertionhandler.cpp + class ExeName : public ComposableParserImpl<ExeName> { + std::shared_ptr<std::string> m_name; + std::shared_ptr<BoundRefBase> m_ref; -// start catch_context.h + template<typename LambdaT> + static auto makeRef(LambdaT const &lambda) -> std::shared_ptr<BoundRefBase> { + return std::make_shared<BoundLambda<LambdaT>>(lambda); + } + + public: + ExeName() : m_name(std::make_shared<std::string>("<executable>")) {} -#include <memory> + explicit ExeName(std::string &ref) : ExeName() { + m_ref = std::make_shared<BoundRef<std::string>>( ref ); + } -namespace Catch { + template<typename LambdaT> + explicit ExeName( LambdaT const& lambda ) : ExeName() { + m_ref = std::make_shared<BoundLambda<LambdaT>>( lambda ); + } - class TestCase; - class Stream; - struct IResultCapture; - struct IRunner; - struct IConfig; + // The exe name is not parsed out of the normal tokens, but is handled specially + auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { + return InternalParseResult::ok(ParseState(ParseResultType::NoMatch, tokens)); + } - using IConfigPtr = std::shared_ptr<IConfig const>; + auto name() const -> std::string { return *m_name; } + auto set( std::string const& newName ) -> ParserResult { - struct IContext - { - virtual ~IContext() = default; + auto lastSlash = newName.find_last_of( "\\/" ); + auto filename = (lastSlash == std::string::npos) + ? newName + : newName.substr( lastSlash+1 ); - virtual IResultCapture* getResultCapture() = 0; - virtual IRunner* getRunner() = 0; - virtual IConfigPtr getConfig() const = 0; + *m_name = filename; + if( m_ref ) + return m_ref->setValue( filename ); + else + return ParserResult::ok( ParseResultType::Matched ); + } }; - struct IMutableContext : IContext - { - virtual ~IMutableContext() = default; - virtual void setResultCapture( IResultCapture* resultCapture ) = 0; - virtual void setRunner( IRunner* runner ) = 0; - virtual void setConfig( IConfigPtr const& config ) = 0; - }; + class Arg : public ParserRefImpl<Arg> { + public: + using ParserRefImpl::ParserRefImpl; - IContext& getCurrentContext(); - IMutableContext& getCurrentMutableContext(); - void cleanUpContext(); -} + auto parse(std::string const &, TokenStream const &tokens) const -> InternalParseResult override { + auto validationResult = validate(); + if (!validationResult) + return InternalParseResult(validationResult); -// end catch_context.h -#include <cassert> + auto remainingTokens = tokens; + auto const &token = *remainingTokens; + if (token.type != TokenType::Argument) + return InternalParseResult::ok(ParseState(ParseResultType::NoMatch, remainingTokens)); -namespace Catch { + auto result = m_ref->setValue(remainingTokens->token); + if (!result) + return InternalParseResult(result); + else + return InternalParseResult::ok(ParseState(ParseResultType::Matched, ++remainingTokens)); + } + }; - auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& { - expr.streamReconstructedExpression( os ); - return os; + inline auto normaliseOpt(std::string const &optName) -> std::string { + if (optName[0] == '/') + return "-" + optName.substr(1); + else + return optName; } - LazyExpression::LazyExpression( bool isNegated ) - : m_isNegated( isNegated ) - {} + class Opt : public ParserRefImpl<Opt> { + protected: + std::vector<std::string> m_optNames; - LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {} + public: + template<typename LambdaT> + explicit Opt( LambdaT const &ref ) : ParserRefImpl(std::make_shared<BoundFlagLambda<LambdaT>>(ref)) {} - LazyExpression::operator bool() const { - return m_transientExpression != nullptr; - } + explicit Opt( bool &ref ) : ParserRefImpl(std::make_shared<BoundFlagRef>(ref)) {} - auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& { - if( lazyExpr.m_isNegated ) - os << "!"; + template<typename LambdaT> + Opt( LambdaT const &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} - if( lazyExpr ) { - if( lazyExpr.m_isNegated && lazyExpr.m_transientExpression->isBinaryExpression() ) - os << "(" << *lazyExpr.m_transientExpression << ")"; - else - os << *lazyExpr.m_transientExpression; + template<typename T> + Opt( T &ref, std::string const &hint ) : ParserRefImpl( ref, hint ) {} + + auto operator[](std::string const &optName) -> Opt & { + m_optNames.push_back(optName); + return *this; } - else { - os << "{** error - unchecked empty expression requested **}"; + + auto getHelpColumns() const -> std::vector<HelpColumns> { + std::ostringstream oss; + bool first = true; + for (auto const &opt : m_optNames) { + if (first) + first = false; + else + oss << ", "; + oss << opt; + } + if (!m_hint.empty()) + oss << " <" << m_hint << ">"; + return {{oss.str(), m_description}}; } - return os; - } - AssertionHandler::AssertionHandler - ( StringRef macroName, - SourceLineInfo const& lineInfo, - StringRef capturedExpression, - ResultDisposition::Flags resultDisposition ) - : m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition } - { - getCurrentContext().getResultCapture()->assertionStarting( m_assertionInfo ); - } - AssertionHandler::~AssertionHandler() { - if ( m_inExceptionGuard ) { - handle( ResultWas::ThrewException, "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE" ); - getCurrentContext().getResultCapture()->exceptionEarlyReported(); + auto isMatch(std::string const &optToken) const -> bool { +#ifdef CLARA_PLATFORM_WINDOWS + auto normalisedToken = normaliseOpt( optToken ); +#else + auto const &normalisedToken = optToken; +#endif + for (auto const &name : m_optNames) { + if (normaliseOpt(name) == normalisedToken) + return true; + } + return false; } - } - void AssertionHandler::handle( ITransientExpression const& expr ) { + using ParserBase::parse; - bool negated = isFalseTest( m_assertionInfo.resultDisposition ); - bool result = expr.getResult() != negated; + auto parse( std::string const&, TokenStream const &tokens ) const -> InternalParseResult override { + auto validationResult = validate(); + if (!validationResult) + return InternalParseResult(validationResult); - handle( result ? ResultWas::Ok : ResultWas::ExpressionFailed, &expr, negated ); - } - void AssertionHandler::handle( ResultWas::OfType resultType ) { - handle( resultType, nullptr, false ); - } - void AssertionHandler::handle( ResultWas::OfType resultType, StringRef const& message ) { - AssertionResultData data( resultType, LazyExpression( false ) ); - data.message = message; - handle( data, nullptr ); - } - void AssertionHandler::handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated ) { - AssertionResultData data( resultType, LazyExpression( negated ) ); - handle( data, expr ); - } - void AssertionHandler::handle( AssertionResultData const& resultData, ITransientExpression const* expr ) { + auto remainingTokens = tokens; + if (remainingTokens && remainingTokens->type == TokenType::Option) { + auto const &token = *remainingTokens; + if (isMatch(token.token)) { + if (m_ref->isFlag()) { + auto result = m_ref->setFlag(true); + if (!result) + return InternalParseResult(result); + if (result.value() == ParseResultType::ShortCircuitAll) + return InternalParseResult::ok(ParseState(result.value(), remainingTokens)); + } else { + ++remainingTokens; + if (!remainingTokens) + return InternalParseResult::runtimeError("Expected argument following " + token.token); + auto const &argToken = *remainingTokens; + if (argToken.type != TokenType::Argument) + return InternalParseResult::runtimeError("Expected argument following " + token.token); + auto result = m_ref->setValue(argToken.token); + if (!result) + return InternalParseResult(result); + if (result.value() == ParseResultType::ShortCircuitAll) + return InternalParseResult::ok(ParseState(result.value(), remainingTokens)); + } + return InternalParseResult::ok(ParseState(ParseResultType::Matched, ++remainingTokens)); + } + } + return InternalParseResult::ok(ParseState(ParseResultType::NoMatch, remainingTokens)); + } - getResultCapture().assertionRun(); + auto validate() const -> Result override { + if (m_optNames.empty()) + return Result::logicError("No options supplied to Opt"); + for (auto const &name : m_optNames) { + if (name.empty()) + return Result::logicError("Option name cannot be empty"); + if (name[0] != '-' && name[0] != '/') + return Result::logicError("Option name must begin with '-' or '/'"); + } + return ParserRefImpl::validate(); + } + }; - AssertionResult assertionResult{ m_assertionInfo, resultData }; - assertionResult.m_resultData.lazyExpression.m_transientExpression = expr; + struct Help : Opt { + Help( bool &showHelpFlag ) + : Opt([&]( bool flag ) { + showHelpFlag = flag; + return ParserResult::ok(ParseResultType::ShortCircuitAll); + }) + { + static_cast<Opt &>(*this) + ("display usage information") + ["-?"]["-h"]["--help"] + .optional(); + } + }; - getResultCapture().assertionEnded( assertionResult ); + struct Parser : ParserBase { - if( !assertionResult.isOk() ) { - m_shouldDebugBreak = getCurrentContext().getConfig()->shouldDebugBreak(); - m_shouldThrow = - getCurrentContext().getRunner()->aborting() || - (m_assertionInfo.resultDisposition & ResultDisposition::Normal); - } - } + mutable ExeName m_exeName; + std::vector<Opt> m_options; + std::vector<Arg> m_args; - auto AssertionHandler::allowThrows() const -> bool { - return getCurrentContext().getConfig()->allowThrows(); - } + auto operator+=(ExeName const &exeName) -> Parser & { + m_exeName = exeName; + return *this; + } - auto AssertionHandler::shouldDebugBreak() const -> bool { - return m_shouldDebugBreak; - } - void AssertionHandler::reactWithDebugBreak() const { - if (m_shouldDebugBreak) { - /////////////////////////////////////////////////////////////////// - // To inspect the state during test, you need to go one level up the callstack - // To go back to the test and change execution, jump over the reactWithoutDebugBreak() call - /////////////////////////////////////////////////////////////////// - CATCH_BREAK_INTO_DEBUGGER(); + auto operator+=(Arg const &arg) -> Parser & { + m_args.push_back(arg); + return *this; } - reactWithoutDebugBreak(); - } - void AssertionHandler::reactWithoutDebugBreak() const { - if( m_shouldThrow ) - throw Catch::TestFailureException(); - } - void AssertionHandler::useActiveException() { - handle( ResultWas::ThrewException, Catch::translateActiveException() ); - } + auto operator+=(Opt const &opt) -> Parser & { + m_options.push_back(opt); + return *this; + } - void AssertionHandler::setExceptionGuard() { - assert( m_inExceptionGuard == false ); - m_inExceptionGuard = true; - } - void AssertionHandler::unsetExceptionGuard() { - assert( m_inExceptionGuard == true ); - m_inExceptionGuard = false; - } + auto operator+=(Parser const &other) -> Parser & { + m_options.insert(m_options.end(), other.m_options.begin(), other.m_options.end()); + m_args.insert(m_args.end(), other.m_args.begin(), other.m_args.end()); + return *this; + } - // This is the overload that takes a string and infers the Equals matcher from it - // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp - void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ) { - handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString ); - } + template<typename T> + auto operator+(T const &other) const -> Parser { + return Parser(*this) += other; + } -} // namespace Catch -// end catch_assertionhandler.cpp -// start catch_assertionresult.cpp + auto getHelpColumns() const -> std::vector<HelpColumns> { + std::vector<HelpColumns> cols; + for (auto const &o : m_options) { + auto childCols = o.getHelpColumns(); + cols.insert(cols.end(), childCols.begin(), childCols.end()); + } + return cols; + } -namespace Catch { - AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression): - resultType(_resultType), - lazyExpression(_lazyExpression) {} + void writeToStream(std::ostream &os) const { + if (!m_exeName.name().empty()) { + os << "usage:\n" << " " << m_exeName.name() << " "; + bool required = true, first = true; + for (auto const &arg : m_args) { + if (first) + first = false; + else + os << " "; + if (arg.isOptional() && required) { + os << "["; + required = false; + } + os << "<" << arg.hint() << ">"; + if (arg.cardinality() == 0) + os << " ... "; + } + if (!required) + os << "]"; + if (!m_options.empty()) + os << " options"; + os << "\n\nwhere options are:" << std::endl; + } - std::string AssertionResultData::reconstructExpression() const { + auto rows = getHelpColumns(); + size_t consoleWidth = CATCH_CLARA_CONFIG_CONSOLE_WIDTH; + size_t optWidth = 0; + for (auto const &cols : rows) + optWidth = std::max(optWidth, cols.left.size() + 2); - if( reconstructedExpression.empty() ) { - if( lazyExpression ) { - // !TBD Use stringstream for now, but rework above to pass stream in - std::ostringstream oss; - oss << lazyExpression; - reconstructedExpression = oss.str(); + for (auto const &cols : rows) { + auto row = + TextFlow::Column(cols.left).width(optWidth).indent(2) + + TextFlow::Spacer(4) + + TextFlow::Column(cols.right).width(consoleWidth - 7 - optWidth); + os << row << std::endl; } } - return reconstructedExpression; - } - AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) - : m_info( info ), - m_resultData( data ) - {} + friend auto operator<<(std::ostream &os, Parser const &parser) -> std::ostream & { + parser.writeToStream(os); + return os; + } - // Result was a success - bool AssertionResult::succeeded() const { - return Catch::isOk( m_resultData.resultType ); - } + auto validate() const -> Result override { + for (auto const &opt : m_options) { + auto result = opt.validate(); + if (!result) + return result; + } + for (auto const &arg : m_args) { + auto result = arg.validate(); + if (!result) + return result; + } + return Result::ok(); + } - // Result was a success, or failure is suppressed - bool AssertionResult::isOk() const { - return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition ); - } + using ParserBase::parse; - ResultWas::OfType AssertionResult::getResultType() const { - return m_resultData.resultType; - } + auto parse( std::string const& exeName, TokenStream const &tokens) const -> InternalParseResult override { + std::vector<ParserBase const *> allParsers; + allParsers.reserve(m_args.size() + m_options.size()); + std::set<ParserBase const *> requiredParsers; - bool AssertionResult::hasExpression() const { - return m_info.capturedExpression[0] != 0; - } + for (auto const &opt : m_options) { + allParsers.push_back(&opt); + if (!opt.isOptional()) + requiredParsers.insert(&opt); + } - bool AssertionResult::hasMessage() const { - return !m_resultData.message.empty(); - } + size_t optionalArgs = 0; + for (auto const &arg : m_args) { + allParsers.push_back(&arg); + if (!arg.isOptional()) { + if (optionalArgs > 0) + return InternalParseResult::logicError( + "Required arguments must preceed any optional arguments"); + else + ++optionalArgs; + requiredParsers.insert(&arg); + } + } - std::string AssertionResult::getExpression() const { - if (isFalseTest(m_info.resultDisposition)) - return '!' + std::string(m_info.capturedExpression); - else - return m_info.capturedExpression; - } + m_exeName.set( exeName ); - std::string AssertionResult::getExpressionInMacro() const { - std::string expr; - if( m_info.macroName[0] == 0 ) - expr = m_info.capturedExpression; - else { - expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 ); - expr += m_info.macroName; - expr += "( "; - expr += m_info.capturedExpression; - expr += " )"; + auto result = InternalParseResult::ok(ParseState(ParseResultType::NoMatch, tokens)); + while (result.value().remainingTokens()) { + auto remainingTokenCount = result.value().remainingTokens().count(); + for (auto parser : allParsers) { + result = parser->parse( exeName, result.value().remainingTokens() ); + if (!result || result.value().type() != ParseResultType::NoMatch) { + if (parser->cardinality() == 1) + allParsers.erase(std::remove(allParsers.begin(), allParsers.end(), parser), + allParsers.end()); + requiredParsers.erase(parser); + break; + } + } + if (!result || remainingTokenCount == result.value().remainingTokens().count()) + return result; + } + // !TBD Check missing required options + return result; } - return expr; - } + }; - bool AssertionResult::hasExpandedExpression() const { - return hasExpression() && getExpandedExpression() != getExpression(); + template<typename DerivedT> + template<typename T> + auto ComposableParserImpl<DerivedT>::operator+(T const &other) const -> Parser { + return Parser() + static_cast<DerivedT const &>( *this ) + other; } +} // namespace detail - std::string AssertionResult::getExpandedExpression() const { - std::string expr = m_resultData.reconstructExpression(); - return expr.empty() - ? getExpression() - : expr; - } +// A Combined parser +using detail::Parser; - std::string AssertionResult::getMessage() const { - return m_resultData.message; - } - SourceLineInfo AssertionResult::getSourceInfo() const { - return m_info.lineInfo; - } +// A parser for options +using detail::Opt; - std::string AssertionResult::getTestMacroName() const { - return m_info.macroName; - } +// A parser for arguments +using detail::Arg; -} // end namespace Catch -// end catch_assertionresult.cpp -// start catch_benchmark.cpp +// Wrapper for argc, argv from main() +using detail::Args; -namespace Catch { +// Specifies the name of the executable +using detail::ExeName; - auto BenchmarkLooper::getResolution() -> uint64_t { - return getEstimatedClockResolution() * getCurrentContext().getConfig()->benchmarkResolutionMultiple(); - } +// Convenience wrapper for option parser that specifies the help option +using detail::Help; - void BenchmarkLooper::reportStart() { - getResultCapture().benchmarkStarting( { m_name } ); - } - auto BenchmarkLooper::needsMoreIterations() -> bool { - auto elapsed = m_timer.getElapsedNanoseconds(); +// enum of result types from a parse +using detail::ParseResultType; - // Exponentially increasing iterations until we're confident in our timer resolution - if( elapsed < m_resolution ) { - m_iterationsToRun *= 10; - return true; - } +// Result type for parser operation +using detail::ParserResult; - getResultCapture().benchmarkEnded( { { m_name }, m_count, elapsed } ); - return false; - } +}} // namespace Catch::clara -} // end namespace Catch -// end catch_benchmark.cpp -// start catch_capture_matchers.cpp +// end clara.hpp +#ifdef __clang__ +#pragma clang diagnostic pop +#endif -namespace Catch { +// Restore Clara's value for console width, if present +#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH +#endif - using StringMatcher = Matchers::Impl::MatcherBase<std::string>; +// end catch_clara.h +namespace Catch { - // This is the general overload that takes a any string matcher - // There is another overload, in catch_assertinhandler.h/.cpp, that only takes a string and infers - // the Equals matcher (so the header does not mention matchers) - void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ) { - std::string exceptionMessage = Catch::translateActiveException(); - MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString ); - handler.handle( expr ); - } + clara::Parser makeCommandLineParser( ConfigData& config ); -} // namespace Catch -// end catch_capture_matchers.cpp -// start catch_commandline.cpp +} // end namespace Catch +// end catch_commandline.h #include <fstream> #include <ctime> @@ -6207,14 +5622,6 @@ namespace Catch { return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0)); } - void seedRng( IConfig const& config ) { - if( config.rngSeed() != 0 ) - std::srand( config.rngSeed() ); - } - unsigned int rngSeed() { - return getCurrentContext().getConfig()->rngSeed(); - } - std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { #ifndef __GNUG__ os << info.file << '(' << info.line << ')'; @@ -6232,6 +5639,9 @@ namespace Catch { return std::string(); } + NonCopyable::NonCopyable() = default; + NonCopyable::~NonCopyable() = default; + } // end catch_common.cpp // start catch_config.cpp @@ -6301,6 +5711,11 @@ namespace Catch { // end catch_config.cpp // start catch_console_colour.cpp +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +#endif + // start catch_errno_guard.h namespace Catch { @@ -6346,6 +5761,34 @@ namespace Catch { #if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) ///////////////////////////////////////// +// start catch_windows_h_proxy.h + + +#if defined(CATCH_PLATFORM_WINDOWS) +# if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX) +# define CATCH_DEFINED_NOMINMAX +# define NOMINMAX +# endif +# if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN) +# define CATCH_DEFINED_WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +#endif + +#ifdef __AFXDLL +#include <AfxWin.h> +#else +#include <windows.h> +#endif + +#ifdef CATCH_DEFINED_NOMINMAX +# undef NOMINMAX +#endif +#ifdef CATCH_DEFINED_WIN32_LEAN_AND_MEAN +# undef WIN32_LEAN_AND_MEAN +#endif + +// end catch_windows_h_proxy.h namespace Catch { namespace { @@ -6448,6 +5891,13 @@ namespace { } }; + bool useColourOnPlatform() { + return +#ifdef CATCH_PLATFORM_MAC + !isDebuggerActive() && +#endif + isatty(STDOUT_FILENO); + } IColourImpl* platformColourInstance() { ErrnoGuard guard; IConfigPtr config = getCurrentContext().getConfig(); @@ -6455,7 +5905,7 @@ namespace { ? config->useColour() : UseColour::Auto; if( colourMode == UseColour::Auto ) - colourMode = isatty(STDOUT_FILENO) + colourMode = useColourOnPlatform() ? UseColour::Yes : UseColour::No; return colourMode == UseColour::Yes @@ -6501,6 +5951,11 @@ namespace Catch { } } // end namespace Catch + +#if defined(__clang__) +# pragma clang diagnostic pop +#endif + // end catch_console_colour.cpp // start catch_context.cpp @@ -6520,6 +5975,8 @@ namespace Catch { return m_config; } + virtual ~Context() override; + public: // IMutableContext virtual void setResultCapture( IResultCapture* resultCapture ) override { m_resultCapture = resultCapture; @@ -6555,8 +6012,38 @@ namespace Catch { delete currentContext; currentContext = nullptr; } + IContext::~IContext() = default; + IMutableContext::~IMutableContext() = default; + Context::~Context() = default; } // end catch_context.cpp +// start catch_debug_console.cpp + +// start catch_debug_console.h + +#include <string> + +namespace Catch { + void writeToDebugConsole( std::string const& text ); +} + +// end catch_debug_console.h +#ifdef CATCH_PLATFORM_WINDOWS + + namespace Catch { + void writeToDebugConsole( std::string const& text ) { + ::OutputDebugStringA( text.c_str() ); + } + } +#else + namespace Catch { + void writeToDebugConsole( std::string const& text ) { + // !TBD: Need a version for Mac/ XCode and other IDEs + Catch::cout() << text; + } + } +#endif // Platform +// end catch_debug_console.cpp // start catch_debugger.cpp #ifdef CATCH_PLATFORM_MAC @@ -6567,7 +6054,7 @@ namespace Catch { #include <unistd.h> #include <sys/sysctl.h> - namespace Catch{ + namespace Catch { // The following function is taken directly from the following technical note: // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html @@ -6578,7 +6065,7 @@ namespace Catch { int mib[4]; struct kinfo_proc info; - size_t size; + std::size_t size; // Initialize the flags so that, if sysctl fails for some bizarre // reason, we get a predictable result. @@ -6657,38 +6144,13 @@ namespace Catch { } #endif // Platform // end catch_debugger.cpp -// start catch_debug_console.cpp - -// start catch_debug_console.h - -#include <string> - -namespace Catch { - void writeToDebugConsole( std::string const& text ); -} - -// end catch_debug_console.h -#ifdef CATCH_PLATFORM_WINDOWS - - namespace Catch { - void writeToDebugConsole( std::string const& text ) { - ::OutputDebugStringA( text.c_str() ); - } - } -#else - namespace Catch { - void writeToDebugConsole( std::string const& text ) { - // !TBD: Need a version for Mac/ XCode and other IDEs - Catch::cout() << text; - } - } -#endif // Platform -// end catch_debug_console.cpp // start catch_decomposer.cpp namespace Catch { - void formatReconstructedExpression( std::ostream &os, std::string const& lhs, std::string const& op, std::string const& rhs ) { + ITransientExpression::~ITransientExpression() = default; + + void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ) { if( lhs.size() + rhs.size() < 40 && lhs.find('\n') == std::string::npos && rhs.find('\n') == std::string::npos ) @@ -6751,7 +6213,7 @@ namespace Catch { return tryTranslators(); } @catch (NSException *exception) { - return Catch::toString( [exception description] ); + return Catch::Detail::stringify( [exception description] ); } #else return tryTranslators(); @@ -6784,17 +6246,85 @@ namespace Catch { // end catch_exception_translator_registry.cpp // start catch_fatal_condition.cpp +// start catch_fatal_condition.h + +#include <string> + +#if defined ( CATCH_PLATFORM_WINDOWS ) ///////////////////////////////////////// + +# if !defined ( CATCH_CONFIG_WINDOWS_SEH ) + namespace Catch { + struct FatalConditionHandler { + void reset(); + }; +} - // Report the error condition - void reportFatal( std::string const& message ) { - IContext& context = Catch::getCurrentContext(); - IResultCapture* resultCapture = context.getResultCapture(); - resultCapture->handleFatalErrorCondition( message ); - } +# else // CATCH_CONFIG_WINDOWS_SEH is defined + +namespace Catch { + + struct FatalConditionHandler { + + static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo); + FatalConditionHandler(); + static void reset(); + ~FatalConditionHandler(); + + private: + static bool isSet; + static ULONG guaranteeSize; + static PVOID exceptionHandlerHandle; + }; + +} // namespace Catch + +# endif // CATCH_CONFIG_WINDOWS_SEH + +#else // Not Windows - assumed to be POSIX compatible ////////////////////////// + +# if !defined(CATCH_CONFIG_POSIX_SIGNALS) + +namespace Catch { + struct FatalConditionHandler { + void reset(); + }; +} + +# else // CATCH_CONFIG_POSIX_SIGNALS is defined + +#include <signal.h> + +namespace Catch { + + struct FatalConditionHandler { + + static bool isSet; + static struct sigaction oldSigActions[];// [sizeof(signalDefs) / sizeof(SignalDefs)]; + static stack_t oldSigStack; + static char altStackMem[]; + + static void handleSignal( int sig ); + + FatalConditionHandler(); + ~FatalConditionHandler(); + static void reset(); + }; } // namespace Catch +# endif // CATCH_CONFIG_POSIX_SIGNALS + +#endif // not Windows + +// end catch_fatal_condition.h +namespace { + // Report the error condition + void reportFatal( char const * const message ) { + Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( message ); + } +} + #if defined ( CATCH_PLATFORM_WINDOWS ) ///////////////////////////////////////// # if !defined ( CATCH_CONFIG_WINDOWS_SEH ) @@ -6811,7 +6341,7 @@ namespace Catch { // There is no 1-1 mapping between signals and windows exceptions. // Windows can easily distinguish between SO and SigSegV, // but SigInt, SigTerm, etc are handled differently. - SignalDefs signalDefs[] = { + static SignalDefs signalDefs[] = { { EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal" }, { EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow" }, { EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal" }, @@ -6881,7 +6411,7 @@ namespace Catch { int id; const char* name; }; - SignalDefs signalDefs[] = { + static SignalDefs signalDefs[] = { { SIGINT, "SIGINT - Terminal interrupt signal" }, { SIGILL, "SIGILL - Illegal instruction signal" }, { SIGFPE, "SIGFPE - Floating point error signal" }, @@ -6891,7 +6421,7 @@ namespace Catch { }; void FatalConditionHandler::handleSignal( int sig ) { - std::string name = "<unknown signal>"; + char const * name = "<unknown signal>"; for (auto const& def : signalDefs) { if (sig == def.id) { name = def.name; @@ -6946,6 +6476,32 @@ namespace Catch { #endif // not Windows // end catch_fatal_condition.cpp +// start catch_interfaces_capture.cpp + +namespace Catch { + IResultCapture::~IResultCapture() = default; +} +// end catch_interfaces_capture.cpp +// start catch_interfaces_config.cpp + +namespace Catch { + IConfig::~IConfig() = default; +} +// end catch_interfaces_config.cpp +// start catch_interfaces_exception.cpp + +namespace Catch { + IExceptionTranslator::~IExceptionTranslator() = default; + IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() = default; +} +// end catch_interfaces_exception.cpp +// start catch_interfaces_registry_hub.cpp + +namespace Catch { + IRegistryHub::~IRegistryHub() = default; + IMutableRegistryHub::~IMutableRegistryHub() = default; +} +// end catch_interfaces_registry_hub.cpp // start catch_interfaces_reporter.cpp // start catch_reporter_multi.h @@ -6965,7 +6521,7 @@ namespace Catch { void noMatchingTestCases( std::string const& spec ) override; - static std::set<Verbosity> getSupportedVerbosities(); + static std::set<Verbosity> getSupportedVerbosities(); void testRunStarting( TestRunInfo const& testRunInfo ) override; void testGroupStarting( GroupInfo const& groupInfo ) override; @@ -6986,6 +6542,7 @@ namespace Catch { }; } // end namespace Catch + // end catch_reporter_multi.h namespace Catch { @@ -7028,6 +6585,8 @@ namespace Catch { } } + AssertionStats::~AssertionStats() = default; + SectionStats::SectionStats( SectionInfo const& _sectionInfo, Counts const& _assertions, double _durationInSeconds, @@ -7038,6 +6597,8 @@ namespace Catch { missingAssertions( _missingAssertions ) {} + SectionStats::~SectionStats() = default; + TestCaseStats::TestCaseStats( TestCaseInfo const& _testInfo, Totals const& _totals, std::string const& _stdOut, @@ -7050,6 +6611,8 @@ namespace Catch { aborting( _aborting ) {} + TestCaseStats::~TestCaseStats() = default; + TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo, Totals const& _totals, bool _aborting ) @@ -7063,6 +6626,8 @@ namespace Catch { aborting( false ) {} + TestGroupStats::~TestGroupStats() = default; + TestRunStats::TestRunStats( TestRunInfo const& _runInfo, Totals const& _totals, bool _aborting ) @@ -7071,8 +6636,14 @@ namespace Catch { aborting( _aborting ) {} + TestRunStats::~TestRunStats() = default; + + void IStreamingReporter::fatalErrorEncountered( StringRef ) {} bool IStreamingReporter::isMulti() const { return false; } + IReporterFactory::~IReporterFactory() = default; + IReporterRegistry::~IReporterRegistry() = default; + void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter ) { if( !existingReporter ) { @@ -7096,6 +6667,19 @@ namespace Catch { } // end namespace Catch // end catch_interfaces_reporter.cpp +// start catch_interfaces_runner.cpp + +namespace Catch { + IRunner::~IRunner() = default; +} +// end catch_interfaces_runner.cpp +// start catch_interfaces_testcase.cpp + +namespace Catch { + ITestInvoker::~ITestInvoker() = default; + ITestCaseRegistry::~ITestCaseRegistry() = default; +} +// end catch_interfaces_testcase.cpp // start catch_leak_detector.cpp namespace Catch { @@ -7114,16 +6698,50 @@ namespace Catch { _CrtSetBreakAlloc(-1); } -#else +#else + + LeakDetector::LeakDetector(){} + +#endif + +} +// end catch_leak_detector.cpp +// start catch_list.cpp + +// start catch_list.h + +#include <set> + +namespace Catch { + + std::size_t listTests( Config const& config ); + + std::size_t listTestsNamesOnly( Config const& config ); + + struct TagInfo { + void add( std::string const& spelling ); + std::string all() const; + + std::set<std::string> spellings; + std::size_t count = 0; + }; + + std::size_t listTags( Config const& config ); + + std::size_t listReporters( Config const& /*config*/ ); - LeakDetector::LeakDetector(){} + Option<std::size_t> list( Config const& config ); -#endif +} // end namespace Catch + +// end catch_list.h +// start catch_text.h +namespace Catch { + using namespace clara::TextFlow; } -// end catch_leak_detector.cpp -// start catch_list.cpp +// end catch_text.h #include <limits> #include <algorithm> #include <iomanip> @@ -7280,6 +6898,8 @@ namespace Matchers { return m_cachedToString; } + MatcherUntypedBase::~MatcherUntypedBase() = default; + } // namespace Impl } // namespace Matchers @@ -7417,47 +7037,29 @@ namespace Catch { } // end namespace Catch // end catch_message.cpp -// start catch_notimplemented_exception.cpp - -#include <sstream> - -namespace Catch { - - NotImplementedException::NotImplementedException( SourceLineInfo const& lineInfo ) { - std::ostringstream oss; - oss << lineInfo << ": function "; - oss << "not implemented"; - m_what = oss.str(); - } - - const char* NotImplementedException::what() const noexcept { - return m_what.c_str(); - } +// start catch_random_number_generator.cpp -} // end namespace Catch -// end catch_notimplemented_exception.cpp -// start catch_registry_hub.cpp +// start catch_random_number_generator.h -// start catch_test_case_registry_impl.hpp - -#include <vector> -#include <set> #include <algorithm> -#include <ios> namespace Catch { - class TestCase; struct IConfig; + void seedRng( IConfig const& config ); + + unsigned int rngSeed(); + struct RandomNumberGenerator { using result_type = std::ptrdiff_t; - result_type operator()( result_type n ) const; - static constexpr result_type min() { return 0; } static constexpr result_type max() { return 1000000; } + + result_type operator()( result_type n ) const; result_type operator()() const; + template<typename V> static void shuffle( V& vector ) { RandomNumberGenerator rng; @@ -7465,6 +7067,44 @@ namespace Catch { } }; +} + +// end catch_random_number_generator.h +#include <cstdlib> + +namespace Catch { + + void seedRng( IConfig const& config ) { + if( config.rngSeed() != 0 ) + std::srand( config.rngSeed() ); + } + unsigned int rngSeed() { + return getCurrentContext().getConfig()->rngSeed(); + } + + RandomNumberGenerator::result_type RandomNumberGenerator::operator()( result_type n ) const { + return std::rand() % n; + } + RandomNumberGenerator::result_type RandomNumberGenerator::operator()() const { + return std::rand() % max(); + } + +} +// end catch_random_number_generator.cpp +// start catch_registry_hub.cpp + +// start catch_test_case_registry_impl.h + +#include <vector> +#include <set> +#include <algorithm> +#include <ios> + +namespace Catch { + + class TestCase; + struct IConfig; + std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ); bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); @@ -7486,7 +7126,7 @@ namespace Catch { std::vector<TestCase> m_functions; mutable RunTests::InWhatOrder m_currentSortOrder = RunTests::InDeclarationOrder; mutable std::vector<TestCase> m_sortedFunctions; - size_t m_unnamedCount = 0; + std::size_t m_unnamedCount = 0; std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised }; @@ -7506,8 +7146,8 @@ namespace Catch { } // end namespace Catch -// end catch_test_case_registry_impl.hpp -// start catch_reporter_registry.hpp +// end catch_test_case_registry_impl.h +// start catch_reporter_registry.h #include <map> @@ -7517,28 +7157,15 @@ namespace Catch { public: - ~ReporterRegistry() override {} + ~ReporterRegistry() override; - IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override { - auto it = m_factories.find( name ); - if( it == m_factories.end() ) - return nullptr; - return it->second->create( ReporterConfig( config ) ); - } + IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const override; - void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) { - m_factories.emplace(name, factory); - } - void registerListener( IReporterFactoryPtr const& factory ) { - m_listeners.push_back( factory ); - } + void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ); + void registerListener( IReporterFactoryPtr const& factory ); - FactoryMap const& getFactories() const override { - return m_factories; - } - Listeners const& getListeners() const override { - return m_listeners; - } + FactoryMap const& getFactories() const override; + Listeners const& getListeners() const override; private: FactoryMap m_factories; @@ -7546,7 +7173,7 @@ namespace Catch { }; } -// end catch_reporter_registry.hpp +// end catch_reporter_registry.h // start catch_tag_alias_registry.h // start catch_tag_alias.h @@ -7583,6 +7210,24 @@ namespace Catch { } // end namespace Catch // end catch_tag_alias_registry.h +// start catch_startup_exception_registry.h + +#include <vector> +#include <exception> + +namespace Catch { + + class StartupExceptionRegistry { + public: + void add(std::exception_ptr const& exception) noexcept; + std::vector<std::exception_ptr> const& getExceptions() const noexcept; + private: + std::vector<std::exception_ptr> m_exceptions; + }; + +} // end namespace Catch + +// end catch_startup_exception_registry.h namespace Catch { namespace { @@ -7591,8 +7236,7 @@ namespace Catch { private NonCopyable { public: // IRegistryHub - RegistryHub() { - } + RegistryHub() = default; IReporterRegistry const& getReporterRegistry() const override { return m_reporterRegistry; } @@ -7609,82 +7253,234 @@ namespace Catch { return m_exceptionRegistry; } - public: // IMutableRegistryHub - void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override { - m_reporterRegistry.registerReporter( name, factory ); - } - void registerListener( IReporterFactoryPtr const& factory ) override { - m_reporterRegistry.registerListener( factory ); - } - void registerTest( TestCase const& testInfo ) override { - m_testCaseRegistry.registerTest( testInfo ); - } - void registerTranslator( const IExceptionTranslator* translator ) override { - m_exceptionTranslatorRegistry.registerTranslator( translator ); - } - void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override { - m_tagAliasRegistry.add( alias, tag, lineInfo ); - } - void registerStartupException() noexcept override { - m_exceptionRegistry.add(std::current_exception()); - } + public: // IMutableRegistryHub + void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) override { + m_reporterRegistry.registerReporter( name, factory ); + } + void registerListener( IReporterFactoryPtr const& factory ) override { + m_reporterRegistry.registerListener( factory ); + } + void registerTest( TestCase const& testInfo ) override { + m_testCaseRegistry.registerTest( testInfo ); + } + void registerTranslator( const IExceptionTranslator* translator ) override { + m_exceptionTranslatorRegistry.registerTranslator( translator ); + } + void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) override { + m_tagAliasRegistry.add( alias, tag, lineInfo ); + } + void registerStartupException() noexcept override { + m_exceptionRegistry.add(std::current_exception()); + } + + private: + TestRegistry m_testCaseRegistry; + ReporterRegistry m_reporterRegistry; + ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; + TagAliasRegistry m_tagAliasRegistry; + StartupExceptionRegistry m_exceptionRegistry; + }; + + // Single, global, instance + RegistryHub*& getTheRegistryHub() { + static RegistryHub* theRegistryHub = nullptr; + if( !theRegistryHub ) + theRegistryHub = new RegistryHub(); + return theRegistryHub; + } + } + + IRegistryHub& getRegistryHub() { + return *getTheRegistryHub(); + } + IMutableRegistryHub& getMutableRegistryHub() { + return *getTheRegistryHub(); + } + void cleanUp() { + delete getTheRegistryHub(); + getTheRegistryHub() = nullptr; + cleanUpContext(); + } + std::string translateActiveException() { + return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); + } + +} // end namespace Catch +// end catch_registry_hub.cpp +// start catch_reporter_registry.cpp + +namespace Catch { + + ReporterRegistry::~ReporterRegistry() = default; + + IStreamingReporterPtr ReporterRegistry::create( std::string const& name, IConfigPtr const& config ) const { + auto it = m_factories.find( name ); + if( it == m_factories.end() ) + return nullptr; + return it->second->create( ReporterConfig( config ) ); + } + + void ReporterRegistry::registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) { + m_factories.emplace(name, factory); + } + void ReporterRegistry::registerListener( IReporterFactoryPtr const& factory ) { + m_listeners.push_back( factory ); + } + + IReporterRegistry::FactoryMap const& ReporterRegistry::getFactories() const { + return m_factories; + } + IReporterRegistry::Listeners const& ReporterRegistry::getListeners() const { + return m_listeners; + } + +} +// end catch_reporter_registry.cpp +// start catch_result_type.cpp + +namespace Catch { + + bool isOk( ResultWas::OfType resultType ) { + return ( resultType & ResultWas::FailureBit ) == 0; + } + bool isJustInfo( int flags ) { + return flags == ResultWas::Info; + } + + ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) { + return static_cast<ResultDisposition::Flags>( static_cast<int>( lhs ) | static_cast<int>( rhs ) ); + } + + bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; } + bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; } + bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; } + +} // end namespace Catch +// end catch_result_type.cpp +// start catch_run_context.cpp +// start catch_run_context.h + +#include <string> + +namespace Catch { + + struct IMutableContext; + + class StreamRedirect { + + public: + StreamRedirect(std::ostream& stream, std::string& targetString); + + ~StreamRedirect(); + + private: + std::ostream& m_stream; + std::streambuf* m_prevBuf; + std::ostringstream m_oss; + std::string& m_targetString; + }; + + // StdErr has two constituent streams in C++, std::cerr and std::clog + // This means that we need to redirect 2 streams into 1 to keep proper + // order of writes and cannot use StreamRedirect on its own + class StdErrRedirect { + public: + StdErrRedirect(std::string& targetString); + ~StdErrRedirect(); + private: + std::streambuf* m_cerrBuf; + std::streambuf* m_clogBuf; + std::ostringstream m_oss; + std::string& m_targetString; + }; + + /////////////////////////////////////////////////////////////////////////// + + class RunContext : public IResultCapture, public IRunner { + + public: + RunContext( RunContext const& ) = delete; + RunContext& operator =( RunContext const& ) = delete; + + explicit RunContext(IConfigPtr const& _config, IStreamingReporterPtr&& reporter); + + virtual ~RunContext(); + + void testGroupStarting(std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount); + void testGroupEnded(std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount); + + Totals runTest(TestCase const& testCase); + + IConfigPtr config() const; + IStreamingReporter& reporter() const; + + private: // IResultCapture + + void assertionStarting(AssertionInfo const& info) override; + void assertionEnded(AssertionResult const& result) override; + + bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override; + bool testForMissingAssertions(Counts& assertions); + + void sectionEnded(SectionEndInfo const& endInfo) override; + void sectionEndedEarly(SectionEndInfo const& endInfo) override; + + void benchmarkStarting( BenchmarkInfo const& info ) override; + void benchmarkEnded( BenchmarkStats const& stats ) override; + + void pushScopedMessage(MessageInfo const& message) override; + void popScopedMessage(MessageInfo const& message) override; + + std::string getCurrentTestName() const override; - private: - TestRegistry m_testCaseRegistry; - ReporterRegistry m_reporterRegistry; - ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; - TagAliasRegistry m_tagAliasRegistry; - StartupExceptionRegistry m_exceptionRegistry; - }; + const AssertionResult* getLastResult() const override; - // Single, global, instance - RegistryHub*& getTheRegistryHub() { - static RegistryHub* theRegistryHub = nullptr; - if( !theRegistryHub ) - theRegistryHub = new RegistryHub(); - return theRegistryHub; - } - } + void exceptionEarlyReported() override; - IRegistryHub& getRegistryHub() { - return *getTheRegistryHub(); - } - IMutableRegistryHub& getMutableRegistryHub() { - return *getTheRegistryHub(); - } - void cleanUp() { - delete getTheRegistryHub(); - getTheRegistryHub() = nullptr; - cleanUpContext(); - } - std::string translateActiveException() { - return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); - } + void handleFatalErrorCondition( StringRef message ) override; -} // end namespace Catch -// end catch_registry_hub.cpp -// start catch_result_type.cpp + bool lastAssertionPassed() override; -namespace Catch { + void assertionPassed() override; - bool isOk( ResultWas::OfType resultType ) { - return ( resultType & ResultWas::FailureBit ) == 0; - } - bool isJustInfo( int flags ) { - return flags == ResultWas::Info; - } + void assertionRun() override; - ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) { - return static_cast<ResultDisposition::Flags>( static_cast<int>( lhs ) | static_cast<int>( rhs ) ); - } + public: + // !TBD We need to do this another way! + bool aborting() const override; - bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; } - bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; } - bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; } + private: + + void runCurrentTest(std::string& redirectedCout, std::string& redirectedCerr); + void invokeActiveTestCase(); + + private: + + void handleUnfinishedSections(); + + TestRunInfo m_runInfo; + IMutableContext& m_context; + TestCase const* m_activeTestCase = nullptr; + ITracker* m_testCaseTracker; + Option<AssertionResult> m_lastResult; + + IConfigPtr m_config; + Totals m_totals; + IStreamingReporterPtr m_reporter; + std::vector<MessageInfo> m_messages; + AssertionInfo m_lastAssertionInfo; + std::vector<SectionEndInfo> m_unfinishedSections; + std::vector<ITracker*> m_activeSections; + TrackerContext m_trackerContext; + std::size_t m_prevPassed = 0; + bool m_shouldReportUnexpected = true; + }; + + IResultCapture& getResultCapture(); } // end namespace Catch -// end catch_result_type.cpp -// start catch_run_context.cpp + +// end catch_run_context.h #include <cassert> #include <algorithm> @@ -7889,11 +7685,13 @@ namespace Catch { m_shouldReportUnexpected = false; } - void RunContext::handleFatalErrorCondition(std::string const & message) { + void RunContext::handleFatalErrorCondition( StringRef message ) { + // First notify reporter that bad things happened + m_reporter->fatalErrorEncountered(message); + // Don't rebuild the result -- the stringification itself can cause more fatal errors // Instead, fake a result data. - AssertionResultData tempResult( ResultWas::Unknown, { false } ); - tempResult.resultType = ResultWas::FatalErrorCondition; + AssertionResultData tempResult( ResultWas::FatalErrorCondition, { false } ); tempResult.message = message; AssertionResult result(m_lastAssertionInfo, tempResult); @@ -7902,7 +7700,7 @@ namespace Catch { handleUnfinishedSections(); // Recreate section for test case (as we will lose the one that was in scope) - TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); + auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description); Counts assertions; @@ -7910,7 +7708,7 @@ namespace Catch { SectionStats testCaseSectionStats(testCaseSection, assertions, 0, false); m_reporter->sectionEnded(testCaseSectionStats); - TestCaseInfo testInfo = m_activeTestCase->getTestCaseInfo(); + auto const& testInfo = m_activeTestCase->getTestCaseInfo(); Totals deltaTotals; deltaTotals.testCases.failed = 1; @@ -7944,7 +7742,7 @@ namespace Catch { } void RunContext::runCurrentTest(std::string & redirectedCout, std::string & redirectedCerr) { - TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); + auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description); m_reporter->sectionStarting(testCaseSection); Counts prevAssertions = m_totals.assertions; @@ -8006,7 +7804,7 @@ namespace Catch { } IResultCapture& getResultCapture() { - if (IResultCapture* capture = getCurrentContext().getResultCapture()) + if (auto* capture = getCurrentContext().getResultCapture()) return *capture; else CATCH_INTERNAL_ERROR("No result capture instance"); @@ -8041,32 +7839,346 @@ namespace Catch { #pragma warning(pop) #endif - // This indicates whether the section should be executed or not - Section::operator bool() const { - return m_sectionIncluded; + // This indicates whether the section should be executed or not + Section::operator bool() const { + return m_sectionIncluded; + } + +} // end namespace Catch +// end catch_section.cpp +// start catch_section_info.cpp + +namespace Catch { + + SectionInfo::SectionInfo + ( SourceLineInfo const& _lineInfo, + std::string const& _name, + std::string const& _description ) + : name( _name ), + description( _description ), + lineInfo( _lineInfo ) + {} + + SectionEndInfo::SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds ) + : sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds ) + {} + +} // end namespace Catch +// end catch_section_info.cpp +// start catch_session.cpp + +// start catch_session.h + +#include <memory> + +namespace Catch { + + class Session : NonCopyable { + public: + + Session(); + ~Session() override; + + void showHelp() const; + void libIdentify(); + + int applyCommandLine( int argc, char* argv[] ); + + void useConfigData( ConfigData const& configData ); + + int run( int argc, char* argv[] ); + #if defined(WIN32) && defined(UNICODE) + int run( int argc, wchar_t* const argv[] ); + #endif + int run(); + + clara::Parser const& cli() const; + void cli( clara::Parser const& newParser ); + ConfigData& configData(); + Config& config(); + private: + int runInternal(); + + clara::Parser m_cli; + ConfigData m_configData; + std::shared_ptr<Config> m_config; + }; + +} // end namespace Catch + +// end catch_session.h +// start catch_version.h + +#include <iosfwd> + +namespace Catch { + + // Versioning information + struct Version { + Version( Version const& ) = delete; + Version& operator=( Version const& ) = delete; + Version( unsigned int _majorVersion, + unsigned int _minorVersion, + unsigned int _patchNumber, + char const * const _branchName, + unsigned int _buildNumber ); + + unsigned int const majorVersion; + unsigned int const minorVersion; + unsigned int const patchNumber; + + // buildNumber is only used if branchName is not null + char const * const branchName; + unsigned int const buildNumber; + + friend std::ostream& operator << ( std::ostream& os, Version const& version ); + }; + + Version const& libraryVersion(); +} + +// end catch_version.h +#include <cstdlib> +#include <iomanip> + +namespace { + const int MaxExitCode = 255; + using Catch::IStreamingReporterPtr; + using Catch::IConfigPtr; + using Catch::Config; + + IStreamingReporterPtr createReporter(std::string const& reporterName, IConfigPtr const& config) { + auto reporter = Catch::getRegistryHub().getReporterRegistry().create(reporterName, config); + CATCH_ENFORCE(reporter, "No reporter registered with name: '" << reporterName << "'"); + + return reporter; + } + +#ifndef CATCH_CONFIG_DEFAULT_REPORTER +#define CATCH_CONFIG_DEFAULT_REPORTER "console" +#endif + + IStreamingReporterPtr makeReporter(std::shared_ptr<Config> const& config) { + auto const& reporterNames = config->getReporterNames(); + if (reporterNames.empty()) + return createReporter(CATCH_CONFIG_DEFAULT_REPORTER, config); + + IStreamingReporterPtr reporter; + for (auto const& name : reporterNames) + addReporter(reporter, createReporter(name, config)); + return reporter; + } + +#undef CATCH_CONFIG_DEFAULT_REPORTER + + void addListeners(IStreamingReporterPtr& reporters, IConfigPtr const& config) { + auto const& listeners = Catch::getRegistryHub().getReporterRegistry().getListeners(); + for (auto const& listener : listeners) + addReporter(reporters, listener->create(Catch::ReporterConfig(config))); + } + + Catch::Totals runTests(std::shared_ptr<Config> const& config) { + using namespace Catch; + IStreamingReporterPtr reporter = makeReporter(config); + addListeners(reporter, config); + + RunContext context(config, std::move(reporter)); + + Totals totals; + + context.testGroupStarting(config->name(), 1, 1); + + TestSpec testSpec = config->testSpec(); + if (!testSpec.hasFilters()) + testSpec = TestSpecParser(ITagAliasRegistry::get()).parse("~[.]").testSpec(); // All not hidden tests + + auto const& allTestCases = getAllTestCasesSorted(*config); + for (auto const& testCase : allTestCases) { + if (!context.aborting() && matchTest(testCase, testSpec, *config)) + totals += context.runTest(testCase); + else + context.reporter().skipTest(testCase); + } + + context.testGroupEnded(config->name(), totals, 1, 1); + return totals; + } + + void applyFilenamesAsTags(Catch::IConfig const& config) { + using namespace Catch; + auto& tests = const_cast<std::vector<TestCase>&>(getAllTestCasesSorted(config)); + for (auto& testCase : tests) { + auto tags = testCase.tags; + + std::string filename = testCase.lineInfo.file; + auto lastSlash = filename.find_last_of("\\/"); + if (lastSlash != std::string::npos) { + filename.erase(0, lastSlash); + filename[0] = '#'; + } + + auto lastDot = filename.find_last_of('.'); + if (lastDot != std::string::npos) { + filename.erase(lastDot); + } + + tags.push_back(std::move(filename)); + setTags(testCase, tags); + } + } + +} + +namespace Catch { + + Session::Session() { + static bool alreadyInstantiated = false; + if( alreadyInstantiated ) + CATCH_INTERNAL_ERROR( "Only one instance of Catch::Session can ever be used" ); + alreadyInstantiated = true; + m_cli = makeCommandLineParser( m_configData ); + } + Session::~Session() { + Catch::cleanUp(); + } + + void Session::showHelp() const { + Catch::cout() + << "\nCatch v" << libraryVersion() << "\n" + << m_cli << std::endl + << "For more detailed usage please see the project docs\n" << std::endl; + } + void Session::libIdentify() { + Catch::cout() + << std::left << std::setw(16) << "description: " << "A Catch test executable\n" + << std::left << std::setw(16) << "category: " << "testframework\n" + << std::left << std::setw(16) << "framework: " << "Catch Test\n" + << std::left << std::setw(16) << "version: " << libraryVersion() << std::endl; + } + + int Session::applyCommandLine( int argc, char* argv[] ) { + auto result = m_cli.parse( clara::Args( argc, argv ) ); + if( !result ) { + Catch::cerr() + << Colour( Colour::Red ) + << "\nError(s) in input:\n" + << Column( result.errorMessage() ).indent( 2 ) + << "\n\n"; + Catch::cerr() << "Run with -? for usage\n" << std::endl; + return MaxExitCode; + } + + if( m_configData.showHelp ) + showHelp(); + if( m_configData.libIdentify ) + libIdentify(); + m_config.reset(); + return 0; + } + + void Session::useConfigData( ConfigData const& configData ) { + m_configData = configData; + m_config.reset(); + } + + int Session::run( int argc, char* argv[] ) { + const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions(); + if ( !exceptions.empty() ) { + Catch::cerr() << "Errors occured during startup!" << '\n'; + // iterate over all exceptions and notify user + for ( const auto& ex_ptr : exceptions ) { + try { + std::rethrow_exception(ex_ptr); + } catch ( std::exception const& ex ) { + Catch::cerr() << ex.what() << '\n'; + } + } + return 1; + } + int returnCode = applyCommandLine( argc, argv ); + if( returnCode == 0 ) + returnCode = run(); + return returnCode; + } + +#if defined(WIN32) && defined(UNICODE) + int Session::run( int argc, wchar_t* const argv[] ) { + + char **utf8Argv = new char *[ argc ]; + + for ( int i = 0; i < argc; ++i ) { + int bufSize = WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, NULL, 0, NULL, NULL ); + + utf8Argv[ i ] = new char[ bufSize ]; + + WideCharToMultiByte( CP_UTF8, 0, argv[i], -1, utf8Argv[i], bufSize, NULL, NULL ); + } + + int returnCode = run( argc, utf8Argv ); + + for ( int i = 0; i < argc; ++i ) + delete [] utf8Argv[ i ]; + + delete [] utf8Argv; + + return returnCode; + } +#endif + int Session::run() { + if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeStart ) != 0 ) { + Catch::cout() << "...waiting for enter/ return before starting" << std::endl; + static_cast<void>(std::getchar()); + } + int exitCode = runInternal(); + if( ( m_configData.waitForKeypress & WaitForKeypress::BeforeExit ) != 0 ) { + Catch::cout() << "...waiting for enter/ return before exiting, with code: " << exitCode << std::endl; + static_cast<void>(std::getchar()); + } + return exitCode; + } + + clara::Parser const& Session::cli() const { + return m_cli; + } + void Session::cli( clara::Parser const& newParser ) { + m_cli = newParser; + } + ConfigData& Session::configData() { + return m_configData; + } + Config& Session::config() { + if( !m_config ) + m_config = std::make_shared<Config>( m_configData ); + return *m_config; } -} // end namespace Catch -// end catch_section.cpp -// start catch_section_info.cpp + int Session::runInternal() { + if( m_configData.showHelp || m_configData.libIdentify ) + return 0; -namespace Catch { + try + { + config(); // Force config to be constructed - SectionInfo::SectionInfo - ( SourceLineInfo const& _lineInfo, - std::string const& _name, - std::string const& _description ) - : name( _name ), - description( _description ), - lineInfo( _lineInfo ) - {} + seedRng( *m_config ); - SectionEndInfo::SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds ) - : sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds ) - {} + if( m_configData.filenamesAsTags ) + applyFilenamesAsTags( *m_config ); + + // Handle list request + if( Option<std::size_t> listed = list( config() ) ) + return static_cast<int>( *listed ); + + return (std::min)( MaxExitCode, static_cast<int>( runTests( m_config ).assertions.failed ) ); + } + catch( std::exception& ex ) { + Catch::cerr() << ex.what() << std::endl; + return MaxExitCode; + } + } } // end namespace Catch -// end catch_section_info.cpp +// end catch_session.cpp // start catch_startup_exception_registry.cpp namespace Catch { @@ -8094,7 +8206,7 @@ namespace Catch { namespace Catch { - template<typename WriterF, size_t bufferSize=256> + template<typename WriterF, std::size_t bufferSize=256> class StreamBufImpl : public StreamBufBase { char data[bufferSize]; WriterF m_writer; @@ -8132,6 +8244,8 @@ namespace Catch { /////////////////////////////////////////////////////////////////////////// + Catch::IStream::~IStream() = default; + FileStream::FileStream( std::string const& filename ) { m_ofs.open( filename.c_str() ); CATCH_ENFORCE( !m_ofs.fail(), "Unable to open file: '" << filename << "'" ); @@ -8180,8 +8294,90 @@ namespace Catch { #endif } // end catch_stream.cpp +// start catch_streambuf.cpp + +namespace Catch { + StreamBufBase::~StreamBufBase() = default; +} +// end catch_streambuf.cpp +// start catch_string_manip.cpp + +#include <algorithm> +#include <ostream> +#include <cstring> +#include <cctype> + +namespace Catch { + + bool startsWith( std::string const& s, std::string const& prefix ) { + return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin()); + } + bool startsWith( std::string const& s, char prefix ) { + return !s.empty() && s[0] == prefix; + } + bool endsWith( std::string const& s, std::string const& suffix ) { + return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin()); + } + bool endsWith( std::string const& s, char suffix ) { + return !s.empty() && s[s.size()-1] == suffix; + } + bool contains( std::string const& s, std::string const& infix ) { + return s.find( infix ) != std::string::npos; + } + char toLowerCh(char c) { + return static_cast<char>( std::tolower( c ) ); + } + void toLowerInPlace( std::string& s ) { + std::transform( s.begin(), s.end(), s.begin(), toLowerCh ); + } + std::string toLower( std::string const& s ) { + std::string lc = s; + toLowerInPlace( lc ); + return lc; + } + std::string trim( std::string const& str ) { + static char const* whitespaceChars = "\n\r\t "; + std::string::size_type start = str.find_first_not_of( whitespaceChars ); + std::string::size_type end = str.find_last_not_of( whitespaceChars ); + + return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string(); + } + + bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) { + bool replaced = false; + std::size_t i = str.find( replaceThis ); + while( i != std::string::npos ) { + replaced = true; + str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() ); + if( i < str.size()-withThis.size() ) + i = str.find( replaceThis, i+withThis.size() ); + else + i = std::string::npos; + } + return replaced; + } + + pluralise::pluralise( std::size_t count, std::string const& label ) + : m_count( count ), + m_label( label ) + {} + + std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) { + os << pluraliser.m_count << ' ' << pluraliser.m_label; + if( pluraliser.m_count != 1 ) + os << 's'; + return os; + } + +} +// end catch_string_manip.cpp // start catch_stringref.cpp +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +#endif + #include <ostream> #include <cassert> #include <cstring> @@ -8335,78 +8531,11 @@ namespace Catch { } } // namespace Catch -// end catch_stringref.cpp -// start catch_string_manip.cpp - -#include <algorithm> -#include <ostream> -#include <cstring> -#include <cctype> - -namespace Catch { - - bool startsWith( std::string const& s, std::string const& prefix ) { - return s.size() >= prefix.size() && std::equal(prefix.begin(), prefix.end(), s.begin()); - } - bool startsWith( std::string const& s, char prefix ) { - return !s.empty() && s[0] == prefix; - } - bool endsWith( std::string const& s, std::string const& suffix ) { - return s.size() >= suffix.size() && std::equal(suffix.rbegin(), suffix.rend(), s.rbegin()); - } - bool endsWith( std::string const& s, char suffix ) { - return !s.empty() && s[s.size()-1] == suffix; - } - bool contains( std::string const& s, std::string const& infix ) { - return s.find( infix ) != std::string::npos; - } - char toLowerCh(char c) { - return static_cast<char>( std::tolower( c ) ); - } - void toLowerInPlace( std::string& s ) { - std::transform( s.begin(), s.end(), s.begin(), toLowerCh ); - } - std::string toLower( std::string const& s ) { - std::string lc = s; - toLowerInPlace( lc ); - return lc; - } - std::string trim( std::string const& str ) { - static char const* whitespaceChars = "\n\r\t "; - std::string::size_type start = str.find_first_not_of( whitespaceChars ); - std::string::size_type end = str.find_last_not_of( whitespaceChars ); - - return start != std::string::npos ? str.substr( start, 1+end-start ) : std::string(); - } - - bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) { - bool replaced = false; - std::size_t i = str.find( replaceThis ); - while( i != std::string::npos ) { - replaced = true; - str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() ); - if( i < str.size()-withThis.size() ) - i = str.find( replaceThis, i+withThis.size() ); - else - i = std::string::npos; - } - return replaced; - } - - pluralise::pluralise( std::size_t count, std::string const& label ) - : m_count( count ), - m_label( label ) - {} - - std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) { - os << pluraliser.m_count << ' ' << pluraliser.m_label; - if( pluraliser.m_count != 1 ) - os << 's'; - return os; - } -} -// end catch_string_manip.cpp +#if defined(__clang__) +# pragma clang diagnostic pop +#endif +// end catch_stringref.cpp // start catch_tag_alias.cpp namespace Catch { @@ -8594,7 +8723,7 @@ namespace Catch { std::string TestCaseInfo::tagsAsString() const { std::string ret; // '[' and ']' per tag - size_t full_size = 2 * tags.size(); + std::size_t full_size = 2 * tags.size(); for (const auto& tag : tags) { full_size += tag.size(); } @@ -8643,9 +8772,6 @@ namespace Catch { namespace Catch { - RandomNumberGenerator::result_type RandomNumberGenerator::operator()( result_type n ) const { return std::rand() % n; } - RandomNumberGenerator::result_type RandomNumberGenerator::operator()() const { return std::rand() % max(); } - std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) { std::vector<TestCase> sorted = unsortedTestCases; @@ -8744,7 +8870,10 @@ namespace Catch { #include <stdexcept> #include <memory> -CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +#endif namespace Catch { namespace TestCaseTracking { @@ -8754,6 +8883,8 @@ namespace TestCaseTracking { location( _location ) {} + ITracker::~ITracker() = default; + TrackerContext& TrackerContext::instance() { static TrackerContext s_instance; return s_instance; @@ -9001,7 +9132,9 @@ using TestCaseTracking::IndexTracker; } // namespace Catch -CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS +#if defined(__clang__) +# pragma clang diagnostic pop +#endif // end catch_test_case_tracker.cpp // start catch_test_registry.cpp @@ -9028,6 +9161,8 @@ namespace Catch { getMutableRegistryHub().registerStartupException(); } } + + AutoReg::~AutoReg() = default; } // end catch_test_registry.cpp // start catch_test_spec.cpp @@ -9039,6 +9174,11 @@ namespace Catch { namespace Catch { + TestSpec::Pattern::~Pattern() = default; + TestSpec::NamePattern::~NamePattern() = default; + TestSpec::TagPattern::~TagPattern() = default; + TestSpec::ExcludedPattern::~ExcludedPattern() = default; + TestSpec::NamePattern::NamePattern( std::string const& name ) : m_wildcardPattern( toLower( name ), CaseSensitive::No ) {} @@ -9172,7 +9312,7 @@ namespace Catch { uint64_t sum = 0; static const uint64_t iterations = 1000000; - for( size_t i = 0; i < iterations; ++i ) { + for( std::size_t i = 0; i < iterations; ++i ) { uint64_t ticks; uint64_t baseTicks = getCurrentNanosecondsSinceEpoch(); @@ -9214,6 +9354,12 @@ namespace Catch { // end catch_timer.cpp // start catch_tostring.cpp +#if defined(__clang__) +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wexit-time-destructors" +# pragma clang diagnostic ignored "-Wglobal-constructors" +#endif + #include <iomanip> namespace Catch { @@ -9409,23 +9555,12 @@ std::string StringMaker<double>::convert(double value) { return fpToString(value, 10); } -#ifdef __OBJC__ -std::string StringMaker<NSString*>::convert(NSString* nsstring) { - if (!nsstring) - return "nil"; - return "@" + toString([nsstring UTF8String]); -} -std::string StringMaker<NSString * CATCH_ARC_STRONG>::convert(NSString* CATCH_ARC_STRONG nsstring) { - if (!nsstring) - return "nil"; - return "@" + toString([nsstring UTF8String]); -} -std::string StringMaker<NSObject*>::convert(NSObject* nsObject) { - return ::Catch::Detail::stringify([nsObject description]); -} +} // end namespace Catch + +#if defined(__clang__) +# pragma clang diagnostic pop #endif -} // end namespace Catch // end catch_tostring.cpp // start catch_totals.cpp @@ -9514,7 +9649,7 @@ namespace Catch { } Version const& libraryVersion() { - static Version version( 2, 0, 0, "develop", 3 ); + static Version version( 2, 0, 0, "develop", 4 ); return version; } @@ -9561,7 +9696,7 @@ namespace Catch { // end catch_wildcard_pattern.cpp // start catch_xmlwriter.cpp -// start catch_xmlwriter.hpp +// start catch_xmlwriter.h #include <sstream> #include <vector> @@ -9657,7 +9792,7 @@ namespace Catch { } -// end catch_xmlwriter.hpp +// end catch_xmlwriter.h #include <iomanip> namespace Catch { @@ -9859,7 +9994,7 @@ namespace Catch { // + 1 for decimal point // + 3 for the 3 decimal places // + 1 for null terminator - const size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; + const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1; char buffer[maxDoubleSize]; // Save previous errno, to prevent sprintf from overwriting it @@ -10182,178 +10317,178 @@ namespace Catch { #include <cfloat> #include <cstdio> -namespace { - std::size_t makeRatio( std::size_t number, std::size_t total ) { - std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0; - return ( ratio == 0 && number > 0 ) ? 1 : ratio; - } +namespace Catch { - std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) { - if( i > j && i > k ) - return i; - else if( j > k ) - return j; - else - return k; - } + namespace { + std::size_t makeRatio( std::size_t number, std::size_t total ) { + std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0; + return ( ratio == 0 && number > 0 ) ? 1 : ratio; + } - struct ColumnInfo { - enum Justification { Left, Right }; - std::string name; - int width; - Justification justification; - }; - struct ColumnBreak {}; - struct RowBreak {}; + std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) { + if( i > j && i > k ) + return i; + else if( j > k ) + return j; + else + return k; + } - class TablePrinter { - std::ostream& m_os; - std::vector<ColumnInfo> m_columnInfos; - std::ostringstream m_oss; - int m_currentColumn = -1; - bool m_isOpen = false; + struct ColumnInfo { + enum Justification { Left, Right }; + std::string name; + int width; + Justification justification; + }; + struct ColumnBreak {}; + struct RowBreak {}; - public: - TablePrinter( std::ostream& os, std::vector<ColumnInfo> const& columnInfos ) - : m_os( os ), - m_columnInfos( columnInfos ) - {} + class TablePrinter { + std::ostream& m_os; + std::vector<ColumnInfo> m_columnInfos; + std::ostringstream m_oss; + int m_currentColumn = -1; + bool m_isOpen = false; - auto columnInfos() const -> std::vector<ColumnInfo> const& { - return m_columnInfos; - } + public: + TablePrinter( std::ostream& os, std::vector<ColumnInfo> const& columnInfos ) + : m_os( os ), + m_columnInfos( columnInfos ) + {} - void open() { - if( !m_isOpen ) { - m_isOpen = true; - *this << RowBreak(); - for( auto const& info : m_columnInfos ) - *this << info.name << ColumnBreak(); - *this << RowBreak(); - m_os << Catch::getLineOfChars<'-'>() << "\n"; - } - } - void close() { - if( m_isOpen ) { - *this << RowBreak(); - m_os << std::endl; - m_isOpen = false; + auto columnInfos() const -> std::vector<ColumnInfo> const& { + return m_columnInfos; } - } - template<typename T> - friend TablePrinter& operator << ( TablePrinter& tp, T const& value ) { - tp.m_oss << value; - return tp; - } - - friend TablePrinter& operator << ( TablePrinter& tp, ColumnBreak ) { - auto colStr = tp.m_oss.str(); - // This takes account of utf8 encodings - auto strSize = Catch::StringRef( colStr ).numberOfCharacters(); - tp.m_oss.str(""); - tp.open(); - if( tp.m_currentColumn == static_cast<int>(tp.m_columnInfos.size()-1) ) { - tp.m_currentColumn = -1; - tp.m_os << "\n"; - } - tp.m_currentColumn++; - - auto colInfo = tp.m_columnInfos[tp.m_currentColumn]; - auto padding = ( strSize+2 < static_cast<size_t>( colInfo.width ) ) - ? std::string( colInfo.width-(strSize+2), ' ' ) - : std::string(); - if( colInfo.justification == ColumnInfo::Left ) - tp.m_os << colStr << padding << " "; - else - tp.m_os << padding << colStr << " "; - return tp; - } + void open() { + if( !m_isOpen ) { + m_isOpen = true; + *this << RowBreak(); + for( auto const& info : m_columnInfos ) + *this << info.name << ColumnBreak(); + *this << RowBreak(); + m_os << Catch::getLineOfChars<'-'>() << "\n"; + } + } + void close() { + if( m_isOpen ) { + *this << RowBreak(); + m_os << std::endl; + m_isOpen = false; + } + } - friend TablePrinter& operator << ( TablePrinter& tp, RowBreak ) { - if( tp.m_currentColumn > 0 ) { - tp.m_os << "\n"; - tp.m_currentColumn = -1; + template<typename T> + friend TablePrinter& operator << ( TablePrinter& tp, T const& value ) { + tp.m_oss << value; + return tp; + } + + friend TablePrinter& operator << ( TablePrinter& tp, ColumnBreak ) { + auto colStr = tp.m_oss.str(); + // This takes account of utf8 encodings + auto strSize = Catch::StringRef( colStr ).numberOfCharacters(); + tp.m_oss.str(""); + tp.open(); + if( tp.m_currentColumn == static_cast<int>(tp.m_columnInfos.size()-1) ) { + tp.m_currentColumn = -1; + tp.m_os << "\n"; + } + tp.m_currentColumn++; + + auto colInfo = tp.m_columnInfos[tp.m_currentColumn]; + auto padding = ( strSize+2 < static_cast<std::size_t>( colInfo.width ) ) + ? std::string( colInfo.width-(strSize+2), ' ' ) + : std::string(); + if( colInfo.justification == ColumnInfo::Left ) + tp.m_os << colStr << padding << " "; + else + tp.m_os << padding << colStr << " "; + return tp; } - return tp; - } - }; - class Duration { - enum class Unit { - Auto, - Nanoseconds, - Microseconds, - Milliseconds, - Seconds, - Minutes + friend TablePrinter& operator << ( TablePrinter& tp, RowBreak ) { + if( tp.m_currentColumn > 0 ) { + tp.m_os << "\n"; + tp.m_currentColumn = -1; + } + return tp; + } }; - static const uint64_t s_nanosecondsInAMicrosecond = 1000; - static const uint64_t s_nanosecondsInAMillisecond = 1000*s_nanosecondsInAMicrosecond; - static const uint64_t s_nanosecondsInASecond = 1000*s_nanosecondsInAMillisecond; - static const uint64_t s_nanosecondsInAMinute = 60*s_nanosecondsInASecond; - uint64_t m_inNanoseconds; - Unit m_units; + class Duration { + enum class Unit { + Auto, + Nanoseconds, + Microseconds, + Milliseconds, + Seconds, + Minutes + }; + static const uint64_t s_nanosecondsInAMicrosecond = 1000; + static const uint64_t s_nanosecondsInAMillisecond = 1000*s_nanosecondsInAMicrosecond; + static const uint64_t s_nanosecondsInASecond = 1000*s_nanosecondsInAMillisecond; + static const uint64_t s_nanosecondsInAMinute = 60*s_nanosecondsInASecond; - public: - Duration( uint64_t inNanoseconds, Unit units = Unit::Auto ) - : m_inNanoseconds( inNanoseconds ), - m_units( units ) - { - if( m_units == Unit::Auto ) { - if( m_inNanoseconds < s_nanosecondsInAMicrosecond ) - m_units = Unit::Nanoseconds; - else if( m_inNanoseconds < s_nanosecondsInAMillisecond ) - m_units = Unit::Microseconds; - else if( m_inNanoseconds < s_nanosecondsInASecond ) - m_units = Unit::Milliseconds; - else if( m_inNanoseconds < s_nanosecondsInAMinute ) - m_units = Unit::Seconds; - else - m_units = Unit::Minutes; - } + uint64_t m_inNanoseconds; + Unit m_units; - } + public: + Duration( uint64_t inNanoseconds, Unit units = Unit::Auto ) + : m_inNanoseconds( inNanoseconds ), + m_units( units ) + { + if( m_units == Unit::Auto ) { + if( m_inNanoseconds < s_nanosecondsInAMicrosecond ) + m_units = Unit::Nanoseconds; + else if( m_inNanoseconds < s_nanosecondsInAMillisecond ) + m_units = Unit::Microseconds; + else if( m_inNanoseconds < s_nanosecondsInASecond ) + m_units = Unit::Milliseconds; + else if( m_inNanoseconds < s_nanosecondsInAMinute ) + m_units = Unit::Seconds; + else + m_units = Unit::Minutes; + } - auto value() const -> double { - switch( m_units ) { - case Unit::Microseconds: - return m_inNanoseconds / static_cast<double>( s_nanosecondsInAMicrosecond ); - case Unit::Milliseconds: - return m_inNanoseconds / static_cast<double>( s_nanosecondsInAMillisecond ); - case Unit::Seconds: - return m_inNanoseconds / static_cast<double>( s_nanosecondsInASecond ); - case Unit::Minutes: - return m_inNanoseconds / static_cast<double>( s_nanosecondsInAMinute ); - default: - return static_cast<double>( m_inNanoseconds ); - } - } - auto unitsAsString() const -> std::string { - switch( m_units ) { - case Unit::Nanoseconds: - return "ns"; - case Unit::Microseconds: - return "µs"; - case Unit::Milliseconds: - return "ms"; - case Unit::Seconds: - return "s"; - case Unit::Minutes: - return "m"; - default: - return "** internal error **"; } - } - friend auto operator << ( std::ostream& os, Duration const& duration ) -> std::ostream& { - return os << duration.value() << " " << duration.unitsAsString(); - } - }; -} + auto value() const -> double { + switch( m_units ) { + case Unit::Microseconds: + return m_inNanoseconds / static_cast<double>( s_nanosecondsInAMicrosecond ); + case Unit::Milliseconds: + return m_inNanoseconds / static_cast<double>( s_nanosecondsInAMillisecond ); + case Unit::Seconds: + return m_inNanoseconds / static_cast<double>( s_nanosecondsInASecond ); + case Unit::Minutes: + return m_inNanoseconds / static_cast<double>( s_nanosecondsInAMinute ); + default: + return static_cast<double>( m_inNanoseconds ); + } + } + auto unitsAsString() const -> std::string { + switch( m_units ) { + case Unit::Nanoseconds: + return "ns"; + case Unit::Microseconds: + return "µs"; + case Unit::Milliseconds: + return "ms"; + case Unit::Seconds: + return "s"; + case Unit::Minutes: + return "m"; + default: + return "** internal error **"; + } -namespace Catch { + } + friend auto operator << ( std::ostream& os, Duration const& duration ) -> std::ostream& { + return os << duration.value() << " " << duration.unitsAsString(); + } + }; + } // end anon namespace struct ConsoleReporter : StreamingReporterBase<ConsoleReporter> { TablePrinter m_tablePrinter; @@ -10819,7 +10954,7 @@ namespace Catch { // Also, UTC only, again because of backward compatibility (%z is C++11) time_t rawtime; std::time(&rawtime); - const size_t timeStampSize = sizeof("2017-01-16T17:06:45Z"); + auto const timeStampSize = sizeof("2017-01-16T17:06:45Z"); #ifdef _MSC_VER std::tm timeInfo = {}; @@ -11061,7 +11196,7 @@ namespace Catch { } std::set<Verbosity> MultipleReporters::getSupportedVerbosities() { - return { }; + return std::set<Verbosity>{ }; } void MultipleReporters::noMatchingTestCases( std::string const& spec ) { @@ -11348,26 +11483,6 @@ namespace Catch { namespace Catch { LeakDetector leakDetector; - - // These are all here to avoid warnings about not having any out of line - // virtual methods - NonCopyable::~NonCopyable() {} - IStream::~IStream() noexcept {} - FileStream::~FileStream() noexcept {} - CoutStream::~CoutStream() noexcept {} - DebugOutStream::~DebugOutStream() noexcept {} - StreamBufBase::~StreamBufBase() noexcept {} - IResultCapture::~IResultCapture() {} - ITestInvoker::~ITestInvoker() {} - ITestCaseRegistry::~ITestCaseRegistry() {} - IRegistryHub::~IRegistryHub() {} - IMutableRegistryHub::~IMutableRegistryHub() {} - IExceptionTranslator::~IExceptionTranslator() {} - IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {} - IRunner::~IRunner() {} - IConfig::~IConfig() {} - - void Config::dummy() {} } #ifdef __clang__ @@ -11402,7 +11517,7 @@ int main (int argc, char * const argv[]) { #endif Catch::registerTestMethods(); - int result = Catch::Session().run( argc, (char* const*)argv ); + int result = Catch::Session().run( argc, (char**)argv ); #if !CATCH_ARC_ENABLED [pool drain]; diff --git a/test_package/conanfile.py b/test_package/conanfile.py index ebefc8ac..2311ab7f 100644 --- a/test_package/conanfile.py +++ b/test_package/conanfile.py @@ -10,7 +10,7 @@ class CatchConanTest(ConanFile): settings = "os", "compiler", "arch", "build_type" username = getenv("CONAN_USERNAME", "philsquared") channel = getenv("CONAN_CHANNEL", "testing") - requires = "Catch/2.0.0-develop.3@%s/%s" % (username, channel) + requires = "Catch/2.0.0-develop.4@%s/%s" % (username, channel) def build(self): cmake = CMake(self)