OSVR-Core
catch.hpp
1 /*
2  * Catch v1.5.8
3  * Generated: 2016-10-26 12:07:30.938259
4  * ----------------------------------------------------------
5  * This file has been merged from multiple headers. Please don't edit it directly
6  * Copyright (c) 2012 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 
14 #define TWOBLUECUBES_CATCH_HPP_INCLUDED
15 
16 #ifdef __clang__
17 # pragma clang system_header
18 #elif defined __GNUC__
19 # pragma GCC system_header
20 #endif
21 
22 // #included from: internal/catch_suppress_warnings.h
23 
24 #ifdef __clang__
25 # ifdef __ICC // icpc defines the __clang__ macro
26 # pragma warning(push)
27 # pragma warning(disable: 161 1682)
28 # else // __ICC
29 # pragma clang diagnostic ignored "-Wglobal-constructors"
30 # pragma clang diagnostic ignored "-Wvariadic-macros"
31 # pragma clang diagnostic ignored "-Wc99-extensions"
32 # pragma clang diagnostic ignored "-Wunused-variable"
33 # pragma clang diagnostic push
34 # pragma clang diagnostic ignored "-Wpadded"
35 # pragma clang diagnostic ignored "-Wc++98-compat"
36 # pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
37 # pragma clang diagnostic ignored "-Wswitch-enum"
38 # pragma clang diagnostic ignored "-Wcovered-switch-default"
39 # endif
40 #elif defined __GNUC__
41 # pragma GCC diagnostic ignored "-Wvariadic-macros"
42 # pragma GCC diagnostic ignored "-Wunused-variable"
43 # pragma GCC diagnostic push
44 # pragma GCC diagnostic ignored "-Wpadded"
45 #endif
46 #if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER)
47 # define CATCH_IMPL
48 #endif
49 
50 #ifdef CATCH_IMPL
51 # ifndef CLARA_CONFIG_MAIN
52 # define CLARA_CONFIG_MAIN_NOT_DEFINED
53 # define CLARA_CONFIG_MAIN
54 # endif
55 #endif
56 
57 // #included from: internal/catch_notimplemented_exception.h
58 #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED
59 
60 // #included from: catch_common.h
61 #define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED
62 
63 #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
64 #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
65 #ifdef CATCH_CONFIG_COUNTER
66 # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ )
67 #else
68 # define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
69 #endif
70 
71 #define INTERNAL_CATCH_STRINGIFY2( expr ) #expr
72 #define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr )
73 
74 #include <sstream>
75 #include <stdexcept>
76 #include <algorithm>
77 
78 // #included from: catch_compiler_capabilities.h
79 #define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
80 
81 // Detect a number of compiler features - mostly C++11/14 conformance - by compiler
82 // The following features are defined:
83 //
84 // CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported?
85 // CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported?
86 // CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods
87 // CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported?
88 // CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported
89 // CATCH_CONFIG_CPP11_LONG_LONG : is long long supported?
90 // CATCH_CONFIG_CPP11_OVERRIDE : is override supported?
91 // CATCH_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr)
92 
93 // CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
94 
95 // CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported?
96 // CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported?
97 // ****************
98 // Note to maintainers: if new toggles are added please document them
99 // in configuration.md, too
100 // ****************
101 
102 // In general each macro has a _NO_<feature name> form
103 // (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature.
104 // Many features, at point of detection, define an _INTERNAL_ macro, so they
105 // can be combined, en-mass, with the _NO_ forms later.
106 
107 // All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11
108 
109 #ifdef __cplusplus
110 
111 # if __cplusplus >= 201103L
112 # define CATCH_CPP11_OR_GREATER
113 # endif
114 
115 # if __cplusplus >= 201402L
116 # define CATCH_CPP14_OR_GREATER
117 # endif
118 
119 #endif
120 
121 #ifdef __clang__
122 
123 # if __has_feature(cxx_nullptr)
124 # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
125 # endif
126 
127 # if __has_feature(cxx_noexcept)
128 # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
129 # endif
130 
131 # if defined(CATCH_CPP11_OR_GREATER)
132 # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
133 # endif
134 
135 #endif // __clang__
136 
138 // Borland
139 #ifdef __BORLANDC__
140 
141 #endif // __BORLANDC__
142 
144 // EDG
145 #ifdef __EDG_VERSION__
146 
147 #endif // __EDG_VERSION__
148 
150 // Digital Mars
151 #ifdef __DMC__
152 
153 #endif // __DMC__
154 
156 // GCC
157 #ifdef __GNUC__
158 
159 # if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
160 # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
161 # endif
162 
163 # if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) && defined(CATCH_CPP11_OR_GREATER)
164 # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS _Pragma( "GCC diagnostic ignored \"-Wparentheses\"" )
165 # endif
166 
167 // - otherwise more recent versions define __cplusplus >= 201103L
168 // and will get picked up below
169 
170 #endif // __GNUC__
171 
173 // Visual C++
174 #ifdef _MSC_VER
175 
176 #if (_MSC_VER >= 1600)
177 # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
178 # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
179 #endif
180 
181 #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
182 #define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
183 #define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
184 #endif
185 
186 #endif // _MSC_VER
187 
189 
190 // Use variadic macros if the compiler supports them
191 #if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \
192  ( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \
193  ( defined __GNUC__ && __GNUC__ >= 3 ) || \
194  ( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L )
195 
196 #define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
197 
198 #endif
199 
200 // Use __COUNTER__ if the compiler supports it
201 #if ( defined _MSC_VER && _MSC_VER >= 1300 ) || \
202  ( defined __GNUC__ && __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 ) || \
203  ( defined __clang__ && __clang_major__ >= 3 )
204 
205 #define CATCH_INTERNAL_CONFIG_COUNTER
206 
207 #endif
208 
210 // C++ language feature support
211 
212 // catch all support for C++11
213 #if defined(CATCH_CPP11_OR_GREATER)
214 
215 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR)
216 # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
217 # endif
218 
219 # ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
220 # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
221 # endif
222 
223 # ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
224 # define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
225 # endif
226 
227 # ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
228 # define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
229 # endif
230 
231 # ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE
232 # define CATCH_INTERNAL_CONFIG_CPP11_TUPLE
233 # endif
234 
235 # ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
236 # define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
237 # endif
238 
239 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG)
240 # define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG
241 # endif
242 
243 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE)
244 # define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE
245 # endif
246 # if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
247 # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
248 # endif
249 
250 #endif // __cplusplus >= 201103L
251 
252 // Now set the actual defines based on the above + anything the user has configured
253 #if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11)
254 # define CATCH_CONFIG_CPP11_NULLPTR
255 #endif
256 #if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11)
257 # define CATCH_CONFIG_CPP11_NOEXCEPT
258 #endif
259 #if defined(CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_NO_CPP11)
260 # define CATCH_CONFIG_CPP11_GENERATED_METHODS
261 #endif
262 #if defined(CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_NO_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_NO_CPP11)
263 # define CATCH_CONFIG_CPP11_IS_ENUM
264 #endif
265 #if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11)
266 # define CATCH_CONFIG_CPP11_TUPLE
267 #endif
268 #if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS)
269 # define CATCH_CONFIG_VARIADIC_MACROS
270 #endif
271 #if defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_CPP11)
272 # define CATCH_CONFIG_CPP11_LONG_LONG
273 #endif
274 #if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11)
275 # define CATCH_CONFIG_CPP11_OVERRIDE
276 #endif
277 #if defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_CPP11)
278 # define CATCH_CONFIG_CPP11_UNIQUE_PTR
279 #endif
280 #if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
281 # define CATCH_CONFIG_COUNTER
282 #endif
283 
284 #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
285 # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
286 #endif
287 
288 // noexcept support:
289 #if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT)
290 # define CATCH_NOEXCEPT noexcept
291 # define CATCH_NOEXCEPT_IS(x) noexcept(x)
292 #else
293 # define CATCH_NOEXCEPT throw()
294 # define CATCH_NOEXCEPT_IS(x)
295 #endif
296 
297 // nullptr support
298 #ifdef CATCH_CONFIG_CPP11_NULLPTR
299 # define CATCH_NULL nullptr
300 #else
301 # define CATCH_NULL NULL
302 #endif
303 
304 // override support
305 #ifdef CATCH_CONFIG_CPP11_OVERRIDE
306 # define CATCH_OVERRIDE override
307 #else
308 # define CATCH_OVERRIDE
309 #endif
310 
311 // unique_ptr support
312 #ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR
313 # define CATCH_AUTO_PTR( T ) std::unique_ptr<T>
314 #else
315 # define CATCH_AUTO_PTR( T ) std::auto_ptr<T>
316 #endif
317 
318 namespace Catch {
319 
320  struct IConfig;
321 
322  struct CaseSensitive { enum Choice {
323  Yes,
324  No
325  }; };
326 
327  class NonCopyable {
328 #ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
329  NonCopyable( NonCopyable const& ) = delete;
330  NonCopyable( NonCopyable && ) = delete;
331  NonCopyable& operator = ( NonCopyable const& ) = delete;
332  NonCopyable& operator = ( NonCopyable && ) = delete;
333 #else
334  NonCopyable( NonCopyable const& info );
335  NonCopyable& operator = ( NonCopyable const& );
336 #endif
337 
338  protected:
339  NonCopyable() {}
340  virtual ~NonCopyable();
341  };
342 
343  class SafeBool {
344  public:
345  typedef void (SafeBool::*type)() const;
346 
347  static type makeSafe( bool value ) {
348  return value ? &SafeBool::trueValue : 0;
349  }
350  private:
351  void trueValue() const {}
352  };
353 
354  template<typename ContainerT>
355  inline void deleteAll( ContainerT& container ) {
356  typename ContainerT::const_iterator it = container.begin();
357  typename ContainerT::const_iterator itEnd = container.end();
358  for(; it != itEnd; ++it )
359  delete *it;
360  }
361  template<typename AssociativeContainerT>
362  inline void deleteAllValues( AssociativeContainerT& container ) {
363  typename AssociativeContainerT::const_iterator it = container.begin();
364  typename AssociativeContainerT::const_iterator itEnd = container.end();
365  for(; it != itEnd; ++it )
366  delete it->second;
367  }
368 
369  bool startsWith( std::string const& s, std::string const& prefix );
370  bool endsWith( std::string const& s, std::string const& suffix );
371  bool contains( std::string const& s, std::string const& infix );
372  void toLowerInPlace( std::string& s );
373  std::string toLower( std::string const& s );
374  std::string trim( std::string const& str );
375  bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
376 
377  struct pluralise {
378  pluralise( std::size_t count, std::string const& label );
379 
380  friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
381 
382  std::size_t m_count;
383  std::string m_label;
384  };
385 
386  struct SourceLineInfo {
387 
388  SourceLineInfo();
389  SourceLineInfo( char const* _file, std::size_t _line );
390  SourceLineInfo( SourceLineInfo const& other );
391 # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
392  SourceLineInfo( SourceLineInfo && ) = default;
393  SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
394  SourceLineInfo& operator = ( SourceLineInfo && ) = default;
395 # endif
396  bool empty() const;
397  bool operator == ( SourceLineInfo const& other ) const;
398  bool operator < ( SourceLineInfo const& other ) const;
399 
400  std::string file;
401  std::size_t line;
402  };
403 
404  std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
405 
406  // This is just here to avoid compiler warnings with macro constants and boolean literals
407  inline bool isTrue( bool value ){ return value; }
408  inline bool alwaysTrue() { return true; }
409  inline bool alwaysFalse() { return false; }
410 
411  void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo );
412 
413  void seedRng( IConfig const& config );
414  unsigned int rngSeed();
415 
416  // Use this in variadic streaming macros to allow
417  // >> +StreamEndStop
418  // as well as
419  // >> stuff +StreamEndStop
420  struct StreamEndStop {
421  std::string operator+() {
422  return std::string();
423  }
424  };
425  template<typename T>
426  T const& operator + ( T const& value, StreamEndStop ) {
427  return value;
428  }
429 }
430 
431 #define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
432 #define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO );
433 
434 #include <ostream>
435 
436 namespace Catch {
437 
438  class NotImplementedException : public std::exception
439  {
440  public:
441  NotImplementedException( SourceLineInfo const& lineInfo );
443 
444  virtual ~NotImplementedException() CATCH_NOEXCEPT {}
445 
446  virtual const char* what() const CATCH_NOEXCEPT;
447 
448  private:
449  std::string m_what;
450  SourceLineInfo m_lineInfo;
451  };
452 
453 } // end namespace Catch
454 
456 #define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO )
457 
458 // #included from: internal/catch_context.h
459 #define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
460 
461 // #included from: catch_interfaces_generators.h
462 #define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED
463 
464 #include <string>
465 
466 namespace Catch {
467 
468  struct IGeneratorInfo {
469  virtual ~IGeneratorInfo();
470  virtual bool moveNext() = 0;
471  virtual std::size_t getCurrentIndex() const = 0;
472  };
473 
475  virtual ~IGeneratorsForTest();
476 
477  virtual IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) = 0;
478  virtual bool moveNext() = 0;
479  };
480 
481  IGeneratorsForTest* createGeneratorsForTest();
482 
483 } // end namespace Catch
484 
485 // #included from: catch_ptr.hpp
486 #define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED
487 
488 #ifdef __clang__
489 #pragma clang diagnostic push
490 #pragma clang diagnostic ignored "-Wpadded"
491 #endif
492 
493 namespace Catch {
494 
495  // An intrusive reference counting smart pointer.
496  // T must implement addRef() and release() methods
497  // typically implementing the IShared interface
498  template<typename T>
499  class Ptr {
500  public:
501  Ptr() : m_p( CATCH_NULL ){}
502  Ptr( T* p ) : m_p( p ){
503  if( m_p )
504  m_p->addRef();
505  }
506  Ptr( Ptr const& other ) : m_p( other.m_p ){
507  if( m_p )
508  m_p->addRef();
509  }
510  ~Ptr(){
511  if( m_p )
512  m_p->release();
513  }
514  void reset() {
515  if( m_p )
516  m_p->release();
517  m_p = CATCH_NULL;
518  }
519  Ptr& operator = ( T* p ){
520  Ptr temp( p );
521  swap( temp );
522  return *this;
523  }
524  Ptr& operator = ( Ptr const& other ){
525  Ptr temp( other );
526  swap( temp );
527  return *this;
528  }
529  void swap( Ptr& other ) { std::swap( m_p, other.m_p ); }
530  T* get() const{ return m_p; }
531  T& operator*() const { return *m_p; }
532  T* operator->() const { return m_p; }
533  bool operator !() const { return m_p == CATCH_NULL; }
534  operator SafeBool::type() const { return SafeBool::makeSafe( m_p != CATCH_NULL ); }
535 
536  private:
537  T* m_p;
538  };
539 
540  struct IShared : NonCopyable {
541  virtual ~IShared();
542  virtual void addRef() const = 0;
543  virtual void release() const = 0;
544  };
545 
546  template<typename T = IShared>
547  struct SharedImpl : T {
548 
549  SharedImpl() : m_rc( 0 ){}
550 
551  virtual void addRef() const {
552  ++m_rc;
553  }
554  virtual void release() const {
555  if( --m_rc == 0 )
556  delete this;
557  }
558 
559  mutable unsigned int m_rc;
560  };
561 
562 } // end namespace Catch
563 
564 #ifdef __clang__
565 #pragma clang diagnostic pop
566 #endif
567 
568 #include <memory>
569 #include <vector>
570 #include <stdlib.h>
571 
572 namespace Catch {
573 
574  class TestCase;
575  class Stream;
576  struct IResultCapture;
577  struct IRunner;
578  struct IGeneratorsForTest;
579  struct IConfig;
580 
581  struct IContext
582  {
583  virtual ~IContext();
584 
585  virtual IResultCapture* getResultCapture() = 0;
586  virtual IRunner* getRunner() = 0;
587  virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0;
588  virtual bool advanceGeneratorsForCurrentTest() = 0;
589  virtual Ptr<IConfig const> getConfig() const = 0;
590  };
591 
593  {
594  virtual ~IMutableContext();
595  virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
596  virtual void setRunner( IRunner* runner ) = 0;
597  virtual void setConfig( Ptr<IConfig const> const& config ) = 0;
598  };
599 
600  IContext& getCurrentContext();
601  IMutableContext& getCurrentMutableContext();
602  void cleanUpContext();
603  Stream createStream( std::string const& streamName );
604 
605 }
606 
607 // #included from: internal/catch_test_registry.hpp
608 #define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED
609 
610 // #included from: catch_interfaces_testcase.h
611 #define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
612 
613 #include <vector>
614 
615 namespace Catch {
616 
617  class TestSpec;
618 
619  struct ITestCase : IShared {
620  virtual void invoke () const = 0;
621  protected:
622  virtual ~ITestCase();
623  };
624 
625  class TestCase;
626  struct IConfig;
627 
629  virtual ~ITestCaseRegistry();
630  virtual std::vector<TestCase> const& getAllTests() const = 0;
631  virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const = 0;
632  };
633 
634  bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config );
635  std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config );
636  std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config );
637 
638 }
639 
640 namespace Catch {
641 
642 template<typename C>
643 class MethodTestCase : public SharedImpl<ITestCase> {
644 
645 public:
646  MethodTestCase( void (C::*method)() ) : m_method( method ) {}
647 
648  virtual void invoke() const {
649  C obj;
650  (obj.*m_method)();
651  }
652 
653 private:
654  virtual ~MethodTestCase() {}
655 
656  void (C::*m_method)();
657 };
658 
659 typedef void(*TestFunction)();
660 
661 struct NameAndDesc {
662  NameAndDesc( const char* _name = "", const char* _description= "" )
663  : name( _name ), description( _description )
664  {}
665 
666  const char* name;
667  const char* description;
668 };
669 
670 void registerTestCase
671  ( ITestCase* testCase,
672  char const* className,
673  NameAndDesc const& nameAndDesc,
674  SourceLineInfo const& lineInfo );
675 
676 struct AutoReg {
677 
678  AutoReg
679  ( TestFunction function,
680  SourceLineInfo const& lineInfo,
681  NameAndDesc const& nameAndDesc );
682 
683  template<typename C>
684  AutoReg
685  ( void (C::*method)(),
686  char const* className,
687  NameAndDesc const& nameAndDesc,
688  SourceLineInfo const& lineInfo ) {
689 
690  registerTestCase
691  ( new MethodTestCase<C>( method ),
692  className,
693  nameAndDesc,
694  lineInfo );
695  }
696 
697  ~AutoReg();
698 
699 private:
700  AutoReg( AutoReg const& );
701  void operator= ( AutoReg const& );
702 };
703 
704 void registerTestCaseFunction
705  ( TestFunction function,
706  SourceLineInfo const& lineInfo,
707  NameAndDesc const& nameAndDesc );
708 
709 } // end namespace Catch
710 
711 #ifdef CATCH_CONFIG_VARIADIC_MACROS
712  #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
714  static void TestName(); \
715  namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); }\
716  static void TestName()
717  #define INTERNAL_CATCH_TESTCASE( ... ) \
718  INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ )
719 
721  #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
722  namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); }
723 
725  #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
726  namespace{ \
727  struct TestName : ClassName{ \
728  void test(); \
729  }; \
730  Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestName::test, #ClassName, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); \
731  } \
732  void TestName::test()
733  #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
734  INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ )
735 
737  #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
738  Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) );
739 
740 #else
741  #define INTERNAL_CATCH_TESTCASE2( TestName, Name, Desc ) \
743  static void TestName(); \
744  namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &TestName, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); }\
745  static void TestName()
746  #define INTERNAL_CATCH_TESTCASE( Name, Desc ) \
747  INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), Name, Desc )
748 
750  #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
751  namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( Name, Desc ), CATCH_INTERNAL_LINEINFO ); }
752 
754  #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestCaseName, ClassName, TestName, Desc )\
755  namespace{ \
756  struct TestCaseName : ClassName{ \
757  void test(); \
758  }; \
759  Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &TestCaseName::test, #ClassName, Catch::NameAndDesc( TestName, Desc ), CATCH_INTERNAL_LINEINFO ); \
760  } \
761  void TestCaseName::test()
762  #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, TestName, Desc )\
763  INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, TestName, Desc )
764 
766  #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, Name, Desc ) \
767  Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) );
768 #endif
769 
770 // #included from: internal/catch_capture.hpp
771 #define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
772 
773 // #included from: catch_result_builder.h
774 #define TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED
775 
776 // #included from: catch_result_type.h
777 #define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED
778 
779 namespace Catch {
780 
781  // ResultWas::OfType enum
782  struct ResultWas { enum OfType {
783  Unknown = -1,
784  Ok = 0,
785  Info = 1,
786  Warning = 2,
787 
788  FailureBit = 0x10,
789 
790  ExpressionFailed = FailureBit | 1,
791  ExplicitFailure = FailureBit | 2,
792 
793  Exception = 0x100 | FailureBit,
794 
795  ThrewException = Exception | 1,
796  DidntThrowException = Exception | 2,
797 
798  FatalErrorCondition = 0x200 | FailureBit
799 
800  }; };
801 
802  inline bool isOk( ResultWas::OfType resultType ) {
803  return ( resultType & ResultWas::FailureBit ) == 0;
804  }
805  inline bool isJustInfo( int flags ) {
806  return flags == ResultWas::Info;
807  }
808 
809  // ResultDisposition::Flags enum
810  struct ResultDisposition { enum Flags {
811  Normal = 0x01,
812 
813  ContinueOnFailure = 0x02, // Failures fail test, but execution continues
814  FalseTest = 0x04, // Prefix expression with !
815  SuppressFail = 0x08 // Failures are reported but do not fail the test
816  }; };
817 
818  inline ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) {
819  return static_cast<ResultDisposition::Flags>( static_cast<int>( lhs ) | static_cast<int>( rhs ) );
820  }
821 
822  inline bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; }
823  inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; }
824  inline bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; }
825 
826 } // end namespace Catch
827 
828 // #included from: catch_assertionresult.h
829 #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
830 
831 #include <string>
832 
833 namespace Catch {
834 
836  {
837  AssertionInfo() {}
838  AssertionInfo( std::string const& _macroName,
839  SourceLineInfo const& _lineInfo,
840  std::string const& _capturedExpression,
841  ResultDisposition::Flags _resultDisposition );
842 
843  std::string macroName;
844  SourceLineInfo lineInfo;
845  std::string capturedExpression;
846  ResultDisposition::Flags resultDisposition;
847  };
848 
850  {
851  AssertionResultData() : resultType( ResultWas::Unknown ) {}
852 
853  std::string reconstructedExpression;
854  std::string message;
855  ResultWas::OfType resultType;
856  };
857 
859  public:
860  AssertionResult();
861  AssertionResult( AssertionInfo const& info, AssertionResultData const& data );
862  ~AssertionResult();
863 # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
864  AssertionResult( AssertionResult const& ) = default;
865  AssertionResult( AssertionResult && ) = default;
866  AssertionResult& operator = ( AssertionResult const& ) = default;
867  AssertionResult& operator = ( AssertionResult && ) = default;
868 # endif
869 
870  bool isOk() const;
871  bool succeeded() const;
872  ResultWas::OfType getResultType() const;
873  bool hasExpression() const;
874  bool hasMessage() const;
875  std::string getExpression() const;
876  std::string getExpressionInMacro() const;
877  bool hasExpandedExpression() const;
878  std::string getExpandedExpression() const;
879  std::string getMessage() const;
880  SourceLineInfo getSourceInfo() const;
881  std::string getTestMacroName() const;
882 
883  protected:
884  AssertionInfo m_info;
885  AssertionResultData m_resultData;
886  };
887 
888 } // end namespace Catch
889 
890 // #included from: catch_matchers.hpp
891 #define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED
892 
893 namespace Catch {
894 namespace Matchers {
895  namespace Impl {
896 
897  namespace Generic {
898  template<typename ExpressionT> class AllOf;
899  template<typename ExpressionT> class AnyOf;
900  template<typename ExpressionT> class Not;
901  }
902 
903  template<typename ExpressionT>
904  struct Matcher : SharedImpl<IShared>
905  {
906  typedef ExpressionT ExpressionType;
907 
908  virtual ~Matcher() {}
909  virtual Ptr<Matcher> clone() const = 0;
910  virtual bool match( ExpressionT const& expr ) const = 0;
911  virtual std::string toString() const = 0;
912 
913  Generic::AllOf<ExpressionT> operator && ( Matcher<ExpressionT> const& other ) const;
914  Generic::AnyOf<ExpressionT> operator || ( Matcher<ExpressionT> const& other ) const;
915  Generic::Not<ExpressionT> operator ! () const;
916  };
917 
918  template<typename DerivedT, typename ExpressionT>
919  struct MatcherImpl : Matcher<ExpressionT> {
920 
921  virtual Ptr<Matcher<ExpressionT> > clone() const {
922  return Ptr<Matcher<ExpressionT> >( new DerivedT( static_cast<DerivedT const&>( *this ) ) );
923  }
924  };
925 
926  namespace Generic {
927  template<typename ExpressionT>
928  class Not : public MatcherImpl<Not<ExpressionT>, ExpressionT> {
929  public:
930  explicit Not( Matcher<ExpressionT> const& matcher ) : m_matcher(matcher.clone()) {}
931  Not( Not const& other ) : m_matcher( other.m_matcher ) {}
932 
933  virtual bool match( ExpressionT const& expr ) const CATCH_OVERRIDE {
934  return !m_matcher->match( expr );
935  }
936 
937  virtual std::string toString() const CATCH_OVERRIDE {
938  return "not " + m_matcher->toString();
939  }
940  private:
941  Ptr< Matcher<ExpressionT> > m_matcher;
942  };
943 
944  template<typename ExpressionT>
945  class AllOf : public MatcherImpl<AllOf<ExpressionT>, ExpressionT> {
946  public:
947 
948  AllOf() {}
949  AllOf( AllOf const& other ) : m_matchers( other.m_matchers ) {}
950 
951  AllOf& add( Matcher<ExpressionT> const& matcher ) {
952  m_matchers.push_back( matcher.clone() );
953  return *this;
954  }
955  virtual bool match( ExpressionT const& expr ) const
956  {
957  for( std::size_t i = 0; i < m_matchers.size(); ++i )
958  if( !m_matchers[i]->match( expr ) )
959  return false;
960  return true;
961  }
962  virtual std::string toString() const {
963  std::ostringstream oss;
964  oss << "( ";
965  for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
966  if( i != 0 )
967  oss << " and ";
968  oss << m_matchers[i]->toString();
969  }
970  oss << " )";
971  return oss.str();
972  }
973 
974  AllOf operator && ( Matcher<ExpressionT> const& other ) const {
975  AllOf allOfExpr( *this );
976  allOfExpr.add( other );
977  return allOfExpr;
978  }
979 
980  private:
981  std::vector<Ptr<Matcher<ExpressionT> > > m_matchers;
982  };
983 
984  template<typename ExpressionT>
985  class AnyOf : public MatcherImpl<AnyOf<ExpressionT>, ExpressionT> {
986  public:
987 
988  AnyOf() {}
989  AnyOf( AnyOf const& other ) : m_matchers( other.m_matchers ) {}
990 
991  AnyOf& add( Matcher<ExpressionT> const& matcher ) {
992  m_matchers.push_back( matcher.clone() );
993  return *this;
994  }
995  virtual bool match( ExpressionT const& expr ) const
996  {
997  for( std::size_t i = 0; i < m_matchers.size(); ++i )
998  if( m_matchers[i]->match( expr ) )
999  return true;
1000  return false;
1001  }
1002  virtual std::string toString() const {
1003  std::ostringstream oss;
1004  oss << "( ";
1005  for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
1006  if( i != 0 )
1007  oss << " or ";
1008  oss << m_matchers[i]->toString();
1009  }
1010  oss << " )";
1011  return oss.str();
1012  }
1013 
1014  AnyOf operator || ( Matcher<ExpressionT> const& other ) const {
1015  AnyOf anyOfExpr( *this );
1016  anyOfExpr.add( other );
1017  return anyOfExpr;
1018  }
1019 
1020  private:
1021  std::vector<Ptr<Matcher<ExpressionT> > > m_matchers;
1022  };
1023 
1024  } // namespace Generic
1025 
1026  template<typename ExpressionT>
1028  Generic::AllOf<ExpressionT> allOfExpr;
1029  allOfExpr.add( *this );
1030  allOfExpr.add( other );
1031  return allOfExpr;
1032  }
1033 
1034  template<typename ExpressionT>
1036  Generic::AnyOf<ExpressionT> anyOfExpr;
1037  anyOfExpr.add( *this );
1038  anyOfExpr.add( other );
1039  return anyOfExpr;
1040  }
1041 
1042  template<typename ExpressionT>
1044  return Generic::Not<ExpressionT>( *this );
1045  }
1046 
1047  namespace StdString {
1048 
1049  inline std::string makeString( std::string const& str ) { return str; }
1050  inline std::string makeString( const char* str ) { return str ? std::string( str ) : std::string(); }
1051 
1053  {
1054  CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity )
1055  : m_caseSensitivity( caseSensitivity ),
1056  m_str( adjustString( str ) )
1057  {}
1058  std::string adjustString( std::string const& str ) const {
1059  return m_caseSensitivity == CaseSensitive::No
1060  ? toLower( str )
1061  : str;
1062 
1063  }
1064  std::string toStringSuffix() const
1065  {
1066  return m_caseSensitivity == CaseSensitive::No
1067  ? " (case insensitive)"
1068  : "";
1069  }
1070  CaseSensitive::Choice m_caseSensitivity;
1071  std::string m_str;
1072  };
1073 
1074  struct Equals : MatcherImpl<Equals, std::string> {
1075  Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes )
1076  : m_data( str, caseSensitivity )
1077  {}
1078  Equals( Equals const& other ) : m_data( other.m_data ){}
1079 
1080  virtual ~Equals();
1081 
1082  virtual bool match( std::string const& expr ) const {
1083  return m_data.m_str == m_data.adjustString( expr );;
1084  }
1085  virtual std::string toString() const {
1086  return "equals: \"" + m_data.m_str + "\"" + m_data.toStringSuffix();
1087  }
1088 
1089  CasedString m_data;
1090  };
1091 
1092  struct Contains : MatcherImpl<Contains, std::string> {
1093  Contains( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes )
1094  : m_data( substr, caseSensitivity ){}
1095  Contains( Contains const& other ) : m_data( other.m_data ){}
1096 
1097  virtual ~Contains();
1098 
1099  virtual bool match( std::string const& expr ) const {
1100  return m_data.adjustString( expr ).find( m_data.m_str ) != std::string::npos;
1101  }
1102  virtual std::string toString() const {
1103  return "contains: \"" + m_data.m_str + "\"" + m_data.toStringSuffix();
1104  }
1105 
1106  CasedString m_data;
1107  };
1108 
1109  struct StartsWith : MatcherImpl<StartsWith, std::string> {
1110  StartsWith( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes )
1111  : m_data( substr, caseSensitivity ){}
1112 
1113  StartsWith( StartsWith const& other ) : m_data( other.m_data ){}
1114 
1115  virtual ~StartsWith();
1116 
1117  virtual bool match( std::string const& expr ) const {
1118  return startsWith( m_data.adjustString( expr ), m_data.m_str );
1119  }
1120  virtual std::string toString() const {
1121  return "starts with: \"" + m_data.m_str + "\"" + m_data.toStringSuffix();
1122  }
1123 
1124  CasedString m_data;
1125  };
1126 
1127  struct EndsWith : MatcherImpl<EndsWith, std::string> {
1128  EndsWith( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes )
1129  : m_data( substr, caseSensitivity ){}
1130  EndsWith( EndsWith const& other ) : m_data( other.m_data ){}
1131 
1132  virtual ~EndsWith();
1133 
1134  virtual bool match( std::string const& expr ) const {
1135  return endsWith( m_data.adjustString( expr ), m_data.m_str );
1136  }
1137  virtual std::string toString() const {
1138  return "ends with: \"" + m_data.m_str + "\"" + m_data.toStringSuffix();
1139  }
1140 
1141  CasedString m_data;
1142  };
1143  } // namespace StdString
1144  } // namespace Impl
1145 
1146  // The following functions create the actual matcher objects.
1147  // This allows the types to be inferred
1148  template<typename ExpressionT>
1150  return Impl::Generic::Not<ExpressionT>( m );
1151  }
1152 
1153  template<typename ExpressionT>
1155  Impl::Matcher<ExpressionT> const& m2 ) {
1156  return Impl::Generic::AllOf<ExpressionT>().add( m1 ).add( m2 );
1157  }
1158  template<typename ExpressionT>
1160  Impl::Matcher<ExpressionT> const& m2,
1161  Impl::Matcher<ExpressionT> const& m3 ) {
1162  return Impl::Generic::AllOf<ExpressionT>().add( m1 ).add( m2 ).add( m3 );
1163  }
1164  template<typename ExpressionT>
1166  Impl::Matcher<ExpressionT> const& m2 ) {
1167  return Impl::Generic::AnyOf<ExpressionT>().add( m1 ).add( m2 );
1168  }
1169  template<typename ExpressionT>
1171  Impl::Matcher<ExpressionT> const& m2,
1172  Impl::Matcher<ExpressionT> const& m3 ) {
1173  return Impl::Generic::AnyOf<ExpressionT>().add( m1 ).add( m2 ).add( m3 );
1174  }
1175 
1176  inline Impl::StdString::Equals Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) {
1177  return Impl::StdString::Equals( str, caseSensitivity );
1178  }
1179  inline Impl::StdString::Equals Equals( const char* str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) {
1180  return Impl::StdString::Equals( Impl::StdString::makeString( str ), caseSensitivity );
1181  }
1182  inline Impl::StdString::Contains Contains( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) {
1183  return Impl::StdString::Contains( substr, caseSensitivity );
1184  }
1185  inline Impl::StdString::Contains Contains( const char* substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) {
1186  return Impl::StdString::Contains( Impl::StdString::makeString( substr ), caseSensitivity );
1187  }
1188  inline Impl::StdString::StartsWith StartsWith( std::string const& substr ) {
1189  return Impl::StdString::StartsWith( substr );
1190  }
1191  inline Impl::StdString::StartsWith StartsWith( const char* substr ) {
1193  }
1194  inline Impl::StdString::EndsWith EndsWith( std::string const& substr ) {
1195  return Impl::StdString::EndsWith( substr );
1196  }
1197  inline Impl::StdString::EndsWith EndsWith( const char* substr ) {
1199  }
1200 
1201 } // namespace Matchers
1202 
1203 using namespace Matchers;
1204 
1205 } // namespace Catch
1206 
1207 namespace Catch {
1208 
1210 
1211  template<typename T> class ExpressionLhs;
1212 
1213  struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
1214 
1216  CopyableStream() {}
1217  CopyableStream( CopyableStream const& other ) {
1218  oss << other.oss.str();
1219  }
1220  CopyableStream& operator=( CopyableStream const& other ) {
1221  oss.str("");
1222  oss << other.oss.str();
1223  return *this;
1224  }
1225  std::ostringstream oss;
1226  };
1227 
1229  public:
1230  ResultBuilder( char const* macroName,
1231  SourceLineInfo const& lineInfo,
1232  char const* capturedExpression,
1233  ResultDisposition::Flags resultDisposition,
1234  char const* secondArg = "" );
1235 
1236  template<typename T>
1237  ExpressionLhs<T const&> operator <= ( T const& operand );
1238  ExpressionLhs<bool> operator <= ( bool value );
1239 
1240  template<typename T>
1241  ResultBuilder& operator << ( T const& value ) {
1242  m_stream.oss << value;
1243  return *this;
1244  }
1245 
1246  template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& );
1247  template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& );
1248 
1249  ResultBuilder& setResultType( ResultWas::OfType result );
1250  ResultBuilder& setResultType( bool result );
1251  ResultBuilder& setLhs( std::string const& lhs );
1252  ResultBuilder& setRhs( std::string const& rhs );
1253  ResultBuilder& setOp( std::string const& op );
1254 
1255  void endExpression();
1256 
1257  std::string reconstructExpression() const;
1258  AssertionResult build() const;
1259 
1260  void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal );
1261  void captureResult( ResultWas::OfType resultType );
1262  void captureExpression();
1263  void captureExpectedException( std::string const& expectedMessage );
1264  void captureExpectedException( Matchers::Impl::Matcher<std::string> const& matcher );
1265  void handleResult( AssertionResult const& result );
1266  void react();
1267  bool shouldDebugBreak() const;
1268  bool allowThrows() const;
1269 
1270  private:
1271  AssertionInfo m_assertionInfo;
1272  AssertionResultData m_data;
1273  struct ExprComponents {
1274  ExprComponents() : testFalse( false ) {}
1275  bool testFalse;
1276  std::string lhs, rhs, op;
1277  } m_exprComponents;
1278  CopyableStream m_stream;
1279 
1280  bool m_shouldDebugBreak;
1281  bool m_shouldThrow;
1282  };
1283 
1284 } // namespace Catch
1285 
1286 // Include after due to circular dependency:
1287 // #included from: catch_expression_lhs.hpp
1288 #define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED
1289 
1290 // #included from: catch_evaluate.hpp
1291 #define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED
1292 
1293 #ifdef _MSC_VER
1294 #pragma warning(push)
1295 #pragma warning(disable:4389) // '==' : signed/unsigned mismatch
1296 #endif
1297 
1298 #include <cstddef>
1299 
1300 namespace Catch {
1301 namespace Internal {
1302 
1303  enum Operator {
1304  IsEqualTo,
1305  IsNotEqualTo,
1306  IsLessThan,
1307  IsGreaterThan,
1308  IsLessThanOrEqualTo,
1309  IsGreaterThanOrEqualTo
1310  };
1311 
1312  template<Operator Op> struct OperatorTraits { static const char* getName(){ return "*error*"; } };
1313  template<> struct OperatorTraits<IsEqualTo> { static const char* getName(){ return "=="; } };
1314  template<> struct OperatorTraits<IsNotEqualTo> { static const char* getName(){ return "!="; } };
1315  template<> struct OperatorTraits<IsLessThan> { static const char* getName(){ return "<"; } };
1316  template<> struct OperatorTraits<IsGreaterThan> { static const char* getName(){ return ">"; } };
1317  template<> struct OperatorTraits<IsLessThanOrEqualTo> { static const char* getName(){ return "<="; } };
1318  template<> struct OperatorTraits<IsGreaterThanOrEqualTo>{ static const char* getName(){ return ">="; } };
1319 
1320  template<typename T>
1321  inline T& opCast(T const& t) { return const_cast<T&>(t); }
1322 
1323 // nullptr_t support based on pull request #154 from Konstantin Baumann
1324 #ifdef CATCH_CONFIG_CPP11_NULLPTR
1325  inline std::nullptr_t opCast(std::nullptr_t) { return nullptr; }
1326 #endif // CATCH_CONFIG_CPP11_NULLPTR
1327 
1328  // So the compare overloads can be operator agnostic we convey the operator as a template
1329  // enum, which is used to specialise an Evaluator for doing the comparison.
1330  template<typename T1, typename T2, Operator Op>
1331  class Evaluator{};
1332 
1333  template<typename T1, typename T2>
1334  struct Evaluator<T1, T2, IsEqualTo> {
1335  static bool evaluate( T1 const& lhs, T2 const& rhs) {
1336  return bool( opCast( lhs ) == opCast( rhs ) );
1337  }
1338  };
1339  template<typename T1, typename T2>
1340  struct Evaluator<T1, T2, IsNotEqualTo> {
1341  static bool evaluate( T1 const& lhs, T2 const& rhs ) {
1342  return bool( opCast( lhs ) != opCast( rhs ) );
1343  }
1344  };
1345  template<typename T1, typename T2>
1346  struct Evaluator<T1, T2, IsLessThan> {
1347  static bool evaluate( T1 const& lhs, T2 const& rhs ) {
1348  return bool( opCast( lhs ) < opCast( rhs ) );
1349  }
1350  };
1351  template<typename T1, typename T2>
1352  struct Evaluator<T1, T2, IsGreaterThan> {
1353  static bool evaluate( T1 const& lhs, T2 const& rhs ) {
1354  return bool( opCast( lhs ) > opCast( rhs ) );
1355  }
1356  };
1357  template<typename T1, typename T2>
1358  struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> {
1359  static bool evaluate( T1 const& lhs, T2 const& rhs ) {
1360  return bool( opCast( lhs ) >= opCast( rhs ) );
1361  }
1362  };
1363  template<typename T1, typename T2>
1364  struct Evaluator<T1, T2, IsLessThanOrEqualTo> {
1365  static bool evaluate( T1 const& lhs, T2 const& rhs ) {
1366  return bool( opCast( lhs ) <= opCast( rhs ) );
1367  }
1368  };
1369 
1370  template<Operator Op, typename T1, typename T2>
1371  bool applyEvaluator( T1 const& lhs, T2 const& rhs ) {
1372  return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
1373  }
1374 
1375  // This level of indirection allows us to specialise for integer types
1376  // to avoid signed/ unsigned warnings
1377 
1378  // "base" overload
1379  template<Operator Op, typename T1, typename T2>
1380  bool compare( T1 const& lhs, T2 const& rhs ) {
1381  return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
1382  }
1383 
1384  // unsigned X to int
1385  template<Operator Op> bool compare( unsigned int lhs, int rhs ) {
1386  return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
1387  }
1388  template<Operator Op> bool compare( unsigned long lhs, int rhs ) {
1389  return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
1390  }
1391  template<Operator Op> bool compare( unsigned char lhs, int rhs ) {
1392  return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
1393  }
1394 
1395  // unsigned X to long
1396  template<Operator Op> bool compare( unsigned int lhs, long rhs ) {
1397  return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
1398  }
1399  template<Operator Op> bool compare( unsigned long lhs, long rhs ) {
1400  return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
1401  }
1402  template<Operator Op> bool compare( unsigned char lhs, long rhs ) {
1403  return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
1404  }
1405 
1406  // int to unsigned X
1407  template<Operator Op> bool compare( int lhs, unsigned int rhs ) {
1408  return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
1409  }
1410  template<Operator Op> bool compare( int lhs, unsigned long rhs ) {
1411  return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
1412  }
1413  template<Operator Op> bool compare( int lhs, unsigned char rhs ) {
1414  return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
1415  }
1416 
1417  // long to unsigned X
1418  template<Operator Op> bool compare( long lhs, unsigned int rhs ) {
1419  return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
1420  }
1421  template<Operator Op> bool compare( long lhs, unsigned long rhs ) {
1422  return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
1423  }
1424  template<Operator Op> bool compare( long lhs, unsigned char rhs ) {
1425  return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
1426  }
1427 
1428  // pointer to long (when comparing against NULL)
1429  template<Operator Op, typename T> bool compare( long lhs, T* rhs ) {
1430  return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
1431  }
1432  template<Operator Op, typename T> bool compare( T* lhs, long rhs ) {
1433  return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
1434  }
1435 
1436  // pointer to int (when comparing against NULL)
1437  template<Operator Op, typename T> bool compare( int lhs, T* rhs ) {
1438  return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
1439  }
1440  template<Operator Op, typename T> bool compare( T* lhs, int rhs ) {
1441  return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
1442  }
1443 
1444 #ifdef CATCH_CONFIG_CPP11_LONG_LONG
1445  // long long to unsigned X
1446  template<Operator Op> bool compare( long long lhs, unsigned int rhs ) {
1447  return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
1448  }
1449  template<Operator Op> bool compare( long long lhs, unsigned long rhs ) {
1450  return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
1451  }
1452  template<Operator Op> bool compare( long long lhs, unsigned long long rhs ) {
1453  return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
1454  }
1455  template<Operator Op> bool compare( long long lhs, unsigned char rhs ) {
1456  return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
1457  }
1458 
1459  // unsigned long long to X
1460  template<Operator Op> bool compare( unsigned long long lhs, int rhs ) {
1461  return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
1462  }
1463  template<Operator Op> bool compare( unsigned long long lhs, long rhs ) {
1464  return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
1465  }
1466  template<Operator Op> bool compare( unsigned long long lhs, long long rhs ) {
1467  return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
1468  }
1469  template<Operator Op> bool compare( unsigned long long lhs, char rhs ) {
1470  return applyEvaluator<Op>( static_cast<long>( lhs ), rhs );
1471  }
1472 
1473  // pointer to long long (when comparing against NULL)
1474  template<Operator Op, typename T> bool compare( long long lhs, T* rhs ) {
1475  return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
1476  }
1477  template<Operator Op, typename T> bool compare( T* lhs, long long rhs ) {
1478  return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
1479  }
1480 #endif // CATCH_CONFIG_CPP11_LONG_LONG
1481 
1482 #ifdef CATCH_CONFIG_CPP11_NULLPTR
1483  // pointer to nullptr_t (when comparing against nullptr)
1484  template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) {
1485  return Evaluator<T*, T*, Op>::evaluate( nullptr, rhs );
1486  }
1487  template<Operator Op, typename T> bool compare( T* lhs, std::nullptr_t ) {
1488  return Evaluator<T*, T*, Op>::evaluate( lhs, nullptr );
1489  }
1490 #endif // CATCH_CONFIG_CPP11_NULLPTR
1491 
1492 } // end of namespace Internal
1493 } // end of namespace Catch
1494 
1495 #ifdef _MSC_VER
1496 #pragma warning(pop)
1497 #endif
1498 
1499 // #included from: catch_tostring.h
1500 #define TWOBLUECUBES_CATCH_TOSTRING_H_INCLUDED
1501 
1502 #include <sstream>
1503 #include <iomanip>
1504 #include <limits>
1505 #include <vector>
1506 #include <cstddef>
1507 
1508 #ifdef __OBJC__
1509 // #included from: catch_objc_arc.hpp
1510 #define TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED
1511 
1512 #import <Foundation/Foundation.h>
1513 
1514 #ifdef __has_feature
1515 #define CATCH_ARC_ENABLED __has_feature(objc_arc)
1516 #else
1517 #define CATCH_ARC_ENABLED 0
1518 #endif
1519 
1520 void arcSafeRelease( NSObject* obj );
1521 id performOptionalSelector( id obj, SEL sel );
1522 
1523 #if !CATCH_ARC_ENABLED
1524 inline void arcSafeRelease( NSObject* obj ) {
1525  [obj release];
1526 }
1527 inline id performOptionalSelector( id obj, SEL sel ) {
1528  if( [obj respondsToSelector: sel] )
1529  return [obj performSelector: sel];
1530  return nil;
1531 }
1532 #define CATCH_UNSAFE_UNRETAINED
1533 #define CATCH_ARC_STRONG
1534 #else
1535 inline void arcSafeRelease( NSObject* ){}
1536 inline id performOptionalSelector( id obj, SEL sel ) {
1537 #ifdef __clang__
1538 #pragma clang diagnostic push
1539 #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
1540 #endif
1541  if( [obj respondsToSelector: sel] )
1542  return [obj performSelector: sel];
1543 #ifdef __clang__
1544 #pragma clang diagnostic pop
1545 #endif
1546  return nil;
1547 }
1548 #define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
1549 #define CATCH_ARC_STRONG __strong
1550 #endif
1551 
1552 #endif
1553 
1554 #ifdef CATCH_CONFIG_CPP11_TUPLE
1555 #include <tuple>
1556 #endif
1557 
1558 #ifdef CATCH_CONFIG_CPP11_IS_ENUM
1559 #include <type_traits>
1560 #endif
1561 
1562 namespace Catch {
1563 
1564 // Why we're here.
1565 template<typename T>
1566 std::string toString( T const& value );
1567 
1568 // Built in overloads
1569 
1570 std::string toString( std::string const& value );
1571 std::string toString( std::wstring const& value );
1572 std::string toString( const char* const value );
1573 std::string toString( char* const value );
1574 std::string toString( const wchar_t* const value );
1575 std::string toString( wchar_t* const value );
1576 std::string toString( int value );
1577 std::string toString( unsigned long value );
1578 std::string toString( unsigned int value );
1579 std::string toString( const double value );
1580 std::string toString( const float value );
1581 std::string toString( bool value );
1582 std::string toString( char value );
1583 std::string toString( signed char value );
1584 std::string toString( unsigned char value );
1585 
1586 #ifdef CATCH_CONFIG_CPP11_LONG_LONG
1587 std::string toString( long long value );
1588 std::string toString( unsigned long long value );
1589 #endif
1590 
1591 #ifdef CATCH_CONFIG_CPP11_NULLPTR
1592 std::string toString( std::nullptr_t );
1593 #endif
1594 
1595 #ifdef __OBJC__
1596  std::string toString( NSString const * const& nsstring );
1597  std::string toString( NSString * CATCH_ARC_STRONG const& nsstring );
1598  std::string toString( NSObject* const& nsObject );
1599 #endif
1600 
1601 namespace Detail {
1602 
1603  extern const std::string unprintableString;
1604 
1605  struct BorgType {
1606  template<typename T> BorgType( T const& );
1607  };
1608 
1609  struct TrueType { char sizer[1]; };
1610  struct FalseType { char sizer[2]; };
1611 
1612  TrueType& testStreamable( std::ostream& );
1613  FalseType testStreamable( FalseType );
1614 
1615  FalseType operator<<( std::ostream const&, BorgType const& );
1616 
1617  template<typename T>
1619  static std::ostream &s;
1620  static T const&t;
1621  enum { value = sizeof( testStreamable(s << t) ) == sizeof( TrueType ) };
1622  };
1623 
1624 #if defined(CATCH_CONFIG_CPP11_IS_ENUM)
1625  template<typename T,
1626  bool IsEnum = std::is_enum<T>::value
1627  >
1628  struct EnumStringMaker
1629  {
1630  static std::string convert( T const& ) { return unprintableString; }
1631  };
1632 
1633  template<typename T>
1634  struct EnumStringMaker<T,true>
1635  {
1636  static std::string convert( T const& v )
1637  {
1638  return ::Catch::toString(
1639  static_cast<typename std::underlying_type<T>::type>(v)
1640  );
1641  }
1642  };
1643 #endif
1644  template<bool C>
1646 #if defined(CATCH_CONFIG_CPP11_IS_ENUM)
1647  template<typename T>
1648  static std::string convert( T const& v )
1649  {
1650  return EnumStringMaker<T>::convert( v );
1651  }
1652 #else
1653  template<typename T>
1654  static std::string convert( T const& ) { return unprintableString; }
1655 #endif
1656  };
1657 
1658  template<>
1659  struct StringMakerBase<true> {
1660  template<typename T>
1661  static std::string convert( T const& _value ) {
1662  std::ostringstream oss;
1663  oss << _value;
1664  return oss.str();
1665  }
1666  };
1667 
1668  std::string rawMemoryToString( const void *object, std::size_t size );
1669 
1670  template<typename T>
1671  inline std::string rawMemoryToString( const T& object ) {
1672  return rawMemoryToString( &object, sizeof(object) );
1673  }
1674 
1675 } // end namespace Detail
1676 
1677 template<typename T>
1678 struct StringMaker :
1679  Detail::StringMakerBase<Detail::IsStreamInsertable<T>::value> {};
1680 
1681 template<typename T>
1682 struct StringMaker<T*> {
1683  template<typename U>
1684  static std::string convert( U* p ) {
1685  if( !p )
1686  return "NULL";
1687  else
1688  return Detail::rawMemoryToString( p );
1689  }
1690 };
1691 
1692 template<typename R, typename C>
1693 struct StringMaker<R C::*> {
1694  static std::string convert( R C::* p ) {
1695  if( !p )
1696  return "NULL";
1697  else
1698  return Detail::rawMemoryToString( p );
1699  }
1700 };
1701 
1702 namespace Detail {
1703  template<typename InputIterator>
1704  std::string rangeToString( InputIterator first, InputIterator last );
1705 }
1706 
1707 //template<typename T, typename Allocator>
1708 //struct StringMaker<std::vector<T, Allocator> > {
1709 // static std::string convert( std::vector<T,Allocator> const& v ) {
1710 // return Detail::rangeToString( v.begin(), v.end() );
1711 // }
1712 //};
1713 
1714 template<typename T, typename Allocator>
1715 std::string toString( std::vector<T,Allocator> const& v ) {
1716  return Detail::rangeToString( v.begin(), v.end() );
1717 }
1718 
1719 #ifdef CATCH_CONFIG_CPP11_TUPLE
1720 
1721 // toString for tuples
1722 namespace TupleDetail {
1723  template<
1724  typename Tuple,
1725  std::size_t N = 0,
1726  bool = (N < std::tuple_size<Tuple>::value)
1727  >
1728  struct ElementPrinter {
1729  static void print( const Tuple& tuple, std::ostream& os )
1730  {
1731  os << ( N ? ", " : " " )
1732  << Catch::toString(std::get<N>(tuple));
1733  ElementPrinter<Tuple,N+1>::print(tuple,os);
1734  }
1735  };
1736 
1737  template<
1738  typename Tuple,
1739  std::size_t N
1740  >
1741  struct ElementPrinter<Tuple,N,false> {
1742  static void print( const Tuple&, std::ostream& ) {}
1743  };
1744 
1745 }
1746 
1747 template<typename ...Types>
1748 struct StringMaker<std::tuple<Types...>> {
1749 
1750  static std::string convert( const std::tuple<Types...>& tuple )
1751  {
1752  std::ostringstream os;
1753  os << '{';
1754  TupleDetail::ElementPrinter<std::tuple<Types...>>::print( tuple, os );
1755  os << " }";
1756  return os.str();
1757  }
1758 };
1759 #endif // CATCH_CONFIG_CPP11_TUPLE
1760 
1761 namespace Detail {
1762  template<typename T>
1763  std::string makeString( T const& value ) {
1764  return StringMaker<T>::convert( value );
1765  }
1766 } // end namespace Detail
1767 
1775 template<typename T>
1776 std::string toString( T const& value ) {
1777  return StringMaker<T>::convert( value );
1778 }
1779 
1780  namespace Detail {
1781  template<typename InputIterator>
1782  std::string rangeToString( InputIterator first, InputIterator last ) {
1783  std::ostringstream oss;
1784  oss << "{ ";
1785  if( first != last ) {
1786  oss << Catch::toString( *first );
1787  for( ++first ; first != last ; ++first )
1788  oss << ", " << Catch::toString( *first );
1789  }
1790  oss << " }";
1791  return oss.str();
1792  }
1793 }
1794 
1795 } // end namespace Catch
1796 
1797 namespace Catch {
1798 
1799 // Wraps the LHS of an expression and captures the operator and RHS (if any) -
1800 // wrapping them all in a ResultBuilder object
1801 template<typename T>
1802 class ExpressionLhs {
1803  ExpressionLhs& operator = ( ExpressionLhs const& );
1804 # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
1805  ExpressionLhs& operator = ( ExpressionLhs && ) = delete;
1806 # endif
1807 
1808 public:
1809  ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ) {}
1810 # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
1811  ExpressionLhs( ExpressionLhs const& ) = default;
1812  ExpressionLhs( ExpressionLhs && ) = default;
1813 # endif
1814 
1815  template<typename RhsT>
1816  ResultBuilder& operator == ( RhsT const& rhs ) {
1817  return captureExpression<Internal::IsEqualTo>( rhs );
1818  }
1819 
1820  template<typename RhsT>
1821  ResultBuilder& operator != ( RhsT const& rhs ) {
1822  return captureExpression<Internal::IsNotEqualTo>( rhs );
1823  }
1824 
1825  template<typename RhsT>
1826  ResultBuilder& operator < ( RhsT const& rhs ) {
1827  return captureExpression<Internal::IsLessThan>( rhs );
1828  }
1829 
1830  template<typename RhsT>
1831  ResultBuilder& operator > ( RhsT const& rhs ) {
1832  return captureExpression<Internal::IsGreaterThan>( rhs );
1833  }
1834 
1835  template<typename RhsT>
1836  ResultBuilder& operator <= ( RhsT const& rhs ) {
1837  return captureExpression<Internal::IsLessThanOrEqualTo>( rhs );
1838  }
1839 
1840  template<typename RhsT>
1841  ResultBuilder& operator >= ( RhsT const& rhs ) {
1842  return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs );
1843  }
1844 
1845  ResultBuilder& operator == ( bool rhs ) {
1846  return captureExpression<Internal::IsEqualTo>( rhs );
1847  }
1848 
1849  ResultBuilder& operator != ( bool rhs ) {
1850  return captureExpression<Internal::IsNotEqualTo>( rhs );
1851  }
1852 
1853  void endExpression() {
1854  bool value = m_lhs ? true : false;
1855  m_rb
1856  .setLhs( Catch::toString( value ) )
1857  .setResultType( value )
1858  .endExpression();
1859  }
1860 
1861  // Only simple binary expressions are allowed on the LHS.
1862  // If more complex compositions are required then place the sub expression in parentheses
1863  template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( RhsT const& );
1864  template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( RhsT const& );
1865  template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( RhsT const& );
1866  template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( RhsT const& );
1867  template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& );
1868  template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& );
1869 
1870 private:
1871  template<Internal::Operator Op, typename RhsT>
1872  ResultBuilder& captureExpression( RhsT const& rhs ) {
1873  return m_rb
1874  .setResultType( Internal::compare<Op>( m_lhs, rhs ) )
1875  .setLhs( Catch::toString( m_lhs ) )
1876  .setRhs( Catch::toString( rhs ) )
1878  }
1879 
1880 private:
1881  ResultBuilder& m_rb;
1882  T m_lhs;
1883 };
1884 
1885 } // end namespace Catch
1886 
1887 
1888 namespace Catch {
1889 
1890  template<typename T>
1891  inline ExpressionLhs<T const&> ResultBuilder::operator <= ( T const& operand ) {
1892  return ExpressionLhs<T const&>( *this, operand );
1893  }
1894 
1895  inline ExpressionLhs<bool> ResultBuilder::operator <= ( bool value ) {
1896  return ExpressionLhs<bool>( *this, value );
1897  }
1898 
1899 } // namespace Catch
1900 
1901 // #included from: catch_message.h
1902 #define TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED
1903 
1904 #include <string>
1905 
1906 namespace Catch {
1907 
1908  struct MessageInfo {
1909  MessageInfo( std::string const& _macroName,
1910  SourceLineInfo const& _lineInfo,
1911  ResultWas::OfType _type );
1912 
1913  std::string macroName;
1914  SourceLineInfo lineInfo;
1915  ResultWas::OfType type;
1916  std::string message;
1917  unsigned int sequence;
1918 
1919  bool operator == ( MessageInfo const& other ) const {
1920  return sequence == other.sequence;
1921  }
1922  bool operator < ( MessageInfo const& other ) const {
1923  return sequence < other.sequence;
1924  }
1925  private:
1926  static unsigned int globalCount;
1927  };
1928 
1930  MessageBuilder( std::string const& macroName,
1931  SourceLineInfo const& lineInfo,
1932  ResultWas::OfType type )
1933  : m_info( macroName, lineInfo, type )
1934  {}
1935 
1936  template<typename T>
1937  MessageBuilder& operator << ( T const& value ) {
1938  m_stream << value;
1939  return *this;
1940  }
1941 
1942  MessageInfo m_info;
1943  std::ostringstream m_stream;
1944  };
1945 
1947  public:
1948  ScopedMessage( MessageBuilder const& builder );
1949  ScopedMessage( ScopedMessage const& other );
1950  ~ScopedMessage();
1951 
1952  MessageInfo m_info;
1953  };
1954 
1955 } // end namespace Catch
1956 
1957 // #included from: catch_interfaces_capture.h
1958 #define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
1959 
1960 #include <string>
1961 
1962 namespace Catch {
1963 
1964  class TestCase;
1965  class AssertionResult;
1966  struct AssertionInfo;
1967  struct SectionInfo;
1968  struct SectionEndInfo;
1969  struct MessageInfo;
1970  class ScopedMessageBuilder;
1971  struct Counts;
1972 
1974 
1975  virtual ~IResultCapture();
1976 
1977  virtual void assertionEnded( AssertionResult const& result ) = 0;
1978  virtual bool sectionStarted( SectionInfo const& sectionInfo,
1979  Counts& assertions ) = 0;
1980  virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0;
1981  virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0;
1982  virtual void pushScopedMessage( MessageInfo const& message ) = 0;
1983  virtual void popScopedMessage( MessageInfo const& message ) = 0;
1984 
1985  virtual std::string getCurrentTestName() const = 0;
1986  virtual const AssertionResult* getLastResult() const = 0;
1987 
1988  virtual void handleFatalErrorCondition( std::string const& message ) = 0;
1989  };
1990 
1991  IResultCapture& getResultCapture();
1992 }
1993 
1994 // #included from: catch_debugger.h
1995 #define TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED
1996 
1997 // #included from: catch_platform.h
1998 #define TWOBLUECUBES_CATCH_PLATFORM_H_INCLUDED
1999 
2000 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
2001 #define CATCH_PLATFORM_MAC
2002 #elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
2003 #define CATCH_PLATFORM_IPHONE
2004 #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
2005 #define CATCH_PLATFORM_WINDOWS
2006 #endif
2007 
2008 #include <string>
2009 
2010 namespace Catch{
2011 
2012  bool isDebuggerActive();
2013  void writeToDebugConsole( std::string const& text );
2014 }
2015 
2016 #ifdef CATCH_PLATFORM_MAC
2017 
2018  // The following code snippet based on:
2019  // http://cocoawithlove.com/2008/03/break-into-debugger.html
2020  #ifdef DEBUG
2021  #if defined(__ppc64__) || defined(__ppc__)
2022  #define CATCH_BREAK_INTO_DEBUGGER() \
2023  if( Catch::isDebuggerActive() ) { \
2024  __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \
2025  : : : "memory","r0","r3","r4" ); \
2026  }
2027  #else
2028  #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) {__asm__("int $3\n" : : );}
2029  #endif
2030  #endif
2031 
2032 #elif defined(_MSC_VER)
2033  #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { __debugbreak(); }
2034 #elif defined(__MINGW32__)
2035  extern "C" __declspec(dllimport) void __stdcall DebugBreak();
2036  #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { DebugBreak(); }
2037 #endif
2038 
2039 #ifndef CATCH_BREAK_INTO_DEBUGGER
2040 #define CATCH_BREAK_INTO_DEBUGGER() Catch::alwaysTrue();
2041 #endif
2042 
2043 // #included from: catch_interfaces_runner.h
2044 #define TWOBLUECUBES_CATCH_INTERFACES_RUNNER_H_INCLUDED
2045 
2046 namespace Catch {
2047  class TestCase;
2048 
2049  struct IRunner {
2050  virtual ~IRunner();
2051  virtual bool aborting() const = 0;
2052  };
2053 }
2054 
2056 // In the event of a failure works out if the debugger needs to be invoked
2057 // and/or an exception thrown and takes appropriate action.
2058 // This needs to be done as a macro so the debugger will stop in the user
2059 // source code rather than in Catch library code
2060 #define INTERNAL_CATCH_REACT( resultBuilder ) \
2061  if( resultBuilder.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \
2062  resultBuilder.react();
2063 
2065 #define INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ) \
2066  do { \
2067  Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
2068  try { \
2069  CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
2070  ( __catchResult <= expr ).endExpression(); \
2071  } \
2072  catch( ... ) { \
2073  __catchResult.useActiveException( Catch::ResultDisposition::Normal ); \
2074  } \
2075  INTERNAL_CATCH_REACT( __catchResult ) \
2076  } while( Catch::isTrue( false && !!(expr) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look
2077 
2079 #define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \
2080  INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
2081  if( Catch::getResultCapture().getLastResult()->succeeded() )
2082 
2084 #define INTERNAL_CATCH_ELSE( expr, resultDisposition, macroName ) \
2085  INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
2086  if( !Catch::getResultCapture().getLastResult()->succeeded() )
2087 
2089 #define INTERNAL_CATCH_NO_THROW( expr, resultDisposition, macroName ) \
2090  do { \
2091  Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
2092  try { \
2093  expr; \
2094  __catchResult.captureResult( Catch::ResultWas::Ok ); \
2095  } \
2096  catch( ... ) { \
2097  __catchResult.useActiveException( resultDisposition ); \
2098  } \
2099  INTERNAL_CATCH_REACT( __catchResult ) \
2100  } while( Catch::alwaysFalse() )
2101 
2103 #define INTERNAL_CATCH_THROWS( expr, resultDisposition, matcher, macroName ) \
2104  do { \
2105  Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition, #matcher ); \
2106  if( __catchResult.allowThrows() ) \
2107  try { \
2108  expr; \
2109  __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
2110  } \
2111  catch( ... ) { \
2112  __catchResult.captureExpectedException( matcher ); \
2113  } \
2114  else \
2115  __catchResult.captureResult( Catch::ResultWas::Ok ); \
2116  INTERNAL_CATCH_REACT( __catchResult ) \
2117  } while( Catch::alwaysFalse() )
2118 
2120 #define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, resultDisposition, macroName ) \
2121  do { \
2122  Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
2123  if( __catchResult.allowThrows() ) \
2124  try { \
2125  expr; \
2126  __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
2127  } \
2128  catch( exceptionType ) { \
2129  __catchResult.captureResult( Catch::ResultWas::Ok ); \
2130  } \
2131  catch( ... ) { \
2132  __catchResult.useActiveException( resultDisposition ); \
2133  } \
2134  else \
2135  __catchResult.captureResult( Catch::ResultWas::Ok ); \
2136  INTERNAL_CATCH_REACT( __catchResult ) \
2137  } while( Catch::alwaysFalse() )
2138 
2140 #ifdef CATCH_CONFIG_VARIADIC_MACROS
2141  #define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, ... ) \
2142  do { \
2143  Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
2144  __catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \
2145  __catchResult.captureResult( messageType ); \
2146  INTERNAL_CATCH_REACT( __catchResult ) \
2147  } while( Catch::alwaysFalse() )
2148 #else
2149  #define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, log ) \
2150  do { \
2151  Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
2152  __catchResult << log + ::Catch::StreamEndStop(); \
2153  __catchResult.captureResult( messageType ); \
2154  INTERNAL_CATCH_REACT( __catchResult ) \
2155  } while( Catch::alwaysFalse() )
2156 #endif
2157 
2159 #define INTERNAL_CATCH_INFO( log, macroName ) \
2160  Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log;
2161 
2163 #define INTERNAL_CHECK_THAT( arg, matcher, resultDisposition, macroName ) \
2164  do { \
2165  Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #arg ", " #matcher, resultDisposition ); \
2166  try { \
2167  std::string matcherAsString = (matcher).toString(); \
2168  __catchResult \
2169  .setLhs( Catch::toString( arg ) ) \
2170  .setRhs( matcherAsString == Catch::Detail::unprintableString ? #matcher : matcherAsString ) \
2171  .setOp( "matches" ) \
2172  .setResultType( (matcher).match( arg ) ); \
2173  __catchResult.captureExpression(); \
2174  } catch( ... ) { \
2175  __catchResult.useActiveException( resultDisposition | Catch::ResultDisposition::ContinueOnFailure ); \
2176  } \
2177  INTERNAL_CATCH_REACT( __catchResult ) \
2178  } while( Catch::alwaysFalse() )
2179 
2180 // #included from: internal/catch_section.h
2181 #define TWOBLUECUBES_CATCH_SECTION_H_INCLUDED
2182 
2183 // #included from: catch_section_info.h
2184 #define TWOBLUECUBES_CATCH_SECTION_INFO_H_INCLUDED
2185 
2186 // #included from: catch_totals.hpp
2187 #define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED
2188 
2189 #include <cstddef>
2190 
2191 namespace Catch {
2192 
2193  struct Counts {
2194  Counts() : passed( 0 ), failed( 0 ), failedButOk( 0 ) {}
2195 
2196  Counts operator - ( Counts const& other ) const {
2197  Counts diff;
2198  diff.passed = passed - other.passed;
2199  diff.failed = failed - other.failed;
2200  diff.failedButOk = failedButOk - other.failedButOk;
2201  return diff;
2202  }
2203  Counts& operator += ( Counts const& other ) {
2204  passed += other.passed;
2205  failed += other.failed;
2206  failedButOk += other.failedButOk;
2207  return *this;
2208  }
2209 
2210  std::size_t total() const {
2211  return passed + failed + failedButOk;
2212  }
2213  bool allPassed() const {
2214  return failed == 0 && failedButOk == 0;
2215  }
2216  bool allOk() const {
2217  return failed == 0;
2218  }
2219 
2220  std::size_t passed;
2221  std::size_t failed;
2222  std::size_t failedButOk;
2223  };
2224 
2225  struct Totals {
2226 
2227  Totals operator - ( Totals const& other ) const {
2228  Totals diff;
2229  diff.assertions = assertions - other.assertions;
2230  diff.testCases = testCases - other.testCases;
2231  return diff;
2232  }
2233 
2234  Totals delta( Totals const& prevTotals ) const {
2235  Totals diff = *this - prevTotals;
2236  if( diff.assertions.failed > 0 )
2237  ++diff.testCases.failed;
2238  else if( diff.assertions.failedButOk > 0 )
2239  ++diff.testCases.failedButOk;
2240  else
2241  ++diff.testCases.passed;
2242  return diff;
2243  }
2244 
2245  Totals& operator += ( Totals const& other ) {
2246  assertions += other.assertions;
2247  testCases += other.testCases;
2248  return *this;
2249  }
2250 
2251  Counts assertions;
2252  Counts testCases;
2253  };
2254 }
2255 
2256 namespace Catch {
2257 
2258  struct SectionInfo {
2259  SectionInfo
2260  ( SourceLineInfo const& _lineInfo,
2261  std::string const& _name,
2262  std::string const& _description = std::string() );
2263 
2264  std::string name;
2265  std::string description;
2266  SourceLineInfo lineInfo;
2267  };
2268 
2270  SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds )
2271  : sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds )
2272  {}
2273 
2274  SectionInfo sectionInfo;
2275  Counts prevAssertions;
2276  double durationInSeconds;
2277  };
2278 
2279 } // end namespace Catch
2280 
2281 // #included from: catch_timer.h
2282 #define TWOBLUECUBES_CATCH_TIMER_H_INCLUDED
2283 
2284 #ifdef CATCH_PLATFORM_WINDOWS
2285 typedef unsigned long long uint64_t;
2286 #else
2287 #include <stdint.h>
2288 #endif
2289 
2290 namespace Catch {
2291 
2292  class Timer {
2293  public:
2294  Timer() : m_ticks( 0 ) {}
2295  void start();
2296  unsigned int getElapsedMicroseconds() const;
2297  unsigned int getElapsedMilliseconds() const;
2298  double getElapsedSeconds() const;
2299 
2300  private:
2301  uint64_t m_ticks;
2302  };
2303 
2304 } // namespace Catch
2305 
2306 #include <string>
2307 
2308 namespace Catch {
2309 
2311  public:
2312  Section( SectionInfo const& info );
2313  ~Section();
2314 
2315  // This indicates whether the section should be executed or not
2316  operator bool() const;
2317 
2318  private:
2319  SectionInfo m_info;
2320 
2321  std::string m_name;
2322  Counts m_assertions;
2323  bool m_sectionIncluded;
2324  Timer m_timer;
2325  };
2326 
2327 } // end namespace Catch
2328 
2329 #ifdef CATCH_CONFIG_VARIADIC_MACROS
2330  #define INTERNAL_CATCH_SECTION( ... ) \
2331  if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) )
2332 #else
2333  #define INTERNAL_CATCH_SECTION( name, desc ) \
2334  if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, name, desc ) )
2335 #endif
2336 
2337 // #included from: internal/catch_generators.hpp
2338 #define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
2339 
2340 #include <iterator>
2341 #include <vector>
2342 #include <string>
2343 #include <stdlib.h>
2344 
2345 namespace Catch {
2346 
2347 template<typename T>
2348 struct IGenerator {
2349  virtual ~IGenerator() {}
2350  virtual T getValue( std::size_t index ) const = 0;
2351  virtual std::size_t size () const = 0;
2352 };
2353 
2354 template<typename T>
2355 class BetweenGenerator : public IGenerator<T> {
2356 public:
2357  BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){}
2358 
2359  virtual T getValue( std::size_t index ) const {
2360  return m_from+static_cast<int>( index );
2361  }
2362 
2363  virtual std::size_t size() const {
2364  return static_cast<std::size_t>( 1+m_to-m_from );
2365  }
2366 
2367 private:
2368 
2369  T m_from;
2370  T m_to;
2371 };
2372 
2373 template<typename T>
2374 class ValuesGenerator : public IGenerator<T> {
2375 public:
2376  ValuesGenerator(){}
2377 
2378  void add( T value ) {
2379  m_values.push_back( value );
2380  }
2381 
2382  virtual T getValue( std::size_t index ) const {
2383  return m_values[index];
2384  }
2385 
2386  virtual std::size_t size() const {
2387  return m_values.size();
2388  }
2389 
2390 private:
2391  std::vector<T> m_values;
2392 };
2393 
2394 template<typename T>
2396 public:
2397  CompositeGenerator() : m_totalSize( 0 ) {}
2398 
2399  // *** Move semantics, similar to auto_ptr ***
2401  : m_fileInfo( other.m_fileInfo ),
2402  m_totalSize( 0 )
2403  {
2404  move( other );
2405  }
2406 
2407  CompositeGenerator& setFileInfo( const char* fileInfo ) {
2408  m_fileInfo = fileInfo;
2409  return *this;
2410  }
2411 
2412  ~CompositeGenerator() {
2413  deleteAll( m_composed );
2414  }
2415 
2416  operator T () const {
2417  size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize );
2418 
2419  typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin();
2420  typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end();
2421  for( size_t index = 0; it != itEnd; ++it )
2422  {
2423  const IGenerator<T>* generator = *it;
2424  if( overallIndex >= index && overallIndex < index + generator->size() )
2425  {
2426  return generator->getValue( overallIndex-index );
2427  }
2428  index += generator->size();
2429  }
2430  CATCH_INTERNAL_ERROR( "Indexed past end of generated range" );
2431  return T(); // Suppress spurious "not all control paths return a value" warning in Visual Studio - if you know how to fix this please do so
2432  }
2433 
2434  void add( const IGenerator<T>* generator ) {
2435  m_totalSize += generator->size();
2436  m_composed.push_back( generator );
2437  }
2438 
2439  CompositeGenerator& then( CompositeGenerator& other ) {
2440  move( other );
2441  return *this;
2442  }
2443 
2444  CompositeGenerator& then( T value ) {
2445  ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
2446  valuesGen->add( value );
2447  add( valuesGen );
2448  return *this;
2449  }
2450 
2451 private:
2452 
2453  void move( CompositeGenerator& other ) {
2454  std::copy( other.m_composed.begin(), other.m_composed.end(), std::back_inserter( m_composed ) );
2455  m_totalSize += other.m_totalSize;
2456  other.m_composed.clear();
2457  }
2458 
2459  std::vector<const IGenerator<T>*> m_composed;
2460  std::string m_fileInfo;
2461  size_t m_totalSize;
2462 };
2463 
2464 namespace Generators
2465 {
2466  template<typename T>
2467  CompositeGenerator<T> between( T from, T to ) {
2468  CompositeGenerator<T> generators;
2469  generators.add( new BetweenGenerator<T>( from, to ) );
2470  return generators;
2471  }
2472 
2473  template<typename T>
2474  CompositeGenerator<T> values( T val1, T val2 ) {
2475  CompositeGenerator<T> generators;
2476  ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
2477  valuesGen->add( val1 );
2478  valuesGen->add( val2 );
2479  generators.add( valuesGen );
2480  return generators;
2481  }
2482 
2483  template<typename T>
2484  CompositeGenerator<T> values( T val1, T val2, T val3 ){
2485  CompositeGenerator<T> generators;
2486  ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
2487  valuesGen->add( val1 );
2488  valuesGen->add( val2 );
2489  valuesGen->add( val3 );
2490  generators.add( valuesGen );
2491  return generators;
2492  }
2493 
2494  template<typename T>
2495  CompositeGenerator<T> values( T val1, T val2, T val3, T val4 ) {
2496  CompositeGenerator<T> generators;
2497  ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
2498  valuesGen->add( val1 );
2499  valuesGen->add( val2 );
2500  valuesGen->add( val3 );
2501  valuesGen->add( val4 );
2502  generators.add( valuesGen );
2503  return generators;
2504  }
2505 
2506 } // end namespace Generators
2507 
2508 using namespace Generators;
2509 
2510 } // end namespace Catch
2511 
2512 #define INTERNAL_CATCH_LINESTR2( line ) #line
2513 #define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line )
2514 
2515 #define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" )
2516 
2517 // #included from: internal/catch_interfaces_exception.h
2518 #define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
2519 
2520 #include <string>
2521 #include <vector>
2522 
2523 // #included from: catch_interfaces_registry_hub.h
2524 #define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
2525 
2526 #include <string>
2527 
2528 namespace Catch {
2529 
2530  class TestCase;
2531  struct ITestCaseRegistry;
2533  struct IExceptionTranslator;
2534  struct IReporterRegistry;
2535  struct IReporterFactory;
2536 
2537  struct IRegistryHub {
2538  virtual ~IRegistryHub();
2539 
2540  virtual IReporterRegistry const& getReporterRegistry() const = 0;
2541  virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0;
2542  virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0;
2543  };
2544 
2546  virtual ~IMutableRegistryHub();
2547  virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) = 0;
2548  virtual void registerListener( Ptr<IReporterFactory> const& factory ) = 0;
2549  virtual void registerTest( TestCase const& testInfo ) = 0;
2550  virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
2551  };
2552 
2553  IRegistryHub& getRegistryHub();
2554  IMutableRegistryHub& getMutableRegistryHub();
2555  void cleanUp();
2556  std::string translateActiveException();
2557 
2558 }
2559 
2560 namespace Catch {
2561 
2562  typedef std::string(*exceptionTranslateFunction)();
2563 
2564  struct IExceptionTranslator;
2565  typedef std::vector<const IExceptionTranslator*> ExceptionTranslators;
2566 
2568  virtual ~IExceptionTranslator();
2569  virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
2570  };
2571 
2573  virtual ~IExceptionTranslatorRegistry();
2574 
2575  virtual std::string translateActiveException() const = 0;
2576  };
2577 
2579  template<typename T>
2580  class ExceptionTranslator : public IExceptionTranslator {
2581  public:
2582 
2583  ExceptionTranslator( std::string(*translateFunction)( T& ) )
2584  : m_translateFunction( translateFunction )
2585  {}
2586 
2587  virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const CATCH_OVERRIDE {
2588  try {
2589  if( it == itEnd )
2590  throw;
2591  else
2592  return (*it)->translate( it+1, itEnd );
2593  }
2594  catch( T& ex ) {
2595  return m_translateFunction( ex );
2596  }
2597  }
2598 
2599  protected:
2600  std::string(*m_translateFunction)( T& );
2601  };
2602 
2603  public:
2604  template<typename T>
2605  ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) {
2606  getMutableRegistryHub().registerTranslator
2607  ( new ExceptionTranslator<T>( translateFunction ) );
2608  }
2609  };
2610 }
2611 
2613 #define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
2614  static std::string translatorName( signature ); \
2615  namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); }\
2616  static std::string translatorName( signature )
2617 
2618 #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
2619 
2620 // #included from: internal/catch_approx.hpp
2621 #define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
2622 
2623 #include <cmath>
2624 #include <limits>
2625 
2626 namespace Catch {
2627 namespace Detail {
2628 
2629  class Approx {
2630  public:
2631  explicit Approx ( double value )
2632  : m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
2633  m_scale( 1.0 ),
2634  m_value( value )
2635  {}
2636 
2637  Approx( Approx const& other )
2638  : m_epsilon( other.m_epsilon ),
2639  m_scale( other.m_scale ),
2640  m_value( other.m_value )
2641  {}
2642 
2643  static Approx custom() {
2644  return Approx( 0 );
2645  }
2646 
2647  Approx operator()( double value ) {
2648  Approx approx( value );
2649  approx.epsilon( m_epsilon );
2650  approx.scale( m_scale );
2651  return approx;
2652  }
2653 
2654  friend bool operator == ( double lhs, Approx const& rhs ) {
2655  // Thanks to Richard Harris for his help refining this formula
2656  return fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_value) ) );
2657  }
2658 
2659  friend bool operator == ( Approx const& lhs, double rhs ) {
2660  return operator==( rhs, lhs );
2661  }
2662 
2663  friend bool operator != ( double lhs, Approx const& rhs ) {
2664  return !operator==( lhs, rhs );
2665  }
2666 
2667  friend bool operator != ( Approx const& lhs, double rhs ) {
2668  return !operator==( rhs, lhs );
2669  }
2670 
2671  Approx& epsilon( double newEpsilon ) {
2672  m_epsilon = newEpsilon;
2673  return *this;
2674  }
2675 
2676  Approx& scale( double newScale ) {
2677  m_scale = newScale;
2678  return *this;
2679  }
2680 
2681  std::string toString() const {
2682  std::ostringstream oss;
2683  oss << "Approx( " << Catch::toString( m_value ) << " )";
2684  return oss.str();
2685  }
2686 
2687  private:
2688  double m_epsilon;
2689  double m_scale;
2690  double m_value;
2691  };
2692 }
2693 
2694 template<>
2695 inline std::string toString<Detail::Approx>( Detail::Approx const& value ) {
2696  return value.toString();
2697 }
2698 
2699 } // end namespace Catch
2700 
2701 // #included from: internal/catch_interfaces_tag_alias_registry.h
2702 #define TWOBLUECUBES_CATCH_INTERFACES_TAG_ALIAS_REGISTRY_H_INCLUDED
2703 
2704 // #included from: catch_tag_alias.h
2705 #define TWOBLUECUBES_CATCH_TAG_ALIAS_H_INCLUDED
2706 
2707 #include <string>
2708 
2709 namespace Catch {
2710 
2711  struct TagAlias {
2712  TagAlias( std::string _tag, SourceLineInfo _lineInfo ) : tag( _tag ), lineInfo( _lineInfo ) {}
2713 
2714  std::string tag;
2715  SourceLineInfo lineInfo;
2716  };
2717 
2719  RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo );
2720  };
2721 
2722 } // end namespace Catch
2723 
2724 #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); }
2725 // #included from: catch_option.hpp
2726 #define TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED
2727 
2728 namespace Catch {
2729 
2730  // An optional type
2731  template<typename T>
2732  class Option {
2733  public:
2734  Option() : nullableValue( CATCH_NULL ) {}
2735  Option( T const& _value )
2736  : nullableValue( new( storage ) T( _value ) )
2737  {}
2738  Option( Option const& _other )
2739  : nullableValue( _other ? new( storage ) T( *_other ) : CATCH_NULL )
2740  {}
2741 
2742  ~Option() {
2743  reset();
2744  }
2745 
2746  Option& operator= ( Option const& _other ) {
2747  if( &_other != this ) {
2748  reset();
2749  if( _other )
2750  nullableValue = new( storage ) T( *_other );
2751  }
2752  return *this;
2753  }
2754  Option& operator = ( T const& _value ) {
2755  reset();
2756  nullableValue = new( storage ) T( _value );
2757  return *this;
2758  }
2759 
2760  void reset() {
2761  if( nullableValue )
2762  nullableValue->~T();
2763  nullableValue = CATCH_NULL;
2764  }
2765 
2766  T& operator*() { return *nullableValue; }
2767  T const& operator*() const { return *nullableValue; }
2768  T* operator->() { return nullableValue; }
2769  const T* operator->() const { return nullableValue; }
2770 
2771  T valueOr( T const& defaultValue ) const {
2772  return nullableValue ? *nullableValue : defaultValue;
2773  }
2774 
2775  bool some() const { return nullableValue != CATCH_NULL; }
2776  bool none() const { return nullableValue == CATCH_NULL; }
2777 
2778  bool operator !() const { return nullableValue == CATCH_NULL; }
2779  operator SafeBool::type() const {
2780  return SafeBool::makeSafe( some() );
2781  }
2782 
2783  private:
2784  T* nullableValue;
2785  char storage[sizeof(T)];
2786  };
2787 
2788 } // end namespace Catch
2789 
2790 namespace Catch {
2791 
2793  virtual ~ITagAliasRegistry();
2794  virtual Option<TagAlias> find( std::string const& alias ) const = 0;
2795  virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0;
2796 
2797  static ITagAliasRegistry const& get();
2798  };
2799 
2800 } // end namespace Catch
2801 
2802 // These files are included here so the single_include script doesn't put them
2803 // in the conditionally compiled sections
2804 // #included from: internal/catch_test_case_info.h
2805 #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
2806 
2807 #include <string>
2808 #include <set>
2809 
2810 #ifdef __clang__
2811 #pragma clang diagnostic push
2812 #pragma clang diagnostic ignored "-Wpadded"
2813 #endif
2814 
2815 namespace Catch {
2816 
2817  struct ITestCase;
2818 
2819  struct TestCaseInfo {
2820  enum SpecialProperties{
2821  None = 0,
2822  IsHidden = 1 << 1,
2823  ShouldFail = 1 << 2,
2824  MayFail = 1 << 3,
2825  Throws = 1 << 4
2826  };
2827 
2828  TestCaseInfo( std::string const& _name,
2829  std::string const& _className,
2830  std::string const& _description,
2831  std::set<std::string> const& _tags,
2832  SourceLineInfo const& _lineInfo );
2833 
2834  TestCaseInfo( TestCaseInfo const& other );
2835 
2836  friend void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags );
2837 
2838  bool isHidden() const;
2839  bool throws() const;
2840  bool okToFail() const;
2841  bool expectedToFail() const;
2842 
2843  std::string name;
2844  std::string className;
2845  std::string description;
2846  std::set<std::string> tags;
2847  std::set<std::string> lcaseTags;
2848  std::string tagsAsString;
2849  SourceLineInfo lineInfo;
2850  SpecialProperties properties;
2851  };
2852 
2853  class TestCase : public TestCaseInfo {
2854  public:
2855 
2856  TestCase( ITestCase* testCase, TestCaseInfo const& info );
2857  TestCase( TestCase const& other );
2858 
2859  TestCase withName( std::string const& _newName ) const;
2860 
2861  void invoke() const;
2862 
2863  TestCaseInfo const& getTestCaseInfo() const;
2864 
2865  void swap( TestCase& other );
2866  bool operator == ( TestCase const& other ) const;
2867  bool operator < ( TestCase const& other ) const;
2868  TestCase& operator = ( TestCase const& other );
2869 
2870  private:
2871  Ptr<ITestCase> test;
2872  };
2873 
2874  TestCase makeTestCase( ITestCase* testCase,
2875  std::string const& className,
2876  std::string const& name,
2877  std::string const& description,
2878  SourceLineInfo const& lineInfo );
2879 }
2880 
2881 #ifdef __clang__
2882 #pragma clang diagnostic pop
2883 #endif
2884 
2885 
2886 #ifdef __OBJC__
2887 // #included from: internal/catch_objc.hpp
2888 #define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED
2889 
2890 #import <objc/runtime.h>
2891 
2892 #include <string>
2893 
2894 // NB. Any general catch headers included here must be included
2895 // in catch.hpp first to make sure they are included by the single
2896 // header for non obj-usage
2897 
2899 // This protocol is really only here for (self) documenting purposes, since
2900 // all its methods are optional.
2901 @protocol OcFixture
2902 
2903 @optional
2904 
2905 -(void) setUp;
2906 -(void) tearDown;
2907 
2908 @end
2909 
2910 namespace Catch {
2911 
2912  class OcMethod : public SharedImpl<ITestCase> {
2913 
2914  public:
2915  OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {}
2916 
2917  virtual void invoke() const {
2918  id obj = [[m_cls alloc] init];
2919 
2920  performOptionalSelector( obj, @selector(setUp) );
2921  performOptionalSelector( obj, m_sel );
2922  performOptionalSelector( obj, @selector(tearDown) );
2923 
2924  arcSafeRelease( obj );
2925  }
2926  private:
2927  virtual ~OcMethod() {}
2928 
2929  Class m_cls;
2930  SEL m_sel;
2931  };
2932 
2933  namespace Detail{
2934 
2935  inline std::string getAnnotation( Class cls,
2936  std::string const& annotationName,
2937  std::string const& testCaseName ) {
2938  NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()];
2939  SEL sel = NSSelectorFromString( selStr );
2940  arcSafeRelease( selStr );
2941  id value = performOptionalSelector( cls, sel );
2942  if( value )
2943  return [(NSString*)value UTF8String];
2944  return "";
2945  }
2946  }
2947 
2948  inline size_t registerTestMethods() {
2949  size_t noTestMethods = 0;
2950  int noClasses = objc_getClassList( CATCH_NULL, 0 );
2951 
2952  Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses);
2953  objc_getClassList( classes, noClasses );
2954 
2955  for( int c = 0; c < noClasses; c++ ) {
2956  Class cls = classes[c];
2957  {
2958  u_int count;
2959  Method* methods = class_copyMethodList( cls, &count );
2960  for( u_int m = 0; m < count ; m++ ) {
2961  SEL selector = method_getName(methods[m]);
2962  std::string methodName = sel_getName(selector);
2963  if( startsWith( methodName, "Catch_TestCase_" ) ) {
2964  std::string testCaseName = methodName.substr( 15 );
2965  std::string name = Detail::getAnnotation( cls, "Name", testCaseName );
2966  std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
2967  const char* className = class_getName( cls );
2968 
2969  getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo() ) );
2970  noTestMethods++;
2971  }
2972  }
2973  free(methods);
2974  }
2975  }
2976  return noTestMethods;
2977  }
2978 
2979  namespace Matchers {
2980  namespace Impl {
2981  namespace NSStringMatchers {
2982 
2983  template<typename MatcherT>
2984  struct StringHolder : MatcherImpl<MatcherT, NSString*>{
2985  StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
2986  StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){}
2987  StringHolder() {
2988  arcSafeRelease( m_substr );
2989  }
2990 
2991  NSString* m_substr;
2992  };
2993 
2994  struct Equals : StringHolder<Equals> {
2995  Equals( NSString* substr ) : StringHolder( substr ){}
2996 
2997  virtual bool match( ExpressionType const& str ) const {
2998  return (str != nil || m_substr == nil ) &&
2999  [str isEqualToString:m_substr];
3000  }
3001 
3002  virtual std::string toString() const {
3003  return "equals string: " + Catch::toString( m_substr );
3004  }
3005  };
3006 
3007  struct Contains : StringHolder<Contains> {
3008  Contains( NSString* substr ) : StringHolder( substr ){}
3009 
3010  virtual bool match( ExpressionType const& str ) const {
3011  return (str != nil || m_substr == nil ) &&
3012  [str rangeOfString:m_substr].location != NSNotFound;
3013  }
3014 
3015  virtual std::string toString() const {
3016  return "contains string: " + Catch::toString( m_substr );
3017  }
3018  };
3019 
3020  struct StartsWith : StringHolder<StartsWith> {
3021  StartsWith( NSString* substr ) : StringHolder( substr ){}
3022 
3023  virtual bool match( ExpressionType const& str ) const {
3024  return (str != nil || m_substr == nil ) &&
3025  [str rangeOfString:m_substr].location == 0;
3026  }
3027 
3028  virtual std::string toString() const {
3029  return "starts with: " + Catch::toString( m_substr );
3030  }
3031  };
3032  struct EndsWith : StringHolder<EndsWith> {
3033  EndsWith( NSString* substr ) : StringHolder( substr ){}
3034 
3035  virtual bool match( ExpressionType const& str ) const {
3036  return (str != nil || m_substr == nil ) &&
3037  [str rangeOfString:m_substr].location == [str length] - [m_substr length];
3038  }
3039 
3040  virtual std::string toString() const {
3041  return "ends with: " + Catch::toString( m_substr );
3042  }
3043  };
3044 
3045  } // namespace NSStringMatchers
3046  } // namespace Impl
3047 
3048  inline Impl::NSStringMatchers::Equals
3049  Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
3050 
3051  inline Impl::NSStringMatchers::Contains
3052  Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
3053 
3054  inline Impl::NSStringMatchers::StartsWith
3055  StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
3056 
3057  inline Impl::NSStringMatchers::EndsWith
3058  EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
3059 
3060  } // namespace Matchers
3061 
3062  using namespace Matchers;
3063 
3064 } // namespace Catch
3065 
3067 #define OC_TEST_CASE( name, desc )\
3068 +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \
3069 {\
3070 return @ name; \
3071 }\
3072 +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \
3073 { \
3074 return @ desc; \
3075 } \
3076 -(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test )
3077 
3078 #endif
3079 
3080 #ifdef CATCH_IMPL
3081 // #included from: internal/catch_impl.hpp
3082 #define TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED
3083 
3084 // Collect all the implementation files together here
3085 // These are the equivalent of what would usually be cpp files
3086 
3087 #ifdef __clang__
3088 #pragma clang diagnostic push
3089 #pragma clang diagnostic ignored "-Wweak-vtables"
3090 #endif
3091 
3092 // #included from: ../catch_session.hpp
3093 #define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED
3094 
3095 // #included from: internal/catch_commandline.hpp
3096 #define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
3097 
3098 // #included from: catch_config.hpp
3099 #define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
3100 
3101 // #included from: catch_test_spec_parser.hpp
3102 #define TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED
3103 
3104 #ifdef __clang__
3105 #pragma clang diagnostic push
3106 #pragma clang diagnostic ignored "-Wpadded"
3107 #endif
3108 
3109 // #included from: catch_test_spec.hpp
3110 #define TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED
3111 
3112 #ifdef __clang__
3113 #pragma clang diagnostic push
3114 #pragma clang diagnostic ignored "-Wpadded"
3115 #endif
3116 
3117 // #included from: catch_wildcard_pattern.hpp
3118 #define TWOBLUECUBES_CATCH_WILDCARD_PATTERN_HPP_INCLUDED
3119 
3120 namespace Catch
3121 {
3122  class WildcardPattern {
3123  enum WildcardPosition {
3124  NoWildcard = 0,
3125  WildcardAtStart = 1,
3126  WildcardAtEnd = 2,
3127  WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd
3128  };
3129 
3130  public:
3131 
3132  WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity )
3133  : m_caseSensitivity( caseSensitivity ),
3134  m_wildcard( NoWildcard ),
3135  m_pattern( adjustCase( pattern ) )
3136  {
3137  if( startsWith( m_pattern, "*" ) ) {
3138  m_pattern = m_pattern.substr( 1 );
3139  m_wildcard = WildcardAtStart;
3140  }
3141  if( endsWith( m_pattern, "*" ) ) {
3142  m_pattern = m_pattern.substr( 0, m_pattern.size()-1 );
3143  m_wildcard = static_cast<WildcardPosition>( m_wildcard | WildcardAtEnd );
3144  }
3145  }
3146  virtual ~WildcardPattern();
3147  virtual bool matches( std::string const& str ) const {
3148  switch( m_wildcard ) {
3149  case NoWildcard:
3150  return m_pattern == adjustCase( str );
3151  case WildcardAtStart:
3152  return endsWith( adjustCase( str ), m_pattern );
3153  case WildcardAtEnd:
3154  return startsWith( adjustCase( str ), m_pattern );
3155  case WildcardAtBothEnds:
3156  return contains( adjustCase( str ), m_pattern );
3157  }
3158 
3159 #ifdef __clang__
3160 #pragma clang diagnostic push
3161 #pragma clang diagnostic ignored "-Wunreachable-code"
3162 #endif
3163  throw std::logic_error( "Unknown enum" );
3164 #ifdef __clang__
3165 #pragma clang diagnostic pop
3166 #endif
3167  }
3168  private:
3169  std::string adjustCase( std::string const& str ) const {
3170  return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str;
3171  }
3172  CaseSensitive::Choice m_caseSensitivity;
3173  WildcardPosition m_wildcard;
3174  std::string m_pattern;
3175  };
3176 }
3177 
3178 #include <string>
3179 #include <vector>
3180 
3181 namespace Catch {
3182 
3183  class TestSpec {
3184  struct Pattern : SharedImpl<> {
3185  virtual ~Pattern();
3186  virtual bool matches( TestCaseInfo const& testCase ) const = 0;
3187  };
3188  class NamePattern : public Pattern {
3189  public:
3190  NamePattern( std::string const& name )
3191  : m_wildcardPattern( toLower( name ), CaseSensitive::No )
3192  {}
3193  virtual ~NamePattern();
3194  virtual bool matches( TestCaseInfo const& testCase ) const {
3195  return m_wildcardPattern.matches( toLower( testCase.name ) );
3196  }
3197  private:
3198  WildcardPattern m_wildcardPattern;
3199  };
3200 
3201  class TagPattern : public Pattern {
3202  public:
3203  TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {}
3204  virtual ~TagPattern();
3205  virtual bool matches( TestCaseInfo const& testCase ) const {
3206  return testCase.lcaseTags.find( m_tag ) != testCase.lcaseTags.end();
3207  }
3208  private:
3209  std::string m_tag;
3210  };
3211 
3212  class ExcludedPattern : public Pattern {
3213  public:
3214  ExcludedPattern( Ptr<Pattern> const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {}
3215  virtual ~ExcludedPattern();
3216  virtual bool matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); }
3217  private:
3218  Ptr<Pattern> m_underlyingPattern;
3219  };
3220 
3221  struct Filter {
3222  std::vector<Ptr<Pattern> > m_patterns;
3223 
3224  bool matches( TestCaseInfo const& testCase ) const {
3225  // All patterns in a filter must match for the filter to be a match
3226  for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) {
3227  if( !(*it)->matches( testCase ) )
3228  return false;
3229  }
3230  return true;
3231  }
3232  };
3233 
3234  public:
3235  bool hasFilters() const {
3236  return !m_filters.empty();
3237  }
3238  bool matches( TestCaseInfo const& testCase ) const {
3239  // A TestSpec matches if any filter matches
3240  for( std::vector<Filter>::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it )
3241  if( it->matches( testCase ) )
3242  return true;
3243  return false;
3244  }
3245 
3246  private:
3247  std::vector<Filter> m_filters;
3248 
3249  friend class TestSpecParser;
3250  };
3251 }
3252 
3253 #ifdef __clang__
3254 #pragma clang diagnostic pop
3255 #endif
3256 
3257 namespace Catch {
3258 
3259  class TestSpecParser {
3260  enum Mode{ None, Name, QuotedName, Tag };
3261  Mode m_mode;
3262  bool m_exclusion;
3263  std::size_t m_start, m_pos;
3264  std::string m_arg;
3265  TestSpec::Filter m_currentFilter;
3266  TestSpec m_testSpec;
3267  ITagAliasRegistry const* m_tagAliases;
3268 
3269  public:
3270  TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {}
3271 
3272  TestSpecParser& parse( std::string const& arg ) {
3273  m_mode = None;
3274  m_exclusion = false;
3275  m_start = std::string::npos;
3276  m_arg = m_tagAliases->expandAliases( arg );
3277  for( m_pos = 0; m_pos < m_arg.size(); ++m_pos )
3278  visitChar( m_arg[m_pos] );
3279  if( m_mode == Name )
3280  addPattern<TestSpec::NamePattern>();
3281  return *this;
3282  }
3283  TestSpec testSpec() {
3284  addFilter();
3285  return m_testSpec;
3286  }
3287  private:
3288  void visitChar( char c ) {
3289  if( m_mode == None ) {
3290  switch( c ) {
3291  case ' ': return;
3292  case '~': m_exclusion = true; return;
3293  case '[': return startNewMode( Tag, ++m_pos );
3294  case '"': return startNewMode( QuotedName, ++m_pos );
3295  default: startNewMode( Name, m_pos ); break;
3296  }
3297  }
3298  if( m_mode == Name ) {
3299  if( c == ',' ) {
3300  addPattern<TestSpec::NamePattern>();
3301  addFilter();
3302  }
3303  else if( c == '[' ) {
3304  if( subString() == "exclude:" )
3305  m_exclusion = true;
3306  else
3307  addPattern<TestSpec::NamePattern>();
3308  startNewMode( Tag, ++m_pos );
3309  }
3310  }
3311  else if( m_mode == QuotedName && c == '"' )
3312  addPattern<TestSpec::NamePattern>();
3313  else if( m_mode == Tag && c == ']' )
3314  addPattern<TestSpec::TagPattern>();
3315  }
3316  void startNewMode( Mode mode, std::size_t start ) {
3317  m_mode = mode;
3318  m_start = start;
3319  }
3320  std::string subString() const { return m_arg.substr( m_start, m_pos - m_start ); }
3321  template<typename T>
3322  void addPattern() {
3323  std::string token = subString();
3324  if( startsWith( token, "exclude:" ) ) {
3325  m_exclusion = true;
3326  token = token.substr( 8 );
3327  }
3328  if( !token.empty() ) {
3329  Ptr<TestSpec::Pattern> pattern = new T( token );
3330  if( m_exclusion )
3331  pattern = new TestSpec::ExcludedPattern( pattern );
3332  m_currentFilter.m_patterns.push_back( pattern );
3333  }
3334  m_exclusion = false;
3335  m_mode = None;
3336  }
3337  void addFilter() {
3338  if( !m_currentFilter.m_patterns.empty() ) {
3339  m_testSpec.m_filters.push_back( m_currentFilter );
3340  m_currentFilter = TestSpec::Filter();
3341  }
3342  }
3343  };
3344  inline TestSpec parseTestSpec( std::string const& arg ) {
3345  return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec();
3346  }
3347 
3348 } // namespace Catch
3349 
3350 #ifdef __clang__
3351 #pragma clang diagnostic pop
3352 #endif
3353 
3354 // #included from: catch_interfaces_config.h
3355 #define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
3356 
3357 #include <iostream>
3358 #include <string>
3359 #include <vector>
3360 
3361 namespace Catch {
3362 
3363  struct Verbosity { enum Level {
3364  NoOutput = 0,
3365  Quiet,
3366  Normal
3367  }; };
3368 
3369  struct WarnAbout { enum What {
3370  Nothing = 0x00,
3371  NoAssertions = 0x01
3372  }; };
3373 
3374  struct ShowDurations { enum OrNot {
3375  DefaultForReporter,
3376  Always,
3377  Never
3378  }; };
3379  struct RunTests { enum InWhatOrder {
3380  InDeclarationOrder,
3381  InLexicographicalOrder,
3382  InRandomOrder
3383  }; };
3384  struct UseColour { enum YesOrNo {
3385  Auto,
3386  Yes,
3387  No
3388  }; };
3389 
3390  class TestSpec;
3391 
3392  struct IConfig : IShared {
3393 
3394  virtual ~IConfig();
3395 
3396  virtual bool allowThrows() const = 0;
3397  virtual std::ostream& stream() const = 0;
3398  virtual std::string name() const = 0;
3399  virtual bool includeSuccessfulResults() const = 0;
3400  virtual bool shouldDebugBreak() const = 0;
3401  virtual bool warnAboutMissingAssertions() const = 0;
3402  virtual int abortAfter() const = 0;
3403  virtual bool showInvisibles() const = 0;
3404  virtual ShowDurations::OrNot showDurations() const = 0;
3405  virtual TestSpec const& testSpec() const = 0;
3406  virtual RunTests::InWhatOrder runOrder() const = 0;
3407  virtual unsigned int rngSeed() const = 0;
3408  virtual UseColour::YesOrNo useColour() const = 0;
3409  };
3410 }
3411 
3412 // #included from: catch_stream.h
3413 #define TWOBLUECUBES_CATCH_STREAM_H_INCLUDED
3414 
3415 // #included from: catch_streambuf.h
3416 #define TWOBLUECUBES_CATCH_STREAMBUF_H_INCLUDED
3417 
3418 #include <streambuf>
3419 
3420 namespace Catch {
3421 
3422  class StreamBufBase : public std::streambuf {
3423  public:
3424  virtual ~StreamBufBase() CATCH_NOEXCEPT;
3425  };
3426 }
3427 
3428 #include <streambuf>
3429 #include <ostream>
3430 #include <fstream>
3431 
3432 namespace Catch {
3433 
3434  std::ostream& cout();
3435  std::ostream& cerr();
3436 
3437  struct IStream {
3438  virtual ~IStream() CATCH_NOEXCEPT;
3439  virtual std::ostream& stream() const = 0;
3440  };
3441 
3442  class FileStream : public IStream {
3443  mutable std::ofstream m_ofs;
3444  public:
3445  FileStream( std::string const& filename );
3446  virtual ~FileStream() CATCH_NOEXCEPT;
3447  public: // IStream
3448  virtual std::ostream& stream() const CATCH_OVERRIDE;
3449  };
3450 
3451  class CoutStream : public IStream {
3452  mutable std::ostream m_os;
3453  public:
3454  CoutStream();
3455  virtual ~CoutStream() CATCH_NOEXCEPT;
3456 
3457  public: // IStream
3458  virtual std::ostream& stream() const CATCH_OVERRIDE;
3459  };
3460 
3461  class DebugOutStream : public IStream {
3462  CATCH_AUTO_PTR( StreamBufBase ) m_streamBuf;
3463  mutable std::ostream m_os;
3464  public:
3465  DebugOutStream();
3466  virtual ~DebugOutStream() CATCH_NOEXCEPT;
3467 
3468  public: // IStream
3469  virtual std::ostream& stream() const CATCH_OVERRIDE;
3470  };
3471 }
3472 
3473 #include <memory>
3474 #include <vector>
3475 #include <string>
3476 #include <iostream>
3477 #include <ctime>
3478 
3479 #ifndef CATCH_CONFIG_CONSOLE_WIDTH
3480 #define CATCH_CONFIG_CONSOLE_WIDTH 80
3481 #endif
3482 
3483 namespace Catch {
3484 
3485  struct ConfigData {
3486 
3487  ConfigData()
3488  : listTests( false ),
3489  listTags( false ),
3490  listReporters( false ),
3491  listTestNamesOnly( false ),
3492  showSuccessfulTests( false ),
3493  shouldDebugBreak( false ),
3494  noThrow( false ),
3495  showHelp( false ),
3496  showInvisibles( false ),
3497  filenamesAsTags( false ),
3498  abortAfter( -1 ),
3499  rngSeed( 0 ),
3500  verbosity( Verbosity::Normal ),
3501  warnings( WarnAbout::Nothing ),
3502  showDurations( ShowDurations::DefaultForReporter ),
3503  runOrder( RunTests::InDeclarationOrder ),
3504  useColour( UseColour::Auto )
3505  {}
3506 
3507  bool listTests;
3508  bool listTags;
3509  bool listReporters;
3510  bool listTestNamesOnly;
3511 
3512  bool showSuccessfulTests;
3513  bool shouldDebugBreak;
3514  bool noThrow;
3515  bool showHelp;
3516  bool showInvisibles;
3517  bool filenamesAsTags;
3518 
3519  int abortAfter;
3520  unsigned int rngSeed;
3521 
3522  Verbosity::Level verbosity;
3523  WarnAbout::What warnings;
3524  ShowDurations::OrNot showDurations;
3525  RunTests::InWhatOrder runOrder;
3526  UseColour::YesOrNo useColour;
3527 
3528  std::string outputFilename;
3529  std::string name;
3530  std::string processName;
3531 
3532  std::vector<std::string> reporterNames;
3533  std::vector<std::string> testsOrTags;
3534  };
3535 
3536  class Config : public SharedImpl<IConfig> {
3537  private:
3538  Config( Config const& other );
3539  Config& operator = ( Config const& other );
3540  virtual void dummy();
3541  public:
3542 
3543  Config()
3544  {}
3545 
3546  Config( ConfigData const& data )
3547  : m_data( data ),
3548  m_stream( openStream() )
3549  {
3550  if( !data.testsOrTags.empty() ) {
3551  TestSpecParser parser( ITagAliasRegistry::get() );
3552  for( std::size_t i = 0; i < data.testsOrTags.size(); ++i )
3553  parser.parse( data.testsOrTags[i] );
3554  m_testSpec = parser.testSpec();
3555  }
3556  }
3557 
3558  virtual ~Config() {
3559  }
3560 
3561  std::string const& getFilename() const {
3562  return m_data.outputFilename ;
3563  }
3564 
3565  bool listTests() const { return m_data.listTests; }
3566  bool listTestNamesOnly() const { return m_data.listTestNamesOnly; }
3567  bool listTags() const { return m_data.listTags; }
3568  bool listReporters() const { return m_data.listReporters; }
3569 
3570  std::string getProcessName() const { return m_data.processName; }
3571 
3572  bool shouldDebugBreak() const { return m_data.shouldDebugBreak; }
3573 
3574  std::vector<std::string> getReporterNames() const { return m_data.reporterNames; }
3575 
3576  int abortAfter() const { return m_data.abortAfter; }
3577 
3578  TestSpec const& testSpec() const { return m_testSpec; }
3579 
3580  bool showHelp() const { return m_data.showHelp; }
3581  bool showInvisibles() const { return m_data.showInvisibles; }
3582 
3583  // IConfig interface
3584  virtual bool allowThrows() const { return !m_data.noThrow; }
3585  virtual std::ostream& stream() const { return m_stream->stream(); }
3586  virtual std::string name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
3587  virtual bool includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
3588  virtual bool warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; }
3589  virtual ShowDurations::OrNot showDurations() const { return m_data.showDurations; }
3590  virtual RunTests::InWhatOrder runOrder() const { return m_data.runOrder; }
3591  virtual unsigned int rngSeed() const { return m_data.rngSeed; }
3592  virtual UseColour::YesOrNo useColour() const { return m_data.useColour; }
3593 
3594  private:
3595 
3596  IStream const* openStream() {
3597  if( m_data.outputFilename.empty() )
3598  return new CoutStream();
3599  else if( m_data.outputFilename[0] == '%' ) {
3600  if( m_data.outputFilename == "%debug" )
3601  return new DebugOutStream();
3602  else
3603  throw std::domain_error( "Unrecognised stream: " + m_data.outputFilename );
3604  }
3605  else
3606  return new FileStream( m_data.outputFilename );
3607  }
3608  ConfigData m_data;
3609 
3610  CATCH_AUTO_PTR( IStream const ) m_stream;
3611  TestSpec m_testSpec;
3612  };
3613 
3614 } // end namespace Catch
3615 
3616 // #included from: catch_clara.h
3617 #define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED
3618 
3619 // Use Catch's value for console width (store Clara's off to the side, if present)
3620 #ifdef CLARA_CONFIG_CONSOLE_WIDTH
3621 #define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH
3622 #undef CLARA_CONFIG_CONSOLE_WIDTH
3623 #endif
3624 #define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
3625 
3626 // Declare Clara inside the Catch namespace
3627 #define STITCH_CLARA_OPEN_NAMESPACE namespace Catch {
3628 // #included from: ../external/clara.h
3629 
3630 // Version 0.0.2.4
3631 
3632 // Only use header guard if we are not using an outer namespace
3633 #if !defined(TWOBLUECUBES_CLARA_H_INCLUDED) || defined(STITCH_CLARA_OPEN_NAMESPACE)
3634 
3635 #ifndef STITCH_CLARA_OPEN_NAMESPACE
3636 #define TWOBLUECUBES_CLARA_H_INCLUDED
3637 #define STITCH_CLARA_OPEN_NAMESPACE
3638 #define STITCH_CLARA_CLOSE_NAMESPACE
3639 #else
3640 #define STITCH_CLARA_CLOSE_NAMESPACE }
3641 #endif
3642 
3643 #define STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE STITCH_CLARA_OPEN_NAMESPACE
3644 
3645 // ----------- #included from tbc_text_format.h -----------
3646 
3647 // Only use header guard if we are not using an outer namespace
3648 #if !defined(TBC_TEXT_FORMAT_H_INCLUDED) || defined(STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE)
3649 #ifndef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
3650 #define TBC_TEXT_FORMAT_H_INCLUDED
3651 #endif
3652 
3653 #include <string>
3654 #include <vector>
3655 #include <sstream>
3656 #include <algorithm>
3657 
3658 // Use optional outer namespace
3659 #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
3660 namespace STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE {
3661 #endif
3662 
3663 namespace Tbc {
3664 
3665 #ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH
3666  const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH;
3667 #else
3668  const unsigned int consoleWidth = 80;
3669 #endif
3670 
3671  struct TextAttributes {
3672  TextAttributes()
3673  : initialIndent( std::string::npos ),
3674  indent( 0 ),
3675  width( consoleWidth-1 ),
3676  tabChar( '\t' )
3677  {}
3678 
3679  TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
3680  TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
3681  TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
3682  TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; }
3683 
3684  std::size_t initialIndent; // indent of first line, or npos
3685  std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
3686  std::size_t width; // maximum width of text, including indent. Longer text will wrap
3687  char tabChar; // If this char is seen the indent is changed to current pos
3688  };
3689 
3690  class Text {
3691  public:
3692  Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() )
3693  : attr( _attr )
3694  {
3695  std::string wrappableChars = " [({.,/|\\-";
3696  std::size_t indent = _attr.initialIndent != std::string::npos
3697  ? _attr.initialIndent
3698  : _attr.indent;
3699  std::string remainder = _str;
3700 
3701  while( !remainder.empty() ) {
3702  if( lines.size() >= 1000 ) {
3703  lines.push_back( "... message truncated due to excessive size" );
3704  return;
3705  }
3706  std::size_t tabPos = std::string::npos;
3707  std::size_t width = (std::min)( remainder.size(), _attr.width - indent );
3708  std::size_t pos = remainder.find_first_of( '\n' );
3709  if( pos <= width ) {
3710  width = pos;
3711  }
3712  pos = remainder.find_last_of( _attr.tabChar, width );
3713  if( pos != std::string::npos ) {
3714  tabPos = pos;
3715  if( remainder[width] == '\n' )
3716  width--;
3717  remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 );
3718  }
3719 
3720  if( width == remainder.size() ) {
3721  spliceLine( indent, remainder, width );
3722  }
3723  else if( remainder[width] == '\n' ) {
3724  spliceLine( indent, remainder, width );
3725  if( width <= 1 || remainder.size() != 1 )
3726  remainder = remainder.substr( 1 );
3727  indent = _attr.indent;
3728  }
3729  else {
3730  pos = remainder.find_last_of( wrappableChars, width );
3731  if( pos != std::string::npos && pos > 0 ) {
3732  spliceLine( indent, remainder, pos );
3733  if( remainder[0] == ' ' )
3734  remainder = remainder.substr( 1 );
3735  }
3736  else {
3737  spliceLine( indent, remainder, width-1 );
3738  lines.back() += "-";
3739  }
3740  if( lines.size() == 1 )
3741  indent = _attr.indent;
3742  if( tabPos != std::string::npos )
3743  indent += tabPos;
3744  }
3745  }
3746  }
3747 
3748  void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) {
3749  lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) );
3750  _remainder = _remainder.substr( _pos );
3751  }
3752 
3753  typedef std::vector<std::string>::const_iterator const_iterator;
3754 
3755  const_iterator begin() const { return lines.begin(); }
3756  const_iterator end() const { return lines.end(); }
3757  std::string const& last() const { return lines.back(); }
3758  std::size_t size() const { return lines.size(); }
3759  std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
3760  std::string toString() const {
3761  std::ostringstream oss;
3762  oss << *this;
3763  return oss.str();
3764  }
3765 
3766  inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) {
3767  for( Text::const_iterator it = _text.begin(), itEnd = _text.end();
3768  it != itEnd; ++it ) {
3769  if( it != _text.begin() )
3770  _stream << "\n";
3771  _stream << *it;
3772  }
3773  return _stream;
3774  }
3775 
3776  private:
3777  std::string str;
3778  TextAttributes attr;
3779  std::vector<std::string> lines;
3780  };
3781 
3782 } // end namespace Tbc
3783 
3784 #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
3785 } // end outer namespace
3786 #endif
3787 
3788 #endif // TBC_TEXT_FORMAT_H_INCLUDED
3789 
3790 // ----------- end of #include from tbc_text_format.h -----------
3791 // ........... back in clara.h
3792 
3793 #undef STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE
3794 
3795 // ----------- #included from clara_compilers.h -----------
3796 
3797 #ifndef TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
3798 #define TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
3799 
3800 // Detect a number of compiler features - mostly C++11/14 conformance - by compiler
3801 // The following features are defined:
3802 //
3803 // CLARA_CONFIG_CPP11_NULLPTR : is nullptr supported?
3804 // CLARA_CONFIG_CPP11_NOEXCEPT : is noexcept supported?
3805 // CLARA_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods
3806 // CLARA_CONFIG_CPP11_OVERRIDE : is override supported?
3807 // CLARA_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr)
3808 
3809 // CLARA_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
3810 
3811 // CLARA_CONFIG_VARIADIC_MACROS : are variadic macros supported?
3812 
3813 // In general each macro has a _NO_<feature name> form
3814 // (e.g. CLARA_CONFIG_CPP11_NO_NULLPTR) which disables the feature.
3815 // Many features, at point of detection, define an _INTERNAL_ macro, so they
3816 // can be combined, en-mass, with the _NO_ forms later.
3817 
3818 // All the C++11 features can be disabled with CLARA_CONFIG_NO_CPP11
3819 
3820 #ifdef __clang__
3821 
3822 #if __has_feature(cxx_nullptr)
3823 #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
3824 #endif
3825 
3826 #if __has_feature(cxx_noexcept)
3827 #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
3828 #endif
3829 
3830 #endif // __clang__
3831 
3833 // GCC
3834 #ifdef __GNUC__
3835 
3836 #if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
3837 #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
3838 #endif
3839 
3840 // - otherwise more recent versions define __cplusplus >= 201103L
3841 // and will get picked up below
3842 
3843 #endif // __GNUC__
3844 
3846 // Visual C++
3847 #ifdef _MSC_VER
3848 
3849 #if (_MSC_VER >= 1600)
3850 #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
3851 #define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
3852 #endif
3853 
3854 #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
3855 #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
3856 #define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
3857 #endif
3858 
3859 #endif // _MSC_VER
3860 
3862 // C++ language feature support
3863 
3864 // catch all support for C++11
3865 #if defined(__cplusplus) && __cplusplus >= 201103L
3866 
3867 #define CLARA_CPP11_OR_GREATER
3868 
3869 #if !defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR)
3870 #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
3871 #endif
3872 
3873 #ifndef CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
3874 #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
3875 #endif
3876 
3877 #ifndef CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
3878 #define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
3879 #endif
3880 
3881 #if !defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE)
3882 #define CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE
3883 #endif
3884 #if !defined(CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
3885 #define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
3886 #endif
3887 
3888 #endif // __cplusplus >= 201103L
3889 
3890 // Now set the actual defines based on the above + anything the user has configured
3891 #if defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NO_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_NO_CPP11)
3892 #define CLARA_CONFIG_CPP11_NULLPTR
3893 #endif
3894 #if defined(CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_NO_CPP11)
3895 #define CLARA_CONFIG_CPP11_NOEXCEPT
3896 #endif
3897 #if defined(CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CLARA_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CLARA_CONFIG_CPP11_GENERATED_METHODS) && !defined(CLARA_CONFIG_NO_CPP11)
3898 #define CLARA_CONFIG_CPP11_GENERATED_METHODS
3899 #endif
3900 #if defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_OVERRIDE) && !defined(CLARA_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_CPP11)
3901 #define CLARA_CONFIG_CPP11_OVERRIDE
3902 #endif
3903 #if defined(CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CLARA_CONFIG_NO_UNIQUE_PTR) && !defined(CLARA_CONFIG_CPP11_UNIQUE_PTR) && !defined(CLARA_CONFIG_NO_CPP11)
3904 #define CLARA_CONFIG_CPP11_UNIQUE_PTR
3905 #endif
3906 
3907 // noexcept support:
3908 #if defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_NOEXCEPT)
3909 #define CLARA_NOEXCEPT noexcept
3910 # define CLARA_NOEXCEPT_IS(x) noexcept(x)
3911 #else
3912 #define CLARA_NOEXCEPT throw()
3913 # define CLARA_NOEXCEPT_IS(x)
3914 #endif
3915 
3916 // nullptr support
3917 #ifdef CLARA_CONFIG_CPP11_NULLPTR
3918 #define CLARA_NULL nullptr
3919 #else
3920 #define CLARA_NULL NULL
3921 #endif
3922 
3923 // override support
3924 #ifdef CLARA_CONFIG_CPP11_OVERRIDE
3925 #define CLARA_OVERRIDE override
3926 #else
3927 #define CLARA_OVERRIDE
3928 #endif
3929 
3930 // unique_ptr support
3931 #ifdef CLARA_CONFIG_CPP11_UNIQUE_PTR
3932 # define CLARA_AUTO_PTR( T ) std::unique_ptr<T>
3933 #else
3934 # define CLARA_AUTO_PTR( T ) std::auto_ptr<T>
3935 #endif
3936 
3937 #endif // TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
3938 
3939 // ----------- end of #include from clara_compilers.h -----------
3940 // ........... back in clara.h
3941 
3942 #include <map>
3943 #include <stdexcept>
3944 #include <memory>
3945 
3946 #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
3947 #define CLARA_PLATFORM_WINDOWS
3948 #endif
3949 
3950 // Use optional outer namespace
3951 #ifdef STITCH_CLARA_OPEN_NAMESPACE
3952 STITCH_CLARA_OPEN_NAMESPACE
3953 #endif
3954 
3955 namespace Clara {
3956 
3957  struct UnpositionalTag {};
3958 
3959  extern UnpositionalTag _;
3960 
3961 #ifdef CLARA_CONFIG_MAIN
3962  UnpositionalTag _;
3963 #endif
3964 
3965  namespace Detail {
3966 
3967 #ifdef CLARA_CONSOLE_WIDTH
3968  const unsigned int consoleWidth = CLARA_CONFIG_CONSOLE_WIDTH;
3969 #else
3970  const unsigned int consoleWidth = 80;
3971 #endif
3972 
3973  using namespace Tbc;
3974 
3975  inline bool startsWith( std::string const& str, std::string const& prefix ) {
3976  return str.size() >= prefix.size() && str.substr( 0, prefix.size() ) == prefix;
3977  }
3978 
3979  template<typename T> struct RemoveConstRef{ typedef T type; };
3980  template<typename T> struct RemoveConstRef<T&>{ typedef T type; };
3981  template<typename T> struct RemoveConstRef<T const&>{ typedef T type; };
3982  template<typename T> struct RemoveConstRef<T const>{ typedef T type; };
3983 
3984  template<typename T> struct IsBool { static const bool value = false; };
3985  template<> struct IsBool<bool> { static const bool value = true; };
3986 
3987  template<typename T>
3988  void convertInto( std::string const& _source, T& _dest ) {
3989  std::stringstream ss;
3990  ss << _source;
3991  ss >> _dest;
3992  if( ss.fail() )
3993  throw std::runtime_error( "Unable to convert " + _source + " to destination type" );
3994  }
3995  inline void convertInto( std::string const& _source, std::string& _dest ) {
3996  _dest = _source;
3997  }
3998  inline void convertInto( std::string const& _source, bool& _dest ) {
3999  std::string sourceLC = _source;
4000  std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), ::tolower );
4001  if( sourceLC == "y" || sourceLC == "1" || sourceLC == "true" || sourceLC == "yes" || sourceLC == "on" )
4002  _dest = true;
4003  else if( sourceLC == "n" || sourceLC == "0" || sourceLC == "false" || sourceLC == "no" || sourceLC == "off" )
4004  _dest = false;
4005  else
4006  throw std::runtime_error( "Expected a boolean value but did not recognise:\n '" + _source + "'" );
4007  }
4008 
4009  template<typename ConfigT>
4010  struct IArgFunction {
4011  virtual ~IArgFunction() {}
4012 #ifdef CLARA_CONFIG_CPP11_GENERATED_METHODS
4013  IArgFunction() = default;
4014  IArgFunction( IArgFunction const& ) = default;
4015 #endif
4016  virtual void set( ConfigT& config, std::string const& value ) const = 0;
4017  virtual bool takesArg() const = 0;
4018  virtual IArgFunction* clone() const = 0;
4019  };
4020 
4021  template<typename ConfigT>
4022  class BoundArgFunction {
4023  public:
4024  BoundArgFunction() : functionObj( CLARA_NULL ) {}
4025  BoundArgFunction( IArgFunction<ConfigT>* _functionObj ) : functionObj( _functionObj ) {}
4026  BoundArgFunction( BoundArgFunction const& other ) : functionObj( other.functionObj ? other.functionObj->clone() : CLARA_NULL ) {}
4027  BoundArgFunction& operator = ( BoundArgFunction const& other ) {
4028  IArgFunction<ConfigT>* newFunctionObj = other.functionObj ? other.functionObj->clone() : CLARA_NULL;
4029  delete functionObj;
4030  functionObj = newFunctionObj;
4031  return *this;
4032  }
4033  ~BoundArgFunction() { delete functionObj; }
4034 
4035  void set( ConfigT& config, std::string const& value ) const {
4036  functionObj->set( config, value );
4037  }
4038  bool takesArg() const { return functionObj->takesArg(); }
4039 
4040  bool isSet() const {
4041  return functionObj != CLARA_NULL;
4042  }
4043  private:
4044  IArgFunction<ConfigT>* functionObj;
4045  };
4046 
4047  template<typename C>
4048  struct NullBinder : IArgFunction<C>{
4049  virtual void set( C&, std::string const& ) const {}
4050  virtual bool takesArg() const { return true; }
4051  virtual IArgFunction<C>* clone() const { return new NullBinder( *this ); }
4052  };
4053 
4054  template<typename C, typename M>
4055  struct BoundDataMember : IArgFunction<C>{
4056  BoundDataMember( M C::* _member ) : member( _member ) {}
4057  virtual void set( C& p, std::string const& stringValue ) const {
4058  convertInto( stringValue, p.*member );
4059  }
4060  virtual bool takesArg() const { return !IsBool<M>::value; }
4061  virtual IArgFunction<C>* clone() const { return new BoundDataMember( *this ); }
4062  M C::* member;
4063  };
4064  template<typename C, typename M>
4065  struct BoundUnaryMethod : IArgFunction<C>{
4066  BoundUnaryMethod( void (C::*_member)( M ) ) : member( _member ) {}
4067  virtual void set( C& p, std::string const& stringValue ) const {
4068  typename RemoveConstRef<M>::type value;
4069  convertInto( stringValue, value );
4070  (p.*member)( value );
4071  }
4072  virtual bool takesArg() const { return !IsBool<M>::value; }
4073  virtual IArgFunction<C>* clone() const { return new BoundUnaryMethod( *this ); }
4074  void (C::*member)( M );
4075  };
4076  template<typename C>
4077  struct BoundNullaryMethod : IArgFunction<C>{
4078  BoundNullaryMethod( void (C::*_member)() ) : member( _member ) {}
4079  virtual void set( C& p, std::string const& stringValue ) const {
4080  bool value;
4081  convertInto( stringValue, value );
4082  if( value )
4083  (p.*member)();
4084  }
4085  virtual bool takesArg() const { return false; }
4086  virtual IArgFunction<C>* clone() const { return new BoundNullaryMethod( *this ); }
4087  void (C::*member)();
4088  };
4089 
4090  template<typename C>
4091  struct BoundUnaryFunction : IArgFunction<C>{
4092  BoundUnaryFunction( void (*_function)( C& ) ) : function( _function ) {}
4093  virtual void set( C& obj, std::string const& stringValue ) const {
4094  bool value;
4095  convertInto( stringValue, value );
4096  if( value )
4097  function( obj );
4098  }
4099  virtual bool takesArg() const { return false; }
4100  virtual IArgFunction<C>* clone() const { return new BoundUnaryFunction( *this ); }
4101  void (*function)( C& );
4102  };
4103 
4104  template<typename C, typename T>
4105  struct BoundBinaryFunction : IArgFunction<C>{
4106  BoundBinaryFunction( void (*_function)( C&, T ) ) : function( _function ) {}
4107  virtual void set( C& obj, std::string const& stringValue ) const {
4108  typename RemoveConstRef<T>::type value;
4109  convertInto( stringValue, value );
4110  function( obj, value );
4111  }
4112  virtual bool takesArg() const { return !IsBool<T>::value; }
4113  virtual IArgFunction<C>* clone() const { return new BoundBinaryFunction( *this ); }
4114  void (*function)( C&, T );
4115  };
4116 
4117  } // namespace Detail
4118 
4119  inline std::vector<std::string> argsToVector( int argc, char const* const* const argv ) {
4120  std::vector<std::string> args( static_cast<std::size_t>( argc ) );
4121  for( std::size_t i = 0; i < static_cast<std::size_t>( argc ); ++i )
4122  args[i] = argv[i];
4123 
4124  return args;
4125  }
4126 
4127  class Parser {
4128  enum Mode { None, MaybeShortOpt, SlashOpt, ShortOpt, LongOpt, Positional };
4129  Mode mode;
4130  std::size_t from;
4131  bool inQuotes;
4132  public:
4133 
4134  struct Token {
4135  enum Type { Positional, ShortOpt, LongOpt };
4136  Token( Type _type, std::string const& _data ) : type( _type ), data( _data ) {}
4137  Type type;
4138  std::string data;
4139  };
4140 
4141  Parser() : mode( None ), from( 0 ), inQuotes( false ){}
4142 
4143  void parseIntoTokens( std::vector<std::string> const& args, std::vector<Token>& tokens ) {
4144  const std::string doubleDash = "--";
4145  for( std::size_t i = 1; i < args.size() && args[i] != doubleDash; ++i )
4146  parseIntoTokens( args[i], tokens);
4147  }
4148 
4149  void parseIntoTokens( std::string const& arg, std::vector<Token>& tokens ) {
4150  for( std::size_t i = 0; i <= arg.size(); ++i ) {
4151  char c = arg[i];
4152  if( c == '"' )
4153  inQuotes = !inQuotes;
4154  mode = handleMode( i, c, arg, tokens );
4155  }
4156  }
4157  Mode handleMode( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
4158  switch( mode ) {
4159  case None: return handleNone( i, c );
4160  case MaybeShortOpt: return handleMaybeShortOpt( i, c );
4161  case ShortOpt:
4162  case LongOpt:
4163  case SlashOpt: return handleOpt( i, c, arg, tokens );
4164  case Positional: return handlePositional( i, c, arg, tokens );
4165  default: throw std::logic_error( "Unknown mode" );
4166  }
4167  }
4168 
4169  Mode handleNone( std::size_t i, char c ) {
4170  if( inQuotes ) {
4171  from = i;
4172  return Positional;
4173  }
4174  switch( c ) {
4175  case '-': return MaybeShortOpt;
4176 #ifdef CLARA_PLATFORM_WINDOWS
4177  case '/': from = i+1; return SlashOpt;
4178 #endif
4179  default: from = i; return Positional;
4180  }
4181  }
4182  Mode handleMaybeShortOpt( std::size_t i, char c ) {
4183  switch( c ) {
4184  case '-': from = i+1; return LongOpt;
4185  default: from = i; return ShortOpt;
4186  }
4187  }
4188  Mode handleOpt( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
4189  if( std::string( ":=\0", 3 ).find( c ) == std::string::npos )
4190  return mode;
4191 
4192  std::string optName = arg.substr( from, i-from );
4193  if( mode == ShortOpt )
4194  for( std::size_t j = 0; j < optName.size(); ++j )
4195  tokens.push_back( Token( Token::ShortOpt, optName.substr( j, 1 ) ) );
4196  else if( mode == SlashOpt && optName.size() == 1 )
4197  tokens.push_back( Token( Token::ShortOpt, optName ) );
4198  else
4199  tokens.push_back( Token( Token::LongOpt, optName ) );
4200  return None;
4201  }
4202  Mode handlePositional( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
4203  if( inQuotes || std::string( "\0", 1 ).find( c ) == std::string::npos )
4204  return mode;
4205 
4206  std::string data = arg.substr( from, i-from );
4207  tokens.push_back( Token( Token::Positional, data ) );
4208  return None;
4209  }
4210  };
4211 
4212  template<typename ConfigT>
4213  struct CommonArgProperties {
4214  CommonArgProperties() {}
4215  CommonArgProperties( Detail::BoundArgFunction<ConfigT> const& _boundField ) : boundField( _boundField ) {}
4216 
4217  Detail::BoundArgFunction<ConfigT> boundField;
4218  std::string description;
4219  std::string detail;
4220  std::string placeholder; // Only value if boundField takes an arg
4221 
4222  bool takesArg() const {
4223  return !placeholder.empty();
4224  }
4225  void validate() const {
4226  if( !boundField.isSet() )
4227  throw std::logic_error( "option not bound" );
4228  }
4229  };
4230  struct OptionArgProperties {
4231  std::vector<std::string> shortNames;
4232  std::string longName;
4233 
4234  bool hasShortName( std::string const& shortName ) const {
4235  return std::find( shortNames.begin(), shortNames.end(), shortName ) != shortNames.end();
4236  }
4237  bool hasLongName( std::string const& _longName ) const {
4238  return _longName == longName;
4239  }
4240  };
4241  struct PositionalArgProperties {
4242  PositionalArgProperties() : position( -1 ) {}
4243  int position; // -1 means non-positional (floating)
4244 
4245  bool isFixedPositional() const {
4246  return position != -1;
4247  }
4248  };
4249 
4250  template<typename ConfigT>
4251  class CommandLine {
4252 
4253  struct Arg : CommonArgProperties<ConfigT>, OptionArgProperties, PositionalArgProperties {
4254  Arg() {}
4255  Arg( Detail::BoundArgFunction<ConfigT> const& _boundField ) : CommonArgProperties<ConfigT>( _boundField ) {}
4256 
4257  using CommonArgProperties<ConfigT>::placeholder; // !TBD
4258 
4259  std::string dbgName() const {
4260  if( !longName.empty() )
4261  return "--" + longName;
4262  if( !shortNames.empty() )
4263  return "-" + shortNames[0];
4264  return "positional args";
4265  }
4266  std::string commands() const {
4267  std::ostringstream oss;
4268  bool first = true;
4269  std::vector<std::string>::const_iterator it = shortNames.begin(), itEnd = shortNames.end();
4270  for(; it != itEnd; ++it ) {
4271  if( first )
4272  first = false;
4273  else
4274  oss << ", ";
4275  oss << "-" << *it;
4276  }
4277  if( !longName.empty() ) {
4278  if( !first )
4279  oss << ", ";
4280  oss << "--" << longName;
4281  }
4282  if( !placeholder.empty() )
4283  oss << " <" << placeholder << ">";
4284  return oss.str();
4285  }
4286  };
4287 
4288  typedef CLARA_AUTO_PTR( Arg ) ArgAutoPtr;
4289 
4290  friend void addOptName( Arg& arg, std::string const& optName )
4291  {
4292  if( optName.empty() )
4293  return;
4294  if( Detail::startsWith( optName, "--" ) ) {
4295  if( !arg.longName.empty() )
4296  throw std::logic_error( "Only one long opt may be specified. '"
4297  + arg.longName
4298  + "' already specified, now attempting to add '"
4299  + optName + "'" );
4300  arg.longName = optName.substr( 2 );
4301  }
4302  else if( Detail::startsWith( optName, "-" ) )
4303  arg.shortNames.push_back( optName.substr( 1 ) );
4304  else
4305  throw std::logic_error( "option must begin with - or --. Option was: '" + optName + "'" );
4306  }
4307  friend void setPositionalArg( Arg& arg, int position )
4308  {
4309  arg.position = position;
4310  }
4311 
4312  class ArgBuilder {
4313  public:
4314  ArgBuilder( Arg* arg ) : m_arg( arg ) {}
4315 
4316  // Bind a non-boolean data member (requires placeholder string)
4317  template<typename C, typename M>
4318  void bind( M C::* field, std::string const& placeholder ) {
4319  m_arg->boundField = new Detail::BoundDataMember<C,M>( field );
4320  m_arg->placeholder = placeholder;
4321  }
4322  // Bind a boolean data member (no placeholder required)
4323  template<typename C>
4324  void bind( bool C::* field ) {
4325  m_arg->boundField = new Detail::BoundDataMember<C,bool>( field );
4326  }
4327 
4328  // Bind a method taking a single, non-boolean argument (requires a placeholder string)
4329  template<typename C, typename M>
4330  void bind( void (C::* unaryMethod)( M ), std::string const& placeholder ) {
4331  m_arg->boundField = new Detail::BoundUnaryMethod<C,M>( unaryMethod );
4332  m_arg->placeholder = placeholder;
4333  }
4334 
4335  // Bind a method taking a single, boolean argument (no placeholder string required)
4336  template<typename C>
4337  void bind( void (C::* unaryMethod)( bool ) ) {
4338  m_arg->boundField = new Detail::BoundUnaryMethod<C,bool>( unaryMethod );
4339  }
4340 
4341  // Bind a method that takes no arguments (will be called if opt is present)
4342  template<typename C>
4343  void bind( void (C::* nullaryMethod)() ) {
4344  m_arg->boundField = new Detail::BoundNullaryMethod<C>( nullaryMethod );
4345  }
4346 
4347  // Bind a free function taking a single argument - the object to operate on (no placeholder string required)
4348  template<typename C>
4349  void bind( void (* unaryFunction)( C& ) ) {
4350  m_arg->boundField = new Detail::BoundUnaryFunction<C>( unaryFunction );
4351  }
4352 
4353  // Bind a free function taking a single argument - the object to operate on (requires a placeholder string)
4354  template<typename C, typename T>
4355  void bind( void (* binaryFunction)( C&, T ), std::string const& placeholder ) {
4356  m_arg->boundField = new Detail::BoundBinaryFunction<C, T>( binaryFunction );
4357  m_arg->placeholder = placeholder;
4358  }
4359 
4360  ArgBuilder& describe( std::string const& description ) {
4361  m_arg->description = description;
4362  return *this;
4363  }
4364  ArgBuilder& detail( std::string const& detail ) {
4365  m_arg->detail = detail;
4366  return *this;
4367  }
4368 
4369  protected:
4370  Arg* m_arg;
4371  };
4372 
4373  class OptBuilder : public ArgBuilder {
4374  public:
4375  OptBuilder( Arg* arg ) : ArgBuilder( arg ) {}
4376  OptBuilder( OptBuilder& other ) : ArgBuilder( other ) {}
4377 
4378  OptBuilder& operator[]( std::string const& optName ) {
4379  addOptName( *ArgBuilder::m_arg, optName );
4380  return *this;
4381  }
4382  };
4383 
4384  public:
4385 
4386  CommandLine()
4387  : m_boundProcessName( new Detail::NullBinder<ConfigT>() ),
4388  m_highestSpecifiedArgPosition( 0 ),
4389  m_throwOnUnrecognisedTokens( false )
4390  {}
4391  CommandLine( CommandLine const& other )
4392  : m_boundProcessName( other.m_boundProcessName ),
4393  m_options ( other.m_options ),
4394  m_positionalArgs( other.m_positionalArgs ),
4395  m_highestSpecifiedArgPosition( other.m_highestSpecifiedArgPosition ),
4396  m_throwOnUnrecognisedTokens( other.m_throwOnUnrecognisedTokens )
4397  {
4398  if( other.m_floatingArg.get() )
4399  m_floatingArg.reset( new Arg( *other.m_floatingArg ) );
4400  }
4401 
4402  CommandLine& setThrowOnUnrecognisedTokens( bool shouldThrow = true ) {
4403  m_throwOnUnrecognisedTokens = shouldThrow;
4404  return *this;
4405  }
4406 
4407  OptBuilder operator[]( std::string const& optName ) {
4408  m_options.push_back( Arg() );
4409  addOptName( m_options.back(), optName );
4410  OptBuilder builder( &m_options.back() );
4411  return builder;
4412  }
4413 
4414  ArgBuilder operator[]( int position ) {
4415  m_positionalArgs.insert( std::make_pair( position, Arg() ) );
4416  if( position > m_highestSpecifiedArgPosition )
4417  m_highestSpecifiedArgPosition = position;
4418  setPositionalArg( m_positionalArgs[position], position );
4419  ArgBuilder builder( &m_positionalArgs[position] );
4420  return builder;
4421  }
4422 
4423  // Invoke this with the _ instance
4424  ArgBuilder operator[]( UnpositionalTag ) {
4425  if( m_floatingArg.get() )
4426  throw std::logic_error( "Only one unpositional argument can be added" );
4427  m_floatingArg.reset( new Arg() );
4428  ArgBuilder builder( m_floatingArg.get() );
4429  return builder;
4430  }
4431 
4432  template<typename C, typename M>
4433  void bindProcessName( M C::* field ) {
4434  m_boundProcessName = new Detail::BoundDataMember<C,M>( field );
4435  }
4436  template<typename C, typename M>
4437  void bindProcessName( void (C::*_unaryMethod)( M ) ) {
4438  m_boundProcessName = new Detail::BoundUnaryMethod<C,M>( _unaryMethod );
4439  }
4440 
4441  void optUsage( std::ostream& os, std::size_t indent = 0, std::size_t width = Detail::consoleWidth ) const {
4442  typename std::vector<Arg>::const_iterator itBegin = m_options.begin(), itEnd = m_options.end(), it;
4443  std::size_t maxWidth = 0;
4444  for( it = itBegin; it != itEnd; ++it )
4445  maxWidth = (std::max)( maxWidth, it->commands().size() );
4446 
4447  for( it = itBegin; it != itEnd; ++it ) {
4448  Detail::Text usage( it->commands(), Detail::TextAttributes()
4449  .setWidth( maxWidth+indent )
4450  .setIndent( indent ) );
4451  Detail::Text desc( it->description, Detail::TextAttributes()
4452  .setWidth( width - maxWidth - 3 ) );
4453 
4454  for( std::size_t i = 0; i < (std::max)( usage.size(), desc.size() ); ++i ) {
4455  std::string usageCol = i < usage.size() ? usage[i] : "";
4456  os << usageCol;
4457 
4458  if( i < desc.size() && !desc[i].empty() )
4459  os << std::string( indent + 2 + maxWidth - usageCol.size(), ' ' )
4460  << desc[i];
4461  os << "\n";
4462  }
4463  }
4464  }
4465  std::string optUsage() const {
4466  std::ostringstream oss;
4467  optUsage( oss );
4468  return oss.str();
4469  }
4470 
4471  void argSynopsis( std::ostream& os ) const {
4472  for( int i = 1; i <= m_highestSpecifiedArgPosition; ++i ) {
4473  if( i > 1 )
4474  os << " ";
4475  typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( i );
4476  if( it != m_positionalArgs.end() )
4477  os << "<" << it->second.placeholder << ">";
4478  else if( m_floatingArg.get() )
4479  os << "<" << m_floatingArg->placeholder << ">";
4480  else
4481  throw std::logic_error( "non consecutive positional arguments with no floating args" );
4482  }
4483  // !TBD No indication of mandatory args
4484  if( m_floatingArg.get() ) {
4485  if( m_highestSpecifiedArgPosition > 1 )
4486  os << " ";
4487  os << "[<" << m_floatingArg->placeholder << "> ...]";
4488  }
4489  }
4490  std::string argSynopsis() const {
4491  std::ostringstream oss;
4492  argSynopsis( oss );
4493  return oss.str();
4494  }
4495 
4496  void usage( std::ostream& os, std::string const& procName ) const {
4497  validate();
4498  os << "usage:\n " << procName << " ";
4499  argSynopsis( os );
4500  if( !m_options.empty() ) {
4501  os << " [options]\n\nwhere options are: \n";
4502  optUsage( os, 2 );
4503  }
4504  os << "\n";
4505  }
4506  std::string usage( std::string const& procName ) const {
4507  std::ostringstream oss;
4508  usage( oss, procName );
4509  return oss.str();
4510  }
4511 
4512  ConfigT parse( std::vector<std::string> const& args ) const {
4513  ConfigT config;
4514  parseInto( args, config );
4515  return config;
4516  }
4517 
4518  std::vector<Parser::Token> parseInto( std::vector<std::string> const& args, ConfigT& config ) const {
4519  std::string processName = args[0];
4520  std::size_t lastSlash = processName.find_last_of( "/\\" );
4521  if( lastSlash != std::string::npos )
4522  processName = processName.substr( lastSlash+1 );
4523  m_boundProcessName.set( config, processName );
4524  std::vector<Parser::Token> tokens;
4525  Parser parser;
4526  parser.parseIntoTokens( args, tokens );
4527  return populate( tokens, config );
4528  }
4529 
4530  std::vector<Parser::Token> populate( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
4531  validate();
4532  std::vector<Parser::Token> unusedTokens = populateOptions( tokens, config );
4533  unusedTokens = populateFixedArgs( unusedTokens, config );
4534  unusedTokens = populateFloatingArgs( unusedTokens, config );
4535  return unusedTokens;
4536  }
4537 
4538  std::vector<Parser::Token> populateOptions( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
4539  std::vector<Parser::Token> unusedTokens;
4540  std::vector<std::string> errors;
4541  for( std::size_t i = 0; i < tokens.size(); ++i ) {
4542  Parser::Token const& token = tokens[i];
4543  typename std::vector<Arg>::const_iterator it = m_options.begin(), itEnd = m_options.end();
4544  for(; it != itEnd; ++it ) {
4545  Arg const& arg = *it;
4546 
4547  try {
4548  if( ( token.type == Parser::Token::ShortOpt && arg.hasShortName( token.data ) ) ||
4549  ( token.type == Parser::Token::LongOpt && arg.hasLongName( token.data ) ) ) {
4550  if( arg.takesArg() ) {
4551  if( i == tokens.size()-1 || tokens[i+1].type != Parser::Token::Positional )
4552  errors.push_back( "Expected argument to option: " + token.data );
4553  else
4554  arg.boundField.set( config, tokens[++i].data );
4555  }
4556  else {
4557  arg.boundField.set( config, "true" );
4558  }
4559  break;
4560  }
4561  }
4562  catch( std::exception& ex ) {
4563  errors.push_back( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" );
4564  }
4565  }
4566  if( it == itEnd ) {
4567  if( token.type == Parser::Token::Positional || !m_throwOnUnrecognisedTokens )
4568  unusedTokens.push_back( token );
4569  else if( errors.empty() && m_throwOnUnrecognisedTokens )
4570  errors.push_back( "unrecognised option: " + token.data );
4571  }
4572  }
4573  if( !errors.empty() ) {
4574  std::ostringstream oss;
4575  for( std::vector<std::string>::const_iterator it = errors.begin(), itEnd = errors.end();
4576  it != itEnd;
4577  ++it ) {
4578  if( it != errors.begin() )
4579  oss << "\n";
4580  oss << *it;
4581  }
4582  throw std::runtime_error( oss.str() );
4583  }
4584  return unusedTokens;
4585  }
4586  std::vector<Parser::Token> populateFixedArgs( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
4587  std::vector<Parser::Token> unusedTokens;
4588  int position = 1;
4589  for( std::size_t i = 0; i < tokens.size(); ++i ) {
4590  Parser::Token const& token = tokens[i];
4591  typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( position );
4592  if( it != m_positionalArgs.end() )
4593  it->second.boundField.set( config, token.data );
4594  else
4595  unusedTokens.push_back( token );
4596  if( token.type == Parser::Token::Positional )
4597  position++;
4598  }
4599  return unusedTokens;
4600  }
4601  std::vector<Parser::Token> populateFloatingArgs( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
4602  if( !m_floatingArg.get() )
4603  return tokens;
4604  std::vector<Parser::Token> unusedTokens;
4605  for( std::size_t i = 0; i < tokens.size(); ++i ) {
4606  Parser::Token const& token = tokens[i];
4607  if( token.type == Parser::Token::Positional )
4608  m_floatingArg->boundField.set( config, token.data );
4609  else
4610  unusedTokens.push_back( token );
4611  }
4612  return unusedTokens;
4613  }
4614 
4615  void validate() const
4616  {
4617  if( m_options.empty() && m_positionalArgs.empty() && !m_floatingArg.get() )
4618  throw std::logic_error( "No options or arguments specified" );
4619 
4620  for( typename std::vector<Arg>::const_iterator it = m_options.begin(),
4621  itEnd = m_options.end();
4622  it != itEnd; ++it )
4623  it->validate();
4624  }
4625 
4626  private:
4627  Detail::BoundArgFunction<ConfigT> m_boundProcessName;
4628  std::vector<Arg> m_options;
4629  std::map<int, Arg> m_positionalArgs;
4630  ArgAutoPtr m_floatingArg;
4631  int m_highestSpecifiedArgPosition;
4632  bool m_throwOnUnrecognisedTokens;
4633  };
4634 
4635 } // end namespace Clara
4636 
4637 STITCH_CLARA_CLOSE_NAMESPACE
4638 #undef STITCH_CLARA_OPEN_NAMESPACE
4639 #undef STITCH_CLARA_CLOSE_NAMESPACE
4640 
4641 #endif // TWOBLUECUBES_CLARA_H_INCLUDED
4642 #undef STITCH_CLARA_OPEN_NAMESPACE
4643 
4644 // Restore Clara's value for console width, if present
4645 #ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
4646 #define CLARA_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
4647 #undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
4648 #endif
4649 
4650 #include <fstream>
4651 
4652 namespace Catch {
4653 
4654  inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; }
4655  inline void abortAfterX( ConfigData& config, int x ) {
4656  if( x < 1 )
4657  throw std::runtime_error( "Value after -x or --abortAfter must be greater than zero" );
4658  config.abortAfter = x;
4659  }
4660  inline void addTestOrTags( ConfigData& config, std::string const& _testSpec ) { config.testsOrTags.push_back( _testSpec ); }
4661  inline void addReporterName( ConfigData& config, std::string const& _reporterName ) { config.reporterNames.push_back( _reporterName ); }
4662 
4663  inline void addWarning( ConfigData& config, std::string const& _warning ) {
4664  if( _warning == "NoAssertions" )
4665  config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions );
4666  else
4667  throw std::runtime_error( "Unrecognised warning: '" + _warning + "'" );
4668  }
4669  inline void setOrder( ConfigData& config, std::string const& order ) {
4670  if( startsWith( "declared", order ) )
4671  config.runOrder = RunTests::InDeclarationOrder;
4672  else if( startsWith( "lexical", order ) )
4673  config.runOrder = RunTests::InLexicographicalOrder;
4674  else if( startsWith( "random", order ) )
4675  config.runOrder = RunTests::InRandomOrder;
4676  else
4677  throw std::runtime_error( "Unrecognised ordering: '" + order + "'" );
4678  }
4679  inline void setRngSeed( ConfigData& config, std::string const& seed ) {
4680  if( seed == "time" ) {
4681  config.rngSeed = static_cast<unsigned int>( std::time(0) );
4682  }
4683  else {
4684  std::stringstream ss;
4685  ss << seed;
4686  ss >> config.rngSeed;
4687  if( ss.fail() )
4688  throw std::runtime_error( "Argment to --rng-seed should be the word 'time' or a number" );
4689  }
4690  }
4691  inline void setVerbosity( ConfigData& config, int level ) {
4692  // !TBD: accept strings?
4693  config.verbosity = static_cast<Verbosity::Level>( level );
4694  }
4695  inline void setShowDurations( ConfigData& config, bool _showDurations ) {
4696  config.showDurations = _showDurations
4697  ? ShowDurations::Always
4698  : ShowDurations::Never;
4699  }
4700  inline void setUseColour( ConfigData& config, std::string const& value ) {
4701  std::string mode = toLower( value );
4702 
4703  if( mode == "yes" )
4704  config.useColour = UseColour::Yes;
4705  else if( mode == "no" )
4706  config.useColour = UseColour::No;
4707  else if( mode == "auto" )
4708  config.useColour = UseColour::Auto;
4709  else
4710  throw std::runtime_error( "colour mode must be one of: auto, yes or no" );
4711  }
4712  inline void forceColour( ConfigData& config ) {
4713  config.useColour = UseColour::Yes;
4714  }
4715  inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) {
4716  std::ifstream f( _filename.c_str() );
4717  if( !f.is_open() )
4718  throw std::domain_error( "Unable to load input file: " + _filename );
4719 
4720  std::string line;
4721  while( std::getline( f, line ) ) {
4722  line = trim(line);
4723  if( !line.empty() && !startsWith( line, "#" ) ) {
4724  if( !startsWith( line, "\"" ) )
4725  line = "\"" + line + "\"";
4726  addTestOrTags( config, line + "," );
4727  }
4728  }
4729  }
4730 
4731  inline Clara::CommandLine<ConfigData> makeCommandLineParser() {
4732 
4733  using namespace Clara;
4734  CommandLine<ConfigData> cli;
4735 
4736  cli.bindProcessName( &ConfigData::processName );
4737 
4738  cli["-?"]["-h"]["--help"]
4739  .describe( "display usage information" )
4740  .bind( &ConfigData::showHelp );
4741 
4742  cli["-l"]["--list-tests"]
4743  .describe( "list all/matching test cases" )
4744  .bind( &ConfigData::listTests );
4745 
4746  cli["-t"]["--list-tags"]
4747  .describe( "list all/matching tags" )
4748  .bind( &ConfigData::listTags );
4749 
4750  cli["-s"]["--success"]
4751  .describe( "include successful tests in output" )
4752  .bind( &ConfigData::showSuccessfulTests );
4753 
4754  cli["-b"]["--break"]
4755  .describe( "break into debugger on failure" )
4756  .bind( &ConfigData::shouldDebugBreak );
4757 
4758  cli["-e"]["--nothrow"]
4759  .describe( "skip exception tests" )
4760  .bind( &ConfigData::noThrow );
4761 
4762  cli["-i"]["--invisibles"]
4763  .describe( "show invisibles (tabs, newlines)" )
4764  .bind( &ConfigData::showInvisibles );
4765 
4766  cli["-o"]["--out"]
4767  .describe( "output filename" )
4768  .bind( &ConfigData::outputFilename, "filename" );
4769 
4770  cli["-r"]["--reporter"]
4771 // .placeholder( "name[:filename]" )
4772  .describe( "reporter to use (defaults to console)" )
4773  .bind( &addReporterName, "name" );
4774 
4775  cli["-n"]["--name"]
4776  .describe( "suite name" )
4777  .bind( &ConfigData::name, "name" );
4778 
4779  cli["-a"]["--abort"]
4780  .describe( "abort at first failure" )
4781  .bind( &abortAfterFirst );
4782 
4783  cli["-x"]["--abortx"]
4784  .describe( "abort after x failures" )
4785  .bind( &abortAfterX, "no. failures" );
4786 
4787  cli["-w"]["--warn"]
4788  .describe( "enable warnings" )
4789  .bind( &addWarning, "warning name" );
4790 
4791 // - needs updating if reinstated
4792 // cli.into( &setVerbosity )
4793 // .describe( "level of verbosity (0=no output)" )
4794 // .shortOpt( "v")
4795 // .longOpt( "verbosity" )
4796 // .placeholder( "level" );
4797 
4798  cli[_]
4799  .describe( "which test or tests to use" )
4800  .bind( &addTestOrTags, "test name, pattern or tags" );
4801 
4802  cli["-d"]["--durations"]
4803  .describe( "show test durations" )
4804  .bind( &setShowDurations, "yes|no" );
4805 
4806  cli["-f"]["--input-file"]
4807  .describe( "load test names to run from a file" )
4808  .bind( &loadTestNamesFromFile, "filename" );
4809 
4810  cli["-#"]["--filenames-as-tags"]
4811  .describe( "adds a tag for the filename" )
4812  .bind( &ConfigData::filenamesAsTags );
4813 
4814  // Less common commands which don't have a short form
4815  cli["--list-test-names-only"]
4816  .describe( "list all/matching test cases names only" )
4817  .bind( &ConfigData::listTestNamesOnly );
4818 
4819  cli["--list-reporters"]
4820  .describe( "list all reporters" )
4821  .bind( &ConfigData::listReporters );
4822 
4823  cli["--order"]
4824  .describe( "test case order (defaults to decl)" )
4825  .bind( &setOrder, "decl|lex|rand" );
4826 
4827  cli["--rng-seed"]
4828  .describe( "set a specific seed for random numbers" )
4829  .bind( &setRngSeed, "'time'|number" );
4830 
4831  cli["--force-colour"]
4832  .describe( "force colourised output (deprecated)" )
4833  .bind( &forceColour );
4834 
4835  cli["--use-colour"]
4836  .describe( "should output be colourised" )
4837  .bind( &setUseColour, "yes|no" );
4838 
4839  return cli;
4840  }
4841 
4842 } // end namespace Catch
4843 
4844 // #included from: internal/catch_list.hpp
4845 #define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
4846 
4847 // #included from: catch_text.h
4848 #define TWOBLUECUBES_CATCH_TEXT_H_INCLUDED
4849 
4850 #define TBC_TEXT_FORMAT_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
4851 
4852 #define CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE Catch
4853 // #included from: ../external/tbc_text_format.h
4854 // Only use header guard if we are not using an outer namespace
4855 #ifndef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
4856 # ifdef TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED
4857 # ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
4858 # define TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
4859 # endif
4860 # else
4861 # define TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED
4862 # endif
4863 #endif
4864 #ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
4865 #include <string>
4866 #include <vector>
4867 #include <sstream>
4868 
4869 // Use optional outer namespace
4870 #ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
4871 namespace CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE {
4872 #endif
4873 
4874 namespace Tbc {
4875 
4876 #ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH
4877  const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH;
4878 #else
4879  const unsigned int consoleWidth = 80;
4880 #endif
4881 
4882  struct TextAttributes {
4883  TextAttributes()
4884  : initialIndent( std::string::npos ),
4885  indent( 0 ),
4886  width( consoleWidth-1 ),
4887  tabChar( '\t' )
4888  {}
4889 
4890  TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
4891  TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
4892  TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
4893  TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; }
4894 
4895  std::size_t initialIndent; // indent of first line, or npos
4896  std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
4897  std::size_t width; // maximum width of text, including indent. Longer text will wrap
4898  char tabChar; // If this char is seen the indent is changed to current pos
4899  };
4900 
4901  class Text {
4902  public:
4903  Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() )
4904  : attr( _attr )
4905  {
4906  std::string wrappableChars = " [({.,/|\\-";
4907  std::size_t indent = _attr.initialIndent != std::string::npos
4908  ? _attr.initialIndent
4909  : _attr.indent;
4910  std::string remainder = _str;
4911 
4912  while( !remainder.empty() ) {
4913  if( lines.size() >= 1000 ) {
4914  lines.push_back( "... message truncated due to excessive size" );
4915  return;
4916  }
4917  std::size_t tabPos = std::string::npos;
4918  std::size_t width = (std::min)( remainder.size(), _attr.width - indent );
4919  std::size_t pos = remainder.find_first_of( '\n' );
4920  if( pos <= width ) {
4921  width = pos;
4922  }
4923  pos = remainder.find_last_of( _attr.tabChar, width );
4924  if( pos != std::string::npos ) {
4925  tabPos = pos;
4926  if( remainder[width] == '\n' )
4927  width--;
4928  remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 );
4929  }
4930 
4931  if( width == remainder.size() ) {
4932  spliceLine( indent, remainder, width );
4933  }
4934  else if( remainder[width] == '\n' ) {
4935  spliceLine( indent, remainder, width );
4936  if( width <= 1 || remainder.size() != 1 )
4937  remainder = remainder.substr( 1 );
4938  indent = _attr.indent;
4939  }
4940  else {
4941  pos = remainder.find_last_of( wrappableChars, width );
4942  if( pos != std::string::npos && pos > 0 ) {
4943  spliceLine( indent, remainder, pos );
4944  if( remainder[0] == ' ' )
4945  remainder = remainder.substr( 1 );
4946  }
4947  else {
4948  spliceLine( indent, remainder, width-1 );
4949  lines.back() += "-";
4950  }
4951  if( lines.size() == 1 )
4952  indent = _attr.indent;
4953  if( tabPos != std::string::npos )
4954  indent += tabPos;
4955  }
4956  }
4957  }
4958 
4959  void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) {
4960  lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) );
4961  _remainder = _remainder.substr( _pos );
4962  }
4963 
4964  typedef std::vector<std::string>::const_iterator const_iterator;
4965 
4966  const_iterator begin() const { return lines.begin(); }
4967  const_iterator end() const { return lines.end(); }
4968  std::string const& last() const { return lines.back(); }
4969  std::size_t size() const { return lines.size(); }
4970  std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
4971  std::string toString() const {
4972  std::ostringstream oss;
4973  oss << *this;
4974  return oss.str();
4975  }
4976 
4977  inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) {
4978  for( Text::const_iterator it = _text.begin(), itEnd = _text.end();
4979  it != itEnd; ++it ) {
4980  if( it != _text.begin() )
4981  _stream << "\n";
4982  _stream << *it;
4983  }
4984  return _stream;
4985  }
4986 
4987  private:
4988  std::string str;
4989  TextAttributes attr;
4990  std::vector<std::string> lines;
4991  };
4992 
4993 } // end namespace Tbc
4994 
4995 #ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
4996 } // end outer namespace
4997 #endif
4998 
4999 #endif // TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
5000 #undef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
5001 
5002 namespace Catch {
5003  using Tbc::Text;
5004  using Tbc::TextAttributes;
5005 }
5006 
5007 // #included from: catch_console_colour.hpp
5008 #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_HPP_INCLUDED
5009 
5010 namespace Catch {
5011 
5012  struct Colour {
5013  enum Code {
5014  None = 0,
5015 
5016  White,
5017  Red,
5018  Green,
5019  Blue,
5020  Cyan,
5021  Yellow,
5022  Grey,
5023 
5024  Bright = 0x10,
5025 
5026  BrightRed = Bright | Red,
5027  BrightGreen = Bright | Green,
5028  LightGrey = Bright | Grey,
5029  BrightWhite = Bright | White,
5030 
5031  // By intention
5032  FileName = LightGrey,
5033  Warning = Yellow,
5034  ResultError = BrightRed,
5035  ResultSuccess = BrightGreen,
5036  ResultExpectedFailure = Warning,
5037 
5038  Error = BrightRed,
5039  Success = Green,
5040 
5041  OriginalExpression = Cyan,
5042  ReconstructedExpression = Yellow,
5043 
5044  SecondaryText = LightGrey,
5045  Headers = White
5046  };
5047 
5048  // Use constructed object for RAII guard
5049  Colour( Code _colourCode );
5050  Colour( Colour const& other );
5051  ~Colour();
5052 
5053  // Use static method for one-shot changes
5054  static void use( Code _colourCode );
5055 
5056  private:
5057  bool m_moved;
5058  };
5059 
5060  inline std::ostream& operator << ( std::ostream& os, Colour const& ) { return os; }
5061 
5062 } // end namespace Catch
5063 
5064 // #included from: catch_interfaces_reporter.h
5065 #define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
5066 
5067 #include <string>
5068 #include <ostream>
5069 #include <map>
5070 #include <assert.h>
5071 
5072 namespace Catch
5073 {
5074  struct ReporterConfig {
5075  explicit ReporterConfig( Ptr<IConfig const> const& _fullConfig )
5076  : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
5077 
5078  ReporterConfig( Ptr<IConfig const> const& _fullConfig, std::ostream& _stream )
5079  : m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
5080 
5081  std::ostream& stream() const { return *m_stream; }
5082  Ptr<IConfig const> fullConfig() const { return m_fullConfig; }
5083 
5084  private:
5085  std::ostream* m_stream;
5086  Ptr<IConfig const> m_fullConfig;
5087  };
5088 
5089  struct ReporterPreferences {
5090  ReporterPreferences()
5091  : shouldRedirectStdOut( false )
5092  {}
5093 
5094  bool shouldRedirectStdOut;
5095  };
5096 
5097  template<typename T>
5098  struct LazyStat : Option<T> {
5099  LazyStat() : used( false ) {}
5100  LazyStat& operator=( T const& _value ) {
5101  Option<T>::operator=( _value );
5102  used = false;
5103  return *this;
5104  }
5105  void reset() {
5106  Option<T>::reset();
5107  used = false;
5108  }
5109  bool used;
5110  };
5111 
5112  struct TestRunInfo {
5113  TestRunInfo( std::string const& _name ) : name( _name ) {}
5114  std::string name;
5115  };
5116  struct GroupInfo {
5117  GroupInfo( std::string const& _name,
5118  std::size_t _groupIndex,
5119  std::size_t _groupsCount )
5120  : name( _name ),
5121  groupIndex( _groupIndex ),
5122  groupsCounts( _groupsCount )
5123  {}
5124 
5125  std::string name;
5126  std::size_t groupIndex;
5127  std::size_t groupsCounts;
5128  };
5129 
5130  struct AssertionStats {
5131  AssertionStats( AssertionResult const& _assertionResult,
5132  std::vector<MessageInfo> const& _infoMessages,
5133  Totals const& _totals )
5134  : assertionResult( _assertionResult ),
5135  infoMessages( _infoMessages ),
5136  totals( _totals )
5137  {
5138  if( assertionResult.hasMessage() ) {
5139  // Copy message into messages list.
5140  // !TBD This should have been done earlier, somewhere
5141  MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
5142  builder << assertionResult.getMessage();
5143  builder.m_info.message = builder.m_stream.str();
5144 
5145  infoMessages.push_back( builder.m_info );
5146  }
5147  }
5148  virtual ~AssertionStats();
5149 
5150 # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
5151  AssertionStats( AssertionStats const& ) = default;
5152  AssertionStats( AssertionStats && ) = default;
5153  AssertionStats& operator = ( AssertionStats const& ) = default;
5154  AssertionStats& operator = ( AssertionStats && ) = default;
5155 # endif
5156 
5157  AssertionResult assertionResult;
5158  std::vector<MessageInfo> infoMessages;
5159  Totals totals;
5160  };
5161 
5162  struct SectionStats {
5163  SectionStats( SectionInfo const& _sectionInfo,
5164  Counts const& _assertions,
5165  double _durationInSeconds,
5166  bool _missingAssertions )
5167  : sectionInfo( _sectionInfo ),
5168  assertions( _assertions ),
5169  durationInSeconds( _durationInSeconds ),
5170  missingAssertions( _missingAssertions )
5171  {}
5172  virtual ~SectionStats();
5173 # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
5174  SectionStats( SectionStats const& ) = default;
5175  SectionStats( SectionStats && ) = default;
5176  SectionStats& operator = ( SectionStats const& ) = default;
5177  SectionStats& operator = ( SectionStats && ) = default;
5178 # endif
5179 
5180  SectionInfo sectionInfo;
5181  Counts assertions;
5182  double durationInSeconds;
5183  bool missingAssertions;
5184  };
5185 
5186  struct TestCaseStats {
5187  TestCaseStats( TestCaseInfo const& _testInfo,
5188  Totals const& _totals,
5189  std::string const& _stdOut,
5190  std::string const& _stdErr,
5191  bool _aborting )
5192  : testInfo( _testInfo ),
5193  totals( _totals ),
5194  stdOut( _stdOut ),
5195  stdErr( _stdErr ),
5196  aborting( _aborting )
5197  {}
5198  virtual ~TestCaseStats();
5199 
5200 # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
5201  TestCaseStats( TestCaseStats const& ) = default;
5202  TestCaseStats( TestCaseStats && ) = default;
5203  TestCaseStats& operator = ( TestCaseStats const& ) = default;
5204  TestCaseStats& operator = ( TestCaseStats && ) = default;
5205 # endif
5206 
5207  TestCaseInfo testInfo;
5208  Totals totals;
5209  std::string stdOut;
5210  std::string stdErr;
5211  bool aborting;
5212  };
5213 
5214  struct TestGroupStats {
5215  TestGroupStats( GroupInfo const& _groupInfo,
5216  Totals const& _totals,
5217  bool _aborting )
5218  : groupInfo( _groupInfo ),
5219  totals( _totals ),
5220  aborting( _aborting )
5221  {}
5222  TestGroupStats( GroupInfo const& _groupInfo )
5223  : groupInfo( _groupInfo ),
5224  aborting( false )
5225  {}
5226  virtual ~TestGroupStats();
5227 
5228 # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
5229  TestGroupStats( TestGroupStats const& ) = default;
5230  TestGroupStats( TestGroupStats && ) = default;
5231  TestGroupStats& operator = ( TestGroupStats const& ) = default;
5232  TestGroupStats& operator = ( TestGroupStats && ) = default;
5233 # endif
5234 
5235  GroupInfo groupInfo;
5236  Totals totals;
5237  bool aborting;
5238  };
5239 
5240  struct TestRunStats {
5241  TestRunStats( TestRunInfo const& _runInfo,
5242  Totals const& _totals,
5243  bool _aborting )
5244  : runInfo( _runInfo ),
5245  totals( _totals ),
5246  aborting( _aborting )
5247  {}
5248  virtual ~TestRunStats();
5249 
5250 # ifndef CATCH_CONFIG_CPP11_GENERATED_METHODS
5251  TestRunStats( TestRunStats const& _other )
5252  : runInfo( _other.runInfo ),
5253  totals( _other.totals ),
5254  aborting( _other.aborting )
5255  {}
5256 # else
5257  TestRunStats( TestRunStats const& ) = default;
5258  TestRunStats( TestRunStats && ) = default;
5259  TestRunStats& operator = ( TestRunStats const& ) = default;
5260  TestRunStats& operator = ( TestRunStats && ) = default;
5261 # endif
5262 
5263  TestRunInfo runInfo;
5264  Totals totals;
5265  bool aborting;
5266  };
5267 
5268  class MultipleReporters;
5269 
5270  struct IStreamingReporter : IShared {
5271  virtual ~IStreamingReporter();
5272 
5273  // Implementing class must also provide the following static method:
5274  // static std::string getDescription();
5275 
5276  virtual ReporterPreferences getPreferences() const = 0;
5277 
5278  virtual void noMatchingTestCases( std::string const& spec ) = 0;
5279 
5280  virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
5281  virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0;
5282 
5283  virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
5284  virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
5285 
5286  virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
5287 
5288  // The return value indicates if the messages buffer should be cleared:
5289  virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
5290 
5291  virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
5292  virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
5293  virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
5294  virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
5295 
5296  virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
5297 
5298  virtual MultipleReporters* tryAsMulti() { return CATCH_NULL; }
5299  };
5300 
5301  struct IReporterFactory : IShared {
5302  virtual ~IReporterFactory();
5303  virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0;
5304  virtual std::string getDescription() const = 0;
5305  };
5306 
5307  struct IReporterRegistry {
5308  typedef std::map<std::string, Ptr<IReporterFactory> > FactoryMap;
5309  typedef std::vector<Ptr<IReporterFactory> > Listeners;
5310 
5311  virtual ~IReporterRegistry();
5312  virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const = 0;
5313  virtual FactoryMap const& getFactories() const = 0;
5314  virtual Listeners const& getListeners() const = 0;
5315  };
5316 
5317  Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter );
5318 
5319 }
5320 
5321 #include <limits>
5322 #include <algorithm>
5323 
5324 namespace Catch {
5325 
5326  inline std::size_t listTests( Config const& config ) {
5327 
5328  TestSpec testSpec = config.testSpec();
5329  if( config.testSpec().hasFilters() )
5330  Catch::cout() << "Matching test cases:\n";
5331  else {
5332  Catch::cout() << "All available test cases:\n";
5333  testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
5334  }
5335 
5336  std::size_t matchedTests = 0;
5337  TextAttributes nameAttr, tagsAttr;
5338  nameAttr.setInitialIndent( 2 ).setIndent( 4 );
5339  tagsAttr.setIndent( 6 );
5340 
5341  std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
5342  for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
5343  it != itEnd;
5344  ++it ) {
5345  matchedTests++;
5346  TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
5347  Colour::Code colour = testCaseInfo.isHidden()
5348  ? Colour::SecondaryText
5349  : Colour::None;
5350  Colour colourGuard( colour );
5351 
5352  Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl;
5353  if( !testCaseInfo.tags.empty() )
5354  Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl;
5355  }
5356 
5357  if( !config.testSpec().hasFilters() )
5358  Catch::cout() << pluralise( matchedTests, "test case" ) << "\n" << std::endl;
5359  else
5360  Catch::cout() << pluralise( matchedTests, "matching test case" ) << "\n" << std::endl;
5361  return matchedTests;
5362  }
5363 
5364  inline std::size_t listTestsNamesOnly( Config const& config ) {
5365  TestSpec testSpec = config.testSpec();
5366  if( !config.testSpec().hasFilters() )
5367  testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
5368  std::size_t matchedTests = 0;
5369  std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
5370  for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
5371  it != itEnd;
5372  ++it ) {
5373  matchedTests++;
5374  TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
5375  if( startsWith( testCaseInfo.name, "#" ) )
5376  Catch::cout() << "\"" << testCaseInfo.name << "\"" << std::endl;
5377  else
5378  Catch::cout() << testCaseInfo.name << std::endl;
5379  }
5380  return matchedTests;
5381  }
5382 
5383  struct TagInfo {
5384  TagInfo() : count ( 0 ) {}
5385  void add( std::string const& spelling ) {
5386  ++count;
5387  spellings.insert( spelling );
5388  }
5389  std::string all() const {
5390  std::string out;
5391  for( std::set<std::string>::const_iterator it = spellings.begin(), itEnd = spellings.end();
5392  it != itEnd;
5393  ++it )
5394  out += "[" + *it + "]";
5395  return out;
5396  }
5397  std::set<std::string> spellings;
5398  std::size_t count;
5399  };
5400 
5401  inline std::size_t listTags( Config const& config ) {
5402  TestSpec testSpec = config.testSpec();
5403  if( config.testSpec().hasFilters() )
5404  Catch::cout() << "Tags for matching test cases:\n";
5405  else {
5406  Catch::cout() << "All available tags:\n";
5407  testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
5408  }
5409 
5410  std::map<std::string, TagInfo> tagCounts;
5411 
5412  std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
5413  for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
5414  it != itEnd;
5415  ++it ) {
5416  for( std::set<std::string>::const_iterator tagIt = it->getTestCaseInfo().tags.begin(),
5417  tagItEnd = it->getTestCaseInfo().tags.end();
5418  tagIt != tagItEnd;
5419  ++tagIt ) {
5420  std::string tagName = *tagIt;
5421  std::string lcaseTagName = toLower( tagName );
5422  std::map<std::string, TagInfo>::iterator countIt = tagCounts.find( lcaseTagName );
5423  if( countIt == tagCounts.end() )
5424  countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
5425  countIt->second.add( tagName );
5426  }
5427  }
5428 
5429  for( std::map<std::string, TagInfo>::const_iterator countIt = tagCounts.begin(),
5430  countItEnd = tagCounts.end();
5431  countIt != countItEnd;
5432  ++countIt ) {
5433  std::ostringstream oss;
5434  oss << " " << std::setw(2) << countIt->second.count << " ";
5435  Text wrapper( countIt->second.all(), TextAttributes()
5436  .setInitialIndent( 0 )
5437  .setIndent( oss.str().size() )
5438  .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );
5439  Catch::cout() << oss.str() << wrapper << "\n";
5440  }
5441  Catch::cout() << pluralise( tagCounts.size(), "tag" ) << "\n" << std::endl;
5442  return tagCounts.size();
5443  }
5444 
5445  inline std::size_t listReporters( Config const& /*config*/ ) {
5446  Catch::cout() << "Available reporters:\n";
5447  IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
5448  IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it;
5449  std::size_t maxNameLen = 0;
5450  for(it = itBegin; it != itEnd; ++it )
5451  maxNameLen = (std::max)( maxNameLen, it->first.size() );
5452 
5453  for(it = itBegin; it != itEnd; ++it ) {
5454  Text wrapper( it->second->getDescription(), TextAttributes()
5455  .setInitialIndent( 0 )
5456  .setIndent( 7+maxNameLen )
5457  .setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) );
5458  Catch::cout() << " "
5459  << it->first
5460  << ":"
5461  << std::string( maxNameLen - it->first.size() + 2, ' ' )
5462  << wrapper << "\n";
5463  }
5464  Catch::cout() << std::endl;
5465  return factories.size();
5466  }
5467 
5468  inline Option<std::size_t> list( Config const& config ) {
5469  Option<std::size_t> listedCount;
5470  if( config.listTests() )
5471  listedCount = listedCount.valueOr(0) + listTests( config );
5472  if( config.listTestNamesOnly() )
5473  listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config );
5474  if( config.listTags() )
5475  listedCount = listedCount.valueOr(0) + listTags( config );
5476  if( config.listReporters() )
5477  listedCount = listedCount.valueOr(0) + listReporters( config );
5478  return listedCount;
5479  }
5480 
5481 } // end namespace Catch
5482 
5483 // #included from: internal/catch_run_context.hpp
5484 #define TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED
5485 
5486 // #included from: catch_test_case_tracker.hpp
5487 #define TWOBLUECUBES_CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
5488 
5489 #include <map>
5490 #include <string>
5491 #include <assert.h>
5492 #include <vector>
5493 
5494 namespace Catch {
5495 namespace TestCaseTracking {
5496 
5497  struct ITracker : SharedImpl<> {
5498  virtual ~ITracker();
5499 
5500  // static queries
5501  virtual std::string name() const = 0;
5502 
5503  // dynamic queries
5504  virtual bool isComplete() const = 0; // Successfully completed or failed
5505  virtual bool isSuccessfullyCompleted() const = 0;
5506  virtual bool isOpen() const = 0; // Started but not complete
5507  virtual bool hasChildren() const = 0;
5508 
5509  virtual ITracker& parent() = 0;
5510 
5511  // actions
5512  virtual void close() = 0; // Successfully complete
5513  virtual void fail() = 0;
5514  virtual void markAsNeedingAnotherRun() = 0;
5515 
5516  virtual void addChild( Ptr<ITracker> const& child ) = 0;
5517  virtual ITracker* findChild( std::string const& name ) = 0;
5518  virtual void openChild() = 0;
5519 
5520  // Debug/ checking
5521  virtual bool isSectionTracker() const = 0;
5522  virtual bool isIndexTracker() const = 0;
5523  };
5524 
5525  class TrackerContext {
5526 
5527  enum RunState {
5528  NotStarted,
5529  Executing,
5530  CompletedCycle
5531  };
5532 
5533  Ptr<ITracker> m_rootTracker;
5534  ITracker* m_currentTracker;
5535  RunState m_runState;
5536 
5537  public:
5538 
5539  static TrackerContext& instance() {
5540  static TrackerContext s_instance;
5541  return s_instance;
5542  }
5543 
5544  TrackerContext()
5545  : m_currentTracker( CATCH_NULL ),
5546  m_runState( NotStarted )
5547  {}
5548 
5549  ITracker& startRun();
5550 
5551  void endRun() {
5552  m_rootTracker.reset();
5553  m_currentTracker = CATCH_NULL;
5554  m_runState = NotStarted;
5555  }
5556 
5557  void startCycle() {
5558  m_currentTracker = m_rootTracker.get();
5559  m_runState = Executing;
5560  }
5561  void completeCycle() {
5562  m_runState = CompletedCycle;
5563  }
5564 
5565  bool completedCycle() const {
5566  return m_runState == CompletedCycle;
5567  }
5568  ITracker& currentTracker() {
5569  return *m_currentTracker;
5570  }
5571  void setCurrentTracker( ITracker* tracker ) {
5572  m_currentTracker = tracker;
5573  }
5574  };
5575 
5576  class TrackerBase : public ITracker {
5577  protected:
5578  enum CycleState {
5579  NotStarted,
5580  Executing,
5581  ExecutingChildren,
5582  NeedsAnotherRun,
5583  CompletedSuccessfully,
5584  Failed
5585  };
5586  class TrackerHasName {
5587  std::string m_name;
5588  public:
5589  TrackerHasName( std::string const& name ) : m_name( name ) {}
5590  bool operator ()( Ptr<ITracker> const& tracker ) {
5591  return tracker->name() == m_name;
5592  }
5593  };
5594  typedef std::vector<Ptr<ITracker> > Children;
5595  std::string m_name;
5596  TrackerContext& m_ctx;
5597  ITracker* m_parent;
5598  Children m_children;
5599  CycleState m_runState;
5600  public:
5601  TrackerBase( std::string const& name, TrackerContext& ctx, ITracker* parent )
5602  : m_name( name ),
5603  m_ctx( ctx ),
5604  m_parent( parent ),
5605  m_runState( NotStarted )
5606  {}
5607  virtual ~TrackerBase();
5608 
5609  virtual std::string name() const CATCH_OVERRIDE {
5610  return m_name;
5611  }
5612  virtual bool isComplete() const CATCH_OVERRIDE {
5613  return m_runState == CompletedSuccessfully || m_runState == Failed;
5614  }
5615  virtual bool isSuccessfullyCompleted() const CATCH_OVERRIDE {
5616  return m_runState == CompletedSuccessfully;
5617  }
5618  virtual bool isOpen() const CATCH_OVERRIDE {
5619  return m_runState != NotStarted && !isComplete();
5620  }
5621  virtual bool hasChildren() const CATCH_OVERRIDE {
5622  return !m_children.empty();
5623  }
5624 
5625  virtual void addChild( Ptr<ITracker> const& child ) CATCH_OVERRIDE {
5626  m_children.push_back( child );
5627  }
5628 
5629  virtual ITracker* findChild( std::string const& name ) CATCH_OVERRIDE {
5630  Children::const_iterator it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( name ) );
5631  return( it != m_children.end() )
5632  ? it->get()
5633  : CATCH_NULL;
5634  }
5635  virtual ITracker& parent() CATCH_OVERRIDE {
5636  assert( m_parent ); // Should always be non-null except for root
5637  return *m_parent;
5638  }
5639 
5640  virtual void openChild() CATCH_OVERRIDE {
5641  if( m_runState != ExecutingChildren ) {
5642  m_runState = ExecutingChildren;
5643  if( m_parent )
5644  m_parent->openChild();
5645  }
5646  }
5647 
5648  virtual bool isSectionTracker() const CATCH_OVERRIDE { return false; }
5649  virtual bool isIndexTracker() const CATCH_OVERRIDE { return false; }
5650 
5651  void open() {
5652  m_runState = Executing;
5653  moveToThis();
5654  if( m_parent )
5655  m_parent->openChild();
5656  }
5657 
5658  virtual void close() CATCH_OVERRIDE {
5659 
5660  // Close any still open children (e.g. generators)
5661  while( &m_ctx.currentTracker() != this )
5662  m_ctx.currentTracker().close();
5663 
5664  switch( m_runState ) {
5665  case NotStarted:
5666  case CompletedSuccessfully:
5667  case Failed:
5668  throw std::logic_error( "Illogical state" );
5669 
5670  case NeedsAnotherRun:
5671  break;;
5672 
5673  case Executing:
5674  m_runState = CompletedSuccessfully;
5675  break;
5676  case ExecutingChildren:
5677  if( m_children.empty() || m_children.back()->isComplete() )
5678  m_runState = CompletedSuccessfully;
5679  break;
5680 
5681  default:
5682  throw std::logic_error( "Unexpected state" );
5683  }
5684  moveToParent();
5685  m_ctx.completeCycle();
5686  }
5687  virtual void fail() CATCH_OVERRIDE {
5688  m_runState = Failed;
5689  if( m_parent )
5690  m_parent->markAsNeedingAnotherRun();
5691  moveToParent();
5692  m_ctx.completeCycle();
5693  }
5694  virtual void markAsNeedingAnotherRun() CATCH_OVERRIDE {
5695  m_runState = NeedsAnotherRun;
5696  }
5697  private:
5698  void moveToParent() {
5699  assert( m_parent );
5700  m_ctx.setCurrentTracker( m_parent );
5701  }
5702  void moveToThis() {
5703  m_ctx.setCurrentTracker( this );
5704  }
5705  };
5706 
5707  class SectionTracker : public TrackerBase {
5708  public:
5709  SectionTracker( std::string const& name, TrackerContext& ctx, ITracker* parent )
5710  : TrackerBase( name, ctx, parent )
5711  {}
5712  virtual ~SectionTracker();
5713 
5714  virtual bool isSectionTracker() const CATCH_OVERRIDE { return true; }
5715 
5716  static SectionTracker& acquire( TrackerContext& ctx, std::string const& name ) {
5717  SectionTracker* section = CATCH_NULL;
5718 
5719  ITracker& currentTracker = ctx.currentTracker();
5720  if( ITracker* childTracker = currentTracker.findChild( name ) ) {
5721  assert( childTracker );
5722  assert( childTracker->isSectionTracker() );
5723  section = static_cast<SectionTracker*>( childTracker );
5724  }
5725  else {
5726  section = new SectionTracker( name, ctx, &currentTracker );
5727  currentTracker.addChild( section );
5728  }
5729  if( !ctx.completedCycle() && !section->isComplete() ) {
5730 
5731  section->open();
5732  }
5733  return *section;
5734  }
5735  };
5736 
5737  class IndexTracker : public TrackerBase {
5738  int m_size;
5739  int m_index;
5740  public:
5741  IndexTracker( std::string const& name, TrackerContext& ctx, ITracker* parent, int size )
5742  : TrackerBase( name, ctx, parent ),
5743  m_size( size ),
5744  m_index( -1 )
5745  {}
5746  virtual ~IndexTracker();
5747 
5748  virtual bool isIndexTracker() const CATCH_OVERRIDE { return true; }
5749 
5750  static IndexTracker& acquire( TrackerContext& ctx, std::string const& name, int size ) {
5751  IndexTracker* tracker = CATCH_NULL;
5752 
5753  ITracker& currentTracker = ctx.currentTracker();
5754  if( ITracker* childTracker = currentTracker.findChild( name ) ) {
5755  assert( childTracker );
5756  assert( childTracker->isIndexTracker() );
5757  tracker = static_cast<IndexTracker*>( childTracker );
5758  }
5759  else {
5760  tracker = new IndexTracker( name, ctx, &currentTracker, size );
5761  currentTracker.addChild( tracker );
5762  }
5763 
5764  if( !ctx.completedCycle() && !tracker->isComplete() ) {
5765  if( tracker->m_runState != ExecutingChildren && tracker->m_runState != NeedsAnotherRun )
5766  tracker->moveNext();
5767  tracker->open();
5768  }
5769 
5770  return *tracker;
5771  }
5772 
5773  int index() const { return m_index; }
5774 
5775  void moveNext() {
5776  m_index++;
5777  m_children.clear();
5778  }
5779 
5780  virtual void close() CATCH_OVERRIDE {
5781  TrackerBase::close();
5782  if( m_runState == CompletedSuccessfully && m_index < m_size-1 )
5783  m_runState = Executing;
5784  }
5785  };
5786 
5787  inline ITracker& TrackerContext::startRun() {
5788  m_rootTracker = new SectionTracker( "{root}", *this, CATCH_NULL );
5789  m_currentTracker = CATCH_NULL;
5790  m_runState = Executing;
5791  return *m_rootTracker;
5792  }
5793 
5794 } // namespace TestCaseTracking
5795 
5796 using TestCaseTracking::ITracker;
5797 using TestCaseTracking::TrackerContext;
5798 using TestCaseTracking::SectionTracker;
5799 using TestCaseTracking::IndexTracker;
5800 
5801 } // namespace Catch
5802 
5803 // #included from: catch_fatal_condition.hpp
5804 #define TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
5805 
5806 namespace Catch {
5807 
5808  // Report the error condition then exit the process
5809  inline void fatal( std::string const& message, int exitCode ) {
5810  IContext& context = Catch::getCurrentContext();
5811  IResultCapture* resultCapture = context.getResultCapture();
5812  resultCapture->handleFatalErrorCondition( message );
5813 
5814  if( Catch::alwaysTrue() ) // avoids "no return" warnings
5815  exit( exitCode );
5816  }
5817 
5818 } // namespace Catch
5819 
5820 #if defined ( CATCH_PLATFORM_WINDOWS )
5821 
5822 namespace Catch {
5823 
5824  struct FatalConditionHandler {
5825  void reset() {}
5826  };
5827 
5828 } // namespace Catch
5829 
5830 #else // Not Windows - assumed to be POSIX compatible
5831 
5832 #include <signal.h>
5833 
5834 namespace Catch {
5835 
5836  struct SignalDefs { int id; const char* name; };
5837  extern SignalDefs signalDefs[];
5838  SignalDefs signalDefs[] = {
5839  { SIGINT, "SIGINT - Terminal interrupt signal" },
5840  { SIGILL, "SIGILL - Illegal instruction signal" },
5841  { SIGFPE, "SIGFPE - Floating point error signal" },
5842  { SIGSEGV, "SIGSEGV - Segmentation violation signal" },
5843  { SIGTERM, "SIGTERM - Termination request signal" },
5844  { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" }
5845  };
5846 
5847  struct FatalConditionHandler {
5848 
5849  static void handleSignal( int sig ) {
5850  for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i )
5851  if( sig == signalDefs[i].id )
5852  fatal( signalDefs[i].name, -sig );
5853  fatal( "<unknown signal>", -sig );
5854  }
5855 
5856  FatalConditionHandler() : m_isSet( true ) {
5857  for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i )
5858  signal( signalDefs[i].id, handleSignal );
5859  }
5860  ~FatalConditionHandler() {
5861  reset();
5862  }
5863  void reset() {
5864  if( m_isSet ) {
5865  for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i )
5866  signal( signalDefs[i].id, SIG_DFL );
5867  m_isSet = false;
5868  }
5869  }
5870 
5871  bool m_isSet;
5872  };
5873 
5874 } // namespace Catch
5875 
5876 #endif // not Windows
5877 
5878 #include <set>
5879 #include <string>
5880 
5881 namespace Catch {
5882 
5883  class StreamRedirect {
5884 
5885  public:
5886  StreamRedirect( std::ostream& stream, std::string& targetString )
5887  : m_stream( stream ),
5888  m_prevBuf( stream.rdbuf() ),
5889  m_targetString( targetString )
5890  {
5891  stream.rdbuf( m_oss.rdbuf() );
5892  }
5893 
5894  ~StreamRedirect() {
5895  m_targetString += m_oss.str();
5896  m_stream.rdbuf( m_prevBuf );
5897  }
5898 
5899  private:
5900  std::ostream& m_stream;
5901  std::streambuf* m_prevBuf;
5902  std::ostringstream m_oss;
5903  std::string& m_targetString;
5904  };
5905 
5907 
5908  class RunContext : public IResultCapture, public IRunner {
5909 
5910  RunContext( RunContext const& );
5911  void operator =( RunContext const& );
5912 
5913  public:
5914 
5915  explicit RunContext( Ptr<IConfig const> const& _config, Ptr<IStreamingReporter> const& reporter )
5916  : m_runInfo( _config->name() ),
5917  m_context( getCurrentMutableContext() ),
5918  m_activeTestCase( CATCH_NULL ),
5919  m_config( _config ),
5920  m_reporter( reporter )
5921  {
5922  m_context.setRunner( this );
5923  m_context.setConfig( m_config );
5924  m_context.setResultCapture( this );
5925  m_reporter->testRunStarting( m_runInfo );
5926  }
5927 
5928  virtual ~RunContext() {
5929  m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) );
5930  }
5931 
5932  void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) {
5933  m_reporter->testGroupStarting( GroupInfo( testSpec, groupIndex, groupsCount ) );
5934  }
5935  void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ) {
5936  m_reporter->testGroupEnded( TestGroupStats( GroupInfo( testSpec, groupIndex, groupsCount ), totals, aborting() ) );
5937  }
5938 
5939  Totals runTest( TestCase const& testCase ) {
5940  Totals prevTotals = m_totals;
5941 
5942  std::string redirectedCout;
5943  std::string redirectedCerr;
5944 
5945  TestCaseInfo testInfo = testCase.getTestCaseInfo();
5946 
5947  m_reporter->testCaseStarting( testInfo );
5948 
5949  m_activeTestCase = &testCase;
5950 
5951  do {
5952  m_trackerContext.startRun();
5953  do {
5954  m_trackerContext.startCycle();
5955  m_testCaseTracker = &SectionTracker::acquire( m_trackerContext, testInfo.name );
5956  runCurrentTest( redirectedCout, redirectedCerr );
5957  }
5958  while( !m_testCaseTracker->isSuccessfullyCompleted() && !aborting() );
5959  }
5960  // !TBD: deprecated - this will be replaced by indexed trackers
5961  while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() );
5962 
5963  Totals deltaTotals = m_totals.delta( prevTotals );
5964  if( testInfo.expectedToFail() && deltaTotals.testCases.passed > 0 ) {
5965  deltaTotals.assertions.failed++;
5966  deltaTotals.testCases.passed--;
5967  deltaTotals.testCases.failed++;
5968  }
5969  m_totals.testCases += deltaTotals.testCases;
5970  m_reporter->testCaseEnded( TestCaseStats( testInfo,
5971  deltaTotals,
5972  redirectedCout,
5973  redirectedCerr,
5974  aborting() ) );
5975 
5976  m_activeTestCase = CATCH_NULL;
5977  m_testCaseTracker = CATCH_NULL;
5978 
5979  return deltaTotals;
5980  }
5981 
5982  Ptr<IConfig const> config() const {
5983  return m_config;
5984  }
5985 
5986  private: // IResultCapture
5987 
5988  virtual void assertionEnded( AssertionResult const& result ) {
5989  if( result.getResultType() == ResultWas::Ok ) {
5990  m_totals.assertions.passed++;
5991  }
5992  else if( !result.isOk() ) {
5993  m_totals.assertions.failed++;
5994  }
5995 
5996  if( m_reporter->assertionEnded( AssertionStats( result, m_messages, m_totals ) ) )
5997  m_messages.clear();
5998 
5999  // Reset working state
6000  m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition );
6001  m_lastResult = result;
6002  }
6003 
6004  virtual bool sectionStarted (
6005  SectionInfo const& sectionInfo,
6006  Counts& assertions
6007  )
6008  {
6009  std::ostringstream oss;
6010  oss << sectionInfo.name << "@" << sectionInfo.lineInfo;
6011 
6012  ITracker& sectionTracker = SectionTracker::acquire( m_trackerContext, oss.str() );
6013  if( !sectionTracker.isOpen() )
6014  return false;
6015  m_activeSections.push_back( &sectionTracker );
6016 
6017  m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
6018 
6019  m_reporter->sectionStarting( sectionInfo );
6020 
6021  assertions = m_totals.assertions;
6022 
6023  return true;
6024  }
6025  bool testForMissingAssertions( Counts& assertions ) {
6026  if( assertions.total() != 0 )
6027  return false;
6028  if( !m_config->warnAboutMissingAssertions() )
6029  return false;
6030  if( m_trackerContext.currentTracker().hasChildren() )
6031  return false;
6032  m_totals.assertions.failed++;
6033  assertions.failed++;
6034  return true;
6035  }
6036 
6037  virtual void sectionEnded( SectionEndInfo const& endInfo ) {
6038  Counts assertions = m_totals.assertions - endInfo.prevAssertions;
6039  bool missingAssertions = testForMissingAssertions( assertions );
6040 
6041  if( !m_activeSections.empty() ) {
6042  m_activeSections.back()->close();
6043  m_activeSections.pop_back();
6044  }
6045 
6046  m_reporter->sectionEnded( SectionStats( endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions ) );
6047  m_messages.clear();
6048  }
6049 
6050  virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) {
6051  if( m_unfinishedSections.empty() )
6052  m_activeSections.back()->fail();
6053  else
6054  m_activeSections.back()->close();
6055  m_activeSections.pop_back();
6056 
6057  m_unfinishedSections.push_back( endInfo );
6058  }
6059 
6060  virtual void pushScopedMessage( MessageInfo const& message ) {
6061  m_messages.push_back( message );
6062  }
6063 
6064  virtual void popScopedMessage( MessageInfo const& message ) {
6065  m_messages.erase( std::remove( m_messages.begin(), m_messages.end(), message ), m_messages.end() );
6066  }
6067 
6068  virtual std::string getCurrentTestName() const {
6069  return m_activeTestCase
6070  ? m_activeTestCase->getTestCaseInfo().name
6071  : "";
6072  }
6073 
6074  virtual const AssertionResult* getLastResult() const {
6075  return &m_lastResult;
6076  }
6077 
6078  virtual void handleFatalErrorCondition( std::string const& message ) {
6079  ResultBuilder resultBuilder = makeUnexpectedResultBuilder();
6080  resultBuilder.setResultType( ResultWas::FatalErrorCondition );
6081  resultBuilder << message;
6082  resultBuilder.captureExpression();
6083 
6084  handleUnfinishedSections();
6085 
6086  // Recreate section for test case (as we will lose the one that was in scope)
6087  TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
6088  SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description );
6089 
6090  Counts assertions;
6091  assertions.failed = 1;
6092  SectionStats testCaseSectionStats( testCaseSection, assertions, 0, false );
6093  m_reporter->sectionEnded( testCaseSectionStats );
6094 
6095  TestCaseInfo testInfo = m_activeTestCase->getTestCaseInfo();
6096 
6097  Totals deltaTotals;
6098  deltaTotals.testCases.failed = 1;
6099  m_reporter->testCaseEnded( TestCaseStats( testInfo,
6100  deltaTotals,
6101  "",
6102  "",
6103  false ) );
6104  m_totals.testCases.failed++;
6105  testGroupEnded( "", m_totals, 1, 1 );
6106  m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, false ) );
6107  }
6108 
6109  public:
6110  // !TBD We need to do this another way!
6111  bool aborting() const {
6112  return m_totals.assertions.failed == static_cast<std::size_t>( m_config->abortAfter() );
6113  }
6114 
6115  private:
6116 
6117  void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
6118  TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
6119  SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description );
6120  m_reporter->sectionStarting( testCaseSection );
6121  Counts prevAssertions = m_totals.assertions;
6122  double duration = 0;
6123  try {
6124  m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal );
6125 
6126  seedRng( *m_config );
6127 
6128  Timer timer;
6129  timer.start();
6130  if( m_reporter->getPreferences().shouldRedirectStdOut ) {
6131  StreamRedirect coutRedir( Catch::cout(), redirectedCout );
6132  StreamRedirect cerrRedir( Catch::cerr(), redirectedCerr );
6133  invokeActiveTestCase();
6134  }
6135  else {
6136  invokeActiveTestCase();
6137  }
6138  duration = timer.getElapsedSeconds();
6139  }
6140  catch( TestFailureException& ) {
6141  // This just means the test was aborted due to failure
6142  }
6143  catch(...) {
6144  makeUnexpectedResultBuilder().useActiveException();
6145  }
6146  m_testCaseTracker->close();
6147  handleUnfinishedSections();
6148  m_messages.clear();
6149 
6150  Counts assertions = m_totals.assertions - prevAssertions;
6151  bool missingAssertions = testForMissingAssertions( assertions );
6152 
6153  if( testCaseInfo.okToFail() ) {
6154  std::swap( assertions.failedButOk, assertions.failed );
6155  m_totals.assertions.failed -= assertions.failedButOk;
6156  m_totals.assertions.failedButOk += assertions.failedButOk;
6157  }
6158 
6159  SectionStats testCaseSectionStats( testCaseSection, assertions, duration, missingAssertions );
6160  m_reporter->sectionEnded( testCaseSectionStats );
6161  }
6162 
6163  void invokeActiveTestCase() {
6164  FatalConditionHandler fatalConditionHandler; // Handle signals
6165  m_activeTestCase->invoke();
6166  fatalConditionHandler.reset();
6167  }
6168 
6169  private:
6170 
6171  ResultBuilder makeUnexpectedResultBuilder() const {
6172  return ResultBuilder( m_lastAssertionInfo.macroName.c_str(),
6173  m_lastAssertionInfo.lineInfo,
6174  m_lastAssertionInfo.capturedExpression.c_str(),
6175  m_lastAssertionInfo.resultDisposition );
6176  }
6177 
6178  void handleUnfinishedSections() {
6179  // If sections ended prematurely due to an exception we stored their
6180  // infos here so we can tear them down outside the unwind process.
6181  for( std::vector<SectionEndInfo>::const_reverse_iterator it = m_unfinishedSections.rbegin(),
6182  itEnd = m_unfinishedSections.rend();
6183  it != itEnd;
6184  ++it )
6185  sectionEnded( *it );
6186  m_unfinishedSections.clear();
6187  }
6188 
6189  TestRunInfo m_runInfo;
6190  IMutableContext& m_context;
6191  TestCase const* m_activeTestCase;
6192  ITracker* m_testCaseTracker;
6193  ITracker* m_currentSectionTracker;
6194  AssertionResult m_lastResult;
6195 
6196  Ptr<IConfig const> m_config;
6197  Totals m_totals;
6198  Ptr<IStreamingReporter> m_reporter;
6199  std::vector<MessageInfo> m_messages;
6200  AssertionInfo m_lastAssertionInfo;
6201  std::vector<SectionEndInfo> m_unfinishedSections;
6202  std::vector<ITracker*> m_activeSections;
6203  TrackerContext m_trackerContext;
6204  };
6205 
6206  IResultCapture& getResultCapture() {
6207  if( IResultCapture* capture = getCurrentContext().getResultCapture() )
6208  return *capture;
6209  else
6210  throw std::logic_error( "No result capture instance" );
6211  }
6212 
6213 } // end namespace Catch
6214 
6215 // #included from: internal/catch_version.h
6216 #define TWOBLUECUBES_CATCH_VERSION_H_INCLUDED
6217 
6218 namespace Catch {
6219 
6220  // Versioning information
6221  struct Version {
6222  Version( unsigned int _majorVersion,
6223  unsigned int _minorVersion,
6224  unsigned int _patchNumber,
6225  std::string const& _branchName,
6226  unsigned int _buildNumber );
6227 
6228  unsigned int const majorVersion;
6229  unsigned int const minorVersion;
6230  unsigned int const patchNumber;
6231 
6232  // buildNumber is only used if branchName is not null
6233  std::string const branchName;
6234  unsigned int const buildNumber;
6235 
6236  friend std::ostream& operator << ( std::ostream& os, Version const& version );
6237 
6238  private:
6239  void operator=( Version const& );
6240  };
6241 
6242  extern Version libraryVersion;
6243 }
6244 
6245 #include <fstream>
6246 #include <stdlib.h>
6247 #include <limits>
6248 
6249 namespace Catch {
6250 
6251  Ptr<IStreamingReporter> createReporter( std::string const& reporterName, Ptr<Config> const& config ) {
6252  Ptr<IStreamingReporter> reporter = getRegistryHub().getReporterRegistry().create( reporterName, config.get() );
6253  if( !reporter ) {
6254  std::ostringstream oss;
6255  oss << "No reporter registered with name: '" << reporterName << "'";
6256  throw std::domain_error( oss.str() );
6257  }
6258  return reporter;
6259  }
6260 
6261  Ptr<IStreamingReporter> makeReporter( Ptr<Config> const& config ) {
6262  std::vector<std::string> reporters = config->getReporterNames();
6263  if( reporters.empty() )
6264  reporters.push_back( "console" );
6265 
6266  Ptr<IStreamingReporter> reporter;
6267  for( std::vector<std::string>::const_iterator it = reporters.begin(), itEnd = reporters.end();
6268  it != itEnd;
6269  ++it )
6270  reporter = addReporter( reporter, createReporter( *it, config ) );
6271  return reporter;
6272  }
6273  Ptr<IStreamingReporter> addListeners( Ptr<IConfig const> const& config, Ptr<IStreamingReporter> reporters ) {
6274  IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners();
6275  for( IReporterRegistry::Listeners::const_iterator it = listeners.begin(), itEnd = listeners.end();
6276  it != itEnd;
6277  ++it )
6278  reporters = addReporter(reporters, (*it)->create( ReporterConfig( config ) ) );
6279  return reporters;
6280  }
6281 
6282  Totals runTests( Ptr<Config> const& config ) {
6283 
6284  Ptr<IConfig const> iconfig = config.get();
6285 
6286  Ptr<IStreamingReporter> reporter = makeReporter( config );
6287  reporter = addListeners( iconfig, reporter );
6288 
6289  RunContext context( iconfig, reporter );
6290 
6291  Totals totals;
6292 
6293  context.testGroupStarting( config->name(), 1, 1 );
6294 
6295  TestSpec testSpec = config->testSpec();
6296  if( !testSpec.hasFilters() )
6297  testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests
6298 
6299  std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *iconfig );
6300  for( std::vector<TestCase>::const_iterator it = allTestCases.begin(), itEnd = allTestCases.end();
6301  it != itEnd;
6302  ++it ) {
6303  if( !context.aborting() && matchTest( *it, testSpec, *iconfig ) )
6304  totals += context.runTest( *it );
6305  else
6306  reporter->skipTest( *it );
6307  }
6308 
6309  context.testGroupEnded( iconfig->name(), totals, 1, 1 );
6310  return totals;
6311  }
6312 
6313  void applyFilenamesAsTags( IConfig const& config ) {
6314  std::vector<TestCase> const& tests = getAllTestCasesSorted( config );
6315  for(std::size_t i = 0; i < tests.size(); ++i ) {
6316  TestCase& test = const_cast<TestCase&>( tests[i] );
6317  std::set<std::string> tags = test.tags;
6318 
6319  std::string filename = test.lineInfo.file;
6320  std::string::size_type lastSlash = filename.find_last_of( "\\/" );
6321  if( lastSlash != std::string::npos )
6322  filename = filename.substr( lastSlash+1 );
6323 
6324  std::string::size_type lastDot = filename.find_last_of( "." );
6325  if( lastDot != std::string::npos )
6326  filename = filename.substr( 0, lastDot );
6327 
6328  tags.insert( "#" + filename );
6329  setTags( test, tags );
6330  }
6331  }
6332 
6333  class Session : NonCopyable {
6334  static bool alreadyInstantiated;
6335 
6336  public:
6337 
6338  struct OnUnusedOptions { enum DoWhat { Ignore, Fail }; };
6339 
6340  Session()
6341  : m_cli( makeCommandLineParser() ) {
6342  if( alreadyInstantiated ) {
6343  std::string msg = "Only one instance of Catch::Session can ever be used";
6344  Catch::cerr() << msg << std::endl;
6345  throw std::logic_error( msg );
6346  }
6347  alreadyInstantiated = true;
6348  }
6349  ~Session() {
6350  Catch::cleanUp();
6351  }
6352 
6353  void showHelp( std::string const& processName ) {
6354  Catch::cout() << "\nCatch v" << libraryVersion << "\n";
6355 
6356  m_cli.usage( Catch::cout(), processName );
6357  Catch::cout() << "For more detail usage please see the project docs\n" << std::endl;
6358  }
6359 
6360  int applyCommandLine( int argc, char const* const* const argv, OnUnusedOptions::DoWhat unusedOptionBehaviour = OnUnusedOptions::Fail ) {
6361  try {
6362  m_cli.setThrowOnUnrecognisedTokens( unusedOptionBehaviour == OnUnusedOptions::Fail );
6363  m_unusedTokens = m_cli.parseInto( Clara::argsToVector( argc, argv ), m_configData );
6364  if( m_configData.showHelp )
6365  showHelp( m_configData.processName );
6366  m_config.reset();
6367  }
6368  catch( std::exception& ex ) {
6369  {
6370  Colour colourGuard( Colour::Red );
6371  Catch::cerr()
6372  << "\nError(s) in input:\n"
6373  << Text( ex.what(), TextAttributes().setIndent(2) )
6374  << "\n\n";
6375  }
6376  m_cli.usage( Catch::cout(), m_configData.processName );
6377  return (std::numeric_limits<int>::max)();
6378  }
6379  return 0;
6380  }
6381 
6382  void useConfigData( ConfigData const& _configData ) {
6383  m_configData = _configData;
6384  m_config.reset();
6385  }
6386 
6387  int run( int argc, char const* const* const argv ) {
6388 
6389  int returnCode = applyCommandLine( argc, argv );
6390  if( returnCode == 0 )
6391  returnCode = run();
6392  return returnCode;
6393  }
6394 
6395  int run() {
6396  if( m_configData.showHelp )
6397  return 0;
6398 
6399  try
6400  {
6401  config(); // Force config to be constructed
6402 
6403  seedRng( *m_config );
6404 
6405  if( m_configData.filenamesAsTags )
6406  applyFilenamesAsTags( *m_config );
6407 
6408  // Handle list request
6409  if( Option<std::size_t> listed = list( config() ) )
6410  return static_cast<int>( *listed );
6411 
6412  return static_cast<int>( runTests( m_config ).assertions.failed );
6413  }
6414  catch( std::exception& ex ) {
6415  Catch::cerr() << ex.what() << std::endl;
6416  return (std::numeric_limits<int>::max)();
6417  }
6418  }
6419 
6420  Clara::CommandLine<ConfigData> const& cli() const {
6421  return m_cli;
6422  }
6423  std::vector<Clara::Parser::Token> const& unusedTokens() const {
6424  return m_unusedTokens;
6425  }
6426  ConfigData& configData() {
6427  return m_configData;
6428  }
6429  Config& config() {
6430  if( !m_config )
6431  m_config = new Config( m_configData );
6432  return *m_config;
6433  }
6434  private:
6435  Clara::CommandLine<ConfigData> m_cli;
6436  std::vector<Clara::Parser::Token> m_unusedTokens;
6437  ConfigData m_configData;
6438  Ptr<Config> m_config;
6439  };
6440 
6441  bool Session::alreadyInstantiated = false;
6442 
6443 } // end namespace Catch
6444 
6445 // #included from: catch_registry_hub.hpp
6446 #define TWOBLUECUBES_CATCH_REGISTRY_HUB_HPP_INCLUDED
6447 
6448 // #included from: catch_test_case_registry_impl.hpp
6449 #define TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
6450 
6451 #include <vector>
6452 #include <set>
6453 #include <sstream>
6454 #include <iostream>
6455 #include <algorithm>
6456 
6457 #ifdef CATCH_CPP14_OR_GREATER
6458 #include <random>
6459 #endif
6460 
6461 namespace Catch {
6462 
6463  struct RandomNumberGenerator {
6464  typedef std::ptrdiff_t result_type;
6465 
6466  result_type operator()( result_type n ) const { return std::rand() % n; }
6467 
6468 #ifdef CATCH_CPP14_OR_GREATER
6469  static constexpr result_type min() { return 0; }
6470  static constexpr result_type max() { return 1000000; }
6471  result_type operator()() const { return std::rand() % max(); }
6472 #endif
6473  template<typename V>
6474  static void shuffle( V& vector ) {
6475  RandomNumberGenerator rng;
6476 #ifdef CATCH_CPP14_OR_GREATER
6477  std::shuffle( vector.begin(), vector.end(), rng );
6478 #else
6479  std::random_shuffle( vector.begin(), vector.end(), rng );
6480 #endif
6481  }
6482  };
6483 
6484  inline std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) {
6485 
6486  std::vector<TestCase> sorted = unsortedTestCases;
6487 
6488  switch( config.runOrder() ) {
6489  case RunTests::InLexicographicalOrder:
6490  std::sort( sorted.begin(), sorted.end() );
6491  break;
6492  case RunTests::InRandomOrder:
6493  {
6494  seedRng( config );
6495  RandomNumberGenerator::shuffle( sorted );
6496  }
6497  break;
6498  case RunTests::InDeclarationOrder:
6499  // already in declaration order
6500  break;
6501  }
6502  return sorted;
6503  }
6504  bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) {
6505  return testSpec.matches( testCase ) && ( config.allowThrows() || !testCase.throws() );
6506  }
6507 
6508  void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) {
6509  std::set<TestCase> seenFunctions;
6510  for( std::vector<TestCase>::const_iterator it = functions.begin(), itEnd = functions.end();
6511  it != itEnd;
6512  ++it ) {
6513  std::pair<std::set<TestCase>::const_iterator, bool> prev = seenFunctions.insert( *it );
6514  if( !prev.second ) {
6515  std::ostringstream ss;
6516 
6517  ss << Colour( Colour::Red )
6518  << "error: TEST_CASE( \"" << it->name << "\" ) already defined.\n"
6519  << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n"
6520  << "\tRedefined at " << it->getTestCaseInfo().lineInfo << std::endl;
6521 
6522  throw std::runtime_error(ss.str());
6523  }
6524  }
6525  }
6526 
6527  std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ) {
6528  std::vector<TestCase> filtered;
6529  filtered.reserve( testCases.size() );
6530  for( std::vector<TestCase>::const_iterator it = testCases.begin(), itEnd = testCases.end();
6531  it != itEnd;
6532  ++it )
6533  if( matchTest( *it, testSpec, config ) )
6534  filtered.push_back( *it );
6535  return filtered;
6536  }
6537  std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ) {
6538  return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config );
6539  }
6540 
6541  class TestRegistry : public ITestCaseRegistry {
6542  public:
6543  TestRegistry()
6544  : m_currentSortOrder( RunTests::InDeclarationOrder ),
6545  m_unnamedCount( 0 )
6546  {}
6547  virtual ~TestRegistry();
6548 
6549  virtual void registerTest( TestCase const& testCase ) {
6550  std::string name = testCase.getTestCaseInfo().name;
6551  if( name == "" ) {
6552  std::ostringstream oss;
6553  oss << "Anonymous test case " << ++m_unnamedCount;
6554  return registerTest( testCase.withName( oss.str() ) );
6555  }
6556  m_functions.push_back( testCase );
6557  }
6558 
6559  virtual std::vector<TestCase> const& getAllTests() const {
6560  return m_functions;
6561  }
6562  virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const {
6563  if( m_sortedFunctions.empty() )
6564  enforceNoDuplicateTestCases( m_functions );
6565 
6566  if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) {
6567  m_sortedFunctions = sortTests( config, m_functions );
6568  m_currentSortOrder = config.runOrder();
6569  }
6570  return m_sortedFunctions;
6571  }
6572 
6573  private:
6574  std::vector<TestCase> m_functions;
6575  mutable RunTests::InWhatOrder m_currentSortOrder;
6576  mutable std::vector<TestCase> m_sortedFunctions;
6577  size_t m_unnamedCount;
6578  std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised
6579  };
6580 
6582 
6583  class FreeFunctionTestCase : public SharedImpl<ITestCase> {
6584  public:
6585 
6586  FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {}
6587 
6588  virtual void invoke() const {
6589  m_fun();
6590  }
6591 
6592  private:
6593  virtual ~FreeFunctionTestCase();
6594 
6595  TestFunction m_fun;
6596  };
6597 
6598  inline std::string extractClassName( std::string const& classOrQualifiedMethodName ) {
6599  std::string className = classOrQualifiedMethodName;
6600  if( startsWith( className, "&" ) )
6601  {
6602  std::size_t lastColons = className.rfind( "::" );
6603  std::size_t penultimateColons = className.rfind( "::", lastColons-1 );
6604  if( penultimateColons == std::string::npos )
6605  penultimateColons = 1;
6606  className = className.substr( penultimateColons, lastColons-penultimateColons );
6607  }
6608  return className;
6609  }
6610 
6611  void registerTestCase
6612  ( ITestCase* testCase,
6613  char const* classOrQualifiedMethodName,
6614  NameAndDesc const& nameAndDesc,
6615  SourceLineInfo const& lineInfo ) {
6616 
6617  getMutableRegistryHub().registerTest
6618  ( makeTestCase
6619  ( testCase,
6620  extractClassName( classOrQualifiedMethodName ),
6621  nameAndDesc.name,
6622  nameAndDesc.description,
6623  lineInfo ) );
6624  }
6625  void registerTestCaseFunction
6626  ( TestFunction function,
6627  SourceLineInfo const& lineInfo,
6628  NameAndDesc const& nameAndDesc ) {
6629  registerTestCase( new FreeFunctionTestCase( function ), "", nameAndDesc, lineInfo );
6630  }
6631 
6633 
6634  AutoReg::AutoReg
6635  ( TestFunction function,
6636  SourceLineInfo const& lineInfo,
6637  NameAndDesc const& nameAndDesc ) {
6638  registerTestCaseFunction( function, lineInfo, nameAndDesc );
6639  }
6640 
6641  AutoReg::~AutoReg() {}
6642 
6643 } // end namespace Catch
6644 
6645 // #included from: catch_reporter_registry.hpp
6646 #define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED
6647 
6648 #include <map>
6649 
6650 namespace Catch {
6651 
6652  class ReporterRegistry : public IReporterRegistry {
6653 
6654  public:
6655 
6656  virtual ~ReporterRegistry() CATCH_OVERRIDE {}
6657 
6658  virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const CATCH_OVERRIDE {
6659  FactoryMap::const_iterator it = m_factories.find( name );
6660  if( it == m_factories.end() )
6661  return CATCH_NULL;
6662  return it->second->create( ReporterConfig( config ) );
6663  }
6664 
6665  void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) {
6666  m_factories.insert( std::make_pair( name, factory ) );
6667  }
6668  void registerListener( Ptr<IReporterFactory> const& factory ) {
6669  m_listeners.push_back( factory );
6670  }
6671 
6672  virtual FactoryMap const& getFactories() const CATCH_OVERRIDE {
6673  return m_factories;
6674  }
6675  virtual Listeners const& getListeners() const CATCH_OVERRIDE {
6676  return m_listeners;
6677  }
6678 
6679  private:
6680  FactoryMap m_factories;
6681  Listeners m_listeners;
6682  };
6683 }
6684 
6685 // #included from: catch_exception_translator_registry.hpp
6686 #define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
6687 
6688 #ifdef __OBJC__
6689 #import "Foundation/Foundation.h"
6690 #endif
6691 
6692 namespace Catch {
6693 
6694  class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
6695  public:
6696  ~ExceptionTranslatorRegistry() {
6697  deleteAll( m_translators );
6698  }
6699 
6700  virtual void registerTranslator( const IExceptionTranslator* translator ) {
6701  m_translators.push_back( translator );
6702  }
6703 
6704  virtual std::string translateActiveException() const {
6705  try {
6706 #ifdef __OBJC__
6707  // In Objective-C try objective-c exceptions first
6708  @try {
6709  return tryTranslators();
6710  }
6711  @catch (NSException *exception) {
6712  return Catch::toString( [exception description] );
6713  }
6714 #else
6715  return tryTranslators();
6716 #endif
6717  }
6718  catch( TestFailureException& ) {
6719  throw;
6720  }
6721  catch( std::exception& ex ) {
6722  return ex.what();
6723  }
6724  catch( std::string& msg ) {
6725  return msg;
6726  }
6727  catch( const char* msg ) {
6728  return msg;
6729  }
6730  catch(...) {
6731  return "Unknown exception";
6732  }
6733  }
6734 
6735  std::string tryTranslators() const {
6736  if( m_translators.empty() )
6737  throw;
6738  else
6739  return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() );
6740  }
6741 
6742  private:
6743  std::vector<const IExceptionTranslator*> m_translators;
6744  };
6745 }
6746 
6747 namespace Catch {
6748 
6749  namespace {
6750 
6751  class RegistryHub : public IRegistryHub, public IMutableRegistryHub {
6752 
6753  RegistryHub( RegistryHub const& );
6754  void operator=( RegistryHub const& );
6755 
6756  public: // IRegistryHub
6757  RegistryHub() {
6758  }
6759  virtual IReporterRegistry const& getReporterRegistry() const CATCH_OVERRIDE {
6760  return m_reporterRegistry;
6761  }
6762  virtual ITestCaseRegistry const& getTestCaseRegistry() const CATCH_OVERRIDE {
6763  return m_testCaseRegistry;
6764  }
6765  virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() CATCH_OVERRIDE {
6766  return m_exceptionTranslatorRegistry;
6767  }
6768 
6769  public: // IMutableRegistryHub
6770  virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) CATCH_OVERRIDE {
6771  m_reporterRegistry.registerReporter( name, factory );
6772  }
6773  virtual void registerListener( Ptr<IReporterFactory> const& factory ) CATCH_OVERRIDE {
6774  m_reporterRegistry.registerListener( factory );
6775  }
6776  virtual void registerTest( TestCase const& testInfo ) CATCH_OVERRIDE {
6777  m_testCaseRegistry.registerTest( testInfo );
6778  }
6779  virtual void registerTranslator( const IExceptionTranslator* translator ) CATCH_OVERRIDE {
6780  m_exceptionTranslatorRegistry.registerTranslator( translator );
6781  }
6782 
6783  private:
6784  TestRegistry m_testCaseRegistry;
6785  ReporterRegistry m_reporterRegistry;
6786  ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
6787  };
6788 
6789  // Single, global, instance
6790  inline RegistryHub*& getTheRegistryHub() {
6791  static RegistryHub* theRegistryHub = CATCH_NULL;
6792  if( !theRegistryHub )
6793  theRegistryHub = new RegistryHub();
6794  return theRegistryHub;
6795  }
6796  }
6797 
6798  IRegistryHub& getRegistryHub() {
6799  return *getTheRegistryHub();
6800  }
6801  IMutableRegistryHub& getMutableRegistryHub() {
6802  return *getTheRegistryHub();
6803  }
6804  void cleanUp() {
6805  delete getTheRegistryHub();
6806  getTheRegistryHub() = CATCH_NULL;
6807  cleanUpContext();
6808  }
6809  std::string translateActiveException() {
6810  return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
6811  }
6812 
6813 } // end namespace Catch
6814 
6815 // #included from: catch_notimplemented_exception.hpp
6816 #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED
6817 
6818 #include <ostream>
6819 
6820 namespace Catch {
6821 
6822  NotImplementedException::NotImplementedException( SourceLineInfo const& lineInfo )
6823  : m_lineInfo( lineInfo ) {
6824  std::ostringstream oss;
6825  oss << lineInfo << ": function ";
6826  oss << "not implemented";
6827  m_what = oss.str();
6828  }
6829 
6830  const char* NotImplementedException::what() const CATCH_NOEXCEPT {
6831  return m_what.c_str();
6832  }
6833 
6834 } // end namespace Catch
6835 
6836 // #included from: catch_context_impl.hpp
6837 #define TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
6838 
6839 // #included from: catch_stream.hpp
6840 #define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED
6841 
6842 #include <stdexcept>
6843 #include <cstdio>
6844 #include <iostream>
6845 
6846 namespace Catch {
6847 
6848  template<typename WriterF, size_t bufferSize=256>
6849  class StreamBufImpl : public StreamBufBase {
6850  char data[bufferSize];
6851  WriterF m_writer;
6852 
6853  public:
6854  StreamBufImpl() {
6855  setp( data, data + sizeof(data) );
6856  }
6857 
6858  ~StreamBufImpl() CATCH_NOEXCEPT {
6859  sync();
6860  }
6861 
6862  private:
6863  int overflow( int c ) {
6864  sync();
6865 
6866  if( c != EOF ) {
6867  if( pbase() == epptr() )
6868  m_writer( std::string( 1, static_cast<char>( c ) ) );
6869  else
6870  sputc( static_cast<char>( c ) );
6871  }
6872  return 0;
6873  }
6874 
6875  int sync() {
6876  if( pbase() != pptr() ) {
6877  m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) );
6878  setp( pbase(), epptr() );
6879  }
6880  return 0;
6881  }
6882  };
6883 
6885 
6886  FileStream::FileStream( std::string const& filename ) {
6887  m_ofs.open( filename.c_str() );
6888  if( m_ofs.fail() ) {
6889  std::ostringstream oss;
6890  oss << "Unable to open file: '" << filename << "'";
6891  throw std::domain_error( oss.str() );
6892  }
6893  }
6894 
6895  std::ostream& FileStream::stream() const {
6896  return m_ofs;
6897  }
6898 
6899  struct OutputDebugWriter {
6900 
6901  void operator()( std::string const&str ) {
6902  writeToDebugConsole( str );
6903  }
6904  };
6905 
6906  DebugOutStream::DebugOutStream()
6907  : m_streamBuf( new StreamBufImpl<OutputDebugWriter>() ),
6908  m_os( m_streamBuf.get() )
6909  {}
6910 
6911  std::ostream& DebugOutStream::stream() const {
6912  return m_os;
6913  }
6914 
6915  // Store the streambuf from cout up-front because
6916  // cout may get redirected when running tests
6917  CoutStream::CoutStream()
6918  : m_os( Catch::cout().rdbuf() )
6919  {}
6920 
6921  std::ostream& CoutStream::stream() const {
6922  return m_os;
6923  }
6924 
6925 #ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions
6926  std::ostream& cout() {
6927  return std::cout;
6928  }
6929  std::ostream& cerr() {
6930  return std::cerr;
6931  }
6932 #endif
6933 }
6934 
6935 namespace Catch {
6936 
6937  class Context : public IMutableContext {
6938 
6939  Context() : m_config( CATCH_NULL ), m_runner( CATCH_NULL ), m_resultCapture( CATCH_NULL ) {}
6940  Context( Context const& );
6941  void operator=( Context const& );
6942 
6943  public: // IContext
6944  virtual IResultCapture* getResultCapture() {
6945  return m_resultCapture;
6946  }
6947  virtual IRunner* getRunner() {
6948  return m_runner;
6949  }
6950  virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) {
6951  return getGeneratorsForCurrentTest()
6952  .getGeneratorInfo( fileInfo, totalSize )
6953  .getCurrentIndex();
6954  }
6955  virtual bool advanceGeneratorsForCurrentTest() {
6956  IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
6957  return generators && generators->moveNext();
6958  }
6959 
6960  virtual Ptr<IConfig const> getConfig() const {
6961  return m_config;
6962  }
6963 
6964  public: // IMutableContext
6965  virtual void setResultCapture( IResultCapture* resultCapture ) {
6966  m_resultCapture = resultCapture;
6967  }
6968  virtual void setRunner( IRunner* runner ) {
6969  m_runner = runner;
6970  }
6971  virtual void setConfig( Ptr<IConfig const> const& config ) {
6972  m_config = config;
6973  }
6974 
6975  friend IMutableContext& getCurrentMutableContext();
6976 
6977  private:
6978  IGeneratorsForTest* findGeneratorsForCurrentTest() {
6979  std::string testName = getResultCapture()->getCurrentTestName();
6980 
6981  std::map<std::string, IGeneratorsForTest*>::const_iterator it =
6982  m_generatorsByTestName.find( testName );
6983  return it != m_generatorsByTestName.end()
6984  ? it->second
6985  : CATCH_NULL;
6986  }
6987 
6988  IGeneratorsForTest& getGeneratorsForCurrentTest() {
6989  IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
6990  if( !generators ) {
6991  std::string testName = getResultCapture()->getCurrentTestName();
6992  generators = createGeneratorsForTest();
6993  m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
6994  }
6995  return *generators;
6996  }
6997 
6998  private:
6999  Ptr<IConfig const> m_config;
7000  IRunner* m_runner;
7001  IResultCapture* m_resultCapture;
7002  std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName;
7003  };
7004 
7005  namespace {
7006  Context* currentContext = CATCH_NULL;
7007  }
7008  IMutableContext& getCurrentMutableContext() {
7009  if( !currentContext )
7010  currentContext = new Context();
7011  return *currentContext;
7012  }
7013  IContext& getCurrentContext() {
7014  return getCurrentMutableContext();
7015  }
7016 
7017  void cleanUpContext() {
7018  delete currentContext;
7019  currentContext = CATCH_NULL;
7020  }
7021 }
7022 
7023 // #included from: catch_console_colour_impl.hpp
7024 #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
7025 
7026 namespace Catch {
7027  namespace {
7028 
7029  struct IColourImpl {
7030  virtual ~IColourImpl() {}
7031  virtual void use( Colour::Code _colourCode ) = 0;
7032  };
7033 
7034  struct NoColourImpl : IColourImpl {
7035  void use( Colour::Code ) {}
7036 
7037  static IColourImpl* instance() {
7038  static NoColourImpl s_instance;
7039  return &s_instance;
7040  }
7041  };
7042 
7043  } // anon namespace
7044 } // namespace Catch
7045 
7046 #if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI )
7047 # ifdef CATCH_PLATFORM_WINDOWS
7048 # define CATCH_CONFIG_COLOUR_WINDOWS
7049 # else
7050 # define CATCH_CONFIG_COLOUR_ANSI
7051 # endif
7052 #endif
7053 
7054 #if defined ( CATCH_CONFIG_COLOUR_WINDOWS )
7055 
7056 #ifndef NOMINMAX
7057 #define NOMINMAX
7058 #endif
7059 
7060 #ifdef __AFXDLL
7061 #include <AfxWin.h>
7062 #else
7063 #include <windows.h>
7064 #endif
7065 
7066 namespace Catch {
7067 namespace {
7068 
7069  class Win32ColourImpl : public IColourImpl {
7070  public:
7071  Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) )
7072  {
7073  CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
7074  GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo );
7075  originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY );
7076  originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
7077  }
7078 
7079  virtual void use( Colour::Code _colourCode ) {
7080  switch( _colourCode ) {
7081  case Colour::None: return setTextAttribute( originalForegroundAttributes );
7082  case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
7083  case Colour::Red: return setTextAttribute( FOREGROUND_RED );
7084  case Colour::Green: return setTextAttribute( FOREGROUND_GREEN );
7085  case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE );
7086  case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN );
7087  case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN );
7088  case Colour::Grey: return setTextAttribute( 0 );
7089 
7090  case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY );
7091  case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED );
7092  case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN );
7093  case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
7094 
7095  case Colour::Bright: throw std::logic_error( "not a colour" );
7096  }
7097  }
7098 
7099  private:
7100  void setTextAttribute( WORD _textAttribute ) {
7101  SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes );
7102  }
7103  HANDLE stdoutHandle;
7104  WORD originalForegroundAttributes;
7105  WORD originalBackgroundAttributes;
7106  };
7107 
7108  IColourImpl* platformColourInstance() {
7109  static Win32ColourImpl s_instance;
7110 
7111  Ptr<IConfig const> config = getCurrentContext().getConfig();
7112  UseColour::YesOrNo colourMode = config
7113  ? config->useColour()
7114  : UseColour::Auto;
7115  if( colourMode == UseColour::Auto )
7116  colourMode = !isDebuggerActive()
7117  ? UseColour::Yes
7118  : UseColour::No;
7119  return colourMode == UseColour::Yes
7120  ? &s_instance
7121  : NoColourImpl::instance();
7122  }
7123 
7124 } // end anon namespace
7125 } // end namespace Catch
7126 
7127 #elif defined( CATCH_CONFIG_COLOUR_ANSI )
7128 
7129 #include <unistd.h>
7130 
7131 namespace Catch {
7132 namespace {
7133 
7134  // use POSIX/ ANSI console terminal codes
7135  // Thanks to Adam Strzelecki for original contribution
7136  // (http://github.com/nanoant)
7137  // https://github.com/philsquared/Catch/pull/131
7138  class PosixColourImpl : public IColourImpl {
7139  public:
7140  virtual void use( Colour::Code _colourCode ) {
7141  switch( _colourCode ) {
7142  case Colour::None:
7143  case Colour::White: return setColour( "[0m" );
7144  case Colour::Red: return setColour( "[0;31m" );
7145  case Colour::Green: return setColour( "[0;32m" );
7146  case Colour::Blue: return setColour( "[0:34m" );
7147  case Colour::Cyan: return setColour( "[0;36m" );
7148  case Colour::Yellow: return setColour( "[0;33m" );
7149  case Colour::Grey: return setColour( "[1;30m" );
7150 
7151  case Colour::LightGrey: return setColour( "[0;37m" );
7152  case Colour::BrightRed: return setColour( "[1;31m" );
7153  case Colour::BrightGreen: return setColour( "[1;32m" );
7154  case Colour::BrightWhite: return setColour( "[1;37m" );
7155 
7156  case Colour::Bright: throw std::logic_error( "not a colour" );
7157  }
7158  }
7159  static IColourImpl* instance() {
7160  static PosixColourImpl s_instance;
7161  return &s_instance;
7162  }
7163 
7164  private:
7165  void setColour( const char* _escapeCode ) {
7166  Catch::cout() << '\033' << _escapeCode;
7167  }
7168  };
7169 
7170  IColourImpl* platformColourInstance() {
7171  Ptr<IConfig const> config = getCurrentContext().getConfig();
7172  UseColour::YesOrNo colourMode = config
7173  ? config->useColour()
7174  : UseColour::Auto;
7175  if( colourMode == UseColour::Auto )
7176  colourMode = (!isDebuggerActive() && isatty(STDOUT_FILENO) )
7177  ? UseColour::Yes
7178  : UseColour::No;
7179  return colourMode == UseColour::Yes
7180  ? PosixColourImpl::instance()
7181  : NoColourImpl::instance();
7182  }
7183 
7184 } // end anon namespace
7185 } // end namespace Catch
7186 
7187 #else // not Windows or ANSI
7188 
7189 namespace Catch {
7190 
7191  static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); }
7192 
7193 } // end namespace Catch
7194 
7195 #endif // Windows/ ANSI/ None
7196 
7197 namespace Catch {
7198 
7199  Colour::Colour( Code _colourCode ) : m_moved( false ) { use( _colourCode ); }
7200  Colour::Colour( Colour const& _other ) : m_moved( false ) { const_cast<Colour&>( _other ).m_moved = true; }
7201  Colour::~Colour(){ if( !m_moved ) use( None ); }
7202 
7203  void Colour::use( Code _colourCode ) {
7204  static IColourImpl* impl = platformColourInstance();
7205  impl->use( _colourCode );
7206  }
7207 
7208 } // end namespace Catch
7209 
7210 // #included from: catch_generators_impl.hpp
7211 #define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
7212 
7213 #include <vector>
7214 #include <string>
7215 #include <map>
7216 
7217 namespace Catch {
7218 
7219  struct GeneratorInfo : IGeneratorInfo {
7220 
7221  GeneratorInfo( std::size_t size )
7222  : m_size( size ),
7223  m_currentIndex( 0 )
7224  {}
7225 
7226  bool moveNext() {
7227  if( ++m_currentIndex == m_size ) {
7228  m_currentIndex = 0;
7229  return false;
7230  }
7231  return true;
7232  }
7233 
7234  std::size_t getCurrentIndex() const {
7235  return m_currentIndex;
7236  }
7237 
7238  std::size_t m_size;
7239  std::size_t m_currentIndex;
7240  };
7241 
7243 
7244  class GeneratorsForTest : public IGeneratorsForTest {
7245 
7246  public:
7247  ~GeneratorsForTest() {
7248  deleteAll( m_generatorsInOrder );
7249  }
7250 
7251  IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) {
7252  std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
7253  if( it == m_generatorsByName.end() ) {
7254  IGeneratorInfo* info = new GeneratorInfo( size );
7255  m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
7256  m_generatorsInOrder.push_back( info );
7257  return *info;
7258  }
7259  return *it->second;
7260  }
7261 
7262  bool moveNext() {
7263  std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
7264  std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
7265  for(; it != itEnd; ++it ) {
7266  if( (*it)->moveNext() )
7267  return true;
7268  }
7269  return false;
7270  }
7271 
7272  private:
7273  std::map<std::string, IGeneratorInfo*> m_generatorsByName;
7274  std::vector<IGeneratorInfo*> m_generatorsInOrder;
7275  };
7276 
7277  IGeneratorsForTest* createGeneratorsForTest()
7278  {
7279  return new GeneratorsForTest();
7280  }
7281 
7282 } // end namespace Catch
7283 
7284 // #included from: catch_assertionresult.hpp
7285 #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED
7286 
7287 namespace Catch {
7288 
7289  AssertionInfo::AssertionInfo( std::string const& _macroName,
7290  SourceLineInfo const& _lineInfo,
7291  std::string const& _capturedExpression,
7292  ResultDisposition::Flags _resultDisposition )
7293  : macroName( _macroName ),
7294  lineInfo( _lineInfo ),
7295  capturedExpression( _capturedExpression ),
7296  resultDisposition( _resultDisposition )
7297  {}
7298 
7299  AssertionResult::AssertionResult() {}
7300 
7301  AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data )
7302  : m_info( info ),
7303  m_resultData( data )
7304  {}
7305 
7306  AssertionResult::~AssertionResult() {}
7307 
7308  // Result was a success
7309  bool AssertionResult::succeeded() const {
7310  return Catch::isOk( m_resultData.resultType );
7311  }
7312 
7313  // Result was a success, or failure is suppressed
7314  bool AssertionResult::isOk() const {
7315  return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition );
7316  }
7317 
7318  ResultWas::OfType AssertionResult::getResultType() const {
7319  return m_resultData.resultType;
7320  }
7321 
7322  bool AssertionResult::hasExpression() const {
7323  return !m_info.capturedExpression.empty();
7324  }
7325 
7326  bool AssertionResult::hasMessage() const {
7327  return !m_resultData.message.empty();
7328  }
7329 
7330  std::string AssertionResult::getExpression() const {
7331  if( isFalseTest( m_info.resultDisposition ) )
7332  return "!" + m_info.capturedExpression;
7333  else
7334  return m_info.capturedExpression;
7335  }
7336  std::string AssertionResult::getExpressionInMacro() const {
7337  if( m_info.macroName.empty() )
7338  return m_info.capturedExpression;
7339  else
7340  return m_info.macroName + "( " + m_info.capturedExpression + " )";
7341  }
7342 
7343  bool AssertionResult::hasExpandedExpression() const {
7344  return hasExpression() && getExpandedExpression() != getExpression();
7345  }
7346 
7347  std::string AssertionResult::getExpandedExpression() const {
7348  return m_resultData.reconstructedExpression;
7349  }
7350 
7351  std::string AssertionResult::getMessage() const {
7352  return m_resultData.message;
7353  }
7354  SourceLineInfo AssertionResult::getSourceInfo() const {
7355  return m_info.lineInfo;
7356  }
7357 
7358  std::string AssertionResult::getTestMacroName() const {
7359  return m_info.macroName;
7360  }
7361 
7362 } // end namespace Catch
7363 
7364 // #included from: catch_test_case_info.hpp
7365 #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED
7366 
7367 namespace Catch {
7368 
7369  inline TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) {
7370  if( startsWith( tag, "." ) ||
7371  tag == "hide" ||
7372  tag == "!hide" )
7373  return TestCaseInfo::IsHidden;
7374  else if( tag == "!throws" )
7375  return TestCaseInfo::Throws;
7376  else if( tag == "!shouldfail" )
7377  return TestCaseInfo::ShouldFail;
7378  else if( tag == "!mayfail" )
7379  return TestCaseInfo::MayFail;
7380  else
7381  return TestCaseInfo::None;
7382  }
7383  inline bool isReservedTag( std::string const& tag ) {
7384  return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !isalnum( tag[0] );
7385  }
7386  inline void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) {
7387  if( isReservedTag( tag ) ) {
7388  {
7389  Colour colourGuard( Colour::Red );
7390  Catch::cerr()
7391  << "Tag name [" << tag << "] not allowed.\n"
7392  << "Tag names starting with non alpha-numeric characters are reserved\n";
7393  }
7394  {
7395  Colour colourGuard( Colour::FileName );
7396  Catch::cerr() << _lineInfo << std::endl;
7397  }
7398  exit(1);
7399  }
7400  }
7401 
7402  TestCase makeTestCase( ITestCase* _testCase,
7403  std::string const& _className,
7404  std::string const& _name,
7405  std::string const& _descOrTags,
7406  SourceLineInfo const& _lineInfo )
7407  {
7408  bool isHidden( startsWith( _name, "./" ) ); // Legacy support
7409 
7410  // Parse out tags
7411  std::set<std::string> tags;
7412  std::string desc, tag;
7413  bool inTag = false;
7414  for( std::size_t i = 0; i < _descOrTags.size(); ++i ) {
7415  char c = _descOrTags[i];
7416  if( !inTag ) {
7417  if( c == '[' )
7418  inTag = true;
7419  else
7420  desc += c;
7421  }
7422  else {
7423  if( c == ']' ) {
7424  TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag );
7425  if( prop == TestCaseInfo::IsHidden )
7426  isHidden = true;
7427  else if( prop == TestCaseInfo::None )
7428  enforceNotReservedTag( tag, _lineInfo );
7429 
7430  tags.insert( tag );
7431  tag.clear();
7432  inTag = false;
7433  }
7434  else
7435  tag += c;
7436  }
7437  }
7438  if( isHidden ) {
7439  tags.insert( "hide" );
7440  tags.insert( "." );
7441  }
7442 
7443  TestCaseInfo info( _name, _className, desc, tags, _lineInfo );
7444  return TestCase( _testCase, info );
7445  }
7446 
7447  void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags )
7448  {
7449  testCaseInfo.tags = tags;
7450  testCaseInfo.lcaseTags.clear();
7451 
7452  std::ostringstream oss;
7453  for( std::set<std::string>::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it ) {
7454  oss << "[" << *it << "]";
7455  std::string lcaseTag = toLower( *it );
7456  testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) );
7457  testCaseInfo.lcaseTags.insert( lcaseTag );
7458  }
7459  testCaseInfo.tagsAsString = oss.str();
7460  }
7461 
7462  TestCaseInfo::TestCaseInfo( std::string const& _name,
7463  std::string const& _className,
7464  std::string const& _description,
7465  std::set<std::string> const& _tags,
7466  SourceLineInfo const& _lineInfo )
7467  : name( _name ),
7468  className( _className ),
7469  description( _description ),
7470  lineInfo( _lineInfo ),
7471  properties( None )
7472  {
7473  setTags( *this, _tags );
7474  }
7475 
7476  TestCaseInfo::TestCaseInfo( TestCaseInfo const& other )
7477  : name( other.name ),
7478  className( other.className ),
7479  description( other.description ),
7480  tags( other.tags ),
7481  lcaseTags( other.lcaseTags ),
7482  tagsAsString( other.tagsAsString ),
7483  lineInfo( other.lineInfo ),
7484  properties( other.properties )
7485  {}
7486 
7487  bool TestCaseInfo::isHidden() const {
7488  return ( properties & IsHidden ) != 0;
7489  }
7490  bool TestCaseInfo::throws() const {
7491  return ( properties & Throws ) != 0;
7492  }
7493  bool TestCaseInfo::okToFail() const {
7494  return ( properties & (ShouldFail | MayFail ) ) != 0;
7495  }
7496  bool TestCaseInfo::expectedToFail() const {
7497  return ( properties & (ShouldFail ) ) != 0;
7498  }
7499 
7500  TestCase::TestCase( ITestCase* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {}
7501 
7502  TestCase::TestCase( TestCase const& other )
7503  : TestCaseInfo( other ),
7504  test( other.test )
7505  {}
7506 
7507  TestCase TestCase::withName( std::string const& _newName ) const {
7508  TestCase other( *this );
7509  other.name = _newName;
7510  return other;
7511  }
7512 
7513  void TestCase::swap( TestCase& other ) {
7514  test.swap( other.test );
7515  name.swap( other.name );
7516  className.swap( other.className );
7517  description.swap( other.description );
7518  tags.swap( other.tags );
7519  lcaseTags.swap( other.lcaseTags );
7520  tagsAsString.swap( other.tagsAsString );
7521  std::swap( TestCaseInfo::properties, static_cast<TestCaseInfo&>( other ).properties );
7522  std::swap( lineInfo, other.lineInfo );
7523  }
7524 
7525  void TestCase::invoke() const {
7526  test->invoke();
7527  }
7528 
7529  bool TestCase::operator == ( TestCase const& other ) const {
7530  return test.get() == other.test.get() &&
7531  name == other.name &&
7532  className == other.className;
7533  }
7534 
7535  bool TestCase::operator < ( TestCase const& other ) const {
7536  return name < other.name;
7537  }
7538  TestCase& TestCase::operator = ( TestCase const& other ) {
7539  TestCase temp( other );
7540  swap( temp );
7541  return *this;
7542  }
7543 
7544  TestCaseInfo const& TestCase::getTestCaseInfo() const
7545  {
7546  return *this;
7547  }
7548 
7549 } // end namespace Catch
7550 
7551 // #included from: catch_version.hpp
7552 #define TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED
7553 
7554 namespace Catch {
7555 
7556  Version::Version
7557  ( unsigned int _majorVersion,
7558  unsigned int _minorVersion,
7559  unsigned int _patchNumber,
7560  std::string const& _branchName,
7561  unsigned int _buildNumber )
7562  : majorVersion( _majorVersion ),
7563  minorVersion( _minorVersion ),
7564  patchNumber( _patchNumber ),
7565  branchName( _branchName ),
7566  buildNumber( _buildNumber )
7567  {}
7568 
7569  std::ostream& operator << ( std::ostream& os, Version const& version ) {
7570  os << version.majorVersion << "."
7571  << version.minorVersion << "."
7572  << version.patchNumber;
7573 
7574  if( !version.branchName.empty() ) {
7575  os << "-" << version.branchName
7576  << "." << version.buildNumber;
7577  }
7578  return os;
7579  }
7580 
7581  Version libraryVersion( 1, 5, 8, "", 0 );
7582 
7583 }
7584 
7585 // #included from: catch_message.hpp
7586 #define TWOBLUECUBES_CATCH_MESSAGE_HPP_INCLUDED
7587 
7588 namespace Catch {
7589 
7590  MessageInfo::MessageInfo( std::string const& _macroName,
7591  SourceLineInfo const& _lineInfo,
7592  ResultWas::OfType _type )
7593  : macroName( _macroName ),
7594  lineInfo( _lineInfo ),
7595  type( _type ),
7596  sequence( ++globalCount )
7597  {}
7598 
7599  // This may need protecting if threading support is added
7600  unsigned int MessageInfo::globalCount = 0;
7601 
7603 
7604  ScopedMessage::ScopedMessage( MessageBuilder const& builder )
7605  : m_info( builder.m_info )
7606  {
7607  m_info.message = builder.m_stream.str();
7608  getResultCapture().pushScopedMessage( m_info );
7609  }
7610  ScopedMessage::ScopedMessage( ScopedMessage const& other )
7611  : m_info( other.m_info )
7612  {}
7613 
7614  ScopedMessage::~ScopedMessage() {
7615  getResultCapture().popScopedMessage( m_info );
7616  }
7617 
7618 } // end namespace Catch
7619 
7620 // #included from: catch_legacy_reporter_adapter.hpp
7621 #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED
7622 
7623 // #included from: catch_legacy_reporter_adapter.h
7624 #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED
7625 
7626 namespace Catch
7627 {
7628  // Deprecated
7629  struct IReporter : IShared {
7630  virtual ~IReporter();
7631 
7632  virtual bool shouldRedirectStdout() const = 0;
7633 
7634  virtual void StartTesting() = 0;
7635  virtual void EndTesting( Totals const& totals ) = 0;
7636  virtual void StartGroup( std::string const& groupName ) = 0;
7637  virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0;
7638  virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0;
7639  virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0;
7640  virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0;
7641  virtual void EndSection( std::string const& sectionName, Counts const& assertions ) = 0;
7642  virtual void NoAssertionsInSection( std::string const& sectionName ) = 0;
7643  virtual void NoAssertionsInTestCase( std::string const& testName ) = 0;
7644  virtual void Aborted() = 0;
7645  virtual void Result( AssertionResult const& result ) = 0;
7646  };
7647 
7648  class LegacyReporterAdapter : public SharedImpl<IStreamingReporter>
7649  {
7650  public:
7651  LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter );
7652  virtual ~LegacyReporterAdapter();
7653 
7654  virtual ReporterPreferences getPreferences() const;
7655  virtual void noMatchingTestCases( std::string const& );
7656  virtual void testRunStarting( TestRunInfo const& );
7657  virtual void testGroupStarting( GroupInfo const& groupInfo );
7658  virtual void testCaseStarting( TestCaseInfo const& testInfo );
7659  virtual void sectionStarting( SectionInfo const& sectionInfo );
7660  virtual void assertionStarting( AssertionInfo const& );
7661  virtual bool assertionEnded( AssertionStats const& assertionStats );
7662  virtual void sectionEnded( SectionStats const& sectionStats );
7663  virtual void testCaseEnded( TestCaseStats const& testCaseStats );
7664  virtual void testGroupEnded( TestGroupStats const& testGroupStats );
7665  virtual void testRunEnded( TestRunStats const& testRunStats );
7666  virtual void skipTest( TestCaseInfo const& );
7667 
7668  private:
7669  Ptr<IReporter> m_legacyReporter;
7670  };
7671 }
7672 
7673 namespace Catch
7674 {
7675  LegacyReporterAdapter::LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter )
7676  : m_legacyReporter( legacyReporter )
7677  {}
7678  LegacyReporterAdapter::~LegacyReporterAdapter() {}
7679 
7680  ReporterPreferences LegacyReporterAdapter::getPreferences() const {
7681  ReporterPreferences prefs;
7682  prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout();
7683  return prefs;
7684  }
7685 
7686  void LegacyReporterAdapter::noMatchingTestCases( std::string const& ) {}
7687  void LegacyReporterAdapter::testRunStarting( TestRunInfo const& ) {
7688  m_legacyReporter->StartTesting();
7689  }
7690  void LegacyReporterAdapter::testGroupStarting( GroupInfo const& groupInfo ) {
7691  m_legacyReporter->StartGroup( groupInfo.name );
7692  }
7693  void LegacyReporterAdapter::testCaseStarting( TestCaseInfo const& testInfo ) {
7694  m_legacyReporter->StartTestCase( testInfo );
7695  }
7696  void LegacyReporterAdapter::sectionStarting( SectionInfo const& sectionInfo ) {
7697  m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description );
7698  }
7699  void LegacyReporterAdapter::assertionStarting( AssertionInfo const& ) {
7700  // Not on legacy interface
7701  }
7702 
7703  bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) {
7704  if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
7705  for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
7706  it != itEnd;
7707  ++it ) {
7708  if( it->type == ResultWas::Info ) {
7709  ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal );
7710  rb << it->message;
7711  rb.setResultType( ResultWas::Info );
7712  AssertionResult result = rb.build();
7713  m_legacyReporter->Result( result );
7714  }
7715  }
7716  }
7717  m_legacyReporter->Result( assertionStats.assertionResult );
7718  return true;
7719  }
7720  void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) {
7721  if( sectionStats.missingAssertions )
7722  m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name );
7723  m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions );
7724  }
7725  void LegacyReporterAdapter::testCaseEnded( TestCaseStats const& testCaseStats ) {
7726  m_legacyReporter->EndTestCase
7727  ( testCaseStats.testInfo,
7728  testCaseStats.totals,
7729  testCaseStats.stdOut,
7730  testCaseStats.stdErr );
7731  }
7732  void LegacyReporterAdapter::testGroupEnded( TestGroupStats const& testGroupStats ) {
7733  if( testGroupStats.aborting )
7734  m_legacyReporter->Aborted();
7735  m_legacyReporter->EndGroup( testGroupStats.groupInfo.name, testGroupStats.totals );
7736  }
7737  void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) {
7738  m_legacyReporter->EndTesting( testRunStats.totals );
7739  }
7740  void LegacyReporterAdapter::skipTest( TestCaseInfo const& ) {
7741  }
7742 }
7743 
7744 // #included from: catch_timer.hpp
7745 
7746 #ifdef __clang__
7747 #pragma clang diagnostic push
7748 #pragma clang diagnostic ignored "-Wc++11-long-long"
7749 #endif
7750 
7751 #ifdef CATCH_PLATFORM_WINDOWS
7752 #include <windows.h>
7753 #else
7754 #include <sys/time.h>
7755 #endif
7756 
7757 namespace Catch {
7758 
7759  namespace {
7760 #ifdef CATCH_PLATFORM_WINDOWS
7761  uint64_t getCurrentTicks() {
7762  static uint64_t hz=0, hzo=0;
7763  if (!hz) {
7764  QueryPerformanceFrequency( reinterpret_cast<LARGE_INTEGER*>( &hz ) );
7765  QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &hzo ) );
7766  }
7767  uint64_t t;
7768  QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &t ) );
7769  return ((t-hzo)*1000000)/hz;
7770  }
7771 #else
7772  uint64_t getCurrentTicks() {
7773  timeval t;
7774  gettimeofday(&t,CATCH_NULL);
7775  return static_cast<uint64_t>( t.tv_sec ) * 1000000ull + static_cast<uint64_t>( t.tv_usec );
7776  }
7777 #endif
7778  }
7779 
7780  void Timer::start() {
7781  m_ticks = getCurrentTicks();
7782  }
7783  unsigned int Timer::getElapsedMicroseconds() const {
7784  return static_cast<unsigned int>(getCurrentTicks() - m_ticks);
7785  }
7786  unsigned int Timer::getElapsedMilliseconds() const {
7787  return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
7788  }
7789  double Timer::getElapsedSeconds() const {
7790  return getElapsedMicroseconds()/1000000.0;
7791  }
7792 
7793 } // namespace Catch
7794 
7795 #ifdef __clang__
7796 #pragma clang diagnostic pop
7797 #endif
7798 // #included from: catch_common.hpp
7799 #define TWOBLUECUBES_CATCH_COMMON_HPP_INCLUDED
7800 
7801 namespace Catch {
7802 
7803  bool startsWith( std::string const& s, std::string const& prefix ) {
7804  return s.size() >= prefix.size() && s.substr( 0, prefix.size() ) == prefix;
7805  }
7806  bool endsWith( std::string const& s, std::string const& suffix ) {
7807  return s.size() >= suffix.size() && s.substr( s.size()-suffix.size(), suffix.size() ) == suffix;
7808  }
7809  bool contains( std::string const& s, std::string const& infix ) {
7810  return s.find( infix ) != std::string::npos;
7811  }
7812  char toLowerCh(char c) {
7813  return static_cast<char>( ::tolower( c ) );
7814  }
7815  void toLowerInPlace( std::string& s ) {
7816  std::transform( s.begin(), s.end(), s.begin(), toLowerCh );
7817  }
7818  std::string toLower( std::string const& s ) {
7819  std::string lc = s;
7820  toLowerInPlace( lc );
7821  return lc;
7822  }
7823  std::string trim( std::string const& str ) {
7824  static char const* whitespaceChars = "\n\r\t ";
7825  std::string::size_type start = str.find_first_not_of( whitespaceChars );
7826  std::string::size_type end = str.find_last_not_of( whitespaceChars );
7827 
7828  return start != std::string::npos ? str.substr( start, 1+end-start ) : "";
7829  }
7830 
7831  bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) {
7832  bool replaced = false;
7833  std::size_t i = str.find( replaceThis );
7834  while( i != std::string::npos ) {
7835  replaced = true;
7836  str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() );
7837  if( i < str.size()-withThis.size() )
7838  i = str.find( replaceThis, i+withThis.size() );
7839  else
7840  i = std::string::npos;
7841  }
7842  return replaced;
7843  }
7844 
7845  pluralise::pluralise( std::size_t count, std::string const& label )
7846  : m_count( count ),
7847  m_label( label )
7848  {}
7849 
7850  std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) {
7851  os << pluraliser.m_count << " " << pluraliser.m_label;
7852  if( pluraliser.m_count != 1 )
7853  os << "s";
7854  return os;
7855  }
7856 
7857  SourceLineInfo::SourceLineInfo() : line( 0 ){}
7858  SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line )
7859  : file( _file ),
7860  line( _line )
7861  {}
7862  SourceLineInfo::SourceLineInfo( SourceLineInfo const& other )
7863  : file( other.file ),
7864  line( other.line )
7865  {}
7866  bool SourceLineInfo::empty() const {
7867  return file.empty();
7868  }
7869  bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const {
7870  return line == other.line && file == other.file;
7871  }
7872  bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const {
7873  return line < other.line || ( line == other.line && file < other.file );
7874  }
7875 
7876  void seedRng( IConfig const& config ) {
7877  if( config.rngSeed() != 0 )
7878  std::srand( config.rngSeed() );
7879  }
7880  unsigned int rngSeed() {
7881  return getCurrentContext().getConfig()->rngSeed();
7882  }
7883 
7884  std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
7885 #ifndef __GNUG__
7886  os << info.file << "(" << info.line << ")";
7887 #else
7888  os << info.file << ":" << info.line;
7889 #endif
7890  return os;
7891  }
7892 
7893  void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ) {
7894  std::ostringstream oss;
7895  oss << locationInfo << ": Internal Catch error: '" << message << "'";
7896  if( alwaysTrue() )
7897  throw std::logic_error( oss.str() );
7898  }
7899 }
7900 
7901 // #included from: catch_section.hpp
7902 #define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
7903 
7904 namespace Catch {
7905 
7906  SectionInfo::SectionInfo
7907  ( SourceLineInfo const& _lineInfo,
7908  std::string const& _name,
7909  std::string const& _description )
7910  : name( _name ),
7911  description( _description ),
7912  lineInfo( _lineInfo )
7913  {}
7914 
7915  Section::Section( SectionInfo const& info )
7916  : m_info( info ),
7917  m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) )
7918  {
7919  m_timer.start();
7920  }
7921 
7922  Section::~Section() {
7923  if( m_sectionIncluded ) {
7924  SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() );
7925  if( std::uncaught_exception() )
7926  getResultCapture().sectionEndedEarly( endInfo );
7927  else
7928  getResultCapture().sectionEnded( endInfo );
7929  }
7930  }
7931 
7932  // This indicates whether the section should be executed or not
7933  Section::operator bool() const {
7934  return m_sectionIncluded;
7935  }
7936 
7937 } // end namespace Catch
7938 
7939 // #included from: catch_debugger.hpp
7940 #define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED
7941 
7942 #include <iostream>
7943 
7944 #ifdef CATCH_PLATFORM_MAC
7945 
7946  #include <assert.h>
7947  #include <stdbool.h>
7948  #include <sys/types.h>
7949  #include <unistd.h>
7950  #include <sys/sysctl.h>
7951 
7952  namespace Catch{
7953 
7954  // The following function is taken directly from the following technical note:
7955  // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html
7956 
7957  // Returns true if the current process is being debugged (either
7958  // running under the debugger or has a debugger attached post facto).
7959  bool isDebuggerActive(){
7960 
7961  int mib[4];
7962  struct kinfo_proc info;
7963  size_t size;
7964 
7965  // Initialize the flags so that, if sysctl fails for some bizarre
7966  // reason, we get a predictable result.
7967 
7968  info.kp_proc.p_flag = 0;
7969 
7970  // Initialize mib, which tells sysctl the info we want, in this case
7971  // we're looking for information about a specific process ID.
7972 
7973  mib[0] = CTL_KERN;
7974  mib[1] = KERN_PROC;
7975  mib[2] = KERN_PROC_PID;
7976  mib[3] = getpid();
7977 
7978  // Call sysctl.
7979 
7980  size = sizeof(info);
7981  if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, CATCH_NULL, 0) != 0 ) {
7982  Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
7983  return false;
7984  }
7985 
7986  // We're being debugged if the P_TRACED flag is set.
7987 
7988  return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
7989  }
7990  } // namespace Catch
7991 
7992 #elif defined(_MSC_VER)
7993  extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
7994  namespace Catch {
7995  bool isDebuggerActive() {
7996  return IsDebuggerPresent() != 0;
7997  }
7998  }
7999 #elif defined(__MINGW32__)
8000  extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
8001  namespace Catch {
8002  bool isDebuggerActive() {
8003  return IsDebuggerPresent() != 0;
8004  }
8005  }
8006 #else
8007  namespace Catch {
8008  inline bool isDebuggerActive() { return false; }
8009  }
8010 #endif // Platform
8011 
8012 #ifdef CATCH_PLATFORM_WINDOWS
8013  extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA( const char* );
8014  namespace Catch {
8015  void writeToDebugConsole( std::string const& text ) {
8016  ::OutputDebugStringA( text.c_str() );
8017  }
8018  }
8019 #else
8020  namespace Catch {
8021  void writeToDebugConsole( std::string const& text ) {
8022  // !TBD: Need a version for Mac/ XCode and other IDEs
8023  Catch::cout() << text;
8024  }
8025  }
8026 #endif // Platform
8027 
8028 // #included from: catch_tostring.hpp
8029 #define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED
8030 
8031 namespace Catch {
8032 
8033 namespace Detail {
8034 
8035  const std::string unprintableString = "{?}";
8036 
8037  namespace {
8038  const int hexThreshold = 255;
8039 
8040  struct Endianness {
8041  enum Arch { Big, Little };
8042 
8043  static Arch which() {
8044  union _{
8045  int asInt;
8046  char asChar[sizeof (int)];
8047  } u;
8048 
8049  u.asInt = 1;
8050  return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little;
8051  }
8052  };
8053  }
8054 
8055  std::string rawMemoryToString( const void *object, std::size_t size )
8056  {
8057  // Reverse order for little endian architectures
8058  int i = 0, end = static_cast<int>( size ), inc = 1;
8059  if( Endianness::which() == Endianness::Little ) {
8060  i = end-1;
8061  end = inc = -1;
8062  }
8063 
8064  unsigned char const *bytes = static_cast<unsigned char const *>(object);
8065  std::ostringstream os;
8066  os << "0x" << std::setfill('0') << std::hex;
8067  for( ; i != end; i += inc )
8068  os << std::setw(2) << static_cast<unsigned>(bytes[i]);
8069  return os.str();
8070  }
8071 }
8072 
8073 std::string toString( std::string const& value ) {
8074  std::string s = value;
8075  if( getCurrentContext().getConfig()->showInvisibles() ) {
8076  for(size_t i = 0; i < s.size(); ++i ) {
8077  std::string subs;
8078  switch( s[i] ) {
8079  case '\n': subs = "\\n"; break;
8080  case '\t': subs = "\\t"; break;
8081  default: break;
8082  }
8083  if( !subs.empty() ) {
8084  s = s.substr( 0, i ) + subs + s.substr( i+1 );
8085  ++i;
8086  }
8087  }
8088  }
8089  return "\"" + s + "\"";
8090 }
8091 std::string toString( std::wstring const& value ) {
8092 
8093  std::string s;
8094  s.reserve( value.size() );
8095  for(size_t i = 0; i < value.size(); ++i )
8096  s += value[i] <= 0xff ? static_cast<char>( value[i] ) : '?';
8097  return Catch::toString( s );
8098 }
8099 
8100 std::string toString( const char* const value ) {
8101  return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" );
8102 }
8103 
8104 std::string toString( char* const value ) {
8105  return Catch::toString( static_cast<const char*>( value ) );
8106 }
8107 
8108 std::string toString( const wchar_t* const value )
8109 {
8110  return value ? Catch::toString( std::wstring(value) ) : std::string( "{null string}" );
8111 }
8112 
8113 std::string toString( wchar_t* const value )
8114 {
8115  return Catch::toString( static_cast<const wchar_t*>( value ) );
8116 }
8117 
8118 std::string toString( int value ) {
8119  std::ostringstream oss;
8120  oss << value;
8121  if( value > Detail::hexThreshold )
8122  oss << " (0x" << std::hex << value << ")";
8123  return oss.str();
8124 }
8125 
8126 std::string toString( unsigned long value ) {
8127  std::ostringstream oss;
8128  oss << value;
8129  if( value > Detail::hexThreshold )
8130  oss << " (0x" << std::hex << value << ")";
8131  return oss.str();
8132 }
8133 
8134 std::string toString( unsigned int value ) {
8135  return Catch::toString( static_cast<unsigned long>( value ) );
8136 }
8137 
8138 template<typename T>
8139 std::string fpToString( T value, int precision ) {
8140  std::ostringstream oss;
8141  oss << std::setprecision( precision )
8142  << std::fixed
8143  << value;
8144  std::string d = oss.str();
8145  std::size_t i = d.find_last_not_of( '0' );
8146  if( i != std::string::npos && i != d.size()-1 ) {
8147  if( d[i] == '.' )
8148  i++;
8149  d = d.substr( 0, i+1 );
8150  }
8151  return d;
8152 }
8153 
8154 std::string toString( const double value ) {
8155  return fpToString( value, 10 );
8156 }
8157 std::string toString( const float value ) {
8158  return fpToString( value, 5 ) + "f";
8159 }
8160 
8161 std::string toString( bool value ) {
8162  return value ? "true" : "false";
8163 }
8164 
8165 std::string toString( char value ) {
8166  return value < ' '
8167  ? toString( static_cast<unsigned int>( value ) )
8168  : Detail::makeString( value );
8169 }
8170 
8171 std::string toString( signed char value ) {
8172  return toString( static_cast<char>( value ) );
8173 }
8174 
8175 std::string toString( unsigned char value ) {
8176  return toString( static_cast<char>( value ) );
8177 }
8178 
8179 #ifdef CATCH_CONFIG_CPP11_LONG_LONG
8180 std::string toString( long long value ) {
8181  std::ostringstream oss;
8182  oss << value;
8183  if( value > Detail::hexThreshold )
8184  oss << " (0x" << std::hex << value << ")";
8185  return oss.str();
8186 }
8187 std::string toString( unsigned long long value ) {
8188  std::ostringstream oss;
8189  oss << value;
8190  if( value > Detail::hexThreshold )
8191  oss << " (0x" << std::hex << value << ")";
8192  return oss.str();
8193 }
8194 #endif
8195 
8196 #ifdef CATCH_CONFIG_CPP11_NULLPTR
8197 std::string toString( std::nullptr_t ) {
8198  return "nullptr";
8199 }
8200 #endif
8201 
8202 #ifdef __OBJC__
8203  std::string toString( NSString const * const& nsstring ) {
8204  if( !nsstring )
8205  return "nil";
8206  return "@" + toString([nsstring UTF8String]);
8207  }
8208  std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ) {
8209  if( !nsstring )
8210  return "nil";
8211  return "@" + toString([nsstring UTF8String]);
8212  }
8213  std::string toString( NSObject* const& nsObject ) {
8214  return toString( [nsObject description] );
8215  }
8216 #endif
8217 
8218 } // end namespace Catch
8219 
8220 // #included from: catch_result_builder.hpp
8221 #define TWOBLUECUBES_CATCH_RESULT_BUILDER_HPP_INCLUDED
8222 
8223 namespace Catch {
8224 
8225  std::string capturedExpressionWithSecondArgument( std::string const& capturedExpression, std::string const& secondArg ) {
8226  return secondArg.empty() || secondArg == "\"\""
8227  ? capturedExpression
8228  : capturedExpression + ", " + secondArg;
8229  }
8230  ResultBuilder::ResultBuilder( char const* macroName,
8231  SourceLineInfo const& lineInfo,
8232  char const* capturedExpression,
8233  ResultDisposition::Flags resultDisposition,
8234  char const* secondArg )
8235  : m_assertionInfo( macroName, lineInfo, capturedExpressionWithSecondArgument( capturedExpression, secondArg ), resultDisposition ),
8236  m_shouldDebugBreak( false ),
8237  m_shouldThrow( false )
8238  {}
8239 
8240  ResultBuilder& ResultBuilder::setResultType( ResultWas::OfType result ) {
8241  m_data.resultType = result;
8242  return *this;
8243  }
8244  ResultBuilder& ResultBuilder::setResultType( bool result ) {
8245  m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed;
8246  return *this;
8247  }
8248  ResultBuilder& ResultBuilder::setLhs( std::string const& lhs ) {
8249  m_exprComponents.lhs = lhs;
8250  return *this;
8251  }
8252  ResultBuilder& ResultBuilder::setRhs( std::string const& rhs ) {
8253  m_exprComponents.rhs = rhs;
8254  return *this;
8255  }
8256  ResultBuilder& ResultBuilder::setOp( std::string const& op ) {
8257  m_exprComponents.op = op;
8258  return *this;
8259  }
8260 
8261  void ResultBuilder::endExpression() {
8262  m_exprComponents.testFalse = isFalseTest( m_assertionInfo.resultDisposition );
8263  captureExpression();
8264  }
8265 
8266  void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) {
8267  m_assertionInfo.resultDisposition = resultDisposition;
8268  m_stream.oss << Catch::translateActiveException();
8269  captureResult( ResultWas::ThrewException );
8270  }
8271 
8272  void ResultBuilder::captureResult( ResultWas::OfType resultType ) {
8273  setResultType( resultType );
8274  captureExpression();
8275  }
8276  void ResultBuilder::captureExpectedException( std::string const& expectedMessage ) {
8277  if( expectedMessage.empty() )
8278  captureExpectedException( Matchers::Impl::Generic::AllOf<std::string>() );
8279  else
8280  captureExpectedException( Matchers::Equals( expectedMessage ) );
8281  }
8282 
8283  void ResultBuilder::captureExpectedException( Matchers::Impl::Matcher<std::string> const& matcher ) {
8284 
8285  assert( m_exprComponents.testFalse == false );
8286  AssertionResultData data = m_data;
8287  data.resultType = ResultWas::Ok;
8288  data.reconstructedExpression = m_assertionInfo.capturedExpression;
8289 
8290  std::string actualMessage = Catch::translateActiveException();
8291  if( !matcher.match( actualMessage ) ) {
8292  data.resultType = ResultWas::ExpressionFailed;
8293  data.reconstructedExpression = actualMessage;
8294  }
8295  AssertionResult result( m_assertionInfo, data );
8296  handleResult( result );
8297  }
8298 
8299  void ResultBuilder::captureExpression() {
8300  AssertionResult result = build();
8301  handleResult( result );
8302  }
8303  void ResultBuilder::handleResult( AssertionResult const& result )
8304  {
8305  getResultCapture().assertionEnded( result );
8306 
8307  if( !result.isOk() ) {
8308  if( getCurrentContext().getConfig()->shouldDebugBreak() )
8309  m_shouldDebugBreak = true;
8310  if( getCurrentContext().getRunner()->aborting() || (m_assertionInfo.resultDisposition & ResultDisposition::Normal) )
8311  m_shouldThrow = true;
8312  }
8313  }
8314  void ResultBuilder::react() {
8315  if( m_shouldThrow )
8317  }
8318 
8319  bool ResultBuilder::shouldDebugBreak() const { return m_shouldDebugBreak; }
8320  bool ResultBuilder::allowThrows() const { return getCurrentContext().getConfig()->allowThrows(); }
8321 
8322  AssertionResult ResultBuilder::build() const
8323  {
8324  assert( m_data.resultType != ResultWas::Unknown );
8325 
8326  AssertionResultData data = m_data;
8327 
8328  // Flip bool results if testFalse is set
8329  if( m_exprComponents.testFalse ) {
8330  if( data.resultType == ResultWas::Ok )
8331  data.resultType = ResultWas::ExpressionFailed;
8332  else if( data.resultType == ResultWas::ExpressionFailed )
8333  data.resultType = ResultWas::Ok;
8334  }
8335 
8336  data.message = m_stream.oss.str();
8337  data.reconstructedExpression = reconstructExpression();
8338  if( m_exprComponents.testFalse ) {
8339  if( m_exprComponents.op == "" )
8340  data.reconstructedExpression = "!" + data.reconstructedExpression;
8341  else
8342  data.reconstructedExpression = "!(" + data.reconstructedExpression + ")";
8343  }
8344  return AssertionResult( m_assertionInfo, data );
8345  }
8346  std::string ResultBuilder::reconstructExpression() const {
8347  if( m_exprComponents.op == "" )
8348  return m_exprComponents.lhs.empty() ? m_assertionInfo.capturedExpression : m_exprComponents.op + m_exprComponents.lhs;
8349  else if( m_exprComponents.op == "matches" )
8350  return m_exprComponents.lhs + " " + m_exprComponents.rhs;
8351  else if( m_exprComponents.op != "!" ) {
8352  if( m_exprComponents.lhs.size() + m_exprComponents.rhs.size() < 40 &&
8353  m_exprComponents.lhs.find("\n") == std::string::npos &&
8354  m_exprComponents.rhs.find("\n") == std::string::npos )
8355  return m_exprComponents.lhs + " " + m_exprComponents.op + " " + m_exprComponents.rhs;
8356  else
8357  return m_exprComponents.lhs + "\n" + m_exprComponents.op + "\n" + m_exprComponents.rhs;
8358  }
8359  else
8360  return "{can't expand - use " + m_assertionInfo.macroName + "_FALSE( " + m_assertionInfo.capturedExpression.substr(1) + " ) instead of " + m_assertionInfo.macroName + "( " + m_assertionInfo.capturedExpression + " ) for better diagnostics}";
8361  }
8362 
8363 } // end namespace Catch
8364 
8365 // #included from: catch_tag_alias_registry.hpp
8366 #define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
8367 
8368 // #included from: catch_tag_alias_registry.h
8369 #define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_H_INCLUDED
8370 
8371 #include <map>
8372 
8373 namespace Catch {
8374 
8375  class TagAliasRegistry : public ITagAliasRegistry {
8376  public:
8377  virtual ~TagAliasRegistry();
8378  virtual Option<TagAlias> find( std::string const& alias ) const;
8379  virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const;
8380  void add( char const* alias, char const* tag, SourceLineInfo const& lineInfo );
8381  static TagAliasRegistry& get();
8382 
8383  private:
8384  std::map<std::string, TagAlias> m_registry;
8385  };
8386 
8387 } // end namespace Catch
8388 
8389 #include <map>
8390 #include <iostream>
8391 
8392 namespace Catch {
8393 
8394  TagAliasRegistry::~TagAliasRegistry() {}
8395 
8396  Option<TagAlias> TagAliasRegistry::find( std::string const& alias ) const {
8397  std::map<std::string, TagAlias>::const_iterator it = m_registry.find( alias );
8398  if( it != m_registry.end() )
8399  return it->second;
8400  else
8401  return Option<TagAlias>();
8402  }
8403 
8404  std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {
8405  std::string expandedTestSpec = unexpandedTestSpec;
8406  for( std::map<std::string, TagAlias>::const_iterator it = m_registry.begin(), itEnd = m_registry.end();
8407  it != itEnd;
8408  ++it ) {
8409  std::size_t pos = expandedTestSpec.find( it->first );
8410  if( pos != std::string::npos ) {
8411  expandedTestSpec = expandedTestSpec.substr( 0, pos ) +
8412  it->second.tag +
8413  expandedTestSpec.substr( pos + it->first.size() );
8414  }
8415  }
8416  return expandedTestSpec;
8417  }
8418 
8419  void TagAliasRegistry::add( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) {
8420 
8421  if( !startsWith( alias, "[@" ) || !endsWith( alias, "]" ) ) {
8422  std::ostringstream oss;
8423  oss << "error: tag alias, \"" << alias << "\" is not of the form [@alias name].\n" << lineInfo;
8424  throw std::domain_error( oss.str().c_str() );
8425  }
8426  if( !m_registry.insert( std::make_pair( alias, TagAlias( tag, lineInfo ) ) ).second ) {
8427  std::ostringstream oss;
8428  oss << "error: tag alias, \"" << alias << "\" already registered.\n"
8429  << "\tFirst seen at " << find(alias)->lineInfo << "\n"
8430  << "\tRedefined at " << lineInfo;
8431  throw std::domain_error( oss.str().c_str() );
8432  }
8433  }
8434 
8435  TagAliasRegistry& TagAliasRegistry::get() {
8436  static TagAliasRegistry instance;
8437  return instance;
8438 
8439  }
8440 
8441  ITagAliasRegistry::~ITagAliasRegistry() {}
8442  ITagAliasRegistry const& ITagAliasRegistry::get() { return TagAliasRegistry::get(); }
8443 
8444  RegistrarForTagAliases::RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) {
8445  try {
8446  TagAliasRegistry::get().add( alias, tag, lineInfo );
8447  }
8448  catch( std::exception& ex ) {
8449  Colour colourGuard( Colour::Red );
8450  Catch::cerr() << ex.what() << std::endl;
8451  exit(1);
8452  }
8453  }
8454 
8455 } // end namespace Catch
8456 
8457 // #included from: ../reporters/catch_reporter_multi.hpp
8458 #define TWOBLUECUBES_CATCH_REPORTER_MULTI_HPP_INCLUDED
8459 
8460 namespace Catch {
8461 
8462 class MultipleReporters : public SharedImpl<IStreamingReporter> {
8463  typedef std::vector<Ptr<IStreamingReporter> > Reporters;
8464  Reporters m_reporters;
8465 
8466 public:
8467  void add( Ptr<IStreamingReporter> const& reporter ) {
8468  m_reporters.push_back( reporter );
8469  }
8470 
8471 public: // IStreamingReporter
8472 
8473  virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
8474  return m_reporters[0]->getPreferences();
8475  }
8476 
8477  virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
8478  for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8479  it != itEnd;
8480  ++it )
8481  (*it)->noMatchingTestCases( spec );
8482  }
8483 
8484  virtual void testRunStarting( TestRunInfo const& testRunInfo ) CATCH_OVERRIDE {
8485  for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8486  it != itEnd;
8487  ++it )
8488  (*it)->testRunStarting( testRunInfo );
8489  }
8490 
8491  virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
8492  for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8493  it != itEnd;
8494  ++it )
8495  (*it)->testGroupStarting( groupInfo );
8496  }
8497 
8498  virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
8499  for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8500  it != itEnd;
8501  ++it )
8502  (*it)->testCaseStarting( testInfo );
8503  }
8504 
8505  virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
8506  for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8507  it != itEnd;
8508  ++it )
8509  (*it)->sectionStarting( sectionInfo );
8510  }
8511 
8512  virtual void assertionStarting( AssertionInfo const& assertionInfo ) CATCH_OVERRIDE {
8513  for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8514  it != itEnd;
8515  ++it )
8516  (*it)->assertionStarting( assertionInfo );
8517  }
8518 
8519  // The return value indicates if the messages buffer should be cleared:
8520  virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
8521  bool clearBuffer = false;
8522  for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8523  it != itEnd;
8524  ++it )
8525  clearBuffer |= (*it)->assertionEnded( assertionStats );
8526  return clearBuffer;
8527  }
8528 
8529  virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
8530  for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8531  it != itEnd;
8532  ++it )
8533  (*it)->sectionEnded( sectionStats );
8534  }
8535 
8536  virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
8537  for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8538  it != itEnd;
8539  ++it )
8540  (*it)->testCaseEnded( testCaseStats );
8541  }
8542 
8543  virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
8544  for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8545  it != itEnd;
8546  ++it )
8547  (*it)->testGroupEnded( testGroupStats );
8548  }
8549 
8550  virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
8551  for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8552  it != itEnd;
8553  ++it )
8554  (*it)->testRunEnded( testRunStats );
8555  }
8556 
8557  virtual void skipTest( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
8558  for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8559  it != itEnd;
8560  ++it )
8561  (*it)->skipTest( testInfo );
8562  }
8563 
8564  virtual MultipleReporters* tryAsMulti() CATCH_OVERRIDE {
8565  return this;
8566  }
8567 
8568 };
8569 
8570 Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter ) {
8571  Ptr<IStreamingReporter> resultingReporter;
8572 
8573  if( existingReporter ) {
8574  MultipleReporters* multi = existingReporter->tryAsMulti();
8575  if( !multi ) {
8576  multi = new MultipleReporters;
8577  resultingReporter = Ptr<IStreamingReporter>( multi );
8578  if( existingReporter )
8579  multi->add( existingReporter );
8580  }
8581  else
8582  resultingReporter = existingReporter;
8583  multi->add( additionalReporter );
8584  }
8585  else
8586  resultingReporter = additionalReporter;
8587 
8588  return resultingReporter;
8589 }
8590 
8591 } // end namespace Catch
8592 
8593 // #included from: ../reporters/catch_reporter_xml.hpp
8594 #define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED
8595 
8596 // #included from: catch_reporter_bases.hpp
8597 #define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED
8598 
8599 #include <cstring>
8600 
8601 namespace Catch {
8602 
8603  struct StreamingReporterBase : SharedImpl<IStreamingReporter> {
8604 
8605  StreamingReporterBase( ReporterConfig const& _config )
8606  : m_config( _config.fullConfig() ),
8607  stream( _config.stream() )
8608  {
8609  m_reporterPrefs.shouldRedirectStdOut = false;
8610  }
8611 
8612  virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
8613  return m_reporterPrefs;
8614  }
8615 
8616  virtual ~StreamingReporterBase() CATCH_OVERRIDE;
8617 
8618  virtual void noMatchingTestCases( std::string const& ) CATCH_OVERRIDE {}
8619 
8620  virtual void testRunStarting( TestRunInfo const& _testRunInfo ) CATCH_OVERRIDE {
8621  currentTestRunInfo = _testRunInfo;
8622  }
8623  virtual void testGroupStarting( GroupInfo const& _groupInfo ) CATCH_OVERRIDE {
8624  currentGroupInfo = _groupInfo;
8625  }
8626 
8627  virtual void testCaseStarting( TestCaseInfo const& _testInfo ) CATCH_OVERRIDE {
8628  currentTestCaseInfo = _testInfo;
8629  }
8630  virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE {
8631  m_sectionStack.push_back( _sectionInfo );
8632  }
8633 
8634  virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) CATCH_OVERRIDE {
8635  m_sectionStack.pop_back();
8636  }
8637  virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) CATCH_OVERRIDE {
8638  currentTestCaseInfo.reset();
8639  }
8640  virtual void testGroupEnded( TestGroupStats const& /* _testGroupStats */ ) CATCH_OVERRIDE {
8641  currentGroupInfo.reset();
8642  }
8643  virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) CATCH_OVERRIDE {
8644  currentTestCaseInfo.reset();
8645  currentGroupInfo.reset();
8646  currentTestRunInfo.reset();
8647  }
8648 
8649  virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {
8650  // Don't do anything with this by default.
8651  // It can optionally be overridden in the derived class.
8652  }
8653 
8654  Ptr<IConfig const> m_config;
8655  std::ostream& stream;
8656 
8657  LazyStat<TestRunInfo> currentTestRunInfo;
8658  LazyStat<GroupInfo> currentGroupInfo;
8659  LazyStat<TestCaseInfo> currentTestCaseInfo;
8660 
8661  std::vector<SectionInfo> m_sectionStack;
8662  ReporterPreferences m_reporterPrefs;
8663  };
8664 
8665  struct CumulativeReporterBase : SharedImpl<IStreamingReporter> {
8666  template<typename T, typename ChildNodeT>
8667  struct Node : SharedImpl<> {
8668  explicit Node( T const& _value ) : value( _value ) {}
8669  virtual ~Node() {}
8670 
8671  typedef std::vector<Ptr<ChildNodeT> > ChildNodes;
8672  T value;
8673  ChildNodes children;
8674  };
8675  struct SectionNode : SharedImpl<> {
8676  explicit SectionNode( SectionStats const& _stats ) : stats( _stats ) {}
8677  virtual ~SectionNode();
8678 
8679  bool operator == ( SectionNode const& other ) const {
8680  return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo;
8681  }
8682  bool operator == ( Ptr<SectionNode> const& other ) const {
8683  return operator==( *other );
8684  }
8685 
8686  SectionStats stats;
8687  typedef std::vector<Ptr<SectionNode> > ChildSections;
8688  typedef std::vector<AssertionStats> Assertions;
8689  ChildSections childSections;
8690  Assertions assertions;
8691  std::string stdOut;
8692  std::string stdErr;
8693  };
8694 
8695  struct BySectionInfo {
8696  BySectionInfo( SectionInfo const& other ) : m_other( other ) {}
8697  BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {}
8698  bool operator() ( Ptr<SectionNode> const& node ) const {
8699  return node->stats.sectionInfo.lineInfo == m_other.lineInfo;
8700  }
8701  private:
8702  void operator=( BySectionInfo const& );
8703  SectionInfo const& m_other;
8704  };
8705 
8706  typedef Node<TestCaseStats, SectionNode> TestCaseNode;
8707  typedef Node<TestGroupStats, TestCaseNode> TestGroupNode;
8708  typedef Node<TestRunStats, TestGroupNode> TestRunNode;
8709 
8710  CumulativeReporterBase( ReporterConfig const& _config )
8711  : m_config( _config.fullConfig() ),
8712  stream( _config.stream() )
8713  {
8714  m_reporterPrefs.shouldRedirectStdOut = false;
8715  }
8716  ~CumulativeReporterBase();
8717 
8718  virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
8719  return m_reporterPrefs;
8720  }
8721 
8722  virtual void testRunStarting( TestRunInfo const& ) CATCH_OVERRIDE {}
8723  virtual void testGroupStarting( GroupInfo const& ) CATCH_OVERRIDE {}
8724 
8725  virtual void testCaseStarting( TestCaseInfo const& ) CATCH_OVERRIDE {}
8726 
8727  virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
8728  SectionStats incompleteStats( sectionInfo, Counts(), 0, false );
8729  Ptr<SectionNode> node;
8730  if( m_sectionStack.empty() ) {
8731  if( !m_rootSection )
8732  m_rootSection = new SectionNode( incompleteStats );
8733  node = m_rootSection;
8734  }
8735  else {
8736  SectionNode& parentNode = *m_sectionStack.back();
8737  SectionNode::ChildSections::const_iterator it =
8738  std::find_if( parentNode.childSections.begin(),
8739  parentNode.childSections.end(),
8740  BySectionInfo( sectionInfo ) );
8741  if( it == parentNode.childSections.end() ) {
8742  node = new SectionNode( incompleteStats );
8743  parentNode.childSections.push_back( node );
8744  }
8745  else
8746  node = *it;
8747  }
8748  m_sectionStack.push_back( node );
8749  m_deepestSection = node;
8750  }
8751 
8752  virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {}
8753 
8754  virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
8755  assert( !m_sectionStack.empty() );
8756  SectionNode& sectionNode = *m_sectionStack.back();
8757  sectionNode.assertions.push_back( assertionStats );
8758  return true;
8759  }
8760  virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
8761  assert( !m_sectionStack.empty() );
8762  SectionNode& node = *m_sectionStack.back();
8763  node.stats = sectionStats;
8764  m_sectionStack.pop_back();
8765  }
8766  virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
8767  Ptr<TestCaseNode> node = new TestCaseNode( testCaseStats );
8768  assert( m_sectionStack.size() == 0 );
8769  node->children.push_back( m_rootSection );
8770  m_testCases.push_back( node );
8771  m_rootSection.reset();
8772 
8773  assert( m_deepestSection );
8774  m_deepestSection->stdOut = testCaseStats.stdOut;
8775  m_deepestSection->stdErr = testCaseStats.stdErr;
8776  }
8777  virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
8778  Ptr<TestGroupNode> node = new TestGroupNode( testGroupStats );
8779  node->children.swap( m_testCases );
8780  m_testGroups.push_back( node );
8781  }
8782  virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
8783  Ptr<TestRunNode> node = new TestRunNode( testRunStats );
8784  node->children.swap( m_testGroups );
8785  m_testRuns.push_back( node );
8786  testRunEndedCumulative();
8787  }
8788  virtual void testRunEndedCumulative() = 0;
8789 
8790  virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {}
8791 
8792  Ptr<IConfig const> m_config;
8793  std::ostream& stream;
8794  std::vector<AssertionStats> m_assertions;
8795  std::vector<std::vector<Ptr<SectionNode> > > m_sections;
8796  std::vector<Ptr<TestCaseNode> > m_testCases;
8797  std::vector<Ptr<TestGroupNode> > m_testGroups;
8798 
8799  std::vector<Ptr<TestRunNode> > m_testRuns;
8800 
8801  Ptr<SectionNode> m_rootSection;
8802  Ptr<SectionNode> m_deepestSection;
8803  std::vector<Ptr<SectionNode> > m_sectionStack;
8804  ReporterPreferences m_reporterPrefs;
8805 
8806  };
8807 
8808  template<char C>
8809  char const* getLineOfChars() {
8810  static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0};
8811  if( !*line ) {
8812  memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
8813  line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0;
8814  }
8815  return line;
8816  }
8817 
8818  struct TestEventListenerBase : StreamingReporterBase {
8819  TestEventListenerBase( ReporterConfig const& _config )
8820  : StreamingReporterBase( _config )
8821  {}
8822 
8823  virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {}
8824  virtual bool assertionEnded( AssertionStats const& ) CATCH_OVERRIDE {
8825  return false;
8826  }
8827  };
8828 
8829 } // end namespace Catch
8830 
8831 // #included from: ../internal/catch_reporter_registrars.hpp
8832 #define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
8833 
8834 namespace Catch {
8835 
8836  template<typename T>
8837  class LegacyReporterRegistrar {
8838 
8839  class ReporterFactory : public IReporterFactory {
8840  virtual IStreamingReporter* create( ReporterConfig const& config ) const {
8841  return new LegacyReporterAdapter( new T( config ) );
8842  }
8843 
8844  virtual std::string getDescription() const {
8845  return T::getDescription();
8846  }
8847  };
8848 
8849  public:
8850 
8851  LegacyReporterRegistrar( std::string const& name ) {
8852  getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
8853  }
8854  };
8855 
8856  template<typename T>
8857  class ReporterRegistrar {
8858 
8859  class ReporterFactory : public SharedImpl<IReporterFactory> {
8860 
8861  // *** Please Note ***:
8862  // - If you end up here looking at a compiler error because it's trying to register
8863  // your custom reporter class be aware that the native reporter interface has changed
8864  // to IStreamingReporter. The "legacy" interface, IReporter, is still supported via
8865  // an adapter. Just use REGISTER_LEGACY_REPORTER to take advantage of the adapter.
8866  // However please consider updating to the new interface as the old one is now
8867  // deprecated and will probably be removed quite soon!
8868  // Please contact me via github if you have any questions at all about this.
8869  // In fact, ideally, please contact me anyway to let me know you've hit this - as I have
8870  // no idea who is actually using custom reporters at all (possibly no-one!).
8871  // The new interface is designed to minimise exposure to interface changes in the future.
8872  virtual IStreamingReporter* create( ReporterConfig const& config ) const {
8873  return new T( config );
8874  }
8875 
8876  virtual std::string getDescription() const {
8877  return T::getDescription();
8878  }
8879  };
8880 
8881  public:
8882 
8883  ReporterRegistrar( std::string const& name ) {
8884  getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
8885  }
8886  };
8887 
8888  template<typename T>
8889  class ListenerRegistrar {
8890 
8891  class ListenerFactory : public SharedImpl<IReporterFactory> {
8892 
8893  virtual IStreamingReporter* create( ReporterConfig const& config ) const {
8894  return new T( config );
8895  }
8896  virtual std::string getDescription() const {
8897  return "";
8898  }
8899  };
8900 
8901  public:
8902 
8903  ListenerRegistrar() {
8904  getMutableRegistryHub().registerListener( new ListenerFactory() );
8905  }
8906  };
8907 }
8908 
8909 #define INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) \
8910  namespace{ Catch::LegacyReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
8911 
8912 #define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \
8913  namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
8914 
8915 #define INTERNAL_CATCH_REGISTER_LISTENER( listenerType ) \
8916  namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; }
8917 
8918 // #included from: ../internal/catch_xmlwriter.hpp
8919 #define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
8920 
8921 #include <sstream>
8922 #include <string>
8923 #include <vector>
8924 #include <iomanip>
8925 
8926 namespace Catch {
8927 
8928  class XmlEncode {
8929  public:
8930  enum ForWhat { ForTextNodes, ForAttributes };
8931 
8932  XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes )
8933  : m_str( str ),
8934  m_forWhat( forWhat )
8935  {}
8936 
8937  void encodeTo( std::ostream& os ) const {
8938 
8939  // Apostrophe escaping not necessary if we always use " to write attributes
8940  // (see: http://www.w3.org/TR/xml/#syntax)
8941 
8942  for( std::size_t i = 0; i < m_str.size(); ++ i ) {
8943  char c = m_str[i];
8944  switch( c ) {
8945  case '<': os << "&lt;"; break;
8946  case '&': os << "&amp;"; break;
8947 
8948  case '>':
8949  // See: http://www.w3.org/TR/xml/#syntax
8950  if( i > 2 && m_str[i-1] == ']' && m_str[i-2] == ']' )
8951  os << "&gt;";
8952  else
8953  os << c;
8954  break;
8955 
8956  case '\"':
8957  if( m_forWhat == ForAttributes )
8958  os << "&quot;";
8959  else
8960  os << c;
8961  break;
8962 
8963  default:
8964  // Escape control chars - based on contribution by @espenalb in PR #465 and
8965  // by @mrpi PR #588
8966  if ( ( c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' )
8967  os << "&#x" << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>( c ) << ';';
8968  else
8969  os << c;
8970  }
8971  }
8972  }
8973 
8974  friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) {
8975  xmlEncode.encodeTo( os );
8976  return os;
8977  }
8978 
8979  private:
8980  std::string m_str;
8981  ForWhat m_forWhat;
8982  };
8983 
8984  class XmlWriter {
8985  public:
8986 
8987  class ScopedElement {
8988  public:
8989  ScopedElement( XmlWriter* writer )
8990  : m_writer( writer )
8991  {}
8992 
8993  ScopedElement( ScopedElement const& other )
8994  : m_writer( other.m_writer ){
8995  other.m_writer = CATCH_NULL;
8996  }
8997 
8998  ~ScopedElement() {
8999  if( m_writer )
9000  m_writer->endElement();
9001  }
9002 
9003  ScopedElement& writeText( std::string const& text, bool indent = true ) {
9004  m_writer->writeText( text, indent );
9005  return *this;
9006  }
9007 
9008  template<typename T>
9009  ScopedElement& writeAttribute( std::string const& name, T const& attribute ) {
9010  m_writer->writeAttribute( name, attribute );
9011  return *this;
9012  }
9013 
9014  private:
9015  mutable XmlWriter* m_writer;
9016  };
9017 
9018  XmlWriter()
9019  : m_tagIsOpen( false ),
9020  m_needsNewline( false ),
9021  m_os( &Catch::cout() )
9022  {
9023  // We encode control characters, which requires
9024  // XML 1.1
9025  // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
9026  *m_os << "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n";
9027  }
9028 
9029  XmlWriter( std::ostream& os )
9030  : m_tagIsOpen( false ),
9031  m_needsNewline( false ),
9032  m_os( &os )
9033  {
9034  *m_os << "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n";
9035  }
9036 
9037  ~XmlWriter() {
9038  while( !m_tags.empty() )
9039  endElement();
9040  }
9041 
9042  XmlWriter& startElement( std::string const& name ) {
9043  ensureTagClosed();
9044  newlineIfNecessary();
9045  stream() << m_indent << "<" << name;
9046  m_tags.push_back( name );
9047  m_indent += " ";
9048  m_tagIsOpen = true;
9049  return *this;
9050  }
9051 
9052  ScopedElement scopedElement( std::string const& name ) {
9053  ScopedElement scoped( this );
9054  startElement( name );
9055  return scoped;
9056  }
9057 
9058  XmlWriter& endElement() {
9059  newlineIfNecessary();
9060  m_indent = m_indent.substr( 0, m_indent.size()-2 );
9061  if( m_tagIsOpen ) {
9062  stream() << "/>\n";
9063  m_tagIsOpen = false;
9064  }
9065  else {
9066  stream() << m_indent << "</" << m_tags.back() << ">\n";
9067  }
9068  m_tags.pop_back();
9069  return *this;
9070  }
9071 
9072  XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ) {
9073  if( !name.empty() && !attribute.empty() )
9074  stream() << " " << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << "\"";
9075  return *this;
9076  }
9077 
9078  XmlWriter& writeAttribute( std::string const& name, bool attribute ) {
9079  stream() << " " << name << "=\"" << ( attribute ? "true" : "false" ) << "\"";
9080  return *this;
9081  }
9082 
9083  template<typename T>
9084  XmlWriter& writeAttribute( std::string const& name, T const& attribute ) {
9085  std::ostringstream oss;
9086  oss << attribute;
9087  return writeAttribute( name, oss.str() );
9088  }
9089 
9090  XmlWriter& writeText( std::string const& text, bool indent = true ) {
9091  if( !text.empty() ){
9092  bool tagWasOpen = m_tagIsOpen;
9093  ensureTagClosed();
9094  if( tagWasOpen && indent )
9095  stream() << m_indent;
9096  stream() << XmlEncode( text );
9097  m_needsNewline = true;
9098  }
9099  return *this;
9100  }
9101 
9102  XmlWriter& writeComment( std::string const& text ) {
9103  ensureTagClosed();
9104  stream() << m_indent << "<!--" << text << "-->";
9105  m_needsNewline = true;
9106  return *this;
9107  }
9108 
9109  XmlWriter& writeBlankLine() {
9110  ensureTagClosed();
9111  stream() << "\n";
9112  return *this;
9113  }
9114 
9115  void setStream( std::ostream& os ) {
9116  m_os = &os;
9117  }
9118 
9119  private:
9120  XmlWriter( XmlWriter const& );
9121  void operator=( XmlWriter const& );
9122 
9123  std::ostream& stream() {
9124  return *m_os;
9125  }
9126 
9127  void ensureTagClosed() {
9128  if( m_tagIsOpen ) {
9129  stream() << ">\n";
9130  m_tagIsOpen = false;
9131  }
9132  }
9133 
9134  void newlineIfNecessary() {
9135  if( m_needsNewline ) {
9136  stream() << "\n";
9137  m_needsNewline = false;
9138  }
9139  }
9140 
9141  bool m_tagIsOpen;
9142  bool m_needsNewline;
9143  std::vector<std::string> m_tags;
9144  std::string m_indent;
9145  std::ostream* m_os;
9146  };
9147 
9148 }
9149 // #included from: catch_reenable_warnings.h
9150 
9151 #define TWOBLUECUBES_CATCH_REENABLE_WARNINGS_H_INCLUDED
9152 
9153 #ifdef __clang__
9154 # ifdef __ICC // icpc defines the __clang__ macro
9155 # pragma warning(pop)
9156 # else
9157 # pragma clang diagnostic pop
9158 # endif
9159 #elif defined __GNUC__
9160 # pragma GCC diagnostic pop
9161 #endif
9162 
9163 
9164 namespace Catch {
9165  class XmlReporter : public StreamingReporterBase {
9166  public:
9167  XmlReporter( ReporterConfig const& _config )
9168  : StreamingReporterBase( _config ),
9169  m_sectionDepth( 0 )
9170  {
9171  m_reporterPrefs.shouldRedirectStdOut = true;
9172  }
9173 
9174  virtual ~XmlReporter() CATCH_OVERRIDE;
9175 
9176  static std::string getDescription() {
9177  return "Reports test results as an XML document";
9178  }
9179 
9180  public: // StreamingReporterBase
9181 
9182  virtual void noMatchingTestCases( std::string const& s ) CATCH_OVERRIDE {
9183  StreamingReporterBase::noMatchingTestCases( s );
9184  }
9185 
9186  virtual void testRunStarting( TestRunInfo const& testInfo ) CATCH_OVERRIDE {
9187  StreamingReporterBase::testRunStarting( testInfo );
9188  m_xml.setStream( stream );
9189  m_xml.startElement( "Catch" );
9190  if( !m_config->name().empty() )
9191  m_xml.writeAttribute( "name", m_config->name() );
9192  }
9193 
9194  virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
9195  StreamingReporterBase::testGroupStarting( groupInfo );
9196  m_xml.startElement( "Group" )
9197  .writeAttribute( "name", groupInfo.name );
9198  }
9199 
9200  virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
9201  StreamingReporterBase::testCaseStarting(testInfo);
9202  m_xml.startElement( "TestCase" ).writeAttribute( "name", testInfo.name );
9203 
9204  if ( m_config->showDurations() == ShowDurations::Always )
9205  m_testCaseTimer.start();
9206  }
9207 
9208  virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
9209  StreamingReporterBase::sectionStarting( sectionInfo );
9210  if( m_sectionDepth++ > 0 ) {
9211  m_xml.startElement( "Section" )
9212  .writeAttribute( "name", trim( sectionInfo.name ) )
9213  .writeAttribute( "description", sectionInfo.description );
9214  }
9215  }
9216 
9217  virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE { }
9218 
9219  virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
9220  const AssertionResult& assertionResult = assertionStats.assertionResult;
9221 
9222  // Print any info messages in <Info> tags.
9223  if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
9224  for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
9225  it != itEnd;
9226  ++it ) {
9227  if( it->type == ResultWas::Info ) {
9228  m_xml.scopedElement( "Info" )
9229  .writeText( it->message );
9230  } else if ( it->type == ResultWas::Warning ) {
9231  m_xml.scopedElement( "Warning" )
9232  .writeText( it->message );
9233  }
9234  }
9235  }
9236 
9237  // Drop out if result was successful but we're not printing them.
9238  if( !m_config->includeSuccessfulResults() && isOk(assertionResult.getResultType()) )
9239  return true;
9240 
9241  // Print the expression if there is one.
9242  if( assertionResult.hasExpression() ) {
9243  m_xml.startElement( "Expression" )
9244  .writeAttribute( "success", assertionResult.succeeded() )
9245  .writeAttribute( "type", assertionResult.getTestMacroName() )
9246  .writeAttribute( "filename", assertionResult.getSourceInfo().file )
9247  .writeAttribute( "line", assertionResult.getSourceInfo().line );
9248 
9249  m_xml.scopedElement( "Original" )
9250  .writeText( assertionResult.getExpression() );
9251  m_xml.scopedElement( "Expanded" )
9252  .writeText( assertionResult.getExpandedExpression() );
9253  }
9254 
9255  // And... Print a result applicable to each result type.
9256  switch( assertionResult.getResultType() ) {
9257  case ResultWas::ThrewException:
9258  m_xml.scopedElement( "Exception" )
9259  .writeAttribute( "filename", assertionResult.getSourceInfo().file )
9260  .writeAttribute( "line", assertionResult.getSourceInfo().line )
9261  .writeText( assertionResult.getMessage() );
9262  break;
9263  case ResultWas::FatalErrorCondition:
9264  m_xml.scopedElement( "FatalErrorCondition" )
9265  .writeAttribute( "filename", assertionResult.getSourceInfo().file )
9266  .writeAttribute( "line", assertionResult.getSourceInfo().line )
9267  .writeText( assertionResult.getMessage() );
9268  break;
9269  case ResultWas::Info:
9270  m_xml.scopedElement( "Info" )
9271  .writeText( assertionResult.getMessage() );
9272  break;
9273  case ResultWas::Warning:
9274  // Warning will already have been written
9275  break;
9276  case ResultWas::ExplicitFailure:
9277  m_xml.scopedElement( "Failure" )
9278  .writeText( assertionResult.getMessage() );
9279  break;
9280  default:
9281  break;
9282  }
9283 
9284  if( assertionResult.hasExpression() )
9285  m_xml.endElement();
9286 
9287  return true;
9288  }
9289 
9290  virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
9291  StreamingReporterBase::sectionEnded( sectionStats );
9292  if( --m_sectionDepth > 0 ) {
9293  XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" );
9294  e.writeAttribute( "successes", sectionStats.assertions.passed );
9295  e.writeAttribute( "failures", sectionStats.assertions.failed );
9296  e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk );
9297 
9298  if ( m_config->showDurations() == ShowDurations::Always )
9299  e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds );
9300 
9301  m_xml.endElement();
9302  }
9303  }
9304 
9305  virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
9306  StreamingReporterBase::testCaseEnded( testCaseStats );
9307  XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" );
9308  e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() );
9309 
9310  if ( m_config->showDurations() == ShowDurations::Always )
9311  e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() );
9312 
9313  m_xml.endElement();
9314  }
9315 
9316  virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
9317  StreamingReporterBase::testGroupEnded( testGroupStats );
9318  // TODO: Check testGroupStats.aborting and act accordingly.
9319  m_xml.scopedElement( "OverallResults" )
9320  .writeAttribute( "successes", testGroupStats.totals.assertions.passed )
9321  .writeAttribute( "failures", testGroupStats.totals.assertions.failed )
9322  .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk );
9323  m_xml.endElement();
9324  }
9325 
9326  virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
9327  StreamingReporterBase::testRunEnded( testRunStats );
9328  m_xml.scopedElement( "OverallResults" )
9329  .writeAttribute( "successes", testRunStats.totals.assertions.passed )
9330  .writeAttribute( "failures", testRunStats.totals.assertions.failed )
9331  .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk );
9332  m_xml.endElement();
9333  }
9334 
9335  private:
9336  Timer m_testCaseTimer;
9337  XmlWriter m_xml;
9338  int m_sectionDepth;
9339  };
9340 
9341  INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter )
9342 
9343 } // end namespace Catch
9344 
9345 // #included from: ../reporters/catch_reporter_junit.hpp
9346 #define TWOBLUECUBES_CATCH_REPORTER_JUNIT_HPP_INCLUDED
9347 
9348 #include <assert.h>
9349 
9350 namespace Catch {
9351 
9352  class JunitReporter : public CumulativeReporterBase {
9353  public:
9354  JunitReporter( ReporterConfig const& _config )
9355  : CumulativeReporterBase( _config ),
9356  xml( _config.stream() )
9357  {
9358  m_reporterPrefs.shouldRedirectStdOut = true;
9359  }
9360 
9361  virtual ~JunitReporter() CATCH_OVERRIDE;
9362 
9363  static std::string getDescription() {
9364  return "Reports test results in an XML format that looks like Ant's junitreport target";
9365  }
9366 
9367  virtual void noMatchingTestCases( std::string const& /*spec*/ ) CATCH_OVERRIDE {}
9368 
9369  virtual void testRunStarting( TestRunInfo const& runInfo ) CATCH_OVERRIDE {
9370  CumulativeReporterBase::testRunStarting( runInfo );
9371  xml.startElement( "testsuites" );
9372  }
9373 
9374  virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
9375  suiteTimer.start();
9376  stdOutForSuite.str("");
9377  stdErrForSuite.str("");
9378  unexpectedExceptions = 0;
9379  CumulativeReporterBase::testGroupStarting( groupInfo );
9380  }
9381 
9382  virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
9383  if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException )
9384  unexpectedExceptions++;
9385  return CumulativeReporterBase::assertionEnded( assertionStats );
9386  }
9387 
9388  virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
9389  stdOutForSuite << testCaseStats.stdOut;
9390  stdErrForSuite << testCaseStats.stdErr;
9391  CumulativeReporterBase::testCaseEnded( testCaseStats );
9392  }
9393 
9394  virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
9395  double suiteTime = suiteTimer.getElapsedSeconds();
9396  CumulativeReporterBase::testGroupEnded( testGroupStats );
9397  writeGroup( *m_testGroups.back(), suiteTime );
9398  }
9399 
9400  virtual void testRunEndedCumulative() CATCH_OVERRIDE {
9401  xml.endElement();
9402  }
9403 
9404  void writeGroup( TestGroupNode const& groupNode, double suiteTime ) {
9405  XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" );
9406  TestGroupStats const& stats = groupNode.value;
9407  xml.writeAttribute( "name", stats.groupInfo.name );
9408  xml.writeAttribute( "errors", unexpectedExceptions );
9409  xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions );
9410  xml.writeAttribute( "tests", stats.totals.assertions.total() );
9411  xml.writeAttribute( "hostname", "tbd" ); // !TBD
9412  if( m_config->showDurations() == ShowDurations::Never )
9413  xml.writeAttribute( "time", "" );
9414  else
9415  xml.writeAttribute( "time", suiteTime );
9416  xml.writeAttribute( "timestamp", "tbd" ); // !TBD
9417 
9418  // Write test cases
9419  for( TestGroupNode::ChildNodes::const_iterator
9420  it = groupNode.children.begin(), itEnd = groupNode.children.end();
9421  it != itEnd;
9422  ++it )
9423  writeTestCase( **it );
9424 
9425  xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite.str() ), false );
9426  xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false );
9427  }
9428 
9429  void writeTestCase( TestCaseNode const& testCaseNode ) {
9430  TestCaseStats const& stats = testCaseNode.value;
9431 
9432  // All test cases have exactly one section - which represents the
9433  // test case itself. That section may have 0-n nested sections
9434  assert( testCaseNode.children.size() == 1 );
9435  SectionNode const& rootSection = *testCaseNode.children.front();
9436 
9437  std::string className = stats.testInfo.className;
9438 
9439  if( className.empty() ) {
9440  if( rootSection.childSections.empty() )
9441  className = "global";
9442  }
9443  writeSection( className, "", rootSection );
9444  }
9445 
9446  void writeSection( std::string const& className,
9447  std::string const& rootName,
9448  SectionNode const& sectionNode ) {
9449  std::string name = trim( sectionNode.stats.sectionInfo.name );
9450  if( !rootName.empty() )
9451  name = rootName + "/" + name;
9452 
9453  if( !sectionNode.assertions.empty() ||
9454  !sectionNode.stdOut.empty() ||
9455  !sectionNode.stdErr.empty() ) {
9456  XmlWriter::ScopedElement e = xml.scopedElement( "testcase" );
9457  if( className.empty() ) {
9458  xml.writeAttribute( "classname", name );
9459  xml.writeAttribute( "name", "root" );
9460  }
9461  else {
9462  xml.writeAttribute( "classname", className );
9463  xml.writeAttribute( "name", name );
9464  }
9465  xml.writeAttribute( "time", Catch::toString( sectionNode.stats.durationInSeconds ) );
9466 
9467  writeAssertions( sectionNode );
9468 
9469  if( !sectionNode.stdOut.empty() )
9470  xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false );
9471  if( !sectionNode.stdErr.empty() )
9472  xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false );
9473  }
9474  for( SectionNode::ChildSections::const_iterator
9475  it = sectionNode.childSections.begin(),
9476  itEnd = sectionNode.childSections.end();
9477  it != itEnd;
9478  ++it )
9479  if( className.empty() )
9480  writeSection( name, "", **it );
9481  else
9482  writeSection( className, name, **it );
9483  }
9484 
9485  void writeAssertions( SectionNode const& sectionNode ) {
9486  for( SectionNode::Assertions::const_iterator
9487  it = sectionNode.assertions.begin(), itEnd = sectionNode.assertions.end();
9488  it != itEnd;
9489  ++it )
9490  writeAssertion( *it );
9491  }
9492  void writeAssertion( AssertionStats const& stats ) {
9493  AssertionResult const& result = stats.assertionResult;
9494  if( !result.isOk() ) {
9495  std::string elementName;
9496  switch( result.getResultType() ) {
9497  case ResultWas::ThrewException:
9498  case ResultWas::FatalErrorCondition:
9499  elementName = "error";
9500  break;
9501  case ResultWas::ExplicitFailure:
9502  elementName = "failure";
9503  break;
9504  case ResultWas::ExpressionFailed:
9505  elementName = "failure";
9506  break;
9507  case ResultWas::DidntThrowException:
9508  elementName = "failure";
9509  break;
9510 
9511  // We should never see these here:
9512  case ResultWas::Info:
9513  case ResultWas::Warning:
9514  case ResultWas::Ok:
9515  case ResultWas::Unknown:
9516  case ResultWas::FailureBit:
9517  case ResultWas::Exception:
9518  elementName = "internalError";
9519  break;
9520  }
9521 
9522  XmlWriter::ScopedElement e = xml.scopedElement( elementName );
9523 
9524  xml.writeAttribute( "message", result.getExpandedExpression() );
9525  xml.writeAttribute( "type", result.getTestMacroName() );
9526 
9527  std::ostringstream oss;
9528  if( !result.getMessage().empty() )
9529  oss << result.getMessage() << "\n";
9530  for( std::vector<MessageInfo>::const_iterator
9531  it = stats.infoMessages.begin(),
9532  itEnd = stats.infoMessages.end();
9533  it != itEnd;
9534  ++it )
9535  if( it->type == ResultWas::Info )
9536  oss << it->message << "\n";
9537 
9538  oss << "at " << result.getSourceInfo();
9539  xml.writeText( oss.str(), false );
9540  }
9541  }
9542 
9543  XmlWriter xml;
9544  Timer suiteTimer;
9545  std::ostringstream stdOutForSuite;
9546  std::ostringstream stdErrForSuite;
9547  unsigned int unexpectedExceptions;
9548  };
9549 
9550  INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter )
9551 
9552 } // end namespace Catch
9553 
9554 // #included from: ../reporters/catch_reporter_console.hpp
9555 #define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_HPP_INCLUDED
9556 
9557 namespace Catch {
9558 
9559  struct ConsoleReporter : StreamingReporterBase {
9560  ConsoleReporter( ReporterConfig const& _config )
9561  : StreamingReporterBase( _config ),
9562  m_headerPrinted( false )
9563  {}
9564 
9565  virtual ~ConsoleReporter() CATCH_OVERRIDE;
9566  static std::string getDescription() {
9567  return "Reports test results as plain lines of text";
9568  }
9569 
9570  virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
9571  stream << "No test cases matched '" << spec << "'" << std::endl;
9572  }
9573 
9574  virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {
9575  }
9576 
9577  virtual bool assertionEnded( AssertionStats const& _assertionStats ) CATCH_OVERRIDE {
9578  AssertionResult const& result = _assertionStats.assertionResult;
9579 
9580  bool printInfoMessages = true;
9581 
9582  // Drop out if result was successful and we're not printing those
9583  if( !m_config->includeSuccessfulResults() && result.isOk() ) {
9584  if( result.getResultType() != ResultWas::Warning )
9585  return false;
9586  printInfoMessages = false;
9587  }
9588 
9589  lazyPrint();
9590 
9591  AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
9592  printer.print();
9593  stream << std::endl;
9594  return true;
9595  }
9596 
9597  virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE {
9598  m_headerPrinted = false;
9599  StreamingReporterBase::sectionStarting( _sectionInfo );
9600  }
9601  virtual void sectionEnded( SectionStats const& _sectionStats ) CATCH_OVERRIDE {
9602  if( _sectionStats.missingAssertions ) {
9603  lazyPrint();
9604  Colour colour( Colour::ResultError );
9605  if( m_sectionStack.size() > 1 )
9606  stream << "\nNo assertions in section";
9607  else
9608  stream << "\nNo assertions in test case";
9609  stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
9610  }
9611  if( m_headerPrinted ) {
9612  if( m_config->showDurations() == ShowDurations::Always )
9613  stream << "Completed in " << _sectionStats.durationInSeconds << "s" << std::endl;
9614  m_headerPrinted = false;
9615  }
9616  else {
9617  if( m_config->showDurations() == ShowDurations::Always )
9618  stream << _sectionStats.sectionInfo.name << " completed in " << _sectionStats.durationInSeconds << "s" << std::endl;
9619  }
9620  StreamingReporterBase::sectionEnded( _sectionStats );
9621  }
9622 
9623  virtual void testCaseEnded( TestCaseStats const& _testCaseStats ) CATCH_OVERRIDE {
9624  StreamingReporterBase::testCaseEnded( _testCaseStats );
9625  m_headerPrinted = false;
9626  }
9627  virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) CATCH_OVERRIDE {
9628  if( currentGroupInfo.used ) {
9629  printSummaryDivider();
9630  stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n";
9631  printTotals( _testGroupStats.totals );
9632  stream << "\n" << std::endl;
9633  }
9634  StreamingReporterBase::testGroupEnded( _testGroupStats );
9635  }
9636  virtual void testRunEnded( TestRunStats const& _testRunStats ) CATCH_OVERRIDE {
9637  printTotalsDivider( _testRunStats.totals );
9638  printTotals( _testRunStats.totals );
9639  stream << std::endl;
9640  StreamingReporterBase::testRunEnded( _testRunStats );
9641  }
9642 
9643  private:
9644 
9645  class AssertionPrinter {
9646  void operator= ( AssertionPrinter const& );
9647  public:
9648  AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
9649  : stream( _stream ),
9650  stats( _stats ),
9651  result( _stats.assertionResult ),
9652  colour( Colour::None ),
9653  message( result.getMessage() ),
9654  messages( _stats.infoMessages ),
9655  printInfoMessages( _printInfoMessages )
9656  {
9657  switch( result.getResultType() ) {
9658  case ResultWas::Ok:
9659  colour = Colour::Success;
9660  passOrFail = "PASSED";
9661  //if( result.hasMessage() )
9662  if( _stats.infoMessages.size() == 1 )
9663  messageLabel = "with message";
9664  if( _stats.infoMessages.size() > 1 )
9665  messageLabel = "with messages";
9666  break;
9667  case ResultWas::ExpressionFailed:
9668  if( result.isOk() ) {
9669  colour = Colour::Success;
9670  passOrFail = "FAILED - but was ok";
9671  }
9672  else {
9673  colour = Colour::Error;
9674  passOrFail = "FAILED";
9675  }
9676  if( _stats.infoMessages.size() == 1 )
9677  messageLabel = "with message";
9678  if( _stats.infoMessages.size() > 1 )
9679  messageLabel = "with messages";
9680  break;
9681  case ResultWas::ThrewException:
9682  colour = Colour::Error;
9683  passOrFail = "FAILED";
9684  messageLabel = "due to unexpected exception with message";
9685  break;
9686  case ResultWas::FatalErrorCondition:
9687  colour = Colour::Error;
9688  passOrFail = "FAILED";
9689  messageLabel = "due to a fatal error condition";
9690  break;
9691  case ResultWas::DidntThrowException:
9692  colour = Colour::Error;
9693  passOrFail = "FAILED";
9694  messageLabel = "because no exception was thrown where one was expected";
9695  break;
9696  case ResultWas::Info:
9697  messageLabel = "info";
9698  break;
9699  case ResultWas::Warning:
9700  messageLabel = "warning";
9701  break;
9702  case ResultWas::ExplicitFailure:
9703  passOrFail = "FAILED";
9704  colour = Colour::Error;
9705  if( _stats.infoMessages.size() == 1 )
9706  messageLabel = "explicitly with message";
9707  if( _stats.infoMessages.size() > 1 )
9708  messageLabel = "explicitly with messages";
9709  break;
9710  // These cases are here to prevent compiler warnings
9711  case ResultWas::Unknown:
9712  case ResultWas::FailureBit:
9713  case ResultWas::Exception:
9714  passOrFail = "** internal error **";
9715  colour = Colour::Error;
9716  break;
9717  }
9718  }
9719 
9720  void print() const {
9721  printSourceInfo();
9722  if( stats.totals.assertions.total() > 0 ) {
9723  if( result.isOk() )
9724  stream << "\n";
9725  printResultType();
9726  printOriginalExpression();
9727  printReconstructedExpression();
9728  }
9729  else {
9730  stream << "\n";
9731  }
9732  printMessage();
9733  }
9734 
9735  private:
9736  void printResultType() const {
9737  if( !passOrFail.empty() ) {
9738  Colour colourGuard( colour );
9739  stream << passOrFail << ":\n";
9740  }
9741  }
9742  void printOriginalExpression() const {
9743  if( result.hasExpression() ) {
9744  Colour colourGuard( Colour::OriginalExpression );
9745  stream << " ";
9746  stream << result.getExpressionInMacro();
9747  stream << "\n";
9748  }
9749  }
9750  void printReconstructedExpression() const {
9751  if( result.hasExpandedExpression() ) {
9752  stream << "with expansion:\n";
9753  Colour colourGuard( Colour::ReconstructedExpression );
9754  stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << "\n";
9755  }
9756  }
9757  void printMessage() const {
9758  if( !messageLabel.empty() )
9759  stream << messageLabel << ":" << "\n";
9760  for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
9761  it != itEnd;
9762  ++it ) {
9763  // If this assertion is a warning ignore any INFO messages
9764  if( printInfoMessages || it->type != ResultWas::Info )
9765  stream << Text( it->message, TextAttributes().setIndent(2) ) << "\n";
9766  }
9767  }
9768  void printSourceInfo() const {
9769  Colour colourGuard( Colour::FileName );
9770  stream << result.getSourceInfo() << ": ";
9771  }
9772 
9773  std::ostream& stream;
9774  AssertionStats const& stats;
9775  AssertionResult const& result;
9776  Colour::Code colour;
9777  std::string passOrFail;
9778  std::string messageLabel;
9779  std::string message;
9780  std::vector<MessageInfo> messages;
9781  bool printInfoMessages;
9782  };
9783 
9784  void lazyPrint() {
9785 
9786  if( !currentTestRunInfo.used )
9787  lazyPrintRunInfo();
9788  if( !currentGroupInfo.used )
9789  lazyPrintGroupInfo();
9790 
9791  if( !m_headerPrinted ) {
9792  printTestCaseAndSectionHeader();
9793  m_headerPrinted = true;
9794  }
9795  }
9796  void lazyPrintRunInfo() {
9797  stream << "\n" << getLineOfChars<'~'>() << "\n";
9798  Colour colour( Colour::SecondaryText );
9799  stream << currentTestRunInfo->name
9800  << " is a Catch v" << libraryVersion << " host application.\n"
9801  << "Run with -? for options\n\n";
9802 
9803  if( m_config->rngSeed() != 0 )
9804  stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n";
9805 
9806  currentTestRunInfo.used = true;
9807  }
9808  void lazyPrintGroupInfo() {
9809  if( !currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1 ) {
9810  printClosedHeader( "Group: " + currentGroupInfo->name );
9811  currentGroupInfo.used = true;
9812  }
9813  }
9814  void printTestCaseAndSectionHeader() {
9815  assert( !m_sectionStack.empty() );
9816  printOpenHeader( currentTestCaseInfo->name );
9817 
9818  if( m_sectionStack.size() > 1 ) {
9819  Colour colourGuard( Colour::Headers );
9820 
9821  std::vector<SectionInfo>::const_iterator
9822  it = m_sectionStack.begin()+1, // Skip first section (test case)
9823  itEnd = m_sectionStack.end();
9824  for( ; it != itEnd; ++it )
9825  printHeaderString( it->name, 2 );
9826  }
9827 
9828  SourceLineInfo lineInfo = m_sectionStack.front().lineInfo;
9829 
9830  if( !lineInfo.empty() ){
9831  stream << getLineOfChars<'-'>() << "\n";
9832  Colour colourGuard( Colour::FileName );
9833  stream << lineInfo << "\n";
9834  }
9835  stream << getLineOfChars<'.'>() << "\n" << std::endl;
9836  }
9837 
9838  void printClosedHeader( std::string const& _name ) {
9839  printOpenHeader( _name );
9840  stream << getLineOfChars<'.'>() << "\n";
9841  }
9842  void printOpenHeader( std::string const& _name ) {
9843  stream << getLineOfChars<'-'>() << "\n";
9844  {
9845  Colour colourGuard( Colour::Headers );
9846  printHeaderString( _name );
9847  }
9848  }
9849 
9850  // if string has a : in first line will set indent to follow it on
9851  // subsequent lines
9852  void printHeaderString( std::string const& _string, std::size_t indent = 0 ) {
9853  std::size_t i = _string.find( ": " );
9854  if( i != std::string::npos )
9855  i+=2;
9856  else
9857  i = 0;
9858  stream << Text( _string, TextAttributes()
9859  .setIndent( indent+i)
9860  .setInitialIndent( indent ) ) << "\n";
9861  }
9862 
9863  struct SummaryColumn {
9864 
9865  SummaryColumn( std::string const& _label, Colour::Code _colour )
9866  : label( _label ),
9867  colour( _colour )
9868  {}
9869  SummaryColumn addRow( std::size_t count ) {
9870  std::ostringstream oss;
9871  oss << count;
9872  std::string row = oss.str();
9873  for( std::vector<std::string>::iterator it = rows.begin(); it != rows.end(); ++it ) {
9874  while( it->size() < row.size() )
9875  *it = " " + *it;
9876  while( it->size() > row.size() )
9877  row = " " + row;
9878  }
9879  rows.push_back( row );
9880  return *this;
9881  }
9882 
9883  std::string label;
9884  Colour::Code colour;
9885  std::vector<std::string> rows;
9886 
9887  };
9888 
9889  void printTotals( Totals const& totals ) {
9890  if( totals.testCases.total() == 0 ) {
9891  stream << Colour( Colour::Warning ) << "No tests ran\n";
9892  }
9893  else if( totals.assertions.total() > 0 && totals.testCases.allPassed() ) {
9894  stream << Colour( Colour::ResultSuccess ) << "All tests passed";
9895  stream << " ("
9896  << pluralise( totals.assertions.passed, "assertion" ) << " in "
9897  << pluralise( totals.testCases.passed, "test case" ) << ")"
9898  << "\n";
9899  }
9900  else {
9901 
9902  std::vector<SummaryColumn> columns;
9903  columns.push_back( SummaryColumn( "", Colour::None )
9904  .addRow( totals.testCases.total() )
9905  .addRow( totals.assertions.total() ) );
9906  columns.push_back( SummaryColumn( "passed", Colour::Success )
9907  .addRow( totals.testCases.passed )
9908  .addRow( totals.assertions.passed ) );
9909  columns.push_back( SummaryColumn( "failed", Colour::ResultError )
9910  .addRow( totals.testCases.failed )
9911  .addRow( totals.assertions.failed ) );
9912  columns.push_back( SummaryColumn( "failed as expected", Colour::ResultExpectedFailure )
9913  .addRow( totals.testCases.failedButOk )
9914  .addRow( totals.assertions.failedButOk ) );
9915 
9916  printSummaryRow( "test cases", columns, 0 );
9917  printSummaryRow( "assertions", columns, 1 );
9918  }
9919  }
9920  void printSummaryRow( std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row ) {
9921  for( std::vector<SummaryColumn>::const_iterator it = cols.begin(); it != cols.end(); ++it ) {
9922  std::string value = it->rows[row];
9923  if( it->label.empty() ) {
9924  stream << label << ": ";
9925  if( value != "0" )
9926  stream << value;
9927  else
9928  stream << Colour( Colour::Warning ) << "- none -";
9929  }
9930  else if( value != "0" ) {
9931  stream << Colour( Colour::LightGrey ) << " | ";
9932  stream << Colour( it->colour )
9933  << value << " " << it->label;
9934  }
9935  }
9936  stream << "\n";
9937  }
9938 
9939  static std::size_t makeRatio( std::size_t number, std::size_t total ) {
9940  std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0;
9941  return ( ratio == 0 && number > 0 ) ? 1 : ratio;
9942  }
9943  static std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) {
9944  if( i > j && i > k )
9945  return i;
9946  else if( j > k )
9947  return j;
9948  else
9949  return k;
9950  }
9951 
9952  void printTotalsDivider( Totals const& totals ) {
9953  if( totals.testCases.total() > 0 ) {
9954  std::size_t failedRatio = makeRatio( totals.testCases.failed, totals.testCases.total() );
9955  std::size_t failedButOkRatio = makeRatio( totals.testCases.failedButOk, totals.testCases.total() );
9956  std::size_t passedRatio = makeRatio( totals.testCases.passed, totals.testCases.total() );
9957  while( failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH-1 )
9958  findMax( failedRatio, failedButOkRatio, passedRatio )++;
9959  while( failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH-1 )
9960  findMax( failedRatio, failedButOkRatio, passedRatio )--;
9961 
9962  stream << Colour( Colour::Error ) << std::string( failedRatio, '=' );
9963  stream << Colour( Colour::ResultExpectedFailure ) << std::string( failedButOkRatio, '=' );
9964  if( totals.testCases.allPassed() )
9965  stream << Colour( Colour::ResultSuccess ) << std::string( passedRatio, '=' );
9966  else
9967  stream << Colour( Colour::Success ) << std::string( passedRatio, '=' );
9968  }
9969  else {
9970  stream << Colour( Colour::Warning ) << std::string( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' );
9971  }
9972  stream << "\n";
9973  }
9974  void printSummaryDivider() {
9975  stream << getLineOfChars<'-'>() << "\n";
9976  }
9977 
9978  private:
9979  bool m_headerPrinted;
9980  };
9981 
9982  INTERNAL_CATCH_REGISTER_REPORTER( "console", ConsoleReporter )
9983 
9984 } // end namespace Catch
9985 
9986 // #included from: ../reporters/catch_reporter_compact.hpp
9987 #define TWOBLUECUBES_CATCH_REPORTER_COMPACT_HPP_INCLUDED
9988 
9989 namespace Catch {
9990 
9991  struct CompactReporter : StreamingReporterBase {
9992 
9993  CompactReporter( ReporterConfig const& _config )
9994  : StreamingReporterBase( _config )
9995  {}
9996 
9997  virtual ~CompactReporter();
9998 
9999  static std::string getDescription() {
10000  return "Reports test results on a single line, suitable for IDEs";
10001  }
10002 
10003  virtual ReporterPreferences getPreferences() const {
10004  ReporterPreferences prefs;
10005  prefs.shouldRedirectStdOut = false;
10006  return prefs;
10007  }
10008 
10009  virtual void noMatchingTestCases( std::string const& spec ) {
10010  stream << "No test cases matched '" << spec << "'" << std::endl;
10011  }
10012 
10013  virtual void assertionStarting( AssertionInfo const& ) {
10014  }
10015 
10016  virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
10017  AssertionResult const& result = _assertionStats.assertionResult;
10018 
10019  bool printInfoMessages = true;
10020 
10021  // Drop out if result was successful and we're not printing those
10022  if( !m_config->includeSuccessfulResults() && result.isOk() ) {
10023  if( result.getResultType() != ResultWas::Warning )
10024  return false;
10025  printInfoMessages = false;
10026  }
10027 
10028  AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
10029  printer.print();
10030 
10031  stream << std::endl;
10032  return true;
10033  }
10034 
10035  virtual void testRunEnded( TestRunStats const& _testRunStats ) {
10036  printTotals( _testRunStats.totals );
10037  stream << "\n" << std::endl;
10038  StreamingReporterBase::testRunEnded( _testRunStats );
10039  }
10040 
10041  private:
10042  class AssertionPrinter {
10043  void operator= ( AssertionPrinter const& );
10044  public:
10045  AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
10046  : stream( _stream )
10047  , stats( _stats )
10048  , result( _stats.assertionResult )
10049  , messages( _stats.infoMessages )
10050  , itMessage( _stats.infoMessages.begin() )
10051  , printInfoMessages( _printInfoMessages )
10052  {}
10053 
10054  void print() {
10055  printSourceInfo();
10056 
10057  itMessage = messages.begin();
10058 
10059  switch( result.getResultType() ) {
10060  case ResultWas::Ok:
10061  printResultType( Colour::ResultSuccess, passedString() );
10062  printOriginalExpression();
10063  printReconstructedExpression();
10064  if ( ! result.hasExpression() )
10065  printRemainingMessages( Colour::None );
10066  else
10067  printRemainingMessages();
10068  break;
10069  case ResultWas::ExpressionFailed:
10070  if( result.isOk() )
10071  printResultType( Colour::ResultSuccess, failedString() + std::string( " - but was ok" ) );
10072  else
10073  printResultType( Colour::Error, failedString() );
10074  printOriginalExpression();
10075  printReconstructedExpression();
10076  printRemainingMessages();
10077  break;
10078  case ResultWas::ThrewException:
10079  printResultType( Colour::Error, failedString() );
10080  printIssue( "unexpected exception with message:" );
10081  printMessage();
10082  printExpressionWas();
10083  printRemainingMessages();
10084  break;
10085  case ResultWas::FatalErrorCondition:
10086  printResultType( Colour::Error, failedString() );
10087  printIssue( "fatal error condition with message:" );
10088  printMessage();
10089  printExpressionWas();
10090  printRemainingMessages();
10091  break;
10092  case ResultWas::DidntThrowException:
10093  printResultType( Colour::Error, failedString() );
10094  printIssue( "expected exception, got none" );
10095  printExpressionWas();
10096  printRemainingMessages();
10097  break;
10098  case ResultWas::Info:
10099  printResultType( Colour::None, "info" );
10100  printMessage();
10101  printRemainingMessages();
10102  break;
10103  case ResultWas::Warning:
10104  printResultType( Colour::None, "warning" );
10105  printMessage();
10106  printRemainingMessages();
10107  break;
10108  case ResultWas::ExplicitFailure:
10109  printResultType( Colour::Error, failedString() );
10110  printIssue( "explicitly" );
10111  printRemainingMessages( Colour::None );
10112  break;
10113  // These cases are here to prevent compiler warnings
10114  case ResultWas::Unknown:
10115  case ResultWas::FailureBit:
10116  case ResultWas::Exception:
10117  printResultType( Colour::Error, "** internal error **" );
10118  break;
10119  }
10120  }
10121 
10122  private:
10123  // Colour::LightGrey
10124 
10125  static Colour::Code dimColour() { return Colour::FileName; }
10126 
10127 #ifdef CATCH_PLATFORM_MAC
10128  static const char* failedString() { return "FAILED"; }
10129  static const char* passedString() { return "PASSED"; }
10130 #else
10131  static const char* failedString() { return "failed"; }
10132  static const char* passedString() { return "passed"; }
10133 #endif
10134 
10135  void printSourceInfo() const {
10136  Colour colourGuard( Colour::FileName );
10137  stream << result.getSourceInfo() << ":";
10138  }
10139 
10140  void printResultType( Colour::Code colour, std::string passOrFail ) const {
10141  if( !passOrFail.empty() ) {
10142  {
10143  Colour colourGuard( colour );
10144  stream << " " << passOrFail;
10145  }
10146  stream << ":";
10147  }
10148  }
10149 
10150  void printIssue( std::string issue ) const {
10151  stream << " " << issue;
10152  }
10153 
10154  void printExpressionWas() {
10155  if( result.hasExpression() ) {
10156  stream << ";";
10157  {
10158  Colour colour( dimColour() );
10159  stream << " expression was:";
10160  }
10161  printOriginalExpression();
10162  }
10163  }
10164 
10165  void printOriginalExpression() const {
10166  if( result.hasExpression() ) {
10167  stream << " " << result.getExpression();
10168  }
10169  }
10170 
10171  void printReconstructedExpression() const {
10172  if( result.hasExpandedExpression() ) {
10173  {
10174  Colour colour( dimColour() );
10175  stream << " for: ";
10176  }
10177  stream << result.getExpandedExpression();
10178  }
10179  }
10180 
10181  void printMessage() {
10182  if ( itMessage != messages.end() ) {
10183  stream << " '" << itMessage->message << "'";
10184  ++itMessage;
10185  }
10186  }
10187 
10188  void printRemainingMessages( Colour::Code colour = dimColour() ) {
10189  if ( itMessage == messages.end() )
10190  return;
10191 
10192  // using messages.end() directly yields compilation error:
10193  std::vector<MessageInfo>::const_iterator itEnd = messages.end();
10194  const std::size_t N = static_cast<std::size_t>( std::distance( itMessage, itEnd ) );
10195 
10196  {
10197  Colour colourGuard( colour );
10198  stream << " with " << pluralise( N, "message" ) << ":";
10199  }
10200 
10201  for(; itMessage != itEnd; ) {
10202  // If this assertion is a warning ignore any INFO messages
10203  if( printInfoMessages || itMessage->type != ResultWas::Info ) {
10204  stream << " '" << itMessage->message << "'";
10205  if ( ++itMessage != itEnd ) {
10206  Colour colourGuard( dimColour() );
10207  stream << " and";
10208  }
10209  }
10210  }
10211  }
10212 
10213  private:
10214  std::ostream& stream;
10215  AssertionStats const& stats;
10216  AssertionResult const& result;
10217  std::vector<MessageInfo> messages;
10218  std::vector<MessageInfo>::const_iterator itMessage;
10219  bool printInfoMessages;
10220  };
10221 
10222  // Colour, message variants:
10223  // - white: No tests ran.
10224  // - red: Failed [both/all] N test cases, failed [both/all] M assertions.
10225  // - white: Passed [both/all] N test cases (no assertions).
10226  // - red: Failed N tests cases, failed M assertions.
10227  // - green: Passed [both/all] N tests cases with M assertions.
10228 
10229  std::string bothOrAll( std::size_t count ) const {
10230  return count == 1 ? "" : count == 2 ? "both " : "all " ;
10231  }
10232 
10233  void printTotals( const Totals& totals ) const {
10234  if( totals.testCases.total() == 0 ) {
10235  stream << "No tests ran.";
10236  }
10237  else if( totals.testCases.failed == totals.testCases.total() ) {
10238  Colour colour( Colour::ResultError );
10239  const std::string qualify_assertions_failed =
10240  totals.assertions.failed == totals.assertions.total() ?
10241  bothOrAll( totals.assertions.failed ) : "";
10242  stream <<
10243  "Failed " << bothOrAll( totals.testCases.failed )
10244  << pluralise( totals.testCases.failed, "test case" ) << ", "
10245  "failed " << qualify_assertions_failed <<
10246  pluralise( totals.assertions.failed, "assertion" ) << ".";
10247  }
10248  else if( totals.assertions.total() == 0 ) {
10249  stream <<
10250  "Passed " << bothOrAll( totals.testCases.total() )
10251  << pluralise( totals.testCases.total(), "test case" )
10252  << " (no assertions).";
10253  }
10254  else if( totals.assertions.failed ) {
10255  Colour colour( Colour::ResultError );
10256  stream <<
10257  "Failed " << pluralise( totals.testCases.failed, "test case" ) << ", "
10258  "failed " << pluralise( totals.assertions.failed, "assertion" ) << ".";
10259  }
10260  else {
10261  Colour colour( Colour::ResultSuccess );
10262  stream <<
10263  "Passed " << bothOrAll( totals.testCases.passed )
10264  << pluralise( totals.testCases.passed, "test case" ) <<
10265  " with " << pluralise( totals.assertions.passed, "assertion" ) << ".";
10266  }
10267  }
10268  };
10269 
10270  INTERNAL_CATCH_REGISTER_REPORTER( "compact", CompactReporter )
10271 
10272 } // end namespace Catch
10273 
10274 namespace Catch {
10275  // These are all here to avoid warnings about not having any out of line
10276  // virtual methods
10277  NonCopyable::~NonCopyable() {}
10278  IShared::~IShared() {}
10279  IStream::~IStream() CATCH_NOEXCEPT {}
10280  FileStream::~FileStream() CATCH_NOEXCEPT {}
10281  CoutStream::~CoutStream() CATCH_NOEXCEPT {}
10282  DebugOutStream::~DebugOutStream() CATCH_NOEXCEPT {}
10283  StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {}
10284  IContext::~IContext() {}
10285  IResultCapture::~IResultCapture() {}
10286  ITestCase::~ITestCase() {}
10287  ITestCaseRegistry::~ITestCaseRegistry() {}
10288  IRegistryHub::~IRegistryHub() {}
10289  IMutableRegistryHub::~IMutableRegistryHub() {}
10290  IExceptionTranslator::~IExceptionTranslator() {}
10291  IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {}
10292  IReporter::~IReporter() {}
10293  IReporterFactory::~IReporterFactory() {}
10294  IReporterRegistry::~IReporterRegistry() {}
10295  IStreamingReporter::~IStreamingReporter() {}
10296  AssertionStats::~AssertionStats() {}
10297  SectionStats::~SectionStats() {}
10298  TestCaseStats::~TestCaseStats() {}
10299  TestGroupStats::~TestGroupStats() {}
10300  TestRunStats::~TestRunStats() {}
10301  CumulativeReporterBase::SectionNode::~SectionNode() {}
10302  CumulativeReporterBase::~CumulativeReporterBase() {}
10303 
10304  StreamingReporterBase::~StreamingReporterBase() {}
10305  ConsoleReporter::~ConsoleReporter() {}
10306  CompactReporter::~CompactReporter() {}
10307  IRunner::~IRunner() {}
10308  IMutableContext::~IMutableContext() {}
10309  IConfig::~IConfig() {}
10310  XmlReporter::~XmlReporter() {}
10311  JunitReporter::~JunitReporter() {}
10312  TestRegistry::~TestRegistry() {}
10313  FreeFunctionTestCase::~FreeFunctionTestCase() {}
10314  IGeneratorInfo::~IGeneratorInfo() {}
10315  IGeneratorsForTest::~IGeneratorsForTest() {}
10316  WildcardPattern::~WildcardPattern() {}
10317  TestSpec::Pattern::~Pattern() {}
10318  TestSpec::NamePattern::~NamePattern() {}
10319  TestSpec::TagPattern::~TagPattern() {}
10320  TestSpec::ExcludedPattern::~ExcludedPattern() {}
10321 
10322  Matchers::Impl::StdString::Equals::~Equals() {}
10323  Matchers::Impl::StdString::Contains::~Contains() {}
10324  Matchers::Impl::StdString::StartsWith::~StartsWith() {}
10325  Matchers::Impl::StdString::EndsWith::~EndsWith() {}
10326 
10327  void Config::dummy() {}
10328 
10329  namespace TestCaseTracking {
10330  ITracker::~ITracker() {}
10331  TrackerBase::~TrackerBase() {}
10332  SectionTracker::~SectionTracker() {}
10333  IndexTracker::~IndexTracker() {}
10334  }
10335 }
10336 
10337 #ifdef __clang__
10338 #pragma clang diagnostic pop
10339 #endif
10340 
10341 #endif
10342 
10343 #ifdef CATCH_CONFIG_MAIN
10344 // #included from: internal/catch_default_main.hpp
10345 #define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED
10346 
10347 #ifndef __OBJC__
10348 
10349 // Standard C/C++ main entry point
10350 int main (int argc, char * argv[]) {
10351  return Catch::Session().run( argc, argv );
10352 }
10353 
10354 #else // __OBJC__
10355 
10356 // Objective-C entry point
10357 int main (int argc, char * const argv[]) {
10358 #if !CATCH_ARC_ENABLED
10359  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
10360 #endif
10361 
10362  Catch::registerTestMethods();
10363  int result = Catch::Session().run( argc, (char* const*)argv );
10364 
10365 #if !CATCH_ARC_ENABLED
10366  [pool drain];
10367 #endif
10368 
10369  return result;
10370 }
10371 
10372 #endif // __OBJC__
10373 
10374 #endif
10375 
10376 #ifdef CLARA_CONFIG_MAIN_NOT_DEFINED
10377 # undef CLARA_CONFIG_MAIN
10378 #endif
10379 
10381 
10382 // If this config identifier is defined then all CATCH macros are prefixed with CATCH_
10383 #ifdef CATCH_CONFIG_PREFIX_ALL
10384 
10385 #define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE" )
10386 #define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, "CATCH_REQUIRE_FALSE" )
10387 
10388 #define CATCH_REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "", "CATCH_REQUIRE_THROWS" )
10389 #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THROWS_AS" )
10390 #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, matcher, "CATCH_REQUIRE_THROWS_WITH" )
10391 #define CATCH_REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_NOTHROW" )
10392 
10393 #define CATCH_CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK" )
10394 #define CATCH_CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, "CATCH_CHECK_FALSE" )
10395 #define CATCH_CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_IF" )
10396 #define CATCH_CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_ELSE" )
10397 #define CATCH_CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CATCH_CHECK_NOFAIL" )
10398 
10399 #define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS" )
10400 #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS_AS" )
10401 #define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, matcher, "CATCH_CHECK_THROWS_WITH" )
10402 #define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_NOTHROW" )
10403 
10404 #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THAT" )
10405 #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THAT" )
10406 
10407 #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" )
10408 #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "CATCH_WARN", msg )
10409 #define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" )
10410 #define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" )
10411 #define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" )
10412 
10413 #ifdef CATCH_CONFIG_VARIADIC_MACROS
10414  #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
10415  #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
10416  #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
10417  #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
10418  #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
10419  #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", __VA_ARGS__ )
10420  #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", __VA_ARGS__ )
10421 #else
10422  #define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
10423  #define CATCH_TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
10424  #define CATCH_METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
10425  #define CATCH_REGISTER_TEST_CASE( function, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( function, name, description )
10426  #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
10427  #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", msg )
10428  #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", msg )
10429 #endif
10430 #define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
10431 
10432 #define CATCH_REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
10433 #define CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType )
10434 
10435 #define CATCH_GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
10436 
10437 // "BDD-style" convenience wrappers
10438 #ifdef CATCH_CONFIG_VARIADIC_MACROS
10439 #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
10440 #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
10441 #else
10442 #define CATCH_SCENARIO( name, tags ) CATCH_TEST_CASE( "Scenario: " name, tags )
10443 #define CATCH_SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
10444 #endif
10445 #define CATCH_GIVEN( desc ) CATCH_SECTION( std::string( "Given: ") + desc, "" )
10446 #define CATCH_WHEN( desc ) CATCH_SECTION( std::string( " When: ") + desc, "" )
10447 #define CATCH_AND_WHEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" )
10448 #define CATCH_THEN( desc ) CATCH_SECTION( std::string( " Then: ") + desc, "" )
10449 #define CATCH_AND_THEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" )
10450 
10451 // If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
10452 #else
10453 
10454 #define REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal, "REQUIRE" )
10455 #define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, "REQUIRE_FALSE" )
10456 
10457 #define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "", "REQUIRE_THROWS" )
10458 #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "REQUIRE_THROWS_AS" )
10459 #define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, matcher, "REQUIRE_THROWS_WITH" )
10460 #define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "REQUIRE_NOTHROW" )
10461 
10462 #define CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK" )
10463 #define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, "CHECK_FALSE" )
10464 #define CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECKED_IF" )
10465 #define CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECKED_ELSE" )
10466 #define CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CHECK_NOFAIL" )
10467 
10468 #define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "", "CHECK_THROWS" )
10469 #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THROWS_AS" )
10470 #define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, matcher, "CHECK_THROWS_WITH" )
10471 #define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK_NOTHROW" )
10472 
10473 #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THAT" )
10474 #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "REQUIRE_THAT" )
10475 
10476 #define INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" )
10477 #define WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "WARN", msg )
10478 #define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" )
10479 #define CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" )
10480 #define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" )
10481 
10482 #ifdef CATCH_CONFIG_VARIADIC_MACROS
10483  #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
10484  #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
10485  #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
10486  #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
10487  #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
10488  #define FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", __VA_ARGS__ )
10489  #define SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", __VA_ARGS__ )
10490 #else
10491  #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
10492  #define TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
10493  #define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
10494  #define REGISTER_TEST_CASE( method, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( method, name, description )
10495  #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
10496  #define FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", msg )
10497  #define SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", msg )
10498 #endif
10499 #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
10500 
10501 #define REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
10502 #define REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType )
10503 
10504 #define GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
10505 
10506 #endif
10507 
10508 #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
10509 
10510 // "BDD-style" convenience wrappers
10511 #ifdef CATCH_CONFIG_VARIADIC_MACROS
10512 #define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
10513 #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
10514 #else
10515 #define SCENARIO( name, tags ) TEST_CASE( "Scenario: " name, tags )
10516 #define SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
10517 #endif
10518 #define GIVEN( desc ) SECTION( std::string(" Given: ") + desc, "" )
10519 #define WHEN( desc ) SECTION( std::string(" When: ") + desc, "" )
10520 #define AND_WHEN( desc ) SECTION( std::string("And when: ") + desc, "" )
10521 #define THEN( desc ) SECTION( std::string(" Then: ") + desc, "" )
10522 #define AND_THEN( desc ) SECTION( std::string(" And: ") + desc, "" )
10523 
10524 using Catch::Detail::Approx;
10525 
10526 #endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
10527 
Definition: catch.hpp:619
#define CATCH_CONFIG_CONSOLE_WIDTH
Widen the console output wrapping so our matrices don&#39;t get so mangled in messages.
Definition: TestIMU.h:30
Definition: DummyTree.h:38
apply_list< quote< or_ >, transform< Haystack, detail::is_< Needle >>> contains
Determines if type Needle is in the list Haystack - is an alias for a type that inherits std::true_ty...
Definition: Contains.h:49
Definition: catch.hpp:343
Definition: catch.hpp:835
Definition: catch.hpp:540
Definition: CommonComponent.h:44
Definition: catch.hpp:1209
Definition: catch.hpp:322
Definition: catch.hpp:2348
Definition: catch.hpp:2545
Definition: catch.hpp:661
Definition: catch.hpp:2718
Definition: catch.hpp:1215
Definition: catch.hpp:1678
Definition: catch.hpp:547
Definition: catch.hpp:1312
std::string makeString(const char(&arrayLiteral)[N])
Safely and easily convert a literal array of characters (like from osvr_json_to_c) into a std::string...
Definition: StringLiteralFileToString.h:45
Definition: catch.hpp:1973
Definition: catch_typelist.h:23
Definition: catch.hpp:810
Definition: catch.hpp:1228
Definition: catch.hpp:676
Definition: catch.hpp:2355
Definition: catch.hpp:2572
Definition: catch.hpp:1609
Definition: catch.hpp:1645
OSVR_TimeValue operator+(OSVR_TimeValue const &tv, std::chrono::duration< Rep, Period > const &additionalTime)
Add a util::time::TimeValue and a std::chrono::duration.
Definition: TimeValueChrono.h:45
Definition: catch.hpp:1618
Definition: catch.hpp:2292
Definition: catch.hpp:1211
Definition: catch.hpp:420
Definition: catch.hpp:2792
double duration(TimeValue const &a, TimeValue const &b)
Get a double containing seconds between the time points.
Definition: TimeValue.h:62
Definition: catch.hpp:2269
detail::size< coerce_list< Ts... >> size
Get the size of a list (number of elements.)
Definition: Size.h:56
Definition: catch.hpp:2395
Definition: catch.hpp:2374
Definition: catch.hpp:849
Definition: catch.hpp:628
Definition: catch.hpp:1331
Definition: catch.hpp:2225
Definition: catch.hpp:919
Definition: newuoa.h:1888
Definition: catch.hpp:438
Definition: catch.hpp:904
t_< detail::transform_< List, Fun >> transform
Given a list and an alias class, apply the alias class to each element in the list and return the res...
Definition: Transform.h:54
Definition: catch.hpp:2537
Definition: catch.hpp:386
Definition: catch.hpp:499
Definition: catch.hpp:2711
Definition: catch.hpp:2732
Definition: catch.hpp:2567
Definition: catch.hpp:1610
Definition: catch.hpp:327
Definition: catch.hpp:2310
time_value_scalar_duration operator-(detail::TimeValueChronoWrapperBase< DerivedA > const &a, detail::TimeValueChronoWrapperBase< DerivedB > const &b)
Subtract one wrapped TimeValue from another and get a std::duration back!
Definition: TimeValueChrono.h:202
Definition: catch.hpp:1605
Definition: catch.hpp:2049
Definition: catch.hpp:468
Definition: MeasureTrackingCameraLatency.cpp:253
Computation was successful.
Definition: Constants.h:376
Definition: catch.hpp:782
Definition: catch.hpp:2819
Definition: catch.hpp:898
Definition: catch.hpp:2853
Definition: catch.hpp:899
Definition: catch.hpp:900
Definition: catch.hpp:2258
Definition: catch.hpp:1908
Definition: catch.hpp:2629
Definition: catch.hpp:377
Definition: catch.hpp:592
Definition: catch.hpp:858
Definition: catch.hpp:1929
Definition: catch.hpp:643
The main class implementing the common components of the Kalman family of filters.
Definition: FlexibleKalmanFilter.h:74
A "Unique Container" designed for composition, not inheritance.
Definition: UniqueContainer.h:327
Definition: catch.hpp:2578
Definition: catch.hpp:2193
Definition: catch.hpp:581
Definition: catch.hpp:1946
Definition: catch.hpp:474