ChaiScript / ChaiScript
1
/*
2
 *  Catch v2.2.2
3
 *  Generated: 2018-04-06 12:05:03.186665
4
 *  ----------------------------------------------------------
5
 *  This file has been merged from multiple headers. Please don't edit it directly
6
 *  Copyright (c) 2018 Two Blue Cubes Ltd. All rights reserved.
7
 *
8
 *  Distributed under the Boost Software License, Version 1.0. (See accompanying
9
 *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
10
 */
11
#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
12
#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
13
// start catch.hpp
14

15

16
#define CATCH_VERSION_MAJOR 2
17
#define CATCH_VERSION_MINOR 2
18
#define CATCH_VERSION_PATCH 2
19

20
#ifdef __clang__
21
#    pragma clang system_header
22
#elif defined __GNUC__
23
#    pragma GCC system_header
24
#endif
25

26
// start catch_suppress_warnings.h
27

28
#ifdef __clang__
29
#   ifdef __ICC // icpc defines the __clang__ macro
30
#       pragma warning(push)
31
#       pragma warning(disable: 161 1682)
32
#   else // __ICC
33
#       pragma clang diagnostic ignored "-Wunused-variable"
34
#       pragma clang diagnostic push
35
#       pragma clang diagnostic ignored "-Wpadded"
36
#       pragma clang diagnostic ignored "-Wswitch-enum"
37
#       pragma clang diagnostic ignored "-Wcovered-switch-default"
38
#    endif
39
#elif defined __GNUC__
40
#    pragma GCC diagnostic ignored "-Wparentheses"
41
#    pragma GCC diagnostic push
42
#    pragma GCC diagnostic ignored "-Wunused-variable"
43
#    pragma GCC diagnostic ignored "-Wpadded"
44
#endif
45
// end catch_suppress_warnings.h
46
#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER)
47
#  define CATCH_IMPL
48
#  define CATCH_CONFIG_ALL_PARTS
49
#endif
50

51
// In the impl file, we want to have access to all parts of the headers
52
// Can also be used to sanely support PCHs
53
#if defined(CATCH_CONFIG_ALL_PARTS)
54
#  define CATCH_CONFIG_EXTERNAL_INTERFACES
55
#  if defined(CATCH_CONFIG_DISABLE_MATCHERS)
56
#    undef CATCH_CONFIG_DISABLE_MATCHERS
57
#  endif
58
#  define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
59
#endif
60

61
#if !defined(CATCH_CONFIG_IMPL_ONLY)
62
// start catch_platform.h
63

64
#ifdef __APPLE__
65
# include <TargetConditionals.h>
66
# if TARGET_OS_OSX == 1
67
#  define CATCH_PLATFORM_MAC
68
# elif TARGET_OS_IPHONE == 1
69
#  define CATCH_PLATFORM_IPHONE
70
# endif
71

72
#elif defined(linux) || defined(__linux) || defined(__linux__)
73
#  define CATCH_PLATFORM_LINUX
74

75
#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
76
#  define CATCH_PLATFORM_WINDOWS
77
#endif
78

79
// end catch_platform.h
80

81
#ifdef CATCH_IMPL
82
#  ifndef CLARA_CONFIG_MAIN
83
#    define CLARA_CONFIG_MAIN_NOT_DEFINED
84
#    define CLARA_CONFIG_MAIN
85
#  endif
86
#endif
87

88
// start catch_user_interfaces.h
89

90
namespace Catch {
91
    unsigned int rngSeed();
92
}
93

94
// end catch_user_interfaces.h
95
// start catch_tag_alias_autoregistrar.h
96

97
// start catch_common.h
98

99
// start catch_compiler_capabilities.h
100

101
// Detect a number of compiler features - by compiler
102
// The following features are defined:
103
//
104
// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported?
105
// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported?
106
// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported?
107
// ****************
108
// Note to maintainers: if new toggles are added please document them
109
// in configuration.md, too
110
// ****************
111

112
// In general each macro has a _NO_<feature name> form
113
// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature.
114
// Many features, at point of detection, define an _INTERNAL_ macro, so they
115
// can be combined, en-mass, with the _NO_ forms later.
116

117
#ifdef __cplusplus
118

119
#  if __cplusplus >= 201402L
120
#    define CATCH_CPP14_OR_GREATER
121
#  endif
122

123
#  if __cplusplus >= 201703L
124
#    define CATCH_CPP17_OR_GREATER
125
#  endif
126

127
#endif
128

129
#if defined(CATCH_CPP17_OR_GREATER)
130
#  define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
131
#endif
132

133
#ifdef __clang__
134

135
#       define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
136
            _Pragma( "clang diagnostic push" ) \
137
            _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \
138
            _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"")
139
#       define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
140
            _Pragma( "clang diagnostic pop" )
141

142
#       define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
143
            _Pragma( "clang diagnostic push" ) \
144
            _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
145
#       define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
146
            _Pragma( "clang diagnostic pop" )
147

148
#endif // __clang__
149

150
////////////////////////////////////////////////////////////////////////////////
151
// Assume that non-Windows platforms support posix signals by default
152
#if !defined(CATCH_PLATFORM_WINDOWS)
153
    #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS
154
#endif
155

156
////////////////////////////////////////////////////////////////////////////////
157
// We know some environments not to support full POSIX signals
158
#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__)
159
    #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
160
#endif
161

162
#ifdef __OS400__
163
#       define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
164
#       define CATCH_CONFIG_COLOUR_NONE
165
#endif
166

167
////////////////////////////////////////////////////////////////////////////////
168
// Cygwin
169
#ifdef __CYGWIN__
170

171
// Required for some versions of Cygwin to declare gettimeofday
172
// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin
173
#   define _BSD_SOURCE
174

175
#endif // __CYGWIN__
176

177
////////////////////////////////////////////////////////////////////////////////
178
// Visual C++
179
#ifdef _MSC_VER
180

181
#  if _MSC_VER >= 1900 // Visual Studio 2015 or newer
182
#    define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
183
#  endif
184

185
// Universal Windows platform does not support SEH
186
// Or console colours (or console at all...)
187
#  if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
188
#    define CATCH_CONFIG_COLOUR_NONE
189
#  else
190
#    define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
191
#  endif
192

193
#endif // _MSC_VER
194

195
////////////////////////////////////////////////////////////////////////////////
196

197
// DJGPP
198
#ifdef __DJGPP__
199
#  define CATCH_INTERNAL_CONFIG_NO_WCHAR
200
#endif // __DJGPP__
201

202
////////////////////////////////////////////////////////////////////////////////
203

204
// Use of __COUNTER__ is suppressed during code analysis in
205
// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly
206
// handled by it.
207
// Otherwise all supported compilers support COUNTER macro,
208
// but user still might want to turn it off
209
#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L )
210
    #define CATCH_INTERNAL_CONFIG_COUNTER
211
#endif
212

213
#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
214
#   define CATCH_CONFIG_COUNTER
215
#endif
216
#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH)
217
#   define CATCH_CONFIG_WINDOWS_SEH
218
#endif
219
// This is set by default, because we assume that unix compilers are posix-signal-compatible by default.
220
#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS)
221
#   define CATCH_CONFIG_POSIX_SIGNALS
222
#endif
223
// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions.
224
#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR)
225
#   define CATCH_CONFIG_WCHAR
226
#endif
227

228
#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
229
#  define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
230
#endif
231

232
#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
233
#   define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
234
#   define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
235
#endif
236
#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS)
237
#   define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
238
#   define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
239
#endif
240

241
// end catch_compiler_capabilities.h
242
#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
243
#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
244
#ifdef CATCH_CONFIG_COUNTER
245
#  define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
246
#else
247
#  define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
248
#endif
249

250
#include <iosfwd>
251
#include <string>
252
#include <cstdint>
253

254
namespace Catch {
255

256
    struct CaseSensitive { enum Choice {
257
        Yes,
258
        No
259
    }; };
260

261 1
    class NonCopyable {
262
        NonCopyable( NonCopyable const& )              = delete;
263
        NonCopyable( NonCopyable && )                  = delete;
264
        NonCopyable& operator = ( NonCopyable const& ) = delete;
265
        NonCopyable& operator = ( NonCopyable && )     = delete;
266

267
    protected:
268
        NonCopyable();
269
        virtual ~NonCopyable();
270
    };
271

272
    struct SourceLineInfo {
273

274
        SourceLineInfo() = delete;
275 1
        SourceLineInfo( char const* _file, std::size_t _line ) noexcept
276 1
        :   file( _file ),
277 1
            line( _line )
278 1
        {}
279

280
        SourceLineInfo( SourceLineInfo const& other )        = default;
281
        SourceLineInfo( SourceLineInfo && )                  = default;
282
        SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
283
        SourceLineInfo& operator = ( SourceLineInfo && )     = default;
284

285
        bool empty() const noexcept;
286
        bool operator == ( SourceLineInfo const& other ) const noexcept;
287
        bool operator < ( SourceLineInfo const& other ) const noexcept;
288

289
        char const* file;
290
        std::size_t line;
291
    };
292

293
    std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
294

295
    // Use this in variadic streaming macros to allow
296
    //    >> +StreamEndStop
297
    // as well as
298
    //    >> stuff +StreamEndStop
299
    struct StreamEndStop {
300
        std::string operator+() const;
301
    };
302
    template<typename T>
303
    T const& operator + ( T const& value, StreamEndStop ) {
304
        return value;
305
    }
306
}
307

308
#define CATCH_INTERNAL_LINEINFO \
309
    ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
310

311
// end catch_common.h
312
namespace Catch {
313

314
    struct RegistrarForTagAliases {
315
        RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo );
316
    };
317

318
} // end namespace Catch
319

320
#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \
321
    CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
322
    namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \
323
    CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
324

325
// end catch_tag_alias_autoregistrar.h
326
// start catch_test_registry.h
327

328
// start catch_interfaces_testcase.h
329

330
#include <vector>
331
#include <memory>
332

333
namespace Catch {
334

335
    class TestSpec;
336

337 1
    struct ITestInvoker {
338
        virtual void invoke () const = 0;
339
        virtual ~ITestInvoker();
340
    };
341

342
    using ITestCasePtr = std::shared_ptr<ITestInvoker>;
343

344
    class TestCase;
345
    struct IConfig;
346

347 1
    struct ITestCaseRegistry {
348
        virtual ~ITestCaseRegistry();
349
        virtual std::vector<TestCase> const& getAllTests() const = 0;
350
        virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const = 0;
351
    };
352

353
    bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
354
    std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
355
    std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );
356

357
}
358

359
// end catch_interfaces_testcase.h
360
// start catch_stringref.h
361

362
#include <cstddef>
363
#include <string>
364
#include <iosfwd>
365

366
namespace Catch {
367

368
    class StringData;
369

370
    /// A non-owning string class (similar to the forthcoming std::string_view)
371
    /// Note that, because a StringRef may be a substring of another string,
372
    /// it may not be null terminated. c_str() must return a null terminated
373
    /// string, however, and so the StringRef will internally take ownership
374
    /// (taking a copy), if necessary. In theory this ownership is not externally
375
    /// visible - but it does mean (substring) StringRefs should not be shared between
376
    /// threads.
377
    class StringRef {
378
    public:
379
        using size_type = std::size_t;
380

381
    private:
382
        friend struct StringRefTestAccess;
383

384
        char const* m_start;
385
        size_type m_size;
386

387
        char* m_data = nullptr;
388

389
        void takeOwnership();
390

391
        static constexpr char const* const s_empty = "";
392

393
    public: // construction/ assignment
394 1
        StringRef() noexcept
395 1
        :   StringRef( s_empty, 0 )
396 1
        {}
397

398 1
        StringRef( StringRef const& other ) noexcept
399 1
        :   m_start( other.m_start ),
400 1
            m_size( other.m_size )
401 1
        {}
402

403
        StringRef( StringRef&& other ) noexcept
404
        :   m_start( other.m_start ),
405
            m_size( other.m_size ),
406
            m_data( other.m_data )
407
        {
408
            other.m_data = nullptr;
409
        }
410

411
        StringRef( char const* rawChars ) noexcept;
412

413 1
        StringRef( char const* rawChars, size_type size ) noexcept
414 1
        :   m_start( rawChars ),
415 1
            m_size( size )
416 1
        {}
417

418 1
        StringRef( std::string const& stdString ) noexcept
419 1
        :   m_start( stdString.c_str() ),
420 1
            m_size( stdString.size() )
421 1
        {}
422

423 1
        ~StringRef() noexcept {
424
            delete[] m_data;
425
        }
426

427 1
        auto operator = ( StringRef const &other ) noexcept -> StringRef& {
428
            delete[] m_data;
429 1
            m_data = nullptr;
430 1
            m_start = other.m_start;
431 1
            m_size = other.m_size;
432 1
            return *this;
433
        }
434

435
        operator std::string() const;
436

437
        void swap( StringRef& other ) noexcept;
438

439
    public: // operators
440
        auto operator == ( StringRef const& other ) const noexcept -> bool;
441
        auto operator != ( StringRef const& other ) const noexcept -> bool;
442

443
        auto operator[] ( size_type index ) const noexcept -> char;
444

445
    public: // named queries
446 1
        auto empty() const noexcept -> bool {
447 1
            return m_size == 0;
448
        }
449 0
        auto size() const noexcept -> size_type {
450 0
            return m_size;
451
        }
452

453
        auto numberOfCharacters() const noexcept -> size_type;
454
        auto c_str() const -> char const*;
455

456
    public: // substrings and searches
457
        auto substr( size_type start, size_type size ) const noexcept -> StringRef;
458

459
        // Returns the current start pointer.
460
        // Note that the pointer can change when if the StringRef is a substring
461
        auto currentData() const noexcept -> char const*;
462

463
    private: // ownership queries - may not be consistent between calls
464
        auto isOwned() const noexcept -> bool;
465
        auto isSubstring() const noexcept -> bool;
466
    };
467

468
    auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string;
469
    auto operator + ( StringRef const& lhs, char const* rhs ) -> std::string;
470
    auto operator + ( char const* lhs, StringRef const& rhs ) -> std::string;
471

472
    auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&;
473
    auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&;
474

475 1
    inline auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
476 1
        return StringRef( rawChars, size );
477
    }
478

479
} // namespace Catch
480

481
// end catch_stringref.h
482
namespace Catch {
483

484
template<typename C>
485
class TestInvokerAsMethod : public ITestInvoker {
486
    void (C::*m_testAsMethod)();
487
public:
488
    TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {}
489

490
    void invoke() const override {
491
        C obj;
492
        (obj.*m_testAsMethod)();
493
    }
494
};
495

496
auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker*;
497

498
template<typename C>
499
auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* {
500
    return new(std::nothrow) TestInvokerAsMethod<C>( testAsMethod );
501
}
502

503
struct NameAndTags {
504
    NameAndTags( StringRef const& name_ = StringRef(), StringRef const& tags_ = StringRef() ) noexcept;
505
    StringRef name;
506
    StringRef tags;
507
};
508

509 1
struct AutoReg : NonCopyable {
510
    AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept;
511
    ~AutoReg();
512
};
513

514
} // end namespace Catch
515

516
#if defined(CATCH_CONFIG_DISABLE)
517
    #define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \
518
        static void TestName()
519
    #define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \
520
        namespace{                        \
521
            struct TestName : ClassName { \
522
                void test();              \
523
            };                            \
524
        }                                 \
525
        void TestName::test()
526

527
#endif
528

529
    ///////////////////////////////////////////////////////////////////////////////
530
    #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
531
        static void TestName(); \
532
        CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
533
        namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
534
        CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
535
        static void TestName()
536
    #define INTERNAL_CATCH_TESTCASE( ... ) \
537
        INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ )
538

539
    ///////////////////////////////////////////////////////////////////////////////
540
    #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
541
        CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
542
        namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
543
        CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
544

545
    ///////////////////////////////////////////////////////////////////////////////
546
    #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
547
        CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
548
        namespace{ \
549
            struct TestName : ClassName{ \
550
                void test(); \
551
            }; \
552
            Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
553
        } \
554
        CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
555
        void TestName::test()
556
    #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
557
        INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ )
558

559
    ///////////////////////////////////////////////////////////////////////////////
560
    #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
561
        CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
562
        Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, "", Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
563
        CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
564

565
// end catch_test_registry.h
566
// start catch_capture.hpp
567

568
// start catch_assertionhandler.h
569

570
// start catch_assertioninfo.h
571

572
// start catch_result_type.h
573

574
namespace Catch {
575

576
    // ResultWas::OfType enum
577
    struct ResultWas { enum OfType {
578
        Unknown = -1,
579
        Ok = 0,
580
        Info = 1,
581
        Warning = 2,
582

583
        FailureBit = 0x10,
584

585
        ExpressionFailed = FailureBit | 1,
586
        ExplicitFailure = FailureBit | 2,
587

588
        Exception = 0x100 | FailureBit,
589

590
        ThrewException = Exception | 1,
591
        DidntThrowException = Exception | 2,
592

593
        FatalErrorCondition = 0x200 | FailureBit
594

595
    }; };
596

597
    bool isOk( ResultWas::OfType resultType );
598
    bool isJustInfo( int flags );
599

600
    // ResultDisposition::Flags enum
601
    struct ResultDisposition { enum Flags {
602
        Normal = 0x01,
603

604
        ContinueOnFailure = 0x02,   // Failures fail test, but execution continues
605
        FalseTest = 0x04,           // Prefix expression with !
606
        SuppressFail = 0x08         // Failures are reported but do not fail the test
607
    }; };
608

609
    ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs );
610

611
    bool shouldContinueOnFailure( int flags );
612 1
    inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; }
613
    bool shouldSuppressFailure( int flags );
614

615
} // end namespace Catch
616

617
// end catch_result_type.h
618
namespace Catch {
619

620
    struct AssertionInfo
621
    {
622
        StringRef macroName;
623
        SourceLineInfo lineInfo;
624
        StringRef capturedExpression;
625
        ResultDisposition::Flags resultDisposition;
626

627
        // We want to delete this constructor but a compiler bug in 4.8 means
628
        // the struct is then treated as non-aggregate
629
        //AssertionInfo() = delete;
630
    };
631

632
} // end namespace Catch
633

634
// end catch_assertioninfo.h
635
// start catch_decomposer.h
636

637
// start catch_tostring.h
638

639
#include <vector>
640
#include <cstddef>
641
#include <type_traits>
642
#include <string>
643
// start catch_stream.h
644

645
#include <iosfwd>
646
#include <cstddef>
647
#include <ostream>
648

649
namespace Catch {
650

651
    std::ostream& cout();
652
    std::ostream& cerr();
653
    std::ostream& clog();
654

655
    class StringRef;
656

657 1
    struct IStream {
658
        virtual ~IStream();
659
        virtual std::ostream& stream() const = 0;
660
    };
661

662
    auto makeStream( StringRef const &filename ) -> IStream const*;
663

664
    class ReusableStringStream {
665
        std::size_t m_index;
666
        std::ostream* m_oss;
667
    public:
668
        ReusableStringStream();
669
        ~ReusableStringStream();
670

671
        auto str() const -> std::string;
672

673
        template<typename T>
674 1
        auto operator << ( T const& value ) -> ReusableStringStream& {
675 1
            *m_oss << value;
676 1
            return *this;
677
        }
678 0
        auto get() -> std::ostream& { return *m_oss; }
679

680
        static void cleanup();
681
    };
682
}
683

684
// end catch_stream.h
685

686
#ifdef __OBJC__
687
// start catch_objc_arc.hpp
688

689
#import <Foundation/Foundation.h>
690

691
#ifdef __has_feature
692
#define CATCH_ARC_ENABLED __has_feature(objc_arc)
693
#else
694
#define CATCH_ARC_ENABLED 0
695
#endif
696

697
void arcSafeRelease( NSObject* obj );
698
id performOptionalSelector( id obj, SEL sel );
699

700
#if !CATCH_ARC_ENABLED
701
inline void arcSafeRelease( NSObject* obj ) {
702
    [obj release];
703
}
704
inline id performOptionalSelector( id obj, SEL sel ) {
705
    if( [obj respondsToSelector: sel] )
706
        return [obj performSelector: sel];
707
    return nil;
708
}
709
#define CATCH_UNSAFE_UNRETAINED
710
#define CATCH_ARC_STRONG
711
#else
712
inline void arcSafeRelease( NSObject* ){}
713
inline id performOptionalSelector( id obj, SEL sel ) {
714
#ifdef __clang__
715
#pragma clang diagnostic push
716
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
717
#endif
718
    if( [obj respondsToSelector: sel] )
719
        return [obj performSelector: sel];
720
#ifdef __clang__
721
#pragma clang diagnostic pop
722
#endif
723
    return nil;
724
}
725
#define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
726
#define CATCH_ARC_STRONG __strong
727
#endif
728

729
// end catch_objc_arc.hpp
730
#endif
731

732
#ifdef _MSC_VER
733
#pragma warning(push)
734
#pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless
735
#endif
736

737
// We need a dummy global operator<< so we can bring it into Catch namespace later
738
struct Catch_global_namespace_dummy {};
739
std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy);
740

741
namespace Catch {
742
    // Bring in operator<< from global namespace into Catch namespace
743
    using ::operator<<;
744

745
    namespace Detail {
746

747
        extern const std::string unprintableString;
748

749
        std::string rawMemoryToString( const void *object, std::size_t size );
750

751
        template<typename T>
752 0
        std::string rawMemoryToString( const T& object ) {
753 0
          return rawMemoryToString( &object, sizeof(object) );
754
        }
755

756
        template<typename T>
757
        class IsStreamInsertable {
758
            template<typename SS, typename TT>
759
            static auto test(int)
760
                -> decltype(std::declval<SS&>() << std::declval<TT>(), std::true_type());
761

762
            template<typename, typename>
763
            static auto test(...)->std::false_type;
764

765
        public:
766
            static const bool value = decltype(test<std::ostream, const T&>(0))::value;
767
        };
768

769
        template<typename E>
770
        std::string convertUnknownEnumToString( E e );
771

772
        template<typename T>
773
        typename std::enable_if<!std::is_enum<T>::value, std::string>::type convertUnstreamable( T const& value ) {
774
#if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER)
775
            (void)value;
776
            return Detail::unprintableString;
777
#else
778
            return CATCH_CONFIG_FALLBACK_STRINGIFIER(value);
779
#endif
780
        }
781
        template<typename T>
782
        typename std::enable_if<std::is_enum<T>::value, std::string>::type convertUnstreamable( T const& value ) {
783
            return convertUnknownEnumToString( value );
784
        }
785

786
#if defined(_MANAGED)
787
        //! Convert a CLR string to a utf8 std::string
788
        template<typename T>
789
        std::string clrReferenceToString( T^ ref ) {
790
            if (ref == nullptr)
791
                return std::string("null");
792
            auto bytes = System::Text::Encoding::UTF8->GetBytes(ref->ToString());
793
            cli::pin_ptr<System::Byte> p = &bytes[0];
794
            return std::string(reinterpret_cast<char const *>(p), bytes->Length);
795
        }
796
#endif
797

798
    } // namespace Detail
799

800
    // If we decide for C++14, change these to enable_if_ts
801
    template <typename T, typename = void>
802
    struct StringMaker {
803
        template <typename Fake = T>
804
        static
805
        typename std::enable_if<::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>::type
806 0
            convert(const Fake& value) {
807 0
                ReusableStringStream rss;
808 0
                rss << value;
809 0
                return rss.str();
810
        }
811

812
        template <typename Fake = T>
813
        static
814
        typename std::enable_if<!::Catch::Detail::IsStreamInsertable<Fake>::value, std::string>::type
815
            convert( const Fake& value ) {
816
                return Detail::convertUnstreamable( value );
817
        }
818
    };
819

820
    namespace Detail {
821

822
        // This function dispatches all stringification requests inside of Catch.
823
        // Should be preferably called fully qualified, like ::Catch::Detail::stringify
824
        template <typename T>
825 0
        std::string stringify(const T& e) {
826 0
            return ::Catch::StringMaker<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::convert(e);
827
        }
828

829
        template<typename E>
830
        std::string convertUnknownEnumToString( E e ) {
831
            return ::Catch::Detail::stringify(static_cast<typename std::underlying_type<E>::type>(e));
832
        }
833

834
#if defined(_MANAGED)
835
        template <typename T>
836
        std::string stringify( T^ e ) {
837
            return ::Catch::StringMaker<T^>::convert(e);
838
        }
839
#endif
840

841
    } // namespace Detail
842

843
    // Some predefined specializations
844

845
    template<>
846
    struct StringMaker<std::string> {
847
        static std::string convert(const std::string& str);
848
    };
849
#ifdef CATCH_CONFIG_WCHAR
850
    template<>
851
    struct StringMaker<std::wstring> {
852
        static std::string convert(const std::wstring& wstr);
853
    };
854
#endif
855

856
    template<>
857
    struct StringMaker<char const *> {
858
        static std::string convert(char const * str);
859
    };
860
    template<>
861
    struct StringMaker<char *> {
862
        static std::string convert(char * str);
863
    };
864

865
#ifdef CATCH_CONFIG_WCHAR
866
    template<>
867
    struct StringMaker<wchar_t const *> {
868
        static std::string convert(wchar_t const * str);
869
    };
870
    template<>
871
    struct StringMaker<wchar_t *> {
872
        static std::string convert(wchar_t * str);
873
    };
874
#endif
875

876
    // TBD: Should we use `strnlen` to ensure that we don't go out of the buffer,
877
    //      while keeping string semantics?
878
    template<int SZ>
879
    struct StringMaker<char[SZ]> {
880 0
        static std::string convert(char const* str) {
881 0
            return ::Catch::Detail::stringify(std::string{ str });
882
        }
883
    };
884
    template<int SZ>
885
    struct StringMaker<signed char[SZ]> {
886
        static std::string convert(signed char const* str) {
887
            return ::Catch::Detail::stringify(std::string{ reinterpret_cast<char const *>(str) });
888
        }
889
    };
890
    template<int SZ>
891
    struct StringMaker<unsigned char[SZ]> {
892
        static std::string convert(unsigned char const* str) {
893
            return ::Catch::Detail::stringify(std::string{ reinterpret_cast<char const *>(str) });
894
        }
895
    };
896

897
    template<>
898
    struct StringMaker<int> {
899
        static std::string convert(int value);
900
    };
901
    template<>
902
    struct StringMaker<long> {
903
        static std::string convert(long value);
904
    };
905
    template<>
906
    struct StringMaker<long long> {
907
        static std::string convert(long long value);
908
    };
909
    template<>
910
    struct StringMaker<unsigned int> {
911
        static std::string convert(unsigned int value);
912
    };
913
    template<>
914
    struct StringMaker<unsigned long> {
915
        static std::string convert(unsigned long value);
916
    };
917
    template<>
918
    struct StringMaker<unsigned long long> {
919
        static std::string convert(unsigned long long value);
920
    };
921

922
    template<>
923
    struct StringMaker<bool> {
924
        static std::string convert(bool b);
925
    };
926

927
    template<>
928
    struct StringMaker<char> {
929
        static std::string convert(char c);
930
    };
931
    template<>
932
    struct StringMaker<signed char> {
933
        static std::string convert(signed char c);
934
    };
935
    template<>
936
    struct StringMaker<unsigned char> {
937
        static std::string convert(unsigned char c);
938
    };
939

940
    template<>
941
    struct StringMaker<std::nullptr_t> {
942
        static std::string convert(std::nullptr_t);
943
    };
944

945
    template<>
946
    struct StringMaker<float> {
947
        static std::string convert(float value);
948
    };
949
    template<>
950
    struct StringMaker<double> {
951
        static std::string convert(double value);
952
    };
953

954
    template <typename T>
955
    struct StringMaker<T*> {
956
        template <typename U>
957 0
        static std::string convert(U* p) {
958 0
            if (p) {
959 0
                return ::Catch::Detail::rawMemoryToString(p);
960
            } else {
961 0
                return "nullptr";
962
            }
963
        }
964
    };
965

966
    template <typename R, typename C>
967
    struct StringMaker<R C::*> {
968
        static std::string convert(R C::* p) {
969
            if (p) {
970
                return ::Catch::Detail::rawMemoryToString(p);
971
            } else {
972
                return "nullptr";
973
            }
974
        }
975
    };
976

977
#if defined(_MANAGED)
978
    template <typename T>
979
    struct StringMaker<T^> {
980
        static std::string convert( T^ ref ) {
981
            return ::Catch::Detail::clrReferenceToString(ref);
982
        }
983
    };
984
#endif
985

986
    namespace Detail {
987
        template<typename InputIterator>
988
        std::string rangeToString(InputIterator first, InputIterator last) {
989
            ReusableStringStream rss;
990
            rss << "{ ";
991
            if (first != last) {
992
                rss << ::Catch::Detail::stringify(*first);
993
                for (++first; first != last; ++first)
994
                    rss << ", " << ::Catch::Detail::stringify(*first);
995
            }
996
            rss << " }";
997
            return rss.str();
998
        }
999
    }
1000

1001
#ifdef __OBJC__
1002
    template<>
1003
    struct StringMaker<NSString*> {
1004
        static std::string convert(NSString * nsstring) {
1005
            if (!nsstring)
1006
                return "nil";
1007
            return std::string("@") + [nsstring UTF8String];
1008
        }
1009
    };
1010
    template<>
1011
    struct StringMaker<NSObject*> {
1012
        static std::string convert(NSObject* nsObject) {
1013
            return ::Catch::Detail::stringify([nsObject description]);
1014
        }
1015

1016
    };
1017
    namespace Detail {
1018
        inline std::string stringify( NSString* nsstring ) {
1019
            return StringMaker<NSString*>::convert( nsstring );
1020
        }
1021

1022
    } // namespace Detail
1023
#endif // __OBJC__
1024

1025
} // namespace Catch
1026

1027
//////////////////////////////////////////////////////
1028
// Separate std-lib types stringification, so it can be selectively enabled
1029
// This means that we do not bring in
1030

1031
#if defined(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS)
1032
#  define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
1033
#  define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
1034
#  define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
1035
#endif
1036

1037
// Separate std::pair specialization
1038
#if defined(CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER)
1039
#include <utility>
1040
namespace Catch {
1041
    template<typename T1, typename T2>
1042
    struct StringMaker<std::pair<T1, T2> > {
1043
        static std::string convert(const std::pair<T1, T2>& pair) {
1044
            ReusableStringStream rss;
1045
            rss << "{ "
1046
                << ::Catch::Detail::stringify(pair.first)
1047
                << ", "
1048
                << ::Catch::Detail::stringify(pair.second)
1049
                << " }";
1050
            return rss.str();
1051
        }
1052
    };
1053
}
1054
#endif // CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
1055

1056
// Separate std::tuple specialization
1057
#if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER)
1058
#include <tuple>
1059
namespace Catch {
1060
    namespace Detail {
1061
        template<
1062
            typename Tuple,
1063
            std::size_t N = 0,
1064
            bool = (N < std::tuple_size<Tuple>::value)
1065
            >
1066
            struct TupleElementPrinter {
1067
            static void print(const Tuple& tuple, std::ostream& os) {
1068
                os << (N ? ", " : " ")
1069
                    << ::Catch::Detail::stringify(std::get<N>(tuple));
1070
                TupleElementPrinter<Tuple, N + 1>::print(tuple, os);
1071
            }
1072
        };
1073

1074
        template<
1075
            typename Tuple,
1076
            std::size_t N
1077
        >
1078
            struct TupleElementPrinter<Tuple, N, false> {
1079
            static void print(const Tuple&, std::ostream&) {}
1080
        };
1081

1082
    }
1083

1084
    template<typename ...Types>
1085
    struct StringMaker<std::tuple<Types...>> {
1086
        static std::string convert(const std::tuple<Types...>& tuple) {
1087
            ReusableStringStream rss;
1088
            rss << '{';
1089
            Detail::TupleElementPrinter<std::tuple<Types...>>::print(tuple, rss.get());
1090
            rss << " }";
1091
            return rss.str();
1092
        }
1093
    };
1094
}
1095
#endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
1096

1097
namespace Catch {
1098
    struct not_this_one {}; // Tag type for detecting which begin/ end are being selected
1099

1100
    // Import begin/ end from std here so they are considered alongside the fallback (...) overloads in this namespace
1101
    using std::begin;
1102
    using std::end;
1103

1104
    not_this_one begin( ... );
1105
    not_this_one end( ... );
1106

1107
    template <typename T>
1108
    struct is_range {
1109
        static const bool value =
1110
            !std::is_same<decltype(begin(std::declval<T>())), not_this_one>::value &&
1111
            !std::is_same<decltype(end(std::declval<T>())), not_this_one>::value;
1112
    };
1113

1114
#if defined(_MANAGED) // Managed types are never ranges
1115
    template <typename T>
1116
    struct is_range<T^> {
1117
        static const bool value = false;
1118
    };
1119
#endif
1120

1121
    template<typename Range>
1122
    std::string rangeToString( Range const& range ) {
1123
        return ::Catch::Detail::rangeToString( begin( range ), end( range ) );
1124
    }
1125

1126
    // Handle vector<bool> specially
1127
    template<typename Allocator>
1128
    std::string rangeToString( std::vector<bool, Allocator> const& v ) {
1129
        ReusableStringStream rss;
1130
        rss << "{ ";
1131
        bool first = true;
1132
        for( bool b : v ) {
1133
            if( first )
1134
                first = false;
1135
            else
1136
                rss << ", ";
1137
            rss << ::Catch::Detail::stringify( b );
1138
        }
1139
        rss << " }";
1140
        return rss.str();
1141
    }
1142

1143
    template<typename R>
1144
    struct StringMaker<R, typename std::enable_if<is_range<R>::value && !::Catch::Detail::IsStreamInsertable<R>::value>::type> {
1145
        static std::string convert( R const& range ) {
1146
            return rangeToString( range );
1147
        }
1148
    };
1149

1150
    template <typename T, int SZ>
1151
    struct StringMaker<T[SZ]> {
1152
        static std::string convert(T const(&arr)[SZ]) {
1153
            return rangeToString(arr);
1154
        }
1155
    };
1156

1157
} // namespace Catch
1158

1159
// Separate std::chrono::duration specialization
1160
#if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER)
1161
#include <ctime>
1162
#include <ratio>
1163
#include <chrono>
1164

1165
namespace Catch {
1166

1167
template <class Ratio>
1168
struct ratio_string {
1169
    static std::string symbol();
1170
};
1171

1172
template <class Ratio>
1173
std::string ratio_string<Ratio>::symbol() {
1174
    Catch::ReusableStringStream rss;
1175
    rss << '[' << Ratio::num << '/'
1176
        << Ratio::den << ']';
1177
    return rss.str();
1178
}
1179
template <>
1180
struct ratio_string<std::atto> {
1181
    static std::string symbol();
1182
};
1183
template <>
1184
struct ratio_string<std::femto> {
1185
    static std::string symbol();
1186
};
1187
template <>
1188
struct ratio_string<std::pico> {
1189
    static std::string symbol();
1190
};
1191
template <>
1192
struct ratio_string<std::nano> {
1193
    static std::string symbol();
1194
};
1195
template <>
1196
struct ratio_string<std::micro> {
1197
    static std::string symbol();
1198
};
1199
template <>
1200
struct ratio_string<std::milli> {
1201
    static std::string symbol();
1202
};
1203

1204
    ////////////
1205
    // std::chrono::duration specializations
1206
    template<typename Value, typename Ratio>
1207
    struct StringMaker<std::chrono::duration<Value, Ratio>> {
1208
        static std::string convert(std::chrono::duration<Value, Ratio> const& duration) {
1209
            ReusableStringStream rss;
1210
            rss << duration.count() << ' ' << ratio_string<Ratio>::symbol() << 's';
1211
            return rss.str();
1212
        }
1213
    };
1214
    template<typename Value>
1215
    struct StringMaker<std::chrono::duration<Value, std::ratio<1>>> {
1216
        static std::string convert(std::chrono::duration<Value, std::ratio<1>> const& duration) {
1217
            ReusableStringStream rss;
1218
            rss << duration.count() << " s";
1219
            return rss.str();
1220
        }
1221
    };
1222
    template<typename Value>
1223
    struct StringMaker<std::chrono::duration<Value, std::ratio<60>>> {
1224
        static std::string convert(std::chrono::duration<Value, std::ratio<60>> const& duration) {
1225
            ReusableStringStream rss;
1226
            rss << duration.count() << " m";
1227
            return rss.str();
1228
        }
1229
    };
1230
    template<typename Value>
1231
    struct StringMaker<std::chrono::duration<Value, std::ratio<3600>>> {
1232
        static std::string convert(std::chrono::duration<Value, std::ratio<3600>> const& duration) {
1233
            ReusableStringStream rss;
1234
            rss << duration.count() << " h";
1235
            return rss.str();
1236
        }
1237
    };
1238

1239
    ////////////
1240
    // std::chrono::time_point specialization
1241
    // Generic time_point cannot be specialized, only std::chrono::time_point<system_clock>
1242
    template<typename Clock, typename Duration>
1243
    struct StringMaker<std::chrono::time_point<Clock, Duration>> {
1244
        static std::string convert(std::chrono::time_point<Clock, Duration> const& time_point) {
1245
            return ::Catch::Detail::stringify(time_point.time_since_epoch()) + " since epoch";
1246
        }
1247
    };
1248
    // std::chrono::time_point<system_clock> specialization
1249
    template<typename Duration>
1250
    struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> {
1251
        static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) {
1252
            auto converted = std::chrono::system_clock::to_time_t(time_point);
1253

1254
#ifdef _MSC_VER
1255
            std::tm timeInfo = {};
1256
            gmtime_s(&timeInfo, &converted);
1257
#else
1258
            std::tm* timeInfo = std::gmtime(&converted);
1259
#endif
1260

1261
            auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");
1262
            char timeStamp[timeStampSize];
1263
            const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
1264

1265
#ifdef _MSC_VER
1266
            std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
1267
#else
1268
            std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
1269
#endif
1270
            return std::string(timeStamp);
1271
        }
1272
    };
1273
}
1274
#endif // CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
1275

1276
#ifdef _MSC_VER
1277
#pragma warning(pop)
1278
#endif
1279

1280
// end catch_tostring.h
1281
#include <iosfwd>
1282

1283
#ifdef _MSC_VER
1284
#pragma warning(push)
1285
#pragma warning(disable:4389) // '==' : signed/unsigned mismatch
1286
#pragma warning(disable:4018) // more "signed/unsigned mismatch"
1287
#pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform)
1288
#pragma warning(disable:4180) // qualifier applied to function type has no meaning
1289
#endif
1290

1291
namespace Catch {
1292

1293 1
    struct ITransientExpression {
1294 0
        auto isBinaryExpression() const -> bool { return m_isBinaryExpression; }
1295 1
        auto getResult() const -> bool { return m_result; }
1296
        virtual void streamReconstructedExpression( std::ostream &os ) const = 0;
1297

1298 1
        ITransientExpression( bool isBinaryExpression, bool result )
1299 1
        :   m_isBinaryExpression( isBinaryExpression ),
1300 1
            m_result( result )
1301 1
        {}
1302

1303
        // We don't actually need a virtual destructor, but many static analysers
1304
        // complain if it's not here :-(
1305
        virtual ~ITransientExpression();
1306

1307
        bool m_isBinaryExpression;
1308
        bool m_result;
1309

1310
    };
1311

1312
    void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs );
1313

1314
    template<typename LhsT, typename RhsT>
1315
    class BinaryExpr  : public ITransientExpression {
1316
        LhsT m_lhs;
1317
        StringRef m_op;
1318
        RhsT m_rhs;
1319

1320 0
        void streamReconstructedExpression( std::ostream &os ) const override {
1321
            formatReconstructedExpression
1322 0
                    ( os, Catch::Detail::stringify( m_lhs ), m_op, Catch::Detail::stringify( m_rhs ) );
1323
        }
1324

1325
    public:
1326 1
        BinaryExpr( bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs )
1327
        :   ITransientExpression{ true, comparisonResult },
1328
            m_lhs( lhs ),
1329
            m_op( op ),
1330 1
            m_rhs( rhs )
1331 1
        {}
1332
    };
1333

1334
    template<typename LhsT>
1335
    class UnaryExpr : public ITransientExpression {
1336
        LhsT m_lhs;
1337

1338 0
        void streamReconstructedExpression( std::ostream &os ) const override {
1339 0
            os << Catch::Detail::stringify( m_lhs );
1340
        }
1341

1342
    public:
1343 1
        explicit UnaryExpr( LhsT lhs )
1344
        :   ITransientExpression{ false, lhs ? true : false },
1345 1
            m_lhs( lhs )
1346 1
        {}
1347
    };
1348

1349
    // Specialised comparison functions to handle equality comparisons between ints and pointers (NULL deduces as an int)
1350
    template<typename LhsT, typename RhsT>
1351 1
    auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return static_cast<bool>(lhs == rhs); }
1352
    template<typename T>
1353
    auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }
1354
    template<typename T>
1355
    auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }
1356
    template<typename T>
1357
    auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }
1358
    template<typename T>
1359
    auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }
1360

1361
    template<typename LhsT, typename RhsT>
1362
    auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return static_cast<bool>(lhs != rhs); }
1363
    template<typename T>
1364
    auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }
1365
    template<typename T>
1366
    auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }
1367
    template<typename T>
1368
    auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }
1369
    template<typename T>
1370
    auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }
1371

1372
    template<typename LhsT>
1373
    class ExprLhs {
1374
        LhsT m_lhs;
1375
    public:
1376 1
        explicit ExprLhs( LhsT lhs ) : m_lhs( lhs ) {}
1377

1378
        template<typename RhsT>
1379 1
        auto operator == ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
1380 1
            return { compareEqual( m_lhs, rhs ), m_lhs, "==", rhs };
1381
        }
1382 1
        auto operator == ( bool rhs ) -> BinaryExpr<LhsT, bool> const {
1383 1
            return { m_lhs == rhs, m_lhs, "==", rhs };
1384
        }
1385

1386
        template<typename RhsT>
1387
        auto operator != ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
1388
            return { compareNotEqual( m_lhs, rhs ), m_lhs, "!=", rhs };
1389
        }
1390
        auto operator != ( bool rhs ) -> BinaryExpr<LhsT, bool> const {
1391
            return { m_lhs != rhs, m_lhs, "!=", rhs };
1392
        }
1393

1394
        template<typename RhsT>
1395 1
        auto operator > ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
1396 1
            return { static_cast<bool>(m_lhs > rhs), m_lhs, ">", rhs };
1397
        }
1398
        template<typename RhsT>
1399
        auto operator < ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
1400
            return { static_cast<bool>(m_lhs < rhs), m_lhs, "<", rhs };
1401
        }
1402
        template<typename RhsT>
1403
        auto operator >= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
1404
            return { static_cast<bool>(m_lhs >= rhs), m_lhs, ">=", rhs };
1405
        }
1406
        template<typename RhsT>
1407
        auto operator <= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
1408
            return { static_cast<bool>(m_lhs <= rhs), m_lhs, "<=", rhs };
1409
        }
1410

1411 1
        auto makeUnaryExpr() const -> UnaryExpr<LhsT> {
1412 1
            return UnaryExpr<LhsT>{ m_lhs };
1413
        }
1414
    };
1415

1416
    void handleExpression( ITransientExpression const& expr );
1417

1418
    template<typename T>
1419
    void handleExpression( ExprLhs<T> const& expr ) {
1420
        handleExpression( expr.makeUnaryExpr() );
1421
    }
1422

1423
    struct Decomposer {
1424
        template<typename T>
1425 1
        auto operator <= ( T const& lhs ) -> ExprLhs<T const&> {
1426 1
            return ExprLhs<T const&>{ lhs };
1427
        }
1428

1429 1
        auto operator <=( bool value ) -> ExprLhs<bool> {
1430 1
            return ExprLhs<bool>{ value };
1431
        }
1432
    };
1433

1434
} // end namespace Catch
1435

1436
#ifdef _MSC_VER
1437
#pragma warning(pop)
1438
#endif
1439

1440
// end catch_decomposer.h
1441
// start catch_interfaces_capture.h
1442

1443
#include <string>
1444

1445
namespace Catch {
1446

1447
    class AssertionResult;
1448
    struct AssertionInfo;
1449
    struct SectionInfo;
1450
    struct SectionEndInfo;
1451
    struct MessageInfo;
1452
    struct Counts;
1453
    struct BenchmarkInfo;
1454
    struct BenchmarkStats;
1455
    struct AssertionReaction;
1456

1457
    struct ITransientExpression;
1458

1459 1
    struct IResultCapture {
1460

1461
        virtual ~IResultCapture();
1462

1463
        virtual bool sectionStarted(    SectionInfo const& sectionInfo,
1464
                                        Counts& assertions ) = 0;
1465
        virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0;
1466
        virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0;
1467

1468
        virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0;
1469
        virtual void benchmarkEnded( BenchmarkStats const& stats ) = 0;
1470

1471
        virtual void pushScopedMessage( MessageInfo const& message ) = 0;
1472
        virtual void popScopedMessage( MessageInfo const& message ) = 0;
1473

1474
        virtual void handleFatalErrorCondition( StringRef message ) = 0;
1475

1476
        virtual void handleExpr
1477
                (   AssertionInfo const& info,
1478
                    ITransientExpression const& expr,
1479
                    AssertionReaction& reaction ) = 0;
1480
        virtual void handleMessage
1481
                (   AssertionInfo const& info,
1482
                    ResultWas::OfType resultType,
1483
                    StringRef const& message,
1484
                    AssertionReaction& reaction ) = 0;
1485
        virtual void handleUnexpectedExceptionNotThrown
1486
                (   AssertionInfo const& info,
1487
                    AssertionReaction& reaction ) = 0;
1488
        virtual void handleUnexpectedInflightException
1489
                (   AssertionInfo const& info,
1490
                    std::string const& message,
1491
                    AssertionReaction& reaction ) = 0;
1492
        virtual void handleIncomplete
1493
                (   AssertionInfo const& info ) = 0;
1494
        virtual void handleNonExpr
1495
                (   AssertionInfo const &info,
1496
                    ResultWas::OfType resultType,
1497
                    AssertionReaction &reaction ) = 0;
1498

1499
        virtual bool lastAssertionPassed() = 0;
1500
        virtual void assertionPassed() = 0;
1501

1502
        // Deprecated, do not use:
1503
        virtual std::string getCurrentTestName() const = 0;
1504
        virtual const AssertionResult* getLastResult() const = 0;
1505
        virtual void exceptionEarlyReported() = 0;
1506
    };
1507

1508
    IResultCapture& getResultCapture();
1509
}
1510

1511
// end catch_interfaces_capture.h
1512
namespace Catch {
1513

1514
    struct TestFailureException{};
1515
    struct AssertionResultData;
1516
    struct IResultCapture;
1517
    class RunContext;
1518

1519
    class LazyExpression {
1520
        friend class AssertionHandler;
1521
        friend struct AssertionStats;
1522
        friend class RunContext;
1523

1524
        ITransientExpression const* m_transientExpression = nullptr;
1525
        bool m_isNegated;
1526
    public:
1527
        LazyExpression( bool isNegated );
1528
        LazyExpression( LazyExpression const& other );
1529
        LazyExpression& operator = ( LazyExpression const& ) = delete;
1530

1531
        explicit operator bool() const;
1532

1533
        friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&;
1534
    };
1535

1536
    struct AssertionReaction {
1537
        bool shouldDebugBreak = false;
1538
        bool shouldThrow = false;
1539
    };
1540

1541
    class AssertionHandler {
1542
        AssertionInfo m_assertionInfo;
1543
        AssertionReaction m_reaction;
1544
        bool m_completed = false;
1545
        IResultCapture& m_resultCapture;
1546

1547
    public:
1548
        AssertionHandler
1549
            (   StringRef macroName,
1550
                SourceLineInfo const& lineInfo,
1551
                StringRef capturedExpression,
1552
                ResultDisposition::Flags resultDisposition );
1553 1
        ~AssertionHandler() {
1554 1
            if ( !m_completed ) {
1555 0
                m_resultCapture.handleIncomplete( m_assertionInfo );
1556
            }
1557
        }
1558

1559
        template<typename T>
1560 1
        void handleExpr( ExprLhs<T> const& expr ) {
1561 1
            handleExpr( expr.makeUnaryExpr() );
1562
        }
1563
        void handleExpr( ITransientExpression const& expr );
1564

1565
        void handleMessage(ResultWas::OfType resultType, StringRef const& message);
1566

1567
        void handleExceptionThrownAsExpected();
1568
        void handleUnexpectedExceptionNotThrown();
1569
        void handleExceptionNotThrownAsExpected();
1570
        void handleThrowingCallSkipped();
1571
        void handleUnexpectedInflightException();
1572

1573
        void complete();
1574
        void setCompleted();
1575

1576
        // query
1577
        auto allowThrows() const -> bool;
1578
    };
1579

1580
    void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString );
1581

1582
} // namespace Catch
1583

1584
// end catch_assertionhandler.h
1585
// start catch_message.h
1586

1587
#include <string>
1588

1589
namespace Catch {
1590

1591
    struct MessageInfo {
1592
        MessageInfo(    std::string const& _macroName,
1593
                        SourceLineInfo const& _lineInfo,
1594
                        ResultWas::OfType _type );
1595

1596
        std::string macroName;
1597
        std::string message;
1598
        SourceLineInfo lineInfo;
1599
        ResultWas::OfType type;
1600
        unsigned int sequence;
1601

1602
        bool operator == ( MessageInfo const& other ) const;
1603
        bool operator < ( MessageInfo const& other ) const;
1604
    private:
1605
        static unsigned int globalCount;
1606
    };
1607

1608
    struct MessageStream {
1609

1610
        template<typename T>
1611
        MessageStream& operator << ( T const& value ) {
1612
            m_stream << value;
1613
            return *this;
1614
        }
1615

1616
        ReusableStringStream m_stream;
1617
    };
1618

1619
    struct MessageBuilder : MessageStream {
1620
        MessageBuilder( std::string const& macroName,
1621
                        SourceLineInfo const& lineInfo,
1622
                        ResultWas::OfType type );
1623

1624
        template<typename T>
1625 0
        MessageBuilder& operator << ( T const& value ) {
1626 0
            m_stream << value;
1627 0
            return *this;
1628
        }
1629

1630
        MessageInfo m_info;
1631
    };
1632

1633
    class ScopedMessage {
1634
    public:
1635
        explicit ScopedMessage( MessageBuilder const& builder );
1636
        ~ScopedMessage();
1637

1638
        MessageInfo m_info;
1639
    };
1640

1641
} // end namespace Catch
1642

1643
// end catch_message.h
1644
#if !defined(CATCH_CONFIG_DISABLE)
1645

1646
#if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION)
1647
  #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__
1648
#else
1649
  #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
1650
#endif
1651

1652
#if defined(CATCH_CONFIG_FAST_COMPILE)
1653

1654
///////////////////////////////////////////////////////////////////////////////
1655
// Another way to speed-up compilation is to omit local try-catch for REQUIRE*
1656
// macros.
1657
#define INTERNAL_CATCH_TRY
1658
#define INTERNAL_CATCH_CATCH( capturer )
1659

1660
#else // CATCH_CONFIG_FAST_COMPILE
1661

1662
#define INTERNAL_CATCH_TRY try
1663
#define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.handleUnexpectedInflightException(); }
1664

1665
#endif
1666

1667
#define INTERNAL_CATCH_REACT( handler ) handler.complete();
1668

1669
///////////////////////////////////////////////////////////////////////////////
1670
#define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \
1671
    do { \
1672
        Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
1673
        INTERNAL_CATCH_TRY { \
1674
            CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
1675
            catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
1676
            CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
1677
        } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
1678
        INTERNAL_CATCH_REACT( catchAssertionHandler ) \
1679
    } while( (void)0, false && static_cast<bool>( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look
1680
    // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
1681

1682
///////////////////////////////////////////////////////////////////////////////
1683
#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
1684
    INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
1685
    if( Catch::getResultCapture().lastAssertionPassed() )
1686

1687
///////////////////////////////////////////////////////////////////////////////
1688
#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
1689
    INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
1690
    if( !Catch::getResultCapture().lastAssertionPassed() )
1691

1692
///////////////////////////////////////////////////////////////////////////////
1693
#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
1694
    do { \
1695
        Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
1696
        try { \
1697
            static_cast<void>(__VA_ARGS__); \
1698
            catchAssertionHandler.handleExceptionNotThrownAsExpected(); \
1699
        } \
1700
        catch( ... ) { \
1701
            catchAssertionHandler.handleUnexpectedInflightException(); \
1702
        } \
1703
        INTERNAL_CATCH_REACT( catchAssertionHandler ) \
1704
    } while( false )
1705

1706
///////////////////////////////////////////////////////////////////////////////
1707
#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \
1708
    do { \
1709
        Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \
1710
        if( catchAssertionHandler.allowThrows() ) \
1711
            try { \
1712
                static_cast<void>(__VA_ARGS__); \
1713
                catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
1714
            } \
1715
            catch( ... ) { \
1716
                catchAssertionHandler.handleExceptionThrownAsExpected(); \
1717
            } \
1718
        else \
1719
            catchAssertionHandler.handleThrowingCallSkipped(); \
1720
        INTERNAL_CATCH_REACT( catchAssertionHandler ) \
1721
    } while( false )
1722

1723
///////////////////////////////////////////////////////////////////////////////
1724
#define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
1725
    do { \
1726
        Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \
1727
        if( catchAssertionHandler.allowThrows() ) \
1728
            try { \
1729
                static_cast<void>(expr); \
1730
                catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
1731
            } \
1732
            catch( exceptionType const& ) { \
1733
                catchAssertionHandler.handleExceptionThrownAsExpected(); \
1734
            } \
1735
            catch( ... ) { \
1736
                catchAssertionHandler.handleUnexpectedInflightException(); \
1737
            } \
1738
        else \
1739
            catchAssertionHandler.handleThrowingCallSkipped(); \
1740
        INTERNAL_CATCH_REACT( catchAssertionHandler ) \
1741
    } while( false )
1742

1743
///////////////////////////////////////////////////////////////////////////////
1744
#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
1745
    do { \
1746
        Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
1747
        catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
1748
        INTERNAL_CATCH_REACT( catchAssertionHandler ) \
1749
    } while( false )
1750

1751
///////////////////////////////////////////////////////////////////////////////
1752
#define INTERNAL_CATCH_INFO( macroName, log ) \
1753
    Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log );
1754

1755
///////////////////////////////////////////////////////////////////////////////
1756
// Although this is matcher-based, it can be used with just a string
1757
#define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \
1758
    do { \
1759
        Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
1760
        if( catchAssertionHandler.allowThrows() ) \
1761
            try { \
1762
                static_cast<void>(__VA_ARGS__); \
1763
                catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
1764
            } \
1765
            catch( ... ) { \
1766
                Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher ); \
1767
            } \
1768
        else \
1769
            catchAssertionHandler.handleThrowingCallSkipped(); \
1770
        INTERNAL_CATCH_REACT( catchAssertionHandler ) \
1771
    } while( false )
1772

1773
#endif // CATCH_CONFIG_DISABLE
1774

1775
// end catch_capture.hpp
1776
// start catch_section.h
1777

1778
// start catch_section_info.h
1779

1780
// start catch_totals.h
1781

1782
#include <cstddef>
1783

1784
namespace Catch {
1785

1786
    struct Counts {
1787
        Counts operator - ( Counts const& other ) const;
1788
        Counts& operator += ( Counts const& other );
1789

1790
        std::size_t total() const;
1791
        bool allPassed() const;
1792
        bool allOk() const;
1793

1794
        std::size_t passed = 0;
1795
        std::size_t failed = 0;
1796
        std::size_t failedButOk = 0;
1797
    };
1798

1799
    struct Totals {
1800

1801
        Totals operator - ( Totals const& other ) const;
1802
        Totals& operator += ( Totals const& other );
1803

1804
        Totals delta( Totals const& prevTotals ) const;
1805

1806
        int error = 0;
1807
        Counts assertions;
1808
        Counts testCases;
1809
    };
1810
}
1811

1812
// end catch_totals.h
1813
#include <string>
1814

1815
namespace Catch {
1816

1817
    struct SectionInfo {
1818
        SectionInfo
1819
            (   SourceLineInfo const& _lineInfo,
1820
                std::string const& _name,
1821
                std::string const& _description = std::string() );
1822

1823
        std::string name;
1824
        std::string description;
1825
        SourceLineInfo lineInfo;
1826
    };
1827

1828
    struct SectionEndInfo {
1829
        SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds );
1830

1831
        SectionInfo sectionInfo;
1832
        Counts prevAssertions;
1833
        double durationInSeconds;
1834
    };
1835

1836
} // end namespace Catch
1837

1838
// end catch_section_info.h
1839
// start catch_timer.h
1840

1841
#include <cstdint>
1842

1843
namespace Catch {
1844

1845
    auto getCurrentNanosecondsSinceEpoch() -> uint64_t;
1846
    auto getEstimatedClockResolution() -> uint64_t;
1847

1848
    class Timer {
1849
        uint64_t m_nanoseconds = 0;
1850
    public:
1851
        void start();
1852
        auto getElapsedNanoseconds() const -> uint64_t;
1853
        auto getElapsedMicroseconds() const -> uint64_t;
1854
        auto getElapsedMilliseconds() const -> unsigned int;
1855
        auto getElapsedSeconds() const -> double;
1856
    };
1857

1858
} // namespace Catch
1859

1860
// end catch_timer.h
1861
#include <string>
1862

1863
namespace Catch {
1864

1865
    class Section : NonCopyable {
1866
    public:
1867
        Section( SectionInfo const& info );
1868
        ~Section();
1869

1870
        // This indicates whether the section should be executed or not
1871
        explicit operator bool() const;
1872

1873
    private:
1874
        SectionInfo m_info;
1875

1876
        std::string m_name;
1877
        Counts m_assertions;
1878
        bool m_sectionIncluded;
1879
        Timer m_timer;
1880
    };
1881

1882
} // end namespace Catch
1883

1884
    #define INTERNAL_CATCH_SECTION( ... ) \
1885
        if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) )
1886

1887
// end catch_section.h
1888
// start catch_benchmark.h
1889

1890
#include <cstdint>
1891
#include <string>
1892

1893
namespace Catch {
1894

1895
    class BenchmarkLooper {
1896

1897
        std::string m_name;
1898
        std::size_t m_count = 0;
1899
        std::size_t m_iterationsToRun = 1;
1900
        uint64_t m_resolution;
1901
        Timer m_timer;
1902

1903
        static auto getResolution() -> uint64_t;
1904
    public:
1905
        // Keep most of this inline as it's on the code path that is being timed
1906
        BenchmarkLooper( StringRef name )
1907
        :   m_name( name ),
1908
            m_resolution( getResolution() )
1909
        {
1910
            reportStart();
1911
            m_timer.start();
1912
        }
1913

1914
        explicit operator bool() {
1915
            if( m_count < m_iterationsToRun )
1916
                return true;
1917
            return needsMoreIterations();
1918
        }
1919

1920
        void increment() {
1921
            ++m_count;
1922
        }
1923

1924
        void reportStart();
1925
        auto needsMoreIterations() -> bool;
1926
    };
1927

1928
} // end namespace Catch
1929

1930
#define BENCHMARK( name ) \
1931
    for( Catch::BenchmarkLooper looper( name ); looper; looper.increment() )
1932

1933
// end catch_benchmark.h
1934
// start catch_interfaces_exception.h
1935

1936
// start catch_interfaces_registry_hub.h
1937

1938
#include <string>
1939
#include <memory>
1940

1941
namespace Catch {
1942

1943
    class TestCase;
1944
    struct ITestCaseRegistry;
1945
    struct IExceptionTranslatorRegistry;
1946
    struct IExceptionTranslator;
1947
    struct IReporterRegistry;
1948
    struct IReporterFactory;
1949
    struct ITagAliasRegistry;
1950
    class StartupExceptionRegistry;
1951

1952
    using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
1953

1954 1
    struct IRegistryHub {
1955
        virtual ~IRegistryHub();
1956

1957
        virtual IReporterRegistry const& getReporterRegistry() const = 0;
1958
        virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0;
1959
        virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0;
1960

1961
        virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0;
1962

1963
        virtual StartupExceptionRegistry const& getStartupExceptionRegistry() const = 0;
1964
    };
1965

1966 1
    struct IMutableRegistryHub {
1967
        virtual ~IMutableRegistryHub();
1968
        virtual void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) = 0;
1969
        virtual void registerListener( IReporterFactoryPtr const& factory ) = 0;
1970
        virtual void registerTest( TestCase const& testInfo ) = 0;
1971
        virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
1972
        virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
1973
        virtual void registerStartupException() noexcept = 0;
1974
    };
1975

1976
    IRegistryHub& getRegistryHub();
1977
    IMutableRegistryHub& getMutableRegistryHub();
1978
    void cleanUp();
1979
    std::string translateActiveException();
1980

1981
}
1982

1983
// end catch_interfaces_registry_hub.h
1984
#if defined(CATCH_CONFIG_DISABLE)
1985
    #define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \
1986
        static std::string translatorName( signature )
1987
#endif
1988

1989
#include <exception>
1990
#include <string>
1991
#include <vector>
1992

1993
namespace Catch {
1994
    using exceptionTranslateFunction = std::string(*)();
1995

1996
    struct IExceptionTranslator;
1997
    using ExceptionTranslators = std::vector<std::unique_ptr<IExceptionTranslator const>>;
1998

1999 0
    struct IExceptionTranslator {
2000
        virtual ~IExceptionTranslator();
2001
        virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
2002
    };
2003

2004 1
    struct IExceptionTranslatorRegistry {
2005
        virtual ~IExceptionTranslatorRegistry();
2006

2007
        virtual std::string translateActiveException() const = 0;
2008
    };
2009

2010
    class ExceptionTranslatorRegistrar {
2011
        template<typename T>
2012
        class ExceptionTranslator : public IExceptionTranslator {
2013
        public:
2014

2015
            ExceptionTranslator( std::string(*translateFunction)( T& ) )
2016
            : m_translateFunction( translateFunction )
2017
            {}
2018

2019
            std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override {
2020
                try {
2021
                    if( it == itEnd )
2022
                        std::rethrow_exception(std::current_exception());
2023
                    else
2024
                        return (*it)->translate( it+1, itEnd );
2025
                }
2026
                catch( T& ex ) {
2027
                    return m_translateFunction( ex );
2028
                }
2029
            }
2030

2031
        protected:
2032
            std::string(*m_translateFunction)( T& );
2033
        };
2034

2035
    public:
2036
        template<typename T>
2037
        ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) {
2038
            getMutableRegistryHub().registerTranslator
2039
                ( new ExceptionTranslator<T>( translateFunction ) );
2040
        }
2041
    };
2042
}
2043

2044
///////////////////////////////////////////////////////////////////////////////
2045
#define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
2046
    static std::string translatorName( signature ); \
2047
    CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
2048
    namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \
2049
    CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
2050
    static std::string translatorName( signature )
2051

2052
#define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
2053

2054
// end catch_interfaces_exception.h
2055
// start catch_approx.h
2056

2057
#include <type_traits>
2058
#include <stdexcept>
2059

2060
namespace Catch {
2061
namespace Detail {
2062

2063
    class Approx {
2064
    private:
2065
        bool equalityComparisonImpl(double other) const;
2066

2067
    public:
2068
        explicit Approx ( double value );
2069

2070
        static Approx custom();
2071

2072
        template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
2073
        Approx operator()( T const& value ) {
2074
            Approx approx( static_cast<double>(value) );
2075
            approx.epsilon( m_epsilon );
2076
            approx.margin( m_margin );
2077
            approx.scale( m_scale );
2078
            return approx;
2079
        }
2080

2081
        template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
2082 0
        explicit Approx( T const& value ): Approx(static_cast<double>(value))
2083 0
        {}
2084

2085
        template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
2086 1
        friend bool operator == ( const T& lhs, Approx const& rhs ) {
2087 1
            auto lhs_v = static_cast<double>(lhs);
2088 1
            return rhs.equalityComparisonImpl(lhs_v);
2089
        }
2090

2091
        template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
2092
        friend bool operator == ( Approx const& lhs, const T& rhs ) {
2093
            return operator==( rhs, lhs );
2094
        }
2095

2096
        template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
2097
        friend bool operator != ( T const& lhs, Approx const& rhs ) {
2098
            return !operator==( lhs, rhs );
2099
        }
2100

2101
        template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
2102
        friend bool operator != ( Approx const& lhs, T const& rhs ) {
2103
            return !operator==( rhs, lhs );
2104
        }
2105

2106
        template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
2107
        friend bool operator <= ( T const& lhs, Approx const& rhs ) {
2108
            return static_cast<double>(lhs) < rhs.m_value || lhs == rhs;
2109
        }
2110

2111
        template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
2112
        friend bool operator <= ( Approx const& lhs, T const& rhs ) {
2113
            return lhs.m_value < static_cast<double>(rhs) || lhs == rhs;
2114
        }
2115

2116
        template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
2117
        friend bool operator >= ( T const& lhs, Approx const& rhs ) {
2118
            return static_cast<double>(lhs) > rhs.m_value || lhs == rhs;
2119
        }
2120

2121
        template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
2122
        friend bool operator >= ( Approx const& lhs, T const& rhs ) {
2123
            return lhs.m_value > static_cast<double>(rhs) || lhs == rhs;
2124
        }
2125

2126
        template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
2127
        Approx& epsilon( T const& newEpsilon ) {
2128
            double epsilonAsDouble = static_cast<double>(newEpsilon);
2129
            if( epsilonAsDouble < 0 || epsilonAsDouble > 1.0 ) {
2130
                throw std::domain_error
2131
                    (   "Invalid Approx::epsilon: " +
2132
                        Catch::Detail::stringify( epsilonAsDouble ) +
2133
                        ", Approx::epsilon has to be between 0 and 1" );
2134
            }
2135
            m_epsilon = epsilonAsDouble;
2136
            return *this;
2137
        }
2138

2139
        template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
2140
        Approx& margin( T const& newMargin ) {
2141
            double marginAsDouble = static_cast<double>(newMargin);
2142
            if( marginAsDouble < 0 ) {
2143
                throw std::domain_error
2144
                    (   "Invalid Approx::margin: " +
2145
                         Catch::Detail::stringify( marginAsDouble ) +
2146
                         ", Approx::Margin has to be non-negative." );
2147

2148
            }
2149
            m_margin = marginAsDouble;
2150
            return *this;
2151
        }
2152

2153
        template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
2154
        Approx& scale( T const& newScale ) {
2155
            m_scale = static_cast<double>(newScale);
2156
            return *this;
2157
        }
2158

2159
        std::string toString() const;
2160

2161
    private:
2162
        double m_epsilon;
2163
        double m_margin;
2164
        double m_scale;
2165
        double m_value;
2166
    };
2167
}
2168

2169
template<>
2170
struct StringMaker<Catch::Detail::Approx> {
2171
    static std::string convert(Catch::Detail::Approx const& value);
2172
};
2173

2174
} // end namespace Catch
2175

2176
// end catch_approx.h
2177
// start catch_string_manip.h
2178

2179
#include <string>
2180
#include <iosfwd>
2181

2182
namespace Catch {
2183

2184
    bool startsWith( std::string const& s, std::string const& prefix );
2185
    bool startsWith( std::string const& s, char prefix );
2186
    bool endsWith( std::string const& s, std::string const& suffix );
2187
    bool endsWith( std::string const& s, char suffix );
2188
    bool contains( std::string const& s, std::string const& infix );
2189
    void toLowerInPlace( std::string& s );
2190
    std::string toLower( std::string const& s );
2191
    std::string trim( std::string const& str );
2192
    bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
2193

2194
    struct pluralise {
2195
        pluralise( std::size_t count, std::string const& label );
2196

2197
        friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
2198

2199
        std::size_t m_count;
2200
        std::string m_label;
2201
    };
2202
}
2203

2204
// end catch_string_manip.h
2205
#ifndef CATCH_CONFIG_DISABLE_MATCHERS
2206
// start catch_capture_matchers.h
2207

2208
// start catch_matchers.h
2209

2210
#include <string>
2211
#include <vector>
2212

2213
namespace Catch {
2214
namespace Matchers {
2215
    namespace Impl {
2216

2217
        template<typename ArgT> struct MatchAllOf;
2218
        template<typename ArgT> struct MatchAnyOf;
2219
        template<typename ArgT> struct MatchNotOf;
2220

2221 0
        class MatcherUntypedBase {
2222
        public:
2223 0
            MatcherUntypedBase() = default;
2224
            MatcherUntypedBase ( MatcherUntypedBase const& ) = default;
2225
            MatcherUntypedBase& operator = ( MatcherUntypedBase const& ) = delete;
2226
            std::string toString() const;
2227

2228
        protected:
2229
            virtual ~MatcherUntypedBase();
2230
            virtual std::string describe() const = 0;
2231
            mutable std::string m_cachedToString;
2232
        };
2233

2234
        template<typename ObjectT>
2235
        struct MatcherMethod {
2236
            virtual bool match( ObjectT const& arg ) const = 0;
2237
        };
2238
        template<typename PtrT>
2239
        struct MatcherMethod<PtrT*> {
2240
            virtual bool match( PtrT* arg ) const = 0;
2241
        };
2242

2243
        template<typename T>
2244
        struct MatcherBase : MatcherUntypedBase, MatcherMethod<T> {
2245

2246
            MatchAllOf<T> operator && ( MatcherBase const& other ) const;
2247
            MatchAnyOf<T> operator || ( MatcherBase const& other ) const;
2248
            MatchNotOf<T> operator ! () const;
2249
        };
2250

2251
        template<typename ArgT>
2252
        struct MatchAllOf : MatcherBase<ArgT> {
2253
            bool match( ArgT const& arg ) const override {
2254
                for( auto matcher : m_matchers ) {
2255
                    if (!matcher->match(arg))
2256
                        return false;
2257
                }
2258
                return true;
2259
            }
2260
            std::string describe() const override {
2261
                std::string description;
2262
                description.reserve( 4 + m_matchers.size()*32 );
2263
                description += "( ";
2264
                bool first = true;
2265
                for( auto matcher : m_matchers ) {
2266
                    if( first )
2267
                        first = false;
2268
                    else
2269
                        description += " and ";
2270
                    description += matcher->toString();
2271
                }
2272
                description += " )";
2273
                return description;
2274
            }
2275

2276
            MatchAllOf<ArgT>& operator && ( MatcherBase<ArgT> const& other ) {
2277
                m_matchers.push_back( &other );
2278
                return *this;
2279
            }
2280

2281
            std::vector<MatcherBase<ArgT> const*> m_matchers;
2282
        };
2283
        template<typename ArgT>
2284
        struct MatchAnyOf : MatcherBase<ArgT> {
2285

2286
            bool match( ArgT const& arg ) const override {
2287
                for( auto matcher : m_matchers ) {
2288
                    if (matcher->match(arg))
2289
                        return true;
2290
                }
2291
                return false;
2292
            }
2293
            std::string describe() const override {
2294
                std::string description;
2295
                description.reserve( 4 + m_matchers.size()*32 );
2296
                description += "( ";
2297
                bool first = true;
2298
                for( auto matcher : m_matchers ) {
2299
                    if( first )
2300
                        first = false;
2301
                    else
2302
                        description += " or ";
2303
                    description += matcher->toString();
2304
                }
2305
                description += " )";
2306
                return description;
2307
            }
2308

2309
            MatchAnyOf<ArgT>& operator || ( MatcherBase<ArgT> const& other ) {
2310
                m_matchers.push_back( &other );
2311
                return *this;
2312
            }
2313

2314
            std::vector<MatcherBase<ArgT> const*> m_matchers;
2315
        };
2316

2317
        template<typename ArgT>
2318
        struct MatchNotOf : MatcherBase<ArgT> {
2319

2320
            MatchNotOf( MatcherBase<ArgT> const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {}
2321

2322
            bool match( ArgT const& arg ) const override {
2323
                return !m_underlyingMatcher.match( arg );
2324
            }
2325

2326
            std::string describe() const override {
2327
                return "not " + m_underlyingMatcher.toString();
2328
            }
2329
            MatcherBase<ArgT> const& m_underlyingMatcher;
2330
        };
2331

2332
        template<typename T>
2333
        MatchAllOf<T> MatcherBase<T>::operator && ( MatcherBase const& other ) const {
2334
            return MatchAllOf<T>() && *this && other;
2335
        }
2336
        template<typename T>
2337
        MatchAnyOf<T> MatcherBase<T>::operator || ( MatcherBase const& other ) const {
2338
            return MatchAnyOf<T>() || *this || other;
2339
        }
2340
        template<typename T>
2341
        MatchNotOf<T> MatcherBase<T>::operator ! () const {
2342
            return MatchNotOf<T>( *this );
2343
        }
2344

2345
    } // namespace Impl
2346

2347
} // namespace Matchers
2348

2349
using namespace Matchers;
2350
using Matchers::Impl::MatcherBase;
2351

2352
} // namespace Catch
2353

2354
// end catch_matchers.h
2355
// start catch_matchers_floating.h
2356

2357
#include <type_traits>
2358
#include <cmath>
2359

2360
namespace Catch {
2361
namespace Matchers {
2362

2363
    namespace Floating {
2364

2365
        enum class FloatingPointKind : uint8_t;
2366

2367
        struct WithinAbsMatcher : MatcherBase<double> {
2368
            WithinAbsMatcher(double target, double margin);
2369
            bool match(double const& matchee) const override;
2370
            std::string describe() const override;
2371
        private:
2372
            double m_target;
2373
            double m_margin;
2374
        };
2375

2376
        struct WithinUlpsMatcher : MatcherBase<double> {
2377
            WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType);
2378
            bool match(double const& matchee) const override;
2379
            std::string describe() const override;
2380
        private:
2381
            double m_target;
2382
            int m_ulps;
2383
            FloatingPointKind m_type;
2384
        };
2385

2386
    } // namespace Floating
2387

2388
    // The following functions create the actual matcher objects.
2389
    // This allows the types to be inferred
2390
    Floating::WithinUlpsMatcher WithinULP(double target, int maxUlpDiff);
2391
    Floating::WithinUlpsMatcher WithinULP(float target, int maxUlpDiff);
2392
    Floating::WithinAbsMatcher WithinAbs(double target, double margin);
2393

2394
} // namespace Matchers
2395
} // namespace Catch
2396

2397
// end catch_matchers_floating.h
2398
// start catch_matchers_generic.hpp
2399

2400
#include <functional>
2401
#include <string>
2402

2403
namespace Catch {
2404
namespace Matchers {
2405
namespace Generic {
2406

2407
namespace Detail {
2408
    std::string finalizeDescription(const std::string& desc);
2409
}
2410

2411
template <typename T>
2412
class PredicateMatcher : public MatcherBase<T> {
2413
    std::function<bool(T const&)> m_predicate;
2414
    std::string m_description;
2415
public:
2416

2417
    PredicateMatcher(std::function<bool(T const&)> const& elem, std::string const& descr)
2418
        :m_predicate(std::move(elem)),
2419
        m_description(Detail::finalizeDescription(descr))
2420
    {}
2421

2422
    bool match( T const& item ) const override {
2423
        return m_predicate(item);
2424
    }
2425

2426
    std::string describe() const override {
2427
        return m_description;
2428
    }
2429
};
2430

2431
} // namespace Generic
2432

2433
    // The following functions create the actual matcher objects.
2434
    // The user has to explicitly specify type to the function, because
2435
    // infering std::function<bool(T const&)> is hard (but possible) and
2436
    // requires a lot of TMP.
2437
    template<typename T>
2438
    Generic::PredicateMatcher<T> Predicate(std::function<bool(T const&)> const& predicate, std::string const& description = "") {
2439
        return Generic::PredicateMatcher<T>(predicate, description);
2440
    }
2441

2442
} // namespace Matchers
2443
} // namespace Catch
2444

2445
// end catch_matchers_generic.hpp
2446
// start catch_matchers_string.h
2447

2448
#include <string>
2449

2450
namespace Catch {
2451
namespace Matchers {
2452

2453
    namespace StdString {
2454

2455
        struct CasedString
2456
        {
2457
            CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity );
2458
            std::string adjustString( std::string const& str ) const;
2459
            std::string caseSensitivitySuffix() const;
2460

2461
            CaseSensitive::Choice m_caseSensitivity;
2462
            std::string m_str;
2463
        };
2464

2465
        struct StringMatcherBase : MatcherBase<std::string> {
2466
            StringMatcherBase( std::string const& operation, CasedString const& comparator );
2467
            std::string describe() const override;
2468

2469
            CasedString m_comparator;
2470
            std::string m_operation;
2471
        };
2472

2473
        struct EqualsMatcher : StringMatcherBase {
2474
            EqualsMatcher( CasedString const& comparator );
2475
            bool match( std::string const& source ) const override;
2476
        };
2477
        struct ContainsMatcher : StringMatcherBase {
2478
            ContainsMatcher( CasedString const& comparator );
2479
            bool match( std::string const& source ) const override;
2480
        };
2481
        struct StartsWithMatcher : StringMatcherBase {
2482
            StartsWithMatcher( CasedString const& comparator );
2483
            bool match( std::string const& source ) const override;
2484
        };
2485
        struct EndsWithMatcher : StringMatcherBase {
2486
            EndsWithMatcher( CasedString const& comparator );
2487
            bool match( std::string const& source ) const override;
2488
        };
2489

2490
        struct RegexMatcher : MatcherBase<std::string> {
2491
            RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity );
2492
            bool match( std::string const& matchee ) const override;
2493
            std::string describe() const override;
2494

2495
        private:
2496
            std::string m_regex;
2497
            CaseSensitive::Choice m_caseSensitivity;
2498
        };
2499

2500
    } // namespace StdString
2501

2502
    // The following functions create the actual matcher objects.
2503
    // This allows the types to be inferred
2504

2505
    StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
2506
    StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
2507
    StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
2508
    StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
2509
    StdString::RegexMatcher Matches( std::string const& regex, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
2510

2511
} // namespace Matchers
2512
} // namespace Catch
2513

2514
// end catch_matchers_string.h
2515
// start catch_matchers_vector.h
2516

2517
#include <algorithm>
2518

2519
namespace Catch {
2520
namespace Matchers {
2521

2522
    namespace Vector {
2523
        namespace Detail {
2524
            template <typename InputIterator, typename T>
2525
            size_t count(InputIterator first, InputIterator last, T const& item) {
2526
                size_t cnt = 0;
2527
                for (; first != last; ++first) {
2528
                    if (*first == item) {
2529
                        ++cnt;
2530
                    }
2531
                }
2532
                return cnt;
2533
            }
2534
            template <typename InputIterator, typename T>
2535
            bool contains(InputIterator first, InputIterator last, T const& item) {
2536
                for (; first != last; ++first) {
2537
                    if (*first == item) {
2538
                        return true;
2539
                    }
2540
                }
2541
                return false;
2542
            }
2543
        }
2544

2545
        template<typename T>
2546
        struct ContainsElementMatcher : MatcherBase<std::vector<T>> {
2547

2548
            ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {}
2549

2550
            bool match(std::vector<T> const &v) const override {
2551
                for (auto const& el : v) {
2552
                    if (el == m_comparator) {
2553
                        return true;
2554
                    }
2555
                }
2556
                return false;
2557
            }
2558

2559
            std::string describe() const override {
2560
                return "Contains: " + ::Catch::Detail::stringify( m_comparator );
2561
            }
2562

2563
            T const& m_comparator;
2564
        };
2565

2566
        template<typename T>
2567
        struct ContainsMatcher : MatcherBase<std::vector<T>> {
2568

2569
            ContainsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
2570

2571
            bool match(std::vector<T> const &v) const override {
2572
                // !TBD: see note in EqualsMatcher
2573
                if (m_comparator.size() > v.size())
2574
                    return false;
2575
                for (auto const& comparator : m_comparator) {
2576
                    auto present = false;
2577
                    for (const auto& el : v) {
2578
                        if (el == comparator) {
2579
                            present = true;
2580
                            break;
2581
                        }
2582
                    }
2583
                    if (!present) {
2584
                        return false;
2585
                    }
2586
                }
2587
                return true;
2588
            }
2589
            std::string describe() const override {
2590
                return "Contains: " + ::Catch::Detail::stringify( m_comparator );
2591
            }
2592

2593
            std::vector<T> const& m_comparator;
2594
        };
2595

2596
        template<typename T>
2597
        struct EqualsMatcher : MatcherBase<std::vector<T>> {
2598

2599
            EqualsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
2600

2601
            bool match(std::vector<T> const &v) const override {
2602
                // !TBD: This currently works if all elements can be compared using !=
2603
                // - a more general approach would be via a compare template that defaults
2604
                // to using !=. but could be specialised for, e.g. std::vector<T> etc
2605
                // - then just call that directly
2606
                if (m_comparator.size() != v.size())
2607
                    return false;
2608
                for (std::size_t i = 0; i < v.size(); ++i)
2609
                    if (m_comparator[i] != v[i])
2610
                        return false;
2611
                return true;
2612
            }
2613
            std::string describe() const override {
2614
                return "Equals: " + ::Catch::Detail::stringify( m_comparator );
2615
            }
2616
            std::vector<T> const& m_comparator;
2617
        };
2618

2619
        template<typename T>
2620
        struct UnorderedEqualsMatcher : MatcherBase<std::vector<T>> {
2621
            UnorderedEqualsMatcher(std::vector<T> const& target) : m_target(target) {}
2622
            bool match(std::vector<T> const& vec) const override {
2623
                // Note: This is a reimplementation of std::is_permutation,
2624
                //       because I don't want to include <algorithm> inside the common path
2625
                if (m_target.size() != vec.size()) {
2626
                    return false;
2627
                }
2628
                auto lfirst = m_target.begin(), llast = m_target.end();
2629
                auto rfirst = vec.begin(), rlast = vec.end();
2630
                // Cut common prefix to optimize checking of permuted parts
2631
                while (lfirst != llast && *lfirst != *rfirst) {
2632
                    ++lfirst; ++rfirst;
2633
                }
2634
                if (lfirst == llast) {
2635
                    return true;
2636
                }
2637

2638
                for (auto mid = lfirst; mid != llast; ++mid) {
2639
                    // Skip already counted items
2640
                    if (Detail::contains(lfirst, mid, *mid)) {
2641
                        continue;
2642
                    }
2643
                    size_t num_vec = Detail::count(rfirst, rlast, *mid);
2644
                    if (num_vec == 0 || Detail::count(lfirst, llast, *mid) != num_vec) {
2645
                        return false;
2646
                    }
2647
                }
2648

2649
                return true;
2650
            }
2651

2652
            std::string describe() const override {
2653
                return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target);
2654
            }
2655
        private:
2656
            std::vector<T> const& m_target;
2657
        };
2658

2659
    } // namespace Vector
2660

2661
    // The following functions create the actual matcher objects.
2662
    // This allows the types to be inferred
2663

2664
    template<typename T>
2665
    Vector::ContainsMatcher<T> Contains( std::vector<T> const& comparator ) {
2666
        return Vector::ContainsMatcher<T>( comparator );
2667
    }
2668

2669
    template<typename T>
2670
    Vector::ContainsElementMatcher<T> VectorContains( T const& comparator ) {
2671
        return Vector::ContainsElementMatcher<T>( comparator );
2672
    }
2673

2674
    template<typename T>
2675
    Vector::EqualsMatcher<T> Equals( std::vector<T> const& comparator ) {
2676
        return Vector::EqualsMatcher<T>( comparator );
2677
    }
2678

2679
    template<typename T>
2680
    Vector::UnorderedEqualsMatcher<T> UnorderedEquals(std::vector<T> const& target) {
2681
        return Vector::UnorderedEqualsMatcher<T>(target);
2682
    }
2683

2684
} // namespace Matchers
2685
} // namespace Catch
2686

2687
// end catch_matchers_vector.h
2688
namespace Catch {
2689

2690
    template<typename ArgT, typename MatcherT>
2691
    class MatchExpr : public ITransientExpression {
2692
        ArgT const& m_arg;
2693
        MatcherT m_matcher;
2694
        StringRef m_matcherString;
2695
    public:
2696 0
        MatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef matcherString )
2697
        :   ITransientExpression{ true, matcher.match( arg ) },
2698
            m_arg( arg ),
2699
            m_matcher( matcher ),
2700 0
            m_matcherString( matcherString )
2701 0
        {}
2702

2703 0
        void streamReconstructedExpression( std::ostream &os ) const override {
2704 0
            auto matcherAsString = m_matcher.toString();
2705 0
            os << Catch::Detail::stringify( m_arg ) << ' ';
2706 0
            if( matcherAsString == Detail::unprintableString )
2707 0
                os << m_matcherString;
2708
            else
2709 0
                os << matcherAsString;
2710
        }
2711
    };
2712

2713
    using StringMatcher = Matchers::Impl::MatcherBase<std::string>;
2714

2715
    void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString  );
2716

2717
    template<typename ArgT, typename MatcherT>
2718
    auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef matcherString  ) -> MatchExpr<ArgT, MatcherT> {
2719
        return MatchExpr<ArgT, MatcherT>( arg, matcher, matcherString );
2720
    }
2721

2722
} // namespace Catch
2723

2724
///////////////////////////////////////////////////////////////////////////////
2725
#define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \
2726
    do { \
2727
        Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
2728
        INTERNAL_CATCH_TRY { \
2729
            catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \
2730
        } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
2731
        INTERNAL_CATCH_REACT( catchAssertionHandler ) \
2732
    } while( false )
2733

2734
///////////////////////////////////////////////////////////////////////////////
2735
#define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \
2736
    do { \
2737
        Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
2738
        if( catchAssertionHandler.allowThrows() ) \
2739
            try { \
2740
                static_cast<void>(__VA_ARGS__ ); \
2741
                catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
2742
            } \
2743
            catch( exceptionType const& ex ) { \
2744
                catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher ) ); \
2745
            } \
2746
            catch( ... ) { \
2747
                catchAssertionHandler.handleUnexpectedInflightException(); \
2748
            } \
2749
        else \
2750
            catchAssertionHandler.handleThrowingCallSkipped(); \
2751
        INTERNAL_CATCH_REACT( catchAssertionHandler ) \
2752
    } while( false )
2753

2754
// end catch_capture_matchers.h
2755
#endif
2756

2757
// These files are included here so the single_include script doesn't put them
2758
// in the conditionally compiled sections
2759
// start catch_test_case_info.h
2760

2761
#include <string>
2762
#include <vector>
2763
#include <memory>
2764

2765
#ifdef __clang__
2766
#pragma clang diagnostic push
2767
#pragma clang diagnostic ignored "-Wpadded"
2768
#endif
2769

2770
namespace Catch {
2771

2772
    struct ITestInvoker;
2773

2774
    struct TestCaseInfo {
2775
        enum SpecialProperties{
2776
            None = 0,
2777
            IsHidden = 1 << 1,
2778
            ShouldFail = 1 << 2,
2779
            MayFail = 1 << 3,
2780
            Throws = 1 << 4,
2781
            NonPortable = 1 << 5,
2782
            Benchmark = 1 << 6
2783
        };
2784

2785
        TestCaseInfo(   std::string const& _name,
2786
                        std::string const& _className,
2787
                        std::string const& _description,
2788
                        std::vector<std::string> const& _tags,
2789
                        SourceLineInfo const& _lineInfo );
2790

2791
        friend void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags );
2792

2793
        bool isHidden() const;
2794
        bool throws() const;
2795
        bool okToFail() const;
2796
        bool expectedToFail() const;
2797

2798
        std::string tagsAsString() const;
2799

2800
        std::string name;
2801
        std::string className;
2802
        std::string description;
2803
        std::vector<std::string> tags;
2804
        std::vector<std::string> lcaseTags;
2805
        SourceLineInfo lineInfo;
2806
        SpecialProperties properties;
2807
    };
2808

2809
    class TestCase : public TestCaseInfo {
2810
    public:
2811

2812
        TestCase( ITestInvoker* testCase, TestCaseInfo&& info );
2813

2814
        TestCase withName( std::string const& _newName ) const;
2815

2816
        void invoke() const;
2817

2818
        TestCaseInfo const& getTestCaseInfo() const;
2819

2820
        bool operator == ( TestCase const& other ) const;
2821
        bool operator < ( TestCase const& other ) const;
2822

2823
    private:
2824
        std::shared_ptr<ITestInvoker> test;
2825
    };
2826

2827
    TestCase makeTestCase(  ITestInvoker* testCase,
2828
                            std::string const& className,
2829
                            NameAndTags const& nameAndTags,
2830
                            SourceLineInfo const& lineInfo );
2831
}
2832

2833
#ifdef __clang__
2834
#pragma clang diagnostic pop
2835
#endif
2836

2837
// end catch_test_case_info.h
2838
// start catch_interfaces_runner.h
2839

2840
namespace Catch {
2841

2842 1
    struct IRunner {
2843
        virtual ~IRunner();
2844
        virtual bool aborting() const = 0;
2845
    };
2846
}
2847

2848
// end catch_interfaces_runner.h
2849

2850
#ifdef __OBJC__
2851
// start catch_objc.hpp
2852

2853
#import <objc/runtime.h>
2854

2855
#include <string>
2856

2857
// NB. Any general catch headers included here must be included
2858
// in catch.hpp first to make sure they are included by the single
2859
// header for non obj-usage
2860

2861
///////////////////////////////////////////////////////////////////////////////
2862
// This protocol is really only here for (self) documenting purposes, since
2863
// all its methods are optional.
2864
@protocol OcFixture
2865

2866
@optional
2867

2868
-(void) setUp;
2869
-(void) tearDown;
2870

2871
@end
2872

2873
namespace Catch {
2874

2875
    class OcMethod : public ITestInvoker {
2876

2877
    public:
2878
        OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {}
2879

2880
        virtual void invoke() const {
2881
            id obj = [[m_cls alloc] init];
2882

2883
            performOptionalSelector( obj, @selector(setUp)  );
2884
            performOptionalSelector( obj, m_sel );
2885
            performOptionalSelector( obj, @selector(tearDown)  );
2886

2887
            arcSafeRelease( obj );
2888
        }
2889
    private:
2890
        virtual ~OcMethod() {}
2891

2892
        Class m_cls;
2893
        SEL m_sel;
2894
    };
2895

2896
    namespace Detail{
2897

2898
        inline std::string getAnnotation(   Class cls,
2899
                                            std::string const& annotationName,
2900
                                            std::string const& testCaseName ) {
2901
            NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()];
2902
            SEL sel = NSSelectorFromString( selStr );
2903
            arcSafeRelease( selStr );
2904
            id value = performOptionalSelector( cls, sel );
2905
            if( value )
2906
                return [(NSString*)value UTF8String];
2907
            return "";
2908
        }
2909
    }
2910

2911
    inline std::size_t registerTestMethods() {
2912
        std::size_t noTestMethods = 0;
2913
        int noClasses = objc_getClassList( nullptr, 0 );
2914

2915
        Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses);
2916
        objc_getClassList( classes, noClasses );
2917

2918
        for( int c = 0; c < noClasses; c++ ) {
2919
            Class cls = classes[c];
2920
            {
2921
                u_int count;
2922
                Method* methods = class_copyMethodList( cls, &count );
2923
                for( u_int m = 0; m < count ; m++ ) {
2924
                    SEL selector = method_getName(methods[m]);
2925
                    std::string methodName = sel_getName(selector);
2926
                    if( startsWith( methodName, "Catch_TestCase_" ) ) {
2927
                        std::string testCaseName = methodName.substr( 15 );
2928
                        std::string name = Detail::getAnnotation( cls, "Name", testCaseName );
2929
                        std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
2930
                        const char* className = class_getName( cls );
2931

2932
                        getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo("",0) ) );
2933
                        noTestMethods++;
2934
                    }
2935
                }
2936
                free(methods);
2937
            }
2938
        }
2939
        return noTestMethods;
2940
    }
2941

2942
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
2943

2944
    namespace Matchers {
2945
        namespace Impl {
2946
        namespace NSStringMatchers {
2947

2948
            struct StringHolder : MatcherBase<NSString*>{
2949
                StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
2950
                StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){}
2951
                StringHolder() {
2952
                    arcSafeRelease( m_substr );
2953
                }
2954

2955
                bool match( NSString* arg ) const override {
2956
                    return false;
2957
                }
2958

2959
                NSString* CATCH_ARC_STRONG m_substr;
2960
            };
2961

2962
            struct Equals : StringHolder {
2963
                Equals( NSString* substr ) : StringHolder( substr ){}
2964

2965
                bool match( NSString* str ) const override {
2966
                    return  (str != nil || m_substr == nil ) &&
2967
                            [str isEqualToString:m_substr];
2968
                }
2969

2970
                std::string describe() const override {
2971
                    return "equals string: " + Catch::Detail::stringify( m_substr );
2972
                }
2973
            };
2974

2975
            struct Contains : StringHolder {
2976
                Contains( NSString* substr ) : StringHolder( substr ){}
2977

2978
                bool match( NSString* str ) const {
2979
                    return  (str != nil || m_substr == nil ) &&
2980
                            [str rangeOfString:m_substr].location != NSNotFound;
2981
                }
2982

2983
                std::string describe() const override {
2984
                    return "contains string: " + Catch::Detail::stringify( m_substr );
2985
                }
2986
            };
2987

2988
            struct StartsWith : StringHolder {
2989
                StartsWith( NSString* substr ) : StringHolder( substr ){}
2990

2991
                bool match( NSString* str ) const override {
2992
                    return  (str != nil || m_substr == nil ) &&
2993
                            [str rangeOfString:m_substr].location == 0;
2994
                }
2995

2996
                std::string describe() const override {
2997
                    return "starts with: " + Catch::Detail::stringify( m_substr );
2998
                }
2999
            };
3000
            struct EndsWith : StringHolder {
3001
                EndsWith( NSString* substr ) : StringHolder( substr ){}
3002

3003
                bool match( NSString* str ) const override {
3004
                    return  (str != nil || m_substr == nil ) &&
3005
                            [str rangeOfString:m_substr].location == [str length] - [m_substr length];
3006
                }
3007

3008
                std::string describe() const override {
3009
                    return "ends with: " + Catch::Detail::stringify( m_substr );
3010
                }
3011
            };
3012

3013
        } // namespace NSStringMatchers
3014
        } // namespace Impl
3015

3016
        inline Impl::NSStringMatchers::Equals
3017
            Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
3018

3019
        inline Impl::NSStringMatchers::Contains
3020
            Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
3021

3022
        inline Impl::NSStringMatchers::StartsWith
3023
            StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
3024

3025
        inline Impl::NSStringMatchers::EndsWith
3026
            EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
3027

3028
    } // namespace Matchers
3029

3030
    using namespace Matchers;
3031

3032
#endif // CATCH_CONFIG_DISABLE_MATCHERS
3033

3034
} // namespace Catch
3035

3036
///////////////////////////////////////////////////////////////////////////////
3037
#define OC_MAKE_UNIQUE_NAME( root, uniqueSuffix ) root##uniqueSuffix
3038
#define OC_TEST_CASE2( name, desc, uniqueSuffix ) \
3039
+(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Name_test_, uniqueSuffix ) \
3040
{ \
3041
return @ name; \
3042
} \
3043
+(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Description_test_, uniqueSuffix ) \
3044
{ \
3045
return @ desc; \
3046
} \
3047
-(void) OC_MAKE_UNIQUE_NAME( Catch_TestCase_test_, uniqueSuffix )
3048

3049
#define OC_TEST_CASE( name, desc ) OC_TEST_CASE2( name, desc, __LINE__ )
3050

3051
// end catch_objc.hpp
3052
#endif
3053

3054
#ifdef CATCH_CONFIG_EXTERNAL_INTERFACES
3055
// start catch_external_interfaces.h
3056

3057
// start catch_reporter_bases.hpp
3058

3059
// start catch_interfaces_reporter.h
3060

3061
// start catch_config.hpp
3062

3063
// start catch_test_spec_parser.h
3064

3065
#ifdef __clang__
3066
#pragma clang diagnostic push
3067
#pragma clang diagnostic ignored "-Wpadded"
3068
#endif
3069

3070
// start catch_test_spec.h
3071

3072
#ifdef __clang__
3073
#pragma clang diagnostic push
3074
#pragma clang diagnostic ignored "-Wpadded"
3075
#endif
3076

3077
// start catch_wildcard_pattern.h
3078

3079
namespace Catch
3080
{
3081
    class WildcardPattern {
3082
        enum WildcardPosition {
3083
            NoWildcard = 0,
3084
            WildcardAtStart = 1,
3085
            WildcardAtEnd = 2,
3086
            WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd
3087
        };
3088

3089
    public:
3090

3091
        WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity );
3092 1
        virtual ~WildcardPattern() = default;
3093
        virtual bool matches( std::string const& str ) const;
3094

3095
    private:
3096
        std::string adjustCase( std::string const& str ) const;
3097
        CaseSensitive::Choice m_caseSensitivity;
3098
        WildcardPosition m_wildcard = NoWildcard;
3099
        std::string m_pattern;
3100
    };
3101
}
3102

3103
// end catch_wildcard_pattern.h
3104
#include <string>
3105
#include <vector>
3106
#include <memory>
3107

3108
namespace Catch {
3109

3110
    class TestSpec {
3111 1
        struct Pattern {
3112
            virtual ~Pattern();
3113
            virtual bool matches( TestCaseInfo const& testCase ) const = 0;
3114
        };
3115
        using PatternPtr = std::shared_ptr<Pattern>;
3116

3117 1
        class NamePattern : public Pattern {
3118
        public:
3119
            NamePattern( std::string const& name );
3120
            virtual ~NamePattern();
3121
            virtual bool matches( TestCaseInfo const& testCase ) const override;
3122
        private:
3123
            WildcardPattern m_wildcardPattern;
3124
        };
3125

3126 1
        class TagPattern : public Pattern {
3127
        public:
3128
            TagPattern( std::string const& tag );
3129
            virtual ~TagPattern();
3130
            virtual bool matches( TestCaseInfo const& testCase ) const override;
3131
        private:
3132
            std::string m_tag;
3133
        };
3134

3135 1
        class ExcludedPattern : public Pattern {
3136
        public:
3137
            ExcludedPattern( PatternPtr const& underlyingPattern );
3138
            virtual ~ExcludedPattern();
3139
            virtual bool matches( TestCaseInfo const& testCase ) const override;
3140
        private:
3141
            PatternPtr m_underlyingPattern;
3142
        };
3143

3144
        struct Filter {
3145
            std::vector<PatternPtr> m_patterns;
3146

3147
            bool matches( TestCaseInfo const& testCase ) const;
3148
        };
3149

3150
    public:
3151
        bool hasFilters() const;
3152
        bool matches( TestCaseInfo const& testCase ) const;
3153

3154
    private:
3155
        std::vector<Filter> m_filters;
3156

3157
        friend class TestSpecParser;
3158
    };
3159
}
3160

3161
#ifdef __clang__
3162
#pragma clang diagnostic pop
3163
#endif
3164

3165
// end catch_test_spec.h
3166
// start catch_interfaces_tag_alias_registry.h
3167

3168
#include <string>
3169

3170
namespace Catch {
3171

3172
    struct TagAlias;
3173

3174
    struct ITagAliasRegistry {
3175
        virtual ~ITagAliasRegistry();
3176
        // Nullptr if not present
3177
        virtual TagAlias const* find( std::string const& alias ) const = 0;
3178
        virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0;
3179

3180
        static ITagAliasRegistry const& get();
3181
    };
3182

3183
} // end namespace Catch
3184

3185
// end catch_interfaces_tag_alias_registry.h
3186
namespace Catch {
3187

3188
    class TestSpecParser {
3189
        enum Mode{ None, Name, QuotedName, Tag, EscapedName };
3190
        Mode m_mode = None;
3191
        bool m_exclusion = false;
3192
        std::size_t m_start = std::string::npos, m_pos = 0;
3193
        std::string m_arg;
3194
        std::vector<std::size_t> m_escapeChars;
3195
        TestSpec::Filter m_currentFilter;
3196
        TestSpec m_testSpec;
3197
        ITagAliasRegistry const* m_tagAliases = nullptr;
3198

3199
    public:
3200
        TestSpecParser( ITagAliasRegistry const& tagAliases );
3201

3202
        TestSpecParser& parse( std::string const& arg );
3203
        TestSpec testSpec();
3204

3205
    private:
3206
        void visitChar( char c );
3207
        void startNewMode( Mode mode, std::size_t start );
3208
        void escape();
3209
        std::string subString() const;
3210

3211
        template<typename T>
3212 1
        void addPattern() {
3213 1
            std::string token = subString();
3214 0
            for( std::size_t i = 0; i < m_escapeChars.size(); ++i )
3215 0
                token = token.substr( 0, m_escapeChars[i]-m_start-i ) + token.substr( m_escapeChars[i]-m_start-i+1 );
3216 1
            m_escapeChars.clear();
3217 1
            if( startsWith( token, "exclude:" ) ) {
3218 0
                m_exclusion = true;
3219 0
                token = token.substr( 8 );
3220
            }
3221 1
            if( !token.empty() ) {
3222 1
                TestSpec::PatternPtr pattern = std::make_shared<T>( token );
3223 1
                if( m_exclusion )
3224 1
                    pattern = std::make_shared<TestSpec::ExcludedPattern>( pattern );
3225 1
                m_currentFilter.m_patterns.push_back( pattern );
3226
            }
3227 1
            m_exclusion = false;
3228 1
            m_mode = None;
3229
        }
3230

3231
        void addFilter();
3232
    };
3233
    TestSpec parseTestSpec( std::string const& arg );
3234

3235
} // namespace Catch
3236

3237
#ifdef __clang__
3238
#pragma clang diagnostic pop
3239
#endif
3240

3241
// end catch_test_spec_parser.h
3242
// start catch_interfaces_config.h
3243

3244
#include <iosfwd>
3245
#include <string>
3246
#include <vector>
3247
#include <memory>
3248

3249
namespace Catch {
3250

3251
    enum class Verbosity {
3252
        Quiet = 0,
3253
        Normal,
3254
        High
3255
    };
3256

3257
    struct WarnAbout { enum What {
3258
        Nothing = 0x00,
3259
        NoAssertions = 0x01,
3260
        NoTests = 0x02
3261
    }; };
3262

3263
    struct ShowDurations { enum OrNot {
3264
        DefaultForReporter,
3265
        Always,
3266
        Never
3267
    }; };
3268
    struct RunTests { enum InWhatOrder {
3269
        InDeclarationOrder,
3270
        InLexicographicalOrder,
3271
        InRandomOrder
3272
    }; };
3273
    struct UseColour { enum YesOrNo {
3274
        Auto,
3275
        Yes,
3276
        No
3277
    }; };
3278
    struct WaitForKeypress { enum When {
3279
        Never,
3280
        BeforeStart = 1,
3281
        BeforeExit = 2,
3282
        BeforeStartAndExit = BeforeStart | BeforeExit
3283
    }; };
3284

3285
    class TestSpec;
3286

3287 1
    struct IConfig : NonCopyable {
3288

3289
        virtual ~IConfig();
3290

3291
        virtual bool allowThrows() const = 0;
3292
        virtual std::ostream& stream() const = 0;
3293
        virtual std::string name() const = 0;
3294
        virtual bool includeSuccessfulResults() const = 0;
3295
        virtual bool shouldDebugBreak() const = 0;
3296
        virtual bool warnAboutMissingAssertions() const = 0;
3297
        virtual bool warnAboutNoTests() const = 0;
3298
        virtual int abortAfter() const = 0;
3299
        virtual bool showInvisibles() const = 0;
3300
        virtual ShowDurations::OrNot showDurations() const = 0;
3301
        virtual TestSpec const& testSpec() const = 0;
3302
        virtual bool hasTestFilters() const = 0;
3303
        virtual RunTests::InWhatOrder runOrder() const = 0;
3304
        virtual unsigned int rngSeed() const = 0;
3305
        virtual int benchmarkResolutionMultiple() const = 0;
3306
        virtual UseColour::YesOrNo useColour() const = 0;
3307
        virtual std::vector<std::string> const& getSectionsToRun() const = 0;
3308
        virtual Verbosity verbosity() const = 0;
3309
    };
3310

3311
    using IConfigPtr = std::shared_ptr<IConfig const>;
3312
}
3313

3314
// end catch_interfaces_config.h
3315
// Libstdc++ doesn't like incomplete classes for unique_ptr
3316

3317
#include <memory>
3318
#include <vector>
3319
#include <string>
3320

3321
#ifndef CATCH_CONFIG_CONSOLE_WIDTH
3322
#define CATCH_CONFIG_CONSOLE_WIDTH 80
3323
#endif
3324

3325
namespace Catch {
3326

3327
    struct IStream;
3328

3329
    struct ConfigData {
3330
        bool listTests = false;
3331
        bool listTags = false;
3332
        bool listReporters = false;
3333
        bool listTestNamesOnly = false;
3334

3335
        bool showSuccessfulTests = false;
3336
        bool shouldDebugBreak = false;
3337
        bool noThrow = false;
3338
        bool showHelp = false;
3339
        bool showInvisibles = false;
3340
        bool filenamesAsTags = false;
3341
        bool libIdentify = false;
3342

3343
        int abortAfter = -1;
3344
        unsigned int rngSeed = 0;
3345
        int benchmarkResolutionMultiple = 100;
3346

3347
        Verbosity verbosity = Verbosity::Normal;
3348
        WarnAbout::What warnings = WarnAbout::Nothing;
3349
        ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter;
3350
        RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder;
3351
        UseColour::YesOrNo useColour = UseColour::Auto;
3352
        WaitForKeypress::When waitForKeypress = WaitForKeypress::Never;
3353

3354
        std::string outputFilename;
3355
        std::string name;
3356
        std::string processName;
3357

3358
        std::vector<std::string> reporterNames;
3359
        std::vector<std::string> testsOrTags;
3360
        std::vector<std::string> sectionsToRun;
3361
    };
3362

3363
    class Config : public IConfig {
3364
    public:
3365

3366
        Config() = default;
3367
        Config( ConfigData const& data );
3368 1
        virtual ~Config() = default;
3369

3370
        std::string const& getFilename() const;
3371

3372
        bool listTests() const;
3373
        bool listTestNamesOnly() const;
3374
        bool listTags() const;
3375
        bool listReporters() const;
3376

3377
        std::string getProcessName() const;
3378

3379
        std::vector<std::string> const& getReporterNames() const;
3380
        std::vector<std::string> const& getTestsOrTags() const;
3381
        std::vector<std::string> const& getSectionsToRun() const override;
3382

3383
        virtual TestSpec const& testSpec() const override;
3384
        bool hasTestFilters() const override;
3385

3386
        bool showHelp() const;
3387

3388
        // IConfig interface
3389
        bool allowThrows() const override;
3390
        std::ostream& stream() const override;
3391
        std::string name() const override;
3392
        bool includeSuccessfulResults() const override;
3393
        bool warnAboutMissingAssertions() const override;
3394
        bool warnAboutNoTests() const override;
3395
        ShowDurations::OrNot showDurations() const override;
3396
        RunTests::InWhatOrder runOrder() const override;
3397
        unsigned int rngSeed() const override;
3398
        int benchmarkResolutionMultiple() const override;
3399
        UseColour::YesOrNo useColour() const override;
3400
        bool shouldDebugBreak() const override;
3401
        int abortAfter() const override;
3402
        bool showInvisibles() const override;
3403
        Verbosity verbosity() const override;
3404

3405
    private:
3406

3407
        IStream const* openStream();
3408
        ConfigData m_data;
3409

3410
        std::unique_ptr<IStream const> m_stream;
3411
        TestSpec m_testSpec;
3412
        bool m_hasTestFilters = false;
3413
    };
3414

3415
} // end namespace Catch
3416

3417
// end catch_config.hpp
3418
// start catch_assertionresult.h
3419

3420
#include <string>
3421

3422
namespace Catch {
3423

3424
    struct AssertionResultData
3425
    {
3426
        AssertionResultData() = delete;
3427

3428
        AssertionResultData( ResultWas::OfType _resultType, LazyExpression const& _lazyExpression );
3429

3430
        std::string message;
3431
        mutable std::string reconstructedExpression;
3432
        LazyExpression lazyExpression;
3433
        ResultWas::OfType resultType;
3434

3435
        std::string reconstructExpression() const;
3436
    };
3437

3438
    class AssertionResult {
3439
    public:
3440
        AssertionResult() = delete;
3441
        AssertionResult( AssertionInfo const& info, AssertionResultData const& data );
3442

3443
        bool isOk() const;
3444
        bool succeeded() const;
3445
        ResultWas::OfType getResultType() const;
3446
        bool hasExpression() const;
3447
        bool hasMessage() const;
3448
        std::string getExpression() const;
3449
        std::string getExpressionInMacro() const;
3450
        bool hasExpandedExpression() const;
3451
        std::string getExpandedExpression() const;
3452
        std::string getMessage() const;
3453
        SourceLineInfo getSourceInfo() const;
3454
        StringRef getTestMacroName() const;
3455

3456
    //protected:
3457
        AssertionInfo m_info;
3458
        AssertionResultData m_resultData;
3459
    };
3460

3461
} // end namespace Catch
3462

3463
// end catch_assertionresult.h
3464
// start catch_option.hpp
3465

3466
namespace Catch {
3467

3468
    // An optional type
3469
    template<typename T>
3470
    class Option {
3471
    public:
3472 1
        Option() : nullableValue( nullptr ) {}
3473
        Option( T const& _value )
3474
        : nullableValue( new( storage ) T( _value ) )
3475
        {}
3476
        Option( Option const& _other )
3477
        : nullableValue( _other ? new( storage ) T( *_other ) : nullptr )
3478
        {}
3479

3480 1
        ~Option() {
3481 1
            reset();
3482
        }
3483

3484
        Option& operator= ( Option const& _other ) {
3485
            if( &_other != this ) {
3486
                reset();
3487
                if( _other )
3488
                    nullableValue = new( storage ) T( *_other );
3489
            }
3490
            return *this;
3491
        }
3492 1
        Option& operator = ( T const& _value ) {
3493 1
            reset();
3494 1
            nullableValue = new( storage ) T( _value );
3495 1
            return *this;
3496
        }
3497

3498 1
        void reset() {
3499 1
            if( nullableValue )
3500 1
                nullableValue->~T();
3501 1
            nullableValue = nullptr;
3502
        }
3503

3504 1
        T& operator*() { return *nullableValue; }
3505 0
        T const& operator*() const { return *nullableValue; }
3506 0
        T* operator->() { return nullableValue; }
3507
        const T* operator->() const { return nullableValue; }
3508

3509 1
        T valueOr( T const& defaultValue ) const {
3510 0
            return nullableValue ? *nullableValue : defaultValue;
3511
        }
3512

3513 1
        bool some() const { return nullableValue != nullptr; }
3514
        bool none() const { return nullableValue == nullptr; }
3515

3516
        bool operator !() const { return nullableValue == nullptr; }
3517 1
        explicit operator bool() const {
3518 1
            return some();
3519
        }
3520

3521
    private:
3522
        T *nullableValue;
3523
        alignas(alignof(T)) char storage[sizeof(T)];
3524
    };
3525

3526
} // end namespace Catch
3527

3528
// end catch_option.hpp
3529
#include <string>
3530
#include <iosfwd>
3531
#include <map>
3532
#include <set>
3533
#include <memory>
3534

3535
namespace Catch {
3536

3537
    struct ReporterConfig {
3538
        explicit ReporterConfig( IConfigPtr const& _fullConfig );
3539

3540
        ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream );
3541

3542
        std::ostream& stream() const;
3543
        IConfigPtr fullConfig() const;
3544

3545
    private:
3546
        std::ostream* m_stream;
3547
        IConfigPtr m_fullConfig;
3548
    };
3549

3550
    struct ReporterPreferences {
3551
        bool shouldRedirectStdOut = false;
3552
    };
3553

3554
    template<typename T>
3555
    struct LazyStat : Option<T> {
3556 1
        LazyStat& operator=( T const& _value ) {
3557 1
            Option<T>::operator=( _value );
3558 1
            used = false;
3559 1
            return *this;
3560
        }
3561 1
        void reset() {
3562 1
            Option<T>::reset();
3563 1
            used = false;
3564
        }
3565
        bool used = false;
3566
    };
3567

3568
    struct TestRunInfo {
3569
        TestRunInfo( std::string const& _name );
3570
        std::string name;
3571
    };
3572
    struct GroupInfo {
3573
        GroupInfo(  std::string const& _name,
3574
                    std::size_t _groupIndex,
3575
                    std::size_t _groupsCount );
3576

3577