Line data Source code
1 : /*
2 : * Catch v1.5.9
3 : * Generated: 2016-11-29 12:14:38.049276
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 :
137 : ////////////////////////////////////////////////////////////////////////////////
138 : // Borland
139 : #ifdef __BORLANDC__
140 :
141 : #endif // __BORLANDC__
142 :
143 : ////////////////////////////////////////////////////////////////////////////////
144 : // EDG
145 : #ifdef __EDG_VERSION__
146 :
147 : #endif // __EDG_VERSION__
148 :
149 : ////////////////////////////////////////////////////////////////////////////////
150 : // Digital Mars
151 : #ifdef __DMC__
152 :
153 : #endif // __DMC__
154 :
155 : ////////////////////////////////////////////////////////////////////////////////
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 :
172 : ////////////////////////////////////////////////////////////////////////////////
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 :
188 : ////////////////////////////////////////////////////////////////////////////////
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 :
209 : ////////////////////////////////////////////////////////////////////////////////
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 398 : NonCopyable() {}
340 : virtual ~NonCopyable();
341 : };
342 :
343 : class SafeBool {
344 : public:
345 : typedef void (SafeBool::*type)() const;
346 :
347 3 : static type makeSafe( bool value ) {
348 3 : return value ? &SafeBool::trueValue : 0;
349 : }
350 : private:
351 0 : void trueValue() const {}
352 : };
353 :
354 : template<typename ContainerT>
355 1 : inline void deleteAll( ContainerT& container ) {
356 1 : typename ContainerT::const_iterator it = container.begin();
357 1 : typename ContainerT::const_iterator itEnd = container.end();
358 1 : for(; it != itEnd; ++it )
359 0 : delete *it;
360 1 : }
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 2 : 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 19616 : 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 2571 : inline bool isTrue( bool value ){ return value; }
408 0 : 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 );
442 : NotImplementedException( NotImplementedException const& ) {}
443 :
444 0 : 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 :
455 : ///////////////////////////////////////////////////////////////////////////////
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 0 : struct IGeneratorInfo {
469 : virtual ~IGeneratorInfo();
470 : virtual bool moveNext() = 0;
471 : virtual std::size_t getCurrentIndex() const = 0;
472 : };
473 :
474 0 : struct IGeneratorsForTest {
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 4 : Ptr() : m_p( CATCH_NULL ){}
502 151 : Ptr( T* p ) : m_p( p ){
503 151 : if( m_p )
504 150 : m_p->addRef();
505 151 : }
506 317 : Ptr( Ptr const& other ) : m_p( other.m_p ){
507 317 : if( m_p )
508 317 : m_p->addRef();
509 317 : }
510 472 : ~Ptr(){
511 472 : if( m_p )
512 467 : m_p->release();
513 472 : }
514 1 : void reset() {
515 1 : if( m_p )
516 0 : m_p->release();
517 1 : m_p = CATCH_NULL;
518 1 : }
519 33 : Ptr& operator = ( T* p ){
520 33 : Ptr temp( p );
521 33 : swap( temp );
522 33 : return *this;
523 : }
524 4 : Ptr& operator = ( Ptr const& other ){
525 4 : Ptr temp( other );
526 4 : swap( temp );
527 4 : return *this;
528 : }
529 37 : void swap( Ptr& other ) { std::swap( m_p, other.m_p ); }
530 309 : T* get() const{ return m_p; }
531 134 : T& operator*() const { return *m_p; }
532 6732 : T* operator->() const { return m_p; }
533 3 : bool operator !() const { return m_p == CATCH_NULL; }
534 2 : operator SafeBool::type() const { return SafeBool::makeSafe( m_p != CATCH_NULL ); }
535 :
536 : private:
537 : T* m_p;
538 : };
539 :
540 148 : 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 148 : struct SharedImpl : T {
548 :
549 148 : SharedImpl() : m_rc( 0 ){}
550 :
551 467 : virtual void addRef() const {
552 467 : ++m_rc;
553 467 : }
554 467 : virtual void release() const {
555 467 : if( --m_rc == 0 )
556 148 : delete this;
557 467 : }
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 1 : 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 :
592 1 : struct IMutableContext : IContext
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 31 : struct ITestCase : IShared {
620 : virtual void invoke () const = 0;
621 : protected:
622 : virtual ~ITestCase();
623 : };
624 :
625 : class TestCase;
626 : struct IConfig;
627 :
628 1 : struct ITestCaseRegistry {
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 31 : NameAndDesc( const char* _name = "", const char* _description= "" )
663 31 : : name( _name ), description( _description )
664 31 : {}
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 : ///////////////////////////////////////////////////////////////////////////////
713 : #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 :
720 : ///////////////////////////////////////////////////////////////////////////////
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 :
724 : ///////////////////////////////////////////////////////////////////////////////
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 :
736 : ///////////////////////////////////////////////////////////////////////////////
737 : #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
738 : Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) );
739 :
740 : #else
741 : ///////////////////////////////////////////////////////////////////////////////
742 : #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 :
749 : ///////////////////////////////////////////////////////////////////////////////
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 :
753 : ///////////////////////////////////////////////////////////////////////////////
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 :
765 : ///////////////////////////////////////////////////////////////////////////////
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 5142 : inline bool isOk( ResultWas::OfType resultType ) {
803 5142 : 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 207 : inline ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) {
819 207 : 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 2571 : inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; }
824 0 : 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 :
835 20706 : struct AssertionInfo
836 : {
837 2 : 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 :
849 20569 : struct AssertionResultData
850 : {
851 2572 : AssertionResultData() : resultType( ResultWas::Unknown ) {}
852 :
853 : std::string reconstructedExpression;
854 : std::string message;
855 : ResultWas::OfType resultType;
856 : };
857 :
858 5142 : class AssertionResult {
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 0 : struct Matcher : SharedImpl<IShared>
905 : {
906 : typedef ExpressionT ExpressionType;
907 :
908 0 : 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 0 : struct MatcherImpl : Matcher<ExpressionT> {
920 :
921 0 : virtual Ptr<Matcher<ExpressionT> > clone() const {
922 0 : 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 0 : class AllOf : public MatcherImpl<AllOf<ExpressionT>, ExpressionT> {
946 : public:
947 :
948 0 : AllOf() {}
949 0 : 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 0 : virtual bool match( ExpressionT const& expr ) const
956 : {
957 0 : for( std::size_t i = 0; i < m_matchers.size(); ++i )
958 0 : if( !m_matchers[i]->match( expr ) )
959 0 : return false;
960 0 : return true;
961 : }
962 0 : virtual std::string toString() const {
963 0 : std::ostringstream oss;
964 0 : oss << "( ";
965 0 : for( std::size_t i = 0; i < m_matchers.size(); ++i ) {
966 0 : if( i != 0 )
967 0 : oss << " and ";
968 0 : oss << m_matchers[i]->toString();
969 : }
970 0 : oss << " )";
971 0 : 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>
1027 : Generic::AllOf<ExpressionT> Matcher<ExpressionT>::operator && ( Matcher<ExpressionT> const& other ) const {
1028 : Generic::AllOf<ExpressionT> allOfExpr;
1029 : allOfExpr.add( *this );
1030 : allOfExpr.add( other );
1031 : return allOfExpr;
1032 : }
1033 :
1034 : template<typename ExpressionT>
1035 : Generic::AnyOf<ExpressionT> Matcher<ExpressionT>::operator || ( Matcher<ExpressionT> const& other ) const {
1036 : Generic::AnyOf<ExpressionT> anyOfExpr;
1037 : anyOfExpr.add( *this );
1038 : anyOfExpr.add( other );
1039 : return anyOfExpr;
1040 : }
1041 :
1042 : template<typename ExpressionT>
1043 : Generic::Not<ExpressionT> Matcher<ExpressionT>::operator ! () const {
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 :
1052 0 : struct CasedString
1053 : {
1054 0 : CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity )
1055 : : m_caseSensitivity( caseSensitivity ),
1056 0 : m_str( adjustString( str ) )
1057 0 : {}
1058 0 : std::string adjustString( std::string const& str ) const {
1059 0 : return m_caseSensitivity == CaseSensitive::No
1060 : ? toLower( str )
1061 0 : : str;
1062 :
1063 : }
1064 0 : std::string toStringSuffix() const
1065 : {
1066 0 : return m_caseSensitivity == CaseSensitive::No
1067 : ? " (case insensitive)"
1068 0 : : "";
1069 : }
1070 : CaseSensitive::Choice m_caseSensitivity;
1071 : std::string m_str;
1072 : };
1073 :
1074 : struct Equals : MatcherImpl<Equals, std::string> {
1075 0 : Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes )
1076 0 : : m_data( str, caseSensitivity )
1077 0 : {}
1078 0 : Equals( Equals const& other ) : m_data( other.m_data ){}
1079 :
1080 : virtual ~Equals();
1081 :
1082 0 : virtual bool match( std::string const& expr ) const {
1083 0 : return m_data.m_str == m_data.adjustString( expr );;
1084 : }
1085 0 : virtual std::string toString() const {
1086 0 : 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 0 : Contains( Contains const& other ) : m_data( other.m_data ){}
1096 :
1097 : virtual ~Contains();
1098 :
1099 0 : virtual bool match( std::string const& expr ) const {
1100 0 : return m_data.adjustString( expr ).find( m_data.m_str ) != std::string::npos;
1101 : }
1102 0 : virtual std::string toString() const {
1103 0 : 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 0 : StartsWith( StartsWith const& other ) : m_data( other.m_data ){}
1114 :
1115 : virtual ~StartsWith();
1116 :
1117 0 : virtual bool match( std::string const& expr ) const {
1118 0 : return startsWith( m_data.adjustString( expr ), m_data.m_str );
1119 : }
1120 0 : virtual std::string toString() const {
1121 0 : 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 0 : EndsWith( EndsWith const& other ) : m_data( other.m_data ){}
1131 :
1132 : virtual ~EndsWith();
1133 :
1134 0 : virtual bool match( std::string const& expr ) const {
1135 0 : return endsWith( m_data.adjustString( expr ), m_data.m_str );
1136 : }
1137 0 : virtual std::string toString() const {
1138 0 : 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>
1149 : inline Impl::Generic::Not<ExpressionT> Not( Impl::Matcher<ExpressionT> const& m ) {
1150 : return Impl::Generic::Not<ExpressionT>( m );
1151 : }
1152 :
1153 : template<typename ExpressionT>
1154 : inline Impl::Generic::AllOf<ExpressionT> AllOf( Impl::Matcher<ExpressionT> const& m1,
1155 : Impl::Matcher<ExpressionT> const& m2 ) {
1156 : return Impl::Generic::AllOf<ExpressionT>().add( m1 ).add( m2 );
1157 : }
1158 : template<typename ExpressionT>
1159 : inline Impl::Generic::AllOf<ExpressionT> AllOf( Impl::Matcher<ExpressionT> const& m1,
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>
1165 : inline Impl::Generic::AnyOf<ExpressionT> AnyOf( Impl::Matcher<ExpressionT> const& m1,
1166 : Impl::Matcher<ExpressionT> const& m2 ) {
1167 : return Impl::Generic::AnyOf<ExpressionT>().add( m1 ).add( m2 );
1168 : }
1169 : template<typename ExpressionT>
1170 : inline Impl::Generic::AnyOf<ExpressionT> AnyOf( Impl::Matcher<ExpressionT> const& m1,
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 0 : inline Impl::StdString::Equals Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) {
1177 0 : 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 ) {
1192 : return Impl::StdString::StartsWith( Impl::StdString::makeString( 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 ) {
1198 : return Impl::StdString::EndsWith( Impl::StdString::makeString( substr ) );
1199 : }
1200 :
1201 : } // namespace Matchers
1202 :
1203 : using namespace Matchers;
1204 :
1205 : } // namespace Catch
1206 :
1207 : namespace Catch {
1208 :
1209 : struct TestFailureException{};
1210 :
1211 : template<typename T> class ExpressionLhs;
1212 :
1213 : struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
1214 :
1215 2571 : struct CopyableStream {
1216 2571 : 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 :
1228 2571 : class ResultBuilder {
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 0 : ResultBuilder& operator << ( T const& value ) {
1242 0 : m_stream.oss << value;
1243 0 : 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 2571 : struct ExprComponents {
1274 2571 : 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 2106 : template<> struct OperatorTraits<IsEqualTo> { static const char* getName(){ return "=="; } };
1314 17 : template<> struct OperatorTraits<IsNotEqualTo> { static const char* getName(){ return "!="; } };
1315 21 : template<> struct OperatorTraits<IsLessThan> { static const char* getName(){ return "<"; } };
1316 27 : template<> struct OperatorTraits<IsGreaterThan> { static const char* getName(){ return ">"; } };
1317 21 : template<> struct OperatorTraits<IsLessThanOrEqualTo> { static const char* getName(){ return "<="; } };
1318 25 : template<> struct OperatorTraits<IsGreaterThanOrEqualTo>{ static const char* getName(){ return ">="; } };
1319 :
1320 : template<typename T>
1321 4434 : 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 2106 : static bool evaluate( T1 const& lhs, T2 const& rhs) {
1336 2106 : return bool( opCast( lhs ) == opCast( rhs ) );
1337 : }
1338 : };
1339 : template<typename T1, typename T2>
1340 : struct Evaluator<T1, T2, IsNotEqualTo> {
1341 17 : static bool evaluate( T1 const& lhs, T2 const& rhs ) {
1342 17 : return bool( opCast( lhs ) != opCast( rhs ) );
1343 : }
1344 : };
1345 : template<typename T1, typename T2>
1346 : struct Evaluator<T1, T2, IsLessThan> {
1347 21 : static bool evaluate( T1 const& lhs, T2 const& rhs ) {
1348 21 : return bool( opCast( lhs ) < opCast( rhs ) );
1349 : }
1350 : };
1351 : template<typename T1, typename T2>
1352 : struct Evaluator<T1, T2, IsGreaterThan> {
1353 27 : static bool evaluate( T1 const& lhs, T2 const& rhs ) {
1354 27 : return bool( opCast( lhs ) > opCast( rhs ) );
1355 : }
1356 : };
1357 : template<typename T1, typename T2>
1358 : struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> {
1359 25 : static bool evaluate( T1 const& lhs, T2 const& rhs ) {
1360 25 : return bool( opCast( lhs ) >= opCast( rhs ) );
1361 : }
1362 : };
1363 : template<typename T1, typename T2>
1364 : struct Evaluator<T1, T2, IsLessThanOrEqualTo> {
1365 21 : static bool evaluate( T1 const& lhs, T2 const& rhs ) {
1366 21 : return bool( opCast( lhs ) <= opCast( rhs ) );
1367 : }
1368 : };
1369 :
1370 : template<Operator Op, typename T1, typename T2>
1371 13 : bool applyEvaluator( T1 const& lhs, T2 const& rhs ) {
1372 13 : 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 2204 : bool compare( T1 const& lhs, T2 const& rhs ) {
1381 2204 : 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 13 : template<Operator Op> bool compare( unsigned char lhs, int rhs ) {
1392 13 : 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>
1618 : struct IsStreamInsertable {
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>
1645 : struct StringMakerBase {
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 3562 : static std::string convert( T const& _value ) {
1662 3562 : std::ostringstream oss;
1663 3562 : oss << _value;
1664 3562 : 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 6 : std::string makeString( T const& value ) {
1764 6 : return StringMaker<T>::convert( value );
1765 : }
1766 : } // end namespace Detail
1767 :
1768 : /// \brief converts any type to a string
1769 : ///
1770 : /// The default template forwards on to ostringstream - except when an
1771 : /// ostringstream overload does not exist - in which case it attempts to detect
1772 : /// that and writes {?}.
1773 : /// Overload (not specialise) this template for custom typs that you don't want
1774 : /// to provide an ostream overload for.
1775 : template<typename T>
1776 3556 : std::string toString( T const& value ) {
1777 3556 : 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 2571 : 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 2106 : ResultBuilder& operator == ( RhsT const& rhs ) {
1817 2106 : return captureExpression<Internal::IsEqualTo>( rhs );
1818 : }
1819 :
1820 : template<typename RhsT>
1821 17 : ResultBuilder& operator != ( RhsT const& rhs ) {
1822 17 : return captureExpression<Internal::IsNotEqualTo>( rhs );
1823 : }
1824 :
1825 : template<typename RhsT>
1826 21 : ResultBuilder& operator < ( RhsT const& rhs ) {
1827 21 : return captureExpression<Internal::IsLessThan>( rhs );
1828 : }
1829 :
1830 : template<typename RhsT>
1831 27 : ResultBuilder& operator > ( RhsT const& rhs ) {
1832 27 : return captureExpression<Internal::IsGreaterThan>( rhs );
1833 : }
1834 :
1835 : template<typename RhsT>
1836 21 : ResultBuilder& operator <= ( RhsT const& rhs ) {
1837 21 : return captureExpression<Internal::IsLessThanOrEqualTo>( rhs );
1838 : }
1839 :
1840 : template<typename RhsT>
1841 25 : ResultBuilder& operator >= ( RhsT const& rhs ) {
1842 25 : 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 354 : void endExpression() {
1854 354 : bool value = m_lhs ? true : false;
1855 354 : m_rb
1856 708 : .setLhs( Catch::toString( value ) )
1857 708 : .setResultType( value )
1858 : .endExpression();
1859 354 : }
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 2217 : ResultBuilder& captureExpression( RhsT const& rhs ) {
1873 : return m_rb
1874 2217 : .setResultType( Internal::compare<Op>( m_lhs, rhs ) )
1875 : .setLhs( Catch::toString( m_lhs ) )
1876 : .setRhs( Catch::toString( rhs ) )
1877 4434 : .setOp( Internal::OperatorTraits<Op>::getName() );
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 2265 : inline ExpressionLhs<T const&> ResultBuilder::operator <= ( T const& operand ) {
1892 2265 : return ExpressionLhs<T const&>( *this, operand );
1893 : }
1894 :
1895 306 : inline ExpressionLhs<bool> ResultBuilder::operator <= ( bool value ) {
1896 306 : 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 0 : 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 0 : bool operator == ( MessageInfo const& other ) const {
1920 0 : 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 :
1929 0 : struct MessageBuilder {
1930 0 : MessageBuilder( std::string const& macroName,
1931 : SourceLineInfo const& lineInfo,
1932 : ResultWas::OfType type )
1933 0 : : m_info( macroName, lineInfo, type )
1934 0 : {}
1935 :
1936 : template<typename T>
1937 0 : MessageBuilder& operator << ( T const& value ) {
1938 0 : m_stream << value;
1939 0 : return *this;
1940 : }
1941 :
1942 : MessageInfo m_info;
1943 : std::ostringstream m_stream;
1944 : };
1945 :
1946 : class ScopedMessage {
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 :
1973 1 : struct IResultCapture {
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 1 : struct IRunner {
2050 : virtual ~IRunner();
2051 : virtual bool aborting() const = 0;
2052 : };
2053 : }
2054 :
2055 : ///////////////////////////////////////////////////////////////////////////////
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 :
2064 : ///////////////////////////////////////////////////////////////////////////////
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 :
2078 : ///////////////////////////////////////////////////////////////////////////////
2079 : #define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \
2080 : INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
2081 : if( Catch::getResultCapture().getLastResult()->succeeded() )
2082 :
2083 : ///////////////////////////////////////////////////////////////////////////////
2084 : #define INTERNAL_CATCH_ELSE( expr, resultDisposition, macroName ) \
2085 : INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
2086 : if( !Catch::getResultCapture().getLastResult()->succeeded() )
2087 :
2088 : ///////////////////////////////////////////////////////////////////////////////
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 :
2102 : ///////////////////////////////////////////////////////////////////////////////
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 :
2119 : ///////////////////////////////////////////////////////////////////////////////
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 :
2139 : ///////////////////////////////////////////////////////////////////////////////
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 :
2158 : ///////////////////////////////////////////////////////////////////////////////
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 :
2162 : ///////////////////////////////////////////////////////////////////////////////
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 492 : Counts() : passed( 0 ), failed( 0 ), failedButOk( 0 ) {}
2195 :
2196 177 : Counts operator - ( Counts const& other ) const {
2197 177 : Counts diff;
2198 177 : diff.passed = passed - other.passed;
2199 177 : diff.failed = failed - other.failed;
2200 177 : diff.failedButOk = failedButOk - other.failedButOk;
2201 177 : return diff;
2202 : }
2203 93 : Counts& operator += ( Counts const& other ) {
2204 93 : passed += other.passed;
2205 93 : failed += other.failed;
2206 93 : failedButOk += other.failedButOk;
2207 93 : return *this;
2208 : }
2209 :
2210 121 : std::size_t total() const {
2211 121 : return passed + failed + failedButOk;
2212 : }
2213 2 : bool allPassed() const {
2214 2 : return failed == 0 && failedButOk == 0;
2215 : }
2216 0 : bool allOk() const {
2217 0 : return failed == 0;
2218 : }
2219 :
2220 : std::size_t passed;
2221 : std::size_t failed;
2222 : std::size_t failedButOk;
2223 : };
2224 :
2225 33 : struct Totals {
2226 :
2227 31 : Totals operator - ( Totals const& other ) const {
2228 31 : Totals diff;
2229 31 : diff.assertions = assertions - other.assertions;
2230 31 : diff.testCases = testCases - other.testCases;
2231 31 : return diff;
2232 : }
2233 :
2234 31 : Totals delta( Totals const& prevTotals ) const {
2235 31 : Totals diff = *this - prevTotals;
2236 31 : if( diff.assertions.failed > 0 )
2237 0 : ++diff.testCases.failed;
2238 31 : else if( diff.assertions.failedButOk > 0 )
2239 0 : ++diff.testCases.failedButOk;
2240 : else
2241 31 : ++diff.testCases.passed;
2242 31 : return diff;
2243 : }
2244 :
2245 31 : Totals& operator += ( Totals const& other ) {
2246 31 : assertions += other.assertions;
2247 31 : testCases += other.testCases;
2248 31 : return *this;
2249 : }
2250 :
2251 : Counts assertions;
2252 : Counts testCases;
2253 : };
2254 : }
2255 :
2256 : namespace Catch {
2257 :
2258 1371 : 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 :
2269 47 : struct SectionEndInfo {
2270 47 : SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds )
2271 47 : : sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds )
2272 47 : {}
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 317 : 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 :
2310 : class Section : NonCopyable {
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>
2395 : class CompositeGenerator {
2396 : public:
2397 : CompositeGenerator() : m_totalSize( 0 ) {}
2398 :
2399 : // *** Move semantics, similar to auto_ptr ***
2400 : CompositeGenerator( CompositeGenerator& other )
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;
2532 : struct IExceptionTranslatorRegistry;
2533 : struct IExceptionTranslator;
2534 : struct IReporterRegistry;
2535 : struct IReporterFactory;
2536 :
2537 1 : 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 :
2545 1 : struct IMutableRegistryHub {
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 :
2567 : struct IExceptionTranslator {
2568 : virtual ~IExceptionTranslator();
2569 : virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0;
2570 : };
2571 :
2572 1 : struct IExceptionTranslatorRegistry {
2573 : virtual ~IExceptionTranslatorRegistry();
2574 :
2575 : virtual std::string translateActiveException() const = 0;
2576 : };
2577 :
2578 : class ExceptionTranslatorRegistrar {
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 :
2612 : ///////////////////////////////////////////////////////////////////////////////
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 0 : struct TagAlias {
2712 0 : TagAlias( std::string _tag, SourceLineInfo _lineInfo ) : tag( _tag ), lineInfo( _lineInfo ) {}
2713 :
2714 : std::string tag;
2715 : SourceLineInfo lineInfo;
2716 : };
2717 :
2718 : struct RegistrarForTagAliases {
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 4 : Option() : nullableValue( CATCH_NULL ) {}
2735 0 : Option( T const& _value )
2736 0 : : nullableValue( new( storage ) T( _value ) )
2737 0 : {}
2738 : Option( Option const& _other )
2739 : : nullableValue( _other ? new( storage ) T( *_other ) : CATCH_NULL )
2740 : {}
2741 :
2742 4 : ~Option() {
2743 4 : reset();
2744 4 : }
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 33 : Option& operator = ( T const& _value ) {
2755 33 : reset();
2756 33 : nullableValue = new( storage ) T( _value );
2757 33 : return *this;
2758 : }
2759 :
2760 72 : void reset() {
2761 72 : if( nullableValue )
2762 33 : nullableValue->~T();
2763 72 : nullableValue = CATCH_NULL;
2764 72 : }
2765 :
2766 0 : T& operator*() { return *nullableValue; }
2767 : T const& operator*() const { return *nullableValue; }
2768 0 : T* operator->() { return nullableValue; }
2769 : const T* operator->() const { return nullableValue; }
2770 :
2771 0 : T valueOr( T const& defaultValue ) const {
2772 0 : return nullableValue ? *nullableValue : defaultValue;
2773 : }
2774 :
2775 1 : 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 1 : operator SafeBool::type() const {
2780 1 : 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 :
2792 1 : struct ITagAliasRegistry {
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 310 : 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 186 : 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 :
2898 : ///////////////////////////////////////////////////////////////////////////////
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 :
3066 : ///////////////////////////////////////////////////////////////////////////////
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 0 : WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity )
3133 : : m_caseSensitivity( caseSensitivity ),
3134 : m_wildcard( NoWildcard ),
3135 0 : m_pattern( adjustCase( pattern ) )
3136 : {
3137 0 : if( startsWith( m_pattern, "*" ) ) {
3138 0 : m_pattern = m_pattern.substr( 1 );
3139 0 : m_wildcard = WildcardAtStart;
3140 : }
3141 0 : if( endsWith( m_pattern, "*" ) ) {
3142 0 : m_pattern = m_pattern.substr( 0, m_pattern.size()-1 );
3143 0 : m_wildcard = static_cast<WildcardPosition>( m_wildcard | WildcardAtEnd );
3144 : }
3145 0 : }
3146 : virtual ~WildcardPattern();
3147 0 : virtual bool matches( std::string const& str ) const {
3148 0 : switch( m_wildcard ) {
3149 : case NoWildcard:
3150 0 : return m_pattern == adjustCase( str );
3151 : case WildcardAtStart:
3152 0 : return endsWith( adjustCase( str ), m_pattern );
3153 : case WildcardAtEnd:
3154 0 : return startsWith( adjustCase( str ), m_pattern );
3155 : case WildcardAtBothEnds:
3156 0 : 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 0 : throw std::logic_error( "Unknown enum" );
3164 : #ifdef __clang__
3165 : #pragma clang diagnostic pop
3166 : #endif
3167 : }
3168 : private:
3169 0 : std::string adjustCase( std::string const& str ) const {
3170 0 : 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 9 : class TestSpec {
3184 2 : struct Pattern : SharedImpl<> {
3185 : virtual ~Pattern();
3186 : virtual bool matches( TestCaseInfo const& testCase ) const = 0;
3187 : };
3188 : class NamePattern : public Pattern {
3189 : public:
3190 0 : NamePattern( std::string const& name )
3191 0 : : m_wildcardPattern( toLower( name ), CaseSensitive::No )
3192 0 : {}
3193 : virtual ~NamePattern();
3194 0 : virtual bool matches( TestCaseInfo const& testCase ) const {
3195 0 : return m_wildcardPattern.matches( toLower( testCase.name ) );
3196 : }
3197 : private:
3198 : WildcardPattern m_wildcardPattern;
3199 : };
3200 :
3201 : class TagPattern : public Pattern {
3202 : public:
3203 1 : TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {}
3204 : virtual ~TagPattern();
3205 31 : virtual bool matches( TestCaseInfo const& testCase ) const {
3206 31 : 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 1 : ExcludedPattern( Ptr<Pattern> const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {}
3215 : virtual ~ExcludedPattern();
3216 31 : virtual bool matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); }
3217 : private:
3218 : Ptr<Pattern> m_underlyingPattern;
3219 : };
3220 :
3221 11 : struct Filter {
3222 : std::vector<Ptr<Pattern> > m_patterns;
3223 :
3224 31 : bool matches( TestCaseInfo const& testCase ) const {
3225 : // All patterns in a filter must match for the filter to be a match
3226 62 : for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) {
3227 31 : if( !(*it)->matches( testCase ) )
3228 0 : return false;
3229 : }
3230 31 : return true;
3231 : }
3232 : };
3233 :
3234 : public:
3235 1 : bool hasFilters() const {
3236 1 : return !m_filters.empty();
3237 : }
3238 31 : bool matches( TestCaseInfo const& testCase ) const {
3239 : // A TestSpec matches if any filter matches
3240 31 : for( std::vector<Filter>::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it )
3241 31 : if( it->matches( testCase ) )
3242 31 : return true;
3243 0 : 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 1 : 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 1 : TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {}
3271 :
3272 1 : TestSpecParser& parse( std::string const& arg ) {
3273 1 : m_mode = None;
3274 1 : m_exclusion = false;
3275 1 : m_start = std::string::npos;
3276 1 : m_arg = m_tagAliases->expandAliases( arg );
3277 4 : for( m_pos = 0; m_pos < m_arg.size(); ++m_pos )
3278 3 : visitChar( m_arg[m_pos] );
3279 1 : if( m_mode == Name )
3280 0 : addPattern<TestSpec::NamePattern>();
3281 1 : return *this;
3282 : }
3283 1 : TestSpec testSpec() {
3284 1 : addFilter();
3285 1 : return m_testSpec;
3286 : }
3287 : private:
3288 3 : void visitChar( char c ) {
3289 3 : if( m_mode == None ) {
3290 2 : switch( c ) {
3291 0 : case ' ': return;
3292 1 : case '~': m_exclusion = true; return;
3293 1 : case '[': return startNewMode( Tag, ++m_pos );
3294 0 : case '"': return startNewMode( QuotedName, ++m_pos );
3295 0 : default: startNewMode( Name, m_pos ); break;
3296 : }
3297 : }
3298 1 : if( m_mode == Name ) {
3299 0 : if( c == ',' ) {
3300 0 : addPattern<TestSpec::NamePattern>();
3301 0 : addFilter();
3302 : }
3303 0 : else if( c == '[' ) {
3304 0 : if( subString() == "exclude:" )
3305 0 : m_exclusion = true;
3306 : else
3307 0 : addPattern<TestSpec::NamePattern>();
3308 0 : startNewMode( Tag, ++m_pos );
3309 : }
3310 : }
3311 1 : else if( m_mode == QuotedName && c == '"' )
3312 0 : addPattern<TestSpec::NamePattern>();
3313 1 : else if( m_mode == Tag && c == ']' )
3314 1 : addPattern<TestSpec::TagPattern>();
3315 : }
3316 1 : void startNewMode( Mode mode, std::size_t start ) {
3317 1 : m_mode = mode;
3318 1 : m_start = start;
3319 1 : }
3320 1 : std::string subString() const { return m_arg.substr( m_start, m_pos - m_start ); }
3321 : template<typename T>
3322 1 : void addPattern() {
3323 1 : std::string token = subString();
3324 1 : if( startsWith( token, "exclude:" ) ) {
3325 0 : m_exclusion = true;
3326 0 : token = token.substr( 8 );
3327 : }
3328 1 : if( !token.empty() ) {
3329 1 : Ptr<TestSpec::Pattern> pattern = new T( token );
3330 1 : if( m_exclusion )
3331 1 : pattern = new TestSpec::ExcludedPattern( pattern );
3332 1 : m_currentFilter.m_patterns.push_back( pattern );
3333 : }
3334 1 : m_exclusion = false;
3335 1 : m_mode = None;
3336 1 : }
3337 1 : void addFilter() {
3338 1 : if( !m_currentFilter.m_patterns.empty() ) {
3339 1 : m_testSpec.m_filters.push_back( m_currentFilter );
3340 1 : m_currentFilter = TestSpec::Filter();
3341 : }
3342 1 : }
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 1 : 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 0 : 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 : #include <memory>
3432 :
3433 : namespace Catch {
3434 :
3435 : std::ostream& cout();
3436 : std::ostream& cerr();
3437 :
3438 1 : struct IStream {
3439 : virtual ~IStream() CATCH_NOEXCEPT;
3440 : virtual std::ostream& stream() const = 0;
3441 : };
3442 :
3443 : class FileStream : public IStream {
3444 : mutable std::ofstream m_ofs;
3445 : public:
3446 : FileStream( std::string const& filename );
3447 : virtual ~FileStream() CATCH_NOEXCEPT;
3448 : public: // IStream
3449 : virtual std::ostream& stream() const CATCH_OVERRIDE;
3450 : };
3451 :
3452 : class CoutStream : public IStream {
3453 : mutable std::ostream m_os;
3454 : public:
3455 : CoutStream();
3456 : virtual ~CoutStream() CATCH_NOEXCEPT;
3457 :
3458 : public: // IStream
3459 : virtual std::ostream& stream() const CATCH_OVERRIDE;
3460 : };
3461 :
3462 : class DebugOutStream : public IStream {
3463 : CATCH_AUTO_PTR( StreamBufBase ) m_streamBuf;
3464 : mutable std::ostream m_os;
3465 : public:
3466 : DebugOutStream();
3467 : virtual ~DebugOutStream() CATCH_NOEXCEPT;
3468 :
3469 : public: // IStream
3470 : virtual std::ostream& stream() const CATCH_OVERRIDE;
3471 : };
3472 : }
3473 :
3474 : #include <memory>
3475 : #include <vector>
3476 : #include <string>
3477 : #include <iostream>
3478 : #include <ctime>
3479 :
3480 : #ifndef CATCH_CONFIG_CONSOLE_WIDTH
3481 : #define CATCH_CONFIG_CONSOLE_WIDTH 80
3482 : #endif
3483 :
3484 : namespace Catch {
3485 :
3486 3 : struct ConfigData {
3487 :
3488 1 : ConfigData()
3489 : : listTests( false ),
3490 : listTags( false ),
3491 : listReporters( false ),
3492 : listTestNamesOnly( false ),
3493 : showSuccessfulTests( false ),
3494 : shouldDebugBreak( false ),
3495 : noThrow( false ),
3496 : showHelp( false ),
3497 : showInvisibles( false ),
3498 : filenamesAsTags( false ),
3499 : abortAfter( -1 ),
3500 : rngSeed( 0 ),
3501 : verbosity( Verbosity::Normal ),
3502 : warnings( WarnAbout::Nothing ),
3503 : showDurations( ShowDurations::DefaultForReporter ),
3504 : runOrder( RunTests::InDeclarationOrder ),
3505 1 : useColour( UseColour::Auto )
3506 1 : {}
3507 :
3508 : bool listTests;
3509 : bool listTags;
3510 : bool listReporters;
3511 : bool listTestNamesOnly;
3512 :
3513 : bool showSuccessfulTests;
3514 : bool shouldDebugBreak;
3515 : bool noThrow;
3516 : bool showHelp;
3517 : bool showInvisibles;
3518 : bool filenamesAsTags;
3519 :
3520 : int abortAfter;
3521 : unsigned int rngSeed;
3522 :
3523 : Verbosity::Level verbosity;
3524 : WarnAbout::What warnings;
3525 : ShowDurations::OrNot showDurations;
3526 : RunTests::InWhatOrder runOrder;
3527 : UseColour::YesOrNo useColour;
3528 :
3529 : std::string outputFilename;
3530 : std::string name;
3531 : std::string processName;
3532 :
3533 : std::vector<std::string> reporterNames;
3534 : std::vector<std::string> testsOrTags;
3535 : };
3536 :
3537 : class Config : public SharedImpl<IConfig> {
3538 : private:
3539 : Config( Config const& other );
3540 : Config& operator = ( Config const& other );
3541 : virtual void dummy();
3542 : public:
3543 :
3544 : Config()
3545 : {}
3546 :
3547 1 : Config( ConfigData const& data )
3548 : : m_data( data ),
3549 1 : m_stream( openStream() )
3550 : {
3551 1 : if( !data.testsOrTags.empty() ) {
3552 0 : TestSpecParser parser( ITagAliasRegistry::get() );
3553 0 : for( std::size_t i = 0; i < data.testsOrTags.size(); ++i )
3554 0 : parser.parse( data.testsOrTags[i] );
3555 0 : m_testSpec = parser.testSpec();
3556 : }
3557 1 : }
3558 :
3559 2 : virtual ~Config() {
3560 2 : }
3561 :
3562 : std::string const& getFilename() const {
3563 : return m_data.outputFilename ;
3564 : }
3565 :
3566 1 : bool listTests() const { return m_data.listTests; }
3567 1 : bool listTestNamesOnly() const { return m_data.listTestNamesOnly; }
3568 1 : bool listTags() const { return m_data.listTags; }
3569 1 : bool listReporters() const { return m_data.listReporters; }
3570 :
3571 : std::string getProcessName() const { return m_data.processName; }
3572 :
3573 0 : bool shouldDebugBreak() const { return m_data.shouldDebugBreak; }
3574 :
3575 1 : std::vector<std::string> getReporterNames() const { return m_data.reporterNames; }
3576 :
3577 101 : int abortAfter() const { return m_data.abortAfter; }
3578 :
3579 1 : TestSpec const& testSpec() const { return m_testSpec; }
3580 :
3581 : bool showHelp() const { return m_data.showHelp; }
3582 0 : bool showInvisibles() const { return m_data.showInvisibles; }
3583 :
3584 : // IConfig interface
3585 31 : virtual bool allowThrows() const { return !m_data.noThrow; }
3586 1 : virtual std::ostream& stream() const { return m_stream->stream(); }
3587 3 : virtual std::string name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
3588 2571 : virtual bool includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
3589 0 : virtual bool warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; }
3590 115 : virtual ShowDurations::OrNot showDurations() const { return m_data.showDurations; }
3591 3 : virtual RunTests::InWhatOrder runOrder() const { return m_data.runOrder; }
3592 69 : virtual unsigned int rngSeed() const { return m_data.rngSeed; }
3593 1 : virtual UseColour::YesOrNo useColour() const { return m_data.useColour; }
3594 :
3595 : private:
3596 :
3597 1 : IStream const* openStream() {
3598 1 : if( m_data.outputFilename.empty() )
3599 1 : return new CoutStream();
3600 0 : else if( m_data.outputFilename[0] == '%' ) {
3601 0 : if( m_data.outputFilename == "%debug" )
3602 0 : return new DebugOutStream();
3603 : else
3604 0 : throw std::domain_error( "Unrecognised stream: " + m_data.outputFilename );
3605 : }
3606 : else
3607 0 : return new FileStream( m_data.outputFilename );
3608 : }
3609 : ConfigData m_data;
3610 :
3611 : CATCH_AUTO_PTR( IStream const ) m_stream;
3612 : TestSpec m_testSpec;
3613 : };
3614 :
3615 : } // end namespace Catch
3616 :
3617 : // #included from: catch_clara.h
3618 : #define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED
3619 :
3620 : // Use Catch's value for console width (store Clara's off to the side, if present)
3621 : #ifdef CLARA_CONFIG_CONSOLE_WIDTH
3622 : #define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH
3623 : #undef CLARA_CONFIG_CONSOLE_WIDTH
3624 : #endif
3625 : #define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
3626 :
3627 : // Declare Clara inside the Catch namespace
3628 : #define STITCH_CLARA_OPEN_NAMESPACE namespace Catch {
3629 : // #included from: ../external/clara.h
3630 :
3631 : // Version 0.0.2.4
3632 :
3633 : // Only use header guard if we are not using an outer namespace
3634 : #if !defined(TWOBLUECUBES_CLARA_H_INCLUDED) || defined(STITCH_CLARA_OPEN_NAMESPACE)
3635 :
3636 : #ifndef STITCH_CLARA_OPEN_NAMESPACE
3637 : #define TWOBLUECUBES_CLARA_H_INCLUDED
3638 : #define STITCH_CLARA_OPEN_NAMESPACE
3639 : #define STITCH_CLARA_CLOSE_NAMESPACE
3640 : #else
3641 : #define STITCH_CLARA_CLOSE_NAMESPACE }
3642 : #endif
3643 :
3644 : #define STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE STITCH_CLARA_OPEN_NAMESPACE
3645 :
3646 : // ----------- #included from tbc_text_format.h -----------
3647 :
3648 : // Only use header guard if we are not using an outer namespace
3649 : #if !defined(TBC_TEXT_FORMAT_H_INCLUDED) || defined(STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE)
3650 : #ifndef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
3651 : #define TBC_TEXT_FORMAT_H_INCLUDED
3652 : #endif
3653 :
3654 : #include <string>
3655 : #include <vector>
3656 : #include <sstream>
3657 : #include <algorithm>
3658 :
3659 : // Use optional outer namespace
3660 : #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
3661 : namespace STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE {
3662 : #endif
3663 :
3664 : namespace Tbc {
3665 :
3666 : #ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH
3667 : const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH;
3668 : #else
3669 : const unsigned int consoleWidth = 80;
3670 : #endif
3671 :
3672 : struct TextAttributes {
3673 0 : TextAttributes()
3674 : : initialIndent( std::string::npos ),
3675 : indent( 0 ),
3676 : width( consoleWidth-1 ),
3677 0 : tabChar( '\t' )
3678 0 : {}
3679 :
3680 : TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
3681 0 : TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
3682 0 : TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
3683 : TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; }
3684 :
3685 : std::size_t initialIndent; // indent of first line, or npos
3686 : std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
3687 : std::size_t width; // maximum width of text, including indent. Longer text will wrap
3688 : char tabChar; // If this char is seen the indent is changed to current pos
3689 : };
3690 :
3691 0 : class Text {
3692 : public:
3693 0 : Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() )
3694 0 : : attr( _attr )
3695 : {
3696 0 : std::string wrappableChars = " [({.,/|\\-";
3697 0 : std::size_t indent = _attr.initialIndent != std::string::npos
3698 : ? _attr.initialIndent
3699 0 : : _attr.indent;
3700 0 : std::string remainder = _str;
3701 :
3702 0 : while( !remainder.empty() ) {
3703 0 : if( lines.size() >= 1000 ) {
3704 0 : lines.push_back( "... message truncated due to excessive size" );
3705 0 : return;
3706 : }
3707 0 : std::size_t tabPos = std::string::npos;
3708 0 : std::size_t width = (std::min)( remainder.size(), _attr.width - indent );
3709 0 : std::size_t pos = remainder.find_first_of( '\n' );
3710 0 : if( pos <= width ) {
3711 0 : width = pos;
3712 : }
3713 0 : pos = remainder.find_last_of( _attr.tabChar, width );
3714 0 : if( pos != std::string::npos ) {
3715 0 : tabPos = pos;
3716 0 : if( remainder[width] == '\n' )
3717 0 : width--;
3718 0 : remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 );
3719 : }
3720 :
3721 0 : if( width == remainder.size() ) {
3722 0 : spliceLine( indent, remainder, width );
3723 : }
3724 0 : else if( remainder[width] == '\n' ) {
3725 0 : spliceLine( indent, remainder, width );
3726 0 : if( width <= 1 || remainder.size() != 1 )
3727 0 : remainder = remainder.substr( 1 );
3728 0 : indent = _attr.indent;
3729 : }
3730 : else {
3731 0 : pos = remainder.find_last_of( wrappableChars, width );
3732 0 : if( pos != std::string::npos && pos > 0 ) {
3733 0 : spliceLine( indent, remainder, pos );
3734 0 : if( remainder[0] == ' ' )
3735 0 : remainder = remainder.substr( 1 );
3736 : }
3737 : else {
3738 0 : spliceLine( indent, remainder, width-1 );
3739 0 : lines.back() += "-";
3740 : }
3741 0 : if( lines.size() == 1 )
3742 0 : indent = _attr.indent;
3743 0 : if( tabPos != std::string::npos )
3744 0 : indent += tabPos;
3745 : }
3746 0 : }
3747 : }
3748 :
3749 0 : void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) {
3750 0 : lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) );
3751 0 : _remainder = _remainder.substr( _pos );
3752 0 : }
3753 :
3754 : typedef std::vector<std::string>::const_iterator const_iterator;
3755 :
3756 : const_iterator begin() const { return lines.begin(); }
3757 : const_iterator end() const { return lines.end(); }
3758 : std::string const& last() const { return lines.back(); }
3759 0 : std::size_t size() const { return lines.size(); }
3760 0 : std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
3761 : std::string toString() const {
3762 : std::ostringstream oss;
3763 : oss << *this;
3764 : return oss.str();
3765 : }
3766 :
3767 : inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) {
3768 : for( Text::const_iterator it = _text.begin(), itEnd = _text.end();
3769 : it != itEnd; ++it ) {
3770 : if( it != _text.begin() )
3771 : _stream << "\n";
3772 : _stream << *it;
3773 : }
3774 : return _stream;
3775 : }
3776 :
3777 : private:
3778 : std::string str;
3779 : TextAttributes attr;
3780 : std::vector<std::string> lines;
3781 : };
3782 :
3783 : } // end namespace Tbc
3784 :
3785 : #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
3786 : } // end outer namespace
3787 : #endif
3788 :
3789 : #endif // TBC_TEXT_FORMAT_H_INCLUDED
3790 :
3791 : // ----------- end of #include from tbc_text_format.h -----------
3792 : // ........... back in clara.h
3793 :
3794 : #undef STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE
3795 :
3796 : // ----------- #included from clara_compilers.h -----------
3797 :
3798 : #ifndef TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
3799 : #define TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
3800 :
3801 : // Detect a number of compiler features - mostly C++11/14 conformance - by compiler
3802 : // The following features are defined:
3803 : //
3804 : // CLARA_CONFIG_CPP11_NULLPTR : is nullptr supported?
3805 : // CLARA_CONFIG_CPP11_NOEXCEPT : is noexcept supported?
3806 : // CLARA_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods
3807 : // CLARA_CONFIG_CPP11_OVERRIDE : is override supported?
3808 : // CLARA_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr)
3809 :
3810 : // CLARA_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
3811 :
3812 : // CLARA_CONFIG_VARIADIC_MACROS : are variadic macros supported?
3813 :
3814 : // In general each macro has a _NO_<feature name> form
3815 : // (e.g. CLARA_CONFIG_CPP11_NO_NULLPTR) which disables the feature.
3816 : // Many features, at point of detection, define an _INTERNAL_ macro, so they
3817 : // can be combined, en-mass, with the _NO_ forms later.
3818 :
3819 : // All the C++11 features can be disabled with CLARA_CONFIG_NO_CPP11
3820 :
3821 : #ifdef __clang__
3822 :
3823 : #if __has_feature(cxx_nullptr)
3824 : #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
3825 : #endif
3826 :
3827 : #if __has_feature(cxx_noexcept)
3828 : #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
3829 : #endif
3830 :
3831 : #endif // __clang__
3832 :
3833 : ////////////////////////////////////////////////////////////////////////////////
3834 : // GCC
3835 : #ifdef __GNUC__
3836 :
3837 : #if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
3838 : #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
3839 : #endif
3840 :
3841 : // - otherwise more recent versions define __cplusplus >= 201103L
3842 : // and will get picked up below
3843 :
3844 : #endif // __GNUC__
3845 :
3846 : ////////////////////////////////////////////////////////////////////////////////
3847 : // Visual C++
3848 : #ifdef _MSC_VER
3849 :
3850 : #if (_MSC_VER >= 1600)
3851 : #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
3852 : #define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
3853 : #endif
3854 :
3855 : #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
3856 : #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
3857 : #define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
3858 : #endif
3859 :
3860 : #endif // _MSC_VER
3861 :
3862 : ////////////////////////////////////////////////////////////////////////////////
3863 : // C++ language feature support
3864 :
3865 : // catch all support for C++11
3866 : #if defined(__cplusplus) && __cplusplus >= 201103L
3867 :
3868 : #define CLARA_CPP11_OR_GREATER
3869 :
3870 : #if !defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR)
3871 : #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR
3872 : #endif
3873 :
3874 : #ifndef CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
3875 : #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT
3876 : #endif
3877 :
3878 : #ifndef CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
3879 : #define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
3880 : #endif
3881 :
3882 : #if !defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE)
3883 : #define CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE
3884 : #endif
3885 : #if !defined(CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
3886 : #define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
3887 : #endif
3888 :
3889 : #endif // __cplusplus >= 201103L
3890 :
3891 : // Now set the actual defines based on the above + anything the user has configured
3892 : #if defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NO_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_NO_CPP11)
3893 : #define CLARA_CONFIG_CPP11_NULLPTR
3894 : #endif
3895 : #if defined(CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_NO_CPP11)
3896 : #define CLARA_CONFIG_CPP11_NOEXCEPT
3897 : #endif
3898 : #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)
3899 : #define CLARA_CONFIG_CPP11_GENERATED_METHODS
3900 : #endif
3901 : #if defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_OVERRIDE) && !defined(CLARA_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_CPP11)
3902 : #define CLARA_CONFIG_CPP11_OVERRIDE
3903 : #endif
3904 : #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)
3905 : #define CLARA_CONFIG_CPP11_UNIQUE_PTR
3906 : #endif
3907 :
3908 : // noexcept support:
3909 : #if defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_NOEXCEPT)
3910 : #define CLARA_NOEXCEPT noexcept
3911 : # define CLARA_NOEXCEPT_IS(x) noexcept(x)
3912 : #else
3913 : #define CLARA_NOEXCEPT throw()
3914 : # define CLARA_NOEXCEPT_IS(x)
3915 : #endif
3916 :
3917 : // nullptr support
3918 : #ifdef CLARA_CONFIG_CPP11_NULLPTR
3919 : #define CLARA_NULL nullptr
3920 : #else
3921 : #define CLARA_NULL NULL
3922 : #endif
3923 :
3924 : // override support
3925 : #ifdef CLARA_CONFIG_CPP11_OVERRIDE
3926 : #define CLARA_OVERRIDE override
3927 : #else
3928 : #define CLARA_OVERRIDE
3929 : #endif
3930 :
3931 : // unique_ptr support
3932 : #ifdef CLARA_CONFIG_CPP11_UNIQUE_PTR
3933 : # define CLARA_AUTO_PTR( T ) std::unique_ptr<T>
3934 : #else
3935 : # define CLARA_AUTO_PTR( T ) std::auto_ptr<T>
3936 : #endif
3937 :
3938 : #endif // TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED
3939 :
3940 : // ----------- end of #include from clara_compilers.h -----------
3941 : // ........... back in clara.h
3942 :
3943 : #include <map>
3944 : #include <stdexcept>
3945 : #include <memory>
3946 :
3947 : #if defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
3948 : #define CLARA_PLATFORM_WINDOWS
3949 : #endif
3950 :
3951 : // Use optional outer namespace
3952 : #ifdef STITCH_CLARA_OPEN_NAMESPACE
3953 : STITCH_CLARA_OPEN_NAMESPACE
3954 : #endif
3955 :
3956 : namespace Clara {
3957 :
3958 : struct UnpositionalTag {};
3959 :
3960 : extern UnpositionalTag _;
3961 :
3962 : #ifdef CLARA_CONFIG_MAIN
3963 : UnpositionalTag _;
3964 : #endif
3965 :
3966 : namespace Detail {
3967 :
3968 : #ifdef CLARA_CONSOLE_WIDTH
3969 : const unsigned int consoleWidth = CLARA_CONFIG_CONSOLE_WIDTH;
3970 : #else
3971 : const unsigned int consoleWidth = 80;
3972 : #endif
3973 :
3974 : using namespace Tbc;
3975 :
3976 56 : inline bool startsWith( std::string const& str, std::string const& prefix ) {
3977 56 : return str.size() >= prefix.size() && str.substr( 0, prefix.size() ) == prefix;
3978 : }
3979 :
3980 : template<typename T> struct RemoveConstRef{ typedef T type; };
3981 : template<typename T> struct RemoveConstRef<T&>{ typedef T type; };
3982 : template<typename T> struct RemoveConstRef<T const&>{ typedef T type; };
3983 : template<typename T> struct RemoveConstRef<T const>{ typedef T type; };
3984 :
3985 : template<typename T> struct IsBool { static const bool value = false; };
3986 : template<> struct IsBool<bool> { static const bool value = true; };
3987 :
3988 : template<typename T>
3989 0 : void convertInto( std::string const& _source, T& _dest ) {
3990 0 : std::stringstream ss;
3991 0 : ss << _source;
3992 0 : ss >> _dest;
3993 0 : if( ss.fail() )
3994 0 : throw std::runtime_error( "Unable to convert " + _source + " to destination type" );
3995 0 : }
3996 1 : inline void convertInto( std::string const& _source, std::string& _dest ) {
3997 1 : _dest = _source;
3998 1 : }
3999 0 : char toLowerCh(char c) {
4000 0 : return static_cast<char>( ::tolower( c ) );
4001 : }
4002 0 : inline void convertInto( std::string const& _source, bool& _dest ) {
4003 0 : std::string sourceLC = _source;
4004 0 : std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), toLowerCh );
4005 0 : if( sourceLC == "y" || sourceLC == "1" || sourceLC == "true" || sourceLC == "yes" || sourceLC == "on" )
4006 0 : _dest = true;
4007 0 : else if( sourceLC == "n" || sourceLC == "0" || sourceLC == "false" || sourceLC == "no" || sourceLC == "off" )
4008 0 : _dest = false;
4009 : else
4010 0 : throw std::runtime_error( "Expected a boolean value but did not recognise:\n '" + _source + "'" );
4011 0 : }
4012 :
4013 : template<typename ConfigT>
4014 80 : struct IArgFunction {
4015 80 : virtual ~IArgFunction() {}
4016 : #ifdef CLARA_CONFIG_CPP11_GENERATED_METHODS
4017 : IArgFunction() = default;
4018 : IArgFunction( IArgFunction const& ) = default;
4019 : #endif
4020 : virtual void set( ConfigT& config, std::string const& value ) const = 0;
4021 : virtual bool takesArg() const = 0;
4022 : virtual IArgFunction* clone() const = 0;
4023 : };
4024 :
4025 : template<typename ConfigT>
4026 : class BoundArgFunction {
4027 : public:
4028 23 : BoundArgFunction() : functionObj( CLARA_NULL ) {}
4029 25 : BoundArgFunction( IArgFunction<ConfigT>* _functionObj ) : functionObj( _functionObj ) {}
4030 53 : BoundArgFunction( BoundArgFunction const& other ) : functionObj( other.functionObj ? other.functionObj->clone() : CLARA_NULL ) {}
4031 24 : BoundArgFunction& operator = ( BoundArgFunction const& other ) {
4032 24 : IArgFunction<ConfigT>* newFunctionObj = other.functionObj ? other.functionObj->clone() : CLARA_NULL;
4033 24 : delete functionObj;
4034 24 : functionObj = newFunctionObj;
4035 24 : return *this;
4036 : }
4037 101 : ~BoundArgFunction() { delete functionObj; }
4038 :
4039 1 : void set( ConfigT& config, std::string const& value ) const {
4040 1 : functionObj->set( config, value );
4041 1 : }
4042 : bool takesArg() const { return functionObj->takesArg(); }
4043 :
4044 22 : bool isSet() const {
4045 22 : return functionObj != CLARA_NULL;
4046 : }
4047 : private:
4048 : IArgFunction<ConfigT>* functionObj;
4049 : };
4050 :
4051 : template<typename C>
4052 3 : struct NullBinder : IArgFunction<C>{
4053 0 : virtual void set( C&, std::string const& ) const {}
4054 0 : virtual bool takesArg() const { return true; }
4055 0 : virtual IArgFunction<C>* clone() const { return new NullBinder( *this ); }
4056 : };
4057 :
4058 : template<typename C, typename M>
4059 140 : struct BoundDataMember : IArgFunction<C>{
4060 13 : BoundDataMember( M C::* _member ) : member( _member ) {}
4061 1 : virtual void set( C& p, std::string const& stringValue ) const {
4062 1 : convertInto( stringValue, p.*member );
4063 1 : }
4064 0 : virtual bool takesArg() const { return !IsBool<M>::value; }
4065 38 : virtual IArgFunction<C>* clone() const { return new BoundDataMember( *this ); }
4066 : M C::* member;
4067 : };
4068 : template<typename C, typename M>
4069 : struct BoundUnaryMethod : IArgFunction<C>{
4070 : BoundUnaryMethod( void (C::*_member)( M ) ) : member( _member ) {}
4071 : virtual void set( C& p, std::string const& stringValue ) const {
4072 : typename RemoveConstRef<M>::type value;
4073 : convertInto( stringValue, value );
4074 : (p.*member)( value );
4075 : }
4076 : virtual bool takesArg() const { return !IsBool<M>::value; }
4077 : virtual IArgFunction<C>* clone() const { return new BoundUnaryMethod( *this ); }
4078 : void (C::*member)( M );
4079 : };
4080 : template<typename C>
4081 : struct BoundNullaryMethod : IArgFunction<C>{
4082 : BoundNullaryMethod( void (C::*_member)() ) : member( _member ) {}
4083 : virtual void set( C& p, std::string const& stringValue ) const {
4084 : bool value;
4085 : convertInto( stringValue, value );
4086 : if( value )
4087 : (p.*member)();
4088 : }
4089 : virtual bool takesArg() const { return false; }
4090 : virtual IArgFunction<C>* clone() const { return new BoundNullaryMethod( *this ); }
4091 : void (C::*member)();
4092 : };
4093 :
4094 : template<typename C>
4095 13 : struct BoundUnaryFunction : IArgFunction<C>{
4096 2 : BoundUnaryFunction( void (*_function)( C& ) ) : function( _function ) {}
4097 0 : virtual void set( C& obj, std::string const& stringValue ) const {
4098 : bool value;
4099 0 : convertInto( stringValue, value );
4100 0 : if( value )
4101 0 : function( obj );
4102 0 : }
4103 0 : virtual bool takesArg() const { return false; }
4104 3 : virtual IArgFunction<C>* clone() const { return new BoundUnaryFunction( *this ); }
4105 : void (*function)( C& );
4106 : };
4107 :
4108 : template<typename C, typename T>
4109 60 : struct BoundBinaryFunction : IArgFunction<C>{
4110 9 : BoundBinaryFunction( void (*_function)( C&, T ) ) : function( _function ) {}
4111 0 : virtual void set( C& obj, std::string const& stringValue ) const {
4112 0 : typename RemoveConstRef<T>::type value;
4113 0 : convertInto( stringValue, value );
4114 0 : function( obj, value );
4115 0 : }
4116 0 : virtual bool takesArg() const { return !IsBool<T>::value; }
4117 14 : virtual IArgFunction<C>* clone() const { return new BoundBinaryFunction( *this ); }
4118 : void (*function)( C&, T );
4119 : };
4120 :
4121 : } // namespace Detail
4122 :
4123 1 : inline std::vector<std::string> argsToVector( int argc, char const* const* const argv ) {
4124 1 : std::vector<std::string> args( static_cast<std::size_t>( argc ) );
4125 2 : for( std::size_t i = 0; i < static_cast<std::size_t>( argc ); ++i )
4126 1 : args[i] = argv[i];
4127 :
4128 1 : return args;
4129 : }
4130 :
4131 : class Parser {
4132 : enum Mode { None, MaybeShortOpt, SlashOpt, ShortOpt, LongOpt, Positional };
4133 : Mode mode;
4134 : std::size_t from;
4135 : bool inQuotes;
4136 : public:
4137 :
4138 0 : struct Token {
4139 : enum Type { Positional, ShortOpt, LongOpt };
4140 0 : Token( Type _type, std::string const& _data ) : type( _type ), data( _data ) {}
4141 : Type type;
4142 : std::string data;
4143 : };
4144 :
4145 1 : Parser() : mode( None ), from( 0 ), inQuotes( false ){}
4146 :
4147 1 : void parseIntoTokens( std::vector<std::string> const& args, std::vector<Token>& tokens ) {
4148 1 : const std::string doubleDash = "--";
4149 1 : for( std::size_t i = 1; i < args.size() && args[i] != doubleDash; ++i )
4150 1 : parseIntoTokens( args[i], tokens);
4151 1 : }
4152 :
4153 0 : void parseIntoTokens( std::string const& arg, std::vector<Token>& tokens ) {
4154 0 : for( std::size_t i = 0; i <= arg.size(); ++i ) {
4155 0 : char c = arg[i];
4156 0 : if( c == '"' )
4157 0 : inQuotes = !inQuotes;
4158 0 : mode = handleMode( i, c, arg, tokens );
4159 : }
4160 0 : }
4161 0 : Mode handleMode( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
4162 0 : switch( mode ) {
4163 0 : case None: return handleNone( i, c );
4164 0 : case MaybeShortOpt: return handleMaybeShortOpt( i, c );
4165 : case ShortOpt:
4166 : case LongOpt:
4167 0 : case SlashOpt: return handleOpt( i, c, arg, tokens );
4168 0 : case Positional: return handlePositional( i, c, arg, tokens );
4169 0 : default: throw std::logic_error( "Unknown mode" );
4170 : }
4171 : }
4172 :
4173 0 : Mode handleNone( std::size_t i, char c ) {
4174 0 : if( inQuotes ) {
4175 0 : from = i;
4176 0 : return Positional;
4177 : }
4178 0 : switch( c ) {
4179 0 : case '-': return MaybeShortOpt;
4180 : #ifdef CLARA_PLATFORM_WINDOWS
4181 : case '/': from = i+1; return SlashOpt;
4182 : #endif
4183 0 : default: from = i; return Positional;
4184 : }
4185 : }
4186 0 : Mode handleMaybeShortOpt( std::size_t i, char c ) {
4187 0 : switch( c ) {
4188 0 : case '-': from = i+1; return LongOpt;
4189 0 : default: from = i; return ShortOpt;
4190 : }
4191 : }
4192 0 : Mode handleOpt( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
4193 0 : if( std::string( ":=\0", 3 ).find( c ) == std::string::npos )
4194 0 : return mode;
4195 :
4196 0 : std::string optName = arg.substr( from, i-from );
4197 0 : if( mode == ShortOpt )
4198 0 : for( std::size_t j = 0; j < optName.size(); ++j )
4199 0 : tokens.push_back( Token( Token::ShortOpt, optName.substr( j, 1 ) ) );
4200 0 : else if( mode == SlashOpt && optName.size() == 1 )
4201 0 : tokens.push_back( Token( Token::ShortOpt, optName ) );
4202 : else
4203 0 : tokens.push_back( Token( Token::LongOpt, optName ) );
4204 0 : return None;
4205 : }
4206 0 : Mode handlePositional( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
4207 0 : if( inQuotes || std::string( "\0", 1 ).find( c ) == std::string::npos )
4208 0 : return mode;
4209 :
4210 0 : std::string data = arg.substr( from, i-from );
4211 0 : tokens.push_back( Token( Token::Positional, data ) );
4212 0 : return None;
4213 : }
4214 : };
4215 :
4216 : template<typename ConfigT>
4217 129 : struct CommonArgProperties {
4218 23 : CommonArgProperties() {}
4219 : CommonArgProperties( Detail::BoundArgFunction<ConfigT> const& _boundField ) : boundField( _boundField ) {}
4220 :
4221 : Detail::BoundArgFunction<ConfigT> boundField;
4222 : std::string description;
4223 : std::string detail;
4224 : std::string placeholder; // Only value if boundField takes an arg
4225 :
4226 0 : bool takesArg() const {
4227 0 : return !placeholder.empty();
4228 : }
4229 22 : void validate() const {
4230 22 : if( !boundField.isSet() )
4231 0 : throw std::logic_error( "option not bound" );
4232 22 : }
4233 : };
4234 152 : struct OptionArgProperties {
4235 : std::vector<std::string> shortNames;
4236 : std::string longName;
4237 :
4238 0 : bool hasShortName( std::string const& shortName ) const {
4239 0 : return std::find( shortNames.begin(), shortNames.end(), shortName ) != shortNames.end();
4240 : }
4241 0 : bool hasLongName( std::string const& _longName ) const {
4242 0 : return _longName == longName;
4243 : }
4244 : };
4245 : struct PositionalArgProperties {
4246 23 : PositionalArgProperties() : position( -1 ) {}
4247 : int position; // -1 means non-positional (floating)
4248 :
4249 : bool isFixedPositional() const {
4250 : return position != -1;
4251 : }
4252 : };
4253 :
4254 : template<typename ConfigT>
4255 1 : class CommandLine {
4256 :
4257 129 : struct Arg : CommonArgProperties<ConfigT>, OptionArgProperties, PositionalArgProperties {
4258 23 : Arg() {}
4259 : Arg( Detail::BoundArgFunction<ConfigT> const& _boundField ) : CommonArgProperties<ConfigT>( _boundField ) {}
4260 :
4261 : using CommonArgProperties<ConfigT>::placeholder; // !TBD
4262 :
4263 : std::string dbgName() const {
4264 : if( !longName.empty() )
4265 : return "--" + longName;
4266 : if( !shortNames.empty() )
4267 : return "-" + shortNames[0];
4268 : return "positional args";
4269 : }
4270 0 : std::string commands() const {
4271 0 : std::ostringstream oss;
4272 0 : bool first = true;
4273 0 : std::vector<std::string>::const_iterator it = shortNames.begin(), itEnd = shortNames.end();
4274 0 : for(; it != itEnd; ++it ) {
4275 0 : if( first )
4276 0 : first = false;
4277 : else
4278 0 : oss << ", ";
4279 0 : oss << "-" << *it;
4280 : }
4281 0 : if( !longName.empty() ) {
4282 0 : if( !first )
4283 0 : oss << ", ";
4284 0 : oss << "--" << longName;
4285 : }
4286 0 : if( !placeholder.empty() )
4287 0 : oss << " <" << placeholder << ">";
4288 0 : return oss.str();
4289 : }
4290 : };
4291 :
4292 : typedef CLARA_AUTO_PTR( Arg ) ArgAutoPtr;
4293 :
4294 39 : friend void addOptName( Arg& arg, std::string const& optName )
4295 : {
4296 39 : if( optName.empty() )
4297 39 : return;
4298 39 : if( Detail::startsWith( optName, "--" ) ) {
4299 22 : if( !arg.longName.empty() )
4300 0 : throw std::logic_error( "Only one long opt may be specified. '"
4301 : + arg.longName
4302 : + "' already specified, now attempting to add '"
4303 0 : + optName + "'" );
4304 22 : arg.longName = optName.substr( 2 );
4305 : }
4306 17 : else if( Detail::startsWith( optName, "-" ) )
4307 17 : arg.shortNames.push_back( optName.substr( 1 ) );
4308 : else
4309 0 : throw std::logic_error( "option must begin with - or --. Option was: '" + optName + "'" );
4310 : }
4311 : friend void setPositionalArg( Arg& arg, int position )
4312 : {
4313 : arg.position = position;
4314 : }
4315 :
4316 : class ArgBuilder {
4317 : public:
4318 23 : ArgBuilder( Arg* arg ) : m_arg( arg ) {}
4319 :
4320 : // Bind a non-boolean data member (requires placeholder string)
4321 : template<typename C, typename M>
4322 2 : void bind( M C::* field, std::string const& placeholder ) {
4323 2 : m_arg->boundField = new Detail::BoundDataMember<C,M>( field );
4324 2 : m_arg->placeholder = placeholder;
4325 2 : }
4326 : // Bind a boolean data member (no placeholder required)
4327 : template<typename C>
4328 10 : void bind( bool C::* field ) {
4329 10 : m_arg->boundField = new Detail::BoundDataMember<C,bool>( field );
4330 10 : }
4331 :
4332 : // Bind a method taking a single, non-boolean argument (requires a placeholder string)
4333 : template<typename C, typename M>
4334 : void bind( void (C::* unaryMethod)( M ), std::string const& placeholder ) {
4335 : m_arg->boundField = new Detail::BoundUnaryMethod<C,M>( unaryMethod );
4336 : m_arg->placeholder = placeholder;
4337 : }
4338 :
4339 : // Bind a method taking a single, boolean argument (no placeholder string required)
4340 : template<typename C>
4341 : void bind( void (C::* unaryMethod)( bool ) ) {
4342 : m_arg->boundField = new Detail::BoundUnaryMethod<C,bool>( unaryMethod );
4343 : }
4344 :
4345 : // Bind a method that takes no arguments (will be called if opt is present)
4346 : template<typename C>
4347 : void bind( void (C::* nullaryMethod)() ) {
4348 : m_arg->boundField = new Detail::BoundNullaryMethod<C>( nullaryMethod );
4349 : }
4350 :
4351 : // Bind a free function taking a single argument - the object to operate on (no placeholder string required)
4352 : template<typename C>
4353 2 : void bind( void (* unaryFunction)( C& ) ) {
4354 2 : m_arg->boundField = new Detail::BoundUnaryFunction<C>( unaryFunction );
4355 2 : }
4356 :
4357 : // Bind a free function taking a single argument - the object to operate on (requires a placeholder string)
4358 : template<typename C, typename T>
4359 9 : void bind( void (* binaryFunction)( C&, T ), std::string const& placeholder ) {
4360 9 : m_arg->boundField = new Detail::BoundBinaryFunction<C, T>( binaryFunction );
4361 9 : m_arg->placeholder = placeholder;
4362 9 : }
4363 :
4364 23 : ArgBuilder& describe( std::string const& description ) {
4365 23 : m_arg->description = description;
4366 23 : return *this;
4367 : }
4368 : ArgBuilder& detail( std::string const& detail ) {
4369 : m_arg->detail = detail;
4370 : return *this;
4371 : }
4372 :
4373 : protected:
4374 : Arg* m_arg;
4375 : };
4376 :
4377 : class OptBuilder : public ArgBuilder {
4378 : public:
4379 22 : OptBuilder( Arg* arg ) : ArgBuilder( arg ) {}
4380 : OptBuilder( OptBuilder& other ) : ArgBuilder( other ) {}
4381 :
4382 17 : OptBuilder& operator[]( std::string const& optName ) {
4383 17 : addOptName( *ArgBuilder::m_arg, optName );
4384 17 : return *this;
4385 : }
4386 : };
4387 :
4388 : public:
4389 :
4390 1 : CommandLine()
4391 : : m_boundProcessName( new Detail::NullBinder<ConfigT>() ),
4392 : m_highestSpecifiedArgPosition( 0 ),
4393 1 : m_throwOnUnrecognisedTokens( false )
4394 1 : {}
4395 : CommandLine( CommandLine const& other )
4396 : : m_boundProcessName( other.m_boundProcessName ),
4397 : m_options ( other.m_options ),
4398 : m_positionalArgs( other.m_positionalArgs ),
4399 : m_highestSpecifiedArgPosition( other.m_highestSpecifiedArgPosition ),
4400 : m_throwOnUnrecognisedTokens( other.m_throwOnUnrecognisedTokens )
4401 : {
4402 : if( other.m_floatingArg.get() )
4403 : m_floatingArg.reset( new Arg( *other.m_floatingArg ) );
4404 : }
4405 :
4406 1 : CommandLine& setThrowOnUnrecognisedTokens( bool shouldThrow = true ) {
4407 1 : m_throwOnUnrecognisedTokens = shouldThrow;
4408 1 : return *this;
4409 : }
4410 :
4411 22 : OptBuilder operator[]( std::string const& optName ) {
4412 22 : m_options.push_back( Arg() );
4413 22 : addOptName( m_options.back(), optName );
4414 22 : OptBuilder builder( &m_options.back() );
4415 22 : return builder;
4416 : }
4417 :
4418 : ArgBuilder operator[]( int position ) {
4419 : m_positionalArgs.insert( std::make_pair( position, Arg() ) );
4420 : if( position > m_highestSpecifiedArgPosition )
4421 : m_highestSpecifiedArgPosition = position;
4422 : setPositionalArg( m_positionalArgs[position], position );
4423 : ArgBuilder builder( &m_positionalArgs[position] );
4424 : return builder;
4425 : }
4426 :
4427 : // Invoke this with the _ instance
4428 1 : ArgBuilder operator[]( UnpositionalTag ) {
4429 1 : if( m_floatingArg.get() )
4430 0 : throw std::logic_error( "Only one unpositional argument can be added" );
4431 1 : m_floatingArg.reset( new Arg() );
4432 1 : ArgBuilder builder( m_floatingArg.get() );
4433 1 : return builder;
4434 : }
4435 :
4436 : template<typename C, typename M>
4437 1 : void bindProcessName( M C::* field ) {
4438 1 : m_boundProcessName = new Detail::BoundDataMember<C,M>( field );
4439 1 : }
4440 : template<typename C, typename M>
4441 : void bindProcessName( void (C::*_unaryMethod)( M ) ) {
4442 : m_boundProcessName = new Detail::BoundUnaryMethod<C,M>( _unaryMethod );
4443 : }
4444 :
4445 0 : void optUsage( std::ostream& os, std::size_t indent = 0, std::size_t width = Detail::consoleWidth ) const {
4446 0 : typename std::vector<Arg>::const_iterator itBegin = m_options.begin(), itEnd = m_options.end(), it;
4447 0 : std::size_t maxWidth = 0;
4448 0 : for( it = itBegin; it != itEnd; ++it )
4449 0 : maxWidth = (std::max)( maxWidth, it->commands().size() );
4450 :
4451 0 : for( it = itBegin; it != itEnd; ++it ) {
4452 : Detail::Text usage( it->commands(), Detail::TextAttributes()
4453 0 : .setWidth( maxWidth+indent )
4454 0 : .setIndent( indent ) );
4455 0 : Detail::Text desc( it->description, Detail::TextAttributes()
4456 0 : .setWidth( width - maxWidth - 3 ) );
4457 :
4458 0 : for( std::size_t i = 0; i < (std::max)( usage.size(), desc.size() ); ++i ) {
4459 0 : std::string usageCol = i < usage.size() ? usage[i] : "";
4460 0 : os << usageCol;
4461 :
4462 0 : if( i < desc.size() && !desc[i].empty() )
4463 0 : os << std::string( indent + 2 + maxWidth - usageCol.size(), ' ' )
4464 0 : << desc[i];
4465 0 : os << "\n";
4466 : }
4467 : }
4468 0 : }
4469 : std::string optUsage() const {
4470 : std::ostringstream oss;
4471 : optUsage( oss );
4472 : return oss.str();
4473 : }
4474 :
4475 0 : void argSynopsis( std::ostream& os ) const {
4476 0 : for( int i = 1; i <= m_highestSpecifiedArgPosition; ++i ) {
4477 0 : if( i > 1 )
4478 0 : os << " ";
4479 0 : typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( i );
4480 0 : if( it != m_positionalArgs.end() )
4481 0 : os << "<" << it->second.placeholder << ">";
4482 0 : else if( m_floatingArg.get() )
4483 0 : os << "<" << m_floatingArg->placeholder << ">";
4484 : else
4485 0 : throw std::logic_error( "non consecutive positional arguments with no floating args" );
4486 : }
4487 : // !TBD No indication of mandatory args
4488 0 : if( m_floatingArg.get() ) {
4489 0 : if( m_highestSpecifiedArgPosition > 1 )
4490 0 : os << " ";
4491 0 : os << "[<" << m_floatingArg->placeholder << "> ...]";
4492 : }
4493 0 : }
4494 : std::string argSynopsis() const {
4495 : std::ostringstream oss;
4496 : argSynopsis( oss );
4497 : return oss.str();
4498 : }
4499 :
4500 0 : void usage( std::ostream& os, std::string const& procName ) const {
4501 0 : validate();
4502 0 : os << "usage:\n " << procName << " ";
4503 0 : argSynopsis( os );
4504 0 : if( !m_options.empty() ) {
4505 0 : os << " [options]\n\nwhere options are: \n";
4506 0 : optUsage( os, 2 );
4507 : }
4508 0 : os << "\n";
4509 0 : }
4510 : std::string usage( std::string const& procName ) const {
4511 : std::ostringstream oss;
4512 : usage( oss, procName );
4513 : return oss.str();
4514 : }
4515 :
4516 : ConfigT parse( std::vector<std::string> const& args ) const {
4517 : ConfigT config;
4518 : parseInto( args, config );
4519 : return config;
4520 : }
4521 :
4522 1 : std::vector<Parser::Token> parseInto( std::vector<std::string> const& args, ConfigT& config ) const {
4523 1 : std::string processName = args[0];
4524 1 : std::size_t lastSlash = processName.find_last_of( "/\\" );
4525 1 : if( lastSlash != std::string::npos )
4526 1 : processName = processName.substr( lastSlash+1 );
4527 1 : m_boundProcessName.set( config, processName );
4528 2 : std::vector<Parser::Token> tokens;
4529 1 : Parser parser;
4530 1 : parser.parseIntoTokens( args, tokens );
4531 2 : return populate( tokens, config );
4532 : }
4533 :
4534 1 : std::vector<Parser::Token> populate( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
4535 1 : validate();
4536 1 : std::vector<Parser::Token> unusedTokens = populateOptions( tokens, config );
4537 1 : unusedTokens = populateFixedArgs( unusedTokens, config );
4538 1 : unusedTokens = populateFloatingArgs( unusedTokens, config );
4539 1 : return unusedTokens;
4540 : }
4541 :
4542 1 : std::vector<Parser::Token> populateOptions( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
4543 1 : std::vector<Parser::Token> unusedTokens;
4544 2 : std::vector<std::string> errors;
4545 1 : for( std::size_t i = 0; i < tokens.size(); ++i ) {
4546 0 : Parser::Token const& token = tokens[i];
4547 0 : typename std::vector<Arg>::const_iterator it = m_options.begin(), itEnd = m_options.end();
4548 0 : for(; it != itEnd; ++it ) {
4549 0 : Arg const& arg = *it;
4550 :
4551 : try {
4552 0 : if( ( token.type == Parser::Token::ShortOpt && arg.hasShortName( token.data ) ) ||
4553 0 : ( token.type == Parser::Token::LongOpt && arg.hasLongName( token.data ) ) ) {
4554 0 : if( arg.takesArg() ) {
4555 0 : if( i == tokens.size()-1 || tokens[i+1].type != Parser::Token::Positional )
4556 0 : errors.push_back( "Expected argument to option: " + token.data );
4557 : else
4558 0 : arg.boundField.set( config, tokens[++i].data );
4559 : }
4560 : else {
4561 0 : arg.boundField.set( config, "true" );
4562 : }
4563 0 : break;
4564 : }
4565 : }
4566 : catch( std::exception& ex ) {
4567 : errors.push_back( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" );
4568 : }
4569 : }
4570 0 : if( it == itEnd ) {
4571 0 : if( token.type == Parser::Token::Positional || !m_throwOnUnrecognisedTokens )
4572 0 : unusedTokens.push_back( token );
4573 0 : else if( errors.empty() && m_throwOnUnrecognisedTokens )
4574 0 : errors.push_back( "unrecognised option: " + token.data );
4575 : }
4576 : }
4577 1 : if( !errors.empty() ) {
4578 0 : std::ostringstream oss;
4579 0 : for( std::vector<std::string>::const_iterator it = errors.begin(), itEnd = errors.end();
4580 : it != itEnd;
4581 : ++it ) {
4582 0 : if( it != errors.begin() )
4583 0 : oss << "\n";
4584 0 : oss << *it;
4585 : }
4586 0 : throw std::runtime_error( oss.str() );
4587 : }
4588 2 : return unusedTokens;
4589 : }
4590 1 : std::vector<Parser::Token> populateFixedArgs( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
4591 1 : std::vector<Parser::Token> unusedTokens;
4592 1 : int position = 1;
4593 1 : for( std::size_t i = 0; i < tokens.size(); ++i ) {
4594 0 : Parser::Token const& token = tokens[i];
4595 0 : typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( position );
4596 0 : if( it != m_positionalArgs.end() )
4597 0 : it->second.boundField.set( config, token.data );
4598 : else
4599 0 : unusedTokens.push_back( token );
4600 0 : if( token.type == Parser::Token::Positional )
4601 0 : position++;
4602 : }
4603 1 : return unusedTokens;
4604 : }
4605 1 : std::vector<Parser::Token> populateFloatingArgs( std::vector<Parser::Token> const& tokens, ConfigT& config ) const {
4606 1 : if( !m_floatingArg.get() )
4607 0 : return tokens;
4608 1 : std::vector<Parser::Token> unusedTokens;
4609 1 : for( std::size_t i = 0; i < tokens.size(); ++i ) {
4610 0 : Parser::Token const& token = tokens[i];
4611 0 : if( token.type == Parser::Token::Positional )
4612 0 : m_floatingArg->boundField.set( config, token.data );
4613 : else
4614 0 : unusedTokens.push_back( token );
4615 : }
4616 1 : return unusedTokens;
4617 : }
4618 :
4619 1 : void validate() const
4620 : {
4621 1 : if( m_options.empty() && m_positionalArgs.empty() && !m_floatingArg.get() )
4622 0 : throw std::logic_error( "No options or arguments specified" );
4623 :
4624 24 : for( typename std::vector<Arg>::const_iterator it = m_options.begin(),
4625 1 : itEnd = m_options.end();
4626 : it != itEnd; ++it )
4627 22 : it->validate();
4628 1 : }
4629 :
4630 : private:
4631 : Detail::BoundArgFunction<ConfigT> m_boundProcessName;
4632 : std::vector<Arg> m_options;
4633 : std::map<int, Arg> m_positionalArgs;
4634 : ArgAutoPtr m_floatingArg;
4635 : int m_highestSpecifiedArgPosition;
4636 : bool m_throwOnUnrecognisedTokens;
4637 : };
4638 :
4639 : } // end namespace Clara
4640 :
4641 : STITCH_CLARA_CLOSE_NAMESPACE
4642 : #undef STITCH_CLARA_OPEN_NAMESPACE
4643 : #undef STITCH_CLARA_CLOSE_NAMESPACE
4644 :
4645 : #endif // TWOBLUECUBES_CLARA_H_INCLUDED
4646 : #undef STITCH_CLARA_OPEN_NAMESPACE
4647 :
4648 : // Restore Clara's value for console width, if present
4649 : #ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
4650 : #define CLARA_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
4651 : #undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
4652 : #endif
4653 :
4654 : #include <fstream>
4655 :
4656 : namespace Catch {
4657 :
4658 0 : inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; }
4659 0 : inline void abortAfterX( ConfigData& config, int x ) {
4660 0 : if( x < 1 )
4661 0 : throw std::runtime_error( "Value after -x or --abortAfter must be greater than zero" );
4662 0 : config.abortAfter = x;
4663 0 : }
4664 0 : inline void addTestOrTags( ConfigData& config, std::string const& _testSpec ) { config.testsOrTags.push_back( _testSpec ); }
4665 0 : inline void addReporterName( ConfigData& config, std::string const& _reporterName ) { config.reporterNames.push_back( _reporterName ); }
4666 :
4667 0 : inline void addWarning( ConfigData& config, std::string const& _warning ) {
4668 0 : if( _warning == "NoAssertions" )
4669 0 : config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions );
4670 : else
4671 0 : throw std::runtime_error( "Unrecognised warning: '" + _warning + "'" );
4672 0 : }
4673 0 : inline void setOrder( ConfigData& config, std::string const& order ) {
4674 0 : if( startsWith( "declared", order ) )
4675 0 : config.runOrder = RunTests::InDeclarationOrder;
4676 0 : else if( startsWith( "lexical", order ) )
4677 0 : config.runOrder = RunTests::InLexicographicalOrder;
4678 0 : else if( startsWith( "random", order ) )
4679 0 : config.runOrder = RunTests::InRandomOrder;
4680 : else
4681 0 : throw std::runtime_error( "Unrecognised ordering: '" + order + "'" );
4682 0 : }
4683 0 : inline void setRngSeed( ConfigData& config, std::string const& seed ) {
4684 0 : if( seed == "time" ) {
4685 0 : config.rngSeed = static_cast<unsigned int>( std::time(0) );
4686 : }
4687 : else {
4688 0 : std::stringstream ss;
4689 0 : ss << seed;
4690 0 : ss >> config.rngSeed;
4691 0 : if( ss.fail() )
4692 0 : throw std::runtime_error( "Argment to --rng-seed should be the word 'time' or a number" );
4693 : }
4694 0 : }
4695 : inline void setVerbosity( ConfigData& config, int level ) {
4696 : // !TBD: accept strings?
4697 : config.verbosity = static_cast<Verbosity::Level>( level );
4698 : }
4699 0 : inline void setShowDurations( ConfigData& config, bool _showDurations ) {
4700 : config.showDurations = _showDurations
4701 : ? ShowDurations::Always
4702 0 : : ShowDurations::Never;
4703 0 : }
4704 0 : inline void setUseColour( ConfigData& config, std::string const& value ) {
4705 0 : std::string mode = toLower( value );
4706 :
4707 0 : if( mode == "yes" )
4708 0 : config.useColour = UseColour::Yes;
4709 0 : else if( mode == "no" )
4710 0 : config.useColour = UseColour::No;
4711 0 : else if( mode == "auto" )
4712 0 : config.useColour = UseColour::Auto;
4713 : else
4714 0 : throw std::runtime_error( "colour mode must be one of: auto, yes or no" );
4715 0 : }
4716 0 : inline void forceColour( ConfigData& config ) {
4717 0 : config.useColour = UseColour::Yes;
4718 0 : }
4719 0 : inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) {
4720 0 : std::ifstream f( _filename.c_str() );
4721 0 : if( !f.is_open() )
4722 0 : throw std::domain_error( "Unable to load input file: " + _filename );
4723 :
4724 0 : std::string line;
4725 0 : while( std::getline( f, line ) ) {
4726 0 : line = trim(line);
4727 0 : if( !line.empty() && !startsWith( line, "#" ) ) {
4728 0 : if( !startsWith( line, "\"" ) )
4729 0 : line = "\"" + line + "\"";
4730 0 : addTestOrTags( config, line + "," );
4731 : }
4732 0 : }
4733 0 : }
4734 :
4735 1 : inline Clara::CommandLine<ConfigData> makeCommandLineParser() {
4736 :
4737 : using namespace Clara;
4738 1 : CommandLine<ConfigData> cli;
4739 :
4740 1 : cli.bindProcessName( &ConfigData::processName );
4741 :
4742 2 : cli["-?"]["-h"]["--help"]
4743 3 : .describe( "display usage information" )
4744 1 : .bind( &ConfigData::showHelp );
4745 :
4746 2 : cli["-l"]["--list-tests"]
4747 3 : .describe( "list all/matching test cases" )
4748 1 : .bind( &ConfigData::listTests );
4749 :
4750 2 : cli["-t"]["--list-tags"]
4751 3 : .describe( "list all/matching tags" )
4752 1 : .bind( &ConfigData::listTags );
4753 :
4754 2 : cli["-s"]["--success"]
4755 3 : .describe( "include successful tests in output" )
4756 1 : .bind( &ConfigData::showSuccessfulTests );
4757 :
4758 2 : cli["-b"]["--break"]
4759 3 : .describe( "break into debugger on failure" )
4760 1 : .bind( &ConfigData::shouldDebugBreak );
4761 :
4762 2 : cli["-e"]["--nothrow"]
4763 3 : .describe( "skip exception tests" )
4764 1 : .bind( &ConfigData::noThrow );
4765 :
4766 2 : cli["-i"]["--invisibles"]
4767 3 : .describe( "show invisibles (tabs, newlines)" )
4768 1 : .bind( &ConfigData::showInvisibles );
4769 :
4770 2 : cli["-o"]["--out"]
4771 3 : .describe( "output filename" )
4772 3 : .bind( &ConfigData::outputFilename, "filename" );
4773 :
4774 2 : cli["-r"]["--reporter"]
4775 : // .placeholder( "name[:filename]" )
4776 3 : .describe( "reporter to use (defaults to console)" )
4777 3 : .bind( &addReporterName, "name" );
4778 :
4779 2 : cli["-n"]["--name"]
4780 3 : .describe( "suite name" )
4781 3 : .bind( &ConfigData::name, "name" );
4782 :
4783 2 : cli["-a"]["--abort"]
4784 3 : .describe( "abort at first failure" )
4785 1 : .bind( &abortAfterFirst );
4786 :
4787 2 : cli["-x"]["--abortx"]
4788 3 : .describe( "abort after x failures" )
4789 3 : .bind( &abortAfterX, "no. failures" );
4790 :
4791 2 : cli["-w"]["--warn"]
4792 3 : .describe( "enable warnings" )
4793 3 : .bind( &addWarning, "warning name" );
4794 :
4795 : // - needs updating if reinstated
4796 : // cli.into( &setVerbosity )
4797 : // .describe( "level of verbosity (0=no output)" )
4798 : // .shortOpt( "v")
4799 : // .longOpt( "verbosity" )
4800 : // .placeholder( "level" );
4801 :
4802 : cli[_]
4803 2 : .describe( "which test or tests to use" )
4804 3 : .bind( &addTestOrTags, "test name, pattern or tags" );
4805 :
4806 2 : cli["-d"]["--durations"]
4807 3 : .describe( "show test durations" )
4808 3 : .bind( &setShowDurations, "yes|no" );
4809 :
4810 2 : cli["-f"]["--input-file"]
4811 3 : .describe( "load test names to run from a file" )
4812 3 : .bind( &loadTestNamesFromFile, "filename" );
4813 :
4814 2 : cli["-#"]["--filenames-as-tags"]
4815 3 : .describe( "adds a tag for the filename" )
4816 1 : .bind( &ConfigData::filenamesAsTags );
4817 :
4818 : // Less common commands which don't have a short form
4819 : cli["--list-test-names-only"]
4820 2 : .describe( "list all/matching test cases names only" )
4821 1 : .bind( &ConfigData::listTestNamesOnly );
4822 :
4823 : cli["--list-reporters"]
4824 2 : .describe( "list all reporters" )
4825 1 : .bind( &ConfigData::listReporters );
4826 :
4827 : cli["--order"]
4828 2 : .describe( "test case order (defaults to decl)" )
4829 3 : .bind( &setOrder, "decl|lex|rand" );
4830 :
4831 : cli["--rng-seed"]
4832 2 : .describe( "set a specific seed for random numbers" )
4833 3 : .bind( &setRngSeed, "'time'|number" );
4834 :
4835 : cli["--force-colour"]
4836 2 : .describe( "force colourised output (deprecated)" )
4837 1 : .bind( &forceColour );
4838 :
4839 : cli["--use-colour"]
4840 2 : .describe( "should output be colourised" )
4841 3 : .bind( &setUseColour, "yes|no" );
4842 :
4843 1 : return cli;
4844 : }
4845 :
4846 : } // end namespace Catch
4847 :
4848 : // #included from: internal/catch_list.hpp
4849 : #define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
4850 :
4851 : // #included from: catch_text.h
4852 : #define TWOBLUECUBES_CATCH_TEXT_H_INCLUDED
4853 :
4854 : #define TBC_TEXT_FORMAT_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
4855 :
4856 : #define CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE Catch
4857 : // #included from: ../external/tbc_text_format.h
4858 : // Only use header guard if we are not using an outer namespace
4859 : #ifndef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
4860 : # ifdef TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED
4861 : # ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
4862 : # define TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
4863 : # endif
4864 : # else
4865 : # define TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED
4866 : # endif
4867 : #endif
4868 : #ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
4869 : #include <string>
4870 : #include <vector>
4871 : #include <sstream>
4872 :
4873 : // Use optional outer namespace
4874 : #ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
4875 : namespace CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE {
4876 : #endif
4877 :
4878 : namespace Tbc {
4879 :
4880 : #ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH
4881 : const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH;
4882 : #else
4883 : const unsigned int consoleWidth = 80;
4884 : #endif
4885 :
4886 : struct TextAttributes {
4887 0 : TextAttributes()
4888 : : initialIndent( std::string::npos ),
4889 : indent( 0 ),
4890 : width( consoleWidth-1 ),
4891 0 : tabChar( '\t' )
4892 0 : {}
4893 :
4894 0 : TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
4895 0 : TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
4896 0 : TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
4897 : TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; }
4898 :
4899 : std::size_t initialIndent; // indent of first line, or npos
4900 : std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
4901 : std::size_t width; // maximum width of text, including indent. Longer text will wrap
4902 : char tabChar; // If this char is seen the indent is changed to current pos
4903 : };
4904 :
4905 0 : class Text {
4906 : public:
4907 0 : Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() )
4908 0 : : attr( _attr )
4909 : {
4910 0 : std::string wrappableChars = " [({.,/|\\-";
4911 0 : std::size_t indent = _attr.initialIndent != std::string::npos
4912 : ? _attr.initialIndent
4913 0 : : _attr.indent;
4914 0 : std::string remainder = _str;
4915 :
4916 0 : while( !remainder.empty() ) {
4917 0 : if( lines.size() >= 1000 ) {
4918 0 : lines.push_back( "... message truncated due to excessive size" );
4919 0 : return;
4920 : }
4921 0 : std::size_t tabPos = std::string::npos;
4922 0 : std::size_t width = (std::min)( remainder.size(), _attr.width - indent );
4923 0 : std::size_t pos = remainder.find_first_of( '\n' );
4924 0 : if( pos <= width ) {
4925 0 : width = pos;
4926 : }
4927 0 : pos = remainder.find_last_of( _attr.tabChar, width );
4928 0 : if( pos != std::string::npos ) {
4929 0 : tabPos = pos;
4930 0 : if( remainder[width] == '\n' )
4931 0 : width--;
4932 0 : remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 );
4933 : }
4934 :
4935 0 : if( width == remainder.size() ) {
4936 0 : spliceLine( indent, remainder, width );
4937 : }
4938 0 : else if( remainder[width] == '\n' ) {
4939 0 : spliceLine( indent, remainder, width );
4940 0 : if( width <= 1 || remainder.size() != 1 )
4941 0 : remainder = remainder.substr( 1 );
4942 0 : indent = _attr.indent;
4943 : }
4944 : else {
4945 0 : pos = remainder.find_last_of( wrappableChars, width );
4946 0 : if( pos != std::string::npos && pos > 0 ) {
4947 0 : spliceLine( indent, remainder, pos );
4948 0 : if( remainder[0] == ' ' )
4949 0 : remainder = remainder.substr( 1 );
4950 : }
4951 : else {
4952 0 : spliceLine( indent, remainder, width-1 );
4953 0 : lines.back() += "-";
4954 : }
4955 0 : if( lines.size() == 1 )
4956 0 : indent = _attr.indent;
4957 0 : if( tabPos != std::string::npos )
4958 0 : indent += tabPos;
4959 : }
4960 0 : }
4961 : }
4962 :
4963 0 : void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) {
4964 0 : lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) );
4965 0 : _remainder = _remainder.substr( _pos );
4966 0 : }
4967 :
4968 : typedef std::vector<std::string>::const_iterator const_iterator;
4969 :
4970 0 : const_iterator begin() const { return lines.begin(); }
4971 0 : const_iterator end() const { return lines.end(); }
4972 : std::string const& last() const { return lines.back(); }
4973 : std::size_t size() const { return lines.size(); }
4974 : std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
4975 : std::string toString() const {
4976 : std::ostringstream oss;
4977 : oss << *this;
4978 : return oss.str();
4979 : }
4980 :
4981 0 : inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) {
4982 0 : for( Text::const_iterator it = _text.begin(), itEnd = _text.end();
4983 : it != itEnd; ++it ) {
4984 0 : if( it != _text.begin() )
4985 0 : _stream << "\n";
4986 0 : _stream << *it;
4987 : }
4988 0 : return _stream;
4989 : }
4990 :
4991 : private:
4992 : std::string str;
4993 : TextAttributes attr;
4994 : std::vector<std::string> lines;
4995 : };
4996 :
4997 : } // end namespace Tbc
4998 :
4999 : #ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
5000 : } // end outer namespace
5001 : #endif
5002 :
5003 : #endif // TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
5004 : #undef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
5005 :
5006 : namespace Catch {
5007 : using Tbc::Text;
5008 : using Tbc::TextAttributes;
5009 : }
5010 :
5011 : // #included from: catch_console_colour.hpp
5012 : #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_HPP_INCLUDED
5013 :
5014 : namespace Catch {
5015 :
5016 : struct Colour {
5017 : enum Code {
5018 : None = 0,
5019 :
5020 : White,
5021 : Red,
5022 : Green,
5023 : Blue,
5024 : Cyan,
5025 : Yellow,
5026 : Grey,
5027 :
5028 : Bright = 0x10,
5029 :
5030 : BrightRed = Bright | Red,
5031 : BrightGreen = Bright | Green,
5032 : LightGrey = Bright | Grey,
5033 : BrightWhite = Bright | White,
5034 :
5035 : // By intention
5036 : FileName = LightGrey,
5037 : Warning = Yellow,
5038 : ResultError = BrightRed,
5039 : ResultSuccess = BrightGreen,
5040 : ResultExpectedFailure = Warning,
5041 :
5042 : Error = BrightRed,
5043 : Success = Green,
5044 :
5045 : OriginalExpression = Cyan,
5046 : ReconstructedExpression = Yellow,
5047 :
5048 : SecondaryText = LightGrey,
5049 : Headers = White
5050 : };
5051 :
5052 : // Use constructed object for RAII guard
5053 : Colour( Code _colourCode );
5054 : Colour( Colour const& other );
5055 : ~Colour();
5056 :
5057 : // Use static method for one-shot changes
5058 : static void use( Code _colourCode );
5059 :
5060 : private:
5061 : bool m_moved;
5062 : };
5063 :
5064 4 : inline std::ostream& operator << ( std::ostream& os, Colour const& ) { return os; }
5065 :
5066 : } // end namespace Catch
5067 :
5068 : // #included from: catch_interfaces_reporter.h
5069 : #define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
5070 :
5071 : #include <string>
5072 : #include <ostream>
5073 : #include <map>
5074 : #include <assert.h>
5075 :
5076 : namespace Catch
5077 : {
5078 1 : struct ReporterConfig {
5079 1 : explicit ReporterConfig( Ptr<IConfig const> const& _fullConfig )
5080 1 : : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
5081 :
5082 : ReporterConfig( Ptr<IConfig const> const& _fullConfig, std::ostream& _stream )
5083 : : m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
5084 :
5085 1 : std::ostream& stream() const { return *m_stream; }
5086 1 : Ptr<IConfig const> fullConfig() const { return m_fullConfig; }
5087 :
5088 : private:
5089 : std::ostream* m_stream;
5090 : Ptr<IConfig const> m_fullConfig;
5091 : };
5092 :
5093 : struct ReporterPreferences {
5094 1 : ReporterPreferences()
5095 1 : : shouldRedirectStdOut( false )
5096 1 : {}
5097 :
5098 : bool shouldRedirectStdOut;
5099 : };
5100 :
5101 : template<typename T>
5102 3 : struct LazyStat : Option<T> {
5103 3 : LazyStat() : used( false ) {}
5104 33 : LazyStat& operator=( T const& _value ) {
5105 33 : Option<T>::operator=( _value );
5106 33 : used = false;
5107 33 : return *this;
5108 : }
5109 35 : void reset() {
5110 35 : Option<T>::reset();
5111 35 : used = false;
5112 35 : }
5113 : bool used;
5114 : };
5115 :
5116 5 : struct TestRunInfo {
5117 1 : TestRunInfo( std::string const& _name ) : name( _name ) {}
5118 : std::string name;
5119 : };
5120 6 : struct GroupInfo {
5121 2 : GroupInfo( std::string const& _name,
5122 : std::size_t _groupIndex,
5123 : std::size_t _groupsCount )
5124 : : name( _name ),
5125 : groupIndex( _groupIndex ),
5126 2 : groupsCounts( _groupsCount )
5127 2 : {}
5128 :
5129 : std::string name;
5130 : std::size_t groupIndex;
5131 : std::size_t groupsCounts;
5132 : };
5133 :
5134 0 : struct AssertionStats {
5135 2571 : AssertionStats( AssertionResult const& _assertionResult,
5136 : std::vector<MessageInfo> const& _infoMessages,
5137 : Totals const& _totals )
5138 : : assertionResult( _assertionResult ),
5139 : infoMessages( _infoMessages ),
5140 2571 : totals( _totals )
5141 : {
5142 2571 : if( assertionResult.hasMessage() ) {
5143 : // Copy message into messages list.
5144 : // !TBD This should have been done earlier, somewhere
5145 0 : MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
5146 0 : builder << assertionResult.getMessage();
5147 0 : builder.m_info.message = builder.m_stream.str();
5148 :
5149 0 : infoMessages.push_back( builder.m_info );
5150 : }
5151 2571 : }
5152 : virtual ~AssertionStats();
5153 :
5154 : # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
5155 : AssertionStats( AssertionStats const& ) = default;
5156 : AssertionStats( AssertionStats && ) = default;
5157 : AssertionStats& operator = ( AssertionStats const& ) = default;
5158 : AssertionStats& operator = ( AssertionStats && ) = default;
5159 : # endif
5160 :
5161 : AssertionResult assertionResult;
5162 : std::vector<MessageInfo> infoMessages;
5163 : Totals totals;
5164 : };
5165 :
5166 0 : struct SectionStats {
5167 115 : SectionStats( SectionInfo const& _sectionInfo,
5168 : Counts const& _assertions,
5169 : double _durationInSeconds,
5170 : bool _missingAssertions )
5171 : : sectionInfo( _sectionInfo ),
5172 : assertions( _assertions ),
5173 : durationInSeconds( _durationInSeconds ),
5174 115 : missingAssertions( _missingAssertions )
5175 115 : {}
5176 : virtual ~SectionStats();
5177 : # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
5178 : SectionStats( SectionStats const& ) = default;
5179 : SectionStats( SectionStats && ) = default;
5180 : SectionStats& operator = ( SectionStats const& ) = default;
5181 : SectionStats& operator = ( SectionStats && ) = default;
5182 : # endif
5183 :
5184 : SectionInfo sectionInfo;
5185 : Counts assertions;
5186 : double durationInSeconds;
5187 : bool missingAssertions;
5188 : };
5189 :
5190 0 : struct TestCaseStats {
5191 31 : TestCaseStats( TestCaseInfo const& _testInfo,
5192 : Totals const& _totals,
5193 : std::string const& _stdOut,
5194 : std::string const& _stdErr,
5195 : bool _aborting )
5196 : : testInfo( _testInfo ),
5197 : totals( _totals ),
5198 : stdOut( _stdOut ),
5199 : stdErr( _stdErr ),
5200 31 : aborting( _aborting )
5201 31 : {}
5202 : virtual ~TestCaseStats();
5203 :
5204 : # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
5205 : TestCaseStats( TestCaseStats const& ) = default;
5206 : TestCaseStats( TestCaseStats && ) = default;
5207 : TestCaseStats& operator = ( TestCaseStats const& ) = default;
5208 : TestCaseStats& operator = ( TestCaseStats && ) = default;
5209 : # endif
5210 :
5211 : TestCaseInfo testInfo;
5212 : Totals totals;
5213 : std::string stdOut;
5214 : std::string stdErr;
5215 : bool aborting;
5216 : };
5217 :
5218 0 : struct TestGroupStats {
5219 1 : TestGroupStats( GroupInfo const& _groupInfo,
5220 : Totals const& _totals,
5221 : bool _aborting )
5222 : : groupInfo( _groupInfo ),
5223 : totals( _totals ),
5224 1 : aborting( _aborting )
5225 1 : {}
5226 : TestGroupStats( GroupInfo const& _groupInfo )
5227 : : groupInfo( _groupInfo ),
5228 : aborting( false )
5229 : {}
5230 : virtual ~TestGroupStats();
5231 :
5232 : # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
5233 : TestGroupStats( TestGroupStats const& ) = default;
5234 : TestGroupStats( TestGroupStats && ) = default;
5235 : TestGroupStats& operator = ( TestGroupStats const& ) = default;
5236 : TestGroupStats& operator = ( TestGroupStats && ) = default;
5237 : # endif
5238 :
5239 : GroupInfo groupInfo;
5240 : Totals totals;
5241 : bool aborting;
5242 : };
5243 :
5244 : struct TestRunStats {
5245 1 : TestRunStats( TestRunInfo const& _runInfo,
5246 : Totals const& _totals,
5247 : bool _aborting )
5248 : : runInfo( _runInfo ),
5249 : totals( _totals ),
5250 1 : aborting( _aborting )
5251 1 : {}
5252 : virtual ~TestRunStats();
5253 :
5254 : # ifndef CATCH_CONFIG_CPP11_GENERATED_METHODS
5255 0 : TestRunStats( TestRunStats const& _other )
5256 : : runInfo( _other.runInfo ),
5257 : totals( _other.totals ),
5258 0 : aborting( _other.aborting )
5259 0 : {}
5260 : # else
5261 : TestRunStats( TestRunStats const& ) = default;
5262 : TestRunStats( TestRunStats && ) = default;
5263 : TestRunStats& operator = ( TestRunStats const& ) = default;
5264 : TestRunStats& operator = ( TestRunStats && ) = default;
5265 : # endif
5266 :
5267 : TestRunInfo runInfo;
5268 : Totals totals;
5269 : bool aborting;
5270 : };
5271 :
5272 : class MultipleReporters;
5273 :
5274 1 : struct IStreamingReporter : IShared {
5275 : virtual ~IStreamingReporter();
5276 :
5277 : // Implementing class must also provide the following static method:
5278 : // static std::string getDescription();
5279 :
5280 : virtual ReporterPreferences getPreferences() const = 0;
5281 :
5282 : virtual void noMatchingTestCases( std::string const& spec ) = 0;
5283 :
5284 : virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0;
5285 : virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0;
5286 :
5287 : virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
5288 : virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
5289 :
5290 : virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
5291 :
5292 : // The return value indicates if the messages buffer should be cleared:
5293 : virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
5294 :
5295 : virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
5296 : virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
5297 : virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
5298 : virtual void testRunEnded( TestRunStats const& testRunStats ) = 0;
5299 :
5300 : virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
5301 :
5302 0 : virtual MultipleReporters* tryAsMulti() { return CATCH_NULL; }
5303 : };
5304 :
5305 4 : struct IReporterFactory : IShared {
5306 : virtual ~IReporterFactory();
5307 : virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0;
5308 : virtual std::string getDescription() const = 0;
5309 : };
5310 :
5311 1 : struct IReporterRegistry {
5312 : typedef std::map<std::string, Ptr<IReporterFactory> > FactoryMap;
5313 : typedef std::vector<Ptr<IReporterFactory> > Listeners;
5314 :
5315 : virtual ~IReporterRegistry();
5316 : virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const = 0;
5317 : virtual FactoryMap const& getFactories() const = 0;
5318 : virtual Listeners const& getListeners() const = 0;
5319 : };
5320 :
5321 : Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter );
5322 :
5323 : }
5324 :
5325 : #include <limits>
5326 : #include <algorithm>
5327 :
5328 : namespace Catch {
5329 :
5330 0 : inline std::size_t listTests( Config const& config ) {
5331 :
5332 0 : TestSpec testSpec = config.testSpec();
5333 0 : if( config.testSpec().hasFilters() )
5334 0 : Catch::cout() << "Matching test cases:\n";
5335 : else {
5336 0 : Catch::cout() << "All available test cases:\n";
5337 0 : testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
5338 : }
5339 :
5340 0 : std::size_t matchedTests = 0;
5341 0 : TextAttributes nameAttr, tagsAttr;
5342 0 : nameAttr.setInitialIndent( 2 ).setIndent( 4 );
5343 0 : tagsAttr.setIndent( 6 );
5344 :
5345 0 : std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
5346 0 : for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
5347 : it != itEnd;
5348 : ++it ) {
5349 0 : matchedTests++;
5350 0 : TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
5351 0 : Colour::Code colour = testCaseInfo.isHidden()
5352 : ? Colour::SecondaryText
5353 0 : : Colour::None;
5354 0 : Colour colourGuard( colour );
5355 :
5356 0 : Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl;
5357 0 : if( !testCaseInfo.tags.empty() )
5358 0 : Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl;
5359 0 : }
5360 :
5361 0 : if( !config.testSpec().hasFilters() )
5362 0 : Catch::cout() << pluralise( matchedTests, "test case" ) << "\n" << std::endl;
5363 : else
5364 0 : Catch::cout() << pluralise( matchedTests, "matching test case" ) << "\n" << std::endl;
5365 0 : return matchedTests;
5366 : }
5367 :
5368 0 : inline std::size_t listTestsNamesOnly( Config const& config ) {
5369 0 : TestSpec testSpec = config.testSpec();
5370 0 : if( !config.testSpec().hasFilters() )
5371 0 : testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
5372 0 : std::size_t matchedTests = 0;
5373 0 : std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
5374 0 : for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
5375 : it != itEnd;
5376 : ++it ) {
5377 0 : matchedTests++;
5378 0 : TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
5379 0 : if( startsWith( testCaseInfo.name, "#" ) )
5380 0 : Catch::cout() << "\"" << testCaseInfo.name << "\"" << std::endl;
5381 : else
5382 0 : Catch::cout() << testCaseInfo.name << std::endl;
5383 : }
5384 0 : return matchedTests;
5385 : }
5386 :
5387 0 : struct TagInfo {
5388 0 : TagInfo() : count ( 0 ) {}
5389 0 : void add( std::string const& spelling ) {
5390 0 : ++count;
5391 0 : spellings.insert( spelling );
5392 0 : }
5393 0 : std::string all() const {
5394 0 : std::string out;
5395 0 : for( std::set<std::string>::const_iterator it = spellings.begin(), itEnd = spellings.end();
5396 : it != itEnd;
5397 : ++it )
5398 0 : out += "[" + *it + "]";
5399 0 : return out;
5400 : }
5401 : std::set<std::string> spellings;
5402 : std::size_t count;
5403 : };
5404 :
5405 0 : inline std::size_t listTags( Config const& config ) {
5406 0 : TestSpec testSpec = config.testSpec();
5407 0 : if( config.testSpec().hasFilters() )
5408 0 : Catch::cout() << "Tags for matching test cases:\n";
5409 : else {
5410 0 : Catch::cout() << "All available tags:\n";
5411 0 : testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
5412 : }
5413 :
5414 0 : std::map<std::string, TagInfo> tagCounts;
5415 :
5416 0 : std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
5417 0 : for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
5418 : it != itEnd;
5419 : ++it ) {
5420 0 : for( std::set<std::string>::const_iterator tagIt = it->getTestCaseInfo().tags.begin(),
5421 0 : tagItEnd = it->getTestCaseInfo().tags.end();
5422 : tagIt != tagItEnd;
5423 : ++tagIt ) {
5424 0 : std::string tagName = *tagIt;
5425 0 : std::string lcaseTagName = toLower( tagName );
5426 0 : std::map<std::string, TagInfo>::iterator countIt = tagCounts.find( lcaseTagName );
5427 0 : if( countIt == tagCounts.end() )
5428 0 : countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
5429 0 : countIt->second.add( tagName );
5430 0 : }
5431 : }
5432 :
5433 0 : for( std::map<std::string, TagInfo>::const_iterator countIt = tagCounts.begin(),
5434 0 : countItEnd = tagCounts.end();
5435 : countIt != countItEnd;
5436 : ++countIt ) {
5437 0 : std::ostringstream oss;
5438 0 : oss << " " << std::setw(2) << countIt->second.count << " ";
5439 0 : Text wrapper( countIt->second.all(), TextAttributes()
5440 0 : .setInitialIndent( 0 )
5441 0 : .setIndent( oss.str().size() )
5442 0 : .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );
5443 0 : Catch::cout() << oss.str() << wrapper << "\n";
5444 0 : }
5445 0 : Catch::cout() << pluralise( tagCounts.size(), "tag" ) << "\n" << std::endl;
5446 0 : return tagCounts.size();
5447 : }
5448 :
5449 0 : inline std::size_t listReporters( Config const& /*config*/ ) {
5450 0 : Catch::cout() << "Available reporters:\n";
5451 0 : IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
5452 0 : IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it;
5453 0 : std::size_t maxNameLen = 0;
5454 0 : for(it = itBegin; it != itEnd; ++it )
5455 0 : maxNameLen = (std::max)( maxNameLen, it->first.size() );
5456 :
5457 0 : for(it = itBegin; it != itEnd; ++it ) {
5458 0 : Text wrapper( it->second->getDescription(), TextAttributes()
5459 0 : .setInitialIndent( 0 )
5460 0 : .setIndent( 7+maxNameLen )
5461 0 : .setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) );
5462 0 : Catch::cout() << " "
5463 0 : << it->first
5464 0 : << ":"
5465 0 : << std::string( maxNameLen - it->first.size() + 2, ' ' )
5466 0 : << wrapper << "\n";
5467 0 : }
5468 0 : Catch::cout() << std::endl;
5469 0 : return factories.size();
5470 : }
5471 :
5472 1 : inline Option<std::size_t> list( Config const& config ) {
5473 1 : Option<std::size_t> listedCount;
5474 1 : if( config.listTests() )
5475 0 : listedCount = listedCount.valueOr(0) + listTests( config );
5476 1 : if( config.listTestNamesOnly() )
5477 0 : listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config );
5478 1 : if( config.listTags() )
5479 0 : listedCount = listedCount.valueOr(0) + listTags( config );
5480 1 : if( config.listReporters() )
5481 0 : listedCount = listedCount.valueOr(0) + listReporters( config );
5482 1 : return listedCount;
5483 : }
5484 :
5485 : } // end namespace Catch
5486 :
5487 : // #included from: internal/catch_run_context.hpp
5488 : #define TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED
5489 :
5490 : // #included from: catch_test_case_tracker.hpp
5491 : #define TWOBLUECUBES_CATCH_TEST_CASE_TRACKER_HPP_INCLUDED
5492 :
5493 : #include <map>
5494 : #include <string>
5495 : #include <assert.h>
5496 : #include <vector>
5497 :
5498 : namespace Catch {
5499 : namespace TestCaseTracking {
5500 :
5501 109 : struct ITracker : SharedImpl<> {
5502 : virtual ~ITracker();
5503 :
5504 : // static queries
5505 : virtual std::string name() const = 0;
5506 :
5507 : // dynamic queries
5508 : virtual bool isComplete() const = 0; // Successfully completed or failed
5509 : virtual bool isSuccessfullyCompleted() const = 0;
5510 : virtual bool isOpen() const = 0; // Started but not complete
5511 : virtual bool hasChildren() const = 0;
5512 :
5513 : virtual ITracker& parent() = 0;
5514 :
5515 : // actions
5516 : virtual void close() = 0; // Successfully complete
5517 : virtual void fail() = 0;
5518 : virtual void markAsNeedingAnotherRun() = 0;
5519 :
5520 : virtual void addChild( Ptr<ITracker> const& child ) = 0;
5521 : virtual ITracker* findChild( std::string const& name ) = 0;
5522 : virtual void openChild() = 0;
5523 :
5524 : // Debug/ checking
5525 : virtual bool isSectionTracker() const = 0;
5526 : virtual bool isIndexTracker() const = 0;
5527 : };
5528 :
5529 1 : class TrackerContext {
5530 :
5531 : enum RunState {
5532 : NotStarted,
5533 : Executing,
5534 : CompletedCycle
5535 : };
5536 :
5537 : Ptr<ITracker> m_rootTracker;
5538 : ITracker* m_currentTracker;
5539 : RunState m_runState;
5540 :
5541 : public:
5542 :
5543 : static TrackerContext& instance() {
5544 : static TrackerContext s_instance;
5545 : return s_instance;
5546 : }
5547 :
5548 1 : TrackerContext()
5549 : : m_currentTracker( CATCH_NULL ),
5550 1 : m_runState( NotStarted )
5551 1 : {}
5552 :
5553 : ITracker& startRun();
5554 :
5555 : void endRun() {
5556 : m_rootTracker.reset();
5557 : m_currentTracker = CATCH_NULL;
5558 : m_runState = NotStarted;
5559 : }
5560 :
5561 68 : void startCycle() {
5562 68 : m_currentTracker = m_rootTracker.get();
5563 68 : m_runState = Executing;
5564 68 : }
5565 115 : void completeCycle() {
5566 115 : m_runState = CompletedCycle;
5567 115 : }
5568 :
5569 317 : bool completedCycle() const {
5570 317 : return m_runState == CompletedCycle;
5571 : }
5572 432 : ITracker& currentTracker() {
5573 432 : return *m_currentTracker;
5574 : }
5575 230 : void setCurrentTracker( ITracker* tracker ) {
5576 230 : m_currentTracker = tracker;
5577 230 : }
5578 : };
5579 :
5580 : class TrackerBase : public ITracker {
5581 : protected:
5582 : enum CycleState {
5583 : NotStarted,
5584 : Executing,
5585 : ExecutingChildren,
5586 : NeedsAnotherRun,
5587 : CompletedSuccessfully,
5588 : Failed
5589 : };
5590 951 : class TrackerHasName {
5591 : std::string m_name;
5592 : public:
5593 317 : TrackerHasName( std::string const& name ) : m_name( name ) {}
5594 825 : bool operator ()( Ptr<ITracker> const& tracker ) {
5595 825 : return tracker->name() == m_name;
5596 : }
5597 : };
5598 : typedef std::vector<Ptr<ITracker> > Children;
5599 : std::string m_name;
5600 : TrackerContext& m_ctx;
5601 : ITracker* m_parent;
5602 : Children m_children;
5603 : CycleState m_runState;
5604 : public:
5605 109 : TrackerBase( std::string const& name, TrackerContext& ctx, ITracker* parent )
5606 : : m_name( name ),
5607 : m_ctx( ctx ),
5608 : m_parent( parent ),
5609 109 : m_runState( NotStarted )
5610 109 : {}
5611 : virtual ~TrackerBase();
5612 :
5613 825 : virtual std::string name() const CATCH_OVERRIDE {
5614 825 : return m_name;
5615 : }
5616 411 : virtual bool isComplete() const CATCH_OVERRIDE {
5617 411 : return m_runState == CompletedSuccessfully || m_runState == Failed;
5618 : }
5619 68 : virtual bool isSuccessfullyCompleted() const CATCH_OVERRIDE {
5620 68 : return m_runState == CompletedSuccessfully;
5621 : }
5622 249 : virtual bool isOpen() const CATCH_OVERRIDE {
5623 249 : return m_runState != NotStarted && !isComplete();
5624 : }
5625 0 : virtual bool hasChildren() const CATCH_OVERRIDE {
5626 0 : return !m_children.empty();
5627 : }
5628 :
5629 78 : virtual void addChild( Ptr<ITracker> const& child ) CATCH_OVERRIDE {
5630 78 : m_children.push_back( child );
5631 78 : }
5632 :
5633 317 : virtual ITracker* findChild( std::string const& name ) CATCH_OVERRIDE {
5634 317 : Children::const_iterator it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( name ) );
5635 634 : return( it != m_children.end() )
5636 239 : ? it->get()
5637 873 : : CATCH_NULL;
5638 : }
5639 0 : virtual ITracker& parent() CATCH_OVERRIDE {
5640 0 : assert( m_parent ); // Should always be non-null except for root
5641 0 : return *m_parent;
5642 : }
5643 :
5644 162 : virtual void openChild() CATCH_OVERRIDE {
5645 162 : if( m_runState != ExecutingChildren ) {
5646 78 : m_runState = ExecutingChildren;
5647 78 : if( m_parent )
5648 47 : m_parent->openChild();
5649 : }
5650 162 : }
5651 :
5652 0 : virtual bool isSectionTracker() const CATCH_OVERRIDE { return false; }
5653 0 : virtual bool isIndexTracker() const CATCH_OVERRIDE { return false; }
5654 :
5655 115 : void open() {
5656 115 : m_runState = Executing;
5657 115 : moveToThis();
5658 115 : if( m_parent )
5659 115 : m_parent->openChild();
5660 115 : }
5661 :
5662 115 : virtual void close() CATCH_OVERRIDE {
5663 :
5664 : // Close any still open children (e.g. generators)
5665 230 : while( &m_ctx.currentTracker() != this )
5666 0 : m_ctx.currentTracker().close();
5667 :
5668 115 : switch( m_runState ) {
5669 : case NotStarted:
5670 : case CompletedSuccessfully:
5671 : case Failed:
5672 0 : throw std::logic_error( "Illogical state" );
5673 :
5674 : case NeedsAnotherRun:
5675 0 : break;;
5676 :
5677 : case Executing:
5678 68 : m_runState = CompletedSuccessfully;
5679 68 : break;
5680 : case ExecutingChildren:
5681 47 : if( m_children.empty() || m_children.back()->isComplete() )
5682 10 : m_runState = CompletedSuccessfully;
5683 47 : break;
5684 :
5685 : default:
5686 0 : throw std::logic_error( "Unexpected state" );
5687 : }
5688 115 : moveToParent();
5689 115 : m_ctx.completeCycle();
5690 115 : }
5691 0 : virtual void fail() CATCH_OVERRIDE {
5692 0 : m_runState = Failed;
5693 0 : if( m_parent )
5694 0 : m_parent->markAsNeedingAnotherRun();
5695 0 : moveToParent();
5696 0 : m_ctx.completeCycle();
5697 0 : }
5698 0 : virtual void markAsNeedingAnotherRun() CATCH_OVERRIDE {
5699 0 : m_runState = NeedsAnotherRun;
5700 0 : }
5701 : private:
5702 115 : void moveToParent() {
5703 115 : assert( m_parent );
5704 115 : m_ctx.setCurrentTracker( m_parent );
5705 115 : }
5706 115 : void moveToThis() {
5707 115 : m_ctx.setCurrentTracker( this );
5708 115 : }
5709 : };
5710 :
5711 : class SectionTracker : public TrackerBase {
5712 : public:
5713 109 : SectionTracker( std::string const& name, TrackerContext& ctx, ITracker* parent )
5714 109 : : TrackerBase( name, ctx, parent )
5715 109 : {}
5716 : virtual ~SectionTracker();
5717 :
5718 239 : virtual bool isSectionTracker() const CATCH_OVERRIDE { return true; }
5719 :
5720 317 : static SectionTracker& acquire( TrackerContext& ctx, std::string const& name ) {
5721 317 : SectionTracker* section = CATCH_NULL;
5722 :
5723 317 : ITracker& currentTracker = ctx.currentTracker();
5724 317 : if( ITracker* childTracker = currentTracker.findChild( name ) ) {
5725 239 : assert( childTracker );
5726 239 : assert( childTracker->isSectionTracker() );
5727 239 : section = static_cast<SectionTracker*>( childTracker );
5728 : }
5729 : else {
5730 78 : section = new SectionTracker( name, ctx, ¤tTracker );
5731 78 : currentTracker.addChild( section );
5732 : }
5733 317 : if( !ctx.completedCycle() && !section->isComplete() ) {
5734 :
5735 115 : section->open();
5736 : }
5737 317 : return *section;
5738 : }
5739 : };
5740 :
5741 : class IndexTracker : public TrackerBase {
5742 : int m_size;
5743 : int m_index;
5744 : public:
5745 : IndexTracker( std::string const& name, TrackerContext& ctx, ITracker* parent, int size )
5746 : : TrackerBase( name, ctx, parent ),
5747 : m_size( size ),
5748 : m_index( -1 )
5749 : {}
5750 : virtual ~IndexTracker();
5751 :
5752 0 : virtual bool isIndexTracker() const CATCH_OVERRIDE { return true; }
5753 :
5754 : static IndexTracker& acquire( TrackerContext& ctx, std::string const& name, int size ) {
5755 : IndexTracker* tracker = CATCH_NULL;
5756 :
5757 : ITracker& currentTracker = ctx.currentTracker();
5758 : if( ITracker* childTracker = currentTracker.findChild( name ) ) {
5759 : assert( childTracker );
5760 : assert( childTracker->isIndexTracker() );
5761 : tracker = static_cast<IndexTracker*>( childTracker );
5762 : }
5763 : else {
5764 : tracker = new IndexTracker( name, ctx, ¤tTracker, size );
5765 : currentTracker.addChild( tracker );
5766 : }
5767 :
5768 : if( !ctx.completedCycle() && !tracker->isComplete() ) {
5769 : if( tracker->m_runState != ExecutingChildren && tracker->m_runState != NeedsAnotherRun )
5770 : tracker->moveNext();
5771 : tracker->open();
5772 : }
5773 :
5774 : return *tracker;
5775 : }
5776 :
5777 : int index() const { return m_index; }
5778 :
5779 : void moveNext() {
5780 : m_index++;
5781 : m_children.clear();
5782 : }
5783 :
5784 0 : virtual void close() CATCH_OVERRIDE {
5785 0 : TrackerBase::close();
5786 0 : if( m_runState == CompletedSuccessfully && m_index < m_size-1 )
5787 0 : m_runState = Executing;
5788 0 : }
5789 : };
5790 :
5791 31 : inline ITracker& TrackerContext::startRun() {
5792 31 : m_rootTracker = new SectionTracker( "{root}", *this, CATCH_NULL );
5793 31 : m_currentTracker = CATCH_NULL;
5794 31 : m_runState = Executing;
5795 31 : return *m_rootTracker;
5796 : }
5797 :
5798 : } // namespace TestCaseTracking
5799 :
5800 : using TestCaseTracking::ITracker;
5801 : using TestCaseTracking::TrackerContext;
5802 : using TestCaseTracking::SectionTracker;
5803 : using TestCaseTracking::IndexTracker;
5804 :
5805 : } // namespace Catch
5806 :
5807 : // #included from: catch_fatal_condition.hpp
5808 : #define TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
5809 :
5810 : namespace Catch {
5811 :
5812 : // Report the error condition then exit the process
5813 0 : inline void fatal( std::string const& message, int exitCode ) {
5814 0 : IContext& context = Catch::getCurrentContext();
5815 0 : IResultCapture* resultCapture = context.getResultCapture();
5816 0 : resultCapture->handleFatalErrorCondition( message );
5817 :
5818 0 : if( Catch::alwaysTrue() ) // avoids "no return" warnings
5819 0 : exit( exitCode );
5820 0 : }
5821 :
5822 : } // namespace Catch
5823 :
5824 : #if defined ( CATCH_PLATFORM_WINDOWS ) /////////////////////////////////////////
5825 :
5826 : namespace Catch {
5827 :
5828 : struct FatalConditionHandler {
5829 : void reset() {}
5830 : };
5831 :
5832 : } // namespace Catch
5833 :
5834 : #else // Not Windows - assumed to be POSIX compatible //////////////////////////
5835 :
5836 : #include <signal.h>
5837 :
5838 : namespace Catch {
5839 :
5840 : struct SignalDefs { int id; const char* name; };
5841 : extern SignalDefs signalDefs[];
5842 : SignalDefs signalDefs[] = {
5843 : { SIGINT, "SIGINT - Terminal interrupt signal" },
5844 : { SIGILL, "SIGILL - Illegal instruction signal" },
5845 : { SIGFPE, "SIGFPE - Floating point error signal" },
5846 : { SIGSEGV, "SIGSEGV - Segmentation violation signal" },
5847 : { SIGTERM, "SIGTERM - Termination request signal" },
5848 : { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" }
5849 : };
5850 :
5851 : struct FatalConditionHandler {
5852 :
5853 0 : static void handleSignal( int sig ) {
5854 0 : for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i )
5855 0 : if( sig == signalDefs[i].id )
5856 0 : fatal( signalDefs[i].name, -sig );
5857 0 : fatal( "<unknown signal>", -sig );
5858 0 : }
5859 :
5860 68 : FatalConditionHandler() : m_isSet( true ) {
5861 476 : for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i )
5862 408 : signal( signalDefs[i].id, handleSignal );
5863 68 : }
5864 68 : ~FatalConditionHandler() {
5865 68 : reset();
5866 68 : }
5867 136 : void reset() {
5868 136 : if( m_isSet ) {
5869 476 : for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i )
5870 408 : signal( signalDefs[i].id, SIG_DFL );
5871 68 : m_isSet = false;
5872 : }
5873 136 : }
5874 :
5875 : bool m_isSet;
5876 : };
5877 :
5878 : } // namespace Catch
5879 :
5880 : #endif // not Windows
5881 :
5882 : #include <set>
5883 : #include <string>
5884 :
5885 : namespace Catch {
5886 :
5887 : class StreamRedirect {
5888 :
5889 : public:
5890 0 : StreamRedirect( std::ostream& stream, std::string& targetString )
5891 : : m_stream( stream ),
5892 0 : m_prevBuf( stream.rdbuf() ),
5893 0 : m_targetString( targetString )
5894 : {
5895 0 : stream.rdbuf( m_oss.rdbuf() );
5896 0 : }
5897 :
5898 0 : ~StreamRedirect() {
5899 0 : m_targetString += m_oss.str();
5900 0 : m_stream.rdbuf( m_prevBuf );
5901 0 : }
5902 :
5903 : private:
5904 : std::ostream& m_stream;
5905 : std::streambuf* m_prevBuf;
5906 : std::ostringstream m_oss;
5907 : std::string& m_targetString;
5908 : };
5909 :
5910 : ///////////////////////////////////////////////////////////////////////////
5911 :
5912 : class RunContext : public IResultCapture, public IRunner {
5913 :
5914 : RunContext( RunContext const& );
5915 : void operator =( RunContext const& );
5916 :
5917 : public:
5918 :
5919 1 : explicit RunContext( Ptr<IConfig const> const& _config, Ptr<IStreamingReporter> const& reporter )
5920 1 : : m_runInfo( _config->name() ),
5921 1 : m_context( getCurrentMutableContext() ),
5922 : m_activeTestCase( CATCH_NULL ),
5923 : m_config( _config ),
5924 3 : m_reporter( reporter )
5925 : {
5926 1 : m_context.setRunner( this );
5927 1 : m_context.setConfig( m_config );
5928 1 : m_context.setResultCapture( this );
5929 1 : m_reporter->testRunStarting( m_runInfo );
5930 1 : }
5931 :
5932 2 : virtual ~RunContext() {
5933 1 : m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) );
5934 1 : }
5935 :
5936 1 : void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) {
5937 1 : m_reporter->testGroupStarting( GroupInfo( testSpec, groupIndex, groupsCount ) );
5938 1 : }
5939 1 : void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ) {
5940 1 : m_reporter->testGroupEnded( TestGroupStats( GroupInfo( testSpec, groupIndex, groupsCount ), totals, aborting() ) );
5941 1 : }
5942 :
5943 31 : Totals runTest( TestCase const& testCase ) {
5944 31 : Totals prevTotals = m_totals;
5945 :
5946 31 : std::string redirectedCout;
5947 62 : std::string redirectedCerr;
5948 :
5949 62 : TestCaseInfo testInfo = testCase.getTestCaseInfo();
5950 :
5951 31 : m_reporter->testCaseStarting( testInfo );
5952 :
5953 31 : m_activeTestCase = &testCase;
5954 :
5955 31 : do {
5956 31 : m_trackerContext.startRun();
5957 68 : do {
5958 68 : m_trackerContext.startCycle();
5959 68 : m_testCaseTracker = &SectionTracker::acquire( m_trackerContext, testInfo.name );
5960 68 : runCurrentTest( redirectedCout, redirectedCerr );
5961 : }
5962 68 : while( !m_testCaseTracker->isSuccessfullyCompleted() && !aborting() );
5963 : }
5964 : // !TBD: deprecated - this will be replaced by indexed trackers
5965 31 : while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() );
5966 :
5967 31 : Totals deltaTotals = m_totals.delta( prevTotals );
5968 31 : if( testInfo.expectedToFail() && deltaTotals.testCases.passed > 0 ) {
5969 0 : deltaTotals.assertions.failed++;
5970 0 : deltaTotals.testCases.passed--;
5971 0 : deltaTotals.testCases.failed++;
5972 : }
5973 31 : m_totals.testCases += deltaTotals.testCases;
5974 31 : m_reporter->testCaseEnded( TestCaseStats( testInfo,
5975 : deltaTotals,
5976 : redirectedCout,
5977 : redirectedCerr,
5978 31 : aborting() ) );
5979 :
5980 31 : m_activeTestCase = CATCH_NULL;
5981 31 : m_testCaseTracker = CATCH_NULL;
5982 :
5983 62 : return deltaTotals;
5984 : }
5985 :
5986 : Ptr<IConfig const> config() const {
5987 : return m_config;
5988 : }
5989 :
5990 : private: // IResultCapture
5991 :
5992 2571 : virtual void assertionEnded( AssertionResult const& result ) {
5993 2571 : if( result.getResultType() == ResultWas::Ok ) {
5994 2571 : m_totals.assertions.passed++;
5995 : }
5996 0 : else if( !result.isOk() ) {
5997 0 : m_totals.assertions.failed++;
5998 : }
5999 :
6000 2571 : if( m_reporter->assertionEnded( AssertionStats( result, m_messages, m_totals ) ) )
6001 0 : m_messages.clear();
6002 :
6003 : // Reset working state
6004 2571 : m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition );
6005 2571 : m_lastResult = result;
6006 2571 : }
6007 :
6008 249 : virtual bool sectionStarted (
6009 : SectionInfo const& sectionInfo,
6010 : Counts& assertions
6011 : )
6012 : {
6013 249 : std::ostringstream oss;
6014 249 : oss << sectionInfo.name << "@" << sectionInfo.lineInfo;
6015 :
6016 249 : ITracker& sectionTracker = SectionTracker::acquire( m_trackerContext, oss.str() );
6017 249 : if( !sectionTracker.isOpen() )
6018 202 : return false;
6019 47 : m_activeSections.push_back( §ionTracker );
6020 :
6021 47 : m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
6022 :
6023 47 : m_reporter->sectionStarting( sectionInfo );
6024 :
6025 47 : assertions = m_totals.assertions;
6026 :
6027 47 : return true;
6028 : }
6029 115 : bool testForMissingAssertions( Counts& assertions ) {
6030 115 : if( assertions.total() != 0 )
6031 115 : return false;
6032 0 : if( !m_config->warnAboutMissingAssertions() )
6033 0 : return false;
6034 0 : if( m_trackerContext.currentTracker().hasChildren() )
6035 0 : return false;
6036 0 : m_totals.assertions.failed++;
6037 0 : assertions.failed++;
6038 0 : return true;
6039 : }
6040 :
6041 47 : virtual void sectionEnded( SectionEndInfo const& endInfo ) {
6042 47 : Counts assertions = m_totals.assertions - endInfo.prevAssertions;
6043 47 : bool missingAssertions = testForMissingAssertions( assertions );
6044 :
6045 47 : if( !m_activeSections.empty() ) {
6046 47 : m_activeSections.back()->close();
6047 47 : m_activeSections.pop_back();
6048 : }
6049 :
6050 47 : m_reporter->sectionEnded( SectionStats( endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions ) );
6051 47 : m_messages.clear();
6052 47 : }
6053 :
6054 0 : virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) {
6055 0 : if( m_unfinishedSections.empty() )
6056 0 : m_activeSections.back()->fail();
6057 : else
6058 0 : m_activeSections.back()->close();
6059 0 : m_activeSections.pop_back();
6060 :
6061 0 : m_unfinishedSections.push_back( endInfo );
6062 0 : }
6063 :
6064 0 : virtual void pushScopedMessage( MessageInfo const& message ) {
6065 0 : m_messages.push_back( message );
6066 0 : }
6067 :
6068 0 : virtual void popScopedMessage( MessageInfo const& message ) {
6069 0 : m_messages.erase( std::remove( m_messages.begin(), m_messages.end(), message ), m_messages.end() );
6070 0 : }
6071 :
6072 31 : virtual std::string getCurrentTestName() const {
6073 : return m_activeTestCase
6074 31 : ? m_activeTestCase->getTestCaseInfo().name
6075 62 : : "";
6076 : }
6077 :
6078 0 : virtual const AssertionResult* getLastResult() const {
6079 0 : return &m_lastResult;
6080 : }
6081 :
6082 0 : virtual void handleFatalErrorCondition( std::string const& message ) {
6083 0 : ResultBuilder resultBuilder = makeUnexpectedResultBuilder();
6084 0 : resultBuilder.setResultType( ResultWas::FatalErrorCondition );
6085 0 : resultBuilder << message;
6086 0 : resultBuilder.captureExpression();
6087 :
6088 0 : handleUnfinishedSections();
6089 :
6090 : // Recreate section for test case (as we will lose the one that was in scope)
6091 0 : TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
6092 0 : SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description );
6093 :
6094 0 : Counts assertions;
6095 0 : assertions.failed = 1;
6096 0 : SectionStats testCaseSectionStats( testCaseSection, assertions, 0, false );
6097 0 : m_reporter->sectionEnded( testCaseSectionStats );
6098 :
6099 0 : TestCaseInfo testInfo = m_activeTestCase->getTestCaseInfo();
6100 :
6101 0 : Totals deltaTotals;
6102 0 : deltaTotals.testCases.failed = 1;
6103 0 : m_reporter->testCaseEnded( TestCaseStats( testInfo,
6104 : deltaTotals,
6105 : "",
6106 : "",
6107 0 : false ) );
6108 0 : m_totals.testCases.failed++;
6109 0 : testGroupEnded( "", m_totals, 1, 1 );
6110 0 : m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, false ) );
6111 0 : }
6112 :
6113 : public:
6114 : // !TBD We need to do this another way!
6115 101 : bool aborting() const {
6116 101 : return m_totals.assertions.failed == static_cast<std::size_t>( m_config->abortAfter() );
6117 : }
6118 :
6119 : private:
6120 :
6121 68 : void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
6122 68 : TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo();
6123 68 : SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description );
6124 68 : m_reporter->sectionStarting( testCaseSection );
6125 68 : Counts prevAssertions = m_totals.assertions;
6126 68 : double duration = 0;
6127 : try {
6128 68 : m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal );
6129 :
6130 68 : seedRng( *m_config );
6131 :
6132 68 : Timer timer;
6133 68 : timer.start();
6134 68 : if( m_reporter->getPreferences().shouldRedirectStdOut ) {
6135 0 : StreamRedirect coutRedir( Catch::cout(), redirectedCout );
6136 0 : StreamRedirect cerrRedir( Catch::cerr(), redirectedCerr );
6137 0 : invokeActiveTestCase();
6138 : }
6139 : else {
6140 68 : invokeActiveTestCase();
6141 : }
6142 68 : duration = timer.getElapsedSeconds();
6143 : }
6144 : catch( TestFailureException& ) {
6145 : // This just means the test was aborted due to failure
6146 : }
6147 : catch(...) {
6148 : makeUnexpectedResultBuilder().useActiveException();
6149 : }
6150 68 : m_testCaseTracker->close();
6151 68 : handleUnfinishedSections();
6152 68 : m_messages.clear();
6153 :
6154 68 : Counts assertions = m_totals.assertions - prevAssertions;
6155 68 : bool missingAssertions = testForMissingAssertions( assertions );
6156 :
6157 68 : if( testCaseInfo.okToFail() ) {
6158 0 : std::swap( assertions.failedButOk, assertions.failed );
6159 0 : m_totals.assertions.failed -= assertions.failedButOk;
6160 0 : m_totals.assertions.failedButOk += assertions.failedButOk;
6161 : }
6162 :
6163 136 : SectionStats testCaseSectionStats( testCaseSection, assertions, duration, missingAssertions );
6164 136 : m_reporter->sectionEnded( testCaseSectionStats );
6165 68 : }
6166 :
6167 68 : void invokeActiveTestCase() {
6168 68 : FatalConditionHandler fatalConditionHandler; // Handle signals
6169 68 : m_activeTestCase->invoke();
6170 68 : fatalConditionHandler.reset();
6171 68 : }
6172 :
6173 : private:
6174 :
6175 0 : ResultBuilder makeUnexpectedResultBuilder() const {
6176 : return ResultBuilder( m_lastAssertionInfo.macroName.c_str(),
6177 : m_lastAssertionInfo.lineInfo,
6178 : m_lastAssertionInfo.capturedExpression.c_str(),
6179 0 : m_lastAssertionInfo.resultDisposition );
6180 : }
6181 :
6182 68 : void handleUnfinishedSections() {
6183 : // If sections ended prematurely due to an exception we stored their
6184 : // infos here so we can tear them down outside the unwind process.
6185 136 : for( std::vector<SectionEndInfo>::const_reverse_iterator it = m_unfinishedSections.rbegin(),
6186 68 : itEnd = m_unfinishedSections.rend();
6187 : it != itEnd;
6188 : ++it )
6189 0 : sectionEnded( *it );
6190 68 : m_unfinishedSections.clear();
6191 68 : }
6192 :
6193 : TestRunInfo m_runInfo;
6194 : IMutableContext& m_context;
6195 : TestCase const* m_activeTestCase;
6196 : ITracker* m_testCaseTracker;
6197 : ITracker* m_currentSectionTracker;
6198 : AssertionResult m_lastResult;
6199 :
6200 : Ptr<IConfig const> m_config;
6201 : Totals m_totals;
6202 : Ptr<IStreamingReporter> m_reporter;
6203 : std::vector<MessageInfo> m_messages;
6204 : AssertionInfo m_lastAssertionInfo;
6205 : std::vector<SectionEndInfo> m_unfinishedSections;
6206 : std::vector<ITracker*> m_activeSections;
6207 : TrackerContext m_trackerContext;
6208 : };
6209 :
6210 2867 : IResultCapture& getResultCapture() {
6211 2867 : if( IResultCapture* capture = getCurrentContext().getResultCapture() )
6212 5734 : return *capture;
6213 : else
6214 0 : throw std::logic_error( "No result capture instance" );
6215 : }
6216 :
6217 : } // end namespace Catch
6218 :
6219 : // #included from: internal/catch_version.h
6220 : #define TWOBLUECUBES_CATCH_VERSION_H_INCLUDED
6221 :
6222 : namespace Catch {
6223 :
6224 : // Versioning information
6225 0 : struct Version {
6226 : Version( unsigned int _majorVersion,
6227 : unsigned int _minorVersion,
6228 : unsigned int _patchNumber,
6229 : std::string const& _branchName,
6230 : unsigned int _buildNumber );
6231 :
6232 : unsigned int const majorVersion;
6233 : unsigned int const minorVersion;
6234 : unsigned int const patchNumber;
6235 :
6236 : // buildNumber is only used if branchName is not null
6237 : std::string const branchName;
6238 : unsigned int const buildNumber;
6239 :
6240 : friend std::ostream& operator << ( std::ostream& os, Version const& version );
6241 :
6242 : private:
6243 : void operator=( Version const& );
6244 : };
6245 :
6246 : extern Version libraryVersion;
6247 : }
6248 :
6249 : #include <fstream>
6250 : #include <stdlib.h>
6251 : #include <limits>
6252 :
6253 : namespace Catch {
6254 :
6255 1 : Ptr<IStreamingReporter> createReporter( std::string const& reporterName, Ptr<Config> const& config ) {
6256 1 : Ptr<IStreamingReporter> reporter = getRegistryHub().getReporterRegistry().create( reporterName, config.get() );
6257 1 : if( !reporter ) {
6258 0 : std::ostringstream oss;
6259 0 : oss << "No reporter registered with name: '" << reporterName << "'";
6260 0 : throw std::domain_error( oss.str() );
6261 : }
6262 1 : return reporter;
6263 : }
6264 :
6265 1 : Ptr<IStreamingReporter> makeReporter( Ptr<Config> const& config ) {
6266 1 : std::vector<std::string> reporters = config->getReporterNames();
6267 1 : if( reporters.empty() )
6268 1 : reporters.push_back( "console" );
6269 :
6270 1 : Ptr<IStreamingReporter> reporter;
6271 2 : for( std::vector<std::string>::const_iterator it = reporters.begin(), itEnd = reporters.end();
6272 : it != itEnd;
6273 : ++it )
6274 1 : reporter = addReporter( reporter, createReporter( *it, config ) );
6275 1 : return reporter;
6276 : }
6277 1 : Ptr<IStreamingReporter> addListeners( Ptr<IConfig const> const& config, Ptr<IStreamingReporter> reporters ) {
6278 1 : IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners();
6279 1 : for( IReporterRegistry::Listeners::const_iterator it = listeners.begin(), itEnd = listeners.end();
6280 : it != itEnd;
6281 : ++it )
6282 0 : reporters = addReporter(reporters, (*it)->create( ReporterConfig( config ) ) );
6283 1 : return reporters;
6284 : }
6285 :
6286 1 : Totals runTests( Ptr<Config> const& config ) {
6287 :
6288 1 : Ptr<IConfig const> iconfig = config.get();
6289 :
6290 2 : Ptr<IStreamingReporter> reporter = makeReporter( config );
6291 1 : reporter = addListeners( iconfig, reporter );
6292 :
6293 2 : RunContext context( iconfig, reporter );
6294 :
6295 1 : Totals totals;
6296 :
6297 1 : context.testGroupStarting( config->name(), 1, 1 );
6298 :
6299 2 : TestSpec testSpec = config->testSpec();
6300 1 : if( !testSpec.hasFilters() )
6301 1 : testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests
6302 :
6303 1 : std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *iconfig );
6304 32 : for( std::vector<TestCase>::const_iterator it = allTestCases.begin(), itEnd = allTestCases.end();
6305 : it != itEnd;
6306 : ++it ) {
6307 31 : if( !context.aborting() && matchTest( *it, testSpec, *iconfig ) )
6308 31 : totals += context.runTest( *it );
6309 : else
6310 0 : reporter->skipTest( *it );
6311 : }
6312 :
6313 1 : context.testGroupEnded( iconfig->name(), totals, 1, 1 );
6314 2 : return totals;
6315 : }
6316 :
6317 0 : void applyFilenamesAsTags( IConfig const& config ) {
6318 0 : std::vector<TestCase> const& tests = getAllTestCasesSorted( config );
6319 0 : for(std::size_t i = 0; i < tests.size(); ++i ) {
6320 0 : TestCase& test = const_cast<TestCase&>( tests[i] );
6321 0 : std::set<std::string> tags = test.tags;
6322 :
6323 0 : std::string filename = test.lineInfo.file;
6324 0 : std::string::size_type lastSlash = filename.find_last_of( "\\/" );
6325 0 : if( lastSlash != std::string::npos )
6326 0 : filename = filename.substr( lastSlash+1 );
6327 :
6328 0 : std::string::size_type lastDot = filename.find_last_of( "." );
6329 0 : if( lastDot != std::string::npos )
6330 0 : filename = filename.substr( 0, lastDot );
6331 :
6332 0 : tags.insert( "#" + filename );
6333 0 : setTags( test, tags );
6334 0 : }
6335 0 : }
6336 :
6337 : class Session : NonCopyable {
6338 : static bool alreadyInstantiated;
6339 :
6340 : public:
6341 :
6342 : struct OnUnusedOptions { enum DoWhat { Ignore, Fail }; };
6343 :
6344 1 : Session()
6345 1 : : m_cli( makeCommandLineParser() ) {
6346 1 : if( alreadyInstantiated ) {
6347 0 : std::string msg = "Only one instance of Catch::Session can ever be used";
6348 0 : Catch::cerr() << msg << std::endl;
6349 0 : throw std::logic_error( msg );
6350 : }
6351 1 : alreadyInstantiated = true;
6352 1 : }
6353 2 : ~Session() {
6354 1 : Catch::cleanUp();
6355 1 : }
6356 :
6357 0 : void showHelp( std::string const& processName ) {
6358 0 : Catch::cout() << "\nCatch v" << libraryVersion << "\n";
6359 :
6360 0 : m_cli.usage( Catch::cout(), processName );
6361 0 : Catch::cout() << "For more detail usage please see the project docs\n" << std::endl;
6362 0 : }
6363 :
6364 1 : int applyCommandLine( int argc, char const* const* const argv, OnUnusedOptions::DoWhat unusedOptionBehaviour = OnUnusedOptions::Fail ) {
6365 : try {
6366 1 : m_cli.setThrowOnUnrecognisedTokens( unusedOptionBehaviour == OnUnusedOptions::Fail );
6367 1 : m_unusedTokens = m_cli.parseInto( Clara::argsToVector( argc, argv ), m_configData );
6368 1 : if( m_configData.showHelp )
6369 0 : showHelp( m_configData.processName );
6370 1 : m_config.reset();
6371 : }
6372 : catch( std::exception& ex ) {
6373 : {
6374 : Colour colourGuard( Colour::Red );
6375 : Catch::cerr()
6376 : << "\nError(s) in input:\n"
6377 : << Text( ex.what(), TextAttributes().setIndent(2) )
6378 : << "\n\n";
6379 : }
6380 : m_cli.usage( Catch::cout(), m_configData.processName );
6381 : return (std::numeric_limits<int>::max)();
6382 : }
6383 1 : return 0;
6384 : }
6385 :
6386 : void useConfigData( ConfigData const& _configData ) {
6387 : m_configData = _configData;
6388 : m_config.reset();
6389 : }
6390 :
6391 1 : int run( int argc, char const* const* const argv ) {
6392 :
6393 1 : int returnCode = applyCommandLine( argc, argv );
6394 1 : if( returnCode == 0 )
6395 1 : returnCode = run();
6396 1 : return returnCode;
6397 : }
6398 :
6399 1 : int run() {
6400 1 : if( m_configData.showHelp )
6401 0 : return 0;
6402 :
6403 : try
6404 : {
6405 1 : config(); // Force config to be constructed
6406 :
6407 1 : seedRng( *m_config );
6408 :
6409 1 : if( m_configData.filenamesAsTags )
6410 0 : applyFilenamesAsTags( *m_config );
6411 :
6412 : // Handle list request
6413 1 : if( Option<std::size_t> listed = list( config() ) )
6414 0 : return static_cast<int>( *listed );
6415 :
6416 1 : return static_cast<int>( runTests( m_config ).assertions.failed );
6417 : }
6418 : catch( std::exception& ex ) {
6419 : Catch::cerr() << ex.what() << std::endl;
6420 : return (std::numeric_limits<int>::max)();
6421 : }
6422 : }
6423 :
6424 : Clara::CommandLine<ConfigData> const& cli() const {
6425 : return m_cli;
6426 : }
6427 : std::vector<Clara::Parser::Token> const& unusedTokens() const {
6428 : return m_unusedTokens;
6429 : }
6430 : ConfigData& configData() {
6431 : return m_configData;
6432 : }
6433 2 : Config& config() {
6434 2 : if( !m_config )
6435 1 : m_config = new Config( m_configData );
6436 2 : return *m_config;
6437 : }
6438 : private:
6439 : Clara::CommandLine<ConfigData> m_cli;
6440 : std::vector<Clara::Parser::Token> m_unusedTokens;
6441 : ConfigData m_configData;
6442 : Ptr<Config> m_config;
6443 : };
6444 :
6445 : bool Session::alreadyInstantiated = false;
6446 :
6447 : } // end namespace Catch
6448 :
6449 : // #included from: catch_registry_hub.hpp
6450 : #define TWOBLUECUBES_CATCH_REGISTRY_HUB_HPP_INCLUDED
6451 :
6452 : // #included from: catch_test_case_registry_impl.hpp
6453 : #define TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED
6454 :
6455 : #include <vector>
6456 : #include <set>
6457 : #include <sstream>
6458 : #include <iostream>
6459 : #include <algorithm>
6460 :
6461 : #ifdef CATCH_CPP14_OR_GREATER
6462 : #include <random>
6463 : #endif
6464 :
6465 : namespace Catch {
6466 :
6467 : struct RandomNumberGenerator {
6468 : typedef std::ptrdiff_t result_type;
6469 :
6470 0 : result_type operator()( result_type n ) const { return std::rand() % n; }
6471 :
6472 : #ifdef CATCH_CPP14_OR_GREATER
6473 : static constexpr result_type min() { return 0; }
6474 : static constexpr result_type max() { return 1000000; }
6475 : result_type operator()() const { return std::rand() % max(); }
6476 : #endif
6477 : template<typename V>
6478 0 : static void shuffle( V& vector ) {
6479 : RandomNumberGenerator rng;
6480 : #ifdef CATCH_CPP14_OR_GREATER
6481 : std::shuffle( vector.begin(), vector.end(), rng );
6482 : #else
6483 0 : std::random_shuffle( vector.begin(), vector.end(), rng );
6484 : #endif
6485 0 : }
6486 : };
6487 :
6488 1 : inline std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) {
6489 :
6490 1 : std::vector<TestCase> sorted = unsortedTestCases;
6491 :
6492 1 : switch( config.runOrder() ) {
6493 : case RunTests::InLexicographicalOrder:
6494 0 : std::sort( sorted.begin(), sorted.end() );
6495 0 : break;
6496 : case RunTests::InRandomOrder:
6497 : {
6498 0 : seedRng( config );
6499 0 : RandomNumberGenerator::shuffle( sorted );
6500 : }
6501 0 : break;
6502 : case RunTests::InDeclarationOrder:
6503 : // already in declaration order
6504 1 : break;
6505 : }
6506 1 : return sorted;
6507 : }
6508 31 : bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) {
6509 31 : return testSpec.matches( testCase ) && ( config.allowThrows() || !testCase.throws() );
6510 : }
6511 :
6512 1 : void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) {
6513 1 : std::set<TestCase> seenFunctions;
6514 32 : for( std::vector<TestCase>::const_iterator it = functions.begin(), itEnd = functions.end();
6515 : it != itEnd;
6516 : ++it ) {
6517 31 : std::pair<std::set<TestCase>::const_iterator, bool> prev = seenFunctions.insert( *it );
6518 31 : if( !prev.second ) {
6519 0 : std::ostringstream ss;
6520 :
6521 0 : ss << Colour( Colour::Red )
6522 0 : << "error: TEST_CASE( \"" << it->name << "\" ) already defined.\n"
6523 0 : << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n"
6524 0 : << "\tRedefined at " << it->getTestCaseInfo().lineInfo << std::endl;
6525 :
6526 0 : throw std::runtime_error(ss.str());
6527 : }
6528 1 : }
6529 1 : }
6530 :
6531 0 : std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ) {
6532 0 : std::vector<TestCase> filtered;
6533 0 : filtered.reserve( testCases.size() );
6534 0 : for( std::vector<TestCase>::const_iterator it = testCases.begin(), itEnd = testCases.end();
6535 : it != itEnd;
6536 : ++it )
6537 0 : if( matchTest( *it, testSpec, config ) )
6538 0 : filtered.push_back( *it );
6539 0 : return filtered;
6540 : }
6541 1 : std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ) {
6542 1 : return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config );
6543 : }
6544 :
6545 : class TestRegistry : public ITestCaseRegistry {
6546 : public:
6547 1 : TestRegistry()
6548 : : m_currentSortOrder( RunTests::InDeclarationOrder ),
6549 1 : m_unnamedCount( 0 )
6550 1 : {}
6551 : virtual ~TestRegistry();
6552 :
6553 31 : virtual void registerTest( TestCase const& testCase ) {
6554 31 : std::string name = testCase.getTestCaseInfo().name;
6555 31 : if( name == "" ) {
6556 0 : std::ostringstream oss;
6557 0 : oss << "Anonymous test case " << ++m_unnamedCount;
6558 31 : return registerTest( testCase.withName( oss.str() ) );
6559 : }
6560 31 : m_functions.push_back( testCase );
6561 : }
6562 :
6563 0 : virtual std::vector<TestCase> const& getAllTests() const {
6564 0 : return m_functions;
6565 : }
6566 1 : virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const {
6567 1 : if( m_sortedFunctions.empty() )
6568 1 : enforceNoDuplicateTestCases( m_functions );
6569 :
6570 1 : if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) {
6571 1 : m_sortedFunctions = sortTests( config, m_functions );
6572 1 : m_currentSortOrder = config.runOrder();
6573 : }
6574 1 : return m_sortedFunctions;
6575 : }
6576 :
6577 : private:
6578 : std::vector<TestCase> m_functions;
6579 : mutable RunTests::InWhatOrder m_currentSortOrder;
6580 : mutable std::vector<TestCase> m_sortedFunctions;
6581 : size_t m_unnamedCount;
6582 : std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised
6583 : };
6584 :
6585 : ///////////////////////////////////////////////////////////////////////////
6586 :
6587 : class FreeFunctionTestCase : public SharedImpl<ITestCase> {
6588 : public:
6589 :
6590 31 : FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {}
6591 :
6592 68 : virtual void invoke() const {
6593 68 : m_fun();
6594 68 : }
6595 :
6596 : private:
6597 : virtual ~FreeFunctionTestCase();
6598 :
6599 : TestFunction m_fun;
6600 : };
6601 :
6602 31 : inline std::string extractClassName( std::string const& classOrQualifiedMethodName ) {
6603 31 : std::string className = classOrQualifiedMethodName;
6604 31 : if( startsWith( className, "&" ) )
6605 : {
6606 0 : std::size_t lastColons = className.rfind( "::" );
6607 0 : std::size_t penultimateColons = className.rfind( "::", lastColons-1 );
6608 0 : if( penultimateColons == std::string::npos )
6609 0 : penultimateColons = 1;
6610 0 : className = className.substr( penultimateColons, lastColons-penultimateColons );
6611 : }
6612 31 : return className;
6613 : }
6614 :
6615 31 : void registerTestCase
6616 : ( ITestCase* testCase,
6617 : char const* classOrQualifiedMethodName,
6618 : NameAndDesc const& nameAndDesc,
6619 : SourceLineInfo const& lineInfo ) {
6620 :
6621 31 : getMutableRegistryHub().registerTest
6622 : ( makeTestCase
6623 : ( testCase,
6624 : extractClassName( classOrQualifiedMethodName ),
6625 : nameAndDesc.name,
6626 : nameAndDesc.description,
6627 31 : lineInfo ) );
6628 31 : }
6629 31 : void registerTestCaseFunction
6630 : ( TestFunction function,
6631 : SourceLineInfo const& lineInfo,
6632 : NameAndDesc const& nameAndDesc ) {
6633 31 : registerTestCase( new FreeFunctionTestCase( function ), "", nameAndDesc, lineInfo );
6634 31 : }
6635 :
6636 : ///////////////////////////////////////////////////////////////////////////
6637 :
6638 31 : AutoReg::AutoReg
6639 : ( TestFunction function,
6640 : SourceLineInfo const& lineInfo,
6641 : NameAndDesc const& nameAndDesc ) {
6642 31 : registerTestCaseFunction( function, lineInfo, nameAndDesc );
6643 31 : }
6644 :
6645 31 : AutoReg::~AutoReg() {}
6646 :
6647 : } // end namespace Catch
6648 :
6649 : // #included from: catch_reporter_registry.hpp
6650 : #define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED
6651 :
6652 : #include <map>
6653 :
6654 : namespace Catch {
6655 :
6656 1 : class ReporterRegistry : public IReporterRegistry {
6657 :
6658 : public:
6659 :
6660 1 : virtual ~ReporterRegistry() CATCH_OVERRIDE {}
6661 :
6662 1 : virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const CATCH_OVERRIDE {
6663 1 : FactoryMap::const_iterator it = m_factories.find( name );
6664 1 : if( it == m_factories.end() )
6665 0 : return CATCH_NULL;
6666 1 : return it->second->create( ReporterConfig( config ) );
6667 : }
6668 :
6669 4 : void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) {
6670 4 : m_factories.insert( std::make_pair( name, factory ) );
6671 4 : }
6672 0 : void registerListener( Ptr<IReporterFactory> const& factory ) {
6673 0 : m_listeners.push_back( factory );
6674 0 : }
6675 :
6676 0 : virtual FactoryMap const& getFactories() const CATCH_OVERRIDE {
6677 0 : return m_factories;
6678 : }
6679 1 : virtual Listeners const& getListeners() const CATCH_OVERRIDE {
6680 1 : return m_listeners;
6681 : }
6682 :
6683 : private:
6684 : FactoryMap m_factories;
6685 : Listeners m_listeners;
6686 : };
6687 : }
6688 :
6689 : // #included from: catch_exception_translator_registry.hpp
6690 : #define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
6691 :
6692 : #ifdef __OBJC__
6693 : #import "Foundation/Foundation.h"
6694 : #endif
6695 :
6696 : namespace Catch {
6697 :
6698 1 : class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
6699 : public:
6700 2 : ~ExceptionTranslatorRegistry() {
6701 1 : deleteAll( m_translators );
6702 1 : }
6703 :
6704 0 : virtual void registerTranslator( const IExceptionTranslator* translator ) {
6705 0 : m_translators.push_back( translator );
6706 0 : }
6707 :
6708 0 : virtual std::string translateActiveException() const {
6709 : try {
6710 : #ifdef __OBJC__
6711 : // In Objective-C try objective-c exceptions first
6712 : @try {
6713 : return tryTranslators();
6714 : }
6715 : @catch (NSException *exception) {
6716 : return Catch::toString( [exception description] );
6717 : }
6718 : #else
6719 0 : return tryTranslators();
6720 : #endif
6721 : }
6722 : catch( TestFailureException& ) {
6723 : throw;
6724 : }
6725 : catch( std::exception& ex ) {
6726 : return ex.what();
6727 : }
6728 : catch( std::string& msg ) {
6729 : return msg;
6730 : }
6731 : catch( const char* msg ) {
6732 : return msg;
6733 : }
6734 : catch(...) {
6735 : return "Unknown exception";
6736 : }
6737 : }
6738 :
6739 0 : std::string tryTranslators() const {
6740 0 : if( m_translators.empty() )
6741 0 : throw;
6742 : else
6743 0 : return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() );
6744 : }
6745 :
6746 : private:
6747 : std::vector<const IExceptionTranslator*> m_translators;
6748 : };
6749 : }
6750 :
6751 : namespace Catch {
6752 :
6753 : namespace {
6754 :
6755 2 : class RegistryHub : public IRegistryHub, public IMutableRegistryHub {
6756 :
6757 : RegistryHub( RegistryHub const& );
6758 : void operator=( RegistryHub const& );
6759 :
6760 : public: // IRegistryHub
6761 1 : RegistryHub() {
6762 1 : }
6763 2 : virtual IReporterRegistry const& getReporterRegistry() const CATCH_OVERRIDE {
6764 2 : return m_reporterRegistry;
6765 : }
6766 1 : virtual ITestCaseRegistry const& getTestCaseRegistry() const CATCH_OVERRIDE {
6767 1 : return m_testCaseRegistry;
6768 : }
6769 0 : virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() CATCH_OVERRIDE {
6770 0 : return m_exceptionTranslatorRegistry;
6771 : }
6772 :
6773 : public: // IMutableRegistryHub
6774 4 : virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) CATCH_OVERRIDE {
6775 4 : m_reporterRegistry.registerReporter( name, factory );
6776 4 : }
6777 0 : virtual void registerListener( Ptr<IReporterFactory> const& factory ) CATCH_OVERRIDE {
6778 0 : m_reporterRegistry.registerListener( factory );
6779 0 : }
6780 31 : virtual void registerTest( TestCase const& testInfo ) CATCH_OVERRIDE {
6781 31 : m_testCaseRegistry.registerTest( testInfo );
6782 31 : }
6783 0 : virtual void registerTranslator( const IExceptionTranslator* translator ) CATCH_OVERRIDE {
6784 0 : m_exceptionTranslatorRegistry.registerTranslator( translator );
6785 0 : }
6786 :
6787 : private:
6788 : TestRegistry m_testCaseRegistry;
6789 : ReporterRegistry m_reporterRegistry;
6790 : ExceptionTranslatorRegistry m_exceptionTranslatorRegistry;
6791 : };
6792 :
6793 : // Single, global, instance
6794 40 : inline RegistryHub*& getTheRegistryHub() {
6795 : static RegistryHub* theRegistryHub = CATCH_NULL;
6796 40 : if( !theRegistryHub )
6797 1 : theRegistryHub = new RegistryHub();
6798 40 : return theRegistryHub;
6799 : }
6800 : }
6801 :
6802 3 : IRegistryHub& getRegistryHub() {
6803 3 : return *getTheRegistryHub();
6804 : }
6805 35 : IMutableRegistryHub& getMutableRegistryHub() {
6806 35 : return *getTheRegistryHub();
6807 : }
6808 1 : void cleanUp() {
6809 1 : delete getTheRegistryHub();
6810 1 : getTheRegistryHub() = CATCH_NULL;
6811 1 : cleanUpContext();
6812 1 : }
6813 0 : std::string translateActiveException() {
6814 0 : return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException();
6815 : }
6816 :
6817 : } // end namespace Catch
6818 :
6819 : // #included from: catch_notimplemented_exception.hpp
6820 : #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED
6821 :
6822 : #include <ostream>
6823 :
6824 : namespace Catch {
6825 :
6826 0 : NotImplementedException::NotImplementedException( SourceLineInfo const& lineInfo )
6827 0 : : m_lineInfo( lineInfo ) {
6828 0 : std::ostringstream oss;
6829 0 : oss << lineInfo << ": function ";
6830 0 : oss << "not implemented";
6831 0 : m_what = oss.str();
6832 0 : }
6833 :
6834 0 : const char* NotImplementedException::what() const CATCH_NOEXCEPT {
6835 0 : return m_what.c_str();
6836 : }
6837 :
6838 : } // end namespace Catch
6839 :
6840 : // #included from: catch_context_impl.hpp
6841 : #define TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
6842 :
6843 : // #included from: catch_stream.hpp
6844 : #define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED
6845 :
6846 : #include <stdexcept>
6847 : #include <cstdio>
6848 : #include <iostream>
6849 :
6850 : namespace Catch {
6851 :
6852 : template<typename WriterF, size_t bufferSize=256>
6853 : class StreamBufImpl : public StreamBufBase {
6854 : char data[bufferSize];
6855 : WriterF m_writer;
6856 :
6857 : public:
6858 0 : StreamBufImpl() {
6859 0 : setp( data, data + sizeof(data) );
6860 0 : }
6861 :
6862 0 : ~StreamBufImpl() CATCH_NOEXCEPT {
6863 0 : sync();
6864 0 : }
6865 :
6866 : private:
6867 0 : int overflow( int c ) {
6868 0 : sync();
6869 :
6870 0 : if( c != EOF ) {
6871 0 : if( pbase() == epptr() )
6872 0 : m_writer( std::string( 1, static_cast<char>( c ) ) );
6873 : else
6874 0 : sputc( static_cast<char>( c ) );
6875 : }
6876 0 : return 0;
6877 : }
6878 :
6879 0 : int sync() {
6880 0 : if( pbase() != pptr() ) {
6881 0 : m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) );
6882 0 : setp( pbase(), epptr() );
6883 : }
6884 0 : return 0;
6885 : }
6886 : };
6887 :
6888 : ///////////////////////////////////////////////////////////////////////////
6889 :
6890 0 : FileStream::FileStream( std::string const& filename ) {
6891 0 : m_ofs.open( filename.c_str() );
6892 0 : if( m_ofs.fail() ) {
6893 0 : std::ostringstream oss;
6894 0 : oss << "Unable to open file: '" << filename << "'";
6895 0 : throw std::domain_error( oss.str() );
6896 : }
6897 0 : }
6898 :
6899 0 : std::ostream& FileStream::stream() const {
6900 0 : return m_ofs;
6901 : }
6902 :
6903 : struct OutputDebugWriter {
6904 :
6905 0 : void operator()( std::string const&str ) {
6906 0 : writeToDebugConsole( str );
6907 0 : }
6908 : };
6909 :
6910 0 : DebugOutStream::DebugOutStream()
6911 : : m_streamBuf( new StreamBufImpl<OutputDebugWriter>() ),
6912 0 : m_os( m_streamBuf.get() )
6913 0 : {}
6914 :
6915 0 : std::ostream& DebugOutStream::stream() const {
6916 0 : return m_os;
6917 : }
6918 :
6919 : // Store the streambuf from cout up-front because
6920 : // cout may get redirected when running tests
6921 1 : CoutStream::CoutStream()
6922 1 : : m_os( Catch::cout().rdbuf() )
6923 1 : {}
6924 :
6925 1 : std::ostream& CoutStream::stream() const {
6926 1 : return m_os;
6927 : }
6928 :
6929 : #ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions
6930 9 : std::ostream& cout() {
6931 9 : return std::cout;
6932 : }
6933 0 : std::ostream& cerr() {
6934 0 : return std::cerr;
6935 : }
6936 : #endif
6937 : }
6938 :
6939 : namespace Catch {
6940 :
6941 2 : class Context : public IMutableContext {
6942 :
6943 1 : Context() : m_config( CATCH_NULL ), m_runner( CATCH_NULL ), m_resultCapture( CATCH_NULL ) {}
6944 : Context( Context const& );
6945 : void operator=( Context const& );
6946 :
6947 : public: // IContext
6948 2898 : virtual IResultCapture* getResultCapture() {
6949 2898 : return m_resultCapture;
6950 : }
6951 0 : virtual IRunner* getRunner() {
6952 0 : return m_runner;
6953 : }
6954 0 : virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) {
6955 0 : return getGeneratorsForCurrentTest()
6956 0 : .getGeneratorInfo( fileInfo, totalSize )
6957 0 : .getCurrentIndex();
6958 : }
6959 31 : virtual bool advanceGeneratorsForCurrentTest() {
6960 31 : IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
6961 31 : return generators && generators->moveNext();
6962 : }
6963 :
6964 1 : virtual Ptr<IConfig const> getConfig() const {
6965 1 : return m_config;
6966 : }
6967 :
6968 : public: // IMutableContext
6969 1 : virtual void setResultCapture( IResultCapture* resultCapture ) {
6970 1 : m_resultCapture = resultCapture;
6971 1 : }
6972 1 : virtual void setRunner( IRunner* runner ) {
6973 1 : m_runner = runner;
6974 1 : }
6975 1 : virtual void setConfig( Ptr<IConfig const> const& config ) {
6976 1 : m_config = config;
6977 1 : }
6978 :
6979 : friend IMutableContext& getCurrentMutableContext();
6980 :
6981 : private:
6982 31 : IGeneratorsForTest* findGeneratorsForCurrentTest() {
6983 31 : std::string testName = getResultCapture()->getCurrentTestName();
6984 :
6985 : std::map<std::string, IGeneratorsForTest*>::const_iterator it =
6986 31 : m_generatorsByTestName.find( testName );
6987 62 : return it != m_generatorsByTestName.end()
6988 0 : ? it->second
6989 62 : : CATCH_NULL;
6990 : }
6991 :
6992 0 : IGeneratorsForTest& getGeneratorsForCurrentTest() {
6993 0 : IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
6994 0 : if( !generators ) {
6995 0 : std::string testName = getResultCapture()->getCurrentTestName();
6996 0 : generators = createGeneratorsForTest();
6997 0 : m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
6998 : }
6999 0 : return *generators;
7000 : }
7001 :
7002 : private:
7003 : Ptr<IConfig const> m_config;
7004 : IRunner* m_runner;
7005 : IResultCapture* m_resultCapture;
7006 : std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName;
7007 : };
7008 :
7009 : namespace {
7010 : Context* currentContext = CATCH_NULL;
7011 : }
7012 2900 : IMutableContext& getCurrentMutableContext() {
7013 2900 : if( !currentContext )
7014 1 : currentContext = new Context();
7015 2900 : return *currentContext;
7016 : }
7017 2899 : IContext& getCurrentContext() {
7018 2899 : return getCurrentMutableContext();
7019 : }
7020 :
7021 1 : void cleanUpContext() {
7022 1 : delete currentContext;
7023 1 : currentContext = CATCH_NULL;
7024 1 : }
7025 : }
7026 :
7027 : // #included from: catch_console_colour_impl.hpp
7028 : #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
7029 :
7030 : namespace Catch {
7031 : namespace {
7032 :
7033 1 : struct IColourImpl {
7034 1 : virtual ~IColourImpl() {}
7035 : virtual void use( Colour::Code _colourCode ) = 0;
7036 : };
7037 :
7038 0 : struct NoColourImpl : IColourImpl {
7039 0 : void use( Colour::Code ) {}
7040 :
7041 0 : static IColourImpl* instance() {
7042 0 : static NoColourImpl s_instance;
7043 0 : return &s_instance;
7044 : }
7045 : };
7046 :
7047 : } // anon namespace
7048 : } // namespace Catch
7049 :
7050 : #if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI )
7051 : # ifdef CATCH_PLATFORM_WINDOWS
7052 : # define CATCH_CONFIG_COLOUR_WINDOWS
7053 : # else
7054 : # define CATCH_CONFIG_COLOUR_ANSI
7055 : # endif
7056 : #endif
7057 :
7058 : #if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) /////////////////////////////////////////
7059 :
7060 : #ifndef NOMINMAX
7061 : #define NOMINMAX
7062 : #endif
7063 :
7064 : #ifdef __AFXDLL
7065 : #include <AfxWin.h>
7066 : #else
7067 : #include <windows.h>
7068 : #endif
7069 :
7070 : namespace Catch {
7071 : namespace {
7072 :
7073 : class Win32ColourImpl : public IColourImpl {
7074 : public:
7075 : Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) )
7076 : {
7077 : CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
7078 : GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo );
7079 : originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY );
7080 : originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
7081 : }
7082 :
7083 : virtual void use( Colour::Code _colourCode ) {
7084 : switch( _colourCode ) {
7085 : case Colour::None: return setTextAttribute( originalForegroundAttributes );
7086 : case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
7087 : case Colour::Red: return setTextAttribute( FOREGROUND_RED );
7088 : case Colour::Green: return setTextAttribute( FOREGROUND_GREEN );
7089 : case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE );
7090 : case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN );
7091 : case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN );
7092 : case Colour::Grey: return setTextAttribute( 0 );
7093 :
7094 : case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY );
7095 : case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED );
7096 : case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN );
7097 : case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
7098 :
7099 : case Colour::Bright: throw std::logic_error( "not a colour" );
7100 : }
7101 : }
7102 :
7103 : private:
7104 : void setTextAttribute( WORD _textAttribute ) {
7105 : SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes );
7106 : }
7107 : HANDLE stdoutHandle;
7108 : WORD originalForegroundAttributes;
7109 : WORD originalBackgroundAttributes;
7110 : };
7111 :
7112 : IColourImpl* platformColourInstance() {
7113 : static Win32ColourImpl s_instance;
7114 :
7115 : Ptr<IConfig const> config = getCurrentContext().getConfig();
7116 : UseColour::YesOrNo colourMode = config
7117 : ? config->useColour()
7118 : : UseColour::Auto;
7119 : if( colourMode == UseColour::Auto )
7120 : colourMode = !isDebuggerActive()
7121 : ? UseColour::Yes
7122 : : UseColour::No;
7123 : return colourMode == UseColour::Yes
7124 : ? &s_instance
7125 : : NoColourImpl::instance();
7126 : }
7127 :
7128 : } // end anon namespace
7129 : } // end namespace Catch
7130 :
7131 : #elif defined( CATCH_CONFIG_COLOUR_ANSI ) //////////////////////////////////////
7132 :
7133 : #include <unistd.h>
7134 :
7135 : namespace Catch {
7136 : namespace {
7137 :
7138 : // use POSIX/ ANSI console terminal codes
7139 : // Thanks to Adam Strzelecki for original contribution
7140 : // (http://github.com/nanoant)
7141 : // https://github.com/philsquared/Catch/pull/131
7142 2 : class PosixColourImpl : public IColourImpl {
7143 : public:
7144 8 : virtual void use( Colour::Code _colourCode ) {
7145 8 : switch( _colourCode ) {
7146 : case Colour::None:
7147 4 : case Colour::White: return setColour( "[0m" );
7148 0 : case Colour::Red: return setColour( "[0;31m" );
7149 0 : case Colour::Green: return setColour( "[0;32m" );
7150 0 : case Colour::Blue: return setColour( "[0:34m" );
7151 0 : case Colour::Cyan: return setColour( "[0;36m" );
7152 1 : case Colour::Yellow: return setColour( "[0;33m" );
7153 0 : case Colour::Grey: return setColour( "[1;30m" );
7154 :
7155 0 : case Colour::LightGrey: return setColour( "[0;37m" );
7156 1 : case Colour::BrightRed: return setColour( "[1;31m" );
7157 2 : case Colour::BrightGreen: return setColour( "[1;32m" );
7158 0 : case Colour::BrightWhite: return setColour( "[1;37m" );
7159 :
7160 0 : case Colour::Bright: throw std::logic_error( "not a colour" );
7161 : }
7162 : }
7163 1 : static IColourImpl* instance() {
7164 1 : static PosixColourImpl s_instance;
7165 1 : return &s_instance;
7166 : }
7167 :
7168 : private:
7169 8 : void setColour( const char* _escapeCode ) {
7170 8 : Catch::cout() << '\033' << _escapeCode;
7171 8 : }
7172 : };
7173 :
7174 1 : IColourImpl* platformColourInstance() {
7175 1 : Ptr<IConfig const> config = getCurrentContext().getConfig();
7176 : UseColour::YesOrNo colourMode = config
7177 1 : ? config->useColour()
7178 2 : : UseColour::Auto;
7179 1 : if( colourMode == UseColour::Auto )
7180 2 : colourMode = (!isDebuggerActive() && isatty(STDOUT_FILENO) )
7181 : ? UseColour::Yes
7182 2 : : UseColour::No;
7183 : return colourMode == UseColour::Yes
7184 : ? PosixColourImpl::instance()
7185 1 : : NoColourImpl::instance();
7186 : }
7187 :
7188 : } // end anon namespace
7189 : } // end namespace Catch
7190 :
7191 : #else // not Windows or ANSI ///////////////////////////////////////////////
7192 :
7193 : namespace Catch {
7194 :
7195 : static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); }
7196 :
7197 : } // end namespace Catch
7198 :
7199 : #endif // Windows/ ANSI/ None
7200 :
7201 : namespace Catch {
7202 :
7203 4 : Colour::Colour( Code _colourCode ) : m_moved( false ) { use( _colourCode ); }
7204 0 : Colour::Colour( Colour const& _other ) : m_moved( false ) { const_cast<Colour&>( _other ).m_moved = true; }
7205 4 : Colour::~Colour(){ if( !m_moved ) use( None ); }
7206 :
7207 8 : void Colour::use( Code _colourCode ) {
7208 8 : static IColourImpl* impl = platformColourInstance();
7209 8 : impl->use( _colourCode );
7210 8 : }
7211 :
7212 : } // end namespace Catch
7213 :
7214 : // #included from: catch_generators_impl.hpp
7215 : #define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
7216 :
7217 : #include <vector>
7218 : #include <string>
7219 : #include <map>
7220 :
7221 : namespace Catch {
7222 :
7223 0 : struct GeneratorInfo : IGeneratorInfo {
7224 :
7225 0 : GeneratorInfo( std::size_t size )
7226 : : m_size( size ),
7227 0 : m_currentIndex( 0 )
7228 0 : {}
7229 :
7230 0 : bool moveNext() {
7231 0 : if( ++m_currentIndex == m_size ) {
7232 0 : m_currentIndex = 0;
7233 0 : return false;
7234 : }
7235 0 : return true;
7236 : }
7237 :
7238 0 : std::size_t getCurrentIndex() const {
7239 0 : return m_currentIndex;
7240 : }
7241 :
7242 : std::size_t m_size;
7243 : std::size_t m_currentIndex;
7244 : };
7245 :
7246 : ///////////////////////////////////////////////////////////////////////////
7247 :
7248 0 : class GeneratorsForTest : public IGeneratorsForTest {
7249 :
7250 : public:
7251 0 : ~GeneratorsForTest() {
7252 0 : deleteAll( m_generatorsInOrder );
7253 0 : }
7254 :
7255 0 : IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) {
7256 0 : std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
7257 0 : if( it == m_generatorsByName.end() ) {
7258 0 : IGeneratorInfo* info = new GeneratorInfo( size );
7259 0 : m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
7260 0 : m_generatorsInOrder.push_back( info );
7261 0 : return *info;
7262 : }
7263 0 : return *it->second;
7264 : }
7265 :
7266 0 : bool moveNext() {
7267 0 : std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
7268 0 : std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
7269 0 : for(; it != itEnd; ++it ) {
7270 0 : if( (*it)->moveNext() )
7271 0 : return true;
7272 : }
7273 0 : return false;
7274 : }
7275 :
7276 : private:
7277 : std::map<std::string, IGeneratorInfo*> m_generatorsByName;
7278 : std::vector<IGeneratorInfo*> m_generatorsInOrder;
7279 : };
7280 :
7281 0 : IGeneratorsForTest* createGeneratorsForTest()
7282 : {
7283 0 : return new GeneratorsForTest();
7284 : }
7285 :
7286 : } // end namespace Catch
7287 :
7288 : // #included from: catch_assertionresult.hpp
7289 : #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED
7290 :
7291 : namespace Catch {
7292 :
7293 5210 : AssertionInfo::AssertionInfo( std::string const& _macroName,
7294 : SourceLineInfo const& _lineInfo,
7295 : std::string const& _capturedExpression,
7296 : ResultDisposition::Flags _resultDisposition )
7297 : : macroName( _macroName ),
7298 : lineInfo( _lineInfo ),
7299 : capturedExpression( _capturedExpression ),
7300 5210 : resultDisposition( _resultDisposition )
7301 5210 : {}
7302 :
7303 1 : AssertionResult::AssertionResult() {}
7304 :
7305 2571 : AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data )
7306 : : m_info( info ),
7307 2571 : m_resultData( data )
7308 2571 : {}
7309 :
7310 5143 : AssertionResult::~AssertionResult() {}
7311 :
7312 : // Result was a success
7313 0 : bool AssertionResult::succeeded() const {
7314 0 : return Catch::isOk( m_resultData.resultType );
7315 : }
7316 :
7317 : // Result was a success, or failure is suppressed
7318 5142 : bool AssertionResult::isOk() const {
7319 5142 : return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition );
7320 : }
7321 :
7322 5142 : ResultWas::OfType AssertionResult::getResultType() const {
7323 5142 : return m_resultData.resultType;
7324 : }
7325 :
7326 0 : bool AssertionResult::hasExpression() const {
7327 0 : return !m_info.capturedExpression.empty();
7328 : }
7329 :
7330 2571 : bool AssertionResult::hasMessage() const {
7331 2571 : return !m_resultData.message.empty();
7332 : }
7333 :
7334 0 : std::string AssertionResult::getExpression() const {
7335 0 : if( isFalseTest( m_info.resultDisposition ) )
7336 0 : return "!" + m_info.capturedExpression;
7337 : else
7338 0 : return m_info.capturedExpression;
7339 : }
7340 0 : std::string AssertionResult::getExpressionInMacro() const {
7341 0 : if( m_info.macroName.empty() )
7342 0 : return m_info.capturedExpression;
7343 : else
7344 0 : return m_info.macroName + "( " + m_info.capturedExpression + " )";
7345 : }
7346 :
7347 0 : bool AssertionResult::hasExpandedExpression() const {
7348 0 : return hasExpression() && getExpandedExpression() != getExpression();
7349 : }
7350 :
7351 0 : std::string AssertionResult::getExpandedExpression() const {
7352 0 : return m_resultData.reconstructedExpression;
7353 : }
7354 :
7355 0 : std::string AssertionResult::getMessage() const {
7356 0 : return m_resultData.message;
7357 : }
7358 0 : SourceLineInfo AssertionResult::getSourceInfo() const {
7359 0 : return m_info.lineInfo;
7360 : }
7361 :
7362 0 : std::string AssertionResult::getTestMacroName() const {
7363 0 : return m_info.macroName;
7364 : }
7365 :
7366 : } // end namespace Catch
7367 :
7368 : // #included from: catch_test_case_info.hpp
7369 : #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED
7370 :
7371 : namespace Catch {
7372 :
7373 102 : inline TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) {
7374 408 : if( startsWith( tag, "." ) ||
7375 408 : tag == "hide" ||
7376 102 : tag == "!hide" )
7377 0 : return TestCaseInfo::IsHidden;
7378 102 : else if( tag == "!throws" )
7379 0 : return TestCaseInfo::Throws;
7380 102 : else if( tag == "!shouldfail" )
7381 0 : return TestCaseInfo::ShouldFail;
7382 102 : else if( tag == "!mayfail" )
7383 0 : return TestCaseInfo::MayFail;
7384 : else
7385 102 : return TestCaseInfo::None;
7386 : }
7387 34 : inline bool isReservedTag( std::string const& tag ) {
7388 34 : return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !isalnum( tag[0] );
7389 : }
7390 34 : inline void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) {
7391 34 : if( isReservedTag( tag ) ) {
7392 : {
7393 0 : Colour colourGuard( Colour::Red );
7394 0 : Catch::cerr()
7395 0 : << "Tag name [" << tag << "] not allowed.\n"
7396 0 : << "Tag names starting with non alpha-numeric characters are reserved\n";
7397 : }
7398 : {
7399 0 : Colour colourGuard( Colour::FileName );
7400 0 : Catch::cerr() << _lineInfo << std::endl;
7401 : }
7402 0 : exit(1);
7403 : }
7404 34 : }
7405 :
7406 31 : TestCase makeTestCase( ITestCase* _testCase,
7407 : std::string const& _className,
7408 : std::string const& _name,
7409 : std::string const& _descOrTags,
7410 : SourceLineInfo const& _lineInfo )
7411 : {
7412 31 : bool isHidden( startsWith( _name, "./" ) ); // Legacy support
7413 :
7414 : // Parse out tags
7415 31 : std::set<std::string> tags;
7416 62 : std::string desc, tag;
7417 31 : bool inTag = false;
7418 403 : for( std::size_t i = 0; i < _descOrTags.size(); ++i ) {
7419 372 : char c = _descOrTags[i];
7420 372 : if( !inTag ) {
7421 37 : if( c == '[' )
7422 34 : inTag = true;
7423 : else
7424 3 : desc += c;
7425 : }
7426 : else {
7427 335 : if( c == ']' ) {
7428 34 : TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag );
7429 34 : if( prop == TestCaseInfo::IsHidden )
7430 0 : isHidden = true;
7431 34 : else if( prop == TestCaseInfo::None )
7432 34 : enforceNotReservedTag( tag, _lineInfo );
7433 :
7434 34 : tags.insert( tag );
7435 34 : tag.clear();
7436 34 : inTag = false;
7437 : }
7438 : else
7439 301 : tag += c;
7440 : }
7441 : }
7442 31 : if( isHidden ) {
7443 0 : tags.insert( "hide" );
7444 0 : tags.insert( "." );
7445 : }
7446 :
7447 62 : TestCaseInfo info( _name, _className, desc, tags, _lineInfo );
7448 62 : return TestCase( _testCase, info );
7449 : }
7450 :
7451 31 : void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags )
7452 : {
7453 31 : testCaseInfo.tags = tags;
7454 31 : testCaseInfo.lcaseTags.clear();
7455 :
7456 31 : std::ostringstream oss;
7457 65 : for( std::set<std::string>::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it ) {
7458 34 : oss << "[" << *it << "]";
7459 34 : std::string lcaseTag = toLower( *it );
7460 34 : testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) );
7461 34 : testCaseInfo.lcaseTags.insert( lcaseTag );
7462 34 : }
7463 31 : testCaseInfo.tagsAsString = oss.str();
7464 31 : }
7465 :
7466 31 : TestCaseInfo::TestCaseInfo( std::string const& _name,
7467 : std::string const& _className,
7468 : std::string const& _description,
7469 : std::set<std::string> const& _tags,
7470 : SourceLineInfo const& _lineInfo )
7471 : : name( _name ),
7472 : className( _className ),
7473 : description( _description ),
7474 : lineInfo( _lineInfo ),
7475 31 : properties( None )
7476 : {
7477 31 : setTags( *this, _tags );
7478 31 : }
7479 :
7480 279 : TestCaseInfo::TestCaseInfo( TestCaseInfo const& other )
7481 : : name( other.name ),
7482 : className( other.className ),
7483 : description( other.description ),
7484 : tags( other.tags ),
7485 : lcaseTags( other.lcaseTags ),
7486 : tagsAsString( other.tagsAsString ),
7487 : lineInfo( other.lineInfo ),
7488 279 : properties( other.properties )
7489 279 : {}
7490 :
7491 0 : bool TestCaseInfo::isHidden() const {
7492 0 : return ( properties & IsHidden ) != 0;
7493 : }
7494 0 : bool TestCaseInfo::throws() const {
7495 0 : return ( properties & Throws ) != 0;
7496 : }
7497 68 : bool TestCaseInfo::okToFail() const {
7498 68 : return ( properties & (ShouldFail | MayFail ) ) != 0;
7499 : }
7500 31 : bool TestCaseInfo::expectedToFail() const {
7501 31 : return ( properties & (ShouldFail ) ) != 0;
7502 : }
7503 :
7504 31 : TestCase::TestCase( ITestCase* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {}
7505 :
7506 155 : TestCase::TestCase( TestCase const& other )
7507 : : TestCaseInfo( other ),
7508 155 : test( other.test )
7509 155 : {}
7510 :
7511 0 : TestCase TestCase::withName( std::string const& _newName ) const {
7512 0 : TestCase other( *this );
7513 0 : other.name = _newName;
7514 0 : return other;
7515 : }
7516 :
7517 0 : void TestCase::swap( TestCase& other ) {
7518 0 : test.swap( other.test );
7519 0 : name.swap( other.name );
7520 0 : className.swap( other.className );
7521 0 : description.swap( other.description );
7522 0 : tags.swap( other.tags );
7523 0 : lcaseTags.swap( other.lcaseTags );
7524 0 : tagsAsString.swap( other.tagsAsString );
7525 0 : std::swap( TestCaseInfo::properties, static_cast<TestCaseInfo&>( other ).properties );
7526 0 : std::swap( lineInfo, other.lineInfo );
7527 0 : }
7528 :
7529 68 : void TestCase::invoke() const {
7530 68 : test->invoke();
7531 68 : }
7532 :
7533 0 : bool TestCase::operator == ( TestCase const& other ) const {
7534 0 : return test.get() == other.test.get() &&
7535 0 : name == other.name &&
7536 0 : className == other.className;
7537 : }
7538 :
7539 193 : bool TestCase::operator < ( TestCase const& other ) const {
7540 193 : return name < other.name;
7541 : }
7542 0 : TestCase& TestCase::operator = ( TestCase const& other ) {
7543 0 : TestCase temp( other );
7544 0 : swap( temp );
7545 0 : return *this;
7546 : }
7547 :
7548 161 : TestCaseInfo const& TestCase::getTestCaseInfo() const
7549 : {
7550 161 : return *this;
7551 : }
7552 :
7553 : } // end namespace Catch
7554 :
7555 : // #included from: catch_version.hpp
7556 : #define TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED
7557 :
7558 : namespace Catch {
7559 :
7560 1 : Version::Version
7561 : ( unsigned int _majorVersion,
7562 : unsigned int _minorVersion,
7563 : unsigned int _patchNumber,
7564 : std::string const& _branchName,
7565 : unsigned int _buildNumber )
7566 : : majorVersion( _majorVersion ),
7567 : minorVersion( _minorVersion ),
7568 : patchNumber( _patchNumber ),
7569 : branchName( _branchName ),
7570 1 : buildNumber( _buildNumber )
7571 1 : {}
7572 :
7573 0 : std::ostream& operator << ( std::ostream& os, Version const& version ) {
7574 0 : os << version.majorVersion << "."
7575 0 : << version.minorVersion << "."
7576 0 : << version.patchNumber;
7577 :
7578 0 : if( !version.branchName.empty() ) {
7579 0 : os << "-" << version.branchName
7580 0 : << "." << version.buildNumber;
7581 : }
7582 0 : return os;
7583 : }
7584 :
7585 1 : Version libraryVersion( 1, 5, 9, "", 0 );
7586 :
7587 : }
7588 :
7589 : // #included from: catch_message.hpp
7590 : #define TWOBLUECUBES_CATCH_MESSAGE_HPP_INCLUDED
7591 :
7592 : namespace Catch {
7593 :
7594 0 : MessageInfo::MessageInfo( std::string const& _macroName,
7595 : SourceLineInfo const& _lineInfo,
7596 : ResultWas::OfType _type )
7597 : : macroName( _macroName ),
7598 : lineInfo( _lineInfo ),
7599 : type( _type ),
7600 0 : sequence( ++globalCount )
7601 0 : {}
7602 :
7603 : // This may need protecting if threading support is added
7604 : unsigned int MessageInfo::globalCount = 0;
7605 :
7606 : ////////////////////////////////////////////////////////////////////////////
7607 :
7608 0 : ScopedMessage::ScopedMessage( MessageBuilder const& builder )
7609 0 : : m_info( builder.m_info )
7610 : {
7611 0 : m_info.message = builder.m_stream.str();
7612 0 : getResultCapture().pushScopedMessage( m_info );
7613 0 : }
7614 0 : ScopedMessage::ScopedMessage( ScopedMessage const& other )
7615 0 : : m_info( other.m_info )
7616 0 : {}
7617 :
7618 0 : ScopedMessage::~ScopedMessage() {
7619 0 : getResultCapture().popScopedMessage( m_info );
7620 0 : }
7621 :
7622 : } // end namespace Catch
7623 :
7624 : // #included from: catch_legacy_reporter_adapter.hpp
7625 : #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED
7626 :
7627 : // #included from: catch_legacy_reporter_adapter.h
7628 : #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED
7629 :
7630 : namespace Catch
7631 : {
7632 : // Deprecated
7633 : struct IReporter : IShared {
7634 : virtual ~IReporter();
7635 :
7636 : virtual bool shouldRedirectStdout() const = 0;
7637 :
7638 : virtual void StartTesting() = 0;
7639 : virtual void EndTesting( Totals const& totals ) = 0;
7640 : virtual void StartGroup( std::string const& groupName ) = 0;
7641 : virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0;
7642 : virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0;
7643 : virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0;
7644 : virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0;
7645 : virtual void EndSection( std::string const& sectionName, Counts const& assertions ) = 0;
7646 : virtual void NoAssertionsInSection( std::string const& sectionName ) = 0;
7647 : virtual void NoAssertionsInTestCase( std::string const& testName ) = 0;
7648 : virtual void Aborted() = 0;
7649 : virtual void Result( AssertionResult const& result ) = 0;
7650 : };
7651 :
7652 : class LegacyReporterAdapter : public SharedImpl<IStreamingReporter>
7653 : {
7654 : public:
7655 : LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter );
7656 : virtual ~LegacyReporterAdapter();
7657 :
7658 : virtual ReporterPreferences getPreferences() const;
7659 : virtual void noMatchingTestCases( std::string const& );
7660 : virtual void testRunStarting( TestRunInfo const& );
7661 : virtual void testGroupStarting( GroupInfo const& groupInfo );
7662 : virtual void testCaseStarting( TestCaseInfo const& testInfo );
7663 : virtual void sectionStarting( SectionInfo const& sectionInfo );
7664 : virtual void assertionStarting( AssertionInfo const& );
7665 : virtual bool assertionEnded( AssertionStats const& assertionStats );
7666 : virtual void sectionEnded( SectionStats const& sectionStats );
7667 : virtual void testCaseEnded( TestCaseStats const& testCaseStats );
7668 : virtual void testGroupEnded( TestGroupStats const& testGroupStats );
7669 : virtual void testRunEnded( TestRunStats const& testRunStats );
7670 : virtual void skipTest( TestCaseInfo const& );
7671 :
7672 : private:
7673 : Ptr<IReporter> m_legacyReporter;
7674 : };
7675 : }
7676 :
7677 : namespace Catch
7678 : {
7679 0 : LegacyReporterAdapter::LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter )
7680 0 : : m_legacyReporter( legacyReporter )
7681 0 : {}
7682 0 : LegacyReporterAdapter::~LegacyReporterAdapter() {}
7683 :
7684 0 : ReporterPreferences LegacyReporterAdapter::getPreferences() const {
7685 0 : ReporterPreferences prefs;
7686 0 : prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout();
7687 0 : return prefs;
7688 : }
7689 :
7690 0 : void LegacyReporterAdapter::noMatchingTestCases( std::string const& ) {}
7691 0 : void LegacyReporterAdapter::testRunStarting( TestRunInfo const& ) {
7692 0 : m_legacyReporter->StartTesting();
7693 0 : }
7694 0 : void LegacyReporterAdapter::testGroupStarting( GroupInfo const& groupInfo ) {
7695 0 : m_legacyReporter->StartGroup( groupInfo.name );
7696 0 : }
7697 0 : void LegacyReporterAdapter::testCaseStarting( TestCaseInfo const& testInfo ) {
7698 0 : m_legacyReporter->StartTestCase( testInfo );
7699 0 : }
7700 0 : void LegacyReporterAdapter::sectionStarting( SectionInfo const& sectionInfo ) {
7701 0 : m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description );
7702 0 : }
7703 0 : void LegacyReporterAdapter::assertionStarting( AssertionInfo const& ) {
7704 : // Not on legacy interface
7705 0 : }
7706 :
7707 0 : bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) {
7708 0 : if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
7709 0 : for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
7710 : it != itEnd;
7711 : ++it ) {
7712 0 : if( it->type == ResultWas::Info ) {
7713 0 : ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal );
7714 0 : rb << it->message;
7715 0 : rb.setResultType( ResultWas::Info );
7716 0 : AssertionResult result = rb.build();
7717 0 : m_legacyReporter->Result( result );
7718 : }
7719 : }
7720 : }
7721 0 : m_legacyReporter->Result( assertionStats.assertionResult );
7722 0 : return true;
7723 : }
7724 0 : void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) {
7725 0 : if( sectionStats.missingAssertions )
7726 0 : m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name );
7727 0 : m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions );
7728 0 : }
7729 0 : void LegacyReporterAdapter::testCaseEnded( TestCaseStats const& testCaseStats ) {
7730 0 : m_legacyReporter->EndTestCase
7731 : ( testCaseStats.testInfo,
7732 : testCaseStats.totals,
7733 : testCaseStats.stdOut,
7734 0 : testCaseStats.stdErr );
7735 0 : }
7736 0 : void LegacyReporterAdapter::testGroupEnded( TestGroupStats const& testGroupStats ) {
7737 0 : if( testGroupStats.aborting )
7738 0 : m_legacyReporter->Aborted();
7739 0 : m_legacyReporter->EndGroup( testGroupStats.groupInfo.name, testGroupStats.totals );
7740 0 : }
7741 0 : void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) {
7742 0 : m_legacyReporter->EndTesting( testRunStats.totals );
7743 0 : }
7744 0 : void LegacyReporterAdapter::skipTest( TestCaseInfo const& ) {
7745 0 : }
7746 : }
7747 :
7748 : // #included from: catch_timer.hpp
7749 :
7750 : #ifdef __clang__
7751 : #pragma clang diagnostic push
7752 : #pragma clang diagnostic ignored "-Wc++11-long-long"
7753 : #endif
7754 :
7755 : #ifdef CATCH_PLATFORM_WINDOWS
7756 : #include <windows.h>
7757 : #else
7758 : #include <sys/time.h>
7759 : #endif
7760 :
7761 : namespace Catch {
7762 :
7763 : namespace {
7764 : #ifdef CATCH_PLATFORM_WINDOWS
7765 : uint64_t getCurrentTicks() {
7766 : static uint64_t hz=0, hzo=0;
7767 : if (!hz) {
7768 : QueryPerformanceFrequency( reinterpret_cast<LARGE_INTEGER*>( &hz ) );
7769 : QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &hzo ) );
7770 : }
7771 : uint64_t t;
7772 : QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &t ) );
7773 : return ((t-hzo)*1000000)/hz;
7774 : }
7775 : #else
7776 432 : uint64_t getCurrentTicks() {
7777 : timeval t;
7778 432 : gettimeofday(&t,CATCH_NULL);
7779 432 : return static_cast<uint64_t>( t.tv_sec ) * 1000000ull + static_cast<uint64_t>( t.tv_usec );
7780 : }
7781 : #endif
7782 : }
7783 :
7784 317 : void Timer::start() {
7785 317 : m_ticks = getCurrentTicks();
7786 317 : }
7787 115 : unsigned int Timer::getElapsedMicroseconds() const {
7788 115 : return static_cast<unsigned int>(getCurrentTicks() - m_ticks);
7789 : }
7790 0 : unsigned int Timer::getElapsedMilliseconds() const {
7791 0 : return static_cast<unsigned int>(getElapsedMicroseconds()/1000);
7792 : }
7793 115 : double Timer::getElapsedSeconds() const {
7794 115 : return getElapsedMicroseconds()/1000000.0;
7795 : }
7796 :
7797 : } // namespace Catch
7798 :
7799 : #ifdef __clang__
7800 : #pragma clang diagnostic pop
7801 : #endif
7802 : // #included from: catch_common.hpp
7803 : #define TWOBLUECUBES_CATCH_COMMON_HPP_INCLUDED
7804 :
7805 : namespace Catch {
7806 :
7807 165 : bool startsWith( std::string const& s, std::string const& prefix ) {
7808 165 : return s.size() >= prefix.size() && s.substr( 0, prefix.size() ) == prefix;
7809 : }
7810 0 : bool endsWith( std::string const& s, std::string const& suffix ) {
7811 0 : return s.size() >= suffix.size() && s.substr( s.size()-suffix.size(), suffix.size() ) == suffix;
7812 : }
7813 0 : bool contains( std::string const& s, std::string const& infix ) {
7814 0 : return s.find( infix ) != std::string::npos;
7815 : }
7816 302 : char toLowerCh(char c) {
7817 302 : return static_cast<char>( ::tolower( c ) );
7818 : }
7819 35 : void toLowerInPlace( std::string& s ) {
7820 35 : std::transform( s.begin(), s.end(), s.begin(), toLowerCh );
7821 35 : }
7822 35 : std::string toLower( std::string const& s ) {
7823 35 : std::string lc = s;
7824 35 : toLowerInPlace( lc );
7825 35 : return lc;
7826 : }
7827 0 : std::string trim( std::string const& str ) {
7828 : static char const* whitespaceChars = "\n\r\t ";
7829 0 : std::string::size_type start = str.find_first_not_of( whitespaceChars );
7830 0 : std::string::size_type end = str.find_last_not_of( whitespaceChars );
7831 :
7832 0 : return start != std::string::npos ? str.substr( start, 1+end-start ) : "";
7833 : }
7834 :
7835 0 : bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) {
7836 0 : bool replaced = false;
7837 0 : std::size_t i = str.find( replaceThis );
7838 0 : while( i != std::string::npos ) {
7839 0 : replaced = true;
7840 0 : str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() );
7841 0 : if( i < str.size()-withThis.size() )
7842 0 : i = str.find( replaceThis, i+withThis.size() );
7843 : else
7844 0 : i = std::string::npos;
7845 : }
7846 0 : return replaced;
7847 : }
7848 :
7849 2 : pluralise::pluralise( std::size_t count, std::string const& label )
7850 : : m_count( count ),
7851 2 : m_label( label )
7852 2 : {}
7853 :
7854 2 : std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) {
7855 2 : os << pluraliser.m_count << " " << pluraliser.m_label;
7856 2 : if( pluraliser.m_count != 1 )
7857 2 : os << "s";
7858 2 : return os;
7859 : }
7860 :
7861 2 : SourceLineInfo::SourceLineInfo() : line( 0 ){}
7862 2851 : SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line )
7863 : : file( _file ),
7864 2851 : line( _line )
7865 2851 : {}
7866 11506 : SourceLineInfo::SourceLineInfo( SourceLineInfo const& other )
7867 : : file( other.file ),
7868 11506 : line( other.line )
7869 11506 : {}
7870 0 : bool SourceLineInfo::empty() const {
7871 0 : return file.empty();
7872 : }
7873 0 : bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const {
7874 0 : return line == other.line && file == other.file;
7875 : }
7876 0 : bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const {
7877 0 : return line < other.line || ( line == other.line && file < other.file );
7878 : }
7879 :
7880 69 : void seedRng( IConfig const& config ) {
7881 69 : if( config.rngSeed() != 0 )
7882 0 : std::srand( config.rngSeed() );
7883 69 : }
7884 0 : unsigned int rngSeed() {
7885 0 : return getCurrentContext().getConfig()->rngSeed();
7886 : }
7887 :
7888 249 : std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
7889 : #ifndef __GNUG__
7890 : os << info.file << "(" << info.line << ")";
7891 : #else
7892 249 : os << info.file << ":" << info.line;
7893 : #endif
7894 249 : return os;
7895 : }
7896 :
7897 0 : void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ) {
7898 0 : std::ostringstream oss;
7899 0 : oss << locationInfo << ": Internal Catch error: '" << message << "'";
7900 0 : if( alwaysTrue() )
7901 0 : throw std::logic_error( oss.str() );
7902 0 : }
7903 : }
7904 :
7905 : // #included from: catch_section.hpp
7906 : #define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED
7907 :
7908 : namespace Catch {
7909 :
7910 317 : SectionInfo::SectionInfo
7911 : ( SourceLineInfo const& _lineInfo,
7912 : std::string const& _name,
7913 : std::string const& _description )
7914 : : name( _name ),
7915 : description( _description ),
7916 317 : lineInfo( _lineInfo )
7917 317 : {}
7918 :
7919 249 : Section::Section( SectionInfo const& info )
7920 : : m_info( info ),
7921 249 : m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) )
7922 : {
7923 249 : m_timer.start();
7924 249 : }
7925 :
7926 498 : Section::~Section() {
7927 249 : if( m_sectionIncluded ) {
7928 47 : SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() );
7929 47 : if( std::uncaught_exception() )
7930 0 : getResultCapture().sectionEndedEarly( endInfo );
7931 : else
7932 47 : getResultCapture().sectionEnded( endInfo );
7933 : }
7934 249 : }
7935 :
7936 : // This indicates whether the section should be executed or not
7937 249 : Section::operator bool() const {
7938 249 : return m_sectionIncluded;
7939 : }
7940 :
7941 : } // end namespace Catch
7942 :
7943 : // #included from: catch_debugger.hpp
7944 : #define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED
7945 :
7946 : #include <iostream>
7947 :
7948 : #ifdef CATCH_PLATFORM_MAC
7949 :
7950 : #include <assert.h>
7951 : #include <stdbool.h>
7952 : #include <sys/types.h>
7953 : #include <unistd.h>
7954 : #include <sys/sysctl.h>
7955 :
7956 : namespace Catch{
7957 :
7958 : // The following function is taken directly from the following technical note:
7959 : // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html
7960 :
7961 : // Returns true if the current process is being debugged (either
7962 : // running under the debugger or has a debugger attached post facto).
7963 : bool isDebuggerActive(){
7964 :
7965 : int mib[4];
7966 : struct kinfo_proc info;
7967 : size_t size;
7968 :
7969 : // Initialize the flags so that, if sysctl fails for some bizarre
7970 : // reason, we get a predictable result.
7971 :
7972 : info.kp_proc.p_flag = 0;
7973 :
7974 : // Initialize mib, which tells sysctl the info we want, in this case
7975 : // we're looking for information about a specific process ID.
7976 :
7977 : mib[0] = CTL_KERN;
7978 : mib[1] = KERN_PROC;
7979 : mib[2] = KERN_PROC_PID;
7980 : mib[3] = getpid();
7981 :
7982 : // Call sysctl.
7983 :
7984 : size = sizeof(info);
7985 : if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, CATCH_NULL, 0) != 0 ) {
7986 : Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
7987 : return false;
7988 : }
7989 :
7990 : // We're being debugged if the P_TRACED flag is set.
7991 :
7992 : return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
7993 : }
7994 : } // namespace Catch
7995 :
7996 : #elif defined(_MSC_VER)
7997 : extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
7998 : namespace Catch {
7999 : bool isDebuggerActive() {
8000 : return IsDebuggerPresent() != 0;
8001 : }
8002 : }
8003 : #elif defined(__MINGW32__)
8004 : extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
8005 : namespace Catch {
8006 : bool isDebuggerActive() {
8007 : return IsDebuggerPresent() != 0;
8008 : }
8009 : }
8010 : #else
8011 : namespace Catch {
8012 1 : inline bool isDebuggerActive() { return false; }
8013 : }
8014 : #endif // Platform
8015 :
8016 : #ifdef CATCH_PLATFORM_WINDOWS
8017 : extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA( const char* );
8018 : namespace Catch {
8019 : void writeToDebugConsole( std::string const& text ) {
8020 : ::OutputDebugStringA( text.c_str() );
8021 : }
8022 : }
8023 : #else
8024 : namespace Catch {
8025 0 : void writeToDebugConsole( std::string const& text ) {
8026 : // !TBD: Need a version for Mac/ XCode and other IDEs
8027 0 : Catch::cout() << text;
8028 0 : }
8029 : }
8030 : #endif // Platform
8031 :
8032 : // #included from: catch_tostring.hpp
8033 : #define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED
8034 :
8035 : namespace Catch {
8036 :
8037 : namespace Detail {
8038 :
8039 1 : const std::string unprintableString = "{?}";
8040 :
8041 : namespace {
8042 : const int hexThreshold = 255;
8043 :
8044 : struct Endianness {
8045 : enum Arch { Big, Little };
8046 :
8047 0 : static Arch which() {
8048 : union _{
8049 : int asInt;
8050 : char asChar[sizeof (int)];
8051 : } u;
8052 :
8053 0 : u.asInt = 1;
8054 0 : return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little;
8055 : }
8056 : };
8057 : }
8058 :
8059 0 : std::string rawMemoryToString( const void *object, std::size_t size )
8060 : {
8061 : // Reverse order for little endian architectures
8062 0 : int i = 0, end = static_cast<int>( size ), inc = 1;
8063 0 : if( Endianness::which() == Endianness::Little ) {
8064 0 : i = end-1;
8065 0 : end = inc = -1;
8066 : }
8067 :
8068 0 : unsigned char const *bytes = static_cast<unsigned char const *>(object);
8069 0 : std::ostringstream os;
8070 0 : os << "0x" << std::setfill('0') << std::hex;
8071 0 : for( ; i != end; i += inc )
8072 0 : os << std::setw(2) << static_cast<unsigned>(bytes[i]);
8073 0 : return os.str();
8074 : }
8075 : }
8076 :
8077 0 : std::string toString( std::string const& value ) {
8078 0 : std::string s = value;
8079 0 : if( getCurrentContext().getConfig()->showInvisibles() ) {
8080 0 : for(size_t i = 0; i < s.size(); ++i ) {
8081 0 : std::string subs;
8082 0 : switch( s[i] ) {
8083 0 : case '\n': subs = "\\n"; break;
8084 0 : case '\t': subs = "\\t"; break;
8085 0 : default: break;
8086 : }
8087 0 : if( !subs.empty() ) {
8088 0 : s = s.substr( 0, i ) + subs + s.substr( i+1 );
8089 0 : ++i;
8090 : }
8091 0 : }
8092 : }
8093 0 : return "\"" + s + "\"";
8094 : }
8095 0 : std::string toString( std::wstring const& value ) {
8096 :
8097 0 : std::string s;
8098 0 : s.reserve( value.size() );
8099 0 : for(size_t i = 0; i < value.size(); ++i )
8100 0 : s += value[i] <= 0xff ? static_cast<char>( value[i] ) : '?';
8101 0 : return Catch::toString( s );
8102 : }
8103 :
8104 0 : std::string toString( const char* const value ) {
8105 0 : return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" );
8106 : }
8107 :
8108 0 : std::string toString( char* const value ) {
8109 0 : return Catch::toString( static_cast<const char*>( value ) );
8110 : }
8111 :
8112 0 : std::string toString( const wchar_t* const value )
8113 : {
8114 0 : return value ? Catch::toString( std::wstring(value) ) : std::string( "{null string}" );
8115 : }
8116 :
8117 0 : std::string toString( wchar_t* const value )
8118 : {
8119 0 : return Catch::toString( static_cast<const wchar_t*>( value ) );
8120 : }
8121 :
8122 824 : std::string toString( int value ) {
8123 824 : std::ostringstream oss;
8124 824 : oss << value;
8125 824 : if( value > Detail::hexThreshold )
8126 156 : oss << " (0x" << std::hex << value << ")";
8127 824 : return oss.str();
8128 : }
8129 :
8130 20 : std::string toString( unsigned long value ) {
8131 20 : std::ostringstream oss;
8132 20 : oss << value;
8133 20 : if( value > Detail::hexThreshold )
8134 0 : oss << " (0x" << std::hex << value << ")";
8135 20 : return oss.str();
8136 : }
8137 :
8138 20 : std::string toString( unsigned int value ) {
8139 20 : return Catch::toString( static_cast<unsigned long>( value ) );
8140 : }
8141 :
8142 : template<typename T>
8143 28 : std::string fpToString( T value, int precision ) {
8144 28 : std::ostringstream oss;
8145 56 : oss << std::setprecision( precision )
8146 28 : << std::fixed
8147 : << value;
8148 28 : std::string d = oss.str();
8149 28 : std::size_t i = d.find_last_not_of( '0' );
8150 28 : if( i != std::string::npos && i != d.size()-1 ) {
8151 18 : if( d[i] == '.' )
8152 14 : i++;
8153 18 : d = d.substr( 0, i+1 );
8154 : }
8155 28 : return d;
8156 : }
8157 :
8158 28 : std::string toString( const double value ) {
8159 28 : return fpToString( value, 10 );
8160 : }
8161 0 : std::string toString( const float value ) {
8162 0 : return fpToString( value, 5 ) + "f";
8163 : }
8164 :
8165 354 : std::string toString( bool value ) {
8166 354 : return value ? "true" : "false";
8167 : }
8168 :
8169 26 : std::string toString( char value ) {
8170 26 : return value < ' '
8171 : ? toString( static_cast<unsigned int>( value ) )
8172 26 : : Detail::makeString( value );
8173 : }
8174 :
8175 13 : std::string toString( signed char value ) {
8176 13 : return toString( static_cast<char>( value ) );
8177 : }
8178 :
8179 13 : std::string toString( unsigned char value ) {
8180 13 : return toString( static_cast<char>( value ) );
8181 : }
8182 :
8183 : #ifdef CATCH_CONFIG_CPP11_LONG_LONG
8184 : std::string toString( long long value ) {
8185 : std::ostringstream oss;
8186 : oss << value;
8187 : if( value > Detail::hexThreshold )
8188 : oss << " (0x" << std::hex << value << ")";
8189 : return oss.str();
8190 : }
8191 : std::string toString( unsigned long long value ) {
8192 : std::ostringstream oss;
8193 : oss << value;
8194 : if( value > Detail::hexThreshold )
8195 : oss << " (0x" << std::hex << value << ")";
8196 : return oss.str();
8197 : }
8198 : #endif
8199 :
8200 : #ifdef CATCH_CONFIG_CPP11_NULLPTR
8201 : std::string toString( std::nullptr_t ) {
8202 : return "nullptr";
8203 : }
8204 : #endif
8205 :
8206 : #ifdef __OBJC__
8207 : std::string toString( NSString const * const& nsstring ) {
8208 : if( !nsstring )
8209 : return "nil";
8210 : return "@" + toString([nsstring UTF8String]);
8211 : }
8212 : std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ) {
8213 : if( !nsstring )
8214 : return "nil";
8215 : return "@" + toString([nsstring UTF8String]);
8216 : }
8217 : std::string toString( NSObject* const& nsObject ) {
8218 : return toString( [nsObject description] );
8219 : }
8220 : #endif
8221 :
8222 : } // end namespace Catch
8223 :
8224 : // #included from: catch_result_builder.hpp
8225 : #define TWOBLUECUBES_CATCH_RESULT_BUILDER_HPP_INCLUDED
8226 :
8227 : namespace Catch {
8228 :
8229 2571 : std::string capturedExpressionWithSecondArgument( std::string const& capturedExpression, std::string const& secondArg ) {
8230 2571 : return secondArg.empty() || secondArg == "\"\""
8231 : ? capturedExpression
8232 7713 : : capturedExpression + ", " + secondArg;
8233 : }
8234 2571 : ResultBuilder::ResultBuilder( char const* macroName,
8235 : SourceLineInfo const& lineInfo,
8236 : char const* capturedExpression,
8237 : ResultDisposition::Flags resultDisposition,
8238 : char const* secondArg )
8239 : : m_assertionInfo( macroName, lineInfo, capturedExpressionWithSecondArgument( capturedExpression, secondArg ), resultDisposition ),
8240 : m_shouldDebugBreak( false ),
8241 2571 : m_shouldThrow( false )
8242 2571 : {}
8243 :
8244 0 : ResultBuilder& ResultBuilder::setResultType( ResultWas::OfType result ) {
8245 0 : m_data.resultType = result;
8246 0 : return *this;
8247 : }
8248 2571 : ResultBuilder& ResultBuilder::setResultType( bool result ) {
8249 2571 : m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed;
8250 2571 : return *this;
8251 : }
8252 2571 : ResultBuilder& ResultBuilder::setLhs( std::string const& lhs ) {
8253 2571 : m_exprComponents.lhs = lhs;
8254 2571 : return *this;
8255 : }
8256 2217 : ResultBuilder& ResultBuilder::setRhs( std::string const& rhs ) {
8257 2217 : m_exprComponents.rhs = rhs;
8258 2217 : return *this;
8259 : }
8260 2217 : ResultBuilder& ResultBuilder::setOp( std::string const& op ) {
8261 2217 : m_exprComponents.op = op;
8262 2217 : return *this;
8263 : }
8264 :
8265 2571 : void ResultBuilder::endExpression() {
8266 2571 : m_exprComponents.testFalse = isFalseTest( m_assertionInfo.resultDisposition );
8267 2571 : captureExpression();
8268 2571 : }
8269 :
8270 0 : void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) {
8271 0 : m_assertionInfo.resultDisposition = resultDisposition;
8272 0 : m_stream.oss << Catch::translateActiveException();
8273 0 : captureResult( ResultWas::ThrewException );
8274 0 : }
8275 :
8276 0 : void ResultBuilder::captureResult( ResultWas::OfType resultType ) {
8277 0 : setResultType( resultType );
8278 0 : captureExpression();
8279 0 : }
8280 0 : void ResultBuilder::captureExpectedException( std::string const& expectedMessage ) {
8281 0 : if( expectedMessage.empty() )
8282 0 : captureExpectedException( Matchers::Impl::Generic::AllOf<std::string>() );
8283 : else
8284 0 : captureExpectedException( Matchers::Equals( expectedMessage ) );
8285 0 : }
8286 :
8287 0 : void ResultBuilder::captureExpectedException( Matchers::Impl::Matcher<std::string> const& matcher ) {
8288 :
8289 0 : assert( m_exprComponents.testFalse == false );
8290 0 : AssertionResultData data = m_data;
8291 0 : data.resultType = ResultWas::Ok;
8292 0 : data.reconstructedExpression = m_assertionInfo.capturedExpression;
8293 :
8294 0 : std::string actualMessage = Catch::translateActiveException();
8295 0 : if( !matcher.match( actualMessage ) ) {
8296 0 : data.resultType = ResultWas::ExpressionFailed;
8297 0 : data.reconstructedExpression = actualMessage;
8298 : }
8299 0 : AssertionResult result( m_assertionInfo, data );
8300 0 : handleResult( result );
8301 0 : }
8302 :
8303 2571 : void ResultBuilder::captureExpression() {
8304 2571 : AssertionResult result = build();
8305 2571 : handleResult( result );
8306 2571 : }
8307 2571 : void ResultBuilder::handleResult( AssertionResult const& result )
8308 : {
8309 2571 : getResultCapture().assertionEnded( result );
8310 :
8311 2571 : if( !result.isOk() ) {
8312 0 : if( getCurrentContext().getConfig()->shouldDebugBreak() )
8313 0 : m_shouldDebugBreak = true;
8314 0 : if( getCurrentContext().getRunner()->aborting() || (m_assertionInfo.resultDisposition & ResultDisposition::Normal) )
8315 0 : m_shouldThrow = true;
8316 : }
8317 2571 : }
8318 2571 : void ResultBuilder::react() {
8319 2571 : if( m_shouldThrow )
8320 0 : throw Catch::TestFailureException();
8321 2571 : }
8322 :
8323 2571 : bool ResultBuilder::shouldDebugBreak() const { return m_shouldDebugBreak; }
8324 0 : bool ResultBuilder::allowThrows() const { return getCurrentContext().getConfig()->allowThrows(); }
8325 :
8326 2571 : AssertionResult ResultBuilder::build() const
8327 : {
8328 2571 : assert( m_data.resultType != ResultWas::Unknown );
8329 :
8330 2571 : AssertionResultData data = m_data;
8331 :
8332 : // Flip bool results if testFalse is set
8333 2571 : if( m_exprComponents.testFalse ) {
8334 207 : if( data.resultType == ResultWas::Ok )
8335 0 : data.resultType = ResultWas::ExpressionFailed;
8336 207 : else if( data.resultType == ResultWas::ExpressionFailed )
8337 207 : data.resultType = ResultWas::Ok;
8338 : }
8339 :
8340 2571 : data.message = m_stream.oss.str();
8341 2571 : data.reconstructedExpression = reconstructExpression();
8342 2571 : if( m_exprComponents.testFalse ) {
8343 207 : if( m_exprComponents.op == "" )
8344 207 : data.reconstructedExpression = "!" + data.reconstructedExpression;
8345 : else
8346 0 : data.reconstructedExpression = "!(" + data.reconstructedExpression + ")";
8347 : }
8348 2571 : return AssertionResult( m_assertionInfo, data );
8349 : }
8350 2571 : std::string ResultBuilder::reconstructExpression() const {
8351 2571 : if( m_exprComponents.op == "" )
8352 354 : return m_exprComponents.lhs.empty() ? m_assertionInfo.capturedExpression : m_exprComponents.op + m_exprComponents.lhs;
8353 2217 : else if( m_exprComponents.op == "matches" )
8354 0 : return m_exprComponents.lhs + " " + m_exprComponents.rhs;
8355 2217 : else if( m_exprComponents.op != "!" ) {
8356 6596 : if( m_exprComponents.lhs.size() + m_exprComponents.rhs.size() < 40 &&
8357 4379 : m_exprComponents.lhs.find("\n") == std::string::npos &&
8358 2162 : m_exprComponents.rhs.find("\n") == std::string::npos )
8359 2162 : return m_exprComponents.lhs + " " + m_exprComponents.op + " " + m_exprComponents.rhs;
8360 : else
8361 55 : return m_exprComponents.lhs + "\n" + m_exprComponents.op + "\n" + m_exprComponents.rhs;
8362 : }
8363 : else
8364 0 : 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}";
8365 : }
8366 :
8367 : } // end namespace Catch
8368 :
8369 : // #included from: catch_tag_alias_registry.hpp
8370 : #define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED
8371 :
8372 : // #included from: catch_tag_alias_registry.h
8373 : #define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_H_INCLUDED
8374 :
8375 : #include <map>
8376 :
8377 : namespace Catch {
8378 :
8379 1 : class TagAliasRegistry : public ITagAliasRegistry {
8380 : public:
8381 : virtual ~TagAliasRegistry();
8382 : virtual Option<TagAlias> find( std::string const& alias ) const;
8383 : virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const;
8384 : void add( char const* alias, char const* tag, SourceLineInfo const& lineInfo );
8385 : static TagAliasRegistry& get();
8386 :
8387 : private:
8388 : std::map<std::string, TagAlias> m_registry;
8389 : };
8390 :
8391 : } // end namespace Catch
8392 :
8393 : #include <map>
8394 : #include <iostream>
8395 :
8396 : namespace Catch {
8397 :
8398 1 : TagAliasRegistry::~TagAliasRegistry() {}
8399 :
8400 0 : Option<TagAlias> TagAliasRegistry::find( std::string const& alias ) const {
8401 0 : std::map<std::string, TagAlias>::const_iterator it = m_registry.find( alias );
8402 0 : if( it != m_registry.end() )
8403 0 : return it->second;
8404 : else
8405 0 : return Option<TagAlias>();
8406 : }
8407 :
8408 1 : std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const {
8409 1 : std::string expandedTestSpec = unexpandedTestSpec;
8410 1 : for( std::map<std::string, TagAlias>::const_iterator it = m_registry.begin(), itEnd = m_registry.end();
8411 : it != itEnd;
8412 : ++it ) {
8413 0 : std::size_t pos = expandedTestSpec.find( it->first );
8414 0 : if( pos != std::string::npos ) {
8415 0 : expandedTestSpec = expandedTestSpec.substr( 0, pos ) +
8416 0 : it->second.tag +
8417 0 : expandedTestSpec.substr( pos + it->first.size() );
8418 : }
8419 : }
8420 1 : return expandedTestSpec;
8421 : }
8422 :
8423 0 : void TagAliasRegistry::add( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) {
8424 :
8425 0 : if( !startsWith( alias, "[@" ) || !endsWith( alias, "]" ) ) {
8426 0 : std::ostringstream oss;
8427 0 : oss << "error: tag alias, \"" << alias << "\" is not of the form [@alias name].\n" << lineInfo;
8428 0 : throw std::domain_error( oss.str().c_str() );
8429 : }
8430 0 : if( !m_registry.insert( std::make_pair( alias, TagAlias( tag, lineInfo ) ) ).second ) {
8431 0 : std::ostringstream oss;
8432 0 : oss << "error: tag alias, \"" << alias << "\" already registered.\n"
8433 0 : << "\tFirst seen at " << find(alias)->lineInfo << "\n"
8434 0 : << "\tRedefined at " << lineInfo;
8435 0 : throw std::domain_error( oss.str().c_str() );
8436 : }
8437 0 : }
8438 :
8439 1 : TagAliasRegistry& TagAliasRegistry::get() {
8440 1 : static TagAliasRegistry instance;
8441 1 : return instance;
8442 :
8443 : }
8444 :
8445 1 : ITagAliasRegistry::~ITagAliasRegistry() {}
8446 1 : ITagAliasRegistry const& ITagAliasRegistry::get() { return TagAliasRegistry::get(); }
8447 :
8448 0 : RegistrarForTagAliases::RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) {
8449 : try {
8450 0 : TagAliasRegistry::get().add( alias, tag, lineInfo );
8451 : }
8452 : catch( std::exception& ex ) {
8453 : Colour colourGuard( Colour::Red );
8454 : Catch::cerr() << ex.what() << std::endl;
8455 : exit(1);
8456 : }
8457 0 : }
8458 :
8459 : } // end namespace Catch
8460 :
8461 : // #included from: ../reporters/catch_reporter_multi.hpp
8462 : #define TWOBLUECUBES_CATCH_REPORTER_MULTI_HPP_INCLUDED
8463 :
8464 : namespace Catch {
8465 :
8466 0 : class MultipleReporters : public SharedImpl<IStreamingReporter> {
8467 : typedef std::vector<Ptr<IStreamingReporter> > Reporters;
8468 : Reporters m_reporters;
8469 :
8470 : public:
8471 0 : void add( Ptr<IStreamingReporter> const& reporter ) {
8472 0 : m_reporters.push_back( reporter );
8473 0 : }
8474 :
8475 : public: // IStreamingReporter
8476 :
8477 0 : virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
8478 0 : return m_reporters[0]->getPreferences();
8479 : }
8480 :
8481 0 : virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
8482 0 : for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8483 : it != itEnd;
8484 : ++it )
8485 0 : (*it)->noMatchingTestCases( spec );
8486 0 : }
8487 :
8488 0 : virtual void testRunStarting( TestRunInfo const& testRunInfo ) CATCH_OVERRIDE {
8489 0 : for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8490 : it != itEnd;
8491 : ++it )
8492 0 : (*it)->testRunStarting( testRunInfo );
8493 0 : }
8494 :
8495 0 : virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
8496 0 : for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8497 : it != itEnd;
8498 : ++it )
8499 0 : (*it)->testGroupStarting( groupInfo );
8500 0 : }
8501 :
8502 0 : virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
8503 0 : for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8504 : it != itEnd;
8505 : ++it )
8506 0 : (*it)->testCaseStarting( testInfo );
8507 0 : }
8508 :
8509 0 : virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
8510 0 : for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8511 : it != itEnd;
8512 : ++it )
8513 0 : (*it)->sectionStarting( sectionInfo );
8514 0 : }
8515 :
8516 0 : virtual void assertionStarting( AssertionInfo const& assertionInfo ) CATCH_OVERRIDE {
8517 0 : for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8518 : it != itEnd;
8519 : ++it )
8520 0 : (*it)->assertionStarting( assertionInfo );
8521 0 : }
8522 :
8523 : // The return value indicates if the messages buffer should be cleared:
8524 0 : virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
8525 0 : bool clearBuffer = false;
8526 0 : for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8527 : it != itEnd;
8528 : ++it )
8529 0 : clearBuffer |= (*it)->assertionEnded( assertionStats );
8530 0 : return clearBuffer;
8531 : }
8532 :
8533 0 : virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
8534 0 : for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8535 : it != itEnd;
8536 : ++it )
8537 0 : (*it)->sectionEnded( sectionStats );
8538 0 : }
8539 :
8540 0 : virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
8541 0 : for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8542 : it != itEnd;
8543 : ++it )
8544 0 : (*it)->testCaseEnded( testCaseStats );
8545 0 : }
8546 :
8547 0 : virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
8548 0 : for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8549 : it != itEnd;
8550 : ++it )
8551 0 : (*it)->testGroupEnded( testGroupStats );
8552 0 : }
8553 :
8554 0 : virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
8555 0 : for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8556 : it != itEnd;
8557 : ++it )
8558 0 : (*it)->testRunEnded( testRunStats );
8559 0 : }
8560 :
8561 0 : virtual void skipTest( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
8562 0 : for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end();
8563 : it != itEnd;
8564 : ++it )
8565 0 : (*it)->skipTest( testInfo );
8566 0 : }
8567 :
8568 0 : virtual MultipleReporters* tryAsMulti() CATCH_OVERRIDE {
8569 0 : return this;
8570 : }
8571 :
8572 : };
8573 :
8574 1 : Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter ) {
8575 1 : Ptr<IStreamingReporter> resultingReporter;
8576 :
8577 1 : if( existingReporter ) {
8578 0 : MultipleReporters* multi = existingReporter->tryAsMulti();
8579 0 : if( !multi ) {
8580 0 : multi = new MultipleReporters;
8581 0 : resultingReporter = Ptr<IStreamingReporter>( multi );
8582 0 : if( existingReporter )
8583 0 : multi->add( existingReporter );
8584 : }
8585 : else
8586 0 : resultingReporter = existingReporter;
8587 0 : multi->add( additionalReporter );
8588 : }
8589 : else
8590 1 : resultingReporter = additionalReporter;
8591 :
8592 1 : return resultingReporter;
8593 : }
8594 :
8595 : } // end namespace Catch
8596 :
8597 : // #included from: ../reporters/catch_reporter_xml.hpp
8598 : #define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED
8599 :
8600 : // #included from: catch_reporter_bases.hpp
8601 : #define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED
8602 :
8603 : #include <cstring>
8604 :
8605 : namespace Catch {
8606 :
8607 : struct StreamingReporterBase : SharedImpl<IStreamingReporter> {
8608 :
8609 1 : StreamingReporterBase( ReporterConfig const& _config )
8610 : : m_config( _config.fullConfig() ),
8611 1 : stream( _config.stream() )
8612 : {
8613 1 : m_reporterPrefs.shouldRedirectStdOut = false;
8614 1 : }
8615 :
8616 68 : virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
8617 68 : return m_reporterPrefs;
8618 : }
8619 :
8620 : virtual ~StreamingReporterBase() CATCH_OVERRIDE;
8621 :
8622 0 : virtual void noMatchingTestCases( std::string const& ) CATCH_OVERRIDE {}
8623 :
8624 1 : virtual void testRunStarting( TestRunInfo const& _testRunInfo ) CATCH_OVERRIDE {
8625 1 : currentTestRunInfo = _testRunInfo;
8626 1 : }
8627 1 : virtual void testGroupStarting( GroupInfo const& _groupInfo ) CATCH_OVERRIDE {
8628 1 : currentGroupInfo = _groupInfo;
8629 1 : }
8630 :
8631 31 : virtual void testCaseStarting( TestCaseInfo const& _testInfo ) CATCH_OVERRIDE {
8632 31 : currentTestCaseInfo = _testInfo;
8633 31 : }
8634 115 : virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE {
8635 115 : m_sectionStack.push_back( _sectionInfo );
8636 115 : }
8637 :
8638 115 : virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) CATCH_OVERRIDE {
8639 115 : m_sectionStack.pop_back();
8640 115 : }
8641 31 : virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) CATCH_OVERRIDE {
8642 31 : currentTestCaseInfo.reset();
8643 31 : }
8644 1 : virtual void testGroupEnded( TestGroupStats const& /* _testGroupStats */ ) CATCH_OVERRIDE {
8645 1 : currentGroupInfo.reset();
8646 1 : }
8647 1 : virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) CATCH_OVERRIDE {
8648 1 : currentTestCaseInfo.reset();
8649 1 : currentGroupInfo.reset();
8650 1 : currentTestRunInfo.reset();
8651 1 : }
8652 :
8653 0 : virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {
8654 : // Don't do anything with this by default.
8655 : // It can optionally be overridden in the derived class.
8656 0 : }
8657 :
8658 : Ptr<IConfig const> m_config;
8659 : std::ostream& stream;
8660 :
8661 : LazyStat<TestRunInfo> currentTestRunInfo;
8662 : LazyStat<GroupInfo> currentGroupInfo;
8663 : LazyStat<TestCaseInfo> currentTestCaseInfo;
8664 :
8665 : std::vector<SectionInfo> m_sectionStack;
8666 : ReporterPreferences m_reporterPrefs;
8667 : };
8668 :
8669 : struct CumulativeReporterBase : SharedImpl<IStreamingReporter> {
8670 : template<typename T, typename ChildNodeT>
8671 : struct Node : SharedImpl<> {
8672 0 : explicit Node( T const& _value ) : value( _value ) {}
8673 0 : virtual ~Node() {}
8674 :
8675 : typedef std::vector<Ptr<ChildNodeT> > ChildNodes;
8676 : T value;
8677 : ChildNodes children;
8678 : };
8679 : struct SectionNode : SharedImpl<> {
8680 0 : explicit SectionNode( SectionStats const& _stats ) : stats( _stats ) {}
8681 : virtual ~SectionNode();
8682 :
8683 : bool operator == ( SectionNode const& other ) const {
8684 : return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo;
8685 : }
8686 : bool operator == ( Ptr<SectionNode> const& other ) const {
8687 : return operator==( *other );
8688 : }
8689 :
8690 : SectionStats stats;
8691 : typedef std::vector<Ptr<SectionNode> > ChildSections;
8692 : typedef std::vector<AssertionStats> Assertions;
8693 : ChildSections childSections;
8694 : Assertions assertions;
8695 : std::string stdOut;
8696 : std::string stdErr;
8697 : };
8698 :
8699 : struct BySectionInfo {
8700 0 : BySectionInfo( SectionInfo const& other ) : m_other( other ) {}
8701 0 : BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {}
8702 0 : bool operator() ( Ptr<SectionNode> const& node ) const {
8703 0 : return node->stats.sectionInfo.lineInfo == m_other.lineInfo;
8704 : }
8705 : private:
8706 : void operator=( BySectionInfo const& );
8707 : SectionInfo const& m_other;
8708 : };
8709 :
8710 : typedef Node<TestCaseStats, SectionNode> TestCaseNode;
8711 : typedef Node<TestGroupStats, TestCaseNode> TestGroupNode;
8712 : typedef Node<TestRunStats, TestGroupNode> TestRunNode;
8713 :
8714 0 : CumulativeReporterBase( ReporterConfig const& _config )
8715 : : m_config( _config.fullConfig() ),
8716 0 : stream( _config.stream() )
8717 : {
8718 0 : m_reporterPrefs.shouldRedirectStdOut = false;
8719 0 : }
8720 : ~CumulativeReporterBase();
8721 :
8722 0 : virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE {
8723 0 : return m_reporterPrefs;
8724 : }
8725 :
8726 0 : virtual void testRunStarting( TestRunInfo const& ) CATCH_OVERRIDE {}
8727 0 : virtual void testGroupStarting( GroupInfo const& ) CATCH_OVERRIDE {}
8728 :
8729 0 : virtual void testCaseStarting( TestCaseInfo const& ) CATCH_OVERRIDE {}
8730 :
8731 0 : virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
8732 0 : SectionStats incompleteStats( sectionInfo, Counts(), 0, false );
8733 0 : Ptr<SectionNode> node;
8734 0 : if( m_sectionStack.empty() ) {
8735 0 : if( !m_rootSection )
8736 0 : m_rootSection = new SectionNode( incompleteStats );
8737 0 : node = m_rootSection;
8738 : }
8739 : else {
8740 0 : SectionNode& parentNode = *m_sectionStack.back();
8741 : SectionNode::ChildSections::const_iterator it =
8742 : std::find_if( parentNode.childSections.begin(),
8743 : parentNode.childSections.end(),
8744 0 : BySectionInfo( sectionInfo ) );
8745 0 : if( it == parentNode.childSections.end() ) {
8746 0 : node = new SectionNode( incompleteStats );
8747 0 : parentNode.childSections.push_back( node );
8748 : }
8749 : else
8750 0 : node = *it;
8751 : }
8752 0 : m_sectionStack.push_back( node );
8753 0 : m_deepestSection = node;
8754 0 : }
8755 :
8756 0 : virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {}
8757 :
8758 0 : virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
8759 0 : assert( !m_sectionStack.empty() );
8760 0 : SectionNode& sectionNode = *m_sectionStack.back();
8761 0 : sectionNode.assertions.push_back( assertionStats );
8762 0 : return true;
8763 : }
8764 0 : virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
8765 0 : assert( !m_sectionStack.empty() );
8766 0 : SectionNode& node = *m_sectionStack.back();
8767 0 : node.stats = sectionStats;
8768 0 : m_sectionStack.pop_back();
8769 0 : }
8770 0 : virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
8771 0 : Ptr<TestCaseNode> node = new TestCaseNode( testCaseStats );
8772 0 : assert( m_sectionStack.size() == 0 );
8773 0 : node->children.push_back( m_rootSection );
8774 0 : m_testCases.push_back( node );
8775 0 : m_rootSection.reset();
8776 :
8777 0 : assert( m_deepestSection );
8778 0 : m_deepestSection->stdOut = testCaseStats.stdOut;
8779 0 : m_deepestSection->stdErr = testCaseStats.stdErr;
8780 0 : }
8781 0 : virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
8782 0 : Ptr<TestGroupNode> node = new TestGroupNode( testGroupStats );
8783 0 : node->children.swap( m_testCases );
8784 0 : m_testGroups.push_back( node );
8785 0 : }
8786 0 : virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
8787 0 : Ptr<TestRunNode> node = new TestRunNode( testRunStats );
8788 0 : node->children.swap( m_testGroups );
8789 0 : m_testRuns.push_back( node );
8790 0 : testRunEndedCumulative();
8791 0 : }
8792 : virtual void testRunEndedCumulative() = 0;
8793 :
8794 0 : virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {}
8795 :
8796 : Ptr<IConfig const> m_config;
8797 : std::ostream& stream;
8798 : std::vector<AssertionStats> m_assertions;
8799 : std::vector<std::vector<Ptr<SectionNode> > > m_sections;
8800 : std::vector<Ptr<TestCaseNode> > m_testCases;
8801 : std::vector<Ptr<TestGroupNode> > m_testGroups;
8802 :
8803 : std::vector<Ptr<TestRunNode> > m_testRuns;
8804 :
8805 : Ptr<SectionNode> m_rootSection;
8806 : Ptr<SectionNode> m_deepestSection;
8807 : std::vector<Ptr<SectionNode> > m_sectionStack;
8808 : ReporterPreferences m_reporterPrefs;
8809 :
8810 : };
8811 :
8812 : template<char C>
8813 0 : char const* getLineOfChars() {
8814 : static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0};
8815 0 : if( !*line ) {
8816 0 : memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
8817 0 : line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0;
8818 : }
8819 0 : return line;
8820 : }
8821 :
8822 : struct TestEventListenerBase : StreamingReporterBase {
8823 : TestEventListenerBase( ReporterConfig const& _config )
8824 : : StreamingReporterBase( _config )
8825 : {}
8826 :
8827 : virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {}
8828 : virtual bool assertionEnded( AssertionStats const& ) CATCH_OVERRIDE {
8829 : return false;
8830 : }
8831 : };
8832 :
8833 : } // end namespace Catch
8834 :
8835 : // #included from: ../internal/catch_reporter_registrars.hpp
8836 : #define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
8837 :
8838 : namespace Catch {
8839 :
8840 : template<typename T>
8841 : class LegacyReporterRegistrar {
8842 :
8843 : class ReporterFactory : public IReporterFactory {
8844 : virtual IStreamingReporter* create( ReporterConfig const& config ) const {
8845 : return new LegacyReporterAdapter( new T( config ) );
8846 : }
8847 :
8848 : virtual std::string getDescription() const {
8849 : return T::getDescription();
8850 : }
8851 : };
8852 :
8853 : public:
8854 :
8855 : LegacyReporterRegistrar( std::string const& name ) {
8856 : getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
8857 : }
8858 : };
8859 :
8860 : template<typename T>
8861 : class ReporterRegistrar {
8862 :
8863 12 : class ReporterFactory : public SharedImpl<IReporterFactory> {
8864 :
8865 : // *** Please Note ***:
8866 : // - If you end up here looking at a compiler error because it's trying to register
8867 : // your custom reporter class be aware that the native reporter interface has changed
8868 : // to IStreamingReporter. The "legacy" interface, IReporter, is still supported via
8869 : // an adapter. Just use REGISTER_LEGACY_REPORTER to take advantage of the adapter.
8870 : // However please consider updating to the new interface as the old one is now
8871 : // deprecated and will probably be removed quite soon!
8872 : // Please contact me via github if you have any questions at all about this.
8873 : // In fact, ideally, please contact me anyway to let me know you've hit this - as I have
8874 : // no idea who is actually using custom reporters at all (possibly no-one!).
8875 : // The new interface is designed to minimise exposure to interface changes in the future.
8876 1 : virtual IStreamingReporter* create( ReporterConfig const& config ) const {
8877 1 : return new T( config );
8878 : }
8879 :
8880 0 : virtual std::string getDescription() const {
8881 0 : return T::getDescription();
8882 : }
8883 : };
8884 :
8885 : public:
8886 :
8887 4 : ReporterRegistrar( std::string const& name ) {
8888 4 : getMutableRegistryHub().registerReporter( name, new ReporterFactory() );
8889 4 : }
8890 : };
8891 :
8892 : template<typename T>
8893 : class ListenerRegistrar {
8894 :
8895 : class ListenerFactory : public SharedImpl<IReporterFactory> {
8896 :
8897 : virtual IStreamingReporter* create( ReporterConfig const& config ) const {
8898 : return new T( config );
8899 : }
8900 : virtual std::string getDescription() const {
8901 : return "";
8902 : }
8903 : };
8904 :
8905 : public:
8906 :
8907 : ListenerRegistrar() {
8908 : getMutableRegistryHub().registerListener( new ListenerFactory() );
8909 : }
8910 : };
8911 : }
8912 :
8913 : #define INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) \
8914 : namespace{ Catch::LegacyReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
8915 :
8916 : #define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \
8917 : namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
8918 :
8919 : #define INTERNAL_CATCH_REGISTER_LISTENER( listenerType ) \
8920 : namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; }
8921 :
8922 : // #included from: ../internal/catch_xmlwriter.hpp
8923 : #define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED
8924 :
8925 : #include <sstream>
8926 : #include <string>
8927 : #include <vector>
8928 : #include <iomanip>
8929 :
8930 : namespace Catch {
8931 :
8932 0 : class XmlEncode {
8933 : public:
8934 : enum ForWhat { ForTextNodes, ForAttributes };
8935 :
8936 0 : XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes )
8937 : : m_str( str ),
8938 0 : m_forWhat( forWhat )
8939 0 : {}
8940 :
8941 0 : void encodeTo( std::ostream& os ) const {
8942 :
8943 : // Apostrophe escaping not necessary if we always use " to write attributes
8944 : // (see: http://www.w3.org/TR/xml/#syntax)
8945 :
8946 0 : for( std::size_t i = 0; i < m_str.size(); ++ i ) {
8947 0 : char c = m_str[i];
8948 0 : switch( c ) {
8949 0 : case '<': os << "<"; break;
8950 0 : case '&': os << "&"; break;
8951 :
8952 : case '>':
8953 : // See: http://www.w3.org/TR/xml/#syntax
8954 0 : if( i > 2 && m_str[i-1] == ']' && m_str[i-2] == ']' )
8955 0 : os << ">";
8956 : else
8957 0 : os << c;
8958 0 : break;
8959 :
8960 : case '\"':
8961 0 : if( m_forWhat == ForAttributes )
8962 0 : os << """;
8963 : else
8964 0 : os << c;
8965 0 : break;
8966 :
8967 : default:
8968 : // Escape control chars - based on contribution by @espenalb in PR #465 and
8969 : // by @mrpi PR #588
8970 0 : if ( ( c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' )
8971 0 : os << "&#x" << std::uppercase << std::hex << std::setfill('0') << std::setw(2) << static_cast<int>( c ) << ';';
8972 : else
8973 0 : os << c;
8974 : }
8975 : }
8976 0 : }
8977 :
8978 0 : friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) {
8979 0 : xmlEncode.encodeTo( os );
8980 0 : return os;
8981 : }
8982 :
8983 : private:
8984 : std::string m_str;
8985 : ForWhat m_forWhat;
8986 : };
8987 :
8988 : class XmlWriter {
8989 : public:
8990 :
8991 : class ScopedElement {
8992 : public:
8993 0 : ScopedElement( XmlWriter* writer )
8994 0 : : m_writer( writer )
8995 0 : {}
8996 :
8997 : ScopedElement( ScopedElement const& other )
8998 : : m_writer( other.m_writer ){
8999 : other.m_writer = CATCH_NULL;
9000 : }
9001 :
9002 0 : ~ScopedElement() {
9003 0 : if( m_writer )
9004 0 : m_writer->endElement();
9005 0 : }
9006 :
9007 0 : ScopedElement& writeText( std::string const& text, bool indent = true ) {
9008 0 : m_writer->writeText( text, indent );
9009 0 : return *this;
9010 : }
9011 :
9012 : template<typename T>
9013 0 : ScopedElement& writeAttribute( std::string const& name, T const& attribute ) {
9014 0 : m_writer->writeAttribute( name, attribute );
9015 0 : return *this;
9016 : }
9017 :
9018 : private:
9019 : mutable XmlWriter* m_writer;
9020 : };
9021 :
9022 : XmlWriter()
9023 : : m_tagIsOpen( false ),
9024 : m_needsNewline( false ),
9025 : m_os( &Catch::cout() )
9026 : {
9027 : // We encode control characters, which requires
9028 : // XML 1.1
9029 : // see http://stackoverflow.com/questions/404107/why-are-control-characters-illegal-in-xml-1-0
9030 : *m_os << "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n";
9031 : }
9032 :
9033 0 : XmlWriter( std::ostream& os )
9034 : : m_tagIsOpen( false ),
9035 : m_needsNewline( false ),
9036 0 : m_os( &os )
9037 : {
9038 0 : *m_os << "<?xml version=\"1.1\" encoding=\"UTF-8\"?>\n";
9039 0 : }
9040 :
9041 0 : ~XmlWriter() {
9042 0 : while( !m_tags.empty() )
9043 0 : endElement();
9044 0 : }
9045 :
9046 0 : XmlWriter& startElement( std::string const& name ) {
9047 0 : ensureTagClosed();
9048 0 : newlineIfNecessary();
9049 0 : stream() << m_indent << "<" << name;
9050 0 : m_tags.push_back( name );
9051 0 : m_indent += " ";
9052 0 : m_tagIsOpen = true;
9053 0 : return *this;
9054 : }
9055 :
9056 0 : ScopedElement scopedElement( std::string const& name ) {
9057 0 : ScopedElement scoped( this );
9058 0 : startElement( name );
9059 0 : return scoped;
9060 : }
9061 :
9062 0 : XmlWriter& endElement() {
9063 0 : newlineIfNecessary();
9064 0 : m_indent = m_indent.substr( 0, m_indent.size()-2 );
9065 0 : if( m_tagIsOpen ) {
9066 0 : stream() << "/>\n";
9067 0 : m_tagIsOpen = false;
9068 : }
9069 : else {
9070 0 : stream() << m_indent << "</" << m_tags.back() << ">\n";
9071 : }
9072 0 : m_tags.pop_back();
9073 0 : return *this;
9074 : }
9075 :
9076 0 : XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ) {
9077 0 : if( !name.empty() && !attribute.empty() )
9078 0 : stream() << " " << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << "\"";
9079 0 : return *this;
9080 : }
9081 :
9082 0 : XmlWriter& writeAttribute( std::string const& name, bool attribute ) {
9083 0 : stream() << " " << name << "=\"" << ( attribute ? "true" : "false" ) << "\"";
9084 0 : return *this;
9085 : }
9086 :
9087 : template<typename T>
9088 0 : XmlWriter& writeAttribute( std::string const& name, T const& attribute ) {
9089 0 : std::ostringstream oss;
9090 0 : oss << attribute;
9091 0 : return writeAttribute( name, oss.str() );
9092 : }
9093 :
9094 0 : XmlWriter& writeText( std::string const& text, bool indent = true ) {
9095 0 : if( !text.empty() ){
9096 0 : bool tagWasOpen = m_tagIsOpen;
9097 0 : ensureTagClosed();
9098 0 : if( tagWasOpen && indent )
9099 0 : stream() << m_indent;
9100 0 : stream() << XmlEncode( text );
9101 0 : m_needsNewline = true;
9102 : }
9103 0 : return *this;
9104 : }
9105 :
9106 : XmlWriter& writeComment( std::string const& text ) {
9107 : ensureTagClosed();
9108 : stream() << m_indent << "<!--" << text << "-->";
9109 : m_needsNewline = true;
9110 : return *this;
9111 : }
9112 :
9113 : XmlWriter& writeBlankLine() {
9114 : ensureTagClosed();
9115 : stream() << "\n";
9116 : return *this;
9117 : }
9118 :
9119 : void setStream( std::ostream& os ) {
9120 : m_os = &os;
9121 : }
9122 :
9123 : private:
9124 : XmlWriter( XmlWriter const& );
9125 : void operator=( XmlWriter const& );
9126 :
9127 0 : std::ostream& stream() {
9128 0 : return *m_os;
9129 : }
9130 :
9131 0 : void ensureTagClosed() {
9132 0 : if( m_tagIsOpen ) {
9133 0 : stream() << ">\n";
9134 0 : m_tagIsOpen = false;
9135 : }
9136 0 : }
9137 :
9138 0 : void newlineIfNecessary() {
9139 0 : if( m_needsNewline ) {
9140 0 : stream() << "\n";
9141 0 : m_needsNewline = false;
9142 : }
9143 0 : }
9144 :
9145 : bool m_tagIsOpen;
9146 : bool m_needsNewline;
9147 : std::vector<std::string> m_tags;
9148 : std::string m_indent;
9149 : std::ostream* m_os;
9150 : };
9151 :
9152 : }
9153 : // #included from: catch_reenable_warnings.h
9154 :
9155 : #define TWOBLUECUBES_CATCH_REENABLE_WARNINGS_H_INCLUDED
9156 :
9157 : #ifdef __clang__
9158 : # ifdef __ICC // icpc defines the __clang__ macro
9159 : # pragma warning(pop)
9160 : # else
9161 : # pragma clang diagnostic pop
9162 : # endif
9163 : #elif defined __GNUC__
9164 : # pragma GCC diagnostic pop
9165 : #endif
9166 :
9167 :
9168 : namespace Catch {
9169 : class XmlReporter : public StreamingReporterBase {
9170 : public:
9171 0 : XmlReporter( ReporterConfig const& _config )
9172 : : StreamingReporterBase( _config ),
9173 0 : m_xml(_config.stream()),
9174 0 : m_sectionDepth( 0 )
9175 : {
9176 0 : m_reporterPrefs.shouldRedirectStdOut = true;
9177 0 : }
9178 :
9179 : virtual ~XmlReporter() CATCH_OVERRIDE;
9180 :
9181 0 : static std::string getDescription() {
9182 0 : return "Reports test results as an XML document";
9183 : }
9184 :
9185 : public: // StreamingReporterBase
9186 :
9187 0 : virtual void noMatchingTestCases( std::string const& s ) CATCH_OVERRIDE {
9188 0 : StreamingReporterBase::noMatchingTestCases( s );
9189 0 : }
9190 :
9191 0 : virtual void testRunStarting( TestRunInfo const& testInfo ) CATCH_OVERRIDE {
9192 0 : StreamingReporterBase::testRunStarting( testInfo );
9193 0 : m_xml.startElement( "Catch" );
9194 0 : if( !m_config->name().empty() )
9195 0 : m_xml.writeAttribute( "name", m_config->name() );
9196 0 : }
9197 :
9198 0 : virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
9199 0 : StreamingReporterBase::testGroupStarting( groupInfo );
9200 0 : m_xml.startElement( "Group" )
9201 0 : .writeAttribute( "name", groupInfo.name );
9202 0 : }
9203 :
9204 0 : virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE {
9205 0 : StreamingReporterBase::testCaseStarting(testInfo);
9206 0 : m_xml.startElement( "TestCase" ).writeAttribute( "name", testInfo.name );
9207 :
9208 0 : if ( m_config->showDurations() == ShowDurations::Always )
9209 0 : m_testCaseTimer.start();
9210 0 : }
9211 :
9212 0 : virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE {
9213 0 : StreamingReporterBase::sectionStarting( sectionInfo );
9214 0 : if( m_sectionDepth++ > 0 ) {
9215 0 : m_xml.startElement( "Section" )
9216 0 : .writeAttribute( "name", trim( sectionInfo.name ) )
9217 0 : .writeAttribute( "description", sectionInfo.description );
9218 : }
9219 0 : }
9220 :
9221 0 : virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE { }
9222 :
9223 0 : virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
9224 0 : const AssertionResult& assertionResult = assertionStats.assertionResult;
9225 :
9226 : // Print any info messages in <Info> tags.
9227 0 : if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
9228 0 : for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
9229 : it != itEnd;
9230 : ++it ) {
9231 0 : if( it->type == ResultWas::Info ) {
9232 : m_xml.scopedElement( "Info" )
9233 0 : .writeText( it->message );
9234 0 : } else if ( it->type == ResultWas::Warning ) {
9235 : m_xml.scopedElement( "Warning" )
9236 0 : .writeText( it->message );
9237 : }
9238 : }
9239 : }
9240 :
9241 : // Drop out if result was successful but we're not printing them.
9242 0 : if( !m_config->includeSuccessfulResults() && isOk(assertionResult.getResultType()) )
9243 0 : return true;
9244 :
9245 : // Print the expression if there is one.
9246 0 : if( assertionResult.hasExpression() ) {
9247 0 : m_xml.startElement( "Expression" )
9248 0 : .writeAttribute( "success", assertionResult.succeeded() )
9249 0 : .writeAttribute( "type", assertionResult.getTestMacroName() )
9250 0 : .writeAttribute( "filename", assertionResult.getSourceInfo().file )
9251 0 : .writeAttribute( "line", assertionResult.getSourceInfo().line );
9252 :
9253 : m_xml.scopedElement( "Original" )
9254 0 : .writeText( assertionResult.getExpression() );
9255 : m_xml.scopedElement( "Expanded" )
9256 0 : .writeText( assertionResult.getExpandedExpression() );
9257 : }
9258 :
9259 : // And... Print a result applicable to each result type.
9260 0 : switch( assertionResult.getResultType() ) {
9261 : case ResultWas::ThrewException:
9262 : m_xml.scopedElement( "Exception" )
9263 0 : .writeAttribute( "filename", assertionResult.getSourceInfo().file )
9264 0 : .writeAttribute( "line", assertionResult.getSourceInfo().line )
9265 0 : .writeText( assertionResult.getMessage() );
9266 0 : break;
9267 : case ResultWas::FatalErrorCondition:
9268 : m_xml.scopedElement( "FatalErrorCondition" )
9269 0 : .writeAttribute( "filename", assertionResult.getSourceInfo().file )
9270 0 : .writeAttribute( "line", assertionResult.getSourceInfo().line )
9271 0 : .writeText( assertionResult.getMessage() );
9272 0 : break;
9273 : case ResultWas::Info:
9274 : m_xml.scopedElement( "Info" )
9275 0 : .writeText( assertionResult.getMessage() );
9276 0 : break;
9277 : case ResultWas::Warning:
9278 : // Warning will already have been written
9279 0 : break;
9280 : case ResultWas::ExplicitFailure:
9281 : m_xml.scopedElement( "Failure" )
9282 0 : .writeText( assertionResult.getMessage() );
9283 0 : break;
9284 : default:
9285 0 : break;
9286 : }
9287 :
9288 0 : if( assertionResult.hasExpression() )
9289 0 : m_xml.endElement();
9290 :
9291 0 : return true;
9292 : }
9293 :
9294 0 : virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE {
9295 0 : StreamingReporterBase::sectionEnded( sectionStats );
9296 0 : if( --m_sectionDepth > 0 ) {
9297 0 : XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" );
9298 0 : e.writeAttribute( "successes", sectionStats.assertions.passed );
9299 0 : e.writeAttribute( "failures", sectionStats.assertions.failed );
9300 0 : e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk );
9301 :
9302 0 : if ( m_config->showDurations() == ShowDurations::Always )
9303 0 : e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds );
9304 :
9305 0 : m_xml.endElement();
9306 : }
9307 0 : }
9308 :
9309 0 : virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
9310 0 : StreamingReporterBase::testCaseEnded( testCaseStats );
9311 0 : XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" );
9312 0 : e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() );
9313 :
9314 0 : if ( m_config->showDurations() == ShowDurations::Always )
9315 0 : e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() );
9316 :
9317 0 : m_xml.endElement();
9318 0 : }
9319 :
9320 0 : virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
9321 0 : StreamingReporterBase::testGroupEnded( testGroupStats );
9322 : // TODO: Check testGroupStats.aborting and act accordingly.
9323 : m_xml.scopedElement( "OverallResults" )
9324 0 : .writeAttribute( "successes", testGroupStats.totals.assertions.passed )
9325 0 : .writeAttribute( "failures", testGroupStats.totals.assertions.failed )
9326 0 : .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk );
9327 0 : m_xml.endElement();
9328 0 : }
9329 :
9330 0 : virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE {
9331 0 : StreamingReporterBase::testRunEnded( testRunStats );
9332 : m_xml.scopedElement( "OverallResults" )
9333 0 : .writeAttribute( "successes", testRunStats.totals.assertions.passed )
9334 0 : .writeAttribute( "failures", testRunStats.totals.assertions.failed )
9335 0 : .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk );
9336 0 : m_xml.endElement();
9337 0 : }
9338 :
9339 : private:
9340 : Timer m_testCaseTimer;
9341 : XmlWriter m_xml;
9342 : int m_sectionDepth;
9343 : };
9344 :
9345 1 : INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter )
9346 :
9347 : } // end namespace Catch
9348 :
9349 : // #included from: ../reporters/catch_reporter_junit.hpp
9350 : #define TWOBLUECUBES_CATCH_REPORTER_JUNIT_HPP_INCLUDED
9351 :
9352 : #include <assert.h>
9353 :
9354 : namespace Catch {
9355 :
9356 : class JunitReporter : public CumulativeReporterBase {
9357 : public:
9358 0 : JunitReporter( ReporterConfig const& _config )
9359 : : CumulativeReporterBase( _config ),
9360 0 : xml( _config.stream() )
9361 : {
9362 0 : m_reporterPrefs.shouldRedirectStdOut = true;
9363 0 : }
9364 :
9365 : virtual ~JunitReporter() CATCH_OVERRIDE;
9366 :
9367 0 : static std::string getDescription() {
9368 0 : return "Reports test results in an XML format that looks like Ant's junitreport target";
9369 : }
9370 :
9371 0 : virtual void noMatchingTestCases( std::string const& /*spec*/ ) CATCH_OVERRIDE {}
9372 :
9373 0 : virtual void testRunStarting( TestRunInfo const& runInfo ) CATCH_OVERRIDE {
9374 0 : CumulativeReporterBase::testRunStarting( runInfo );
9375 0 : xml.startElement( "testsuites" );
9376 0 : }
9377 :
9378 0 : virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE {
9379 0 : suiteTimer.start();
9380 0 : stdOutForSuite.str("");
9381 0 : stdErrForSuite.str("");
9382 0 : unexpectedExceptions = 0;
9383 0 : CumulativeReporterBase::testGroupStarting( groupInfo );
9384 0 : }
9385 :
9386 0 : virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
9387 0 : if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException )
9388 0 : unexpectedExceptions++;
9389 0 : return CumulativeReporterBase::assertionEnded( assertionStats );
9390 : }
9391 :
9392 0 : virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE {
9393 0 : stdOutForSuite << testCaseStats.stdOut;
9394 0 : stdErrForSuite << testCaseStats.stdErr;
9395 0 : CumulativeReporterBase::testCaseEnded( testCaseStats );
9396 0 : }
9397 :
9398 0 : virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE {
9399 0 : double suiteTime = suiteTimer.getElapsedSeconds();
9400 0 : CumulativeReporterBase::testGroupEnded( testGroupStats );
9401 0 : writeGroup( *m_testGroups.back(), suiteTime );
9402 0 : }
9403 :
9404 0 : virtual void testRunEndedCumulative() CATCH_OVERRIDE {
9405 0 : xml.endElement();
9406 0 : }
9407 :
9408 0 : void writeGroup( TestGroupNode const& groupNode, double suiteTime ) {
9409 0 : XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" );
9410 0 : TestGroupStats const& stats = groupNode.value;
9411 0 : xml.writeAttribute( "name", stats.groupInfo.name );
9412 0 : xml.writeAttribute( "errors", unexpectedExceptions );
9413 0 : xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions );
9414 0 : xml.writeAttribute( "tests", stats.totals.assertions.total() );
9415 0 : xml.writeAttribute( "hostname", "tbd" ); // !TBD
9416 0 : if( m_config->showDurations() == ShowDurations::Never )
9417 0 : xml.writeAttribute( "time", "" );
9418 : else
9419 0 : xml.writeAttribute( "time", suiteTime );
9420 0 : xml.writeAttribute( "timestamp", "tbd" ); // !TBD
9421 :
9422 : // Write test cases
9423 0 : for( TestGroupNode::ChildNodes::const_iterator
9424 0 : it = groupNode.children.begin(), itEnd = groupNode.children.end();
9425 : it != itEnd;
9426 : ++it )
9427 0 : writeTestCase( **it );
9428 :
9429 0 : xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite.str() ), false );
9430 0 : xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false );
9431 0 : }
9432 :
9433 0 : void writeTestCase( TestCaseNode const& testCaseNode ) {
9434 0 : TestCaseStats const& stats = testCaseNode.value;
9435 :
9436 : // All test cases have exactly one section - which represents the
9437 : // test case itself. That section may have 0-n nested sections
9438 0 : assert( testCaseNode.children.size() == 1 );
9439 0 : SectionNode const& rootSection = *testCaseNode.children.front();
9440 :
9441 0 : std::string className = stats.testInfo.className;
9442 :
9443 0 : if( className.empty() ) {
9444 0 : if( rootSection.childSections.empty() )
9445 0 : className = "global";
9446 : }
9447 0 : writeSection( className, "", rootSection );
9448 0 : }
9449 :
9450 0 : void writeSection( std::string const& className,
9451 : std::string const& rootName,
9452 : SectionNode const& sectionNode ) {
9453 0 : std::string name = trim( sectionNode.stats.sectionInfo.name );
9454 0 : if( !rootName.empty() )
9455 0 : name = rootName + "/" + name;
9456 :
9457 0 : if( !sectionNode.assertions.empty() ||
9458 0 : !sectionNode.stdOut.empty() ||
9459 0 : !sectionNode.stdErr.empty() ) {
9460 0 : XmlWriter::ScopedElement e = xml.scopedElement( "testcase" );
9461 0 : if( className.empty() ) {
9462 0 : xml.writeAttribute( "classname", name );
9463 0 : xml.writeAttribute( "name", "root" );
9464 : }
9465 : else {
9466 0 : xml.writeAttribute( "classname", className );
9467 0 : xml.writeAttribute( "name", name );
9468 : }
9469 0 : xml.writeAttribute( "time", Catch::toString( sectionNode.stats.durationInSeconds ) );
9470 :
9471 0 : writeAssertions( sectionNode );
9472 :
9473 0 : if( !sectionNode.stdOut.empty() )
9474 0 : xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false );
9475 0 : if( !sectionNode.stdErr.empty() )
9476 0 : xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false );
9477 : }
9478 0 : for( SectionNode::ChildSections::const_iterator
9479 0 : it = sectionNode.childSections.begin(),
9480 0 : itEnd = sectionNode.childSections.end();
9481 : it != itEnd;
9482 : ++it )
9483 0 : if( className.empty() )
9484 0 : writeSection( name, "", **it );
9485 : else
9486 0 : writeSection( className, name, **it );
9487 0 : }
9488 :
9489 0 : void writeAssertions( SectionNode const& sectionNode ) {
9490 0 : for( SectionNode::Assertions::const_iterator
9491 0 : it = sectionNode.assertions.begin(), itEnd = sectionNode.assertions.end();
9492 : it != itEnd;
9493 : ++it )
9494 0 : writeAssertion( *it );
9495 0 : }
9496 0 : void writeAssertion( AssertionStats const& stats ) {
9497 0 : AssertionResult const& result = stats.assertionResult;
9498 0 : if( !result.isOk() ) {
9499 0 : std::string elementName;
9500 0 : switch( result.getResultType() ) {
9501 : case ResultWas::ThrewException:
9502 : case ResultWas::FatalErrorCondition:
9503 0 : elementName = "error";
9504 0 : break;
9505 : case ResultWas::ExplicitFailure:
9506 0 : elementName = "failure";
9507 0 : break;
9508 : case ResultWas::ExpressionFailed:
9509 0 : elementName = "failure";
9510 0 : break;
9511 : case ResultWas::DidntThrowException:
9512 0 : elementName = "failure";
9513 0 : break;
9514 :
9515 : // We should never see these here:
9516 : case ResultWas::Info:
9517 : case ResultWas::Warning:
9518 : case ResultWas::Ok:
9519 : case ResultWas::Unknown:
9520 : case ResultWas::FailureBit:
9521 : case ResultWas::Exception:
9522 0 : elementName = "internalError";
9523 0 : break;
9524 : }
9525 :
9526 0 : XmlWriter::ScopedElement e = xml.scopedElement( elementName );
9527 :
9528 0 : xml.writeAttribute( "message", result.getExpandedExpression() );
9529 0 : xml.writeAttribute( "type", result.getTestMacroName() );
9530 :
9531 0 : std::ostringstream oss;
9532 0 : if( !result.getMessage().empty() )
9533 0 : oss << result.getMessage() << "\n";
9534 0 : for( std::vector<MessageInfo>::const_iterator
9535 0 : it = stats.infoMessages.begin(),
9536 0 : itEnd = stats.infoMessages.end();
9537 : it != itEnd;
9538 : ++it )
9539 0 : if( it->type == ResultWas::Info )
9540 0 : oss << it->message << "\n";
9541 :
9542 0 : oss << "at " << result.getSourceInfo();
9543 0 : xml.writeText( oss.str(), false );
9544 : }
9545 0 : }
9546 :
9547 : XmlWriter xml;
9548 : Timer suiteTimer;
9549 : std::ostringstream stdOutForSuite;
9550 : std::ostringstream stdErrForSuite;
9551 : unsigned int unexpectedExceptions;
9552 : };
9553 :
9554 1 : INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter )
9555 :
9556 : } // end namespace Catch
9557 :
9558 : // #included from: ../reporters/catch_reporter_console.hpp
9559 : #define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_HPP_INCLUDED
9560 :
9561 : namespace Catch {
9562 :
9563 : struct ConsoleReporter : StreamingReporterBase {
9564 1 : ConsoleReporter( ReporterConfig const& _config )
9565 : : StreamingReporterBase( _config ),
9566 1 : m_headerPrinted( false )
9567 1 : {}
9568 :
9569 : virtual ~ConsoleReporter() CATCH_OVERRIDE;
9570 0 : static std::string getDescription() {
9571 0 : return "Reports test results as plain lines of text";
9572 : }
9573 :
9574 0 : virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE {
9575 0 : stream << "No test cases matched '" << spec << "'" << std::endl;
9576 0 : }
9577 :
9578 0 : virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {
9579 0 : }
9580 :
9581 2571 : virtual bool assertionEnded( AssertionStats const& _assertionStats ) CATCH_OVERRIDE {
9582 2571 : AssertionResult const& result = _assertionStats.assertionResult;
9583 :
9584 2571 : bool printInfoMessages = true;
9585 :
9586 : // Drop out if result was successful and we're not printing those
9587 2571 : if( !m_config->includeSuccessfulResults() && result.isOk() ) {
9588 2571 : if( result.getResultType() != ResultWas::Warning )
9589 2571 : return false;
9590 0 : printInfoMessages = false;
9591 : }
9592 :
9593 0 : lazyPrint();
9594 :
9595 0 : AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
9596 0 : printer.print();
9597 0 : stream << std::endl;
9598 0 : return true;
9599 : }
9600 :
9601 115 : virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE {
9602 115 : m_headerPrinted = false;
9603 115 : StreamingReporterBase::sectionStarting( _sectionInfo );
9604 115 : }
9605 115 : virtual void sectionEnded( SectionStats const& _sectionStats ) CATCH_OVERRIDE {
9606 115 : if( _sectionStats.missingAssertions ) {
9607 0 : lazyPrint();
9608 0 : Colour colour( Colour::ResultError );
9609 0 : if( m_sectionStack.size() > 1 )
9610 0 : stream << "\nNo assertions in section";
9611 : else
9612 0 : stream << "\nNo assertions in test case";
9613 0 : stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
9614 : }
9615 115 : if( m_headerPrinted ) {
9616 0 : if( m_config->showDurations() == ShowDurations::Always )
9617 0 : stream << "Completed in " << _sectionStats.durationInSeconds << "s" << std::endl;
9618 0 : m_headerPrinted = false;
9619 : }
9620 : else {
9621 115 : if( m_config->showDurations() == ShowDurations::Always )
9622 0 : stream << _sectionStats.sectionInfo.name << " completed in " << _sectionStats.durationInSeconds << "s" << std::endl;
9623 : }
9624 115 : StreamingReporterBase::sectionEnded( _sectionStats );
9625 115 : }
9626 :
9627 31 : virtual void testCaseEnded( TestCaseStats const& _testCaseStats ) CATCH_OVERRIDE {
9628 31 : StreamingReporterBase::testCaseEnded( _testCaseStats );
9629 31 : m_headerPrinted = false;
9630 31 : }
9631 1 : virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) CATCH_OVERRIDE {
9632 1 : if( currentGroupInfo.used ) {
9633 0 : printSummaryDivider();
9634 0 : stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n";
9635 0 : printTotals( _testGroupStats.totals );
9636 0 : stream << "\n" << std::endl;
9637 : }
9638 1 : StreamingReporterBase::testGroupEnded( _testGroupStats );
9639 1 : }
9640 1 : virtual void testRunEnded( TestRunStats const& _testRunStats ) CATCH_OVERRIDE {
9641 1 : printTotalsDivider( _testRunStats.totals );
9642 1 : printTotals( _testRunStats.totals );
9643 1 : stream << std::endl;
9644 1 : StreamingReporterBase::testRunEnded( _testRunStats );
9645 1 : }
9646 :
9647 : private:
9648 :
9649 0 : class AssertionPrinter {
9650 : void operator= ( AssertionPrinter const& );
9651 : public:
9652 0 : AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
9653 : : stream( _stream ),
9654 : stats( _stats ),
9655 : result( _stats.assertionResult ),
9656 : colour( Colour::None ),
9657 : message( result.getMessage() ),
9658 : messages( _stats.infoMessages ),
9659 0 : printInfoMessages( _printInfoMessages )
9660 : {
9661 0 : switch( result.getResultType() ) {
9662 : case ResultWas::Ok:
9663 0 : colour = Colour::Success;
9664 0 : passOrFail = "PASSED";
9665 : //if( result.hasMessage() )
9666 0 : if( _stats.infoMessages.size() == 1 )
9667 0 : messageLabel = "with message";
9668 0 : if( _stats.infoMessages.size() > 1 )
9669 0 : messageLabel = "with messages";
9670 0 : break;
9671 : case ResultWas::ExpressionFailed:
9672 0 : if( result.isOk() ) {
9673 0 : colour = Colour::Success;
9674 0 : passOrFail = "FAILED - but was ok";
9675 : }
9676 : else {
9677 0 : colour = Colour::Error;
9678 0 : passOrFail = "FAILED";
9679 : }
9680 0 : if( _stats.infoMessages.size() == 1 )
9681 0 : messageLabel = "with message";
9682 0 : if( _stats.infoMessages.size() > 1 )
9683 0 : messageLabel = "with messages";
9684 0 : break;
9685 : case ResultWas::ThrewException:
9686 0 : colour = Colour::Error;
9687 0 : passOrFail = "FAILED";
9688 0 : messageLabel = "due to unexpected exception with message";
9689 0 : break;
9690 : case ResultWas::FatalErrorCondition:
9691 0 : colour = Colour::Error;
9692 0 : passOrFail = "FAILED";
9693 0 : messageLabel = "due to a fatal error condition";
9694 0 : break;
9695 : case ResultWas::DidntThrowException:
9696 0 : colour = Colour::Error;
9697 0 : passOrFail = "FAILED";
9698 0 : messageLabel = "because no exception was thrown where one was expected";
9699 0 : break;
9700 : case ResultWas::Info:
9701 0 : messageLabel = "info";
9702 0 : break;
9703 : case ResultWas::Warning:
9704 0 : messageLabel = "warning";
9705 0 : break;
9706 : case ResultWas::ExplicitFailure:
9707 0 : passOrFail = "FAILED";
9708 0 : colour = Colour::Error;
9709 0 : if( _stats.infoMessages.size() == 1 )
9710 0 : messageLabel = "explicitly with message";
9711 0 : if( _stats.infoMessages.size() > 1 )
9712 0 : messageLabel = "explicitly with messages";
9713 0 : break;
9714 : // These cases are here to prevent compiler warnings
9715 : case ResultWas::Unknown:
9716 : case ResultWas::FailureBit:
9717 : case ResultWas::Exception:
9718 0 : passOrFail = "** internal error **";
9719 0 : colour = Colour::Error;
9720 0 : break;
9721 : }
9722 0 : }
9723 :
9724 0 : void print() const {
9725 0 : printSourceInfo();
9726 0 : if( stats.totals.assertions.total() > 0 ) {
9727 0 : if( result.isOk() )
9728 0 : stream << "\n";
9729 0 : printResultType();
9730 0 : printOriginalExpression();
9731 0 : printReconstructedExpression();
9732 : }
9733 : else {
9734 0 : stream << "\n";
9735 : }
9736 0 : printMessage();
9737 0 : }
9738 :
9739 : private:
9740 0 : void printResultType() const {
9741 0 : if( !passOrFail.empty() ) {
9742 0 : Colour colourGuard( colour );
9743 0 : stream << passOrFail << ":\n";
9744 : }
9745 0 : }
9746 0 : void printOriginalExpression() const {
9747 0 : if( result.hasExpression() ) {
9748 0 : Colour colourGuard( Colour::OriginalExpression );
9749 0 : stream << " ";
9750 0 : stream << result.getExpressionInMacro();
9751 0 : stream << "\n";
9752 : }
9753 0 : }
9754 0 : void printReconstructedExpression() const {
9755 0 : if( result.hasExpandedExpression() ) {
9756 0 : stream << "with expansion:\n";
9757 0 : Colour colourGuard( Colour::ReconstructedExpression );
9758 0 : stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << "\n";
9759 : }
9760 0 : }
9761 0 : void printMessage() const {
9762 0 : if( !messageLabel.empty() )
9763 0 : stream << messageLabel << ":" << "\n";
9764 0 : for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
9765 : it != itEnd;
9766 : ++it ) {
9767 : // If this assertion is a warning ignore any INFO messages
9768 0 : if( printInfoMessages || it->type != ResultWas::Info )
9769 0 : stream << Text( it->message, TextAttributes().setIndent(2) ) << "\n";
9770 : }
9771 0 : }
9772 0 : void printSourceInfo() const {
9773 0 : Colour colourGuard( Colour::FileName );
9774 0 : stream << result.getSourceInfo() << ": ";
9775 0 : }
9776 :
9777 : std::ostream& stream;
9778 : AssertionStats const& stats;
9779 : AssertionResult const& result;
9780 : Colour::Code colour;
9781 : std::string passOrFail;
9782 : std::string messageLabel;
9783 : std::string message;
9784 : std::vector<MessageInfo> messages;
9785 : bool printInfoMessages;
9786 : };
9787 :
9788 0 : void lazyPrint() {
9789 :
9790 0 : if( !currentTestRunInfo.used )
9791 0 : lazyPrintRunInfo();
9792 0 : if( !currentGroupInfo.used )
9793 0 : lazyPrintGroupInfo();
9794 :
9795 0 : if( !m_headerPrinted ) {
9796 0 : printTestCaseAndSectionHeader();
9797 0 : m_headerPrinted = true;
9798 : }
9799 0 : }
9800 0 : void lazyPrintRunInfo() {
9801 0 : stream << "\n" << getLineOfChars<'~'>() << "\n";
9802 0 : Colour colour( Colour::SecondaryText );
9803 0 : stream << currentTestRunInfo->name
9804 0 : << " is a Catch v" << libraryVersion << " host application.\n"
9805 0 : << "Run with -? for options\n\n";
9806 :
9807 0 : if( m_config->rngSeed() != 0 )
9808 0 : stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n";
9809 :
9810 0 : currentTestRunInfo.used = true;
9811 0 : }
9812 0 : void lazyPrintGroupInfo() {
9813 0 : if( !currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1 ) {
9814 0 : printClosedHeader( "Group: " + currentGroupInfo->name );
9815 0 : currentGroupInfo.used = true;
9816 : }
9817 0 : }
9818 0 : void printTestCaseAndSectionHeader() {
9819 0 : assert( !m_sectionStack.empty() );
9820 0 : printOpenHeader( currentTestCaseInfo->name );
9821 :
9822 0 : if( m_sectionStack.size() > 1 ) {
9823 0 : Colour colourGuard( Colour::Headers );
9824 :
9825 : std::vector<SectionInfo>::const_iterator
9826 0 : it = m_sectionStack.begin()+1, // Skip first section (test case)
9827 0 : itEnd = m_sectionStack.end();
9828 0 : for( ; it != itEnd; ++it )
9829 0 : printHeaderString( it->name, 2 );
9830 : }
9831 :
9832 0 : SourceLineInfo lineInfo = m_sectionStack.front().lineInfo;
9833 :
9834 0 : if( !lineInfo.empty() ){
9835 0 : stream << getLineOfChars<'-'>() << "\n";
9836 0 : Colour colourGuard( Colour::FileName );
9837 0 : stream << lineInfo << "\n";
9838 : }
9839 0 : stream << getLineOfChars<'.'>() << "\n" << std::endl;
9840 0 : }
9841 :
9842 0 : void printClosedHeader( std::string const& _name ) {
9843 0 : printOpenHeader( _name );
9844 0 : stream << getLineOfChars<'.'>() << "\n";
9845 0 : }
9846 0 : void printOpenHeader( std::string const& _name ) {
9847 0 : stream << getLineOfChars<'-'>() << "\n";
9848 : {
9849 0 : Colour colourGuard( Colour::Headers );
9850 0 : printHeaderString( _name );
9851 : }
9852 0 : }
9853 :
9854 : // if string has a : in first line will set indent to follow it on
9855 : // subsequent lines
9856 0 : void printHeaderString( std::string const& _string, std::size_t indent = 0 ) {
9857 0 : std::size_t i = _string.find( ": " );
9858 0 : if( i != std::string::npos )
9859 0 : i+=2;
9860 : else
9861 0 : i = 0;
9862 : stream << Text( _string, TextAttributes()
9863 0 : .setIndent( indent+i)
9864 0 : .setInitialIndent( indent ) ) << "\n";
9865 0 : }
9866 :
9867 0 : struct SummaryColumn {
9868 :
9869 0 : SummaryColumn( std::string const& _label, Colour::Code _colour )
9870 : : label( _label ),
9871 0 : colour( _colour )
9872 0 : {}
9873 0 : SummaryColumn addRow( std::size_t count ) {
9874 0 : std::ostringstream oss;
9875 0 : oss << count;
9876 0 : std::string row = oss.str();
9877 0 : for( std::vector<std::string>::iterator it = rows.begin(); it != rows.end(); ++it ) {
9878 0 : while( it->size() < row.size() )
9879 0 : *it = " " + *it;
9880 0 : while( it->size() > row.size() )
9881 0 : row = " " + row;
9882 : }
9883 0 : rows.push_back( row );
9884 0 : return *this;
9885 : }
9886 :
9887 : std::string label;
9888 : Colour::Code colour;
9889 : std::vector<std::string> rows;
9890 :
9891 : };
9892 :
9893 1 : void printTotals( Totals const& totals ) {
9894 1 : if( totals.testCases.total() == 0 ) {
9895 0 : stream << Colour( Colour::Warning ) << "No tests ran\n";
9896 : }
9897 1 : else if( totals.assertions.total() > 0 && totals.testCases.allPassed() ) {
9898 1 : stream << Colour( Colour::ResultSuccess ) << "All tests passed";
9899 1 : stream << " ("
9900 3 : << pluralise( totals.assertions.passed, "assertion" ) << " in "
9901 3 : << pluralise( totals.testCases.passed, "test case" ) << ")"
9902 1 : << "\n";
9903 : }
9904 : else {
9905 :
9906 0 : std::vector<SummaryColumn> columns;
9907 : columns.push_back( SummaryColumn( "", Colour::None )
9908 : .addRow( totals.testCases.total() )
9909 0 : .addRow( totals.assertions.total() ) );
9910 : columns.push_back( SummaryColumn( "passed", Colour::Success )
9911 : .addRow( totals.testCases.passed )
9912 0 : .addRow( totals.assertions.passed ) );
9913 : columns.push_back( SummaryColumn( "failed", Colour::ResultError )
9914 : .addRow( totals.testCases.failed )
9915 0 : .addRow( totals.assertions.failed ) );
9916 : columns.push_back( SummaryColumn( "failed as expected", Colour::ResultExpectedFailure )
9917 : .addRow( totals.testCases.failedButOk )
9918 0 : .addRow( totals.assertions.failedButOk ) );
9919 :
9920 0 : printSummaryRow( "test cases", columns, 0 );
9921 0 : printSummaryRow( "assertions", columns, 1 );
9922 : }
9923 1 : }
9924 0 : void printSummaryRow( std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row ) {
9925 0 : for( std::vector<SummaryColumn>::const_iterator it = cols.begin(); it != cols.end(); ++it ) {
9926 0 : std::string value = it->rows[row];
9927 0 : if( it->label.empty() ) {
9928 0 : stream << label << ": ";
9929 0 : if( value != "0" )
9930 0 : stream << value;
9931 : else
9932 0 : stream << Colour( Colour::Warning ) << "- none -";
9933 : }
9934 0 : else if( value != "0" ) {
9935 0 : stream << Colour( Colour::LightGrey ) << " | ";
9936 0 : stream << Colour( it->colour )
9937 0 : << value << " " << it->label;
9938 : }
9939 0 : }
9940 0 : stream << "\n";
9941 0 : }
9942 :
9943 3 : static std::size_t makeRatio( std::size_t number, std::size_t total ) {
9944 3 : std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0;
9945 3 : return ( ratio == 0 && number > 0 ) ? 1 : ratio;
9946 : }
9947 1 : static std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) {
9948 1 : if( i > j && i > k )
9949 0 : return i;
9950 1 : else if( j > k )
9951 0 : return j;
9952 : else
9953 1 : return k;
9954 : }
9955 :
9956 1 : void printTotalsDivider( Totals const& totals ) {
9957 1 : if( totals.testCases.total() > 0 ) {
9958 1 : std::size_t failedRatio = makeRatio( totals.testCases.failed, totals.testCases.total() );
9959 1 : std::size_t failedButOkRatio = makeRatio( totals.testCases.failedButOk, totals.testCases.total() );
9960 1 : std::size_t passedRatio = makeRatio( totals.testCases.passed, totals.testCases.total() );
9961 2 : while( failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH-1 )
9962 0 : findMax( failedRatio, failedButOkRatio, passedRatio )++;
9963 3 : while( failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH-1 )
9964 1 : findMax( failedRatio, failedButOkRatio, passedRatio )--;
9965 :
9966 1 : stream << Colour( Colour::Error ) << std::string( failedRatio, '=' );
9967 1 : stream << Colour( Colour::ResultExpectedFailure ) << std::string( failedButOkRatio, '=' );
9968 1 : if( totals.testCases.allPassed() )
9969 1 : stream << Colour( Colour::ResultSuccess ) << std::string( passedRatio, '=' );
9970 : else
9971 0 : stream << Colour( Colour::Success ) << std::string( passedRatio, '=' );
9972 : }
9973 : else {
9974 0 : stream << Colour( Colour::Warning ) << std::string( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' );
9975 : }
9976 1 : stream << "\n";
9977 1 : }
9978 0 : void printSummaryDivider() {
9979 0 : stream << getLineOfChars<'-'>() << "\n";
9980 0 : }
9981 :
9982 : private:
9983 : bool m_headerPrinted;
9984 : };
9985 :
9986 1 : INTERNAL_CATCH_REGISTER_REPORTER( "console", ConsoleReporter )
9987 :
9988 : } // end namespace Catch
9989 :
9990 : // #included from: ../reporters/catch_reporter_compact.hpp
9991 : #define TWOBLUECUBES_CATCH_REPORTER_COMPACT_HPP_INCLUDED
9992 :
9993 : namespace Catch {
9994 :
9995 : struct CompactReporter : StreamingReporterBase {
9996 :
9997 0 : CompactReporter( ReporterConfig const& _config )
9998 0 : : StreamingReporterBase( _config )
9999 0 : {}
10000 :
10001 : virtual ~CompactReporter();
10002 :
10003 0 : static std::string getDescription() {
10004 0 : return "Reports test results on a single line, suitable for IDEs";
10005 : }
10006 :
10007 0 : virtual ReporterPreferences getPreferences() const {
10008 0 : ReporterPreferences prefs;
10009 0 : prefs.shouldRedirectStdOut = false;
10010 0 : return prefs;
10011 : }
10012 :
10013 0 : virtual void noMatchingTestCases( std::string const& spec ) {
10014 0 : stream << "No test cases matched '" << spec << "'" << std::endl;
10015 0 : }
10016 :
10017 0 : virtual void assertionStarting( AssertionInfo const& ) {
10018 0 : }
10019 :
10020 0 : virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
10021 0 : AssertionResult const& result = _assertionStats.assertionResult;
10022 :
10023 0 : bool printInfoMessages = true;
10024 :
10025 : // Drop out if result was successful and we're not printing those
10026 0 : if( !m_config->includeSuccessfulResults() && result.isOk() ) {
10027 0 : if( result.getResultType() != ResultWas::Warning )
10028 0 : return false;
10029 0 : printInfoMessages = false;
10030 : }
10031 :
10032 0 : AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
10033 0 : printer.print();
10034 :
10035 0 : stream << std::endl;
10036 0 : return true;
10037 : }
10038 :
10039 0 : virtual void testRunEnded( TestRunStats const& _testRunStats ) {
10040 0 : printTotals( _testRunStats.totals );
10041 0 : stream << "\n" << std::endl;
10042 0 : StreamingReporterBase::testRunEnded( _testRunStats );
10043 0 : }
10044 :
10045 : private:
10046 0 : class AssertionPrinter {
10047 : void operator= ( AssertionPrinter const& );
10048 : public:
10049 0 : AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
10050 : : stream( _stream )
10051 : , stats( _stats )
10052 : , result( _stats.assertionResult )
10053 : , messages( _stats.infoMessages )
10054 0 : , itMessage( _stats.infoMessages.begin() )
10055 0 : , printInfoMessages( _printInfoMessages )
10056 0 : {}
10057 :
10058 0 : void print() {
10059 0 : printSourceInfo();
10060 :
10061 0 : itMessage = messages.begin();
10062 :
10063 0 : switch( result.getResultType() ) {
10064 : case ResultWas::Ok:
10065 0 : printResultType( Colour::ResultSuccess, passedString() );
10066 0 : printOriginalExpression();
10067 0 : printReconstructedExpression();
10068 0 : if ( ! result.hasExpression() )
10069 0 : printRemainingMessages( Colour::None );
10070 : else
10071 0 : printRemainingMessages();
10072 0 : break;
10073 : case ResultWas::ExpressionFailed:
10074 0 : if( result.isOk() )
10075 0 : printResultType( Colour::ResultSuccess, failedString() + std::string( " - but was ok" ) );
10076 : else
10077 0 : printResultType( Colour::Error, failedString() );
10078 0 : printOriginalExpression();
10079 0 : printReconstructedExpression();
10080 0 : printRemainingMessages();
10081 0 : break;
10082 : case ResultWas::ThrewException:
10083 0 : printResultType( Colour::Error, failedString() );
10084 0 : printIssue( "unexpected exception with message:" );
10085 0 : printMessage();
10086 0 : printExpressionWas();
10087 0 : printRemainingMessages();
10088 0 : break;
10089 : case ResultWas::FatalErrorCondition:
10090 0 : printResultType( Colour::Error, failedString() );
10091 0 : printIssue( "fatal error condition with message:" );
10092 0 : printMessage();
10093 0 : printExpressionWas();
10094 0 : printRemainingMessages();
10095 0 : break;
10096 : case ResultWas::DidntThrowException:
10097 0 : printResultType( Colour::Error, failedString() );
10098 0 : printIssue( "expected exception, got none" );
10099 0 : printExpressionWas();
10100 0 : printRemainingMessages();
10101 0 : break;
10102 : case ResultWas::Info:
10103 0 : printResultType( Colour::None, "info" );
10104 0 : printMessage();
10105 0 : printRemainingMessages();
10106 0 : break;
10107 : case ResultWas::Warning:
10108 0 : printResultType( Colour::None, "warning" );
10109 0 : printMessage();
10110 0 : printRemainingMessages();
10111 0 : break;
10112 : case ResultWas::ExplicitFailure:
10113 0 : printResultType( Colour::Error, failedString() );
10114 0 : printIssue( "explicitly" );
10115 0 : printRemainingMessages( Colour::None );
10116 0 : break;
10117 : // These cases are here to prevent compiler warnings
10118 : case ResultWas::Unknown:
10119 : case ResultWas::FailureBit:
10120 : case ResultWas::Exception:
10121 0 : printResultType( Colour::Error, "** internal error **" );
10122 0 : break;
10123 : }
10124 0 : }
10125 :
10126 : private:
10127 : // Colour::LightGrey
10128 :
10129 0 : static Colour::Code dimColour() { return Colour::FileName; }
10130 :
10131 : #ifdef CATCH_PLATFORM_MAC
10132 : static const char* failedString() { return "FAILED"; }
10133 : static const char* passedString() { return "PASSED"; }
10134 : #else
10135 0 : static const char* failedString() { return "failed"; }
10136 0 : static const char* passedString() { return "passed"; }
10137 : #endif
10138 :
10139 0 : void printSourceInfo() const {
10140 0 : Colour colourGuard( Colour::FileName );
10141 0 : stream << result.getSourceInfo() << ":";
10142 0 : }
10143 :
10144 0 : void printResultType( Colour::Code colour, std::string passOrFail ) const {
10145 0 : if( !passOrFail.empty() ) {
10146 : {
10147 0 : Colour colourGuard( colour );
10148 0 : stream << " " << passOrFail;
10149 : }
10150 0 : stream << ":";
10151 : }
10152 0 : }
10153 :
10154 0 : void printIssue( std::string issue ) const {
10155 0 : stream << " " << issue;
10156 0 : }
10157 :
10158 0 : void printExpressionWas() {
10159 0 : if( result.hasExpression() ) {
10160 0 : stream << ";";
10161 : {
10162 0 : Colour colour( dimColour() );
10163 0 : stream << " expression was:";
10164 : }
10165 0 : printOriginalExpression();
10166 : }
10167 0 : }
10168 :
10169 0 : void printOriginalExpression() const {
10170 0 : if( result.hasExpression() ) {
10171 0 : stream << " " << result.getExpression();
10172 : }
10173 0 : }
10174 :
10175 0 : void printReconstructedExpression() const {
10176 0 : if( result.hasExpandedExpression() ) {
10177 : {
10178 0 : Colour colour( dimColour() );
10179 0 : stream << " for: ";
10180 : }
10181 0 : stream << result.getExpandedExpression();
10182 : }
10183 0 : }
10184 :
10185 0 : void printMessage() {
10186 0 : if ( itMessage != messages.end() ) {
10187 0 : stream << " '" << itMessage->message << "'";
10188 0 : ++itMessage;
10189 : }
10190 0 : }
10191 :
10192 0 : void printRemainingMessages( Colour::Code colour = dimColour() ) {
10193 0 : if ( itMessage == messages.end() )
10194 0 : return;
10195 :
10196 : // using messages.end() directly yields compilation error:
10197 0 : std::vector<MessageInfo>::const_iterator itEnd = messages.end();
10198 0 : const std::size_t N = static_cast<std::size_t>( std::distance( itMessage, itEnd ) );
10199 :
10200 : {
10201 0 : Colour colourGuard( colour );
10202 0 : stream << " with " << pluralise( N, "message" ) << ":";
10203 : }
10204 :
10205 0 : for(; itMessage != itEnd; ) {
10206 : // If this assertion is a warning ignore any INFO messages
10207 0 : if( printInfoMessages || itMessage->type != ResultWas::Info ) {
10208 0 : stream << " '" << itMessage->message << "'";
10209 0 : if ( ++itMessage != itEnd ) {
10210 0 : Colour colourGuard( dimColour() );
10211 0 : stream << " and";
10212 : }
10213 : }
10214 : }
10215 : }
10216 :
10217 : private:
10218 : std::ostream& stream;
10219 : AssertionStats const& stats;
10220 : AssertionResult const& result;
10221 : std::vector<MessageInfo> messages;
10222 : std::vector<MessageInfo>::const_iterator itMessage;
10223 : bool printInfoMessages;
10224 : };
10225 :
10226 : // Colour, message variants:
10227 : // - white: No tests ran.
10228 : // - red: Failed [both/all] N test cases, failed [both/all] M assertions.
10229 : // - white: Passed [both/all] N test cases (no assertions).
10230 : // - red: Failed N tests cases, failed M assertions.
10231 : // - green: Passed [both/all] N tests cases with M assertions.
10232 :
10233 0 : std::string bothOrAll( std::size_t count ) const {
10234 0 : return count == 1 ? "" : count == 2 ? "both " : "all " ;
10235 : }
10236 :
10237 0 : void printTotals( const Totals& totals ) const {
10238 0 : if( totals.testCases.total() == 0 ) {
10239 0 : stream << "No tests ran.";
10240 : }
10241 0 : else if( totals.testCases.failed == totals.testCases.total() ) {
10242 0 : Colour colour( Colour::ResultError );
10243 : const std::string qualify_assertions_failed =
10244 0 : totals.assertions.failed == totals.assertions.total() ?
10245 0 : bothOrAll( totals.assertions.failed ) : "";
10246 : stream <<
10247 0 : "Failed " << bothOrAll( totals.testCases.failed )
10248 0 : << pluralise( totals.testCases.failed, "test case" ) << ", "
10249 0 : "failed " << qualify_assertions_failed <<
10250 0 : pluralise( totals.assertions.failed, "assertion" ) << ".";
10251 : }
10252 0 : else if( totals.assertions.total() == 0 ) {
10253 : stream <<
10254 0 : "Passed " << bothOrAll( totals.testCases.total() )
10255 0 : << pluralise( totals.testCases.total(), "test case" )
10256 0 : << " (no assertions).";
10257 : }
10258 0 : else if( totals.assertions.failed ) {
10259 0 : Colour colour( Colour::ResultError );
10260 : stream <<
10261 0 : "Failed " << pluralise( totals.testCases.failed, "test case" ) << ", "
10262 0 : "failed " << pluralise( totals.assertions.failed, "assertion" ) << ".";
10263 : }
10264 : else {
10265 0 : Colour colour( Colour::ResultSuccess );
10266 : stream <<
10267 0 : "Passed " << bothOrAll( totals.testCases.passed )
10268 0 : << pluralise( totals.testCases.passed, "test case" ) <<
10269 0 : " with " << pluralise( totals.assertions.passed, "assertion" ) << ".";
10270 : }
10271 0 : }
10272 : };
10273 :
10274 1 : INTERNAL_CATCH_REGISTER_REPORTER( "compact", CompactReporter )
10275 :
10276 : } // end namespace Catch
10277 :
10278 : namespace Catch {
10279 : // These are all here to avoid warnings about not having any out of line
10280 : // virtual methods
10281 398 : NonCopyable::~NonCopyable() {}
10282 148 : IShared::~IShared() {}
10283 1 : IStream::~IStream() CATCH_NOEXCEPT {}
10284 0 : FileStream::~FileStream() CATCH_NOEXCEPT {}
10285 2 : CoutStream::~CoutStream() CATCH_NOEXCEPT {}
10286 0 : DebugOutStream::~DebugOutStream() CATCH_NOEXCEPT {}
10287 0 : StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {}
10288 1 : IContext::~IContext() {}
10289 1 : IResultCapture::~IResultCapture() {}
10290 31 : ITestCase::~ITestCase() {}
10291 1 : ITestCaseRegistry::~ITestCaseRegistry() {}
10292 1 : IRegistryHub::~IRegistryHub() {}
10293 1 : IMutableRegistryHub::~IMutableRegistryHub() {}
10294 0 : IExceptionTranslator::~IExceptionTranslator() {}
10295 1 : IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {}
10296 0 : IReporter::~IReporter() {}
10297 4 : IReporterFactory::~IReporterFactory() {}
10298 1 : IReporterRegistry::~IReporterRegistry() {}
10299 1 : IStreamingReporter::~IStreamingReporter() {}
10300 2571 : AssertionStats::~AssertionStats() {}
10301 115 : SectionStats::~SectionStats() {}
10302 31 : TestCaseStats::~TestCaseStats() {}
10303 1 : TestGroupStats::~TestGroupStats() {}
10304 1 : TestRunStats::~TestRunStats() {}
10305 0 : CumulativeReporterBase::SectionNode::~SectionNode() {}
10306 0 : CumulativeReporterBase::~CumulativeReporterBase() {}
10307 :
10308 1 : StreamingReporterBase::~StreamingReporterBase() {}
10309 2 : ConsoleReporter::~ConsoleReporter() {}
10310 0 : CompactReporter::~CompactReporter() {}
10311 1 : IRunner::~IRunner() {}
10312 1 : IMutableContext::~IMutableContext() {}
10313 1 : IConfig::~IConfig() {}
10314 0 : XmlReporter::~XmlReporter() {}
10315 0 : JunitReporter::~JunitReporter() {}
10316 1 : TestRegistry::~TestRegistry() {}
10317 62 : FreeFunctionTestCase::~FreeFunctionTestCase() {}
10318 0 : IGeneratorInfo::~IGeneratorInfo() {}
10319 0 : IGeneratorsForTest::~IGeneratorsForTest() {}
10320 0 : WildcardPattern::~WildcardPattern() {}
10321 2 : TestSpec::Pattern::~Pattern() {}
10322 0 : TestSpec::NamePattern::~NamePattern() {}
10323 2 : TestSpec::TagPattern::~TagPattern() {}
10324 2 : TestSpec::ExcludedPattern::~ExcludedPattern() {}
10325 :
10326 0 : Matchers::Impl::StdString::Equals::~Equals() {}
10327 0 : Matchers::Impl::StdString::Contains::~Contains() {}
10328 0 : Matchers::Impl::StdString::StartsWith::~StartsWith() {}
10329 0 : Matchers::Impl::StdString::EndsWith::~EndsWith() {}
10330 :
10331 0 : void Config::dummy() {}
10332 :
10333 : namespace TestCaseTracking {
10334 109 : ITracker::~ITracker() {}
10335 109 : TrackerBase::~TrackerBase() {}
10336 218 : SectionTracker::~SectionTracker() {}
10337 0 : IndexTracker::~IndexTracker() {}
10338 : }
10339 : }
10340 :
10341 : #ifdef __clang__
10342 : #pragma clang diagnostic pop
10343 : #endif
10344 :
10345 : #endif
10346 :
10347 : #ifdef CATCH_CONFIG_MAIN
10348 : // #included from: internal/catch_default_main.hpp
10349 : #define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED
10350 :
10351 : #ifndef __OBJC__
10352 :
10353 : // Standard C/C++ main entry point
10354 1 : int main (int argc, char * argv[]) {
10355 1 : return Catch::Session().run( argc, argv );
10356 : }
10357 :
10358 : #else // __OBJC__
10359 :
10360 : // Objective-C entry point
10361 : int main (int argc, char * const argv[]) {
10362 : #if !CATCH_ARC_ENABLED
10363 : NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
10364 : #endif
10365 :
10366 : Catch::registerTestMethods();
10367 : int result = Catch::Session().run( argc, (char* const*)argv );
10368 :
10369 : #if !CATCH_ARC_ENABLED
10370 : [pool drain];
10371 : #endif
10372 :
10373 : return result;
10374 : }
10375 :
10376 : #endif // __OBJC__
10377 :
10378 : #endif
10379 :
10380 : #ifdef CLARA_CONFIG_MAIN_NOT_DEFINED
10381 : # undef CLARA_CONFIG_MAIN
10382 : #endif
10383 :
10384 : //////
10385 :
10386 : // If this config identifier is defined then all CATCH macros are prefixed with CATCH_
10387 : #ifdef CATCH_CONFIG_PREFIX_ALL
10388 :
10389 : #define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE" )
10390 : #define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, "CATCH_REQUIRE_FALSE" )
10391 :
10392 : #define CATCH_REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "", "CATCH_REQUIRE_THROWS" )
10393 : #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THROWS_AS" )
10394 : #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, matcher, "CATCH_REQUIRE_THROWS_WITH" )
10395 : #define CATCH_REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_NOTHROW" )
10396 :
10397 : #define CATCH_CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK" )
10398 : #define CATCH_CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, "CATCH_CHECK_FALSE" )
10399 : #define CATCH_CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_IF" )
10400 : #define CATCH_CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_ELSE" )
10401 : #define CATCH_CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CATCH_CHECK_NOFAIL" )
10402 :
10403 : #define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS" )
10404 : #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS_AS" )
10405 : #define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, matcher, "CATCH_CHECK_THROWS_WITH" )
10406 : #define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_NOTHROW" )
10407 :
10408 : #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THAT" )
10409 : #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THAT" )
10410 :
10411 : #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" )
10412 : #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "CATCH_WARN", msg )
10413 : #define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" )
10414 : #define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" )
10415 : #define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" )
10416 :
10417 : #ifdef CATCH_CONFIG_VARIADIC_MACROS
10418 : #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
10419 : #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
10420 : #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
10421 : #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
10422 : #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
10423 : #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", __VA_ARGS__ )
10424 : #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", __VA_ARGS__ )
10425 : #else
10426 : #define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
10427 : #define CATCH_TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
10428 : #define CATCH_METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
10429 : #define CATCH_REGISTER_TEST_CASE( function, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( function, name, description )
10430 : #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
10431 : #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", msg )
10432 : #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", msg )
10433 : #endif
10434 : #define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
10435 :
10436 : #define CATCH_REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
10437 : #define CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType )
10438 :
10439 : #define CATCH_GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
10440 :
10441 : // "BDD-style" convenience wrappers
10442 : #ifdef CATCH_CONFIG_VARIADIC_MACROS
10443 : #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
10444 : #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
10445 : #else
10446 : #define CATCH_SCENARIO( name, tags ) CATCH_TEST_CASE( "Scenario: " name, tags )
10447 : #define CATCH_SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
10448 : #endif
10449 : #define CATCH_GIVEN( desc ) CATCH_SECTION( std::string( "Given: ") + desc, "" )
10450 : #define CATCH_WHEN( desc ) CATCH_SECTION( std::string( " When: ") + desc, "" )
10451 : #define CATCH_AND_WHEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" )
10452 : #define CATCH_THEN( desc ) CATCH_SECTION( std::string( " Then: ") + desc, "" )
10453 : #define CATCH_AND_THEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" )
10454 :
10455 : // If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
10456 : #else
10457 :
10458 : #define REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal, "REQUIRE" )
10459 : #define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, "REQUIRE_FALSE" )
10460 :
10461 : #define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "", "REQUIRE_THROWS" )
10462 : #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "REQUIRE_THROWS_AS" )
10463 : #define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, matcher, "REQUIRE_THROWS_WITH" )
10464 : #define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "REQUIRE_NOTHROW" )
10465 :
10466 : #define CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK" )
10467 : #define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, "CHECK_FALSE" )
10468 : #define CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECKED_IF" )
10469 : #define CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECKED_ELSE" )
10470 : #define CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CHECK_NOFAIL" )
10471 :
10472 : #define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "", "CHECK_THROWS" )
10473 : #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THROWS_AS" )
10474 : #define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, matcher, "CHECK_THROWS_WITH" )
10475 : #define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK_NOTHROW" )
10476 :
10477 : #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THAT" )
10478 : #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "REQUIRE_THAT" )
10479 :
10480 : #define INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" )
10481 : #define WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "WARN", msg )
10482 : #define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" )
10483 : #define CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" )
10484 : #define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" )
10485 :
10486 : #ifdef CATCH_CONFIG_VARIADIC_MACROS
10487 : #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
10488 : #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
10489 : #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
10490 : #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
10491 : #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
10492 : #define FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", __VA_ARGS__ )
10493 : #define SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", __VA_ARGS__ )
10494 : #else
10495 : #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
10496 : #define TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
10497 : #define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
10498 : #define REGISTER_TEST_CASE( method, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( method, name, description )
10499 : #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
10500 : #define FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", msg )
10501 : #define SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", msg )
10502 : #endif
10503 : #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
10504 :
10505 : #define REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
10506 : #define REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType )
10507 :
10508 : #define GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
10509 :
10510 : #endif
10511 :
10512 : #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
10513 :
10514 : // "BDD-style" convenience wrappers
10515 : #ifdef CATCH_CONFIG_VARIADIC_MACROS
10516 : #define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
10517 : #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
10518 : #else
10519 : #define SCENARIO( name, tags ) TEST_CASE( "Scenario: " name, tags )
10520 : #define SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
10521 : #endif
10522 : #define GIVEN( desc ) SECTION( std::string(" Given: ") + desc, "" )
10523 : #define WHEN( desc ) SECTION( std::string(" When: ") + desc, "" )
10524 : #define AND_WHEN( desc ) SECTION( std::string("And when: ") + desc, "" )
10525 : #define THEN( desc ) SECTION( std::string(" Then: ") + desc, "" )
10526 : #define AND_THEN( desc ) SECTION( std::string(" And: ") + desc, "" )
10527 :
10528 3 : using Catch::Detail::Approx;
10529 :
10530 : #endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
10531 :
|