catch.hpp
Go to the documentation of this file.
1 /*
2  * Catch v2.4.2
3  * Generated: 2018-10-26 21:12:29.223927
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 4
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 push
34 # pragma clang diagnostic ignored "-Wpadded"
35 # pragma clang diagnostic ignored "-Wswitch-enum"
36 # pragma clang diagnostic ignored "-Wcovered-switch-default"
37 # endif
38 #elif defined __GNUC__
39  // GCC likes to warn on REQUIREs, and we cannot suppress them
40  // locally because g++'s support for _Pragma is lacking in older,
41  // still supported, versions
42 # pragma GCC diagnostic ignored "-Wparentheses"
43 # pragma GCC diagnostic push
44 # pragma GCC diagnostic ignored "-Wunused-variable"
45 # pragma GCC diagnostic ignored "-Wpadded"
46 #endif
47 // end catch_suppress_warnings.h
48 #if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER)
49 # define CATCH_IMPL
50 # define CATCH_CONFIG_ALL_PARTS
51 #endif
52 
53 // In the impl file, we want to have access to all parts of the headers
54 // Can also be used to sanely support PCHs
55 #if defined(CATCH_CONFIG_ALL_PARTS)
56 # define CATCH_CONFIG_EXTERNAL_INTERFACES
57 # if defined(CATCH_CONFIG_DISABLE_MATCHERS)
58 # undef CATCH_CONFIG_DISABLE_MATCHERS
59 # endif
60 # if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER)
61 # define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
62 # endif
63 #endif
64 
65 #if !defined(CATCH_CONFIG_IMPL_ONLY)
66 // start catch_platform.h
67 
68 #ifdef __APPLE__
69 # include <TargetConditionals.h>
70 # if TARGET_OS_OSX == 1
71 # define CATCH_PLATFORM_MAC
72 # elif TARGET_OS_IPHONE == 1
73 # define CATCH_PLATFORM_IPHONE
74 # endif
75 
76 #elif defined(linux) || defined(__linux) || defined(__linux__)
77 # define CATCH_PLATFORM_LINUX
78 
79 #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__)
80 # define CATCH_PLATFORM_WINDOWS
81 #endif
82 
83 // end catch_platform.h
84 
85 #ifdef CATCH_IMPL
86 # ifndef CLARA_CONFIG_MAIN
87 # define CLARA_CONFIG_MAIN_NOT_DEFINED
88 # define CLARA_CONFIG_MAIN
89 # endif
90 #endif
91 
92 // start catch_user_interfaces.h
93 
94 namespace Catch {
95  unsigned int rngSeed();
96 }
97 
98 // end catch_user_interfaces.h
99 // start catch_tag_alias_autoregistrar.h
100 
101 // start catch_common.h
102 
103 // start catch_compiler_capabilities.h
104 
105 // Detect a number of compiler features - by compiler
106 // The following features are defined:
107 //
108 // CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported?
109 // CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported?
110 // CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported?
111 // CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled?
112 // ****************
113 // Note to maintainers: if new toggles are added please document them
114 // in configuration.md, too
115 // ****************
116 
117 // In general each macro has a _NO_<feature name> form
118 // (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature.
119 // Many features, at point of detection, define an _INTERNAL_ macro, so they
120 // can be combined, en-mass, with the _NO_ forms later.
121 
122 #ifdef __cplusplus
123 
124 # if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L)
125 # define CATCH_CPP14_OR_GREATER
126 # endif
127 
128 # if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L)
129 # define CATCH_CPP17_OR_GREATER
130 # endif
131 
132 #endif
133 
134 #if defined(CATCH_CPP17_OR_GREATER)
135 # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
136 #endif
137 
138 #ifdef __clang__
139 
140 # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
141  _Pragma( "clang diagnostic push" ) \
142  _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \
143  _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"")
144 # define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
145  _Pragma( "clang diagnostic pop" )
146 
147 # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
148  _Pragma( "clang diagnostic push" ) \
149  _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
150 # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
151  _Pragma( "clang diagnostic pop" )
152 
153 # define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \
154  _Pragma( "clang diagnostic push" ) \
155  _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" )
156 # define CATCH_INTERNAL_UNSUPPRESS_UNUSED_WARNINGS \
157  _Pragma( "clang diagnostic pop" )
158 
159 #endif // __clang__
160 
162 // Assume that non-Windows platforms support posix signals by default
163 #if !defined(CATCH_PLATFORM_WINDOWS)
164  #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS
165 #endif
166 
168 // We know some environments not to support full POSIX signals
169 #if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__)
170  #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
171 #endif
172 
173 #ifdef __OS400__
174 # define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS
175 # define CATCH_CONFIG_COLOUR_NONE
176 #endif
177 
179 // Android somehow still does not support std::to_string
180 #if defined(__ANDROID__)
181 # define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
182 #endif
183 
185 // Not all Windows environments support SEH properly
186 #if defined(__MINGW32__)
187 # define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH
188 #endif
189 
191 // PS4
192 #if defined(__ORBIS__)
193 # define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE
194 #endif
195 
197 // Cygwin
198 #ifdef __CYGWIN__
199 
200 // Required for some versions of Cygwin to declare gettimeofday
201 // see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin
202 # define _BSD_SOURCE
203 // some versions of cygwin (most) do not support std::to_string. Use the libstd check.
204 // https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813
205 # if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \
206  && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF))
207 
208 # define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING
209 
210 # endif
211 #endif // __CYGWIN__
212 
214 // Visual C++
215 #ifdef _MSC_VER
216 
217 # if _MSC_VER >= 1900 // Visual Studio 2015 or newer
218 # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
219 # endif
220 
221 // Universal Windows platform does not support SEH
222 // Or console colours (or console at all...)
223 # if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
224 # define CATCH_CONFIG_COLOUR_NONE
225 # else
226 # define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
227 # endif
228 
229 #endif // _MSC_VER
230 
232 // Check if we are compiled with -fno-exceptions or equivalent
233 #if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND)
234 # define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED
235 #endif
236 
238 // DJGPP
239 #ifdef __DJGPP__
240 # define CATCH_INTERNAL_CONFIG_NO_WCHAR
241 #endif // __DJGPP__
242 
244 
245 // Use of __COUNTER__ is suppressed during code analysis in
246 // CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly
247 // handled by it.
248 // Otherwise all supported compilers support COUNTER macro,
249 // but user still might want to turn it off
250 #if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L )
251  #define CATCH_INTERNAL_CONFIG_COUNTER
252 #endif
253 
255 // Check if string_view is available and usable
256 // The check is split apart to work around v140 (VS2015) preprocessor issue...
257 #if defined(__has_include)
258 #if __has_include(<string_view>) && defined(CATCH_CPP17_OR_GREATER)
259 # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW
260 #endif
261 #endif
262 
264 // Check if variant is available and usable
265 #if defined(__has_include)
266 # if __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
267 # if defined(__clang__) && (__clang_major__ < 8)
268  // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852
269  // fix should be in clang 8, workaround in libstdc++ 8.2
270 # include <ciso646>
271 # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
272 # define CATCH_CONFIG_NO_CPP17_VARIANT
273 # else
274 # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT
275 # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9)
276 # endif // defined(__clang__) && (__clang_major__ < 8)
277 # endif // __has_include(<variant>) && defined(CATCH_CPP17_OR_GREATER)
278 #endif // __has_include
279 
280 #if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
281 # define CATCH_CONFIG_COUNTER
282 #endif
283 #if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH)
284 # define CATCH_CONFIG_WINDOWS_SEH
285 #endif
286 // This is set by default, because we assume that unix compilers are posix-signal-compatible by default.
287 #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)
288 # define CATCH_CONFIG_POSIX_SIGNALS
289 #endif
290 // This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions.
291 #if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR)
292 # define CATCH_CONFIG_WCHAR
293 #endif
294 
295 #if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING)
296 # define CATCH_CONFIG_CPP11_TO_STRING
297 #endif
298 
299 #if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS)
300 # define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
301 #endif
302 
303 #if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW)
304 # define CATCH_CONFIG_CPP17_STRING_VIEW
305 #endif
306 
307 #if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT)
308 # define CATCH_CONFIG_CPP17_VARIANT
309 #endif
310 
311 #if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT)
312 # define CATCH_INTERNAL_CONFIG_NEW_CAPTURE
313 #endif
314 
315 #if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE)
316 # define CATCH_CONFIG_NEW_CAPTURE
317 #endif
318 
319 #if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
320 # define CATCH_CONFIG_DISABLE_EXCEPTIONS
321 #endif
322 
323 #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
324 # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
325 # define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
326 #endif
327 #if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS)
328 # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
329 # define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
330 #endif
331 #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS)
332 # define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS
333 # define CATCH_INTERNAL_UNSUPPRESS_UNUSED_WARNINGS
334 #endif
335 
336 #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
337 #define CATCH_TRY if ((true))
338 #define CATCH_CATCH_ALL if ((false))
339 #define CATCH_CATCH_ANON(type) if ((false))
340 #else
341 #define CATCH_TRY try
342 #define CATCH_CATCH_ALL catch (...)
343 #define CATCH_CATCH_ANON(type) catch (type)
344 #endif
345 
346 // end catch_compiler_capabilities.h
347 #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
348 #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
349 #ifdef CATCH_CONFIG_COUNTER
350 # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
351 #else
352 # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
353 #endif
354 
355 #include <iosfwd>
356 #include <string>
357 #include <cstdint>
358 
359 // We need a dummy global operator<< so we can bring it into Catch namespace later
361 std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy);
362 
363 namespace Catch {
364 
365  struct CaseSensitive { enum Choice {
367  No
368  }; };
369 
370  class NonCopyable {
371  NonCopyable( NonCopyable const& ) = delete;
372  NonCopyable( NonCopyable && ) = delete;
373  NonCopyable& operator = ( NonCopyable const& ) = delete;
374  NonCopyable& operator = ( NonCopyable && ) = delete;
375 
376  protected:
377  NonCopyable();
378  virtual ~NonCopyable();
379  };
380 
381  struct SourceLineInfo {
382 
383  SourceLineInfo() = delete;
384  SourceLineInfo( char const* _file, std::size_t _line ) noexcept
385  : file( _file ),
386  line( _line )
387  {}
388 
389  SourceLineInfo( SourceLineInfo const& other ) = default;
390  SourceLineInfo( SourceLineInfo && ) = default;
391  SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
392  SourceLineInfo& operator = ( SourceLineInfo && ) = default;
393 
394  bool empty() const noexcept;
395  bool operator == ( SourceLineInfo const& other ) const noexcept;
396  bool operator < ( SourceLineInfo const& other ) const noexcept;
397 
398  char const* file;
399  std::size_t line;
400  };
401 
402  std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
403 
404  // Bring in operator<< from global namespace into Catch namespace
405  // This is necessary because the overload of operator<< above makes
406  // lookup stop at namespace Catch
407  using ::operator<<;
408 
409  // Use this in variadic streaming macros to allow
410  // >> +StreamEndStop
411  // as well as
412  // >> stuff +StreamEndStop
413  struct StreamEndStop {
414  std::string operator+() const;
415  };
416  template<typename T>
417  T const& operator + ( T const& value, StreamEndStop ) {
418  return value;
419  }
420 }
421 
422 #define CATCH_INTERNAL_LINEINFO \
423  ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
424 
425 // end catch_common.h
426 namespace Catch {
427 
429  RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo );
430  };
431 
432 } // end namespace Catch
433 
434 #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \
435  CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
436  namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \
437  CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
438 
439 // end catch_tag_alias_autoregistrar.h
440 // start catch_test_registry.h
441 
442 // start catch_interfaces_testcase.h
443 
444 #include <vector>
445 #include <memory>
446 
447 namespace Catch {
448 
449  class TestSpec;
450 
451  struct ITestInvoker {
452  virtual void invoke () const = 0;
453  virtual ~ITestInvoker();
454  };
455 
456  using ITestCasePtr = std::shared_ptr<ITestInvoker>;
457 
458  class TestCase;
459  struct IConfig;
460 
462  virtual ~ITestCaseRegistry();
463  virtual std::vector<TestCase> const& getAllTests() const = 0;
464  virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const = 0;
465  };
466 
467  bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
468  std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
469  std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );
470 
471 }
472 
473 // end catch_interfaces_testcase.h
474 // start catch_stringref.h
475 
476 #include <cstddef>
477 #include <string>
478 #include <iosfwd>
479 
480 namespace Catch {
481 
482  class StringData;
483 
491  class StringRef {
492  public:
493  using size_type = std::size_t;
494 
495  private:
496  friend struct StringRefTestAccess;
497 
498  char const* m_start;
500 
501  char* m_data = nullptr;
502 
503  void takeOwnership();
504 
505  static constexpr char const* const s_empty = "";
506 
507  public: // construction/ assignment
508  StringRef() noexcept
509  : StringRef( s_empty, 0 )
510  {}
511 
512  StringRef( StringRef const& other ) noexcept
513  : m_start( other.m_start ),
514  m_size( other.m_size )
515  {}
516 
517  StringRef( StringRef&& other ) noexcept
518  : m_start( other.m_start ),
519  m_size( other.m_size ),
520  m_data( other.m_data )
521  {
522  other.m_data = nullptr;
523  }
524 
525  StringRef( char const* rawChars ) noexcept;
526 
527  StringRef( char const* rawChars, size_type size ) noexcept
528  : m_start( rawChars ),
529  m_size( size )
530  {}
531 
532  StringRef( std::string const& stdString ) noexcept
533  : m_start( stdString.c_str() ),
534  m_size( stdString.size() )
535  {}
536 
537  ~StringRef() noexcept {
538  delete[] m_data;
539  }
540 
541  auto operator = ( StringRef const &other ) noexcept -> StringRef& {
542  delete[] m_data;
543  m_data = nullptr;
544  m_start = other.m_start;
545  m_size = other.m_size;
546  return *this;
547  }
548 
549  operator std::string() const;
550 
551  void swap( StringRef& other ) noexcept;
552 
553  public: // operators
554  auto operator == ( StringRef const& other ) const noexcept -> bool;
555  auto operator != ( StringRef const& other ) const noexcept -> bool;
556 
557  auto operator[] ( size_type index ) const noexcept -> char;
558 
559  public: // named queries
560  auto empty() const noexcept -> bool {
561  return m_size == 0;
562  }
563  auto size() const noexcept -> size_type {
564  return m_size;
565  }
566 
567  auto numberOfCharacters() const noexcept -> size_type;
568  auto c_str() const -> char const*;
569 
570  public: // substrings and searches
571  auto substr( size_type start, size_type size ) const noexcept -> StringRef;
572 
573  // Returns the current start pointer.
574  // Note that the pointer can change when if the StringRef is a substring
575  auto currentData() const noexcept -> char const*;
576 
577  private: // ownership queries - may not be consistent between calls
578  auto isOwned() const noexcept -> bool;
579  auto isSubstring() const noexcept -> bool;
580  };
581 
582  auto operator + ( StringRef const& lhs, StringRef const& rhs ) -> std::string;
583  auto operator + ( StringRef const& lhs, char const* rhs ) -> std::string;
584  auto operator + ( char const* lhs, StringRef const& rhs ) -> std::string;
585 
586  auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&;
587  auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&;
588 
589  inline auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
590  return StringRef( rawChars, size );
591  }
592 
593 } // namespace Catch
594 
595 inline auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef {
596  return Catch::StringRef( rawChars, size );
597 }
598 
599 // end catch_stringref.h
600 namespace Catch {
601 
602 template<typename C>
604  void (C::*m_testAsMethod)();
605 public:
606  TestInvokerAsMethod( void (C::*testAsMethod)() ) noexcept : m_testAsMethod( testAsMethod ) {}
607 
608  void invoke() const override {
609  C obj;
610  (obj.*m_testAsMethod)();
611  }
612 };
613 
614 auto makeTestInvoker( void(*testAsFunction)() ) noexcept -> ITestInvoker*;
615 
616 template<typename C>
617 auto makeTestInvoker( void (C::*testAsMethod)() ) noexcept -> ITestInvoker* {
618  return new(std::nothrow) TestInvokerAsMethod<C>( testAsMethod );
619 }
620 
621 struct NameAndTags {
622  NameAndTags( StringRef const& name_ = StringRef(), StringRef const& tags_ = StringRef() ) noexcept;
625 };
626 
628  AutoReg( ITestInvoker* invoker, SourceLineInfo const& lineInfo, StringRef const& classOrMethod, NameAndTags const& nameAndTags ) noexcept;
629  ~AutoReg();
630 };
631 
632 } // end namespace Catch
633 
634 #define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param)
635 #define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__
636 #define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__
637 #define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF
638 
639 #if defined(CATCH_CONFIG_DISABLE)
640  #define INTERNAL_CATCH_TESTCASE_NO_REGISTRATION( TestName, ... ) \
641  static void TestName()
642  #define INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION( TestName, ClassName, ... ) \
643  namespace{ \
644  struct TestName : INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF ClassName) { \
645  void test(); \
646  }; \
647  } \
648  void TestName::test()
649 
650 #endif
651 
653  #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
654  static void TestName(); \
655  CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
656  namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
657  CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
658  static void TestName()
659  #define INTERNAL_CATCH_TESTCASE( ... ) \
660  INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ )
661 
663  #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
664  CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
665  namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
666  CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
667 
669  #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
670  CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
671  namespace{ \
672  struct TestName : INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF ClassName) { \
673  void test(); \
674  }; \
675  Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
676  } \
677  CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
678  void TestName::test()
679  #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
680  INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ )
681 
683  #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
684  CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
685  Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
686  CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
687 
688 // end catch_test_registry.h
689 // start catch_capture.hpp
690 
691 // start catch_assertionhandler.h
692 
693 // start catch_assertioninfo.h
694 
695 // start catch_result_type.h
696 
697 namespace Catch {
698 
699  // ResultWas::OfType enum
700  struct ResultWas { enum OfType {
701  Unknown = -1,
702  Ok = 0,
703  Info = 1,
704  Warning = 2,
705 
706  FailureBit = 0x10,
707 
708  ExpressionFailed = FailureBit | 1,
709  ExplicitFailure = FailureBit | 2,
710 
711  Exception = 0x100 | FailureBit,
712 
713  ThrewException = Exception | 1,
714  DidntThrowException = Exception | 2,
715 
716  FatalErrorCondition = 0x200 | FailureBit
717 
718  }; };
719 
720  bool isOk( ResultWas::OfType resultType );
721  bool isJustInfo( int flags );
722 
723  // ResultDisposition::Flags enum
724  struct ResultDisposition { enum Flags {
725  Normal = 0x01,
726 
727  ContinueOnFailure = 0x02, // Failures fail test, but execution continues
728  FalseTest = 0x04, // Prefix expression with !
729  SuppressFail = 0x08 // Failures are reported but do not fail the test
730  }; };
731 
733 
734  bool shouldContinueOnFailure( int flags );
735  inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; }
736  bool shouldSuppressFailure( int flags );
737 
738 } // end namespace Catch
739 
740 // end catch_result_type.h
741 namespace Catch {
742 
744  {
749 
750  // We want to delete this constructor but a compiler bug in 4.8 means
751  // the struct is then treated as non-aggregate
752  //AssertionInfo() = delete;
753  };
754 
755 } // end namespace Catch
756 
757 // end catch_assertioninfo.h
758 // start catch_decomposer.h
759 
760 // start catch_tostring.h
761 
762 #include <vector>
763 #include <cstddef>
764 #include <type_traits>
765 #include <string>
766 // start catch_stream.h
767 
768 #include <iosfwd>
769 #include <cstddef>
770 #include <ostream>
771 
772 namespace Catch {
773 
774  std::ostream& cout();
775  std::ostream& cerr();
776  std::ostream& clog();
777 
778  class StringRef;
779 
780  struct IStream {
781  virtual ~IStream();
782  virtual std::ostream& stream() const = 0;
783  };
784 
785  auto makeStream( StringRef const &filename ) -> IStream const*;
786 
788  std::size_t m_index;
789  std::ostream* m_oss;
790  public:
793 
794  auto str() const -> std::string;
795 
796  template<typename T>
797  auto operator << ( T const& value ) -> ReusableStringStream& {
798  *m_oss << value;
799  return *this;
800  }
801  auto get() -> std::ostream& { return *m_oss; }
802  };
803 }
804 
805 // end catch_stream.h
806 
807 #ifdef CATCH_CONFIG_CPP17_STRING_VIEW
808 #include <string_view>
809 #endif
810 
811 #ifdef __OBJC__
812 // start catch_objc_arc.hpp
813 
814 #import <Foundation/Foundation.h>
815 
816 #ifdef __has_feature
817 #define CATCH_ARC_ENABLED __has_feature(objc_arc)
818 #else
819 #define CATCH_ARC_ENABLED 0
820 #endif
821 
822 void arcSafeRelease( NSObject* obj );
823 id performOptionalSelector( id obj, SEL sel );
824 
825 #if !CATCH_ARC_ENABLED
826 inline void arcSafeRelease( NSObject* obj ) {
827  [obj release];
828 }
829 inline id performOptionalSelector( id obj, SEL sel ) {
830  if( [obj respondsToSelector: sel] )
831  return [obj performSelector: sel];
832  return nil;
833 }
834 #define CATCH_UNSAFE_UNRETAINED
835 #define CATCH_ARC_STRONG
836 #else
837 inline void arcSafeRelease( NSObject* ){}
838 inline id performOptionalSelector( id obj, SEL sel ) {
839 #ifdef __clang__
840 #pragma clang diagnostic push
841 #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
842 #endif
843  if( [obj respondsToSelector: sel] )
844  return [obj performSelector: sel];
845 #ifdef __clang__
846 #pragma clang diagnostic pop
847 #endif
848  return nil;
849 }
850 #define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
851 #define CATCH_ARC_STRONG __strong
852 #endif
853 
854 // end catch_objc_arc.hpp
855 #endif
856 
857 #ifdef _MSC_VER
858 #pragma warning(push)
859 #pragma warning(disable:4180) // We attempt to stream a function (address) by const&, which MSVC complains about but is harmless
860 #endif
861 
862 namespace Catch {
863  namespace Detail {
864 
865  extern const std::string unprintableString;
866 
867  std::string rawMemoryToString( const void *object, std::size_t size );
868 
869  template<typename T>
870  std::string rawMemoryToString( const T& object ) {
871  return rawMemoryToString( &object, sizeof(object) );
872  }
873 
874  template<typename T>
876  template<typename SS, typename TT>
877  static auto test(int)
878  -> decltype(std::declval<SS&>() << std::declval<TT>(), std::true_type());
879 
880  template<typename, typename>
881  static auto test(...)->std::false_type;
882 
883  public:
884  static const bool value = decltype(test<std::ostream, const T&>(0))::value;
885  };
886 
887  template<typename E>
888  std::string convertUnknownEnumToString( E e );
889 
890  template<typename T>
891  typename std::enable_if<
893  std::string>::type convertUnstreamable( T const& ) {
895  }
896  template<typename T>
897  typename std::enable_if<
899  std::string>::type convertUnstreamable(T const& ex) {
900  return ex.what();
901  }
902 
903  template<typename T>
904  typename std::enable_if<
906  , std::string>::type convertUnstreamable( T const& value ) {
907  return convertUnknownEnumToString( value );
908  }
909 
910 #if defined(_MANAGED)
911  template<typename T>
913  std::string clrReferenceToString( T^ ref ) {
914  if (ref == nullptr)
915  return std::string("null");
916  auto bytes = System::Text::Encoding::UTF8->GetBytes(ref->ToString());
917  cli::pin_ptr<System::Byte> p = &bytes[0];
918  return std::string(reinterpret_cast<char const *>(p), bytes->Length);
919  }
920 #endif
921 
922  } // namespace Detail
923 
924  // If we decide for C++14, change these to enable_if_ts
925  template <typename T, typename = void>
926  struct StringMaker {
927  template <typename Fake = T>
928  static
930  convert(const Fake& value) {
932  // NB: call using the function-like syntax to avoid ambiguity with
933  // user-defined templated operator<< under clang.
934  rss.operator<<(value);
935  return rss.str();
936  }
937 
938  template <typename Fake = T>
939  static
941  convert( const Fake& value ) {
942 #if !defined(CATCH_CONFIG_FALLBACK_STRINGIFIER)
943  return Detail::convertUnstreamable(value);
944 #else
945  return CATCH_CONFIG_FALLBACK_STRINGIFIER(value);
946 #endif
947  }
948  };
949 
950  namespace Detail {
951 
952  // This function dispatches all stringification requests inside of Catch.
953  // Should be preferably called fully qualified, like ::Catch::Detail::stringify
954  template <typename T>
955  std::string stringify(const T& e) {
956  return ::Catch::StringMaker<typename std::remove_cv<typename std::remove_reference<T>::type>::type>::convert(e);
957  }
958 
959  template<typename E>
960  std::string convertUnknownEnumToString( E e ) {
961  return ::Catch::Detail::stringify(static_cast<typename std::underlying_type<E>::type>(e));
962  }
963 
964 #if defined(_MANAGED)
965  template <typename T>
966  std::string stringify( T^ e ) {
967  return ::Catch::StringMaker<T^>::convert(e);
968  }
969 #endif
970 
971  } // namespace Detail
972 
973  // Some predefined specializations
974 
975  template<>
976  struct StringMaker<std::string> {
977  static std::string convert(const std::string& str);
978  };
979 
980 #ifdef CATCH_CONFIG_CPP17_STRING_VIEW
981  template<>
982  struct StringMaker<std::string_view> {
983  static std::string convert(std::string_view str);
984  };
985 #endif
986 
987  template<>
988  struct StringMaker<char const *> {
989  static std::string convert(char const * str);
990  };
991  template<>
992  struct StringMaker<char *> {
993  static std::string convert(char * str);
994  };
995 
996 #ifdef CATCH_CONFIG_WCHAR
997  template<>
998  struct StringMaker<std::wstring> {
999  static std::string convert(const std::wstring& wstr);
1000  };
1001 
1002 # ifdef CATCH_CONFIG_CPP17_STRING_VIEW
1003  template<>
1004  struct StringMaker<std::wstring_view> {
1005  static std::string convert(std::wstring_view str);
1006  };
1007 # endif
1008 
1009  template<>
1010  struct StringMaker<wchar_t const *> {
1011  static std::string convert(wchar_t const * str);
1012  };
1013  template<>
1014  struct StringMaker<wchar_t *> {
1015  static std::string convert(wchar_t * str);
1016  };
1017 #endif
1018 
1019  // TBD: Should we use `strnlen` to ensure that we don't go out of the buffer,
1020  // while keeping string semantics?
1021  template<int SZ>
1022  struct StringMaker<char[SZ]> {
1023  static std::string convert(char const* str) {
1024  return ::Catch::Detail::stringify(std::string{ str });
1025  }
1026  };
1027  template<int SZ>
1028  struct StringMaker<signed char[SZ]> {
1029  static std::string convert(signed char const* str) {
1030  return ::Catch::Detail::stringify(std::string{ reinterpret_cast<char const *>(str) });
1031  }
1032  };
1033  template<int SZ>
1034  struct StringMaker<unsigned char[SZ]> {
1035  static std::string convert(unsigned char const* str) {
1036  return ::Catch::Detail::stringify(std::string{ reinterpret_cast<char const *>(str) });
1037  }
1038  };
1039 
1040  template<>
1041  struct StringMaker<int> {
1042  static std::string convert(int value);
1043  };
1044  template<>
1045  struct StringMaker<long> {
1046  static std::string convert(long value);
1047  };
1048  template<>
1049  struct StringMaker<long long> {
1050  static std::string convert(long long value);
1051  };
1052  template<>
1053  struct StringMaker<unsigned int> {
1054  static std::string convert(unsigned int value);
1055  };
1056  template<>
1057  struct StringMaker<unsigned long> {
1058  static std::string convert(unsigned long value);
1059  };
1060  template<>
1061  struct StringMaker<unsigned long long> {
1062  static std::string convert(unsigned long long value);
1063  };
1064 
1065  template<>
1066  struct StringMaker<bool> {
1067  static std::string convert(bool b);
1068  };
1069 
1070  template<>
1071  struct StringMaker<char> {
1072  static std::string convert(char c);
1073  };
1074  template<>
1075  struct StringMaker<signed char> {
1076  static std::string convert(signed char c);
1077  };
1078  template<>
1079  struct StringMaker<unsigned char> {
1080  static std::string convert(unsigned char c);
1081  };
1082 
1083  template<>
1084  struct StringMaker<std::nullptr_t> {
1085  static std::string convert(std::nullptr_t);
1086  };
1087 
1088  template<>
1089  struct StringMaker<float> {
1090  static std::string convert(float value);
1091  };
1092  template<>
1093  struct StringMaker<double> {
1094  static std::string convert(double value);
1095  };
1096 
1097  template <typename T>
1098  struct StringMaker<T*> {
1099  template <typename U>
1100  static std::string convert(U* p) {
1101  if (p) {
1103  } else {
1104  return "nullptr";
1105  }
1106  }
1107  };
1108 
1109  template <typename R, typename C>
1110  struct StringMaker<R C::*> {
1111  static std::string convert(R C::* p) {
1112  if (p) {
1114  } else {
1115  return "nullptr";
1116  }
1117  }
1118  };
1119 
1120 #if defined(_MANAGED)
1121  template <typename T>
1122  struct StringMaker<T^> {
1123  static std::string convert( T^ ref ) {
1124  return ::Catch::Detail::clrReferenceToString(ref);
1125  }
1126  };
1127 #endif
1128 
1129  namespace Detail {
1130  template<typename InputIterator>
1131  std::string rangeToString(InputIterator first, InputIterator last) {
1133  rss << "{ ";
1134  if (first != last) {
1135  rss << ::Catch::Detail::stringify(*first);
1136  for (++first; first != last; ++first)
1137  rss << ", " << ::Catch::Detail::stringify(*first);
1138  }
1139  rss << " }";
1140  return rss.str();
1141  }
1142  }
1143 
1144 #ifdef __OBJC__
1145  template<>
1146  struct StringMaker<NSString*> {
1147  static std::string convert(NSString * nsstring) {
1148  if (!nsstring)
1149  return "nil";
1150  return std::string("@") + [nsstring UTF8String];
1151  }
1152  };
1153  template<>
1154  struct StringMaker<NSObject*> {
1155  static std::string convert(NSObject* nsObject) {
1156  return ::Catch::Detail::stringify([nsObject description]);
1157  }
1158 
1159  };
1160  namespace Detail {
1161  inline std::string stringify( NSString* nsstring ) {
1162  return StringMaker<NSString*>::convert( nsstring );
1163  }
1164 
1165  } // namespace Detail
1166 #endif // __OBJC__
1167 
1168 } // namespace Catch
1169 
1171 // Separate std-lib types stringification, so it can be selectively enabled
1172 // This means that we do not bring in
1173 
1174 #if defined(CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS)
1175 # define CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
1176 # define CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
1177 # define CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER
1178 # define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
1179 #endif
1180 
1181 // Separate std::pair specialization
1182 #if defined(CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER)
1183 #include <utility>
1184 namespace Catch {
1185  template<typename T1, typename T2>
1186  struct StringMaker<std::pair<T1, T2> > {
1187  static std::string convert(const std::pair<T1, T2>& pair) {
1189  rss << "{ "
1190  << ::Catch::Detail::stringify(pair.first)
1191  << ", "
1192  << ::Catch::Detail::stringify(pair.second)
1193  << " }";
1194  return rss.str();
1195  }
1196  };
1197 }
1198 #endif // CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER
1199 
1200 // Separate std::tuple specialization
1201 #if defined(CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER)
1202 #include <tuple>
1203 namespace Catch {
1204  namespace Detail {
1205  template<
1206  typename Tuple,
1207  std::size_t N = 0,
1209  >
1210  struct TupleElementPrinter {
1211  static void print(const Tuple& tuple, std::ostream& os) {
1212  os << (N ? ", " : " ")
1213  << ::Catch::Detail::stringify(std::get<N>(tuple));
1214  TupleElementPrinter<Tuple, N + 1>::print(tuple, os);
1215  }
1216  };
1217 
1218  template<
1219  typename Tuple,
1220  std::size_t N
1221  >
1222  struct TupleElementPrinter<Tuple, N, false> {
1223  static void print(const Tuple&, std::ostream&) {}
1224  };
1225 
1226  }
1227 
1228  template<typename ...Types>
1229  struct StringMaker<std::tuple<Types...>> {
1230  static std::string convert(const std::tuple<Types...>& tuple) {
1232  rss << '{';
1233  Detail::TupleElementPrinter<std::tuple<Types...>>::print(tuple, rss.get());
1234  rss << " }";
1235  return rss.str();
1236  }
1237  };
1238 }
1239 #endif // CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER
1240 
1241 #if defined(CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER) && defined(CATCH_CONFIG_CPP17_VARIANT)
1242 #include <variant>
1243 namespace Catch {
1244  template<>
1245  struct StringMaker<std::monostate> {
1246  static std::string convert(const std::monostate&) {
1247  return "{ }";
1248  }
1249  };
1250 
1251  template<typename... Elements>
1252  struct StringMaker<std::variant<Elements...>> {
1253  static std::string convert(const std::variant<Elements...>& variant) {
1254  if (variant.valueless_by_exception()) {
1255  return "{valueless variant}";
1256  } else {
1257  return std::visit(
1258  [](const auto& value) {
1260  },
1261  variant
1262  );
1263  }
1264  }
1265  };
1266 }
1267 #endif // CATCH_CONFIG_ENABLE_VARIANT_STRINGMAKER
1268 
1269 namespace Catch {
1270  struct not_this_one {}; // Tag type for detecting which begin/ end are being selected
1271 
1272  // Import begin/ end from std here so they are considered alongside the fallback (...) overloads in this namespace
1273  using std::begin;
1274  using std::end;
1275 
1276  not_this_one begin( ... );
1277  not_this_one end( ... );
1278 
1279  template <typename T>
1280  struct is_range {
1281  static const bool value =
1282  !std::is_same<decltype(begin(std::declval<T>())), not_this_one>::value &&
1283  !std::is_same<decltype(end(std::declval<T>())), not_this_one>::value;
1284  };
1285 
1286 #if defined(_MANAGED) // Managed types are never ranges
1287  template <typename T>
1288  struct is_range<T^> {
1289  static const bool value = false;
1290  };
1291 #endif
1292 
1293  template<typename Range>
1294  std::string rangeToString( Range const& range ) {
1295  return ::Catch::Detail::rangeToString( begin( range ), end( range ) );
1296  }
1297 
1298  // Handle vector<bool> specially
1299  template<typename Allocator>
1300  std::string rangeToString( std::vector<bool, Allocator> const& v ) {
1302  rss << "{ ";
1303  bool first = true;
1304  for( bool b : v ) {
1305  if( first )
1306  first = false;
1307  else
1308  rss << ", ";
1309  rss << ::Catch::Detail::stringify( b );
1310  }
1311  rss << " }";
1312  return rss.str();
1313  }
1314 
1315  template<typename R>
1316  struct StringMaker<R, typename std::enable_if<is_range<R>::value && !::Catch::Detail::IsStreamInsertable<R>::value>::type> {
1317  static std::string convert( R const& range ) {
1318  return rangeToString( range );
1319  }
1320  };
1321 
1322  template <typename T, int SZ>
1323  struct StringMaker<T[SZ]> {
1324  static std::string convert(T const(&arr)[SZ]) {
1325  return rangeToString(arr);
1326  }
1327  };
1328 
1329 } // namespace Catch
1330 
1331 // Separate std::chrono::duration specialization
1332 #if defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER)
1333 #include <ctime>
1334 #include <ratio>
1335 #include <chrono>
1336 
1337 namespace Catch {
1338 
1339 template <class Ratio>
1340 struct ratio_string {
1341  static std::string symbol();
1342 };
1343 
1344 template <class Ratio>
1345 std::string ratio_string<Ratio>::symbol() {
1347  rss << '[' << Ratio::num << '/'
1348  << Ratio::den << ']';
1349  return rss.str();
1350 }
1351 template <>
1352 struct ratio_string<std::atto> {
1353  static std::string symbol();
1354 };
1355 template <>
1356 struct ratio_string<std::femto> {
1357  static std::string symbol();
1358 };
1359 template <>
1360 struct ratio_string<std::pico> {
1361  static std::string symbol();
1362 };
1363 template <>
1364 struct ratio_string<std::nano> {
1365  static std::string symbol();
1366 };
1367 template <>
1368 struct ratio_string<std::micro> {
1369  static std::string symbol();
1370 };
1371 template <>
1372 struct ratio_string<std::milli> {
1373  static std::string symbol();
1374 };
1375 
1377  // std::chrono::duration specializations
1378  template<typename Value, typename Ratio>
1379  struct StringMaker<std::chrono::duration<Value, Ratio>> {
1380  static std::string convert(std::chrono::duration<Value, Ratio> const& duration) {
1382  rss << duration.count() << ' ' << ratio_string<Ratio>::symbol() << 's';
1383  return rss.str();
1384  }
1385  };
1386  template<typename Value>
1387  struct StringMaker<std::chrono::duration<Value, std::ratio<1>>> {
1388  static std::string convert(std::chrono::duration<Value, std::ratio<1>> const& duration) {
1390  rss << duration.count() << " s";
1391  return rss.str();
1392  }
1393  };
1394  template<typename Value>
1395  struct StringMaker<std::chrono::duration<Value, std::ratio<60>>> {
1396  static std::string convert(std::chrono::duration<Value, std::ratio<60>> const& duration) {
1398  rss << duration.count() << " m";
1399  return rss.str();
1400  }
1401  };
1402  template<typename Value>
1403  struct StringMaker<std::chrono::duration<Value, std::ratio<3600>>> {
1404  static std::string convert(std::chrono::duration<Value, std::ratio<3600>> const& duration) {
1406  rss << duration.count() << " h";
1407  return rss.str();
1408  }
1409  };
1410 
1412  // std::chrono::time_point specialization
1413  // Generic time_point cannot be specialized, only std::chrono::time_point<system_clock>
1414  template<typename Clock, typename Duration>
1415  struct StringMaker<std::chrono::time_point<Clock, Duration>> {
1416  static std::string convert(std::chrono::time_point<Clock, Duration> const& time_point) {
1417  return ::Catch::Detail::stringify(time_point.time_since_epoch()) + " since epoch";
1418  }
1419  };
1420  // std::chrono::time_point<system_clock> specialization
1421  template<typename Duration>
1422  struct StringMaker<std::chrono::time_point<std::chrono::system_clock, Duration>> {
1423  static std::string convert(std::chrono::time_point<std::chrono::system_clock, Duration> const& time_point) {
1424  auto converted = std::chrono::system_clock::to_time_t(time_point);
1425 
1426 #ifdef _MSC_VER
1427  std::tm timeInfo = {};
1428  gmtime_s(&timeInfo, &converted);
1429 #else
1430  std::tm* timeInfo = std::gmtime(&converted);
1431 #endif
1432 
1433  auto const timeStampSize = sizeof("2017-01-16T17:06:45Z");
1434  char timeStamp[timeStampSize];
1435  const char * const fmt = "%Y-%m-%dT%H:%M:%SZ";
1436 
1437 #ifdef _MSC_VER
1438  std::strftime(timeStamp, timeStampSize, fmt, &timeInfo);
1439 #else
1440  std::strftime(timeStamp, timeStampSize, fmt, timeInfo);
1441 #endif
1442  return std::string(timeStamp);
1443  }
1444  };
1445 }
1446 #endif // CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER
1447 
1448 #ifdef _MSC_VER
1449 #pragma warning(pop)
1450 #endif
1451 
1452 // end catch_tostring.h
1453 #include <iosfwd>
1454 
1455 #ifdef _MSC_VER
1456 #pragma warning(push)
1457 #pragma warning(disable:4389) // '==' : signed/unsigned mismatch
1458 #pragma warning(disable:4018) // more "signed/unsigned mismatch"
1459 #pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform)
1460 #pragma warning(disable:4180) // qualifier applied to function type has no meaning
1461 #endif
1462 
1463 namespace Catch {
1464 
1466  auto isBinaryExpression() const -> bool { return m_isBinaryExpression; }
1467  auto getResult() const -> bool { return m_result; }
1468  virtual void streamReconstructedExpression( std::ostream &os ) const = 0;
1469 
1470  ITransientExpression( bool isBinaryExpression, bool result )
1471  : m_isBinaryExpression( isBinaryExpression ),
1472  m_result( result )
1473  {}
1474 
1475  // We don't actually need a virtual destructor, but many static analysers
1476  // complain if it's not here :-(
1477  virtual ~ITransientExpression();
1478 
1480  bool m_result;
1481 
1482  };
1483 
1484  void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs );
1485 
1486  template<typename LhsT, typename RhsT>
1488  LhsT m_lhs;
1490  RhsT m_rhs;
1491 
1492  void streamReconstructedExpression( std::ostream &os ) const override {
1494  ( os, Catch::Detail::stringify( m_lhs ), m_op, Catch::Detail::stringify( m_rhs ) );
1495  }
1496 
1497  public:
1498  BinaryExpr( bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs )
1499  : ITransientExpression{ true, comparisonResult },
1500  m_lhs( lhs ),
1501  m_op( op ),
1502  m_rhs( rhs )
1503  {}
1504  };
1505 
1506  template<typename LhsT>
1508  LhsT m_lhs;
1509 
1510  void streamReconstructedExpression( std::ostream &os ) const override {
1511  os << Catch::Detail::stringify( m_lhs );
1512  }
1513 
1514  public:
1515  explicit UnaryExpr( LhsT lhs )
1516  : ITransientExpression{ false, lhs ? true : false },
1517  m_lhs( lhs )
1518  {}
1519  };
1520 
1521  // Specialised comparison functions to handle equality comparisons between ints and pointers (NULL deduces as an int)
1522  template<typename LhsT, typename RhsT>
1523  auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return static_cast<bool>(lhs == rhs); }
1524  template<typename T>
1525  auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }
1526  template<typename T>
1527  auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }
1528  template<typename T>
1529  auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }
1530  template<typename T>
1531  auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }
1532 
1533  template<typename LhsT, typename RhsT>
1534  auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return static_cast<bool>(lhs != rhs); }
1535  template<typename T>
1536  auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }
1537  template<typename T>
1538  auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }
1539  template<typename T>
1540  auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }
1541  template<typename T>
1542  auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }
1543 
1544  template<typename LhsT>
1545  class ExprLhs {
1546  LhsT m_lhs;
1547  public:
1548  explicit ExprLhs( LhsT lhs ) : m_lhs( lhs ) {}
1549 
1550  template<typename RhsT>
1551  auto operator == ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
1552  return { compareEqual( m_lhs, rhs ), m_lhs, "==", rhs };
1553  }
1554  auto operator == ( bool rhs ) -> BinaryExpr<LhsT, bool> const {
1555  return { m_lhs == rhs, m_lhs, "==", rhs };
1556  }
1557 
1558  template<typename RhsT>
1559  auto operator != ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
1560  return { compareNotEqual( m_lhs, rhs ), m_lhs, "!=", rhs };
1561  }
1562  auto operator != ( bool rhs ) -> BinaryExpr<LhsT, bool> const {
1563  return { m_lhs != rhs, m_lhs, "!=", rhs };
1564  }
1565 
1566  template<typename RhsT>
1567  auto operator > ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
1568  return { static_cast<bool>(m_lhs > rhs), m_lhs, ">", rhs };
1569  }
1570  template<typename RhsT>
1571  auto operator < ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
1572  return { static_cast<bool>(m_lhs < rhs), m_lhs, "<", rhs };
1573  }
1574  template<typename RhsT>
1575  auto operator >= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
1576  return { static_cast<bool>(m_lhs >= rhs), m_lhs, ">=", rhs };
1577  }
1578  template<typename RhsT>
1579  auto operator <= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
1580  return { static_cast<bool>(m_lhs <= rhs), m_lhs, "<=", rhs };
1581  }
1582 
1583  auto makeUnaryExpr() const -> UnaryExpr<LhsT> {
1584  return UnaryExpr<LhsT>{ m_lhs };
1585  }
1586  };
1587 
1588  void handleExpression( ITransientExpression const& expr );
1589 
1590  template<typename T>
1591  void handleExpression( ExprLhs<T> const& expr ) {
1592  handleExpression( expr.makeUnaryExpr() );
1593  }
1594 
1595  struct Decomposer {
1596  template<typename T>
1597  auto operator <= ( T const& lhs ) -> ExprLhs<T const&> {
1598  return ExprLhs<T const&>{ lhs };
1599  }
1600 
1601  auto operator <=( bool value ) -> ExprLhs<bool> {
1602  return ExprLhs<bool>{ value };
1603  }
1604  };
1605 
1606 } // end namespace Catch
1607 
1608 #ifdef _MSC_VER
1609 #pragma warning(pop)
1610 #endif
1611 
1612 // end catch_decomposer.h
1613 // start catch_interfaces_capture.h
1614 
1615 #include <string>
1616 
1617 namespace Catch {
1618 
1619  class AssertionResult;
1620  struct AssertionInfo;
1621  struct SectionInfo;
1622  struct SectionEndInfo;
1623  struct MessageInfo;
1624  struct Counts;
1625  struct BenchmarkInfo;
1626  struct BenchmarkStats;
1627  struct AssertionReaction;
1628  struct SourceLineInfo;
1629 
1630  struct ITransientExpression;
1631  struct IGeneratorTracker;
1632 
1634 
1635  virtual ~IResultCapture();
1636 
1637  virtual bool sectionStarted( SectionInfo const& sectionInfo,
1638  Counts& assertions ) = 0;
1639  virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0;
1640  virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0;
1641 
1642  virtual auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker& = 0;
1643 
1644  virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0;
1645  virtual void benchmarkEnded( BenchmarkStats const& stats ) = 0;
1646 
1647  virtual void pushScopedMessage( MessageInfo const& message ) = 0;
1648  virtual void popScopedMessage( MessageInfo const& message ) = 0;
1649 
1650  virtual void handleFatalErrorCondition( StringRef message ) = 0;
1651 
1652  virtual void handleExpr
1653  ( AssertionInfo const& info,
1654  ITransientExpression const& expr,
1655  AssertionReaction& reaction ) = 0;
1656  virtual void handleMessage
1657  ( AssertionInfo const& info,
1658  ResultWas::OfType resultType,
1659  StringRef const& message,
1660  AssertionReaction& reaction ) = 0;
1661  virtual void handleUnexpectedExceptionNotThrown
1662  ( AssertionInfo const& info,
1663  AssertionReaction& reaction ) = 0;
1664  virtual void handleUnexpectedInflightException
1665  ( AssertionInfo const& info,
1666  std::string const& message,
1667  AssertionReaction& reaction ) = 0;
1668  virtual void handleIncomplete
1669  ( AssertionInfo const& info ) = 0;
1670  virtual void handleNonExpr
1671  ( AssertionInfo const &info,
1672  ResultWas::OfType resultType,
1673  AssertionReaction &reaction ) = 0;
1674 
1675  virtual bool lastAssertionPassed() = 0;
1676  virtual void assertionPassed() = 0;
1677 
1678  // Deprecated, do not use:
1679  virtual std::string getCurrentTestName() const = 0;
1680  virtual const AssertionResult* getLastResult() const = 0;
1681  virtual void exceptionEarlyReported() = 0;
1682  };
1683 
1685 }
1686 
1687 // end catch_interfaces_capture.h
1688 namespace Catch {
1689 
1691  struct AssertionResultData;
1692  struct IResultCapture;
1693  class RunContext;
1694 
1696  friend class AssertionHandler;
1697  friend struct AssertionStats;
1698  friend class RunContext;
1699 
1700  ITransientExpression const* m_transientExpression = nullptr;
1702  public:
1703  LazyExpression( bool isNegated );
1704  LazyExpression( LazyExpression const& other );
1705  LazyExpression& operator = ( LazyExpression const& ) = delete;
1706 
1707  explicit operator bool() const;
1708 
1709  friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&;
1710  };
1711 
1713  bool shouldDebugBreak = false;
1714  bool shouldThrow = false;
1715  };
1716 
1720  bool m_completed = false;
1722 
1723  public:
1725  ( StringRef const& macroName,
1726  SourceLineInfo const& lineInfo,
1727  StringRef capturedExpression,
1728  ResultDisposition::Flags resultDisposition );
1730  if ( !m_completed ) {
1731  m_resultCapture.handleIncomplete( m_assertionInfo );
1732  }
1733  }
1734 
1735  template<typename T>
1736  void handleExpr( ExprLhs<T> const& expr ) {
1737  handleExpr( expr.makeUnaryExpr() );
1738  }
1739  void handleExpr( ITransientExpression const& expr );
1740 
1741  void handleMessage(ResultWas::OfType resultType, StringRef const& message);
1742 
1743  void handleExceptionThrownAsExpected();
1744  void handleUnexpectedExceptionNotThrown();
1745  void handleExceptionNotThrownAsExpected();
1746  void handleThrowingCallSkipped();
1747  void handleUnexpectedInflightException();
1748 
1749  void complete();
1750  void setCompleted();
1751 
1752  // query
1753  auto allowThrows() const -> bool;
1754  };
1755 
1756  void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString );
1757 
1758 } // namespace Catch
1759 
1760 // end catch_assertionhandler.h
1761 // start catch_message.h
1762 
1763 #include <string>
1764 #include <vector>
1765 
1766 namespace Catch {
1767 
1768  struct MessageInfo {
1769  MessageInfo( StringRef const& _macroName,
1770  SourceLineInfo const& _lineInfo,
1771  ResultWas::OfType _type );
1772 
1774  std::string message;
1777  unsigned int sequence;
1778 
1779  bool operator == ( MessageInfo const& other ) const;
1780  bool operator < ( MessageInfo const& other ) const;
1781  private:
1782  static unsigned int globalCount;
1783  };
1784 
1785  struct MessageStream {
1786 
1787  template<typename T>
1789  m_stream << value;
1790  return *this;
1791  }
1792 
1794  };
1795 
1797  MessageBuilder( StringRef const& macroName,
1798  SourceLineInfo const& lineInfo,
1799  ResultWas::OfType type );
1800 
1801  template<typename T>
1803  m_stream << value;
1804  return *this;
1805  }
1806 
1808  };
1809 
1811  public:
1812  explicit ScopedMessage( MessageBuilder const& builder );
1813  ~ScopedMessage();
1814 
1816  };
1817 
1818  class Capturer {
1819  std::vector<MessageInfo> m_messages;
1820  IResultCapture& m_resultCapture = getResultCapture();
1821  size_t m_captured = 0;
1822  public:
1823  Capturer( StringRef macroName, SourceLineInfo const& lineInfo, ResultWas::OfType resultType, StringRef names );
1824  ~Capturer();
1825 
1826  void captureValue( size_t index, StringRef value );
1827 
1828  template<typename T>
1829  void captureValues( size_t index, T&& value ) {
1830  captureValue( index, Catch::Detail::stringify( value ) );
1831  }
1832 
1833  template<typename T, typename... Ts>
1834  void captureValues( size_t index, T&& value, Ts&&... values ) {
1835  captureValues( index, value );
1836  captureValues( index+1, values... );
1837  }
1838  };
1839 
1840 } // end namespace Catch
1841 
1842 // end catch_message.h
1843 #if !defined(CATCH_CONFIG_DISABLE)
1844 
1845 #if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION)
1846  #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__
1847 #else
1848  #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
1849 #endif
1850 
1851 #if defined(CATCH_CONFIG_FAST_COMPILE) || defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
1852 
1854 // Another way to speed-up compilation is to omit local try-catch for REQUIRE*
1855 // macros.
1856 #define INTERNAL_CATCH_TRY
1857 #define INTERNAL_CATCH_CATCH( capturer )
1858 
1859 #else // CATCH_CONFIG_FAST_COMPILE
1860 
1861 #define INTERNAL_CATCH_TRY try
1862 #define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.handleUnexpectedInflightException(); }
1863 
1864 #endif
1865 
1866 #define INTERNAL_CATCH_REACT( handler ) handler.complete();
1867 
1869 #define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \
1870  do { \
1871  Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
1872  INTERNAL_CATCH_TRY { \
1873  CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
1874  catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
1875  CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
1876  } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
1877  INTERNAL_CATCH_REACT( catchAssertionHandler ) \
1878  } 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
1879  // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
1880 
1882 #define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
1883  INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
1884  if( Catch::getResultCapture().lastAssertionPassed() )
1885 
1887 #define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
1888  INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
1889  if( !Catch::getResultCapture().lastAssertionPassed() )
1890 
1892 #define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
1893  do { \
1894  Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
1895  try { \
1896  static_cast<void>(__VA_ARGS__); \
1897  catchAssertionHandler.handleExceptionNotThrownAsExpected(); \
1898  } \
1899  catch( ... ) { \
1900  catchAssertionHandler.handleUnexpectedInflightException(); \
1901  } \
1902  INTERNAL_CATCH_REACT( catchAssertionHandler ) \
1903  } while( false )
1904 
1906 #define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \
1907  do { \
1908  Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \
1909  if( catchAssertionHandler.allowThrows() ) \
1910  try { \
1911  static_cast<void>(__VA_ARGS__); \
1912  catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
1913  } \
1914  catch( ... ) { \
1915  catchAssertionHandler.handleExceptionThrownAsExpected(); \
1916  } \
1917  else \
1918  catchAssertionHandler.handleThrowingCallSkipped(); \
1919  INTERNAL_CATCH_REACT( catchAssertionHandler ) \
1920  } while( false )
1921 
1923 #define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
1924  do { \
1925  Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \
1926  if( catchAssertionHandler.allowThrows() ) \
1927  try { \
1928  static_cast<void>(expr); \
1929  catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
1930  } \
1931  catch( exceptionType const& ) { \
1932  catchAssertionHandler.handleExceptionThrownAsExpected(); \
1933  } \
1934  catch( ... ) { \
1935  catchAssertionHandler.handleUnexpectedInflightException(); \
1936  } \
1937  else \
1938  catchAssertionHandler.handleThrowingCallSkipped(); \
1939  INTERNAL_CATCH_REACT( catchAssertionHandler ) \
1940  } while( false )
1941 
1943 #define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
1944  do { \
1945  Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \
1946  catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
1947  INTERNAL_CATCH_REACT( catchAssertionHandler ) \
1948  } while( false )
1949 
1951 #define INTERNAL_CATCH_CAPTURE( varName, macroName, ... ) \
1952  auto varName = Catch::Capturer( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info, #__VA_ARGS__ ); \
1953  varName.captureValues( 0, __VA_ARGS__ )
1954 
1956 #define INTERNAL_CATCH_INFO( macroName, log ) \
1957  Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log );
1958 
1960 // Although this is matcher-based, it can be used with just a string
1961 #define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \
1962  do { \
1963  Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
1964  if( catchAssertionHandler.allowThrows() ) \
1965  try { \
1966  static_cast<void>(__VA_ARGS__); \
1967  catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
1968  } \
1969  catch( ... ) { \
1970  Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher##_catch_sr ); \
1971  } \
1972  else \
1973  catchAssertionHandler.handleThrowingCallSkipped(); \
1974  INTERNAL_CATCH_REACT( catchAssertionHandler ) \
1975  } while( false )
1976 
1977 #endif // CATCH_CONFIG_DISABLE
1978 
1979 // end catch_capture.hpp
1980 // start catch_section.h
1981 
1982 // start catch_section_info.h
1983 
1984 // start catch_totals.h
1985 
1986 #include <cstddef>
1987 
1988 namespace Catch {
1989 
1990  struct Counts {
1991  Counts operator - ( Counts const& other ) const;
1992  Counts& operator += ( Counts const& other );
1993 
1994  std::size_t total() const;
1995  bool allPassed() const;
1996  bool allOk() const;
1997 
1998  std::size_t passed = 0;
1999  std::size_t failed = 0;
2000  std::size_t failedButOk = 0;
2001  };
2002 
2003  struct Totals {
2004 
2005  Totals operator - ( Totals const& other ) const;
2006  Totals& operator += ( Totals const& other );
2007 
2008  Totals delta( Totals const& prevTotals ) const;
2009 
2010  int error = 0;
2013  };
2014 }
2015 
2016 // end catch_totals.h
2017 #include <string>
2018 
2019 namespace Catch {
2020 
2021  struct SectionInfo {
2022  SectionInfo
2023  ( SourceLineInfo const& _lineInfo,
2024  std::string const& _name );
2025 
2026  // Deprecated
2027  SectionInfo
2028  ( SourceLineInfo const& _lineInfo,
2029  std::string const& _name,
2030  std::string const& ) : SectionInfo( _lineInfo, _name ) {}
2031 
2032  std::string name;
2033  std::string description; // !Deprecated: this will always be empty
2035  };
2036 
2041  };
2042 
2043 } // end namespace Catch
2044 
2045 // end catch_section_info.h
2046 // start catch_timer.h
2047 
2048 #include <cstdint>
2049 
2050 namespace Catch {
2051 
2052  auto getCurrentNanosecondsSinceEpoch() -> uint64_t;
2053  auto getEstimatedClockResolution() -> uint64_t;
2054 
2055  class Timer {
2056  uint64_t m_nanoseconds = 0;
2057  public:
2058  void start();
2059  auto getElapsedNanoseconds() const -> uint64_t;
2060  auto getElapsedMicroseconds() const -> uint64_t;
2061  auto getElapsedMilliseconds() const -> unsigned int;
2062  auto getElapsedSeconds() const -> double;
2063  };
2064 
2065 } // namespace Catch
2066 
2067 // end catch_timer.h
2068 #include <string>
2069 
2070 namespace Catch {
2071 
2073  public:
2074  Section( SectionInfo const& info );
2075  ~Section();
2076 
2077  // This indicates whether the section should be executed or not
2078  explicit operator bool() const;
2079 
2080  private:
2082 
2083  std::string m_name;
2087  };
2088 
2089 } // end namespace Catch
2090 
2091 #define INTERNAL_CATCH_SECTION( ... ) \
2092  CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \
2093  if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) \
2094  CATCH_INTERNAL_UNSUPPRESS_UNUSED_WARNINGS
2095 
2096 #define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \
2097  CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \
2098  if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, (Catch::ReusableStringStream() << __VA_ARGS__).str() ) ) \
2099  CATCH_INTERNAL_UNSUPPRESS_UNUSED_WARNINGS
2100 
2101 // end catch_section.h
2102 // start catch_benchmark.h
2103 
2104 #include <cstdint>
2105 #include <string>
2106 
2107 namespace Catch {
2108 
2110 
2111  std::string m_name;
2112  std::size_t m_count = 0;
2113  std::size_t m_iterationsToRun = 1;
2114  uint64_t m_resolution;
2116 
2117  static auto getResolution() -> uint64_t;
2118  public:
2119  // Keep most of this inline as it's on the code path that is being timed
2121  : m_name( name ),
2122  m_resolution( getResolution() )
2123  {
2124  reportStart();
2125  m_timer.start();
2126  }
2127 
2128  explicit operator bool() {
2129  if( m_count < m_iterationsToRun )
2130  return true;
2131  return needsMoreIterations();
2132  }
2133 
2134  void increment() {
2135  ++m_count;
2136  }
2137 
2138  void reportStart();
2139  auto needsMoreIterations() -> bool;
2140  };
2141 
2142 } // end namespace Catch
2143 
2144 #define BENCHMARK( name ) \
2145  for( Catch::BenchmarkLooper looper( name ); looper; looper.increment() )
2146 
2147 // end catch_benchmark.h
2148 // start catch_interfaces_exception.h
2149 
2150 // start catch_interfaces_registry_hub.h
2151 
2152 #include <string>
2153 #include <memory>
2154 
2155 namespace Catch {
2156 
2157  class TestCase;
2158  struct ITestCaseRegistry;
2159  struct IExceptionTranslatorRegistry;
2160  struct IExceptionTranslator;
2161  struct IReporterRegistry;
2162  struct IReporterFactory;
2163  struct ITagAliasRegistry;
2164  class StartupExceptionRegistry;
2165 
2166  using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
2167 
2168  struct IRegistryHub {
2169  virtual ~IRegistryHub();
2170 
2171  virtual IReporterRegistry const& getReporterRegistry() const = 0;
2172  virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0;
2173  virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0;
2174 
2175  virtual IExceptionTranslatorRegistry const& getExceptionTranslatorRegistry() const = 0;
2176 
2177  virtual StartupExceptionRegistry const& getStartupExceptionRegistry() const = 0;
2178  };
2179 
2181  virtual ~IMutableRegistryHub();
2182  virtual void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) = 0;
2183  virtual void registerListener( IReporterFactoryPtr const& factory ) = 0;
2184  virtual void registerTest( TestCase const& testInfo ) = 0;
2185  virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
2186  virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
2187  virtual void registerStartupException() noexcept = 0;
2188  };
2189 
2190  IRegistryHub const& getRegistryHub();
2192  void cleanUp();
2193  std::string translateActiveException();
2194 
2195 }
2196 
2197 // end catch_interfaces_registry_hub.h
2198 #if defined(CATCH_CONFIG_DISABLE)
2199  #define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \
2200  static std::string translatorName( signature )
2201 #endif
2202 
2203 #include <exception>
2204 #include <string>
2205 #include <vector>
2206 
2207 namespace Catch {
2208  using exceptionTranslateFunction = std::string(*)();
2209 
2210  struct IExceptionTranslator;
2211  using ExceptionTranslators = std::vector<std::unique_ptr<IExceptionTranslator const>>;
2212 
2214  virtual ~IExceptionTranslator();
2215  virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
2216  };
2217 
2219  virtual ~IExceptionTranslatorRegistry();
2220 
2221  virtual std::string translateActiveException() const = 0;
2222  };
2223 
2225  template<typename T>
2227  public:
2228 
2229  ExceptionTranslator( std::string(*translateFunction)( T& ) )
2230  : m_translateFunction( translateFunction )
2231  {}
2232 
2233  std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override {
2234  try {
2235  if( it == itEnd )
2236  std::rethrow_exception(std::current_exception());
2237  else
2238  return (*it)->translate( it+1, itEnd );
2239  }
2240  catch( T& ex ) {
2241  return m_translateFunction( ex );
2242  }
2243  }
2244 
2245  protected:
2246  std::string(*m_translateFunction)( T& );
2247  };
2248 
2249  public:
2250  template<typename T>
2251  ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) {
2253  ( new ExceptionTranslator<T>( translateFunction ) );
2254  }
2255  };
2256 }
2257 
2259 #define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
2260  static std::string translatorName( signature ); \
2261  CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
2262  namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \
2263  CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
2264  static std::string translatorName( signature )
2265 
2266 #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
2267 
2268 // end catch_interfaces_exception.h
2269 // start catch_approx.h
2270 
2271 #include <type_traits>
2272 
2273 namespace Catch {
2274 namespace Detail {
2275 
2276  class Approx {
2277  private:
2278  bool equalityComparisonImpl(double other) const;
2279  // Validates the new margin (margin >= 0)
2280  // out-of-line to avoid including stdexcept in the header
2281  void setMargin(double margin);
2282  // Validates the new epsilon (0 < epsilon < 1)
2283  // out-of-line to avoid including stdexcept in the header
2284  void setEpsilon(double epsilon);
2285 
2286  public:
2287  explicit Approx ( double value );
2288 
2289  static Approx custom();
2290 
2291  Approx operator-() const;
2292 
2294  Approx operator()( T const& value ) {
2295  Approx approx( static_cast<double>(value) );
2296  approx.m_epsilon = m_epsilon;
2297  approx.m_margin = m_margin;
2298  approx.m_scale = m_scale;
2299  return approx;
2300  }
2301 
2303  explicit Approx( T const& value ): Approx(static_cast<double>(value))
2304  {}
2305 
2307  friend bool operator == ( const T& lhs, Approx const& rhs ) {
2308  auto lhs_v = static_cast<double>(lhs);
2309  return rhs.equalityComparisonImpl(lhs_v);
2310  }
2311 
2313  friend bool operator == ( Approx const& lhs, const T& rhs ) {
2314  return operator==( rhs, lhs );
2315  }
2316 
2318  friend bool operator != ( T const& lhs, Approx const& rhs ) {
2319  return !operator==( lhs, rhs );
2320  }
2321 
2323  friend bool operator != ( Approx const& lhs, T const& rhs ) {
2324  return !operator==( rhs, lhs );
2325  }
2326 
2328  friend bool operator <= ( T const& lhs, Approx const& rhs ) {
2329  return static_cast<double>(lhs) < rhs.m_value || lhs == rhs;
2330  }
2331 
2333  friend bool operator <= ( Approx const& lhs, T const& rhs ) {
2334  return lhs.m_value < static_cast<double>(rhs) || lhs == rhs;
2335  }
2336 
2338  friend bool operator >= ( T const& lhs, Approx const& rhs ) {
2339  return static_cast<double>(lhs) > rhs.m_value || lhs == rhs;
2340  }
2341 
2343  friend bool operator >= ( Approx const& lhs, T const& rhs ) {
2344  return lhs.m_value > static_cast<double>(rhs) || lhs == rhs;
2345  }
2346 
2348  Approx& epsilon( T const& newEpsilon ) {
2349  double epsilonAsDouble = static_cast<double>(newEpsilon);
2350  setEpsilon(epsilonAsDouble);
2351  return *this;
2352  }
2353 
2355  Approx& margin( T const& newMargin ) {
2356  double marginAsDouble = static_cast<double>(newMargin);
2357  setMargin(marginAsDouble);
2358  return *this;
2359  }
2360 
2362  Approx& scale( T const& newScale ) {
2363  m_scale = static_cast<double>(newScale);
2364  return *this;
2365  }
2366 
2367  std::string toString() const;
2368 
2369  private:
2370  double m_epsilon;
2371  double m_margin;
2372  double m_scale;
2373  double m_value;
2374  };
2375 } // end namespace Detail
2376 
2377 namespace literals {
2378  Detail::Approx operator "" _a(long double val);
2379  Detail::Approx operator "" _a(unsigned long long val);
2380 } // end namespace literals
2381 
2382 template<>
2384  static std::string convert(Catch::Detail::Approx const& value);
2385 };
2386 
2387 } // end namespace Catch
2388 
2389 // end catch_approx.h
2390 // start catch_string_manip.h
2391 
2392 #include <string>
2393 #include <iosfwd>
2394 
2395 namespace Catch {
2396 
2397  bool startsWith( std::string const& s, std::string const& prefix );
2398  bool startsWith( std::string const& s, char prefix );
2399  bool endsWith( std::string const& s, std::string const& suffix );
2400  bool endsWith( std::string const& s, char suffix );
2401  bool contains( std::string const& s, std::string const& infix );
2402  void toLowerInPlace( std::string& s );
2403  std::string toLower( std::string const& s );
2404  std::string trim( std::string const& str );
2405  bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
2406 
2407  struct pluralise {
2408  pluralise( std::size_t count, std::string const& label );
2409 
2410  friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
2411 
2412  std::size_t m_count;
2413  std::string m_label;
2414  };
2415 }
2416 
2417 // end catch_string_manip.h
2418 #ifndef CATCH_CONFIG_DISABLE_MATCHERS
2419 // start catch_capture_matchers.h
2420 
2421 // start catch_matchers.h
2422 
2423 #include <string>
2424 #include <vector>
2425 
2426 namespace Catch {
2427 namespace Matchers {
2428  namespace Impl {
2429 
2430  template<typename ArgT> struct MatchAllOf;
2431  template<typename ArgT> struct MatchAnyOf;
2432  template<typename ArgT> struct MatchNotOf;
2433 
2435  public:
2436  MatcherUntypedBase() = default;
2437  MatcherUntypedBase ( MatcherUntypedBase const& ) = default;
2438  MatcherUntypedBase& operator = ( MatcherUntypedBase const& ) = delete;
2439  std::string toString() const;
2440 
2441  protected:
2442  virtual ~MatcherUntypedBase();
2443  virtual std::string describe() const = 0;
2444  mutable std::string m_cachedToString;
2445  };
2446 
2447 #ifdef __clang__
2448 # pragma clang diagnostic push
2449 # pragma clang diagnostic ignored "-Wnon-virtual-dtor"
2450 #endif
2451 
2452  template<typename ObjectT>
2453  struct MatcherMethod {
2454  virtual bool match( ObjectT const& arg ) const = 0;
2455  };
2456  template<typename PtrT>
2457  struct MatcherMethod<PtrT*> {
2458  virtual bool match( PtrT* arg ) const = 0;
2459  };
2460 
2461 #ifdef __clang__
2462 # pragma clang diagnostic pop
2463 #endif
2464 
2465  template<typename T>
2467 
2468  MatchAllOf<T> operator && ( MatcherBase const& other ) const;
2469  MatchAnyOf<T> operator || ( MatcherBase const& other ) const;
2470  MatchNotOf<T> operator ! () const;
2471  };
2472 
2473  template<typename ArgT>
2474  struct MatchAllOf : MatcherBase<ArgT> {
2475  bool match( ArgT const& arg ) const override {
2476  for( auto matcher : m_matchers ) {
2477  if (!matcher->match(arg))
2478  return false;
2479  }
2480  return true;
2481  }
2482  std::string describe() const override {
2483  std::string description;
2484  description.reserve( 4 + m_matchers.size()*32 );
2485  description += "( ";
2486  bool first = true;
2487  for( auto matcher : m_matchers ) {
2488  if( first )
2489  first = false;
2490  else
2491  description += " and ";
2492  description += matcher->toString();
2493  }
2494  description += " )";
2495  return description;
2496  }
2497 
2498  MatchAllOf<ArgT>& operator && ( MatcherBase<ArgT> const& other ) {
2499  m_matchers.push_back( &other );
2500  return *this;
2501  }
2502 
2503  std::vector<MatcherBase<ArgT> const*> m_matchers;
2504  };
2505  template<typename ArgT>
2506  struct MatchAnyOf : MatcherBase<ArgT> {
2507 
2508  bool match( ArgT const& arg ) const override {
2509  for( auto matcher : m_matchers ) {
2510  if (matcher->match(arg))
2511  return true;
2512  }
2513  return false;
2514  }
2515  std::string describe() const override {
2516  std::string description;
2517  description.reserve( 4 + m_matchers.size()*32 );
2518  description += "( ";
2519  bool first = true;
2520  for( auto matcher : m_matchers ) {
2521  if( first )
2522  first = false;
2523  else
2524  description += " or ";
2525  description += matcher->toString();
2526  }
2527  description += " )";
2528  return description;
2529  }
2530 
2531  MatchAnyOf<ArgT>& operator || ( MatcherBase<ArgT> const& other ) {
2532  m_matchers.push_back( &other );
2533  return *this;
2534  }
2535 
2536  std::vector<MatcherBase<ArgT> const*> m_matchers;
2537  };
2538 
2539  template<typename ArgT>
2540  struct MatchNotOf : MatcherBase<ArgT> {
2541 
2542  MatchNotOf( MatcherBase<ArgT> const& underlyingMatcher ) : m_underlyingMatcher( underlyingMatcher ) {}
2543 
2544  bool match( ArgT const& arg ) const override {
2545  return !m_underlyingMatcher.match( arg );
2546  }
2547 
2548  std::string describe() const override {
2549  return "not " + m_underlyingMatcher.toString();
2550  }
2552  };
2553 
2554  template<typename T>
2556  return MatchAllOf<T>() && *this && other;
2557  }
2558  template<typename T>
2560  return MatchAnyOf<T>() || *this || other;
2561  }
2562  template<typename T>
2564  return MatchNotOf<T>( *this );
2565  }
2566 
2567  } // namespace Impl
2568 
2569 } // namespace Matchers
2570 
2571 using namespace Matchers;
2573 
2574 } // namespace Catch
2575 
2576 // end catch_matchers.h
2577 // start catch_matchers_floating.h
2578 
2579 #include <type_traits>
2580 #include <cmath>
2581 
2582 namespace Catch {
2583 namespace Matchers {
2584 
2585  namespace Floating {
2586 
2587  enum class FloatingPointKind : uint8_t;
2588 
2589  struct WithinAbsMatcher : MatcherBase<double> {
2590  WithinAbsMatcher(double target, double margin);
2591  bool match(double const& matchee) const override;
2592  std::string describe() const override;
2593  private:
2594  double m_target;
2595  double m_margin;
2596  };
2597 
2598  struct WithinUlpsMatcher : MatcherBase<double> {
2599  WithinUlpsMatcher(double target, int ulps, FloatingPointKind baseType);
2600  bool match(double const& matchee) const override;
2601  std::string describe() const override;
2602  private:
2603  double m_target;
2604  int m_ulps;
2605  FloatingPointKind m_type;
2606  };
2607 
2608  } // namespace Floating
2609 
2610  // The following functions create the actual matcher objects.
2611  // This allows the types to be inferred
2612  Floating::WithinUlpsMatcher WithinULP(double target, int maxUlpDiff);
2613  Floating::WithinUlpsMatcher WithinULP(float target, int maxUlpDiff);
2614  Floating::WithinAbsMatcher WithinAbs(double target, double margin);
2615 
2616 } // namespace Matchers
2617 } // namespace Catch
2618 
2619 // end catch_matchers_floating.h
2620 // start catch_matchers_generic.hpp
2621 
2622 #include <functional>
2623 #include <string>
2624 
2625 namespace Catch {
2626 namespace Matchers {
2627 namespace Generic {
2628 
2629 namespace Detail {
2630  std::string finalizeDescription(const std::string& desc);
2631 }
2632 
2633 template <typename T>
2634 class PredicateMatcher : public MatcherBase<T> {
2635  std::function<bool(T const&)> m_predicate;
2636  std::string m_description;
2637 public:
2638 
2639  PredicateMatcher(std::function<bool(T const&)> const& elem, std::string const& descr)
2640  :m_predicate(std::move(elem)),
2641  m_description(Detail::finalizeDescription(descr))
2642  {}
2643 
2644  bool match( T const& item ) const override {
2645  return m_predicate(item);
2646  }
2647 
2648  std::string describe() const override {
2649  return m_description;
2650  }
2651 };
2652 
2653 } // namespace Generic
2654 
2655  // The following functions create the actual matcher objects.
2656  // The user has to explicitly specify type to the function, because
2657  // infering std::function<bool(T const&)> is hard (but possible) and
2658  // requires a lot of TMP.
2659  template<typename T>
2660  Generic::PredicateMatcher<T> Predicate(std::function<bool(T const&)> const& predicate, std::string const& description = "") {
2661  return Generic::PredicateMatcher<T>(predicate, description);
2662  }
2663 
2664 } // namespace Matchers
2665 } // namespace Catch
2666 
2667 // end catch_matchers_generic.hpp
2668 // start catch_matchers_string.h
2669 
2670 #include <string>
2671 
2672 namespace Catch {
2673 namespace Matchers {
2674 
2675  namespace StdString {
2676 
2678  {
2679  CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity );
2680  std::string adjustString( std::string const& str ) const;
2681  std::string caseSensitivitySuffix() const;
2682 
2684  std::string m_str;
2685  };
2686 
2687  struct StringMatcherBase : MatcherBase<std::string> {
2688  StringMatcherBase( std::string const& operation, CasedString const& comparator );
2689  std::string describe() const override;
2690 
2692  std::string m_operation;
2693  };
2694 
2696  EqualsMatcher( CasedString const& comparator );
2697  bool match( std::string const& source ) const override;
2698  };
2700  ContainsMatcher( CasedString const& comparator );
2701  bool match( std::string const& source ) const override;
2702  };
2704  StartsWithMatcher( CasedString const& comparator );
2705  bool match( std::string const& source ) const override;
2706  };
2708  EndsWithMatcher( CasedString const& comparator );
2709  bool match( std::string const& source ) const override;
2710  };
2711 
2712  struct RegexMatcher : MatcherBase<std::string> {
2713  RegexMatcher( std::string regex, CaseSensitive::Choice caseSensitivity );
2714  bool match( std::string const& matchee ) const override;
2715  std::string describe() const override;
2716 
2717  private:
2718  std::string m_regex;
2720  };
2721 
2722  } // namespace StdString
2723 
2724  // The following functions create the actual matcher objects.
2725  // This allows the types to be inferred
2726 
2727  StdString::EqualsMatcher Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
2728  StdString::ContainsMatcher Contains( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
2729  StdString::EndsWithMatcher EndsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
2730  StdString::StartsWithMatcher StartsWith( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
2731  StdString::RegexMatcher Matches( std::string const& regex, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes );
2732 
2733 } // namespace Matchers
2734 } // namespace Catch
2735 
2736 // end catch_matchers_string.h
2737 // start catch_matchers_vector.h
2738 
2739 #include <algorithm>
2740 
2741 namespace Catch {
2742 namespace Matchers {
2743 
2744  namespace Vector {
2745  namespace Detail {
2746  template <typename InputIterator, typename T>
2747  size_t count(InputIterator first, InputIterator last, T const& item) {
2748  size_t cnt = 0;
2749  for (; first != last; ++first) {
2750  if (*first == item) {
2751  ++cnt;
2752  }
2753  }
2754  return cnt;
2755  }
2756  template <typename InputIterator, typename T>
2757  bool contains(InputIterator first, InputIterator last, T const& item) {
2758  for (; first != last; ++first) {
2759  if (*first == item) {
2760  return true;
2761  }
2762  }
2763  return false;
2764  }
2765  }
2766 
2767  template<typename T>
2768  struct ContainsElementMatcher : MatcherBase<std::vector<T>> {
2769 
2770  ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {}
2771 
2772  bool match(std::vector<T> const &v) const override {
2773  for (auto const& el : v) {
2774  if (el == m_comparator) {
2775  return true;
2776  }
2777  }
2778  return false;
2779  }
2780 
2781  std::string describe() const override {
2782  return "Contains: " + ::Catch::Detail::stringify( m_comparator );
2783  }
2784 
2785  T const& m_comparator;
2786  };
2787 
2788  template<typename T>
2789  struct ContainsMatcher : MatcherBase<std::vector<T>> {
2790 
2791  ContainsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
2792 
2793  bool match(std::vector<T> const &v) const override {
2794  // !TBD: see note in EqualsMatcher
2795  if (m_comparator.size() > v.size())
2796  return false;
2797  for (auto const& comparator : m_comparator) {
2798  auto present = false;
2799  for (const auto& el : v) {
2800  if (el == comparator) {
2801  present = true;
2802  break;
2803  }
2804  }
2805  if (!present) {
2806  return false;
2807  }
2808  }
2809  return true;
2810  }
2811  std::string describe() const override {
2812  return "Contains: " + ::Catch::Detail::stringify( m_comparator );
2813  }
2814 
2815  std::vector<T> const& m_comparator;
2816  };
2817 
2818  template<typename T>
2819  struct EqualsMatcher : MatcherBase<std::vector<T>> {
2820 
2821  EqualsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {}
2822 
2823  bool match(std::vector<T> const &v) const override {
2824  // !TBD: This currently works if all elements can be compared using !=
2825  // - a more general approach would be via a compare template that defaults
2826  // to using !=. but could be specialised for, e.g. std::vector<T> etc
2827  // - then just call that directly
2828  if (m_comparator.size() != v.size())
2829  return false;
2830  for (std::size_t i = 0; i < v.size(); ++i)
2831  if (m_comparator[i] != v[i])
2832  return false;
2833  return true;
2834  }
2835  std::string describe() const override {
2836  return "Equals: " + ::Catch::Detail::stringify( m_comparator );
2837  }
2838  std::vector<T> const& m_comparator;
2839  };
2840 
2841  template<typename T>
2842  struct UnorderedEqualsMatcher : MatcherBase<std::vector<T>> {
2843  UnorderedEqualsMatcher(std::vector<T> const& target) : m_target(target) {}
2844  bool match(std::vector<T> const& vec) const override {
2845  // Note: This is a reimplementation of std::is_permutation,
2846  // because I don't want to include <algorithm> inside the common path
2847  if (m_target.size() != vec.size()) {
2848  return false;
2849  }
2850  auto lfirst = m_target.begin(), llast = m_target.end();
2851  auto rfirst = vec.begin(), rlast = vec.end();
2852  // Cut common prefix to optimize checking of permuted parts
2853  while (lfirst != llast && *lfirst == *rfirst) {
2854  ++lfirst; ++rfirst;
2855  }
2856  if (lfirst == llast) {
2857  return true;
2858  }
2859 
2860  for (auto mid = lfirst; mid != llast; ++mid) {
2861  // Skip already counted items
2862  if (Detail::contains(lfirst, mid, *mid)) {
2863  continue;
2864  }
2865  size_t num_vec = Detail::count(rfirst, rlast, *mid);
2866  if (num_vec == 0 || Detail::count(lfirst, llast, *mid) != num_vec) {
2867  return false;
2868  }
2869  }
2870 
2871  return true;
2872  }
2873 
2874  std::string describe() const override {
2875  return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target);
2876  }
2877  private:
2878  std::vector<T> const& m_target;
2879  };
2880 
2881  } // namespace Vector
2882 
2883  // The following functions create the actual matcher objects.
2884  // This allows the types to be inferred
2885 
2886  template<typename T>
2887  Vector::ContainsMatcher<T> Contains( std::vector<T> const& comparator ) {
2888  return Vector::ContainsMatcher<T>( comparator );
2889  }
2890 
2891  template<typename T>
2893  return Vector::ContainsElementMatcher<T>( comparator );
2894  }
2895 
2896  template<typename T>
2897  Vector::EqualsMatcher<T> Equals( std::vector<T> const& comparator ) {
2898  return Vector::EqualsMatcher<T>( comparator );
2899  }
2900 
2901  template<typename T>
2902  Vector::UnorderedEqualsMatcher<T> UnorderedEquals(std::vector<T> const& target) {
2903  return Vector::UnorderedEqualsMatcher<T>(target);
2904  }
2905 
2906 } // namespace Matchers
2907 } // namespace Catch
2908 
2909 // end catch_matchers_vector.h
2910 namespace Catch {
2911 
2912  template<typename ArgT, typename MatcherT>
2914  ArgT const& m_arg;
2915  MatcherT m_matcher;
2917  public:
2918  MatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString )
2919  : ITransientExpression{ true, matcher.match( arg ) },
2920  m_arg( arg ),
2921  m_matcher( matcher ),
2922  m_matcherString( matcherString )
2923  {}
2924 
2925  void streamReconstructedExpression( std::ostream &os ) const override {
2926  auto matcherAsString = m_matcher.toString();
2927  os << Catch::Detail::stringify( m_arg ) << ' ';
2928  if( matcherAsString == Detail::unprintableString )
2929  os << m_matcherString;
2930  else
2931  os << matcherAsString;
2932  }
2933  };
2934 
2936 
2937  void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString );
2938 
2939  template<typename ArgT, typename MatcherT>
2940  auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString ) -> MatchExpr<ArgT, MatcherT> {
2941  return MatchExpr<ArgT, MatcherT>( arg, matcher, matcherString );
2942  }
2943 
2944 } // namespace Catch
2945 
2947 #define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \
2948  do { \
2949  Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
2950  INTERNAL_CATCH_TRY { \
2951  catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher##_catch_sr ) ); \
2952  } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
2953  INTERNAL_CATCH_REACT( catchAssertionHandler ) \
2954  } while( false )
2955 
2957 #define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \
2958  do { \
2959  Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
2960  if( catchAssertionHandler.allowThrows() ) \
2961  try { \
2962  static_cast<void>(__VA_ARGS__ ); \
2963  catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
2964  } \
2965  catch( exceptionType const& ex ) { \
2966  catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher##_catch_sr ) ); \
2967  } \
2968  catch( ... ) { \
2969  catchAssertionHandler.handleUnexpectedInflightException(); \
2970  } \
2971  else \
2972  catchAssertionHandler.handleThrowingCallSkipped(); \
2973  INTERNAL_CATCH_REACT( catchAssertionHandler ) \
2974  } while( false )
2975 
2976 // end catch_capture_matchers.h
2977 #endif
2978 // start catch_generators.hpp
2979 
2980 // start catch_interfaces_generatortracker.h
2981 
2982 
2983 #include <memory>
2984 
2985 namespace Catch {
2986 
2987  namespace Generators {
2989  protected:
2990  size_t m_size = 0;
2991 
2992  public:
2993  GeneratorBase( size_t size ) : m_size( size ) {}
2994  virtual ~GeneratorBase();
2995  auto size() const -> size_t { return m_size; }
2996  };
2997  using GeneratorBasePtr = std::unique_ptr<GeneratorBase>;
2998 
2999  } // namespace Generators
3000 
3002  virtual ~IGeneratorTracker();
3003  virtual auto hasGenerator() const -> bool = 0;
3004  virtual auto getGenerator() const -> Generators::GeneratorBasePtr const& = 0;
3005  virtual void setGenerator( Generators::GeneratorBasePtr&& generator ) = 0;
3006  virtual auto getIndex() const -> std::size_t = 0;
3007  };
3008 
3009 } // namespace Catch
3010 
3011 // end catch_interfaces_generatortracker.h
3012 // start catch_enforce.h
3013 
3014 #include <stdexcept>
3015 
3016 namespace Catch {
3017 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
3018  template <typename Ex>
3019  [[noreturn]]
3020  void throw_exception(Ex const& e) {
3021  throw e;
3022  }
3023 #else // ^^ Exceptions are enabled // Exceptions are disabled vv
3024  [[noreturn]]
3025  void throw_exception(std::exception const& e);
3026 #endif
3027 } // namespace Catch;
3028 
3029 #define CATCH_PREPARE_EXCEPTION( type, msg ) \
3030  type( ( Catch::ReusableStringStream() << msg ).str() )
3031 #define CATCH_INTERNAL_ERROR( msg ) \
3032  Catch::throw_exception(CATCH_PREPARE_EXCEPTION( std::logic_error, CATCH_INTERNAL_LINEINFO << ": Internal Catch error: " << msg))
3033 #define CATCH_ERROR( msg ) \
3034  Catch::throw_exception(CATCH_PREPARE_EXCEPTION( std::domain_error, msg ))
3035 #define CATCH_RUNTIME_ERROR( msg ) \
3036  Catch::throw_exception(CATCH_PREPARE_EXCEPTION( std::runtime_error, msg ))
3037 #define CATCH_ENFORCE( condition, msg ) \
3038  do{ if( !(condition) ) CATCH_ERROR( msg ); } while(false)
3039 
3040 // end catch_enforce.h
3041 #include <memory>
3042 #include <vector>
3043 #include <cassert>
3044 
3045 #include <utility>
3046 
3047 namespace Catch {
3048 namespace Generators {
3049 
3050  // !TBD move this into its own location?
3051  namespace pf{
3052  template<typename T, typename... Args>
3053  std::unique_ptr<T> make_unique( Args&&... args ) {
3054  return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
3055  }
3056  }
3057 
3058  template<typename T>
3059  struct IGenerator {
3060  virtual ~IGenerator() {}
3061  virtual auto get( size_t index ) const -> T = 0;
3062  };
3063 
3064  template<typename T>
3065  class SingleValueGenerator : public IGenerator<T> {
3067  public:
3068  SingleValueGenerator( T const& value ) : m_value( value ) {}
3069 
3070  auto get( size_t ) const -> T override {
3071  return m_value;
3072  }
3073  };
3074 
3075  template<typename T>
3076  class FixedValuesGenerator : public IGenerator<T> {
3077  std::vector<T> m_values;
3078 
3079  public:
3080  FixedValuesGenerator( std::initializer_list<T> values ) : m_values( values ) {}
3081 
3082  auto get( size_t index ) const -> T override {
3083  return m_values[index];
3084  }
3085  };
3086 
3087  template<typename T>
3088  class RangeGenerator : public IGenerator<T> {
3089  T const m_first;
3090  T const m_last;
3091 
3092  public:
3093  RangeGenerator( T const& first, T const& last ) : m_first( first ), m_last( last ) {
3094  assert( m_last > m_first );
3095  }
3096 
3097  auto get( size_t index ) const -> T override {
3098  // ToDo:: introduce a safe cast to catch potential overflows
3099  return static_cast<T>(m_first+index);
3100  }
3101  };
3102 
3103  template<typename T>
3105  auto get( size_t ) const -> T override {
3106  CATCH_INTERNAL_ERROR("A Null Generator is always empty");
3107  }
3108  };
3109 
3110  template<typename T>
3111  class Generator {
3112  std::unique_ptr<IGenerator<T>> m_generator;
3113  size_t m_size;
3114 
3115  public:
3116  Generator( size_t size, std::unique_ptr<IGenerator<T>> generator )
3117  : m_generator( std::move( generator ) ),
3118  m_size( size )
3119  {}
3120 
3121  auto size() const -> size_t { return m_size; }
3122  auto operator[]( size_t index ) const -> T {
3123  assert( index < m_size );
3124  return m_generator->get( index );
3125  }
3126  };
3127 
3128  std::vector<size_t> randomiseIndices( size_t selectionSize, size_t sourceSize );
3129 
3130  template<typename T>
3131  class GeneratorRandomiser : public IGenerator<T> {
3133 
3134  std::vector<size_t> m_indices;
3135  public:
3136  GeneratorRandomiser( Generator<T>&& baseGenerator, size_t numberOfItems )
3137  : m_baseGenerator( std::move( baseGenerator ) ),
3138  m_indices( randomiseIndices( numberOfItems, m_baseGenerator.size() ) )
3139  {}
3140 
3141  auto get( size_t index ) const -> T override {
3142  return m_baseGenerator[m_indices[index]];
3143  }
3144  };
3145 
3146  template<typename T>
3148 
3149  template<typename T>
3151 
3152  template<>
3153  auto all<int>() -> Generator<int>;
3154 
3155  template<typename T>
3156  auto range( T const& first, T const& last ) -> Generator<T> {
3157  return Generator<T>( (last-first), pf::make_unique<RangeGenerator<T>>( first, last ) );
3158  }
3159 
3160  template<typename T>
3161  auto random( T const& first, T const& last ) -> Generator<T> {
3162  auto gen = range( first, last );
3163  auto size = gen.size();
3164 
3165  return Generator<T>( size, pf::make_unique<GeneratorRandomiser<T>>( std::move( gen ), size ) );
3166  }
3167  template<typename T>
3168  auto random( size_t size ) -> Generator<T> {
3169  return Generator<T>( size, pf::make_unique<GeneratorRandomiser<T>>( all<T>(), size ) );
3170  }
3171 
3172  template<typename T>
3173  auto values( std::initializer_list<T> values ) -> Generator<T> {
3174  return Generator<T>( values.size(), pf::make_unique<FixedValuesGenerator<T>>( values ) );
3175  }
3176  template<typename T>
3177  auto value( T const& val ) -> Generator<T> {
3178  return Generator<T>( 1, pf::make_unique<SingleValueGenerator<T>>( val ) );
3179  }
3180 
3181  template<typename T>
3182  auto as() -> Generator<T> {
3183  return Generator<T>( 0, pf::make_unique<NullGenerator<T>>() );
3184  }
3185 
3186  template<typename... Ts>
3187  auto table( std::initializer_list<std::tuple<Ts...>>&& tuples ) -> Generator<std::tuple<Ts...>> {
3188  return values<std::tuple<Ts...>>( std::forward<std::initializer_list<std::tuple<Ts...>>>( tuples ) );
3189  }
3190 
3191  template<typename T>
3193  std::vector<Generator<T>> m_generators;
3194 
3195  using type = T;
3196 
3198 
3199  void populate( T&& val ) {
3200  m_size += 1;
3201  m_generators.emplace_back( value( std::move( val ) ) );
3202  }
3203  template<typename U>
3204  void populate( U&& val ) {
3205  populate( T( std::move( val ) ) );
3206  }
3207  void populate( Generator<T>&& generator ) {
3208  m_size += generator.size();
3209  m_generators.emplace_back( std::move( generator ) );
3210  }
3211 
3212  template<typename U, typename... Gs>
3213  void populate( U&& valueOrGenerator, Gs... moreGenerators ) {
3214  populate( std::forward<U>( valueOrGenerator ) );
3215  populate( std::forward<Gs>( moreGenerators )... );
3216  }
3217 
3218  auto operator[]( size_t index ) const -> T {
3219  size_t sizes = 0;
3220  for( auto const& gen : m_generators ) {
3221  auto localIndex = index-sizes;
3222  sizes += gen.size();
3223  if( index < sizes )
3224  return gen[localIndex];
3225  }
3226  CATCH_INTERNAL_ERROR("Index '" << index << "' is out of range (" << sizes << ')');
3227  }
3228  };
3229 
3230  template<typename T, typename... Gs>
3231  auto makeGenerators( Generator<T>&& generator, Gs... moreGenerators ) -> Generators<T> {
3232  Generators<T> generators;
3233  generators.m_generators.reserve( 1+sizeof...(Gs) );
3234  generators.populate( std::move( generator ), std::forward<Gs>( moreGenerators )... );
3235  return generators;
3236  }
3237  template<typename T>
3238  auto makeGenerators( Generator<T>&& generator ) -> Generators<T> {
3239  Generators<T> generators;
3240  generators.populate( std::move( generator ) );
3241  return generators;
3242  }
3243  template<typename T, typename... Gs>
3244  auto makeGenerators( T&& val, Gs... moreGenerators ) -> Generators<T> {
3245  return makeGenerators( value( std::forward<T>( val ) ), std::forward<Gs>( moreGenerators )... );
3246  }
3247  template<typename T, typename U, typename... Gs>
3248  auto makeGenerators( U&& val, Gs... moreGenerators ) -> Generators<T> {
3249  return makeGenerators( value( T( std::forward<U>( val ) ) ), std::forward<Gs>( moreGenerators )... );
3250  }
3251 
3252  auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker&;
3253 
3254  template<typename L>
3255  // Note: The type after -> is weird, because VS2015 cannot parse
3256  // the expression used in the typedef inside, when it is in
3257  // return type. Yeah, ¯\_(ツ)_/¯
3258  auto generate( SourceLineInfo const& lineInfo, L const& generatorExpression ) -> decltype(std::declval<decltype(generatorExpression())>()[0]) {
3259  using UnderlyingType = typename decltype(generatorExpression())::type;
3260 
3261  IGeneratorTracker& tracker = acquireGeneratorTracker( lineInfo );
3262  if( !tracker.hasGenerator() )
3263  tracker.setGenerator( pf::make_unique<Generators<UnderlyingType>>( generatorExpression() ) );
3264 
3265  auto const& generator = static_cast<Generators<UnderlyingType> const&>( *tracker.getGenerator() );
3266  return generator[tracker.getIndex()];
3267  }
3268 
3269 } // namespace Generators
3270 } // namespace Catch
3271 
3272 #define GENERATE( ... ) \
3273  Catch::Generators::generate( CATCH_INTERNAL_LINEINFO, []{ using namespace Catch::Generators; return makeGenerators( __VA_ARGS__ ); } )
3274 
3275 // end catch_generators.hpp
3276 
3277 // These files are included here so the single_include script doesn't put them
3278 // in the conditionally compiled sections
3279 // start catch_test_case_info.h
3280 
3281 #include <string>
3282 #include <vector>
3283 #include <memory>
3284 
3285 #ifdef __clang__
3286 #pragma clang diagnostic push
3287 #pragma clang diagnostic ignored "-Wpadded"
3288 #endif
3289 
3290 namespace Catch {
3291 
3292  struct ITestInvoker;
3293 
3294  struct TestCaseInfo {
3296  None = 0,
3297  IsHidden = 1 << 1,
3298  ShouldFail = 1 << 2,
3299  MayFail = 1 << 3,
3300  Throws = 1 << 4,
3301  NonPortable = 1 << 5,
3302  Benchmark = 1 << 6
3303  };
3304 
3305  TestCaseInfo( std::string const& _name,
3306  std::string const& _className,
3307  std::string const& _description,
3308  std::vector<std::string> const& _tags,
3309  SourceLineInfo const& _lineInfo );
3310 
3311  friend void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags );
3312 
3313  bool isHidden() const;
3314  bool throws() const;
3315  bool okToFail() const;
3316  bool expectedToFail() const;
3317 
3318  std::string tagsAsString() const;
3319 
3320  std::string name;
3321  std::string className;
3322  std::string description;
3323  std::vector<std::string> tags;
3324  std::vector<std::string> lcaseTags;
3327  };
3328 
3329  class TestCase : public TestCaseInfo {
3330  public:
3331 
3332  TestCase( ITestInvoker* testCase, TestCaseInfo&& info );
3333 
3334  TestCase withName( std::string const& _newName ) const;
3335 
3336  void invoke() const;
3337 
3338  TestCaseInfo const& getTestCaseInfo() const;
3339 
3340  bool operator == ( TestCase const& other ) const;
3341  bool operator < ( TestCase const& other ) const;
3342 
3343  private:
3344  std::shared_ptr<ITestInvoker> test;
3345  };
3346 
3347  TestCase makeTestCase( ITestInvoker* testCase,
3348  std::string const& className,
3349  NameAndTags const& nameAndTags,
3350  SourceLineInfo const& lineInfo );
3351 }
3352 
3353 #ifdef __clang__
3354 #pragma clang diagnostic pop
3355 #endif
3356 
3357 // end catch_test_case_info.h
3358 // start catch_interfaces_runner.h
3359 
3360 namespace Catch {
3361 
3362  struct IRunner {
3363  virtual ~IRunner();
3364  virtual bool aborting() const = 0;
3365  };
3366 }
3367 
3368 // end catch_interfaces_runner.h
3369 
3370 #ifdef __OBJC__
3371 // start catch_objc.hpp
3372 
3373 #import <objc/runtime.h>
3374 
3375 #include <string>
3376 
3377 // NB. Any general catch headers included here must be included
3378 // in catch.hpp first to make sure they are included by the single
3379 // header for non obj-usage
3380 
3382 // This protocol is really only here for (self) documenting purposes, since
3383 // all its methods are optional.
3384 @protocol OcFixture
3385 
3386 @optional
3387 
3388 -(void) setUp;
3389 -(void) tearDown;
3390 
3391 @end
3392 
3393 namespace Catch {
3394 
3395  class OcMethod : public ITestInvoker {
3396 
3397  public:
3398  OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {}
3399 
3400  virtual void invoke() const {
3401  id obj = [[m_cls alloc] init];
3402 
3403  performOptionalSelector( obj, @selector(setUp) );
3404  performOptionalSelector( obj, m_sel );
3405  performOptionalSelector( obj, @selector(tearDown) );
3406 
3407  arcSafeRelease( obj );
3408  }
3409  private:
3410  virtual ~OcMethod() {}
3411 
3412  Class m_cls;
3413  SEL m_sel;
3414  };
3415 
3416  namespace Detail{
3417 
3418  inline std::string getAnnotation( Class cls,
3419  std::string const& annotationName,
3420  std::string const& testCaseName ) {
3421  NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()];
3422  SEL sel = NSSelectorFromString( selStr );
3423  arcSafeRelease( selStr );
3424  id value = performOptionalSelector( cls, sel );
3425  if( value )
3426  return [(NSString*)value UTF8String];
3427  return "";
3428  }
3429  }
3430 
3431  inline std::size_t registerTestMethods() {
3432  std::size_t noTestMethods = 0;
3433  int noClasses = objc_getClassList( nullptr, 0 );
3434 
3435  Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses);
3436  objc_getClassList( classes, noClasses );
3437 
3438  for( int c = 0; c < noClasses; c++ ) {
3439  Class cls = classes[c];
3440  {
3441  u_int count;
3442  Method* methods = class_copyMethodList( cls, &count );
3443  for( u_int m = 0; m < count ; m++ ) {
3444  SEL selector = method_getName(methods[m]);
3445  std::string methodName = sel_getName(selector);
3446  if( startsWith( methodName, "Catch_TestCase_" ) ) {
3447  std::string testCaseName = methodName.substr( 15 );
3448  std::string name = Detail::getAnnotation( cls, "Name", testCaseName );
3449  std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
3450  const char* className = class_getName( cls );
3451 
3452  getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, NameAndTags( name.c_str(), desc.c_str() ), SourceLineInfo("",0) ) );
3453  noTestMethods++;
3454  }
3455  }
3456  free(methods);
3457  }
3458  }
3459  return noTestMethods;
3460  }
3461 
3462 #if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
3463 
3464  namespace Matchers {
3465  namespace Impl {
3466  namespace NSStringMatchers {
3467 
3468  struct StringHolder : MatcherBase<NSString*>{
3469  StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
3470  StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){}
3471  StringHolder() {
3472  arcSafeRelease( m_substr );
3473  }
3474 
3475  bool match( NSString* arg ) const override {
3476  return false;
3477  }
3478 
3479  NSString* CATCH_ARC_STRONG m_substr;
3480  };
3481 
3482  struct Equals : StringHolder {
3483  Equals( NSString* substr ) : StringHolder( substr ){}
3484 
3485  bool match( NSString* str ) const override {
3486  return (str != nil || m_substr == nil ) &&
3487  [str isEqualToString:m_substr];
3488  }
3489 
3490  std::string describe() const override {
3491  return "equals string: " + Catch::Detail::stringify( m_substr );
3492  }
3493  };
3494 
3495  struct Contains : StringHolder {
3496  Contains( NSString* substr ) : StringHolder( substr ){}
3497 
3498  bool match( NSString* str ) const {
3499  return (str != nil || m_substr == nil ) &&
3500  [str rangeOfString:m_substr].location != NSNotFound;
3501  }
3502 
3503  std::string describe() const override {
3504  return "contains string: " + Catch::Detail::stringify( m_substr );
3505  }
3506  };
3507 
3508  struct StartsWith : StringHolder {
3509  StartsWith( NSString* substr ) : StringHolder( substr ){}
3510 
3511  bool match( NSString* str ) const override {
3512  return (str != nil || m_substr == nil ) &&
3513  [str rangeOfString:m_substr].location == 0;
3514  }
3515 
3516  std::string describe() const override {
3517  return "starts with: " + Catch::Detail::stringify( m_substr );
3518  }
3519  };
3520  struct EndsWith : StringHolder {
3521  EndsWith( NSString* substr ) : StringHolder( substr ){}
3522 
3523  bool match( NSString* str ) const override {
3524  return (str != nil || m_substr == nil ) &&
3525  [str rangeOfString:m_substr].location == [str length] - [m_substr length];
3526  }
3527 
3528  std::string describe() const override {
3529  return "ends with: " + Catch::Detail::stringify( m_substr );
3530  }
3531  };
3532 
3533  } // namespace NSStringMatchers
3534  } // namespace Impl
3535 
3537  Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
3538 
3540  Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
3541 
3543  StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
3544 
3546  EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
3547 
3548  } // namespace Matchers
3549 
3550  using namespace Matchers;
3551 
3552 #endif // CATCH_CONFIG_DISABLE_MATCHERS
3553 
3554 } // namespace Catch
3555 
3557 #define OC_MAKE_UNIQUE_NAME( root, uniqueSuffix ) root##uniqueSuffix
3558 #define OC_TEST_CASE2( name, desc, uniqueSuffix ) \
3559 +(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Name_test_, uniqueSuffix ) \
3560 { \
3561 return @ name; \
3562 } \
3563 +(NSString*) OC_MAKE_UNIQUE_NAME( Catch_Description_test_, uniqueSuffix ) \
3564 { \
3565 return @ desc; \
3566 } \
3567 -(void) OC_MAKE_UNIQUE_NAME( Catch_TestCase_test_, uniqueSuffix )
3568 
3569 #define OC_TEST_CASE( name, desc ) OC_TEST_CASE2( name, desc, __LINE__ )
3570 
3571 // end catch_objc.hpp
3572 #endif
3573 
3574 #ifdef CATCH_CONFIG_EXTERNAL_INTERFACES
3575 // start catch_external_interfaces.h
3576 
3577 // start catch_reporter_bases.hpp
3578 
3579 // start catch_interfaces_reporter.h
3580 
3581 // start catch_config.hpp
3582 
3583 // start catch_test_spec_parser.h
3584 
3585 #ifdef __clang__
3586 #pragma clang diagnostic push
3587 #pragma clang diagnostic ignored "-Wpadded"
3588 #endif
3589 
3590 // start catch_test_spec.h
3591 
3592 #ifdef __clang__
3593 #pragma clang diagnostic push
3594 #pragma clang diagnostic ignored "-Wpadded"
3595 #endif
3596 
3597 // start catch_wildcard_pattern.h
3598 
3599 namespace Catch
3600 {
3601  class WildcardPattern {
3602  enum WildcardPosition {
3603  NoWildcard = 0,
3604  WildcardAtStart = 1,
3605  WildcardAtEnd = 2,
3606  WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd
3607  };
3608 
3609  public:
3610 
3611  WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity );
3612  virtual ~WildcardPattern() = default;
3613  virtual bool matches( std::string const& str ) const;
3614 
3615  private:
3616  std::string adjustCase( std::string const& str ) const;
3617  CaseSensitive::Choice m_caseSensitivity;
3618  WildcardPosition m_wildcard = NoWildcard;
3619  std::string m_pattern;
3620  };
3621 }
3622 
3623 // end catch_wildcard_pattern.h
3624 #include <string>
3625 #include <vector>
3626 #include <memory>
3627 
3628 namespace Catch {
3629 
3630  class TestSpec {
3631  struct Pattern {
3632  virtual ~Pattern();
3633  virtual bool matches( TestCaseInfo const& testCase ) const = 0;
3634  };
3635  using PatternPtr = std::shared_ptr<Pattern>;
3636 
3637  class NamePattern : public Pattern {
3638  public:
3639  NamePattern( std::string const& name );
3640  virtual ~NamePattern();
3641  virtual bool matches( TestCaseInfo const& testCase ) const override;
3642  private:
3643  WildcardPattern m_wildcardPattern;
3644  };
3645 
3646  class TagPattern : public Pattern {
3647  public:
3648  TagPattern( std::string const& tag );
3649  virtual ~TagPattern();
3650  virtual bool matches( TestCaseInfo const& testCase ) const override;
3651  private:
3652  std::string m_tag;
3653  };
3654 
3655  class ExcludedPattern : public Pattern {
3656  public:
3657  ExcludedPattern( PatternPtr const& underlyingPattern );
3658  virtual ~ExcludedPattern();
3659  virtual bool matches( TestCaseInfo const& testCase ) const override;
3660  private:
3661  PatternPtr m_underlyingPattern;
3662  };
3663 
3664  struct Filter {
3665  std::vector<PatternPtr> m_patterns;
3666 
3667  bool matches( TestCaseInfo const& testCase ) const;
3668  };
3669 
3670  public:
3671  bool hasFilters() const;
3672  bool matches( TestCaseInfo const& testCase ) const;
3673 
3674  private:
3675  std::vector<Filter> m_filters;
3676 
3677  friend class TestSpecParser;
3678  };
3679 }
3680 
3681 #ifdef __clang__
3682 #pragma clang diagnostic pop
3683 #endif
3684 
3685 // end catch_test_spec.h
3686 // start catch_interfaces_tag_alias_registry.h
3687 
3688 #include <string>
3689 
3690 namespace Catch {
3691 
3692  struct TagAlias;
3693 
3694  struct ITagAliasRegistry {
3695  virtual ~ITagAliasRegistry();
3696  // Nullptr if not present
3697  virtual TagAlias const* find( std::string const& alias ) const = 0;
3698  virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0;
3699 
3700  static ITagAliasRegistry const& get();
3701  };
3702 
3703 } // end namespace Catch
3704 
3705 // end catch_interfaces_tag_alias_registry.h
3706 namespace Catch {
3707 
3708  class TestSpecParser {
3709  enum Mode{ None, Name, QuotedName, Tag, EscapedName };
3710  Mode m_mode = None;
3711  bool m_exclusion = false;
3712  std::size_t m_start = std::string::npos, m_pos = 0;
3713  std::string m_arg;
3714  std::vector<std::size_t> m_escapeChars;
3715  TestSpec::Filter m_currentFilter;
3716  TestSpec m_testSpec;
3717  ITagAliasRegistry const* m_tagAliases = nullptr;
3718 
3719  public:
3720  TestSpecParser( ITagAliasRegistry const& tagAliases );
3721 
3722  TestSpecParser& parse( std::string const& arg );
3723  TestSpec testSpec();
3724 
3725  private:
3726  void visitChar( char c );
3727  void startNewMode( Mode mode, std::size_t start );
3728  void escape();
3729  std::string subString() const;
3730 
3731  template<typename T>
3732  void addPattern() {
3733  std::string token = subString();
3734  for( std::size_t i = 0; i < m_escapeChars.size(); ++i )
3735  token = token.substr( 0, m_escapeChars[i]-m_start-i ) + token.substr( m_escapeChars[i]-m_start-i+1 );
3736  m_escapeChars.clear();
3737  if( startsWith( token, "exclude:" ) ) {
3738  m_exclusion = true;
3739  token = token.substr( 8 );
3740  }
3741  if( !token.empty() ) {
3742  TestSpec::PatternPtr pattern = std::make_shared<T>( token );
3743  if( m_exclusion )
3744  pattern = std::make_shared<TestSpec::ExcludedPattern>( pattern );
3745  m_currentFilter.m_patterns.push_back( pattern );
3746  }
3747  m_exclusion = false;
3748  m_mode = None;
3749  }
3750 
3751  void addFilter();
3752  };
3753  TestSpec parseTestSpec( std::string const& arg );
3754 
3755 } // namespace Catch
3756 
3757 #ifdef __clang__
3758 #pragma clang diagnostic pop
3759 #endif
3760 
3761 // end catch_test_spec_parser.h
3762 // start catch_interfaces_config.h
3763 
3764 #include <iosfwd>
3765 #include <string>
3766 #include <vector>
3767 #include <memory>
3768 
3769 namespace Catch {
3770 
3771  enum class Verbosity {
3772  Quiet = 0,
3773  Normal,
3774  High
3775  };
3776 
3777  struct WarnAbout { enum What {
3778  Nothing = 0x00,
3779  NoAssertions = 0x01,
3780  NoTests = 0x02
3781  }; };
3782 
3783  struct ShowDurations { enum OrNot {
3784  DefaultForReporter,
3785  Always,
3786  Never
3787  }; };
3788  struct RunTests { enum InWhatOrder {
3789  InDeclarationOrder,
3790  InLexicographicalOrder,
3791  InRandomOrder
3792  }; };
3793  struct UseColour { enum YesOrNo {
3794  Auto,
3795  Yes,
3796  No
3797  }; };
3798  struct WaitForKeypress { enum When {
3799  Never,
3800  BeforeStart = 1,
3801  BeforeExit = 2,
3802  BeforeStartAndExit = BeforeStart | BeforeExit
3803  }; };
3804 
3805  class TestSpec;
3806 
3807  struct IConfig : NonCopyable {
3808 
3809  virtual ~IConfig();
3810 
3811  virtual bool allowThrows() const = 0;
3812  virtual std::ostream& stream() const = 0;
3813  virtual std::string name() const = 0;
3814  virtual bool includeSuccessfulResults() const = 0;
3815  virtual bool shouldDebugBreak() const = 0;
3816  virtual bool warnAboutMissingAssertions() const = 0;
3817  virtual bool warnAboutNoTests() const = 0;
3818  virtual int abortAfter() const = 0;
3819  virtual bool showInvisibles() const = 0;
3820  virtual ShowDurations::OrNot showDurations() const = 0;
3821  virtual TestSpec const& testSpec() const = 0;
3822  virtual bool hasTestFilters() const = 0;
3823  virtual RunTests::InWhatOrder runOrder() const = 0;
3824  virtual unsigned int rngSeed() const = 0;
3825  virtual int benchmarkResolutionMultiple() const = 0;
3826  virtual UseColour::YesOrNo useColour() const = 0;
3827  virtual std::vector<std::string> const& getSectionsToRun() const = 0;
3828  virtual Verbosity verbosity() const = 0;
3829  };
3830 
3831  using IConfigPtr = std::shared_ptr<IConfig const>;
3832 }
3833 
3834 // end catch_interfaces_config.h
3835 // Libstdc++ doesn't like incomplete classes for unique_ptr
3836 
3837 #include <memory>
3838 #include <vector>
3839 #include <string>
3840 
3841 #ifndef CATCH_CONFIG_CONSOLE_WIDTH
3842 #define CATCH_CONFIG_CONSOLE_WIDTH 80
3843 #endif
3844 
3845 namespace Catch {
3846 
3847  struct IStream;
3848 
3849  struct ConfigData {
3850  bool listTests = false;
3851  bool listTags = false;
3852  bool listReporters = false;
3853  bool listTestNamesOnly = false;
3854 
3855  bool showSuccessfulTests = false;
3856  bool shouldDebugBreak = false;
3857  bool noThrow = false;
3858  bool showHelp = false;
3859  bool showInvisibles = false;
3860  bool filenamesAsTags = false;
3861  bool libIdentify = false;
3862 
3863  int abortAfter = -1;
3864  unsigned int rngSeed = 0;
3865  int benchmarkResolutionMultiple = 100;
3866 
3867  Verbosity verbosity = Verbosity::Normal;
3868  WarnAbout::What warnings = WarnAbout::Nothing;
3869  ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter;
3870  RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder;
3871  UseColour::YesOrNo useColour = UseColour::Auto;
3872  WaitForKeypress::When waitForKeypress = WaitForKeypress::Never;
3873 
3874  std::string outputFilename;
3875  std::string name;
3876  std::string processName;
3877 #ifndef CATCH_CONFIG_DEFAULT_REPORTER
3878 #define CATCH_CONFIG_DEFAULT_REPORTER "console"
3879 #endif
3880  std::string reporterName = CATCH_CONFIG_DEFAULT_REPORTER;
3881 #undef CATCH_CONFIG_DEFAULT_REPORTER
3882 
3883  std::vector<std::string> testsOrTags;
3884  std::vector<std::string> sectionsToRun;
3885  };
3886 
3887  class Config : public IConfig {
3888  public:
3889 
3890  Config() = default;
3891  Config( ConfigData const& data );
3892  virtual ~Config() = default;
3893 
3894  std::string const& getFilename() const;
3895 
3896  bool listTests() const;
3897  bool listTestNamesOnly() const;
3898  bool listTags() const;
3899  bool listReporters() const;
3900 
3901  std::string getProcessName() const;
3902  std::string const& getReporterName() const;
3903 
3904  std::vector<std::string> const& getTestsOrTags() const;
3905  std::vector<std::string> const& getSectionsToRun() const override;
3906 
3907  virtual TestSpec const& testSpec() const override;
3908  bool hasTestFilters() const override;
3909 
3910  bool showHelp() const;
3911 
3912  // IConfig interface
3913  bool allowThrows() const override;
3914  std::ostream& stream() const override;
3915  std::string name() const override;
3916  bool includeSuccessfulResults() const override;
3917  bool warnAboutMissingAssertions() const override;
3918  bool warnAboutNoTests() const override;
3919  ShowDurations::OrNot showDurations() const override;
3920  RunTests::InWhatOrder runOrder() const override;
3921  unsigned int rngSeed() const override;
3922  int benchmarkResolutionMultiple() const override;
3923  UseColour::YesOrNo useColour() const override;
3924  bool shouldDebugBreak() const override;
3925  int abortAfter() const override;
3926  bool showInvisibles() const override;
3927  Verbosity verbosity() const override;
3928 
3929  private:
3930 
3931  IStream const* openStream();
3932  ConfigData m_data;
3933 
3934  std::unique_ptr<IStream const> m_stream;
3935  TestSpec m_testSpec;
3936  bool m_hasTestFilters = false;
3937  };
3938 
3939 } // end namespace Catch
3940 
3941 // end catch_config.hpp
3942 // start catch_assertionresult.h
3943 
3944 #include <string>
3945 
3946 namespace Catch {
3947 
3948  struct AssertionResultData
3949  {
3950  AssertionResultData() = delete;
3951 
3952  AssertionResultData( ResultWas::OfType _resultType, LazyExpression const& _lazyExpression );
3953 
3954  std::string message;
3955  mutable std::string reconstructedExpression;
3956  LazyExpression lazyExpression;
3957  ResultWas::OfType resultType;
3958 
3959  std::string reconstructExpression() const;
3960  };
3961 
3962  class AssertionResult {
3963  public:
3964  AssertionResult() = delete;
3965  AssertionResult( AssertionInfo const& info, AssertionResultData const& data );
3966 
3967  bool isOk() const;
3968  bool succeeded() const;
3969  ResultWas::OfType getResultType() const;
3970  bool hasExpression() const;
3971  bool hasMessage() const;
3972  std::string getExpression() const;
3973  std::string getExpressionInMacro() const;
3974  bool hasExpandedExpression() const;
3975  std::string getExpandedExpression() const;
3976  std::string getMessage() const;
3977  SourceLineInfo getSourceInfo() const;
3978  StringRef getTestMacroName() const;
3979 
3980  //protected:
3981  AssertionInfo m_info;
3982  AssertionResultData m_resultData;
3983  };
3984 
3985 } // end namespace Catch
3986 
3987 // end catch_assertionresult.h
3988 // start catch_option.hpp
3989 
3990 namespace Catch {
3991 
3992  // An optional type
3993  template<typename T>
3994  class Option {
3995  public:
3996  Option() : nullableValue( nullptr ) {}
3997  Option( T const& _value )
3998  : nullableValue( new( storage ) T( _value ) )
3999  {}
4000  Option( Option const& _other )
4001  : nullableValue( _other ? new( storage ) T( *_other ) : nullptr )
4002  {}
4003 
4004  ~Option() {
4005  reset();
4006  }
4007 
4008  Option& operator= ( Option const& _other ) {
4009  if( &_other != this ) {
4010  reset();
4011  if( _other )
4012  nullableValue = new( storage ) T( *_other );
4013  }
4014  return *this;
4015  }
4016  Option& operator = ( T const& _value ) {
4017  reset();
4018  nullableValue = new( storage ) T( _value );
4019  return *this;
4020  }
4021 
4022  void reset() {
4023  if( nullableValue )
4024  nullableValue->~T();
4025  nullableValue = nullptr;
4026  }
4027 
4028  T& operator*() { return *nullableValue; }
4029  T const& operator*() const { return *nullableValue; }
4030  T* operator->() { return nullableValue; }
4031  const T* operator->() const { return nullableValue; }
4032 
4033  T valueOr( T const& defaultValue ) const {
4034  return nullableValue ? *nullableValue : defaultValue;
4035  }
4036 
4037  bool some() const { return nullableValue != nullptr; }
4038  bool none() const { return nullableValue == nullptr; }
4039 
4040  bool operator !() const { return nullableValue == nullptr; }
4041  explicit operator bool() const {
4042  return some();
4043  }
4044 
4045  private:
4046  T *nullableValue;
4047  alignas(alignof(T)) char storage[sizeof(T)];
4048  };
4049 
4050 } // end namespace Catch
4051 
4052 // end catch_option.hpp
4053 #include <string>
4054 #include <iosfwd>
4055 #include <map>
4056 #include <set>
4057 #include <memory>
4058 
4059 namespace Catch {
4060 
4061  struct ReporterConfig {
4062  explicit ReporterConfig( IConfigPtr const& _fullConfig );
4063 
4064  ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream );
4065 
4066  std::ostream& stream() const;
4067  IConfigPtr fullConfig() const;
4068 
4069  private:
4070  std::ostream* m_stream;
4071  IConfigPtr m_fullConfig;
4072  };
4073 
4074  struct ReporterPreferences {
4075  bool shouldRedirectStdOut = false;
4076  bool shouldReportAllAssertions = false;
4077  };
4078 
4079  template<typename T>
4080  struct LazyStat : Option<T> {
4081  LazyStat& operator=( T const& _value ) {
4082  Option<T>::operator=( _value );
4083  used = false;
4084  return *this;
4085  }
4086  void reset() {
4087  Option<T>::reset();
4088  used = false;
4089  }
4090  bool used = false;
4091  };
4092 
4093  struct TestRunInfo {
4094  TestRunInfo( std::string const& _name );
4095  std::string name;
4096  };
4097  struct GroupInfo {
4098  GroupInfo( std::string const& _name,
4099  std::size_t _groupIndex,
4100  std::size_t _groupsCount );
4101 
4102  std::string name;
4103  std::size_t groupIndex;
4104  std::size_t groupsCounts;
4105  };
4106 
4107  struct AssertionStats {
4108  AssertionStats( AssertionResult const& _assertionResult,
4109  std::vector<MessageInfo> const& _infoMessages,
4110  Totals const& _totals );
4111 
4112  AssertionStats( AssertionStats const& ) = default;
4113  AssertionStats( AssertionStats && ) = default;
4114  AssertionStats& operator = ( AssertionStats const& ) = default;
4115  AssertionStats& operator = ( AssertionStats && ) = default;
4116  virtual ~AssertionStats();
4117 
4118  AssertionResult assertionResult;
4119  std::vector<MessageInfo> infoMessages;
4120  Totals totals;
4121  };
4122 
4123  struct SectionStats {
4124  SectionStats( SectionInfo const& _sectionInfo,
4125  Counts const& _assertions,
4126  double _durationInSeconds,
4127  bool _missingAssertions );
4128  SectionStats( SectionStats const& ) = default;
4129  SectionStats( SectionStats && ) = default;
4130  SectionStats& operator = ( SectionStats const& ) = default;
4131  SectionStats& operator = ( SectionStats && ) = default;
4132  virtual ~SectionStats();
4133 
4134  SectionInfo sectionInfo;
4135  Counts assertions;
4136  double durationInSeconds;
4137  bool missingAssertions;
4138  };
4139 
4140  struct TestCaseStats {
4141  TestCaseStats( TestCaseInfo const& _testInfo,
4142  Totals const& _totals,
4143  std::string const& _stdOut,
4144  std::string const& _stdErr,
4145  bool _aborting );
4146 
4147  TestCaseStats( TestCaseStats const& ) = default;
4148  TestCaseStats( TestCaseStats && ) = default;
4149  TestCaseStats& operator = ( TestCaseStats const& ) = default;
4150  TestCaseStats& operator = ( TestCaseStats && ) = default;
4151  virtual ~TestCaseStats();
4152 
4153  TestCaseInfo testInfo;
4154  Totals totals;
4155  std::string stdOut;
4156  std::string stdErr;
4157  bool aborting;
4158  };
4159 
4160  struct TestGroupStats {
4161  TestGroupStats( GroupInfo const& _groupInfo,
4162  Totals const& _totals,
4163  bool _aborting );
4164  TestGroupStats( GroupInfo const& _groupInfo );
4165 
4166  TestGroupStats( TestGroupStats const& ) = default;
4167  TestGroupStats( TestGroupStats && ) = default;
4168  TestGroupStats& operator = ( TestGroupStats const& ) = default;
4169  TestGroupStats& operator = ( TestGroupStats && ) = default;
4170  virtual ~TestGroupStats();
4171 
4172  GroupInfo groupInfo;
4173  Totals totals;
4174  bool aborting;
4175  };
4176 
4177  struct TestRunStats {
4178  TestRunStats( TestRunInfo const& _runInfo,
4179  Totals const& _totals,
4180  bool _aborting );
4181 
4182  TestRunStats( TestRunStats const& ) = default;
4183  TestRunStats( TestRunStats && ) = default;
4184  TestRunStats& operator = ( TestRunStats const& ) = default;
4185  TestRunStats& operator = ( TestRunStats && ) = default;
4186  virtual ~TestRunStats();
4187 
4188  TestRunInfo runInfo;
4189  Totals totals;
4190  bool aborting;
4191  };
4192 
4193  struct BenchmarkInfo {
4194  std::string name;
4195  };
4196  struct BenchmarkStats {
4197  BenchmarkInfo info;
4198  std::size_t iterations;
4199  uint64_t elapsedTimeInNanoseconds;
4200  };
4201 
4202  struct IStreamingReporter {
4203  virtual ~IStreamingReporter() = default;
4204 
4205  // Implementing class must also provide the following static methods:
4206  // static std::string getDescription();
4207  // static std::set<Verbosity> getSupportedVerbosities()
4208 
4209  virtual ReporterPreferences getPreferences() const = 0;
4210 
4211  virtual void noMatchingTestCases( std::string const& spec ) = 0;
4212 
4213  virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
4214  virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0;
4215 
4216  virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
4217  virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
4218 
4219  // *** experimental ***
4220  virtual void benchmarkStarting( BenchmarkInfo const& ) {}
4221 
4222  virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
4223 
4224  // The return value indicates if the messages buffer should be cleared:
4225  virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
4226 
4227  // *** experimental ***
4228  virtual void benchmarkEnded( BenchmarkStats const& ) {}
4229 
4230  virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
4231  virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
4232  virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
4233  virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
4234 
4235  virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
4236 
4237  // Default empty implementation provided
4238  virtual void fatalErrorEncountered( StringRef name );
4239 
4240  virtual bool isMulti() const;
4241  };
4242  using IStreamingReporterPtr = std::unique_ptr<IStreamingReporter>;
4243 
4244  struct IReporterFactory {
4245  virtual ~IReporterFactory();
4246  virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0;
4247  virtual std::string getDescription() const = 0;
4248  };
4249  using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
4250 
4251  struct IReporterRegistry {
4252  using FactoryMap = std::map<std::string, IReporterFactoryPtr>;
4253  using Listeners = std::vector<IReporterFactoryPtr>;
4254 
4255  virtual ~IReporterRegistry();
4256  virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0;
4257  virtual FactoryMap const& getFactories() const = 0;
4258  virtual Listeners const& getListeners() const = 0;
4259  };
4260 
4261 } // end namespace Catch
4262 
4263 // end catch_interfaces_reporter.h
4264 #include <algorithm>
4265 #include <cstring>
4266 #include <cfloat>
4267 #include <cstdio>
4268 #include <cassert>
4269 #include <memory>
4270 #include <ostream>
4271 
4272 namespace Catch {
4273  void prepareExpandedExpression(AssertionResult& result);
4274 
4275  // Returns double formatted as %.3f (format expected on output)
4276  std::string getFormattedDuration( double duration );
4277 
4278  template<typename DerivedT>
4279  struct StreamingReporterBase : IStreamingReporter {
4280 
4281  StreamingReporterBase( ReporterConfig const& _config )
4282  : m_config( _config.fullConfig() ),
4283  stream( _config.stream() )
4284  {
4285  m_reporterPrefs.shouldRedirectStdOut = false;
4286  if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) )
4287  CATCH_ERROR( "Verbosity level not supported by this reporter" );
4288  }
4289 
4290  ReporterPreferences getPreferences() const override {
4291  return m_reporterPrefs;
4292  }
4293 
4294  static std::set<Verbosity> getSupportedVerbosities() {
4295  return { Verbosity::Normal };
4296  }
4297 
4298  ~StreamingReporterBase() override = default;
4299 
4300  void noMatchingTestCases(std::string const&) override {}
4301 
4302  void testRunStarting(TestRunInfo const& _testRunInfo) override {
4303  currentTestRunInfo = _testRunInfo;
4304  }
4305  void testGroupStarting(GroupInfo const& _groupInfo) override {
4306  currentGroupInfo = _groupInfo;
4307  }
4308 
4309  void testCaseStarting(TestCaseInfo const& _testInfo) override {
4310  currentTestCaseInfo = _testInfo;
4311  }
4312  void sectionStarting(SectionInfo const& _sectionInfo) override {
4313  m_sectionStack.push_back(_sectionInfo);
4314  }
4315 
4316  void sectionEnded(SectionStats const& /* _sectionStats */) override {
4317  m_sectionStack.pop_back();
4318  }
4319  void testCaseEnded(TestCaseStats const& /* _testCaseStats */) override {
4320  currentTestCaseInfo.reset();
4321  }
4322  void testGroupEnded(TestGroupStats const& /* _testGroupStats */) override {
4323  currentGroupInfo.reset();
4324  }
4325  void testRunEnded(TestRunStats const& /* _testRunStats */) override {
4326  currentTestCaseInfo.reset();
4327  currentGroupInfo.reset();
4328  currentTestRunInfo.reset();
4329  }
4330 
4331  void skipTest(TestCaseInfo const&) override {
4332  // Don't do anything with this by default.
4333  // It can optionally be overridden in the derived class.
4334  }
4335 
4336  IConfigPtr m_config;
4337  std::ostream& stream;
4338 
4339  LazyStat<TestRunInfo> currentTestRunInfo;
4340  LazyStat<GroupInfo> currentGroupInfo;
4341  LazyStat<TestCaseInfo> currentTestCaseInfo;
4342 
4343  std::vector<SectionInfo> m_sectionStack;
4344  ReporterPreferences m_reporterPrefs;
4345  };
4346 
4347  template<typename DerivedT>
4348  struct CumulativeReporterBase : IStreamingReporter {
4349  template<typename T, typename ChildNodeT>
4350  struct Node {
4351  explicit Node( T const& _value ) : value( _value ) {}
4352  virtual ~Node() {}
4353 
4354  using ChildNodes = std::vector<std::shared_ptr<ChildNodeT>>;
4355  T value;
4356  ChildNodes children;
4357  };
4358  struct SectionNode {
4359  explicit SectionNode(SectionStats const& _stats) : stats(_stats) {}
4360  virtual ~SectionNode() = default;
4361 
4362  bool operator == (SectionNode const& other) const {
4363  return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo;
4364  }
4365  bool operator == (std::shared_ptr<SectionNode> const& other) const {
4366  return operator==(*other);
4367  }
4368 
4369  SectionStats stats;
4370  using ChildSections = std::vector<std::shared_ptr<SectionNode>>;
4371  using Assertions = std::vector<AssertionStats>;
4372  ChildSections childSections;
4373  Assertions assertions;
4374  std::string stdOut;
4375  std::string stdErr;
4376  };
4377 
4378  struct BySectionInfo {
4379  BySectionInfo( SectionInfo const& other ) : m_other( other ) {}
4380  BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {}
4381  bool operator() (std::shared_ptr<SectionNode> const& node) const {
4382  return ((node->stats.sectionInfo.name == m_other.name) &&
4383  (node->stats.sectionInfo.lineInfo == m_other.lineInfo));
4384  }
4385  void operator=(BySectionInfo const&) = delete;
4386 
4387  private:
4388  SectionInfo const& m_other;
4389  };
4390 
4391  using TestCaseNode = Node<TestCaseStats, SectionNode>;
4392  using TestGroupNode = Node<TestGroupStats, TestCaseNode>;
4393  using TestRunNode = Node<TestRunStats, TestGroupNode>;
4394 
4395  CumulativeReporterBase( ReporterConfig const& _config )
4396  : m_config( _config.fullConfig() ),
4397  stream( _config.stream() )
4398  {
4399  m_reporterPrefs.shouldRedirectStdOut = false;
4400  if( !DerivedT::getSupportedVerbosities().count( m_config->verbosity() ) )
4401  CATCH_ERROR( "Verbosity level not supported by this reporter" );
4402  }
4403  ~CumulativeReporterBase() override = default;
4404 
4405  ReporterPreferences getPreferences() const override {
4406  return m_reporterPrefs;
4407  }
4408 
4409  static std::set<Verbosity> getSupportedVerbosities() {
4410  return { Verbosity::Normal };
4411  }
4412 
4413  void testRunStarting( TestRunInfo const& ) override {}
4414  void testGroupStarting( GroupInfo const& ) override {}
4415 
4416  void testCaseStarting( TestCaseInfo const& ) override {}
4417 
4418  void sectionStarting( SectionInfo const& sectionInfo ) override {
4419  SectionStats incompleteStats( sectionInfo, Counts(), 0, false );
4420  std::shared_ptr<SectionNode> node;
4421  if( m_sectionStack.empty() ) {
4422  if( !m_rootSection )
4423  m_rootSection = std::make_shared<SectionNode>( incompleteStats );
4424  node = m_rootSection;
4425  }
4426  else {
4427  SectionNode& parentNode = *m_sectionStack.back();
4428  auto it =
4429  std::find_if( parentNode.childSections.begin(),
4430  parentNode.childSections.end(),
4431  BySectionInfo( sectionInfo ) );
4432  if( it == parentNode.childSections.end() ) {
4433  node = std::make_shared<SectionNode>( incompleteStats );
4434  parentNode.childSections.push_back( node );
4435  }
4436  else
4437  node = *it;
4438  }
4439  m_sectionStack.push_back( node );
4440  m_deepestSection = std::move(node);
4441  }
4442 
4443  void assertionStarting(AssertionInfo const&) override {}
4444 
4445  bool assertionEnded(AssertionStats const& assertionStats) override {
4446  assert(!m_sectionStack.empty());
4447  // AssertionResult holds a pointer to a temporary DecomposedExpression,
4448  // which getExpandedExpression() calls to build the expression string.
4449  // Our section stack copy of the assertionResult will likely outlive the
4450  // temporary, so it must be expanded or discarded now to avoid calling
4451  // a destroyed object later.
4452  prepareExpandedExpression(const_cast<AssertionResult&>( assertionStats.assertionResult ) );
4453  SectionNode& sectionNode = *m_sectionStack.back();
4454  sectionNode.assertions.push_back(assertionStats);
4455  return true;
4456  }
4457  void sectionEnded(SectionStats const& sectionStats) override {
4458  assert(!m_sectionStack.empty());
4459  SectionNode& node = *m_sectionStack.back();
4460  node.stats = sectionStats;
4461  m_sectionStack.pop_back();
4462  }
4463  void testCaseEnded(TestCaseStats const& testCaseStats) override {
4464  auto node = std::make_shared<TestCaseNode>(testCaseStats);
4465  assert(m_sectionStack.size() == 0);
4466  node->children.push_back(m_rootSection);
4467  m_testCases.push_back(node);
4468  m_rootSection.reset();
4469 
4470  assert(m_deepestSection);
4471  m_deepestSection->stdOut = testCaseStats.stdOut;
4472  m_deepestSection->stdErr = testCaseStats.stdErr;
4473  }
4474  void testGroupEnded(TestGroupStats const& testGroupStats) override {
4475  auto node = std::make_shared<TestGroupNode>(testGroupStats);
4476  node->children.swap(m_testCases);
4477  m_testGroups.push_back(node);
4478  }
4479  void testRunEnded(TestRunStats const& testRunStats) override {
4480  auto node = std::make_shared<TestRunNode>(testRunStats);
4481  node->children.swap(m_testGroups);
4482  m_testRuns.push_back(node);
4483  testRunEndedCumulative();
4484  }
4485  virtual void testRunEndedCumulative() = 0;
4486 
4487  void skipTest(TestCaseInfo const&) override {}
4488 
4489  IConfigPtr m_config;
4490  std::ostream& stream;
4491  std::vector<AssertionStats> m_assertions;
4492  std::vector<std::vector<std::shared_ptr<SectionNode>>> m_sections;
4493  std::vector<std::shared_ptr<TestCaseNode>> m_testCases;
4494  std::vector<std::shared_ptr<TestGroupNode>> m_testGroups;
4495 
4496  std::vector<std::shared_ptr<TestRunNode>> m_testRuns;
4497 
4498  std::shared_ptr<SectionNode> m_rootSection;
4499  std::shared_ptr<SectionNode> m_deepestSection;
4500  std::vector<std::shared_ptr<SectionNode>> m_sectionStack;
4501  ReporterPreferences m_reporterPrefs;
4502  };
4503 
4504  template<char C>
4505  char const* getLineOfChars() {
4506  static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0};
4507  if( !*line ) {
4508  std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
4509  line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0;
4510  }
4511  return line;
4512  }
4513 
4514  struct TestEventListenerBase : StreamingReporterBase<TestEventListenerBase> {
4515  TestEventListenerBase( ReporterConfig const& _config );
4516 
4517  void assertionStarting(AssertionInfo const&) override;
4518  bool assertionEnded(AssertionStats const&) override;
4519  };
4520 
4521 } // end namespace Catch
4522 
4523 // end catch_reporter_bases.hpp
4524 // start catch_console_colour.h
4525 
4526 namespace Catch {
4527 
4528  struct Colour {
4529  enum Code {
4530  None = 0,
4531 
4532  White,
4533  Red,
4534  Green,
4535  Blue,
4536  Cyan,
4537  Yellow,
4538  Grey,
4539 
4540  Bright = 0x10,
4541 
4542  BrightRed = Bright | Red,
4543  BrightGreen = Bright | Green,
4544  LightGrey = Bright | Grey,
4545  BrightWhite = Bright | White,
4546  BrightYellow = Bright | Yellow,
4547 
4548  // By intention
4549  FileName = LightGrey,
4550  Warning = BrightYellow,
4551  ResultError = BrightRed,
4552  ResultSuccess = BrightGreen,
4553  ResultExpectedFailure = Warning,
4554 
4555  Error = BrightRed,
4556  Success = Green,
4557 
4558  OriginalExpression = Cyan,
4559  ReconstructedExpression = BrightYellow,
4560 
4561  SecondaryText = LightGrey,
4562  Headers = White
4563  };
4564 
4565  // Use constructed object for RAII guard
4566  Colour( Code _colourCode );
4567  Colour( Colour&& other ) noexcept;
4568  Colour& operator=( Colour&& other ) noexcept;
4569  ~Colour();
4570 
4571  // Use static method for one-shot changes
4572  static void use( Code _colourCode );
4573 
4574  private:
4575  bool m_moved = false;
4576  };
4577 
4578  std::ostream& operator << ( std::ostream& os, Colour const& );
4579 
4580 } // end namespace Catch
4581 
4582 // end catch_console_colour.h
4583 // start catch_reporter_registrars.hpp
4584 
4585 
4586 namespace Catch {
4587 
4588  template<typename T>
4589  class ReporterRegistrar {
4590 
4591  class ReporterFactory : public IReporterFactory {
4592 
4593  virtual IStreamingReporterPtr create( ReporterConfig const& config ) const override {
4594  return std::unique_ptr<T>( new T( config ) );
4595  }
4596 
4597  virtual std::string getDescription() const override {
4598  return T::getDescription();
4599  }
4600  };
4601 
4602  public:
4603 
4604  explicit ReporterRegistrar( std::string const& name ) {
4605  getMutableRegistryHub().registerReporter( name, std::make_shared<ReporterFactory>() );
4606  }
4607  };
4608 
4609  template<typename T>
4610  class ListenerRegistrar {
4611 
4612  class ListenerFactory : public IReporterFactory {
4613 
4614  virtual IStreamingReporterPtr create( ReporterConfig const& config ) const override {
4615  return std::unique_ptr<T>( new T( config ) );
4616  }
4617  virtual std::string getDescription() const override {
4618  return std::string();
4619  }
4620  };
4621 
4622  public:
4623 
4624  ListenerRegistrar() {
4625  getMutableRegistryHub().registerListener( std::make_shared<ListenerFactory>() );
4626  }
4627  };
4628 }
4629 
4630 #if !defined(CATCH_CONFIG_DISABLE)
4631 
4632 #define CATCH_REGISTER_REPORTER( name, reporterType ) \
4633  CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
4634  namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } \
4635  CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
4636 
4637 #define CATCH_REGISTER_LISTENER( listenerType ) \
4638  CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
4639  namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } \
4640  CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
4641 #else // CATCH_CONFIG_DISABLE
4642 
4643 #define CATCH_REGISTER_REPORTER(name, reporterType)
4644 #define CATCH_REGISTER_LISTENER(listenerType)
4645 
4646 #endif // CATCH_CONFIG_DISABLE
4647 
4648 // end catch_reporter_registrars.hpp
4649 // Allow users to base their work off existing reporters
4650 // start catch_reporter_compact.h
4651 
4652 namespace Catch {
4653 
4654  struct CompactReporter : StreamingReporterBase<CompactReporter> {
4655 
4656  using StreamingReporterBase::StreamingReporterBase;
4657 
4658  ~CompactReporter() override;
4659 
4660  static std::string getDescription();
4661 
4662  ReporterPreferences getPreferences() const override;
4663 
4664  void noMatchingTestCases(std::string const& spec) override;
4665 
4666  void assertionStarting(AssertionInfo const&) override;
4667 
4668  bool assertionEnded(AssertionStats const& _assertionStats) override;
4669 
4670  void sectionEnded(SectionStats const& _sectionStats) override;
4671 
4672  void testRunEnded(TestRunStats const& _testRunStats) override;
4673 
4674  };
4675 
4676 } // end namespace Catch
4677 
4678 // end catch_reporter_compact.h
4679 // start catch_reporter_console.h
4680 
4681 #if defined(_MSC_VER)
4682 #pragma warning(push)
4683 #pragma warning(disable:4061) // Not all labels are EXPLICITLY handled in switch
4684  // Note that 4062 (not all labels are handled
4685  // and default is missing) is enabled
4686 #endif
4687 
4688 namespace Catch {
4689  // Fwd decls
4690  struct SummaryColumn;
4691  class TablePrinter;
4692 
4693  struct ConsoleReporter : StreamingReporterBase<ConsoleReporter> {
4694  std::unique_ptr<TablePrinter> m_tablePrinter;
4695 
4696  ConsoleReporter(ReporterConfig const& config);
4697  ~ConsoleReporter() override;
4698  static std::string getDescription();
4699 
4700  void noMatchingTestCases(std::string const& spec) override;
4701 
4702  void assertionStarting(AssertionInfo const&) override;
4703 
4704  bool assertionEnded(AssertionStats const& _assertionStats) override;
4705 
4706  void sectionStarting(SectionInfo const& _sectionInfo) override;
4707  void sectionEnded(SectionStats const& _sectionStats) override;
4708 
4709  void benchmarkStarting(BenchmarkInfo const& info) override;
4710  void benchmarkEnded(BenchmarkStats const& stats) override;
4711 
4712  void testCaseEnded(TestCaseStats const& _testCaseStats) override;
4713  void testGroupEnded(TestGroupStats const& _testGroupStats) override;
4714  void testRunEnded(TestRunStats const& _testRunStats) override;
4715 
4716  private:
4717 
4718  void lazyPrint();
4719 
4720  void lazyPrintWithoutClosingBenchmarkTable();
4721  void lazyPrintRunInfo();
4722  void lazyPrintGroupInfo();
4723  void printTestCaseAndSectionHeader();
4724 
4725  void printClosedHeader(std::string const& _name);
4726  void printOpenHeader(std::string const& _name);
4727 
4728  // if string has a : in first line will set indent to follow it on
4729  // subsequent lines
4730  void printHeaderString(std::string const& _string, std::size_t indent = 0);
4731 
4732  void printTotals(Totals const& totals);
4733  void printSummaryRow(std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row);
4734 
4735  void printTotalsDivider(Totals const& totals);
4736  void printSummaryDivider();
4737 
4738  private:
4739  bool m_headerPrinted = false;
4740  };
4741 
4742 } // end namespace Catch
4743 
4744 #if defined(_MSC_VER)
4745 #pragma warning(pop)
4746 #endif
4747 
4748 // end catch_reporter_console.h
4749 // start catch_reporter_junit.h
4750 
4751 // start catch_xmlwriter.h
4752 
4753 #include <vector>
4754 
4755 namespace Catch {
4756 
4757  class XmlEncode {
4758  public:
4759  enum ForWhat { ForTextNodes, ForAttributes };
4760 
4761  XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes );
4762 
4763  void encodeTo( std::ostream& os ) const;
4764 
4765  friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode );
4766 
4767  private:
4768  std::string m_str;
4769  ForWhat m_forWhat;
4770  };
4771 
4772  class XmlWriter {
4773  public:
4774 
4775  class ScopedElement {
4776  public:
4777  ScopedElement( XmlWriter* writer );
4778 
4779  ScopedElement( ScopedElement&& other ) noexcept;
4780  ScopedElement& operator=( ScopedElement&& other ) noexcept;
4781 
4782  ~ScopedElement();
4783 
4784  ScopedElement& writeText( std::string const& text, bool indent = true );
4785 
4786  template<typename T>
4787  ScopedElement& writeAttribute( std::string const& name, T const& attribute ) {
4788  m_writer->writeAttribute( name, attribute );
4789  return *this;
4790  }
4791 
4792  private:
4793  mutable XmlWriter* m_writer = nullptr;
4794  };
4795 
4796  XmlWriter( std::ostream& os = Catch::cout() );
4797  ~XmlWriter();
4798 
4799  XmlWriter( XmlWriter const& ) = delete;
4800  XmlWriter& operator=( XmlWriter const& ) = delete;
4801 
4802  XmlWriter& startElement( std::string const& name );
4803 
4804  ScopedElement scopedElement( std::string const& name );
4805 
4806  XmlWriter& endElement();
4807 
4808  XmlWriter& writeAttribute( std::string const& name, std::string const& attribute );
4809 
4810  XmlWriter& writeAttribute( std::string const& name, bool attribute );
4811 
4812  template<typename T>
4813  XmlWriter& writeAttribute( std::string const& name, T const& attribute ) {
4815  rss << attribute;
4816  return writeAttribute( name, rss.str() );
4817  }
4818 
4819  XmlWriter& writeText( std::string const& text, bool indent = true );
4820 
4821  XmlWriter& writeComment( std::string const& text );
4822 
4823  void writeStylesheetRef( std::string const& url );
4824 
4825  XmlWriter& writeBlankLine();
4826 
4827  void ensureTagClosed();
4828 
4829  private:
4830 
4831  void writeDeclaration();
4832 
4833  void newlineIfNecessary();
4834 
4835  bool m_tagIsOpen = false;
4836  bool m_needsNewline = false;
4837  std::vector<std::string> m_tags;
4838  std::string m_indent;
4839  std::ostream& m_os;
4840  };
4841 
4842 }
4843 
4844 // end catch_xmlwriter.h
4845 namespace Catch {
4846 
4847  class JunitReporter : public CumulativeReporterBase<JunitReporter> {
4848  public:
4849  JunitReporter(ReporterConfig const& _config);
4850 
4851  ~JunitReporter() override;
4852 
4853  static std::string getDescription();
4854 
4855  void noMatchingTestCases(std::string const& /*spec*/) override;
4856 
4857  void testRunStarting(TestRunInfo const& runInfo) override;
4858 
4859  void testGroupStarting(GroupInfo const& groupInfo) override;
4860 
4861  void testCaseStarting(TestCaseInfo const& testCaseInfo) override;
4862  bool assertionEnded(AssertionStats const& assertionStats) override;
4863 
4864  void testCaseEnded(TestCaseStats const& testCaseStats) override;
4865 
4866  void testGroupEnded(TestGroupStats const& testGroupStats) override;
4867 
4868  void testRunEndedCumulative() override;
4869 
4870  void writeGroup(TestGroupNode const& groupNode, double suiteTime);
4871 
4872  void writeTestCase(TestCaseNode const& testCaseNode);
4873 
4874  void writeSection(std::string const& className,
4875  std::string const& rootName,
4876  SectionNode const& sectionNode);
4877 
4878  void writeAssertions(SectionNode const& sectionNode);
4879  void writeAssertion(AssertionStats const& stats);
4880 
4881  XmlWriter xml;
4882  Timer suiteTimer;
4883  std::string stdOutForSuite;
4884  std::string stdErrForSuite;
4885  unsigned int unexpectedExceptions = 0;
4886  bool m_okToFail = false;
4887  };
4888 
4889 } // end namespace Catch
4890 
4891 // end catch_reporter_junit.h
4892 // start catch_reporter_xml.h
4893 
4894 namespace Catch {
4895  class XmlReporter : public StreamingReporterBase<XmlReporter> {
4896  public:
4897  XmlReporter(ReporterConfig const& _config);
4898 
4899  ~XmlReporter() override;
4900 
4901  static std::string getDescription();
4902 
4903  virtual std::string getStylesheetRef() const;
4904 
4905  void writeSourceInfo(SourceLineInfo const& sourceInfo);
4906 
4907  public: // StreamingReporterBase
4908 
4909  void noMatchingTestCases(std::string const& s) override;
4910 
4911  void testRunStarting(TestRunInfo const& testInfo) override;
4912 
4913  void testGroupStarting(GroupInfo const& groupInfo) override;
4914 
4915  void testCaseStarting(TestCaseInfo const& testInfo) override;
4916 
4917  void sectionStarting(SectionInfo const& sectionInfo) override;
4918 
4919  void assertionStarting(AssertionInfo const&) override;
4920 
4921  bool assertionEnded(AssertionStats const& assertionStats) override;
4922 
4923  void sectionEnded(SectionStats const& sectionStats) override;
4924 
4925  void testCaseEnded(TestCaseStats const& testCaseStats) override;
4926 
4927  void testGroupEnded(TestGroupStats const& testGroupStats) override;
4928 
4929  void testRunEnded(TestRunStats const& testRunStats) override;
4930 
4931  private:
4932  Timer m_testCaseTimer;
4933  XmlWriter m_xml;
4934  int m_sectionDepth = 0;
4935  };
4936 
4937 } // end namespace Catch
4938 
4939 // end catch_reporter_xml.h
4940 
4941 // end catch_external_interfaces.h
4942 #endif
4943 
4944 #endif // ! CATCH_CONFIG_IMPL_ONLY
4945 
4946 #ifdef CATCH_IMPL
4947 // start catch_impl.hpp
4948 
4949 #ifdef __clang__
4950 #pragma clang diagnostic push
4951 #pragma clang diagnostic ignored "-Wweak-vtables"
4952 #endif
4953 
4954 // Keep these here for external reporters
4955 // start catch_test_case_tracker.h
4956 
4957 #include <string>
4958 #include <vector>
4959 #include <memory>
4960 
4961 namespace Catch {
4962 namespace TestCaseTracking {
4963 
4964  struct NameAndLocation {
4965  std::string name;
4966  SourceLineInfo location;
4967 
4968  NameAndLocation( std::string const& _name, SourceLineInfo const& _location );
4969  };
4970 
4971  struct ITracker;
4972 
4973  using ITrackerPtr = std::shared_ptr<ITracker>;
4974 
4975  struct ITracker {
4976  virtual ~ITracker();
4977 
4978  // static queries
4979  virtual NameAndLocation const& nameAndLocation() const = 0;
4980 
4981  // dynamic queries
4982  virtual bool isComplete() const = 0; // Successfully completed or failed
4983  virtual bool isSuccessfullyCompleted() const = 0;
4984  virtual bool isOpen() const = 0; // Started but not complete
4985  virtual bool hasChildren() const = 0;
4986 
4987  virtual ITracker& parent() = 0;
4988 
4989  // actions
4990  virtual void close() = 0; // Successfully complete
4991  virtual void fail() = 0;
4992  virtual void markAsNeedingAnotherRun() = 0;
4993 
4994  virtual void addChild( ITrackerPtr const& child ) = 0;
4995  virtual ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) = 0;
4996  virtual void openChild() = 0;
4997 
4998  // Debug/ checking
4999  virtual bool isSectionTracker() const = 0;
5000  virtual bool isIndexTracker() const = 0;
5001  };
5002 
5003  class TrackerContext {
5004 
5005  enum RunState {
5006  NotStarted,
5007  Executing,
5008  CompletedCycle
5009  };
5010 
5011  ITrackerPtr m_rootTracker;
5012  ITracker* m_currentTracker = nullptr;
5013  RunState m_runState = NotStarted;
5014 
5015  public:
5016 
5017  static TrackerContext& instance();
5018 
5019  ITracker& startRun();
5020  void endRun();
5021 
5022  void startCycle();
5023  void completeCycle();
5024 
5025  bool completedCycle() const;
5026  ITracker& currentTracker();
5027  void setCurrentTracker( ITracker* tracker );
5028  };
5029 
5030  class TrackerBase : public ITracker {
5031  protected:
5032  enum CycleState {
5033  NotStarted,
5034  Executing,
5035  ExecutingChildren,
5036  NeedsAnotherRun,
5037  CompletedSuccessfully,
5038  Failed
5039  };
5040 
5041  using Children = std::vector<ITrackerPtr>;
5042  NameAndLocation m_nameAndLocation;
5043  TrackerContext& m_ctx;
5044  ITracker* m_parent;
5045  Children m_children;
5046  CycleState m_runState = NotStarted;
5047 
5048  public:
5049  TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent );
5050 
5051  NameAndLocation const& nameAndLocation() const override;
5052  bool isComplete() const override;
5053  bool isSuccessfullyCompleted() const override;
5054  bool isOpen() const override;
5055  bool hasChildren() const override;
5056 
5057  void addChild( ITrackerPtr const& child ) override;
5058 
5059  ITrackerPtr findChild( NameAndLocation const& nameAndLocation ) override;
5060  ITracker& parent() override;
5061 
5062  void openChild() override;
5063 
5064  bool isSectionTracker() const override;
5065  bool isIndexTracker() const override;
5066 
5067  void open();
5068 
5069  void close() override;
5070  void fail() override;
5071  void markAsNeedingAnotherRun() override;
5072 
5073  private:
5074  void moveToParent();
5075  void moveToThis();
5076  };
5077 
5078  class SectionTracker : public TrackerBase {
5079  std::vector<std::string> m_filters;
5080  public:
5081  SectionTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent );
5082 
5083  bool isSectionTracker() const override;
5084 
5085  static SectionTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation );
5086 
5087  void tryOpen();
5088 
5089  void addInitialFilters( std::vector<std::string> const& filters );
5090  void addNextFilters( std::vector<std::string> const& filters );
5091  };
5092 
5093  class IndexTracker : public TrackerBase {
5094  int m_size;
5095  int m_index = -1;
5096  public:
5097  IndexTracker( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent, int size );
5098 
5099  bool isIndexTracker() const override;
5100  void close() override;
5101 
5102  static IndexTracker& acquire( TrackerContext& ctx, NameAndLocation const& nameAndLocation, int size );
5103 
5104  int index() const;
5105 
5106  void moveNext();
5107  };
5108 
5109 } // namespace TestCaseTracking
5110 
5111 using TestCaseTracking::ITracker;
5112 using TestCaseTracking::TrackerContext;
5113 using TestCaseTracking::SectionTracker;
5114 using TestCaseTracking::IndexTracker;
5115 
5116 } // namespace Catch
5117 
5118 // end catch_test_case_tracker.h
5119 
5120 // start catch_leak_detector.h
5121 
5122 namespace Catch {
5123 
5124  struct LeakDetector {
5125  LeakDetector();
5126  ~LeakDetector();
5127  };
5128 
5129 }
5130 // end catch_leak_detector.h
5131 // Cpp files will be included in the single-header file here
5132 // start catch_approx.cpp
5133 
5134 #include <cmath>
5135 #include <limits>
5136 
5137 namespace {
5138 
5139 // Performs equivalent check of std::fabs(lhs - rhs) <= margin
5140 // But without the subtraction to allow for INFINITY in comparison
5141 bool marginComparison(double lhs, double rhs, double margin) {
5142  return (lhs + margin >= rhs) && (rhs + margin >= lhs);
5143 }
5144 
5145 }
5146 
5147 namespace Catch {
5148 namespace Detail {
5149 
5150  Approx::Approx ( double value )
5151  : m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
5152  m_margin( 0.0 ),
5153  m_scale( 0.0 ),
5154  m_value( value )
5155  {}
5156 
5157  Approx Approx::custom() {
5158  return Approx( 0 );
5159  }
5160 
5161  Approx Approx::operator-() const {
5162  auto temp(*this);
5163  temp.m_value = -temp.m_value;
5164  return temp;
5165  }
5166 
5167  std::string Approx::toString() const {
5169  rss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )";
5170  return rss.str();
5171  }
5172 
5173  bool Approx::equalityComparisonImpl(const double other) const {
5174  // First try with fixed margin, then compute margin based on epsilon, scale and Approx's value
5175  // Thanks to Richard Harris for his help refining the scaled margin value
5176  return marginComparison(m_value, other, m_margin) || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(m_value)));
5177  }
5178 
5179  void Approx::setMargin(double margin) {
5180  CATCH_ENFORCE(margin >= 0,
5181  "Invalid Approx::margin: " << margin << '.'
5182  << " Approx::Margin has to be non-negative.");
5183  m_margin = margin;
5184  }
5185 
5186  void Approx::setEpsilon(double epsilon) {
5187  CATCH_ENFORCE(epsilon >= 0 && epsilon <= 1.0,
5188  "Invalid Approx::epsilon: " << epsilon << '.'
5189  << " Approx::epsilon has to be in [0, 1]");
5190  m_epsilon = epsilon;
5191  }
5192 
5193 } // end namespace Detail
5194 
5195 namespace literals {
5196  Detail::Approx operator "" _a(long double val) {
5197  return Detail::Approx(val);
5198  }
5199  Detail::Approx operator "" _a(unsigned long long val) {
5200  return Detail::Approx(val);
5201  }
5202 } // end namespace literals
5203 
5205  return value.toString();
5206 }
5207 
5208 } // end namespace Catch
5209 // end catch_approx.cpp
5210 // start catch_assertionhandler.cpp
5211 
5212 // start catch_context.h
5213 
5214 #include <memory>
5215 
5216 namespace Catch {
5217 
5218  struct IResultCapture;
5219  struct IRunner;
5220  struct IConfig;
5221  struct IMutableContext;
5222 
5223  using IConfigPtr = std::shared_ptr<IConfig const>;
5224 
5225  struct IContext
5226  {
5227  virtual ~IContext();
5228 
5229  virtual IResultCapture* getResultCapture() = 0;
5230  virtual IRunner* getRunner() = 0;
5231  virtual IConfigPtr const& getConfig() const = 0;
5232  };
5233 
5234  struct IMutableContext : IContext
5235  {
5236  virtual ~IMutableContext();
5237  virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
5238  virtual void setRunner( IRunner* runner ) = 0;
5239  virtual void setConfig( IConfigPtr const& config ) = 0;
5240 
5241  private:
5242  static IMutableContext *currentContext;
5243  friend IMutableContext& getCurrentMutableContext();
5244  friend void cleanUpContext();
5245  static void createContext();
5246  };
5247 
5248  inline IMutableContext& getCurrentMutableContext()
5249  {
5250  if( !IMutableContext::currentContext )
5251  IMutableContext::createContext();
5252  return *IMutableContext::currentContext;
5253  }
5254 
5255  inline IContext& getCurrentContext()
5256  {
5257  return getCurrentMutableContext();
5258  }
5259 
5260  void cleanUpContext();
5261 }
5262 
5263 // end catch_context.h
5264 // start catch_debugger.h
5265 
5266 namespace Catch {
5267  bool isDebuggerActive();
5268 }
5269 
5270 #ifdef CATCH_PLATFORM_MAC
5271 
5272  #define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */
5273 
5274 #elif defined(CATCH_PLATFORM_LINUX)
5275  // If we can use inline assembler, do it because this allows us to break
5276  // directly at the location of the failing check instead of breaking inside
5277  // raise() called from it, i.e. one stack frame below.
5278  #if defined(__GNUC__) && (defined(__i386) || defined(__x86_64))
5279  #define CATCH_TRAP() asm volatile ("int $3") /* NOLINT */
5280  #else // Fall back to the generic way.
5281  #include <signal.h>
5282 
5283  #define CATCH_TRAP() raise(SIGTRAP)
5284  #endif
5285 #elif defined(_MSC_VER)
5286  #define CATCH_TRAP() __debugbreak()
5287 #elif defined(__MINGW32__)
5288  extern "C" __declspec(dllimport) void __stdcall DebugBreak();
5289  #define CATCH_TRAP() DebugBreak()
5290 #endif
5291 
5292 #ifdef CATCH_TRAP
5293  #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { CATCH_TRAP(); }
5294 #else
5295  namespace Catch {
5296  inline void doNothing() {}
5297  }
5298  #define CATCH_BREAK_INTO_DEBUGGER() Catch::doNothing()
5299 #endif
5300 
5301 // end catch_debugger.h
5302 // start catch_run_context.h
5303 
5304 // start catch_fatal_condition.h
5305 
5306 // start catch_windows_h_proxy.h
5307 
5308 
5309 #if defined(CATCH_PLATFORM_WINDOWS)
5310 
5311 #if !defined(NOMINMAX) && !defined(CATCH_CONFIG_NO_NOMINMAX)
5312 # define CATCH_DEFINED_NOMINMAX
5313 # define NOMINMAX
5314 #endif
5315 #if !defined(WIN32_LEAN_AND_MEAN) && !defined(CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN)
5316 # define CATCH_DEFINED_WIN32_LEAN_AND_MEAN
5317 # define WIN32_LEAN_AND_MEAN
5318 #endif
5319 
5320 #ifdef __AFXDLL
5321 #include <AfxWin.h>
5322 #else
5323 #include <windows.h>
5324 #endif
5325 
5326 #ifdef CATCH_DEFINED_NOMINMAX
5327 # undef NOMINMAX
5328 #endif
5329 #ifdef CATCH_DEFINED_WIN32_LEAN_AND_MEAN
5330 # undef WIN32_LEAN_AND_MEAN
5331 #endif
5332 
5333 #endif // defined(CATCH_PLATFORM_WINDOWS)
5334 
5335 // end catch_windows_h_proxy.h
5336 #if defined( CATCH_CONFIG_WINDOWS_SEH )
5337 
5338 namespace Catch {
5339 
5340  struct FatalConditionHandler {
5341 
5342  static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo);
5343  FatalConditionHandler();
5344  static void reset();
5345  ~FatalConditionHandler();
5346 
5347  private:
5348  static bool isSet;
5349  static ULONG guaranteeSize;
5350  static PVOID exceptionHandlerHandle;
5351  };
5352 
5353 } // namespace Catch
5354 
5355 #elif defined ( CATCH_CONFIG_POSIX_SIGNALS )
5356 
5357 #include <signal.h>
5358 
5359 namespace Catch {
5360 
5361  struct FatalConditionHandler {
5362 
5363  static bool isSet;
5364  static struct sigaction oldSigActions[];
5365  static stack_t oldSigStack;
5366  static char altStackMem[];
5367 
5368  static void handleSignal( int sig );
5369 
5370  FatalConditionHandler();
5371  ~FatalConditionHandler();
5372  static void reset();
5373  };
5374 
5375 } // namespace Catch
5376 
5377 #else
5378 
5379 namespace Catch {
5380  struct FatalConditionHandler {
5381  void reset();
5382  };
5383 }
5384 
5385 #endif
5386 
5387 // end catch_fatal_condition.h
5388 #include <string>
5389 
5390 namespace Catch {
5391 
5392  struct IMutableContext;
5393 
5395 
5396  class RunContext : public IResultCapture, public IRunner {
5397 
5398  public:
5399  RunContext( RunContext const& ) = delete;
5400  RunContext& operator =( RunContext const& ) = delete;
5401 
5402  explicit RunContext( IConfigPtr const& _config, IStreamingReporterPtr&& reporter );
5403 
5404  ~RunContext() override;
5405 
5406  void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount );
5407  void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount );
5408 
5409  Totals runTest(TestCase const& testCase);
5410 
5411  IConfigPtr config() const;
5412  IStreamingReporter& reporter() const;
5413 
5414  public: // IResultCapture
5415 
5416  // Assertion handlers
5417  void handleExpr
5418  ( AssertionInfo const& info,
5419  ITransientExpression const& expr,
5420  AssertionReaction& reaction ) override;
5421  void handleMessage
5422  ( AssertionInfo const& info,
5423  ResultWas::OfType resultType,
5424  StringRef const& message,
5425  AssertionReaction& reaction ) override;
5426  void handleUnexpectedExceptionNotThrown
5427  ( AssertionInfo const& info,
5428  AssertionReaction& reaction ) override;
5429  void handleUnexpectedInflightException
5430  ( AssertionInfo const& info,
5431  std::string const& message,
5432  AssertionReaction& reaction ) override;
5433  void handleIncomplete
5434  ( AssertionInfo const& info ) override;
5435  void handleNonExpr
5436  ( AssertionInfo const &info,
5437  ResultWas::OfType resultType,
5438  AssertionReaction &reaction ) override;
5439 
5440  bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override;
5441 
5442  void sectionEnded( SectionEndInfo const& endInfo ) override;
5443  void sectionEndedEarly( SectionEndInfo const& endInfo ) override;
5444 
5445  auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker& override;
5446 
5447  void benchmarkStarting( BenchmarkInfo const& info ) override;
5448  void benchmarkEnded( BenchmarkStats const& stats ) override;
5449 
5450  void pushScopedMessage( MessageInfo const& message ) override;
5451  void popScopedMessage( MessageInfo const& message ) override;
5452 
5453  std::string getCurrentTestName() const override;
5454 
5455  const AssertionResult* getLastResult() const override;
5456 
5457  void exceptionEarlyReported() override;
5458 
5459  void handleFatalErrorCondition( StringRef message ) override;
5460 
5461  bool lastAssertionPassed() override;
5462 
5463  void assertionPassed() override;
5464 
5465  public:
5466  // !TBD We need to do this another way!
5467  bool aborting() const final;
5468 
5469  private:
5470 
5471  void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr );
5472  void invokeActiveTestCase();
5473 
5474  void resetAssertionInfo();
5475  bool testForMissingAssertions( Counts& assertions );
5476 
5477  void assertionEnded( AssertionResult const& result );
5478  void reportExpr
5479  ( AssertionInfo const &info,
5480  ResultWas::OfType resultType,
5481  ITransientExpression const *expr,
5482  bool negated );
5483 
5484  void populateReaction( AssertionReaction& reaction );
5485 
5486  private:
5487 
5488  void handleUnfinishedSections();
5489 
5490  TestRunInfo m_runInfo;
5491  IMutableContext& m_context;
5492  TestCase const* m_activeTestCase = nullptr;
5493  ITracker* m_testCaseTracker;
5494  Option<AssertionResult> m_lastResult;
5495 
5496  IConfigPtr m_config;
5497  Totals m_totals;
5498  IStreamingReporterPtr m_reporter;
5499  std::vector<MessageInfo> m_messages;
5500  AssertionInfo m_lastAssertionInfo;
5501  std::vector<SectionEndInfo> m_unfinishedSections;
5502  std::vector<ITracker*> m_activeSections;
5503  TrackerContext m_trackerContext;
5504  bool m_lastAssertionPassed = false;
5505  bool m_shouldReportUnexpected = true;
5506  bool m_includeSuccessfulResults;
5507  };
5508 
5509 } // end namespace Catch
5510 
5511 // end catch_run_context.h
5512 namespace Catch {
5513 
5514  namespace {
5515  auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& {
5516  expr.streamReconstructedExpression( os );
5517  return os;
5518  }
5519  }
5520 
5521  LazyExpression::LazyExpression( bool isNegated )
5522  : m_isNegated( isNegated )
5523  {}
5524 
5525  LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {}
5526 
5527  LazyExpression::operator bool() const {
5528  return m_transientExpression != nullptr;
5529  }
5530 
5531  auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& {
5532  if( lazyExpr.m_isNegated )
5533  os << "!";
5534 
5535  if( lazyExpr ) {
5536  if( lazyExpr.m_isNegated && lazyExpr.m_transientExpression->isBinaryExpression() )
5537  os << "(" << *lazyExpr.m_transientExpression << ")";
5538  else
5539  os << *lazyExpr.m_transientExpression;
5540  }
5541  else {
5542  os << "{** error - unchecked empty expression requested **}";
5543  }
5544  return os;
5545  }
5546 
5548  ( StringRef const& macroName,
5549  SourceLineInfo const& lineInfo,
5550  StringRef capturedExpression,
5551  ResultDisposition::Flags resultDisposition )
5552  : m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition },
5553  m_resultCapture( getResultCapture() )
5554  {}
5555 
5557  m_resultCapture.handleExpr( m_assertionInfo, expr, m_reaction );
5558  }
5559  void AssertionHandler::handleMessage(ResultWas::OfType resultType, StringRef const& message) {
5560  m_resultCapture.handleMessage( m_assertionInfo, resultType, message, m_reaction );
5561  }
5562 
5563  auto AssertionHandler::allowThrows() const -> bool {
5564  return getCurrentContext().getConfig()->allowThrows();
5565  }
5566 
5568  setCompleted();
5569  if( m_reaction.shouldDebugBreak ) {
5570 
5571  // If you find your debugger stopping you here then go one level up on the
5572  // call-stack for the code that caused it (typically a failed assertion)
5573 
5574  // (To go back to the test and change execution, jump over the throw, next)
5575  CATCH_BREAK_INTO_DEBUGGER();
5576  }
5577  if (m_reaction.shouldThrow) {
5578 #if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
5580 #else
5581  CATCH_ERROR( "Test failure requires aborting test!" );
5582 #endif
5583  }
5584  }
5586  m_completed = true;
5587  }
5588 
5590  m_resultCapture.handleUnexpectedInflightException( m_assertionInfo, Catch::translateActiveException(), m_reaction );
5591  }
5592 
5594  m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction);
5595  }
5597  m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction);
5598  }
5599 
5601  m_resultCapture.handleUnexpectedExceptionNotThrown( m_assertionInfo, m_reaction );
5602  }
5603 
5605  m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction);
5606  }
5607 
5608  // This is the overload that takes a string and infers the Equals matcher from it
5609  // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp
5610  void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString ) {
5611  handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString );
5612  }
5613 
5614 } // namespace Catch
5615 // end catch_assertionhandler.cpp
5616 // start catch_assertionresult.cpp
5617 
5618 namespace Catch {
5619  AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression):
5620  lazyExpression(_lazyExpression),
5621  resultType(_resultType) {}
5622 
5623  std::string AssertionResultData::reconstructExpression() const {
5624 
5625  if( reconstructedExpression.empty() ) {
5626  if( lazyExpression ) {
5628  rss << lazyExpression;
5629  reconstructedExpression = rss.str();
5630  }
5631  }
5632  return reconstructedExpression;
5633  }
5634 
5635  AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data )
5636  : m_info( info ),
5637  m_resultData( data )
5638  {}
5639 
5640  // Result was a success
5641  bool AssertionResult::succeeded() const {
5642  return Catch::isOk( m_resultData.resultType );
5643  }
5644 
5645  // Result was a success, or failure is suppressed
5646  bool AssertionResult::isOk() const {
5647  return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition );
5648  }
5649 
5650  ResultWas::OfType AssertionResult::getResultType() const {
5651  return m_resultData.resultType;
5652  }
5653 
5654  bool AssertionResult::hasExpression() const {
5655  return m_info.capturedExpression[0] != 0;
5656  }
5657 
5658  bool AssertionResult::hasMessage() const {
5659  return !m_resultData.message.empty();
5660  }
5661 
5662  std::string AssertionResult::getExpression() const {
5663  if( isFalseTest( m_info.resultDisposition ) )
5664  return "!(" + m_info.capturedExpression + ")";
5665  else
5666  return m_info.capturedExpression;
5667  }
5668 
5669  std::string AssertionResult::getExpressionInMacro() const {
5670  std::string expr;
5671  if( m_info.macroName[0] == 0 )
5672  expr = m_info.capturedExpression;
5673  else {
5674  expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 );
5675  expr += m_info.macroName;
5676  expr += "( ";
5677  expr += m_info.capturedExpression;
5678  expr += " )";
5679  }
5680  return expr;
5681  }
5682 
5683  bool AssertionResult::hasExpandedExpression() const {
5684  return hasExpression() && getExpandedExpression() != getExpression();
5685  }
5686 
5687  std::string AssertionResult::getExpandedExpression() const {
5688  std::string expr = m_resultData.reconstructExpression();
5689  return expr.empty()
5690  ? getExpression()
5691  : expr;
5692  }
5693 
5694  std::string AssertionResult::getMessage() const {
5695  return m_resultData.message;
5696  }
5697  SourceLineInfo AssertionResult::getSourceInfo() const {
5698  return m_info.lineInfo;
5699  }
5700 
5701  StringRef AssertionResult::getTestMacroName() const {
5702  return m_info.macroName;
5703  }
5704 
5705 } // end namespace Catch
5706 // end catch_assertionresult.cpp
5707 // start catch_benchmark.cpp
5708 
5709 namespace Catch {
5710 
5711  auto BenchmarkLooper::getResolution() -> uint64_t {
5712  return getEstimatedClockResolution() * getCurrentContext().getConfig()->benchmarkResolutionMultiple();
5713  }
5714 
5716  getResultCapture().benchmarkStarting( { m_name } );
5717  }
5718  auto BenchmarkLooper::needsMoreIterations() -> bool {
5719  auto elapsed = m_timer.getElapsedNanoseconds();
5720 
5721  // Exponentially increasing iterations until we're confident in our timer resolution
5722  if( elapsed < m_resolution ) {
5723  m_iterationsToRun *= 10;
5724  return true;
5725  }
5726 
5727  getResultCapture().benchmarkEnded( { { m_name }, m_count, elapsed } );
5728  return false;
5729  }
5730 
5731 } // end namespace Catch
5732 // end catch_benchmark.cpp
5733 // start catch_capture_matchers.cpp
5734 
5735 namespace Catch {
5736 
5738 
5739  // This is the general overload that takes a any string matcher
5740  // There is another overload, in catch_assertionhandler.h/.cpp, that only takes a string and infers
5741  // the Equals matcher (so the header does not mention matchers)
5742  void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString ) {
5743  std::string exceptionMessage = Catch::translateActiveException();
5744  MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString );
5745  handler.handleExpr( expr );
5746  }
5747 
5748 } // namespace Catch
5749 // end catch_capture_matchers.cpp
5750 // start catch_commandline.cpp
5751 
5752 // start catch_commandline.h
5753 
5754 // start catch_clara.h
5755 
5756 // Use Catch's value for console width (store Clara's off to the side, if present)
5757 #ifdef CLARA_CONFIG_CONSOLE_WIDTH
5758 #define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
5759 #undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
5760 #endif
5761 #define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH-1
5762 
5763 #ifdef __clang__
5764 #pragma clang diagnostic push
5765 #pragma clang diagnostic ignored "-Wweak-vtables"
5766 #pragma clang diagnostic ignored "-Wexit-time-destructors"
5767 #pragma clang diagnostic ignored "-Wshadow"
5768 #endif
5769 
5770 // start clara.hpp
5771 // Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
5772 //
5773 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5774 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5775 //
5776 // See https://github.com/philsquared/Clara for more details
5777 
5778 // Clara v1.1.5
5779 
5780 
5781 #ifndef CATCH_CLARA_CONFIG_CONSOLE_WIDTH
5782 #define CATCH_CLARA_CONFIG_CONSOLE_WIDTH 80
5783 #endif
5784 
5785 #ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
5786 #define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CLARA_CONFIG_CONSOLE_WIDTH
5787 #endif
5788 
5789 #ifndef CLARA_CONFIG_OPTIONAL_TYPE
5790 #ifdef __has_include
5791 #if __has_include(<optional>) && __cplusplus >= 201703L
5792 #include <optional>
5793 #define CLARA_CONFIG_OPTIONAL_TYPE std::optional
5794 #endif
5795 #endif
5796 #endif
5797 
5798 // ----------- #included from clara_textflow.hpp -----------
5799 
5800 // TextFlowCpp
5801 //
5802 // A single-header library for wrapping and laying out basic text, by Phil Nash
5803 //
5804 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5805 // file LICENSE.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5806 //
5807 // This project is hosted at https://github.com/philsquared/textflowcpp
5808 
5809 
5810 #include <cassert>
5811 #include <ostream>
5812 #include <sstream>
5813 #include <vector>
5814 
5815 #ifndef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
5816 #define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH 80
5817 #endif
5818 
5819 namespace Catch {
5820 namespace clara {
5821 namespace TextFlow {
5822 
5823 inline auto isWhitespace(char c) -> bool {
5824  static std::string chars = " \t\n\r";
5825  return chars.find(c) != std::string::npos;
5826 }
5827 inline auto isBreakableBefore(char c) -> bool {
5828  static std::string chars = "[({<|";
5829  return chars.find(c) != std::string::npos;
5830 }
5831 inline auto isBreakableAfter(char c) -> bool {
5832  static std::string chars = "])}>.,:;*+-=&/\\";
5833  return chars.find(c) != std::string::npos;
5834 }
5835 
5836 class Columns;
5837 
5838 class Column {
5839  std::vector<std::string> m_strings;
5840  size_t m_width = CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH;
5841  size_t m_indent = 0;
5842  size_t m_initialIndent = std::string::npos;
5843 
5844 public:
5845  class iterator {
5846  friend Column;
5847 
5848  Column const& m_column;
5849  size_t m_stringIndex = 0;
5850  size_t m_pos = 0;
5851 
5852  size_t m_len = 0;
5853  size_t m_end = 0;
5854  bool m_suffix = false;
5855 
5856  iterator(Column const& column, size_t stringIndex)
5857  : m_column(column),
5858  m_stringIndex(stringIndex) {}
5859 
5860  auto line() const -> std::string const& { return m_column.m_strings[m_stringIndex]; }
5861 
5862  auto isBoundary(size_t at) const -> bool {
5863  assert(at > 0);
5864  assert(at <= line().size());
5865 
5866  return at == line().size() ||
5867  (isWhitespace(line()[at]) && !isWhitespace(line()[at - 1])) ||
5868  isBreakableBefore(line()[at]) ||
5869  isBreakableAfter(line()[at - 1]);
5870  }
5871 
5872  void calcLength() {
5873  assert(m_stringIndex < m_column.m_strings.size());
5874 
5875  m_suffix = false;
5876  auto width = m_column.m_width - indent();
5877  m_end = m_pos;
5878  while (m_end < line().size() && line()[m_end] != '\n')
5879  ++m_end;
5880 
5881  if (m_end < m_pos + width) {
5882  m_len = m_end - m_pos;
5883  } else {
5884  size_t len = width;
5885  while (len > 0 && !isBoundary(m_pos + len))
5886  --len;
5887  while (len > 0 && isWhitespace(line()[m_pos + len - 1]))
5888  --len;
5889 
5890  if (len > 0) {
5891  m_len = len;
5892  } else {
5893  m_suffix = true;
5894  m_len = width - 1;
5895  }
5896  }
5897  }
5898 
5899  auto indent() const -> size_t {
5900  auto initial = m_pos == 0 && m_stringIndex == 0 ? m_column.m_initialIndent : std::string::npos;
5901  return initial == std::string::npos ? m_column.m_indent : initial;
5902  }
5903 
5904  auto addIndentAndSuffix(std::string const &plain) const -> std::string {
5905  return std::string(indent(), ' ') + (m_suffix ? plain + "-" : plain);
5906  }
5907 
5908  public:
5909  using difference_type = std::ptrdiff_t;
5910  using value_type = std::string;
5911  using pointer = value_type * ;
5912  using reference = value_type & ;
5913  using iterator_category = std::forward_iterator_tag;
5914 
5915  explicit iterator(Column const& column) : m_column(column) {
5916  assert(m_column.m_width > m_column.m_indent);
5917  assert(m_column.m_initialIndent == std::string::npos || m_column.m_width > m_column.m_initialIndent);
5918  calcLength();
5919  if (m_len == 0)
5920  m_stringIndex++; // Empty string
5921  }
5922 
5923  auto operator *() const -> std::string {
5924  assert(m_stringIndex < m_column.m_strings.size());
5925  assert(m_pos <= m_end);
5926  return addIndentAndSuffix(line().substr(m_pos, m_len));
5927  }
5928 
5929  auto operator ++() -> iterator& {
5930  m_pos += m_len;
5931  if (m_pos < line().size() && line()[m_pos] == '\n')
5932  m_pos += 1;
5933  else
5934  while (m_pos < line().size() && isWhitespace(line()[m_pos]))
5935  ++m_pos;
5936 
5937  if (m_pos == line().size()) {
5938  m_pos = 0;
5939  ++m_stringIndex;
5940  }
5941  if (m_stringIndex < m_column.m_strings.size())
5942  calcLength();
5943  return *this;
5944  }
5945  auto operator ++(int) -> iterator {
5946  iterator prev(*this);
5947  operator++();
5948  return prev;
5949  }
5950 
5951  auto operator ==(iterator const& other) const -> bool {
5952  return
5953  m_pos == other.m_pos &&
5954  m_stringIndex == other.m_stringIndex &&
5955  &m_column == &other.m_column;
5956  }
5957  auto operator !=(iterator const& other) const -> bool {
5958  return !operator==(other);
5959  }
5960  };
5961  using const_iterator = iterator;
5962 
5963  explicit Column(std::string const& text) { m_strings.push_back(text); }
5964 
5965  auto width(size_t newWidth) -> Column& {
5966  assert(newWidth > 0);
5967  m_width = newWidth;
5968  return *this;
5969  }
5970  auto indent(size_t newIndent) -> Column& {
5971  m_indent = newIndent;
5972  return *this;
5973  }
5974  auto initialIndent(size_t newIndent) -> Column& {
5975  m_initialIndent = newIndent;
5976  return *this;
5977  }
5978 
5979  auto width() const -> size_t { return m_width; }
5980  auto begin() const -> iterator { return iterator(*this); }
5981  auto end() const -> iterator { return { *this, m_strings.size() }; }
5982 
5983  inline friend std::ostream& operator << (std::ostream& os, Column const& col) {
5984  bool first = true;
5985  for (auto line : col) {
5986  if (first)
5987  first = false;
5988  else
5989  os << "\n";
5990  os << line;
5991  }
5992  return os;
5993  }
5994 
5995  auto operator + (Column const& other)->Columns;
5996 
5997  auto toString() const -> std::string {
5998  std::ostringstream oss;
5999  oss << *this;
6000  return oss.str();
6001  }
6002 };
6003 
6004 class Spacer : public Column {
6005 
6006 public:
6007  explicit Spacer(size_t spaceWidth) : Column("") {
6008  width(spaceWidth);
6009  }
6010 };
6011 
6012 class Columns {
6013  std::vector<Column> m_columns;
6014 
6015 public:
6016 
6017  class iterator {
6018  friend Columns;
6019  struct EndTag {};
6020 
6021  std::vector<Column> const& m_columns;
6022  std::vector<Column::iterator> m_iterators;
6023  size_t m_activeIterators;
6024 
6025  iterator(Columns const& columns, EndTag)
6026  : m_columns(columns.m_columns),
6027  m_activeIterators(0) {
6028  m_iterators.reserve(m_columns.size());
6029 
6030  for (auto const& col : m_columns)
6031  m_iterators.push_back(col.end());
6032  }
6033 
6034  public:
6035  using difference_type = std::ptrdiff_t;
6036  using value_type = std::string;
6037  using pointer = value_type * ;
6038  using reference = value_type & ;
6039  using iterator_category = std::forward_iterator_tag;
6040 
6041  explicit iterator(Columns const& columns)
6042  : m_columns(columns.m_columns),
6043  m_activeIterators(m_columns.size()) {
6044  m_iterators.reserve(m_columns.size());
6045 
6046  for (auto const& col : m_columns)
6047  m_iterators.push_back(col.begin());
6048  }
6049 
6050  auto operator ==(iterator const& other) const -> bool {
6051  return m_iterators == other.m_iterators;
6052  }
6053  auto operator !=(iterator const& other) const -> bool {
6054  return m_iterators != other.m_iterators;
6055  }
6056  auto operator *() const -> std::string {
6057  std::string row, padding;
6058 
6059  for (size_t i = 0; i < m_columns.size(); ++i) {
6060  auto width = m_columns[i].width();
6061  if (m_iterators[i] != m_columns[i].end()) {
6062  std::string col = *m_iterators[i];
6063  row += padding + col;
6064  if (col.size() < width)
6065  padding = std::string(width - col.size(), ' ');
6066  else
6067  padding = "";
6068  } else {
6069  padding += std::string(width, ' ');
6070  }
6071  }
6072  return row;
6073  }
6074  auto operator ++() -> iterator& {
6075  for (size_t i = 0; i < m_columns.size(); ++i) {
6076  if (m_iterators[i] != m_columns[i].end())
6077  ++m_iterators[i];
6078  }
6079  return *this;
6080  }
6081  auto operator ++(int) -> iterator {
6082  iterator prev(*this);
6083  operator++();
6084  return prev;
6085  }
6086  };
6087  using const_iterator = iterator;
6088 
6089  auto begin() const -> iterator { return iterator(*this); }
6090  auto end() const -> iterator { return { *this, iterator::EndTag() }; }
6091 
6092  auto operator += (Column const& col) -> Columns& {
6093  m_columns.push_back(col);
6094  return *this;
6095  }
6096  auto operator + (Column const& col) -> Columns {
6097  Columns combined = *this;
6098  combined += col;
6099  return combined;
6100  }
6101 
6102  inline friend std::ostream& operator << (std::ostream& os, Columns const& cols) {
6103 
6104  bool first = true;
6105  for (auto line : cols) {
6106  if (first)
6107  first = false;
6108  else
6109  os << "\n";
6110  os << line;
6111  }
6112  return os;
6113  }
6114 
6115  auto toString() const -> std::string {
6116  std::ostringstream oss;
6117  oss << *this;
6118  return oss.str();
6119  }
6120 };
6121 
6122 inline auto Column::operator + (Column const& other) -> Columns {
6123  Columns cols;
6124  cols += *this;
6125  cols += other;
6126  return cols;
6127 }
6128 }
6129 
6130 }
6131 }
6132 
6133 // ----------- end of #include from clara_textflow.hpp -----------
6134 // ........... back in clara.hpp
6135 
6136 #include <string>
6137 #include <memory>
6138 #include <set>
6139 #include <algorithm>
6140 
6141 #if !defined(CATCH_PLATFORM_WINDOWS) && ( defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) )
6142 #define CATCH_PLATFORM_WINDOWS
6143 #endif
6144 
6145 namespace Catch { namespace clara {
6146 namespace detail {
6147 
6148  // Traits for extracting arg and return type of lambdas (for single argument lambdas)
6149  template<typename L>
6150  struct UnaryLambdaTraits : UnaryLambdaTraits<decltype( &L::operator() )> {};
6151 
6152  template<typename ClassT, typename ReturnT, typename... Args>
6153  struct UnaryLambdaTraits<ReturnT( ClassT::* )( Args... ) const> {
6154  static const bool isValid = false;
6155  };
6156 
6157  template<typename ClassT, typename ReturnT, typename ArgT>
6158  struct UnaryLambdaTraits<ReturnT( ClassT::* )( ArgT ) const> {
6159  static const bool isValid = true;
6160  using ArgType = typename std::remove_const<typename std::remove_reference<ArgT>::type>::type;
6161  using ReturnType = ReturnT;
6162  };
6163 
6164  class TokenStream;
6165 
6166  // Transport for raw args (copied from main args, or supplied via init list for testing)
6167  class Args {
6168  friend TokenStream;
6169  std::string m_exeName;
6170  std::vector<std::string> m_args;
6171 
6172  public:
6173  Args( int argc, char const* const* argv )
6174  : m_exeName(argv[0]),
6175  m_args(argv + 1, argv + argc) {}
6176 
6177  Args( std::initializer_list<std::string> args )
6178  : m_exeName( *args.begin() ),
6179  m_args( args.begin()+1, args.end() )
6180  {}
6181 
6182  auto exeName() const -> std::string {
6183  return m_exeName;
6184  }
6185  };
6186 
6187  // Wraps a token coming from a token stream. These may not directly correspond to strings as a single string
6188  // may encode an option + its argument if the : or = form is used
6189  enum class TokenType {
6190  Option, Argument
6191  };
6192  struct Token {
6193  TokenType type;
6194  std::string token;
6195  };
6196 
6197  inline auto isOptPrefix( char c ) -> bool {
6198  return c == '-'
6199 #ifdef CATCH_PLATFORM_WINDOWS
6200  || c == '/'
6201 #endif
6202  ;
6203  }
6204 
6205  // Abstracts iterators into args as a stream of tokens, with option arguments uniformly handled
6206  class TokenStream {
6207  using Iterator = std::vector<std::string>::const_iterator;
6208  Iterator it;
6209  Iterator itEnd;
6210  std::vector<Token> m_tokenBuffer;
6211 
6212  void loadBuffer() {
6213  m_tokenBuffer.resize( 0 );
6214 
6215  // Skip any empty strings
6216  while( it != itEnd && it->empty() )
6217  ++it;
6218 
6219  if( it != itEnd ) {
6220  auto const &next = *it;
6221  if( isOptPrefix( next[0] ) ) {
6222  auto delimiterPos = next.find_first_of( " :=" );
6223  if( delimiterPos != std::string::npos ) {
6224  m_tokenBuffer.push_back( { TokenType::Option, next.substr( 0, delimiterPos ) } );
6225  m_tokenBuffer.push_back( { TokenType::Argument, next.substr( delimiterPos + 1 ) } );
6226  } else {
6227  if( next[1] != '-' && next.size() > 2 ) {
6228  std::string opt = "- ";
6229  for( size_t i = 1; i < next.size(); ++i ) {
6230  opt[1] = next[i];
6231  m_tokenBuffer.push_back( { TokenType::Option, opt } );
6232  }
6233  } else {
6234  m_tokenBuffer.push_back( { TokenType::Option, next } );
6235  }
6236  }
6237  } else {
6238  m_tokenBuffer.push_back( { TokenType::Argument, next } );
6239  }
6240  }
6241  }
6242 
6243  public:
6244  explicit TokenStream( Args const &args ) : TokenStream( args.m_args.begin(), args.m_args.end() ) {}
6245 
6246  TokenStream( Iterator it, Iterator itEnd ) : it( it ), itEnd( itEnd ) {
6247  loadBuffer();
6248  }
6249 
6250  explicit operator bool() const {
6251  return !m_tokenBuffer.empty() || it != itEnd;
6252  }
6253 
6254  auto count() const -> size_t { return m_tokenBuffer.size() + (itEnd - it); }
6255 
6256  auto operator*() const -> Token {
6257  assert( !m_tokenBuffer.empty() );
6258  return m_tokenBuffer.front();
6259  }
6260 
6261  auto operator->() const -> Token const * {
6262  assert( !m_tokenBuffer.empty() );
6263  return &m_tokenBuffer.front();
6264  }
6265 
6266  auto operator++() -> TokenStream & {
6267  if( m_tokenBuffer.size() >= 2 ) {
6268  m_tokenBuffer.erase( m_tokenBuffer.begin() );
6269  } else {
6270  if( it != itEnd )
6271  ++it;
6272  loadBuffer();
6273  }
6274  return *this;
6275  }
6276  };
6277 
6278  class ResultBase {
6279  public:
6280  enum Type {
6281  Ok, LogicError, RuntimeError
6282  };
6283 
6284  protected: