annotate include/catch.hpp @ 398:3399bd48cb40

Ajout d'une méthode pour obtenir le nombre de FPS Méthode de capture des trames vidéos plus résistante aux erreur Utilisation d'un dictionnaire pour les fichier de configuration afin de garder le nom des sections
author Jean-Philippe Jodoin <jpjodoin@gmail.com>
date Mon, 29 Jul 2013 13:46:07 -0400
parents f0f800b95765
children c6f497291fd8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
220
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1 /*
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2 * Generated: 2012-06-06 08:05:56.928287
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3 * ----------------------------------------------------------
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4 * This file has been merged from multiple headers. Please don't edit it directly
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
5 * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
6 *
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
7 * Distributed under the Boost Software License, Version 1.0. (See accompanying
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
8 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
9 */
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
10 #ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
11 #define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
12
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
13 // #included from: internal/catch_context.h
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
14
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
15 // #included from: catch_interfaces_reporter.h
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
16
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
17 // #included from: catch_common.h
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
18
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
19 #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
20 #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
21 #define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
22
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
23 #define INTERNAL_CATCH_STRINGIFY2( expr ) #expr
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
24 #define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
25
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
26 #ifdef __GNUC__
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
27 #define ATTRIBUTE_NORETURN __attribute__ ((noreturn))
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
28 #else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
29 #define ATTRIBUTE_NORETURN
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
30 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
31
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
32 #include <sstream>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
33 #include <stdexcept>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
34 #include <algorithm>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
35
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
36 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
37
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
38 class NonCopyable {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
39 NonCopyable( const NonCopyable& );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
40 void operator = ( const NonCopyable& );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
41 protected:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
42 NonCopyable() {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
43 virtual ~NonCopyable() {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
44 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
45
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
46 class SafeBool {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
47 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
48 typedef void (SafeBool::*type)() const;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
49
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
50 static type makeSafe( bool value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
51 return value ? &SafeBool::trueValue : 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
52 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
53 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
54 void trueValue() const {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
55 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
56
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
57 template<typename ContainerT>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
58 inline void deleteAll( ContainerT& container ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
59 typename ContainerT::const_iterator it = container.begin();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
60 typename ContainerT::const_iterator itEnd = container.end();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
61 for(; it != itEnd; ++it )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
62 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
63 delete *it;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
64 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
65 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
66 template<typename AssociativeContainerT>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
67 inline void deleteAllValues( AssociativeContainerT& container ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
68 typename AssociativeContainerT::const_iterator it = container.begin();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
69 typename AssociativeContainerT::const_iterator itEnd = container.end();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
70 for(; it != itEnd; ++it )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
71 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
72 delete it->second;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
73 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
74 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
75
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
76 template<typename ContainerT, typename Function>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
77 inline void forEach( ContainerT& container, Function function ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
78 std::for_each( container.begin(), container.end(), function );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
79 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
80
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
81 template<typename ContainerT, typename Function>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
82 inline void forEach( const ContainerT& container, Function function ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
83 std::for_each( container.begin(), container.end(), function );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
84 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
85
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
86 struct SourceLineInfo {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
87
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
88 SourceLineInfo() : line( 0 ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
89 SourceLineInfo( const std::string& _file, std::size_t _line )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
90 : file( _file ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
91 line( _line )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
92 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
93 SourceLineInfo( const SourceLineInfo& other )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
94 : file( other.file ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
95 line( other.line )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
96 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
97 void swap( SourceLineInfo& other ){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
98 file.swap( other.file );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
99 std::swap( line, other.line );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
100 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
101
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
102 std::string file;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
103 std::size_t line;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
104 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
105
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
106 inline std::ostream& operator << ( std::ostream& os, const SourceLineInfo& info ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
107 #ifndef __GNUG__
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
108 os << info.file << "(" << info.line << "): ";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
109 #else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
110 os << info.file << ":" << info.line << ": ";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
111 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
112 return os;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
113 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
114
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
115 ATTRIBUTE_NORETURN
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
116 inline void throwLogicError( const std::string& message, const std::string& file, std::size_t line ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
117 std::ostringstream oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
118 oss << "Internal Catch error: '" << message << "' at: " << SourceLineInfo( file, line );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
119 throw std::logic_error( oss.str() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
120 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
121 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
122
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
123 #define CATCH_INTERNAL_ERROR( msg ) throwLogicError( msg, __FILE__, __LINE__ );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
124 #define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, __LINE__ )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
125
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
126 // #included from: catch_totals.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
127
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
128 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
129
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
130 struct Counts {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
131 Counts() : passed( 0 ), failed( 0 ) {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
132
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
133 Counts operator - ( const Counts& other ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
134 Counts diff;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
135 diff.passed = passed - other.passed;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
136 diff.failed = failed - other.failed;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
137 return diff;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
138 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
139 Counts& operator += ( const Counts& other ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
140 passed += other.passed;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
141 failed += other.failed;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
142 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
143 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
144
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
145 std::size_t total() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
146 return passed + failed;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
147 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
148
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
149 std::size_t passed;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
150 std::size_t failed;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
151 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
152
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
153 struct Totals {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
154
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
155 Totals operator - ( const Totals& other ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
156 Totals diff;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
157 diff.assertions = assertions - other.assertions;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
158 diff.testCases = testCases - other.testCases;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
159 return diff;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
160 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
161
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
162 Totals delta( const Totals& prevTotals ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
163 Totals diff = *this - prevTotals;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
164 if( diff.assertions.failed > 0 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
165 ++diff.testCases.failed;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
166 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
167 ++diff.testCases.passed;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
168 return diff;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
169 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
170
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
171 Counts assertions;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
172 Counts testCases;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
173 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
174 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
175
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
176 // #included from: catch_ptr.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
177
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
178 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
179
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
180 // An intrusive reference counting smart pointer.
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
181 // T must implement addRef() and release() methods
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
182 // typically implementing the IShared interface
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
183 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
184 class Ptr {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
185 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
186 Ptr() : m_p( NULL ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
187 Ptr( T* p ) : m_p( p ){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
188 m_p->addRef();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
189 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
190 Ptr( const Ptr& other ) : m_p( other.m_p ){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
191 m_p->addRef();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
192 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
193 ~Ptr(){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
194 if( m_p )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
195 m_p->release();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
196 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
197 Ptr& operator = ( T* p ){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
198 Ptr temp( p );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
199 swap( temp );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
200 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
201 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
202 Ptr& operator = ( Ptr& other ){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
203 Ptr temp( other );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
204 swap( temp );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
205 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
206 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
207 void swap( Ptr& other ){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
208 std::swap( m_p, other.m_p );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
209 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
210
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
211 T* get(){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
212 return m_p;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
213 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
214 const T* get() const{
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
215 return m_p;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
216 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
217
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
218 T& operator*(){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
219 return *m_p;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
220 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
221 const T& operator*() const{
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
222 return *m_p;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
223 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
224
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
225 T* operator->(){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
226 return m_p;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
227 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
228 const T* operator->() const{
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
229 return m_p;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
230 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
231
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
232 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
233 T* m_p;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
234 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
235
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
236 struct IShared : NonCopyable {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
237 virtual ~IShared(){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
238 virtual void addRef() = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
239 virtual void release() = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
240 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
241
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
242 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
243 struct SharedImpl : T {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
244
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
245 SharedImpl() : m_rc( 0 ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
246
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
247 virtual void addRef(){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
248 ++m_rc;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
249 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
250 virtual void release(){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
251 if( --m_rc == 0 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
252 delete this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
253 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
254
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
255 int m_rc;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
256 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
257
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
258 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
259
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
260 #include <string>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
261 #include <ostream>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
262 #include <map>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
263
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
264 namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
265 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
266 struct IReporterConfig {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
267 virtual ~IReporterConfig() {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
268 virtual std::ostream& stream () const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
269 virtual bool includeSuccessfulResults () const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
270 virtual std::string getName () const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
271 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
272
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
273 class TestCaseInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
274 class ResultInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
275
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
276 struct IReporter : IShared {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
277 virtual ~IReporter() {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
278 virtual bool shouldRedirectStdout() const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
279 virtual void StartTesting() = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
280 virtual void EndTesting( const Totals& totals ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
281 virtual void StartGroup( const std::string& groupName ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
282 virtual void EndGroup( const std::string& groupName, const Totals& totals ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
283 virtual void StartSection( const std::string& sectionName, const std::string& description ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
284 virtual void EndSection( const std::string& sectionName, const Counts& assertions ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
285 virtual void StartTestCase( const TestCaseInfo& testInfo ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
286 virtual void Aborted() = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
287 virtual void EndTestCase( const TestCaseInfo& testInfo, const Totals& totals, const std::string& stdOut, const std::string& stdErr ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
288 virtual void Result( const ResultInfo& result ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
289 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
290
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
291 struct IReporterFactory {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
292 virtual ~IReporterFactory() {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
293 virtual IReporter* create( const IReporterConfig& config ) const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
294 virtual std::string getDescription() const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
295 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
296
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
297 struct IReporterRegistry {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
298 typedef std::map<std::string, IReporterFactory*> FactoryMap;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
299
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
300 virtual ~IReporterRegistry() {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
301 virtual IReporter* create( const std::string& name, const IReporterConfig& config ) const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
302 virtual void registerReporter( const std::string& name, IReporterFactory* factory ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
303 virtual const FactoryMap& getFactories() const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
304 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
305
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
306 inline std::string trim( const std::string& str ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
307 std::string::size_type start = str.find_first_not_of( "\n\r\t " );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
308 std::string::size_type end = str.find_last_not_of( "\n\r\t " );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
309
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
310 return start != std::string::npos ? str.substr( start, 1+end-start ) : "";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
311 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
312 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
313
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
314 // #included from: catch_interfaces_config.h
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
315
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
316 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
317
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
318 struct IConfig {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
319
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
320 virtual ~IConfig(){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
321
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
322 virtual bool allowThrows() const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
323 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
324 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
325
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
326 #include <memory>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
327 #include <vector>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
328 #include <stdlib.h>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
329
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
330 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
331
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
332 class TestCaseInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
333 struct IResultCapture;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
334 struct ITestCaseRegistry;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
335 struct IRunner;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
336 struct IExceptionTranslatorRegistry;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
337 class GeneratorsForTest;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
338
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
339 class StreamBufBase : public std::streambuf{};
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
340
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
341 struct IContext
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
342 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
343 virtual ~IContext(){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
344
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
345 virtual IResultCapture& getResultCapture() = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
346 virtual IRunner& getRunner() = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
347 virtual IReporterRegistry& getReporterRegistry() = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
348 virtual ITestCaseRegistry& getTestCaseRegistry() = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
349 virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
350 virtual size_t getGeneratorIndex( const std::string& fileInfo, size_t totalSize ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
351 virtual bool advanceGeneratorsForCurrentTest() = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
352 virtual const IConfig* getConfig() const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
353 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
354
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
355 struct IMutableContext : IContext
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
356 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
357 virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
358 virtual void setRunner( IRunner* runner ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
359 virtual void setConfig( const IConfig* config ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
360 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
361
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
362 IContext& getCurrentContext();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
363 IMutableContext& getCurrentMutableContext();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
364
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
365 class Context : public IMutableContext {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
366
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
367 Context();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
368 Context( const Context& );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
369 void operator=( const Context& );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
370
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
371 public: // IContext
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
372 virtual IResultCapture& getResultCapture();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
373 virtual IRunner& getRunner();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
374 virtual IReporterRegistry& getReporterRegistry();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
375 virtual ITestCaseRegistry& getTestCaseRegistry();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
376 virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
377 virtual size_t getGeneratorIndex( const std::string& fileInfo, size_t totalSize );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
378 virtual bool advanceGeneratorsForCurrentTest();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
379 virtual const IConfig* getConfig() const;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
380
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
381 public: // IMutableContext
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
382 virtual void setResultCapture( IResultCapture* resultCapture );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
383 virtual void setRunner( IRunner* runner );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
384 virtual void setConfig( const IConfig* config );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
385
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
386 public: // Statics
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
387 static std::streambuf* createStreamBuf( const std::string& streamName );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
388 static void cleanUp();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
389
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
390 friend IMutableContext& getCurrentMutableContext();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
391
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
392 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
393 GeneratorsForTest* findGeneratorsForCurrentTest();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
394 GeneratorsForTest& getGeneratorsForCurrentTest();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
395
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
396 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
397 std::auto_ptr<IReporterRegistry> m_reporterRegistry;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
398 std::auto_ptr<ITestCaseRegistry> m_testCaseRegistry;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
399 std::auto_ptr<IExceptionTranslatorRegistry> m_exceptionTranslatorRegistry;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
400 IRunner* m_runner;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
401 IResultCapture* m_resultCapture;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
402 const IConfig* m_config;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
403 std::map<std::string, GeneratorsForTest*> m_generatorsByTestName;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
404 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
405 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
406
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
407 // #included from: internal/catch_test_registry.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
408
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
409 // #included from: catch_interfaces_testcase.h
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
410
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
411 #include <vector>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
412
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
413 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
414 struct ITestCase {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
415 virtual ~ITestCase(){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
416 virtual void invoke () const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
417 virtual ITestCase* clone() const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
418 virtual bool operator == ( const ITestCase& other ) const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
419 virtual bool operator < ( const ITestCase& other ) const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
420 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
421
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
422 class TestCaseInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
423
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
424 struct ITestCaseRegistry {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
425 virtual ~ITestCaseRegistry(){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
426 virtual void registerTest( const TestCaseInfo& testInfo ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
427 virtual const std::vector<TestCaseInfo>& getAllTests() const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
428 virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
429 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
430 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
431
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
432 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
433
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
434 template<typename C>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
435 class MethodTestCase : public ITestCase {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
436
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
437 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
438 MethodTestCase( void (C::*method)() ) : m_method( method ) {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
439
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
440 virtual void invoke() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
441 C obj;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
442 (obj.*m_method)();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
443 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
444
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
445 virtual ITestCase* clone() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
446 return new MethodTestCase<C>( m_method );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
447 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
448
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
449 virtual bool operator == ( const ITestCase& other ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
450 const MethodTestCase* mtOther = dynamic_cast<const MethodTestCase*>( &other );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
451 return mtOther && m_method == mtOther->m_method;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
452 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
453
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
454 virtual bool operator < ( const ITestCase& other ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
455 const MethodTestCase* mtOther = dynamic_cast<const MethodTestCase*>( &other );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
456 return mtOther && &m_method < &mtOther->m_method;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
457 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
458
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
459 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
460 void (C::*m_method)();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
461 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
462
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
463 typedef void(*TestFunction)();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
464
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
465 struct AutoReg {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
466
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
467 AutoReg( TestFunction function,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
468 const char* name,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
469 const char* description,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
470 const SourceLineInfo& lineInfo );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
471
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
472 template<typename C>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
473 AutoReg( void (C::*method)(),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
474 const char* name,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
475 const char* description,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
476 const SourceLineInfo& lineInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
477 registerTestCase( new MethodTestCase<C>( method ), name, description, lineInfo );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
478 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
479
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
480 void registerTestCase( ITestCase* testCase,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
481 const char* name,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
482 const char* description,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
483 const SourceLineInfo& lineInfo );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
484
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
485 ~AutoReg();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
486
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
487 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
488 AutoReg( const AutoReg& );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
489 void operator= ( const AutoReg& );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
490 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
491
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
492 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
493
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
494 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
495 #define INTERNAL_CATCH_TESTCASE( Name, Desc ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
496 static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )(); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
497 namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ ), Name, Desc, CATCH_INTERNAL_LINEINFO ); }\
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
498 static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
499
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
500 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
501 #define INTERNAL_CATCH_TESTCASE_NORETURN( Name, Desc ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
502 static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )() ATTRIBUTE_NORETURN; \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
503 namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ ), Name, Desc, CATCH_INTERNAL_LINEINFO ); }\
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
504 static void INTERNAL_CATCH_UNIQUE_NAME( TestCaseFunction_catch_internal_ )()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
505
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
506 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
507 #define CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
508 namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, Name, Desc, CATCH_INTERNAL_LINEINFO ); }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
509
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
510 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
511 #define TEST_CASE_METHOD( ClassName, TestName, Desc )\
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
512 namespace{ \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
513 struct INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ ) : ClassName{ \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
514 void test(); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
515 }; \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
516 Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ )::test, TestName, Desc, CATCH_INTERNAL_LINEINFO ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
517 } \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
518 void INTERNAL_CATCH_UNIQUE_NAME( TestCaseMethod_catch_internal_ )::test()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
519
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
520 // #included from: internal/catch_capture.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
521
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
522 // #included from: catch_expression_builder.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
523
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
524 // #included from: catch_expression.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
525
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
526 // #included from: catch_resultinfo_builder.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
527
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
528 // #included from: catch_tostring.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
529
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
530 #include <sstream>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
531
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
532 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
533 namespace Detail {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
534
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
535 struct NonStreamable {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
536 template<typename T> NonStreamable( const T& ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
537 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
538
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
539 // If the type does not have its own << overload for ostream then
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
540 // this one will be used instead
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
541 inline std::ostream& operator << ( std::ostream& ss, NonStreamable ){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
542 return ss << "{?}";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
543 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
544
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
545 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
546 inline std::string makeString( const T& value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
547 std::ostringstream oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
548 oss << value;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
549 return oss.str();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
550 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
551
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
552 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
553 inline std::string makeString( T* p ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
554 if( !p )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
555 return INTERNAL_CATCH_STRINGIFY( NULL );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
556 std::ostringstream oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
557 oss << p;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
558 return oss.str();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
559 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
560
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
561 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
562 inline std::string makeString( const T* p ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
563 if( !p )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
564 return INTERNAL_CATCH_STRINGIFY( NULL );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
565 std::ostringstream oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
566 oss << p;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
567 return oss.str();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
568 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
569
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
570 } // end namespace Detail
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
571
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
572 /// \brief converts any type to a string
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
573 ///
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
574 /// The default template forwards on to ostringstream - except when an
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
575 /// ostringstream overload does not exist - in which case it attempts to detect
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
576 /// that and writes {?}.
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
577 /// Overload (not specialise) this template for custom typs that you don't want
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
578 /// to provide an ostream overload for.
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
579 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
580 std::string toString( const T& value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
581 return Detail::makeString( value );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
582 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
583
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
584 // Built in overloads
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
585
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
586 inline std::string toString( const std::string& value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
587 return "\"" + value + "\"";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
588 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
589
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
590 inline std::string toString( const std::wstring& value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
591 std::ostringstream oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
592 oss << "\"";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
593 for(size_t i = 0; i < value.size(); ++i )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
594 oss << static_cast<char>( value[i] <= 0xff ? value[i] : '?');
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
595 oss << "\"";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
596 return oss.str();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
597 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
598
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
599 inline std::string toString( const char* const value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
600 return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
601 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
602
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
603 inline std::string toString( char* const value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
604 return Catch::toString( static_cast<const char*>( value ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
605 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
606
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
607 inline std::string toString( int value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
608 std::ostringstream oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
609 oss << value;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
610 return oss.str();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
611 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
612
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
613 inline std::string toString( unsigned long value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
614 std::ostringstream oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
615 if( value > 8192 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
616 oss << "0x" << std::hex << value;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
617 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
618 oss << value;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
619 return oss.str();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
620 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
621
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
622 inline std::string toString( unsigned int value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
623 return toString( static_cast<unsigned long>( value ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
624 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
625
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
626 inline std::string toString( const double value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
627 std::ostringstream oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
628 oss << value;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
629 return oss.str();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
630 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
631
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
632 inline std::string toString( bool value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
633 return value ? "true" : "false";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
634 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
635
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
636 inline std::string toString( char value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
637 return value < ' '
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
638 ? toString( (unsigned int)value )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
639 : Detail::makeString( value );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
640 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
641
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
642 inline std::string toString( signed char value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
643 return toString( static_cast<char>( value ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
644 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
645
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
646 #ifdef CATCH_CONFIG_CPP11_NULLPTR
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
647 inline std::string toString( std::nullptr_t ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
648 return "nullptr";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
649 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
650 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
651
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
652 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
653
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
654 // #included from: catch_resultinfo.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
655
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
656 #include <string>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
657 // #included from: catch_result_type.h
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
658
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
659 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
660
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
661 struct ResultWas { enum OfType {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
662 Unknown = -1,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
663 Ok = 0,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
664 Info = 1,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
665 Warning = 2,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
666
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
667 FailureBit = 0x10,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
668
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
669 ExpressionFailed = FailureBit | 1,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
670 ExplicitFailure = FailureBit | 2,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
671
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
672 Exception = 0x100 | FailureBit,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
673
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
674 ThrewException = Exception | 1,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
675 DidntThrowException = Exception | 2
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
676
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
677 }; };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
678
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
679 struct ResultAction { enum Value {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
680 None,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
681 Failed = 1, // Failure - but no debug break if Debug bit not set
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
682 Debug = 2, // If this bit is set, invoke the debugger
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
683 Abort = 4 // Test run should abort
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
684 }; };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
685
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
686 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
687
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
688
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
689 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
690
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
691 class ResultInfo {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
692 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
693 ResultInfo()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
694 : m_macroName(),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
695 m_expr(),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
696 m_lhs(),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
697 m_rhs(),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
698 m_op(),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
699 m_message(),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
700 m_result( ResultWas::Unknown ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
701 m_isNot( false )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
702 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
703
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
704 ResultInfo( const char* expr,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
705 ResultWas::OfType result,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
706 bool isNot,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
707 const SourceLineInfo& lineInfo,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
708 const char* macroName,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
709 const char* message )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
710 : m_macroName( macroName ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
711 m_lineInfo( lineInfo ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
712 m_expr( expr ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
713 m_lhs(),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
714 m_rhs(),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
715 m_op( isNotExpression( expr ) ? "!" : "" ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
716 m_message( message ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
717 m_result( result ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
718 m_isNot( isNot )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
719 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
720 if( isNot )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
721 m_expr = "!" + m_expr;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
722 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
723
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
724 virtual ~ResultInfo() {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
725
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
726 bool ok() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
727 return ( m_result & ResultWas::FailureBit ) != ResultWas::FailureBit;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
728 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
729
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
730 ResultWas::OfType getResultType() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
731 return m_result;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
732 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
733
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
734 bool hasExpression() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
735 return !m_expr.empty();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
736 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
737
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
738 bool hasMessage() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
739 return !m_message.empty();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
740 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
741
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
742 std::string getExpression() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
743 return m_expr;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
744 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
745
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
746 bool hasExpandedExpression() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
747 return hasExpression() && getExpandedExpressionInternal() != m_expr;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
748 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
749
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
750 std::string getExpandedExpression() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
751 return hasExpression() ? getExpandedExpressionInternal() : "";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
752 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
753
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
754 std::string getMessage() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
755 return m_message;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
756 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
757
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
758 std::string getFilename() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
759 return m_lineInfo.file;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
760 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
761
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
762 std::size_t getLine() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
763 return m_lineInfo.line;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
764 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
765
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
766 std::string getTestMacroName() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
767 return m_macroName;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
768 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
769
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
770 protected:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
771
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
772 std::string getExpandedExpressionInternal() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
773 if( m_op == "" || m_isNot )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
774 return m_lhs.empty() ? m_expr : m_op + m_lhs;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
775 else if( m_op == "matches" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
776 return m_lhs + " " + m_rhs;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
777 else if( m_op != "!" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
778 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
779 if( m_lhs.size() + m_rhs.size() < 30 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
780 return m_lhs + " " + m_op + " " + m_rhs;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
781 else if( m_lhs.size() < 70 && m_rhs.size() < 70 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
782 return "\n\t" + m_lhs + "\n\t" + m_op + "\n\t" + m_rhs;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
783 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
784 return "\n" + m_lhs + "\n" + m_op + "\n" + m_rhs + "\n\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
785 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
786 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
787 return "{can't expand - use " + m_macroName + "_FALSE( " + m_expr.substr(1) + " ) instead of " + m_macroName + "( " + m_expr + " ) for better diagnostics}";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
788 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
789
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
790 bool isNotExpression( const char* expr ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
791 return expr && expr[0] == '!';
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
792 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
793
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
794 protected:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
795 std::string m_macroName;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
796 SourceLineInfo m_lineInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
797 std::string m_expr, m_lhs, m_rhs, m_op;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
798 std::string m_message;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
799 ResultWas::OfType m_result;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
800 bool m_isNot;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
801 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
802
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
803 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
804
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
805 // #included from: catch_evaluate.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
806
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
807 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
808 namespace Internal {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
809
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
810 enum Operator {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
811 IsEqualTo,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
812 IsNotEqualTo,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
813 IsLessThan,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
814 IsGreaterThan,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
815 IsLessThanOrEqualTo,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
816 IsGreaterThanOrEqualTo
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
817 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
818
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
819 template<Operator Op> struct OperatorTraits { static const char* getName(){ return "*error*"; } };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
820 template<> struct OperatorTraits<IsEqualTo> { static const char* getName(){ return "=="; } };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
821 template<> struct OperatorTraits<IsNotEqualTo> { static const char* getName(){ return "!="; } };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
822 template<> struct OperatorTraits<IsLessThan> { static const char* getName(){ return "<"; } };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
823 template<> struct OperatorTraits<IsGreaterThan> { static const char* getName(){ return ">"; } };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
824 template<> struct OperatorTraits<IsLessThanOrEqualTo> { static const char* getName(){ return "<="; } };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
825 template<> struct OperatorTraits<IsGreaterThanOrEqualTo>{ static const char* getName(){ return ">="; } };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
826
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
827 // So the compare overloads can be operator agnostic we convey the operator as a template
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
828 // enum, which is used to specialise an Evaluator for doing the comparison.
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
829 template<typename T1, typename T2, Operator Op>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
830 class Evaluator{};
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
831
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
832 template<typename T1, typename T2>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
833 struct Evaluator<T1, T2, IsEqualTo> {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
834 static bool evaluate( const T1& lhs, const T2& rhs) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
835 return const_cast<T1&>( lhs ) == const_cast<T2&>( rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
836 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
837 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
838 template<typename T1, typename T2>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
839 struct Evaluator<T1, T2, IsNotEqualTo> {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
840 static bool evaluate( const T1& lhs, const T2& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
841 return const_cast<T1&>( lhs ) != const_cast<T2&>( rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
842 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
843 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
844 template<typename T1, typename T2>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
845 struct Evaluator<T1, T2, IsLessThan> {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
846 static bool evaluate( const T1& lhs, const T2& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
847 return const_cast<T1&>( lhs ) < const_cast<T2&>( rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
848 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
849 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
850 template<typename T1, typename T2>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
851 struct Evaluator<T1, T2, IsGreaterThan> {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
852 static bool evaluate( const T1& lhs, const T2& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
853 return const_cast<T1&>( lhs ) > const_cast<T2&>( rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
854 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
855 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
856 template<typename T1, typename T2>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
857 struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
858 static bool evaluate( const T1& lhs, const T2& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
859 return const_cast<T1&>( lhs ) >= const_cast<T2&>( rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
860 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
861 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
862 template<typename T1, typename T2>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
863 struct Evaluator<T1, T2, IsLessThanOrEqualTo> {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
864 static bool evaluate( const T1& lhs, const T2& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
865 return const_cast<T1&>( lhs ) <= const_cast<T2&>( rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
866 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
867 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
868
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
869 template<Operator Op, typename T1, typename T2>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
870 bool applyEvaluator( const T1& lhs, const T2& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
871 return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
872 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
873
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
874 // "base" overload
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
875 template<Operator Op, typename T1, typename T2>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
876 bool compare( const T1& lhs, const T2& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
877 return Evaluator<T1, T2, Op>::evaluate( lhs, rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
878 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
879
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
880 // unsigned X to int
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
881 template<Operator Op> bool compare( unsigned int lhs, int rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
882 return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
883 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
884 template<Operator Op> bool compare( unsigned long lhs, int rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
885 return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
886 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
887 template<Operator Op> bool compare( unsigned char lhs, int rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
888 return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
889 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
890
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
891 // unsigned X to long
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
892 template<Operator Op> bool compare( unsigned int lhs, long rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
893 return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
894 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
895 template<Operator Op> bool compare( unsigned long lhs, long rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
896 return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
897 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
898 template<Operator Op> bool compare( unsigned char lhs, long rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
899 return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
900 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
901
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
902 // int to unsigned X
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
903 template<Operator Op> bool compare( int lhs, unsigned int rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
904 return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
905 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
906 template<Operator Op> bool compare( int lhs, unsigned long rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
907 return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
908 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
909 template<Operator Op> bool compare( int lhs, unsigned char rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
910 return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
911 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
912
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
913 // long to unsigned X
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
914 template<Operator Op> bool compare( long lhs, unsigned int rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
915 return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
916 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
917 template<Operator Op> bool compare( long lhs, unsigned long rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
918 return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
919 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
920 template<Operator Op> bool compare( long lhs, unsigned char rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
921 return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
922 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
923
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
924 // pointer to long (when comparing against NULL)
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
925 template<Operator Op, typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
926 bool compare( long lhs, const T* rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
927 return Evaluator<const T*, const T*, Op>::evaluate( reinterpret_cast<const T*>( lhs ), rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
928 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
929
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
930 template<Operator Op, typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
931 bool compare( long lhs, T* rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
932 return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
933 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
934
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
935 template<Operator Op, typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
936 bool compare( const T* lhs, long rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
937 return Evaluator<const T*, const T*, Op>::evaluate( lhs, reinterpret_cast<const T*>( rhs ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
938 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
939
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
940 template<Operator Op, typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
941 bool compare( T* lhs, long rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
942 return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
943 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
944
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
945 // pointer to int (when comparing against NULL)
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
946 template<Operator Op, typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
947 bool compare( int lhs, const T* rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
948 return Evaluator<const T*, const T*, Op>::evaluate( reinterpret_cast<const T*>( lhs ), rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
949 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
950
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
951 template<Operator Op, typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
952 bool compare( int lhs, T* rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
953 return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
954 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
955
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
956 template<Operator Op, typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
957 bool compare( const T* lhs, int rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
958 return Evaluator<const T*, const T*, Op>::evaluate( lhs, reinterpret_cast<const T*>( rhs ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
959 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
960
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
961 template<Operator Op, typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
962 bool compare( T* lhs, int rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
963 return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
964 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
965
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
966 } // end of namespace Internal
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
967 } // end of namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
968
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
969 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
970
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
971 struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
972
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
973 class ResultInfoBuilder : public ResultInfo {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
974
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
975 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
976
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
977 ResultInfoBuilder() {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
978
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
979 ResultInfoBuilder( const char* expr,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
980 bool isNot,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
981 const SourceLineInfo& lineInfo,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
982 const char* macroName,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
983 const char* message = "" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
984 : ResultInfo( expr, ResultWas::Unknown, isNot, lineInfo, macroName, message )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
985 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
986
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
987 void setResultType( ResultWas::OfType result ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
988 // Flip bool results if isNot is set
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
989 if( m_isNot && result == ResultWas::Ok )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
990 m_result = ResultWas::ExpressionFailed;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
991 else if( m_isNot && result == ResultWas::ExpressionFailed )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
992 m_result = ResultWas::Ok;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
993 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
994 m_result = result;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
995 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
996
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
997 void setMessage( const std::string& message ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
998 m_message = message;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
999 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1000
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1001 void setLineInfo( const SourceLineInfo& lineInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1002 m_lineInfo = lineInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1003 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1004
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1005 void setLhs( const std::string& lhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1006 m_lhs = lhs;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1007 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1008
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1009 void setRhs( const std::string& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1010 m_rhs = rhs;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1011 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1012
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1013 void setOp( const std::string& op ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1014 m_op = op;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1015 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1016
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1017 template<typename RhsT>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1018 STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator ||
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1019 (
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1020 const RhsT&
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1021 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1022
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1023 template<typename RhsT>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1024 STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator &&
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1025 (
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1026 const RhsT&
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1027 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1028
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1029 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1030 friend class ExpressionBuilder;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1031 template<typename T> friend class Expression;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1032
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1033 template<typename T> friend class PtrExpression;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1034
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1035 ResultInfoBuilder& captureBoolExpression( bool result ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1036 m_lhs = Catch::toString( result );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1037 m_op = m_isNot ? "!" : "";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1038 setResultType( result ? ResultWas::Ok : ResultWas::ExpressionFailed );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1039 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1040 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1041
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1042 template<Internal::Operator Op, typename T1, typename T2>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1043 ResultInfoBuilder& captureExpression( const T1& lhs, const T2& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1044 setResultType( Internal::compare<Op>( lhs, rhs ) ? ResultWas::Ok : ResultWas::ExpressionFailed );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1045 m_lhs = Catch::toString( lhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1046 m_rhs = Catch::toString( rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1047 m_op = Internal::OperatorTraits<Op>::getName();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1048 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1049 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1050
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1051 template<Internal::Operator Op, typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1052 ResultInfoBuilder& captureExpression( const T* lhs, int rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1053 return captureExpression<Op>( lhs, reinterpret_cast<const T*>( rhs ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1054 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1055 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1056
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1057 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1058
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1059 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1060
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1061 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1062 class Expression {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1063 void operator = ( const Expression& );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1064
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1065 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1066 Expression( ResultInfoBuilder& result, T lhs )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1067 : m_result( result ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1068 m_lhs( lhs )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1069 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1070
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1071 template<typename RhsT>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1072 ResultInfoBuilder& operator == ( const RhsT& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1073 return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1074 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1075
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1076 template<typename RhsT>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1077 ResultInfoBuilder& operator != ( const RhsT& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1078 return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1079 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1080
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1081 template<typename RhsT>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1082 ResultInfoBuilder& operator < ( const RhsT& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1083 return m_result.captureExpression<Internal::IsLessThan>( m_lhs, rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1084 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1085
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1086 template<typename RhsT>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1087 ResultInfoBuilder& operator > ( const RhsT& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1088 return m_result.captureExpression<Internal::IsGreaterThan>( m_lhs, rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1089 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1090
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1091 template<typename RhsT>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1092 ResultInfoBuilder& operator <= ( const RhsT& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1093 return m_result.captureExpression<Internal::IsLessThanOrEqualTo>( m_lhs, rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1094 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1095
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1096 template<typename RhsT>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1097 ResultInfoBuilder& operator >= ( const RhsT& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1098 return m_result.captureExpression<Internal::IsGreaterThanOrEqualTo>( m_lhs, rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1099 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1100
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1101 ResultInfoBuilder& operator == ( bool rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1102 return m_result.captureExpression<Internal::IsEqualTo>( m_lhs, rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1103 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1104
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1105 ResultInfoBuilder& operator != ( bool rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1106 return m_result.captureExpression<Internal::IsNotEqualTo>( m_lhs, rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1107 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1108
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1109 operator ResultInfoBuilder& () {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1110 return m_result.captureBoolExpression( m_lhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1111 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1112
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1113 template<typename RhsT>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1114 STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( const RhsT& );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1115
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1116 template<typename RhsT>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1117 STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( const RhsT& );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1118
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1119 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1120 ResultInfoBuilder& m_result;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1121 T m_lhs;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1122 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1123
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1124 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1125
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1126 #include <sstream>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1127
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1128 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1129
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1130 class ExpressionBuilder {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1131 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1132
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1133 ExpressionBuilder( const SourceLineInfo& lineInfo,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1134 const char* macroName,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1135 const char* expr = "",
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1136 bool isNot = false )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1137 : m_result( expr, isNot, lineInfo, macroName ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1138 m_messageStream()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1139 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1140
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1141 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1142 Expression<const T&> operator->* ( const T & operand ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1143 Expression<const T&> expr( m_result, operand );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1144 return expr;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1145 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1146
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1147 Expression<bool> operator->* ( bool value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1148 Expression<bool> expr( m_result, value );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1149 return expr;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1150 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1151
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1152 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1153 ExpressionBuilder& operator << ( const T & value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1154 m_messageStream << Catch::toString( value );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1155 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1156 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1157
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1158 template<typename MatcherT, typename ArgT>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1159 ExpressionBuilder& acceptMatcher( const MatcherT& matcher,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1160 const ArgT& arg,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1161 const std::string& matcherCallAsString ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1162 std::string matcherAsString = Catch::toString( matcher );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1163 if( matcherAsString == "{?}" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1164 matcherAsString = matcherCallAsString;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1165 m_result.setLhs( Catch::toString( arg ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1166 m_result.setRhs( matcherAsString );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1167 m_result.setOp( "matches" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1168 m_result.setResultType( matcher( arg ) ? ResultWas::Ok : ResultWas::ExpressionFailed );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1169 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1170 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1171
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1172 template<typename MatcherT, typename ArgT>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1173 ExpressionBuilder& acceptMatcher( const MatcherT& matcher,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1174 ArgT* arg,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1175 const std::string& matcherCallAsString ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1176 std::string matcherAsString = Catch::toString( matcher );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1177 if( matcherAsString == "{?}" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1178 matcherAsString = matcherCallAsString;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1179 m_result.setLhs( Catch::toString( arg ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1180 m_result.setRhs( matcherAsString );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1181 m_result.setOp( "matches" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1182 m_result.setResultType( matcher( arg ) ? ResultWas::Ok : ResultWas::ExpressionFailed );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1183 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1184 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1185
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1186 ExpressionBuilder& setResultType( ResultWas::OfType resultType ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1187 m_result.setResultType( resultType );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1188 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1189 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1190
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1191 operator ResultInfoBuilder&() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1192 m_result.setMessage( m_messageStream.str() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1193 return m_result;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1194 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1195
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1196 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1197 ResultInfoBuilder m_result;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1198 std::ostringstream m_messageStream;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1199 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1200
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1201 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1202
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1203 // #included from: catch_interfaces_capture.h
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1204
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1205 #include <string>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1206
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1207 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1208
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1209 class TestCaseInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1210 class ScopedInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1211 class ResultInfoBuilder;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1212 class ResultInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1213
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1214 struct IResultCapture {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1215
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1216 virtual ~IResultCapture(){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1217
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1218 virtual void testEnded( const ResultInfo& result ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1219 virtual bool sectionStarted( const std::string& name,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1220 const std::string& description,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1221 const SourceLineInfo& lineInfo,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1222 Counts& assertions ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1223 virtual void sectionEnded( const std::string& name, const Counts& assertions ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1224 virtual void pushScopedInfo( ScopedInfo* scopedInfo ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1225 virtual void popScopedInfo( ScopedInfo* scopedInfo ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1226 virtual bool shouldDebugBreak() const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1227
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1228 virtual ResultAction::Value acceptResult( bool result ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1229 virtual ResultAction::Value acceptResult( ResultWas::OfType result ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1230 virtual ResultAction::Value acceptExpression( const ResultInfoBuilder& resultInfo ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1231 virtual void acceptMessage( const std::string& msg ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1232
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1233 virtual std::string getCurrentTestName() const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1234 virtual const ResultInfo* getLastResult() const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1235 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1236 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1237
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1238 // #included from: catch_debugger.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1239
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1240 #include <iostream>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1241
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1242 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1243 #define CATCH_PLATFORM_MAC
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1244 #elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1245 #define CATCH_PLATFORM_IPHONE
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1246 #elif defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER)
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1247 #define CATCH_PLATFORM_WINDOWS
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1248 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1249
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1250 #ifdef CATCH_PLATFORM_MAC
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1251
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1252 #include <assert.h>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1253 #include <stdbool.h>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1254 #include <sys/types.h>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1255 #include <unistd.h>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1256 #include <sys/sysctl.h>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1257
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1258 namespace Catch{
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1259
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1260 // The following function is taken directly from the following technical note:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1261 // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1262
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1263 // Returns true if the current process is being debugged (either
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1264 // running under the debugger or has a debugger attached post facto).
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1265 inline bool isDebuggerActive(){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1266
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1267 int junk;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1268 int mib[4];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1269 struct kinfo_proc info;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1270 size_t size;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1271
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1272 // Initialize the flags so that, if sysctl fails for some bizarre
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1273 // reason, we get a predictable result.
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1274
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1275 info.kp_proc.p_flag = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1276
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1277 // Initialize mib, which tells sysctl the info we want, in this case
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1278 // we're looking for information about a specific process ID.
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1279
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1280 mib[0] = CTL_KERN;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1281 mib[1] = KERN_PROC;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1282 mib[2] = KERN_PROC_PID;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1283 mib[3] = getpid();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1284
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1285 // Call sysctl.
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1286
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1287 size = sizeof(info);
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1288 junk = sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, NULL, 0);
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1289 assert(junk == 0);
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1290
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1291 // We're being debugged if the P_TRACED flag is set.
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1292
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1293 return ( (info.kp_proc.p_flag & P_TRACED) != 0 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1294 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1295 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1296
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1297 // The following code snippet taken from:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1298 // http://cocoawithlove.com/2008/03/break-into-debugger.html
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1299 #ifdef DEBUG
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1300 #if defined(__ppc64__) || defined(__ppc__)
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1301 #define BreakIntoDebugger() \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1302 if( Catch::isDebuggerActive() ) { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1303 __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1304 : : : "memory","r0","r3","r4" ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1305 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1306 #else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1307 #define BreakIntoDebugger() if( Catch::isDebuggerActive() ) {__asm__("int $3\n" : : );}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1308 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1309 #else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1310 inline void BreakIntoDebugger(){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1311 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1312
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1313 #elif defined(_MSC_VER)
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1314 extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1315 #define BreakIntoDebugger() if (IsDebuggerPresent() ) { __debugbreak(); }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1316 inline bool isDebuggerActive() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1317 return IsDebuggerPresent() != 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1318 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1319 #elif defined(__MINGW32__)
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1320 extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1321 extern "C" __declspec(dllimport) void __stdcall DebugBreak();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1322 #define BreakIntoDebugger() if (IsDebuggerPresent() ) { DebugBreak(); }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1323 inline bool isDebuggerActive() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1324 return IsDebuggerPresent() != 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1325 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1326 #else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1327 inline void BreakIntoDebugger(){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1328 inline bool isDebuggerActive() { return false; }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1329 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1330
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1331 #ifdef CATCH_PLATFORM_WINDOWS
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1332 extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA( const char* );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1333 inline void writeToDebugConsole( const std::string& text ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1334 ::OutputDebugStringA( text.c_str() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1335 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1336 #else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1337 inline void writeToDebugConsole( const std::string& text ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1338 // !TBD: Need a version for Mac/ XCode and other IDEs
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1339 std::cout << text;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1340 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1341 #endif // CATCH_PLATFORM_WINDOWS
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1342
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1343 #include <ostream>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1344
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1345 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1346
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1347 struct TestFailureException{};
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1348
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1349 class ScopedInfo {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1350 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1351 ScopedInfo() : m_oss() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1352 getCurrentContext().getResultCapture().pushScopedInfo( this );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1353 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1354
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1355 ~ScopedInfo() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1356 getCurrentContext().getResultCapture().popScopedInfo( this );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1357 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1358
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1359 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1360 ScopedInfo& operator << ( const T& value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1361 m_oss << value;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1362 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1363 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1364
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1365 std::string getInfo () const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1366 return m_oss.str();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1367 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1368
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1369 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1370 std::ostringstream m_oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1371 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1372
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1373 // This is just here to avoid compiler warnings with macro constants
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1374 inline bool isTrue( bool value ){ return value; }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1375
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1376 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1377
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1378 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1379 #define INTERNAL_CATCH_ACCEPT_EXPR( expr, stopOnFailure, originalExpr ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1380 if( Catch::ResultAction::Value internal_catch_action = Catch::getCurrentContext().getResultCapture().acceptExpression( expr ) ) { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1381 if( internal_catch_action & Catch::ResultAction::Debug ) BreakIntoDebugger(); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1382 if( internal_catch_action & Catch::ResultAction::Abort ) throw Catch::TestFailureException(); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1383 if( Catch::isTrue( stopOnFailure ) ) throw Catch::TestFailureException(); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1384 if( Catch::isTrue( false ) ){ bool this_is_here_to_invoke_warnings = ( originalExpr ); Catch::isTrue( this_is_here_to_invoke_warnings ); } \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1385 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1386
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1387 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1388 #define INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1389 do { try { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1390 INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr, isNot )->*expr ), stopOnFailure, expr ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1391 } catch( Catch::TestFailureException& ) { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1392 throw; \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1393 } catch( ... ) { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1394 INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, expr ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1395 throw; \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1396 } } while( Catch::isTrue( false ) )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1397
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1398 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1399 #define INTERNAL_CATCH_IF( expr, isNot, stopOnFailure, macroName ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1400 INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1401 if( Catch::getCurrentContext().getResultCapture().getLastResult()->ok() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1402
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1403 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1404 #define INTERNAL_CATCH_ELSE( expr, isNot, stopOnFailure, macroName ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1405 INTERNAL_CATCH_TEST( expr, isNot, stopOnFailure, macroName ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1406 if( !Catch::getCurrentContext().getResultCapture().getLastResult()->ok() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1407
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1408 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1409 #define INTERNAL_CATCH_NO_THROW( expr, stopOnFailure, macroName ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1410 try { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1411 expr; \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1412 INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1413 } \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1414 catch( ... ) { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1415 INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1416 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1417
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1418 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1419 #define INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1420 try { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1421 if( Catch::getCurrentContext().getConfig()->allowThrows() ) { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1422 expr; \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1423 INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::DidntThrowException ), stopOnFailure, false ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1424 } \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1425 } \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1426 catch( Catch::TestFailureException& ) { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1427 throw; \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1428 } \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1429 catch( exceptionType ) { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1430 INTERNAL_CATCH_ACCEPT_EXPR( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ).setResultType( Catch::ResultWas::Ok ), stopOnFailure, false ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1431 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1432
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1433 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1434 #define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, stopOnFailure, macroName ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1435 INTERNAL_CATCH_THROWS( expr, exceptionType, stopOnFailure, macroName ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1436 catch( ... ) { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1437 INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #expr ) << Catch::getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), stopOnFailure, false ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1438 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1439
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1440 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1441 #define INTERNAL_CATCH_MSG( reason, resultType, stopOnFailure, macroName ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1442 Catch::getCurrentContext().getResultCapture().acceptExpression( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName ) << reason ).setResultType( resultType ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1443
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1444 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1445 #define INTERNAL_CATCH_SCOPED_INFO( log ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1446 Catch::ScopedInfo INTERNAL_CATCH_UNIQUE_NAME( info ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1447 INTERNAL_CATCH_UNIQUE_NAME( info ) << log
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1448
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1449 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1450 #define INTERNAL_CHECK_THAT( arg, matcher, stopOnFailure, macroName ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1451 do { try { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1452 INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher, false ).acceptMatcher( ::Catch::Matchers::matcher, arg, #matcher ) ), stopOnFailure, false ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1453 } catch( Catch::TestFailureException& ) { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1454 throw; \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1455 } catch( ... ) { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1456 INTERNAL_CATCH_ACCEPT_EXPR( ( Catch::ExpressionBuilder( CATCH_INTERNAL_LINEINFO, macroName, #arg " " #matcher ) << Catch::getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() ).setResultType( Catch::ResultWas::ThrewException ), false, false ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1457 throw; \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1458 }}while( Catch::isTrue( false ) )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1459
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1460 // #included from: internal/catch_section.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1461
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1462 #include <string>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1463
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1464 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1465
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1466 class Section {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1467 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1468 Section( const std::string& name,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1469 const std::string& description,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1470 const SourceLineInfo& lineInfo )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1471 : m_name( name ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1472 m_sectionIncluded( getCurrentContext().getResultCapture().sectionStarted( name, description, lineInfo, m_assertions ) )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1473 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1474
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1475 ~Section() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1476 if( m_sectionIncluded )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1477 getCurrentContext().getResultCapture().sectionEnded( m_name, m_assertions );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1478 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1479
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1480 // This indicates whether the section should be executed or not
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1481 operator bool() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1482 return m_sectionIncluded;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1483 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1484
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1485 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1486
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1487 std::string m_name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1488 Counts m_assertions;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1489 bool m_sectionIncluded;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1490 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1491
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1492 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1493
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1494 #define INTERNAL_CATCH_SECTION( name, desc ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1495 if( Catch::Section INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::Section( name, desc, CATCH_INTERNAL_LINEINFO ) )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1496
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1497 // #included from: internal/catch_generators.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1498
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1499 #include <iterator>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1500 #include <vector>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1501 #include <string>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1502 #include <stdlib.h>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1503
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1504 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1505
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1506 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1507 struct IGenerator {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1508 virtual ~IGenerator() {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1509 virtual T getValue( std::size_t index ) const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1510 virtual std::size_t size () const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1511 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1512
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1513 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1514 class BetweenGenerator : public IGenerator<T> {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1515 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1516 BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1517
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1518 virtual T getValue( std::size_t index ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1519 return m_from+static_cast<T>( index );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1520 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1521
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1522 virtual std::size_t size() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1523 return static_cast<std::size_t>( 1+m_to-m_from );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1524 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1525
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1526 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1527
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1528 T m_from;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1529 T m_to;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1530 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1531
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1532 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1533 class ValuesGenerator : public IGenerator<T> {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1534 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1535 ValuesGenerator(){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1536
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1537 void add( T value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1538 m_values.push_back( value );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1539 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1540
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1541 virtual T getValue( std::size_t index ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1542 return m_values[index];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1543 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1544
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1545 virtual std::size_t size() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1546 return m_values.size();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1547 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1548
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1549 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1550 std::vector<T> m_values;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1551 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1552
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1553 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1554 class CompositeGenerator {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1555 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1556 CompositeGenerator() : m_totalSize( 0 ) {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1557
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1558 // *** Move semantics, similar to auto_ptr ***
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1559 CompositeGenerator( CompositeGenerator& other )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1560 : m_fileInfo( other.m_fileInfo ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1561 m_totalSize( 0 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1562 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1563 move( other );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1564 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1565
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1566 CompositeGenerator& setFileInfo( const char* fileInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1567 m_fileInfo = fileInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1568 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1569 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1570
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1571 ~CompositeGenerator() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1572 deleteAll( m_composed );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1573 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1574
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1575 operator T () const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1576 size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1577
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1578 typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1579 typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1580 for( size_t index = 0; it != itEnd; ++it )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1581 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1582 const IGenerator<T>* generator = *it;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1583 if( overallIndex >= index && overallIndex < index + generator->size() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1584 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1585 return generator->getValue( overallIndex-index );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1586 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1587 index += generator->size();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1588 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1589 CATCH_INTERNAL_ERROR( "Indexed past end of generated range" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1590 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
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1591 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1592
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1593 void add( const IGenerator<T>* generator ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1594 m_totalSize += generator->size();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1595 m_composed.push_back( generator );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1596 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1597
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1598 CompositeGenerator& then( CompositeGenerator& other ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1599 move( other );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1600 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1601 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1602
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1603 CompositeGenerator& then( T value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1604 ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1605 valuesGen->add( value );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1606 add( valuesGen );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1607 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1608 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1609
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1610 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1611
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1612 void move( CompositeGenerator& other ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1613 std::copy( other.m_composed.begin(), other.m_composed.end(), std::back_inserter( m_composed ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1614 m_totalSize += other.m_totalSize;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1615 other.m_composed.clear();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1616 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1617
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1618 std::vector<const IGenerator<T>*> m_composed;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1619 std::string m_fileInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1620 size_t m_totalSize;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1621 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1622
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1623 namespace Generators
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1624 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1625 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1626 CompositeGenerator<T> between( T from, T to ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1627 CompositeGenerator<T> generators;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1628 generators.add( new BetweenGenerator<T>( from, to ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1629 return generators;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1630 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1631
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1632 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1633 CompositeGenerator<T> values( T val1, T val2 ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1634 CompositeGenerator<T> generators;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1635 ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1636 valuesGen->add( val1 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1637 valuesGen->add( val2 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1638 generators.add( valuesGen );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1639 return generators;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1640 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1641
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1642 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1643 CompositeGenerator<T> values( T val1, T val2, T val3 ){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1644 CompositeGenerator<T> generators;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1645 ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1646 valuesGen->add( val1 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1647 valuesGen->add( val2 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1648 valuesGen->add( val3 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1649 generators.add( valuesGen );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1650 return generators;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1651 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1652
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1653 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1654 CompositeGenerator<T> values( T val1, T val2, T val3, T val4 ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1655 CompositeGenerator<T> generators;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1656 ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1657 valuesGen->add( val1 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1658 valuesGen->add( val2 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1659 valuesGen->add( val3 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1660 valuesGen->add( val4 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1661 generators.add( valuesGen );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1662 return generators;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1663 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1664
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1665 } // end namespace Generators
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1666
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1667 using namespace Generators;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1668
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1669 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1670
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1671 #define INTERNAL_CATCH_LINESTR2( line ) #line
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1672 #define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1673
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1674 #define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1675
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1676 // #included from: internal/catch_interfaces_exception.h
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1677
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1678 #include <string>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1679
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1680 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1681
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1682 typedef std::string(*exceptionTranslateFunction)();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1683
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1684 struct IExceptionTranslator {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1685 virtual ~IExceptionTranslator(){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1686 virtual std::string translate() const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1687 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1688
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1689 struct IExceptionTranslatorRegistry {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1690 virtual ~IExceptionTranslatorRegistry(){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1691
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1692 virtual void registerTranslator( IExceptionTranslator* translator ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1693 virtual std::string translateActiveException() const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1694 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1695
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1696 class ExceptionTranslatorRegistrar {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1697 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1698 class ExceptionTranslator : public IExceptionTranslator {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1699 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1700
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1701 ExceptionTranslator( std::string(*translateFunction)( T& ) )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1702 : m_translateFunction( translateFunction )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1703 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1704
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1705 virtual std::string translate() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1706 try {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1707 throw;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1708 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1709 catch( T& ex ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1710 return m_translateFunction( ex );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1711 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1712 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1713
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1714 protected:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1715 std::string(*m_translateFunction)( T& );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1716 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1717
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1718 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1719 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1720 ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1721 getCurrentContext().getExceptionTranslatorRegistry().registerTranslator
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1722 ( new ExceptionTranslator<T>( translateFunction ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1723 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1724 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1725 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1726
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1727 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1728 #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1729 static std::string INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator )( signature ); \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1730 namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ) ); }\
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1731 static std::string INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator )( signature )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1732
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1733 // #included from: internal/catch_approx.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1734
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1735 #include <cmath>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1736 #include <limits>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1737
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1738 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1739 namespace Detail {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1740
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1741 class Approx {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1742 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1743 explicit Approx ( double value )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1744 : m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1745 m_scale( 1.0 ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1746 m_value( value )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1747 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1748
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1749 Approx( const Approx& other )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1750 : m_epsilon( other.m_epsilon ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1751 m_scale( other.m_scale ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1752 m_value( other.m_value )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1753 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1754
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1755 static Approx custom() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1756 return Approx( 0 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1757 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1758
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1759 Approx operator()( double value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1760 Approx approx( value );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1761 approx.epsilon( m_epsilon );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1762 approx.scale( m_scale );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1763 return approx;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1764 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1765
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1766 friend bool operator == ( double lhs, const Approx& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1767 // Thanks to Richard Harris for his help refining this formula
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1768 return fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_value) ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1769 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1770
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1771 friend bool operator == ( const Approx& lhs, double rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1772 return operator==( rhs, lhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1773 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1774
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1775 friend bool operator != ( double lhs, const Approx& rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1776 return !operator==( lhs, rhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1777 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1778
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1779 friend bool operator != ( const Approx& lhs, double rhs ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1780 return !operator==( rhs, lhs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1781 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1782
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1783 Approx& epsilon( double newEpsilon ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1784 m_epsilon = newEpsilon;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1785 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1786 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1787
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1788 Approx& scale( double newScale ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1789 m_scale = newScale;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1790 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1791 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1792
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1793 std::string toString() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1794 std::ostringstream oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1795 oss << "Approx( " << m_value << ")";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1796 return oss.str();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1797 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1798
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1799 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1800 double m_epsilon;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1801 double m_scale;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1802 double m_value;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1803 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1804 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1805
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1806 template<>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1807 inline std::string toString<Detail::Approx>( const Detail::Approx& value ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1808 return value.toString();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1809 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1810
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1811 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1812
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1813 // #included from: internal/catch_matchers.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1814
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1815 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1816 namespace Matchers {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1817 namespace Impl {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1818 namespace StdString {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1819
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1820 struct Equals {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1821 Equals( const std::string& str ) : m_str( str ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1822
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1823 bool operator()( const std::string& str ) const
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1824 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1825 return str == m_str;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1826 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1827
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1828 friend std::ostream& operator<<( std::ostream& os, const Equals& matcher )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1829 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1830 os << "equals: \"" << matcher.m_str << "\"";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1831 return os;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1832 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1833 std::string m_str;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1834 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1835
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1836 struct Contains {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1837 Contains( const std::string& substr ) : m_substr( substr ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1838
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1839 bool operator()( const std::string& str ) const
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1840 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1841 return str.find( m_substr ) != std::string::npos;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1842 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1843
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1844 friend std::ostream& operator<<( std::ostream& os, const Contains& matcher )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1845 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1846 os << "contains: \"" << matcher.m_substr << "\"";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1847 return os;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1848 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1849 std::string m_substr;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1850 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1851
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1852 struct StartsWith {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1853 StartsWith( const std::string& substr ) : m_substr( substr ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1854
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1855 bool operator()( const std::string& str ) const
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1856 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1857 return str.find( m_substr ) == 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1858 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1859
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1860 friend std::ostream& operator<<( std::ostream& os, const StartsWith& matcher )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1861 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1862 os << "starts with: \"" << matcher.m_substr << "\"";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1863 return os;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1864 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1865 std::string m_substr;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1866 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1867
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1868 struct EndsWith {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1869 EndsWith( const std::string& substr ) : m_substr( substr ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1870
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1871 bool operator()( const std::string& str ) const
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1872 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1873 return str.find( m_substr ) == str.size() - m_substr.size();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1874 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1875
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1876 friend std::ostream& operator<<( std::ostream& os, const EndsWith& matcher )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1877 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1878 os << "ends with: \"" << matcher.m_substr << "\"";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1879 return os;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1880 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1881 std::string m_substr;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1882 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1883 } // namespace StdString
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1884 } // namespace Impl
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1885
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1886 inline Impl::StdString::Equals Equals( const std::string& str ){ return Impl::StdString::Equals( str ); }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1887 inline Impl::StdString::Contains Contains( const std::string& substr ){ return Impl::StdString::Contains( substr ); }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1888 inline Impl::StdString::StartsWith StartsWith( const std::string& substr ){ return Impl::StdString::StartsWith( substr ); }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1889 inline Impl::StdString::EndsWith EndsWith( const std::string& substr ){ return Impl::StdString::EndsWith( substr ); }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1890
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1891 } // namespace Matchers
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1892
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1893 using namespace Matchers;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1894
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1895 } // namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1896
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1897 // These files are included here so the single_include script doesn't put them
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1898 // in the conditionally compiled sections
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1899 // #included from: internal/catch_test_case_info.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1900
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1901 #include <map>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1902 #include <string>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1903
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1904 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1905
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1906 class TestCaseInfo {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1907 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1908 TestCaseInfo( ITestCase* testCase,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1909 const char* name,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1910 const char* description,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1911 const SourceLineInfo& lineInfo )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1912 : m_test( testCase ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1913 m_name( name ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1914 m_description( description ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1915 m_lineInfo( lineInfo )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1916 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1917
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1918 TestCaseInfo()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1919 : m_test( NULL ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1920 m_name(),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1921 m_description()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1922 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1923
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1924 TestCaseInfo( const TestCaseInfo& other )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1925 : m_test( other.m_test->clone() ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1926 m_name( other.m_name ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1927 m_description( other.m_description ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1928 m_lineInfo( other.m_lineInfo )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1929 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1930
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1931 TestCaseInfo( const TestCaseInfo& other, const std::string& name )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1932 : m_test( other.m_test->clone() ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1933 m_name( name ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1934 m_description( other.m_description ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1935 m_lineInfo( other.m_lineInfo )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1936 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1937
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1938 TestCaseInfo& operator = ( const TestCaseInfo& other ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1939 TestCaseInfo temp( other );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1940 swap( temp );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1941 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1942 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1943
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1944 ~TestCaseInfo() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1945 delete m_test;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1946 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1947
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1948 void invoke() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1949 m_test->invoke();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1950 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1951
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1952 const std::string& getName() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1953 return m_name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1954 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1955
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1956 const std::string& getDescription() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1957 return m_description;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1958 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1959
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1960 const SourceLineInfo& getLineInfo() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1961 return m_lineInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1962 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1963
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1964 bool isHidden() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1965 return m_name.size() >= 2 && m_name[0] == '.' && m_name[1] == '/';
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1966 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1967
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1968 void swap( TestCaseInfo& other ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1969 std::swap( m_test, other.m_test );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1970 m_name.swap( other.m_name );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1971 m_description.swap( other.m_description );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1972 m_lineInfo.swap( other.m_lineInfo );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1973 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1974
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1975 bool operator == ( const TestCaseInfo& other ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1976 return *m_test == *other.m_test && m_name == other.m_name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1977 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1978
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1979 bool operator < ( const TestCaseInfo& other ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1980 return m_name < other.m_name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1981 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1982
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1983 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1984 ITestCase* m_test;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1985 std::string m_name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1986 std::string m_description;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1987 SourceLineInfo m_lineInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1988 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1989
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1990 ///////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1991
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1992 class TestSpec {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1993 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1994 TestSpec( const std::string& rawSpec )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1995 : m_rawSpec( rawSpec ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1996 m_isWildcarded( false ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1997
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1998 if( m_rawSpec[m_rawSpec.size()-1] == '*' ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
1999 m_rawSpec = m_rawSpec.substr( 0, m_rawSpec.size()-1 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2000 m_isWildcarded = true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2001 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2002 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2003
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2004 bool matches ( const std::string& testName ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2005 if( !m_isWildcarded )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2006 return m_rawSpec == testName;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2007 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2008 return testName.size() >= m_rawSpec.size() && testName.substr( 0, m_rawSpec.size() ) == m_rawSpec;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2009 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2010
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2011 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2012 std::string m_rawSpec;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2013 bool m_isWildcarded;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2014 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2015 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2016
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2017 // #included from: internal/catch_interfaces_runner.h
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2018
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2019 #include <string>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2020
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2021 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2022 class TestCaseInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2023
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2024 struct IRunner {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2025 virtual ~IRunner() {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2026 virtual void runAll( bool runHiddenTests = false ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2027 virtual std::size_t runMatching( const std::string& rawTestSpec ) = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2028 virtual Totals getTotals() const = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2029 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2030 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2031
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2032
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2033 #ifdef __OBJC__
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2034 // #included from: internal/catch_objc.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2035
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2036 #import <Foundation/Foundation.h>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2037 #import <objc/runtime.h>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2038
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2039 #include <string>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2040
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2041 // NB. Any general catch headers included here must be included
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2042 // in catch.hpp first to make sure they are included by the single
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2043 // header for non obj-usage
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2044
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2045 #ifdef __has_feature
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2046 #define CATCH_ARC_ENABLED __has_feature(objc_arc)
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2047 #else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2048 #define CATCH_ARC_ENABLED 0
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2049 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2050
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2051 void arcSafeRelease( NSObject* obj );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2052 id performOptionalSelector( id obj, SEL sel );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2053
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2054 #if !CATCH_ARC_ENABLED
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2055 inline void arcSafeRelease( NSObject* obj ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2056 [obj release];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2057 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2058 inline id performOptionalSelector( id obj, SEL sel ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2059 if( [obj respondsToSelector: sel] )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2060 return [obj performSelector: sel];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2061 return nil;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2062 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2063 #define CATCH_UNSAFE_UNRETAINED
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2064 #else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2065 inline void arcSafeRelease( NSObject* ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2066 inline id performOptionalSelector( id obj, SEL sel ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2067 #pragma clang diagnostic push
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2068 #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2069 if( [obj respondsToSelector: sel] )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2070 return [obj performSelector: sel];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2071 #pragma clang diagnostic pop
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2072 return nil;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2073 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2074 #define CATCH_UNSAFE_UNRETAINED __unsafe_unretained
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2075 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2076
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2077 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2078 // This protocol is really only here for (self) documenting purposes, since
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2079 // all its methods are optional.
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2080 @protocol OcFixture
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2081
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2082 @optional
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2083
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2084 -(void) setUp;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2085 -(void) tearDown;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2086
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2087 @end
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2088
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2089 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2090
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2091 class OcMethod : public ITestCase {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2092
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2093 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2094 OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2095
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2096 virtual void invoke() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2097 id obj = [[m_cls alloc] init];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2098
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2099 performOptionalSelector( obj, @selector(setUp) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2100 performOptionalSelector( obj, m_sel );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2101 performOptionalSelector( obj, @selector(tearDown) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2102
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2103 arcSafeRelease( obj );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2104 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2105
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2106 virtual ITestCase* clone() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2107 return new OcMethod( m_cls, m_sel );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2108 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2109
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2110 virtual bool operator == ( const ITestCase& other ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2111 const OcMethod* ocmOther = dynamic_cast<const OcMethod*> ( &other );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2112 return ocmOther && ocmOther->m_sel == m_sel;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2113 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2114
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2115 virtual bool operator < ( const ITestCase& other ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2116 const OcMethod* ocmOther = dynamic_cast<const OcMethod*> ( &other );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2117 return ocmOther && ocmOther->m_sel < m_sel;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2118 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2119
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2120 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2121 Class m_cls;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2122 SEL m_sel;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2123 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2124
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2125 namespace Detail{
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2126
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2127 inline bool startsWith( const std::string& str, const std::string& sub ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2128 return str.length() > sub.length() && str.substr( 0, sub.length() ) == sub;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2129 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2130
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2131 inline std::string getAnnotation( Class cls,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2132 const std::string& annotationName,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2133 const std::string& testCaseName ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2134 NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2135 SEL sel = NSSelectorFromString( selStr );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2136 arcSafeRelease( selStr );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2137 id value = performOptionalSelector( cls, sel );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2138 if( value )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2139 return [(NSString*)value UTF8String];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2140 return "";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2141 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2142 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2143
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2144 inline size_t registerTestMethods() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2145 size_t noTestMethods = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2146 int noClasses = objc_getClassList( NULL, 0 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2147
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2148 Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses);
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2149 objc_getClassList( classes, noClasses );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2150
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2151 for( int c = 0; c < noClasses; c++ ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2152 Class cls = classes[c];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2153 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2154 u_int count;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2155 Method* methods = class_copyMethodList( cls, &count );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2156 for( u_int m = 0; m < count ; m++ ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2157 SEL selector = method_getName(methods[m]);
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2158 std::string methodName = sel_getName(selector);
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2159 if( Detail::startsWith( methodName, "Catch_TestCase_" ) ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2160 std::string testCaseName = methodName.substr( 15 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2161 std::string name = Detail::getAnnotation( cls, "Name", testCaseName );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2162 std::string desc = Detail::getAnnotation( cls, "Description", testCaseName );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2163
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2164 getCurrentContext().getTestCaseRegistry().registerTest( TestCaseInfo( new OcMethod( cls, selector ), name.c_str(), desc.c_str(), SourceLineInfo() ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2165 noTestMethods++;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2166 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2167 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2168 free(methods);
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2169 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2170 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2171 return noTestMethods;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2172 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2173
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2174 inline std::string toString( NSString* const& nsstring ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2175 return std::string( "@\"" ) + [nsstring UTF8String] + "\"";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2176 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2177
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2178 namespace Matchers {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2179 namespace Impl {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2180 namespace NSStringMatchers {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2181
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2182 struct StringHolder {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2183 StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2184 StringHolder() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2185 arcSafeRelease( m_substr );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2186 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2187
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2188 NSString* m_substr;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2189 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2190
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2191 struct Equals : StringHolder {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2192 Equals( NSString* substr ) : StringHolder( substr ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2193
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2194 bool operator()( NSString* str ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2195 return [str isEqualToString:m_substr];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2196 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2197
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2198 friend std::ostream& operator<<( std::ostream& os, const Equals& matcher ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2199 os << "equals string: " << Catch::toString( matcher.m_substr );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2200 return os;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2201 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2202 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2203
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2204 struct Contains : StringHolder {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2205 Contains( NSString* substr ) : StringHolder( substr ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2206
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2207 bool operator()( NSString* str ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2208 return [str rangeOfString:m_substr].location != NSNotFound;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2209 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2210
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2211 friend std::ostream& operator<<( std::ostream& os, const Contains& matcher ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2212 os << "contains: " << Catch::toString( matcher.m_substr );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2213 return os;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2214 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2215 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2216
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2217 struct StartsWith : StringHolder {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2218 StartsWith( NSString* substr ) : StringHolder( substr ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2219
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2220 bool operator()( NSString* str ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2221 return [str rangeOfString:m_substr].location == 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2222 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2223
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2224 friend std::ostream& operator<<( std::ostream& os, const StartsWith& matcher ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2225 os << "starts with: " << Catch::toString( matcher.m_substr );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2226 return os;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2227 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2228 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2229 struct EndsWith : StringHolder {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2230 EndsWith( NSString* substr ) : StringHolder( substr ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2231
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2232 bool operator()( NSString* str ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2233 return [str rangeOfString:m_substr].location == [str length] - [m_substr length];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2234 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2235
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2236 friend std::ostream& operator<<( std::ostream& os, const EndsWith& matcher ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2237 os << "ends with: " << Catch::toString( matcher.m_substr );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2238 return os;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2239 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2240 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2241
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2242 } // namespace NSStringMatchers
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2243 } // namespace Impl
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2244
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2245 inline Impl::NSStringMatchers::Equals
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2246 Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2247
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2248 inline Impl::NSStringMatchers::Contains
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2249 Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2250
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2251 inline Impl::NSStringMatchers::StartsWith
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2252 StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2253
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2254 inline Impl::NSStringMatchers::EndsWith
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2255 EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2256
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2257 } // namespace Matchers
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2258
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2259 using namespace Matchers;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2260
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2261 } // namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2262
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2263 ///////////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2264 #define OC_TEST_CASE( name, desc )\
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2265 +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2266 {\
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2267 return @ name; \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2268 }\
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2269 +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2270 { \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2271 return @ desc; \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2272 } \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2273 -(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2274
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2275 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2276
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2277 #if defined( CATCH_CONFIG_MAIN ) || defined( CATCH_CONFIG_RUNNER )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2278 // #included from: catch_runner.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2279
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2280 // #included from: internal/catch_context_impl.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2281 // #included from: catch_test_case_registry_impl.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2282
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2283 #include <vector>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2284 #include <set>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2285 #include <sstream>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2286 #include <iostream>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2287
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2288 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2289
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2290 class TestRegistry : public ITestCaseRegistry {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2291 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2292 TestRegistry() : m_unnamedCount( 0 ) {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2293
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2294 virtual void registerTest( const TestCaseInfo& testInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2295 if( testInfo.getName() == "" ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2296 std::ostringstream oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2297 oss << testInfo.getName() << "unnamed/" << ++m_unnamedCount;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2298 return registerTest( TestCaseInfo( testInfo, oss.str() ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2299 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2300
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2301 if( m_functions.find( testInfo ) == m_functions.end() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2302 m_functions.insert( testInfo );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2303 m_functionsInOrder.push_back( testInfo );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2304 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2305 else {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2306 const TestCaseInfo& prev = *m_functions.find( testInfo );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2307 std::cerr << "error: TEST_CASE( \"" << testInfo.getName() << "\" ) already defined.\n"
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2308 << "\tFirst seen at " << SourceLineInfo( prev.getLineInfo() ) << "\n"
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2309 << "\tRedefined at " << SourceLineInfo( testInfo.getLineInfo() ) << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2310 exit(1);
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2311 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2312 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2313
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2314 virtual const std::vector<TestCaseInfo>& getAllTests() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2315 return m_functionsInOrder;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2316 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2317
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2318 virtual std::vector<TestCaseInfo> getMatchingTestCases( const std::string& rawTestSpec ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2319 TestSpec testSpec( rawTestSpec );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2320
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2321 std::vector<TestCaseInfo> testList;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2322 std::vector<TestCaseInfo>::const_iterator it = m_functionsInOrder.begin();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2323 std::vector<TestCaseInfo>::const_iterator itEnd = m_functionsInOrder.end();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2324 for(; it != itEnd; ++it ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2325 if( testSpec.matches( it->getName() ) ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2326 testList.push_back( *it );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2327 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2328 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2329 return testList;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2330 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2331
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2332 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2333
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2334 std::set<TestCaseInfo> m_functions;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2335 std::vector<TestCaseInfo> m_functionsInOrder;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2336 size_t m_unnamedCount;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2337 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2338
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2339 ///////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2340
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2341 class FreeFunctionTestCase : public ITestCase {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2342 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2343
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2344 FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2345
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2346 virtual void invoke() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2347 m_fun();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2348 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2349
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2350 virtual ITestCase* clone() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2351 return new FreeFunctionTestCase( m_fun );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2352 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2353
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2354 virtual bool operator == ( const ITestCase& other ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2355 const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2356 return ffOther && m_fun == ffOther->m_fun;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2357 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2358
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2359 virtual bool operator < ( const ITestCase& other ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2360 const FreeFunctionTestCase* ffOther = dynamic_cast<const FreeFunctionTestCase*> ( &other );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2361 return ffOther && m_fun < ffOther->m_fun;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2362 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2363
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2364 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2365 TestFunction m_fun;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2366 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2367
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2368 ///////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2369
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2370 AutoReg::AutoReg( TestFunction function,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2371 const char* name,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2372 const char* description,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2373 const SourceLineInfo& lineInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2374 registerTestCase( new FreeFunctionTestCase( function ), name, description, lineInfo );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2375 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2376
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2377 AutoReg::~AutoReg() {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2378
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2379 void AutoReg::registerTestCase( ITestCase* testCase,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2380 const char* name,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2381 const char* description,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2382 const SourceLineInfo& lineInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2383 getCurrentContext().getTestCaseRegistry().registerTest( TestCaseInfo( testCase, name, description, lineInfo ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2384 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2385
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2386 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2387
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2388 // #included from: catch_runner_impl.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2389
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2390 // #included from: catch_config.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2391
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2392 #include <memory>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2393 #include <vector>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2394 #include <string>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2395 #include <iostream>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2396
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2397 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2398
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2399 struct Include { enum WhichResults {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2400 FailedOnly,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2401 SuccessfulResults
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2402 }; };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2403
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2404 struct List{ enum What {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2405 None = 0,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2406
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2407 Reports = 1,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2408 Tests = 2,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2409 All = 3,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2410
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2411 WhatMask = 0xf,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2412
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2413 AsText = 0x10,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2414 AsXml = 0x11,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2415
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2416 AsMask = 0xf0
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2417 }; };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2418
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2419 class Config : public IReporterConfig, public IConfig {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2420 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2421 Config( const Config& other );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2422 Config& operator = ( const Config& other );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2423 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2424
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2425 Config()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2426 : m_listSpec( List::None ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2427 m_shouldDebugBreak( false ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2428 m_showHelp( false ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2429 m_streambuf( NULL ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2430 m_os( std::cout.rdbuf() ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2431 m_includeWhichResults( Include::FailedOnly ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2432 m_cutoff( -1 ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2433 m_allowThrows( true )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2434 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2435
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2436 ~Config() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2437 m_os.rdbuf( std::cout.rdbuf() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2438 delete m_streambuf;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2439 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2440
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2441 void setReporter( const std::string& reporterName ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2442 if( m_reporter.get() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2443 return setError( "Only one reporter may be specified" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2444 setReporter( getCurrentContext().getReporterRegistry().create( reporterName, *this ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2445 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2446
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2447 void addTestSpec( const std::string& testSpec ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2448 m_testSpecs.push_back( testSpec );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2449 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2450
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2451 bool testsSpecified() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2452 return !m_testSpecs.empty();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2453 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2454
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2455 const std::vector<std::string>& getTestSpecs() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2456 return m_testSpecs;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2457 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2458
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2459 List::What getListSpec( void ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2460 return m_listSpec;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2461 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2462
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2463 void setListSpec( List::What listSpec ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2464 m_listSpec = listSpec;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2465 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2466
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2467 void setFilename( const std::string& filename ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2468 m_filename = filename;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2469 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2470
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2471 const std::string& getFilename() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2472 return m_filename;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2473 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2474
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2475 const std::string& getMessage() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2476 return m_message;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2477 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2478
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2479 void setError( const std::string& errorMessage ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2480 m_message = errorMessage;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2481 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2482
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2483 void setReporter( IReporter* reporter ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2484 m_reporter = reporter;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2485 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2486
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2487 Ptr<IReporter> getReporter() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2488 if( !m_reporter.get() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2489 const_cast<Config*>( this )->setReporter( getCurrentContext().getReporterRegistry().create( "basic", *this ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2490 return m_reporter;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2491 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2492
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2493 List::What listWhat() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2494 return static_cast<List::What>( m_listSpec & List::WhatMask );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2495 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2496
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2497 List::What listAs() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2498 return static_cast<List::What>( m_listSpec & List::AsMask );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2499 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2500
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2501 void setIncludeWhichResults( Include::WhichResults includeWhichResults ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2502 m_includeWhichResults = includeWhichResults;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2503 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2504
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2505 void setShouldDebugBreak( bool shouldDebugBreakFlag ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2506 m_shouldDebugBreak = shouldDebugBreakFlag;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2507 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2508
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2509 void setName( const std::string& name ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2510 m_name = name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2511 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2512
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2513 std::string getName() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2514 return m_name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2515 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2516
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2517 bool shouldDebugBreak() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2518 return m_shouldDebugBreak;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2519 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2520
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2521 void setShowHelp( bool showHelpFlag ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2522 m_showHelp = showHelpFlag;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2523 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2524
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2525 bool showHelp() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2526 return m_showHelp;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2527 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2528
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2529 virtual std::ostream& stream() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2530 return m_os;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2531 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2532
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2533 void setStreamBuf( std::streambuf* buf ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2534 m_os.rdbuf( buf ? buf : std::cout.rdbuf() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2535 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2536
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2537 void useStream( const std::string& streamName ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2538 std::streambuf* newBuf = Context::createStreamBuf( streamName );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2539 setStreamBuf( newBuf );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2540 delete m_streambuf;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2541 m_streambuf = newBuf;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2542 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2543
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2544 virtual bool includeSuccessfulResults() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2545 return m_includeWhichResults == Include::SuccessfulResults;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2546 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2547
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2548 int getCutoff() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2549 return m_cutoff;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2550 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2551
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2552 void setCutoff( int cutoff ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2553 m_cutoff = cutoff;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2554 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2555
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2556 void setAllowThrows( bool allowThrows ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2557 m_allowThrows = allowThrows;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2558 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2559
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2560 virtual bool allowThrows() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2561 return m_allowThrows;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2562 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2563
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2564 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2565 Ptr<IReporter> m_reporter;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2566 std::string m_filename;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2567 std::string m_message;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2568 List::What m_listSpec;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2569 std::vector<std::string> m_testSpecs;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2570 bool m_shouldDebugBreak;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2571 bool m_showHelp;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2572 std::streambuf* m_streambuf;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2573 mutable std::ostream m_os;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2574 Include::WhichResults m_includeWhichResults;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2575 std::string m_name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2576 int m_cutoff;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2577 bool m_allowThrows;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2578 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2579
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2580 struct NewConfig {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2581 std::string reporter;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2582 std::string outputFilename;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2583 List::What listSpec;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2584 std::vector<std::string> testSpecs;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2585 bool shouldDebugBreak;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2586 bool showHelp;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2587 Include::WhichResults includeWhichResults;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2588 std::string name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2589 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2590
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2591 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2592
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2593 // #included from: catch_running_test.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2594
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2595 // #included from: catch_section_info.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2596
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2597 #include <map>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2598 #include <string>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2599
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2600 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2601
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2602 class SectionInfo {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2603 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2604
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2605 enum Status {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2606 Root,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2607 Unknown,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2608 Branch,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2609 TestedBranch,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2610 TestedLeaf
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2611 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2612
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2613 SectionInfo( SectionInfo* parent )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2614 : m_status( Unknown ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2615 m_parent( parent )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2616 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2617
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2618 SectionInfo()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2619 : m_status( Root ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2620 m_parent( NULL )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2621 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2622
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2623 ~SectionInfo() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2624 deleteAllValues( m_subSections );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2625 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2626
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2627 bool shouldRun() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2628 return m_status < TestedBranch;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2629 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2630
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2631 bool ran() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2632 if( m_status < Branch ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2633 m_status = TestedLeaf;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2634 return true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2635 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2636 return false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2637 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2638
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2639 void ranToCompletion() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2640 if( m_status == Branch && !hasUntestedSections() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2641 m_status = TestedBranch;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2642 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2643
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2644 SectionInfo* findSubSection( const std::string& name ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2645 std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.find( name );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2646 return it != m_subSections.end()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2647 ? it->second
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2648 : NULL;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2649 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2650
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2651 SectionInfo* addSubSection( const std::string& name ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2652 SectionInfo* subSection = new SectionInfo( this );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2653 m_subSections.insert( std::make_pair( name, subSection ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2654 m_status = Branch;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2655 return subSection;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2656 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2657
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2658 SectionInfo* getParent() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2659 return m_parent;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2660 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2661
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2662 bool hasUntestedSections() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2663 if( m_status == Unknown )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2664 return true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2665
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2666 std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.begin();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2667 std::map<std::string, SectionInfo*>::const_iterator itEnd = m_subSections.end();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2668 for(; it != itEnd; ++it ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2669 if( it->second->hasUntestedSections() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2670 return true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2671 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2672 return false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2673 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2674
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2675 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2676 Status m_status;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2677 std::map<std::string, SectionInfo*> m_subSections;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2678 SectionInfo* m_parent;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2679 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2680 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2681
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2682 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2683
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2684 class RunningTest {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2685
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2686 enum RunStatus {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2687 NothingRun,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2688 EncounteredASection,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2689 RanAtLeastOneSection,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2690 RanToCompletionWithSections,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2691 RanToCompletionWithNoSections
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2692 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2693
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2694 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2695 explicit RunningTest( const TestCaseInfo* info = NULL )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2696 : m_info( info ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2697 m_runStatus( RanAtLeastOneSection ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2698 m_currentSection( &m_rootSection ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2699 m_changed( false )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2700 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2701
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2702 bool wasSectionSeen() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2703 return m_runStatus == RanAtLeastOneSection ||
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2704 m_runStatus == RanToCompletionWithSections;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2705 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2706
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2707 void reset() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2708 m_runStatus = NothingRun;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2709 m_changed = false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2710 m_lastSectionToRun = NULL;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2711 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2712
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2713 void ranToCompletion() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2714 if( m_runStatus == RanAtLeastOneSection ||
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2715 m_runStatus == EncounteredASection ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2716 m_runStatus = RanToCompletionWithSections;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2717 if( m_lastSectionToRun ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2718 m_lastSectionToRun->ranToCompletion();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2719 m_changed = true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2720 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2721 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2722 else {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2723 m_runStatus = RanToCompletionWithNoSections;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2724 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2725 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2726
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2727 bool addSection( const std::string& name ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2728 if( m_runStatus == NothingRun )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2729 m_runStatus = EncounteredASection;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2730
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2731 SectionInfo* thisSection = m_currentSection->findSubSection( name );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2732 if( !thisSection ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2733 thisSection = m_currentSection->addSubSection( name );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2734 m_changed = true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2735 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2736
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2737 if( !wasSectionSeen() && thisSection->shouldRun() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2738 m_currentSection = thisSection;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2739 m_lastSectionToRun = NULL;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2740 return true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2741 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2742 return false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2743 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2744
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2745 void endSection( const std::string& ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2746 if( m_currentSection->ran() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2747 m_runStatus = RanAtLeastOneSection;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2748 m_changed = true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2749 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2750 else if( m_runStatus == EncounteredASection ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2751 m_runStatus = RanAtLeastOneSection;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2752 m_lastSectionToRun = m_currentSection;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2753 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2754 m_currentSection = m_currentSection->getParent();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2755 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2756
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2757 const TestCaseInfo& getTestCaseInfo() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2758 return *m_info;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2759 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2760
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2761 bool hasUntestedSections() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2762 return m_runStatus == RanAtLeastOneSection ||
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2763 ( m_rootSection.hasUntestedSections() && m_changed );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2764 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2765
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2766 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2767 const TestCaseInfo* m_info;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2768 RunStatus m_runStatus;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2769 SectionInfo m_rootSection;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2770 SectionInfo* m_currentSection;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2771 SectionInfo* m_lastSectionToRun;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2772 bool m_changed;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2773 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2774 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2775
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2776 #include <set>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2777 #include <string>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2778
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2779 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2780
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2781 class StreamRedirect {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2782
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2783 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2784 StreamRedirect( std::ostream& stream, std::string& targetString )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2785 : m_stream( stream ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2786 m_prevBuf( stream.rdbuf() ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2787 m_targetString( targetString )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2788 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2789 stream.rdbuf( m_oss.rdbuf() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2790 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2791
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2792 ~StreamRedirect() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2793 m_targetString += m_oss.str();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2794 m_stream.rdbuf( m_prevBuf );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2795 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2796
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2797 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2798 std::ostream& m_stream;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2799 std::streambuf* m_prevBuf;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2800 std::ostringstream m_oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2801 std::string& m_targetString;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2802 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2803
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2804 ///////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2805
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2806 class Runner : public IResultCapture, public IRunner {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2807
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2808 Runner( const Runner& );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2809 void operator =( const Runner& );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2810
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2811 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2812
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2813 explicit Runner( Config& config )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2814 : m_context( getCurrentMutableContext() ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2815 m_runningTest( NULL ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2816 m_config( config ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2817 m_reporter( config.getReporter() ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2818 m_prevRunner( &m_context.getRunner() ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2819 m_prevResultCapture( &m_context.getResultCapture() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2820 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2821 m_context.setRunner( this );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2822 m_context.setConfig( &m_config );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2823 m_context.setResultCapture( this );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2824 m_reporter->StartTesting();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2825 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2826
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2827 ~Runner() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2828 m_reporter->EndTesting( m_totals );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2829 m_context.setRunner( m_prevRunner );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2830 m_context.setConfig( NULL );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2831 m_context.setResultCapture( m_prevResultCapture );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2832 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2833
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2834 virtual void runAll( bool runHiddenTests = false ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2835 const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2836 for( std::size_t i=0; i < allTests.size(); ++i ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2837 if( runHiddenTests || !allTests[i].isHidden() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2838 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2839 if( aborting() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2840 m_reporter->Aborted();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2841 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2842 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2843 runTest( allTests[i] );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2844 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2845 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2846 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2847
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2848 virtual std::size_t runMatching( const std::string& rawTestSpec ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2849 TestSpec testSpec( rawTestSpec );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2850
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2851 const std::vector<TestCaseInfo>& allTests = getCurrentContext().getTestCaseRegistry().getAllTests();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2852 std::size_t testsRun = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2853 for( std::size_t i=0; i < allTests.size(); ++i ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2854 if( testSpec.matches( allTests[i].getName() ) ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2855 if( aborting() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2856 m_reporter->Aborted();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2857 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2858 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2859 runTest( allTests[i] );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2860 testsRun++;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2861 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2862 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2863 return testsRun;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2864 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2865
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2866 void runTest( const TestCaseInfo& testInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2867 Totals prevTotals = m_totals;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2868
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2869 std::string redirectedCout;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2870 std::string redirectedCerr;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2871
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2872 m_reporter->StartTestCase( testInfo );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2873
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2874 m_runningTest = new RunningTest( &testInfo );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2875
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2876 do {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2877 do {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2878 // m_reporter->StartGroup( "test case run" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2879 m_currentResult.setLineInfo( m_runningTest->getTestCaseInfo().getLineInfo() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2880 runCurrentTest( redirectedCout, redirectedCerr );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2881 // m_reporter->EndGroup( "test case run", m_totals.delta( prevTotals ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2882 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2883 while( m_runningTest->hasUntestedSections() && !aborting() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2884 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2885 while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2886
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2887 delete m_runningTest;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2888 m_runningTest = NULL;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2889
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2890 Totals deltaTotals = m_totals.delta( prevTotals );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2891 m_totals.testCases += deltaTotals.testCases;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2892 m_reporter->EndTestCase( testInfo, deltaTotals, redirectedCout, redirectedCerr );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2893 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2894
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2895 virtual Totals getTotals() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2896 return m_totals;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2897 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2898
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2899 const Config& config() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2900 return m_config;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2901 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2902
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2903 private: // IResultCapture
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2904
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2905 virtual ResultAction::Value acceptResult( bool result ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2906 return acceptResult( result ? ResultWas::Ok : ResultWas::ExpressionFailed );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2907 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2908
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2909 virtual ResultAction::Value acceptResult( ResultWas::OfType result ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2910 m_currentResult.setResultType( result );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2911 return actOnCurrentResult();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2912 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2913
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2914 virtual ResultAction::Value acceptExpression( const ResultInfoBuilder& resultInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2915 m_currentResult = resultInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2916 return actOnCurrentResult();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2917 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2918
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2919 virtual void acceptMessage( const std::string& msg ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2920 m_currentResult.setMessage( msg );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2921 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2922
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2923 virtual void testEnded( const ResultInfo& result ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2924 if( result.getResultType() == ResultWas::Ok ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2925 m_totals.assertions.passed++;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2926 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2927 else if( !result.ok() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2928 m_totals.assertions.failed++;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2929
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2930 std::vector<ResultInfo>::const_iterator it = m_info.begin();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2931 std::vector<ResultInfo>::const_iterator itEnd = m_info.end();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2932 for(; it != itEnd; ++it )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2933 m_reporter->Result( *it );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2934 m_info.clear();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2935 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2936
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2937 if( result.getResultType() == ResultWas::Info )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2938 m_info.push_back( result );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2939 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2940 m_reporter->Result( result );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2941 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2942
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2943 virtual bool sectionStarted (
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2944 const std::string& name,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2945 const std::string& description,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2946 const SourceLineInfo& lineInfo,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2947 Counts& assertions
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2948 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2949 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2950 std::ostringstream oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2951 oss << name << "@" << lineInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2952
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2953 if( !m_runningTest->addSection( oss.str() ) )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2954 return false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2955
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2956 m_currentResult.setLineInfo( lineInfo );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2957 m_reporter->StartSection( name, description );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2958 assertions = m_totals.assertions;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2959
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2960 return true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2961 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2962
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2963 virtual void sectionEnded( const std::string& name, const Counts& prevAssertions ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2964 m_runningTest->endSection( name );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2965 m_reporter->EndSection( name, m_totals.assertions - prevAssertions );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2966 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2967
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2968 virtual void pushScopedInfo( ScopedInfo* scopedInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2969 m_scopedInfos.push_back( scopedInfo );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2970 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2971
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2972 virtual void popScopedInfo( ScopedInfo* scopedInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2973 if( m_scopedInfos.back() == scopedInfo )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2974 m_scopedInfos.pop_back();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2975 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2976
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2977 virtual bool shouldDebugBreak() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2978 return m_config.shouldDebugBreak();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2979 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2980
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2981 virtual std::string getCurrentTestName() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2982 return m_runningTest
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2983 ? m_runningTest->getTestCaseInfo().getName()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2984 : "";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2985 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2986
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2987 virtual const ResultInfo* getLastResult() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2988 return &m_lastResult;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2989 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2990
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2991 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2992
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2993 bool aborting() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2994 return m_totals.assertions.failed == static_cast<std::size_t>( m_config.getCutoff() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2995 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2996
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2997 ResultAction::Value actOnCurrentResult() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2998 testEnded( m_currentResult );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
2999 m_lastResult = m_currentResult;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3000
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3001 m_currentResult = ResultInfoBuilder();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3002
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3003 ResultAction::Value action = ResultAction::None;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3004
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3005 if( !m_lastResult.ok() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3006 action = ResultAction::Failed;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3007 if( shouldDebugBreak() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3008 action = (ResultAction::Value)( action | ResultAction::Debug );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3009 if( aborting() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3010 action = (ResultAction::Value)( action | ResultAction::Abort );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3011 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3012 return action;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3013 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3014
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3015 void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3016 try {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3017 m_runningTest->reset();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3018 if( m_reporter->shouldRedirectStdout() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3019 StreamRedirect coutRedir( std::cout, redirectedCout );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3020 StreamRedirect cerrRedir( std::cerr, redirectedCerr );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3021 m_runningTest->getTestCaseInfo().invoke();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3022 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3023 else {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3024 m_runningTest->getTestCaseInfo().invoke();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3025 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3026 m_runningTest->ranToCompletion();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3027 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3028 catch( TestFailureException& ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3029 // This just means the test was aborted due to failure
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3030 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3031 catch(...) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3032 acceptMessage( getCurrentContext().getExceptionTranslatorRegistry().translateActiveException() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3033 acceptResult( ResultWas::ThrewException );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3034 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3035 m_info.clear();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3036 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3037
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3038 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3039 IMutableContext& m_context;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3040 RunningTest* m_runningTest;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3041 ResultInfoBuilder m_currentResult;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3042 ResultInfo m_lastResult;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3043
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3044 const Config& m_config;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3045 Totals m_totals;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3046 Ptr<IReporter> m_reporter;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3047 std::vector<ScopedInfo*> m_scopedInfos;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3048 std::vector<ResultInfo> m_info;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3049 IRunner* m_prevRunner;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3050 IResultCapture* m_prevResultCapture;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3051 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3052
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3053 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3054
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3055 // #included from: catch_generators_impl.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3056
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3057 #include <vector>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3058 #include <string>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3059 #include <map>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3060
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3061 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3062
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3063 struct GeneratorInfo {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3064
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3065 GeneratorInfo( std::size_t size )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3066 : m_size( size ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3067 m_currentIndex( 0 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3068 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3069
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3070 bool moveNext() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3071 if( ++m_currentIndex == m_size ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3072 m_currentIndex = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3073 return false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3074 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3075 return true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3076 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3077
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3078 std::size_t getCurrentIndex() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3079 return m_currentIndex;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3080 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3081
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3082 std::size_t m_size;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3083 std::size_t m_currentIndex;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3084 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3085
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3086 ///////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3087
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3088 class GeneratorsForTest {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3089
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3090 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3091 ~GeneratorsForTest() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3092 deleteAll( m_generatorsInOrder );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3093 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3094
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3095 GeneratorInfo& getGeneratorInfo( const std::string& fileInfo, std::size_t size ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3096 std::map<std::string, GeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3097 if( it == m_generatorsByName.end() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3098 GeneratorInfo* info = new GeneratorInfo( size );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3099 m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3100 m_generatorsInOrder.push_back( info );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3101 return *info;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3102 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3103 return *it->second;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3104 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3105
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3106 bool moveNext() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3107 std::vector<GeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3108 std::vector<GeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3109 for(; it != itEnd; ++it ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3110 if( (*it)->moveNext() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3111 return true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3112 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3113 return false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3114 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3115
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3116 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3117 std::map<std::string, GeneratorInfo*> m_generatorsByName;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3118 std::vector<GeneratorInfo*> m_generatorsInOrder;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3119 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3120
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3121 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3122
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3123 #define INTERNAL_CATCH_LINESTR2( line ) #line
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3124 #define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3125
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3126 #define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3127
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3128 // #included from: catch_console_colour_impl.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3129
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3130 // #included from: catch_console_colour.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3131
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3132 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3133
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3134 struct ConsoleColourImpl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3135
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3136 class TextColour : NonCopyable {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3137 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3138
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3139 enum Colours {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3140 None,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3141
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3142 FileName,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3143 ResultError,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3144 ResultSuccess,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3145
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3146 Error,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3147 Success,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3148
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3149 OriginalExpression,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3150 ReconstructedExpression
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3151 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3152
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3153 TextColour( Colours colour = None );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3154 void set( Colours colour );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3155 ~TextColour();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3156
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3157 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3158 ConsoleColourImpl* m_impl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3159 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3160
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3161 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3162
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3163 #ifdef CATCH_PLATFORM_WINDOWS
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3164
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3165 #include <windows.h>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3166
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3167 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3168
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3169 namespace {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3170
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3171 WORD mapConsoleColour( TextColour::Colours colour ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3172 switch( colour ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3173 case TextColour::FileName:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3174 return FOREGROUND_INTENSITY; // greyed out
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3175 case TextColour::ResultError:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3176 return FOREGROUND_RED | FOREGROUND_INTENSITY; // bright red
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3177 case TextColour::ResultSuccess:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3178 return FOREGROUND_GREEN | FOREGROUND_INTENSITY; // bright green
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3179 case TextColour::Error:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3180 return FOREGROUND_RED; // dark red
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3181 case TextColour::Success:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3182 return FOREGROUND_GREEN; // dark green
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3183 case TextColour::OriginalExpression:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3184 return FOREGROUND_BLUE | FOREGROUND_GREEN; // turquoise
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3185 case TextColour::ReconstructedExpression:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3186 return FOREGROUND_RED | FOREGROUND_GREEN; // greeny-yellow
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3187 default: return 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3188 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3189 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3190 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3191
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3192 struct ConsoleColourImpl {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3193
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3194 ConsoleColourImpl()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3195 : hStdout( GetStdHandle(STD_OUTPUT_HANDLE) ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3196 wOldColorAttrs( 0 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3197 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3198 GetConsoleScreenBufferInfo( hStdout, &csbiInfo );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3199 wOldColorAttrs = csbiInfo.wAttributes;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3200 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3201
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3202 ~ConsoleColourImpl() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3203 SetConsoleTextAttribute( hStdout, wOldColorAttrs );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3204 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3205
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3206 void set( TextColour::Colours colour ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3207 WORD consoleColour = mapConsoleColour( colour );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3208 if( consoleColour > 0 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3209 SetConsoleTextAttribute( hStdout, consoleColour );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3210 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3211
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3212 HANDLE hStdout;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3213 CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3214 WORD wOldColorAttrs;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3215 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3216
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3217 TextColour::TextColour( Colours colour )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3218 : m_impl( new ConsoleColourImpl() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3219 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3220 if( colour )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3221 m_impl->set( colour );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3222 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3223
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3224 TextColour::~TextColour() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3225 delete m_impl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3226 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3227
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3228 void TextColour::set( Colours colour ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3229 m_impl->set( colour );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3230 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3231
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3232 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3233
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3234 #else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3235
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3236 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3237 TextColour::TextColour( Colours ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3238 TextColour::~TextColour(){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3239 void TextColour::set( Colours ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3240
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3241 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3242
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3243 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3244
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3245
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3246 // #included from: catch_exception_translator_registry.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3247
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3248 #ifdef __OBJC__
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3249 #import "Foundation/Foundation.h"
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3250 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3251
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3252 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3253
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3254 class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3255
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3256 ~ExceptionTranslatorRegistry() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3257 deleteAll( m_translators );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3258 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3259
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3260 virtual void registerTranslator( IExceptionTranslator* translator ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3261 m_translators.push_back( translator );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3262 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3263
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3264 virtual std::string translateActiveException() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3265 try {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3266 #ifdef __OBJC__
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3267 // In Objective-C try objective-c exceptions first
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3268 @try {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3269 throw;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3270 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3271 @catch (NSException *exception) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3272 return toString( [exception description] );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3273 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3274 #else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3275 throw;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3276 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3277 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3278 catch( std::exception& ex ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3279 return ex.what();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3280 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3281 catch( std::string& msg ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3282 return msg;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3283 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3284 catch( const char* msg ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3285 return msg;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3286 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3287 catch(...) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3288 return tryTranslators( m_translators.begin() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3289 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3290 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3291
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3292 std::string tryTranslators( std::vector<IExceptionTranslator*>::const_iterator it ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3293 if( it == m_translators.end() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3294 return "Unknown exception";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3295
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3296 try {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3297 return (*it)->translate();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3298 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3299 catch(...) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3300 return tryTranslators( it+1 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3301 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3302 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3303
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3304 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3305 std::vector<IExceptionTranslator*> m_translators;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3306 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3307 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3308
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3309 // #included from: catch_reporter_registry.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3310
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3311 #include <map>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3312
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3313 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3314
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3315 class ReporterRegistry : public IReporterRegistry {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3316
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3317 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3318
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3319 ~ReporterRegistry() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3320 deleteAllValues( m_factories );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3321 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3322
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3323 virtual IReporter* create( const std::string& name, const IReporterConfig& config ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3324 FactoryMap::const_iterator it = m_factories.find( name );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3325 if( it == m_factories.end() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3326 return NULL;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3327 return it->second->create( config );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3328 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3329
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3330 void registerReporter( const std::string& name, IReporterFactory* factory ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3331 m_factories.insert( std::make_pair( name, factory ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3332 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3333
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3334 const FactoryMap& getFactories() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3335 return m_factories;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3336 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3337
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3338 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3339 FactoryMap m_factories;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3340 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3341 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3342
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3343 // #included from: catch_stream.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3344
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3345 #include <stdexcept>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3346 #include <cstdio>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3347
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3348 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3349
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3350 template<typename WriterF, size_t bufferSize=256>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3351 class StreamBufImpl : public StreamBufBase {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3352 char data[bufferSize];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3353 WriterF m_writer;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3354
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3355 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3356 StreamBufImpl() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3357 setp( data, data + sizeof(data) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3358 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3359
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3360 ~StreamBufImpl() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3361 sync();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3362 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3363
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3364 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3365 int overflow( int c ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3366 sync();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3367
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3368 if( c != EOF ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3369 if( pbase() == epptr() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3370 m_writer( std::string( 1, static_cast<char>( c ) ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3371 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3372 sputc( static_cast<char>( c ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3373 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3374 return 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3375 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3376
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3377 int sync() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3378 if( pbase() != pptr() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3379 m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3380 setp( pbase(), epptr() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3381 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3382 return 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3383 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3384 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3385
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3386 ///////////////////////////////////////////////////////////////////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3387
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3388 struct OutputDebugWriter {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3389
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3390 void operator()( const std::string &str ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3391 writeToDebugConsole( str );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3392 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3393 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3394 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3395
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3396 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3397
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3398 namespace {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3399 Context* currentContext = NULL;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3400 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3401 IMutableContext& getCurrentMutableContext() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3402 if( !currentContext )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3403 currentContext = new Context();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3404 return *currentContext;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3405 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3406 IContext& getCurrentContext() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3407 return getCurrentMutableContext();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3408 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3409
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3410 Context::Context()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3411 : m_reporterRegistry( new ReporterRegistry ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3412 m_testCaseRegistry( new TestRegistry ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3413 m_exceptionTranslatorRegistry( new ExceptionTranslatorRegistry ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3414 m_config( NULL )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3415 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3416
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3417 void Context::cleanUp() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3418 delete currentContext;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3419 currentContext = NULL;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3420 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3421
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3422 void Context::setRunner( IRunner* runner ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3423 m_runner = runner;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3424 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3425
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3426 void Context::setResultCapture( IResultCapture* resultCapture ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3427 m_resultCapture = resultCapture;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3428 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3429
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3430 const IConfig* Context::getConfig() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3431 return m_config;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3432 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3433 void Context::setConfig( const IConfig* config ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3434 m_config = config;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3435 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3436
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3437 IResultCapture& Context::getResultCapture() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3438 return *m_resultCapture;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3439 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3440
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3441 IRunner& Context::getRunner() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3442 return *m_runner;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3443 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3444
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3445 IReporterRegistry& Context::getReporterRegistry() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3446 return *m_reporterRegistry.get();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3447 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3448
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3449 ITestCaseRegistry& Context::getTestCaseRegistry() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3450 return *m_testCaseRegistry.get();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3451 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3452
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3453 IExceptionTranslatorRegistry& Context::getExceptionTranslatorRegistry() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3454 return *m_exceptionTranslatorRegistry.get();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3455 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3456
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3457 std::streambuf* Context::createStreamBuf( const std::string& streamName ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3458 if( streamName == "stdout" ) return std::cout.rdbuf();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3459 if( streamName == "stderr" ) return std::cerr.rdbuf();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3460 if( streamName == "debug" ) return new StreamBufImpl<OutputDebugWriter>;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3461
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3462 throw std::domain_error( "Unknown stream: " + streamName );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3463 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3464
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3465 GeneratorsForTest* Context::findGeneratorsForCurrentTest() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3466 std::string testName = getResultCapture().getCurrentTestName();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3467
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3468 std::map<std::string, GeneratorsForTest*>::const_iterator it =
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3469 m_generatorsByTestName.find( testName );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3470 return it != m_generatorsByTestName.end()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3471 ? it->second
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3472 : NULL;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3473 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3474
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3475 GeneratorsForTest& Context::getGeneratorsForCurrentTest() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3476 GeneratorsForTest* generators = findGeneratorsForCurrentTest();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3477 if( !generators ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3478 std::string testName = getResultCapture().getCurrentTestName();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3479 generators = new GeneratorsForTest();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3480 m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3481 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3482 return *generators;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3483 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3484
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3485 size_t Context::getGeneratorIndex( const std::string& fileInfo, size_t totalSize ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3486 return getGeneratorsForCurrentTest()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3487 .getGeneratorInfo( fileInfo, totalSize )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3488 .getCurrentIndex();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3489 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3490
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3491 bool Context::advanceGeneratorsForCurrentTest() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3492 GeneratorsForTest* generators = findGeneratorsForCurrentTest();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3493 return generators && generators->moveNext();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3494 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3495 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3496 // #included from: internal/catch_commandline.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3497
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3498 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3499
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3500 class Command {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3501 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3502 Command(){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3503
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3504 explicit Command( const std::string& name ) : m_name( name ) {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3505
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3506 Command& operator += ( const std::string& arg ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3507 m_args.push_back( arg );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3508 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3509 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3510 Command& operator += ( const Command& other ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3511 std::copy( other.m_args.begin(), other.m_args.end(), std::back_inserter( m_args ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3512 if( m_name.empty() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3513 m_name = other.m_name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3514 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3515 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3516 Command operator + ( const Command& other ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3517 Command newCommand( *this );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3518 newCommand += other;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3519 return newCommand;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3520 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3521
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3522 operator SafeBool::type() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3523 return SafeBool::makeSafe( !m_name.empty() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3524 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3525
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3526 std::string name() const { return m_name; }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3527 std::string operator[]( std::size_t i ) const { return m_args[i]; }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3528 std::size_t argsCount() const { return m_args.size(); }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3529
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3530 void raiseError( const std::string& message ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3531 std::ostringstream oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3532 oss << "Error while parsing " << m_name << ". " << message << ".";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3533 if( m_args.size() > 0 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3534 oss << " Arguments where:";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3535 for( std::size_t i = 0; i < m_args.size(); ++i )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3536 oss << " " << m_args[i];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3537 throw std::domain_error( oss.str() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3538 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3539
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3540 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3541
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3542 std::string m_name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3543 std::vector<std::string> m_args;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3544 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3545
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3546 class CommandParser {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3547 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3548 CommandParser( int argc, char const * const * argv ) : m_argc( static_cast<std::size_t>( argc ) ), m_argv( argv ) {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3549
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3550 Command find( const std::string& arg1, const std::string& arg2, const std::string& arg3 ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3551 return find( arg1 ) + find( arg2 ) + find( arg3 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3552 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3553
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3554 Command find( const std::string& shortArg, const std::string& longArg ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3555 return find( shortArg ) + find( longArg );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3556 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3557 Command find( const std::string& arg ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3558 for( std::size_t i = 0; i < m_argc; ++i )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3559 if( m_argv[i] == arg )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3560 return getArgs( i );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3561 return Command();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3562 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3563
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3564 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3565 Command getArgs( std::size_t from ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3566 Command command( m_argv[from] );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3567 for( std::size_t i = from+1; i < m_argc && m_argv[i][0] != '-'; ++i )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3568 command += m_argv[i];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3569 return command;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3570 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3571
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3572 std::size_t m_argc;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3573 char const * const * m_argv;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3574 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3575
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3576 inline bool parseIntoConfig( const CommandParser& parser, Config& config ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3577
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3578 try {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3579 if( Command cmd = parser.find( "-l", "--list" ) ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3580 if( cmd.argsCount() > 2 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3581 cmd.raiseError( "Expected upto 2 arguments" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3582
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3583 List::What listSpec = List::All;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3584 if( cmd.argsCount() >= 1 ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3585 if( cmd[0] == "tests" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3586 listSpec = List::Tests;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3587 else if( cmd[0] == "reporters" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3588 listSpec = List::Reports;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3589 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3590 cmd.raiseError( "Expected [tests] or [reporters]" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3591 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3592 if( cmd.argsCount() >= 2 ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3593 if( cmd[1] == "xml" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3594 listSpec = static_cast<List::What>( listSpec | List::AsXml );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3595 else if( cmd[1] == "text" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3596 listSpec = static_cast<List::What>( listSpec | List::AsText );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3597 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3598 cmd.raiseError( "Expected [xml] or [text]" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3599 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3600 config.setListSpec( static_cast<List::What>( config.getListSpec() | listSpec ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3601 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3602
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3603 if( Command cmd = parser.find( "-t", "--test" ) ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3604 if( cmd.argsCount() == 0 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3605 cmd.raiseError( "Expected at least one argument" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3606 for( std::size_t i = 0; i < cmd.argsCount(); ++i )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3607 config.addTestSpec( cmd[i] );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3608 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3609
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3610 if( Command cmd = parser.find( "-r", "--reporter" ) ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3611 if( cmd.argsCount() != 1 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3612 cmd.raiseError( "Expected one argument" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3613 config.setReporter( cmd[0] );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3614 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3615
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3616 if( Command cmd = parser.find( "-o", "--out" ) ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3617 if( cmd.argsCount() == 0 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3618 cmd.raiseError( "Expected filename" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3619 if( cmd[0][0] == '%' )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3620 config.useStream( cmd[0].substr( 1 ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3621 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3622 config.setFilename( cmd[0] );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3623 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3624
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3625 if( Command cmd = parser.find( "-s", "--success" ) ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3626 if( cmd.argsCount() != 0 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3627 cmd.raiseError( "Does not accept arguments" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3628 config.setIncludeWhichResults( Include::SuccessfulResults );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3629 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3630
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3631 if( Command cmd = parser.find( "-b", "--break" ) ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3632 if( cmd.argsCount() != 0 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3633 cmd.raiseError( "Does not accept arguments" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3634 config.setShouldDebugBreak( true );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3635 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3636
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3637 if( Command cmd = parser.find( "-n", "--name" ) ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3638 if( cmd.argsCount() != 1 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3639 cmd.raiseError( "Expected a name" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3640 config.setName( cmd[0] );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3641 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3642
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3643 if( Command cmd = parser.find( "-h", "-?", "--help" ) ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3644 if( cmd.argsCount() != 0 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3645 cmd.raiseError( "Does not accept arguments" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3646 config.setShowHelp( true );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3647 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3648
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3649 if( Command cmd = parser.find( "-a", "--abort" ) ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3650 if( cmd.argsCount() > 1 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3651 cmd.raiseError( "Only accepts 0-1 arguments" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3652 int threshold = 1;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3653 if( cmd.argsCount() == 1 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3654 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3655 std::stringstream ss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3656 ss << cmd[0];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3657 ss >> threshold;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3658 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3659 config.setCutoff( threshold );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3660 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3661
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3662 if( Command cmd = parser.find( "-nt", "--nothrow" ) ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3663 if( cmd.argsCount() != 0 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3664 cmd.raiseError( "Does not accept arguments" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3665 config.setAllowThrows( false );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3666 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3667
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3668 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3669 catch( std::exception& ex ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3670 config.setError( ex.what() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3671 return false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3672 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3673 return true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3674 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3675
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3676 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3677
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3678 // #included from: internal/catch_list.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3679
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3680 #include <limits>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3681
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3682 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3683 inline int List( Config& config ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3684
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3685 IContext& context = getCurrentContext();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3686 if( config.listWhat() & List::Reports ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3687 std::cout << "Available reports:\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3688 IReporterRegistry::FactoryMap::const_iterator it = context.getReporterRegistry().getFactories().begin();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3689 IReporterRegistry::FactoryMap::const_iterator itEnd = context.getReporterRegistry().getFactories().end();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3690 for(; it != itEnd; ++it ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3691 // !TBD: consider listAs()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3692 std::cout << "\t" << it->first << "\n\t\t'" << it->second->getDescription() << "'\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3693 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3694 std::cout << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3695 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3696
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3697 if( config.listWhat() & List::Tests ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3698 std::cout << "Available tests:\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3699 std::vector<TestCaseInfo>::const_iterator it = context.getTestCaseRegistry().getAllTests().begin();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3700 std::vector<TestCaseInfo>::const_iterator itEnd = context.getTestCaseRegistry().getAllTests().end();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3701 for(; it != itEnd; ++it ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3702 // !TBD: consider listAs()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3703 std::cout << "\t" << it->getName() << "\n\t\t '" << it->getDescription() << "'\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3704 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3705 std::cout << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3706 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3707
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3708 if( ( config.listWhat() & List::All ) == 0 ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3709 std::cerr << "Unknown list type" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3710 return (std::numeric_limits<int>::max)();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3711 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3712
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3713 if( config.getReporter().get() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3714 std::cerr << "Reporters ignored when listing" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3715 if( !config.testsSpecified() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3716 std::cerr << "Test specs ignored when listing" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3717 return 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3718 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3719
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3720 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3721
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3722 // #included from: reporters/catch_reporter_basic.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3723
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3724 // #included from: ../internal/catch_reporter_registrars.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3725
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3726 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3727
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3728 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3729 class ReporterRegistrar {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3730
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3731 class ReporterFactory : public IReporterFactory {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3732
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3733 virtual IReporter* create( const IReporterConfig& config ) const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3734 return new T( config );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3735 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3736
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3737 virtual std::string getDescription() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3738 return T::getDescription();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3739 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3740 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3741
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3742 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3743
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3744 ReporterRegistrar( const std::string& name ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3745 getCurrentContext().getReporterRegistry().registerReporter( name, new ReporterFactory() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3746 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3747 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3748 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3749
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3750 #define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3751 Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3752
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3753 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3754
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3755 struct pluralise {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3756 pluralise( std::size_t count, const std::string& label )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3757 : m_count( count ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3758 m_label( label )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3759 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3760
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3761 friend std::ostream& operator << ( std::ostream& os, const pluralise& pluraliser ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3762 os << pluraliser.m_count << " " << pluraliser.m_label;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3763 if( pluraliser.m_count != 1 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3764 os << "s";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3765 return os;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3766 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3767
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3768 std::size_t m_count;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3769 std::string m_label;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3770 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3771
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3772 class BasicReporter : public SharedImpl<IReporter> {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3773
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3774 struct SpanInfo {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3775
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3776 SpanInfo()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3777 : emitted( false )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3778 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3779
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3780 SpanInfo( const std::string& spanName )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3781 : name( spanName ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3782 emitted( false )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3783 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3784
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3785 SpanInfo( const SpanInfo& other )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3786 : name( other.name ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3787 emitted( other.emitted )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3788 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3789
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3790 std::string name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3791 bool emitted;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3792 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3793
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3794 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3795 BasicReporter( const IReporterConfig& config )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3796 : m_config( config ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3797 m_firstSectionInTestCase( true ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3798 m_aborted( false )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3799 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3800
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3801 static std::string getDescription() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3802 return "Reports test results as lines of text";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3803 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3804
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3805 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3806
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3807 void ReportCounts( const std::string& label, const Counts& counts, const std::string& allPrefix = "All " ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3808 if( counts.passed )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3809 m_config.stream() << counts.failed << " of " << counts.total() << " " << label << "s failed";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3810 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3811 m_config.stream() << ( counts.failed > 1 ? allPrefix : "" ) << pluralise( counts.failed, label ) << " failed";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3812 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3813
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3814 void ReportCounts( const Totals& totals, const std::string& allPrefix = "All " ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3815 if( totals.assertions.total() == 0 ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3816 m_config.stream() << "No tests ran";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3817 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3818 else if( totals.assertions.failed ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3819 TextColour colour( TextColour::ResultError );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3820 ReportCounts( "test case", totals.testCases, allPrefix );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3821 if( totals.testCases.failed > 0 ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3822 m_config.stream() << " (";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3823 ReportCounts( "assertion", totals.assertions, allPrefix );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3824 m_config.stream() << ")";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3825 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3826 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3827 else {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3828 TextColour colour( TextColour::ResultSuccess );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3829 m_config.stream() << allPrefix << "tests passed ("
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3830 << pluralise( totals.assertions.passed, "assertion" ) << " in "
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3831 << pluralise( totals.testCases.passed, "test case" ) << ")";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3832 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3833 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3834
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3835 private: // IReporter
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3836
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3837 virtual bool shouldRedirectStdout() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3838 return false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3839 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3840
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3841 virtual void StartTesting() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3842 m_testingSpan = SpanInfo();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3843 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3844
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3845 virtual void Aborted() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3846 m_aborted = true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3847 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3848
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3849 virtual void EndTesting( const Totals& totals ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3850 // Output the overall test results even if "Started Testing" was not emitted
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3851 if( m_aborted ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3852 m_config.stream() << "\n[Testing aborted. ";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3853 ReportCounts( totals, "The first " );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3854 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3855 else {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3856 m_config.stream() << "\n[Testing completed. ";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3857 ReportCounts( totals );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3858 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3859 m_config.stream() << "]\n" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3860 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3861
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3862 virtual void StartGroup( const std::string& groupName ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3863 m_groupSpan = groupName;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3864 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3865
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3866 virtual void EndGroup( const std::string& groupName, const Totals& totals ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3867 if( m_groupSpan.emitted && !groupName.empty() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3868 m_config.stream() << "[End of group: '" << groupName << "'. ";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3869 ReportCounts( totals );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3870 m_config.stream() << "]\n" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3871 m_groupSpan = SpanInfo();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3872 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3873 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3874
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3875 virtual void StartTestCase( const TestCaseInfo& testInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3876 m_testSpan = testInfo.getName();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3877 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3878
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3879 virtual void StartSection( const std::string& sectionName, const std::string& ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3880 m_sectionSpans.push_back( SpanInfo( sectionName ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3881 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3882
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3883 virtual void EndSection( const std::string& sectionName, const Counts& assertions ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3884 SpanInfo& sectionSpan = m_sectionSpans.back();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3885 if( sectionSpan.emitted && !sectionSpan.name.empty() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3886 m_config.stream() << "[End of section: '" << sectionName << "' ";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3887
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3888 if( assertions.failed ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3889 TextColour colour( TextColour::ResultError );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3890 ReportCounts( "assertion", assertions);
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3891 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3892 else {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3893 TextColour colour( TextColour::ResultSuccess );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3894 m_config.stream() << ( assertions.passed > 1 ? "All " : "" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3895 << pluralise( assertions.passed, "assertion" ) << "passed" ;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3896 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3897 m_config.stream() << "]\n" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3898 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3899 m_sectionSpans.pop_back();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3900 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3901
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3902 virtual void Result( const ResultInfo& resultInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3903 if( !m_config.includeSuccessfulResults() && resultInfo.getResultType() == ResultWas::Ok )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3904 return;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3905
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3906 StartSpansLazily();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3907
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3908 if( !resultInfo.getFilename().empty() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3909 TextColour colour( TextColour::FileName );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3910 m_config.stream() << SourceLineInfo( resultInfo.getFilename(), resultInfo.getLine() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3911 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3912
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3913 if( resultInfo.hasExpression() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3914 TextColour colour( TextColour::OriginalExpression );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3915 m_config.stream() << resultInfo.getExpression();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3916 if( resultInfo.ok() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3917 TextColour successColour( TextColour::Success );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3918 m_config.stream() << " succeeded";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3919 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3920 else {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3921 TextColour errorColour( TextColour::Error );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3922 m_config.stream() << " failed";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3923 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3924 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3925 switch( resultInfo.getResultType() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3926 case ResultWas::ThrewException:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3927 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3928 TextColour colour( TextColour::Error );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3929 if( resultInfo.hasExpression() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3930 m_config.stream() << " with unexpected";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3931 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3932 m_config.stream() << "Unexpected";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3933 m_config.stream() << " exception with message: '" << resultInfo.getMessage() << "'";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3934 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3935 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3936 case ResultWas::DidntThrowException:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3937 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3938 TextColour colour( TextColour::Error );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3939 if( resultInfo.hasExpression() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3940 m_config.stream() << " because no exception was thrown where one was expected";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3941 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3942 m_config.stream() << "No exception thrown where one was expected";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3943 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3944 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3945 case ResultWas::Info:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3946 streamVariableLengthText( "info", resultInfo.getMessage() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3947 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3948 case ResultWas::Warning:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3949 m_config.stream() << "warning:\n'" << resultInfo.getMessage() << "'";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3950 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3951 case ResultWas::ExplicitFailure:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3952 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3953 TextColour colour( TextColour::Error );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3954 m_config.stream() << "failed with message: '" << resultInfo.getMessage() << "'";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3955 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3956 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3957 case ResultWas::Unknown: // These cases are here to prevent compiler warnings
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3958 case ResultWas::Ok:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3959 case ResultWas::FailureBit:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3960 case ResultWas::ExpressionFailed:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3961 case ResultWas::Exception:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3962 default:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3963 if( !resultInfo.hasExpression() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3964 if( resultInfo.ok() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3965 TextColour colour( TextColour::Success );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3966 m_config.stream() << " succeeded";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3967 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3968 else {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3969 TextColour colour( TextColour::Error );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3970 m_config.stream() << " failed";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3971 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3972 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3973 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3974 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3975
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3976 if( resultInfo.hasExpandedExpression() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3977 m_config.stream() << " for: ";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3978 TextColour colour( TextColour::ReconstructedExpression );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3979 m_config.stream() << resultInfo.getExpandedExpression();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3980 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3981 m_config.stream() << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3982 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3983
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3984 virtual void EndTestCase( const TestCaseInfo& testInfo,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3985 const Totals& totals,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3986 const std::string& stdOut,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3987 const std::string& stdErr ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3988 if( !stdOut.empty() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3989 StartSpansLazily();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3990 streamVariableLengthText( "stdout", stdOut );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3991 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3992
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3993 if( !stdErr.empty() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3994 StartSpansLazily();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3995 streamVariableLengthText( "stderr", stdErr );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3996 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3997
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3998 if( m_testSpan.emitted ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
3999 m_config.stream() << "[Finished: '" << testInfo.getName() << "' ";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4000 ReportCounts( totals );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4001 m_config.stream() << "]" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4002 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4003 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4004
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4005 private: // helpers
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4006
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4007 void StartSpansLazily() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4008 if( !m_testingSpan.emitted ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4009 if( m_config.getName().empty() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4010 m_config.stream() << "[Started testing]" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4011 else
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4012 m_config.stream() << "[Started testing: " << m_config.getName() << "]" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4013 m_testingSpan.emitted = true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4014 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4015
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4016 if( !m_groupSpan.emitted && !m_groupSpan.name.empty() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4017 m_config.stream() << "[Started group: '" << m_groupSpan.name << "']" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4018 m_groupSpan.emitted = true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4019 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4020
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4021 if( !m_testSpan.emitted ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4022 m_config.stream() << std::endl << "[Running: " << m_testSpan.name << "]" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4023 m_testSpan.emitted = true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4024 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4025
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4026 if( !m_sectionSpans.empty() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4027 SpanInfo& sectionSpan = m_sectionSpans.back();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4028 if( !sectionSpan.emitted && !sectionSpan.name.empty() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4029 if( m_firstSectionInTestCase ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4030 m_config.stream() << "\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4031 m_firstSectionInTestCase = false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4032 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4033 std::vector<SpanInfo>::iterator it = m_sectionSpans.begin();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4034 std::vector<SpanInfo>::iterator itEnd = m_sectionSpans.end();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4035 for(; it != itEnd; ++it ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4036 SpanInfo& prevSpan = *it;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4037 if( !prevSpan.emitted && !prevSpan.name.empty() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4038 m_config.stream() << "[Started section: '" << prevSpan.name << "']" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4039 prevSpan.emitted = true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4040 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4041 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4042 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4043 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4044 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4045
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4046 void streamVariableLengthText( const std::string& prefix, const std::string& text ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4047 std::string trimmed = trim( text );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4048 if( trimmed.find_first_of( "\r\n" ) == std::string::npos ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4049 m_config.stream() << "[" << prefix << ": " << trimmed << "]\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4050 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4051 else {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4052 m_config.stream() << "\n[" << prefix << "] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" << trimmed
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4053 << "\n[end of " << prefix << "] <<<<<<<<<<<<<<<<<<<<<<<<\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4054 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4055 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4056
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4057 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4058 const IReporterConfig& m_config;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4059 bool m_firstSectionInTestCase;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4060
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4061 SpanInfo m_testingSpan;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4062 SpanInfo m_groupSpan;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4063 SpanInfo m_testSpan;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4064 std::vector<SpanInfo> m_sectionSpans;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4065 bool m_aborted;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4066 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4067
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4068 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4069
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4070 // #included from: reporters/catch_reporter_xml.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4071
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4072 // #included from: ../internal/catch_xmlwriter.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4073
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4074 #include <sstream>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4075 #include <string>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4076 #include <vector>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4077
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4078 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4079
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4080 class XmlWriter {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4081 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4082
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4083 class ScopedElement {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4084 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4085 ScopedElement( XmlWriter* writer )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4086 : m_writer( writer )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4087 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4088
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4089 ScopedElement( const ScopedElement& other )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4090 : m_writer( other.m_writer ){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4091 other.m_writer = NULL;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4092 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4093
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4094 ~ScopedElement() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4095 if( m_writer )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4096 m_writer->endElement();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4097 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4098
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4099 ScopedElement& writeText( const std::string& text ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4100 m_writer->writeText( text );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4101 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4102 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4103
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4104 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4105 ScopedElement& writeAttribute( const std::string& name, const T& attribute ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4106 m_writer->writeAttribute( name, attribute );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4107 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4108 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4109
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4110 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4111 mutable XmlWriter* m_writer;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4112 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4113
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4114 XmlWriter()
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4115 : m_tagIsOpen( false ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4116 m_needsNewline( false ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4117 m_os( &std::cout )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4118 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4119
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4120 XmlWriter( std::ostream& os )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4121 : m_tagIsOpen( false ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4122 m_needsNewline( false ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4123 m_os( &os )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4124 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4125
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4126 ~XmlWriter() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4127 while( !m_tags.empty() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4128 endElement();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4129 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4130
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4131 XmlWriter& operator = ( const XmlWriter& other ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4132 XmlWriter temp( other );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4133 swap( temp );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4134 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4135 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4136
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4137 void swap( XmlWriter& other ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4138 std::swap( m_tagIsOpen, other.m_tagIsOpen );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4139 std::swap( m_needsNewline, other.m_needsNewline );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4140 std::swap( m_tags, other.m_tags );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4141 std::swap( m_indent, other.m_indent );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4142 std::swap( m_os, other.m_os );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4143 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4144
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4145 XmlWriter& startElement( const std::string& name ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4146 ensureTagClosed();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4147 newlineIfNecessary();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4148 stream() << m_indent << "<" << name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4149 m_tags.push_back( name );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4150 m_indent += " ";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4151 m_tagIsOpen = true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4152 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4153 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4154
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4155 ScopedElement scopedElement( const std::string& name ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4156 ScopedElement scoped( this );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4157 startElement( name );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4158 return scoped;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4159 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4160
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4161 XmlWriter& endElement() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4162 newlineIfNecessary();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4163 m_indent = m_indent.substr( 0, m_indent.size()-2 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4164 if( m_tagIsOpen ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4165 stream() << "/>\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4166 m_tagIsOpen = false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4167 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4168 else {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4169 stream() << m_indent << "</" << m_tags.back() << ">\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4170 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4171 m_tags.pop_back();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4172 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4173 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4174
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4175 XmlWriter& writeAttribute( const std::string& name, const std::string& attribute ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4176 if( !name.empty() && !attribute.empty() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4177 stream() << " " << name << "=\"";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4178 writeEncodedText( attribute );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4179 stream() << "\"";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4180 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4181 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4182 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4183
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4184 XmlWriter& writeAttribute( const std::string& name, bool attribute ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4185 stream() << " " << name << "=\"" << ( attribute ? "true" : "false" ) << "\"";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4186 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4187 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4188
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4189 template<typename T>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4190 XmlWriter& writeAttribute( const std::string& name, const T& attribute ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4191 if( !name.empty() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4192 stream() << " " << name << "=\"" << attribute << "\"";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4193 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4194 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4195
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4196 XmlWriter& writeText( const std::string& text ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4197 if( !text.empty() ){
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4198 bool tagWasOpen = m_tagIsOpen;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4199 ensureTagClosed();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4200 if( tagWasOpen )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4201 stream() << m_indent;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4202 writeEncodedText( text );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4203 m_needsNewline = true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4204 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4205 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4206 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4207
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4208 XmlWriter& writeComment( const std::string& text ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4209 ensureTagClosed();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4210 stream() << m_indent << "<!--" << text << "-->";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4211 m_needsNewline = true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4212 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4213 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4214
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4215 XmlWriter& writeBlankLine() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4216 ensureTagClosed();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4217 stream() << "\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4218 return *this;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4219 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4220
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4221 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4222
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4223 std::ostream& stream() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4224 return *m_os;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4225 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4226
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4227 void ensureTagClosed() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4228 if( m_tagIsOpen ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4229 stream() << ">\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4230 m_tagIsOpen = false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4231 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4232 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4233
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4234 void newlineIfNecessary() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4235 if( m_needsNewline ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4236 stream() << "\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4237 m_needsNewline = false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4238 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4239 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4240
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4241 void writeEncodedText( const std::string& text ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4242 static const char* charsToEncode = "<&\"";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4243 std::string mtext = text;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4244 std::string::size_type pos = mtext.find_first_of( charsToEncode );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4245 while( pos != std::string::npos ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4246 stream() << mtext.substr( 0, pos );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4247
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4248 switch( mtext[pos] ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4249 case '<':
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4250 stream() << "&lt;";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4251 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4252 case '&':
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4253 stream() << "&amp;";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4254 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4255 case '\"':
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4256 stream() << "&quot;";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4257 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4258 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4259 mtext = mtext.substr( pos+1 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4260 pos = mtext.find_first_of( charsToEncode );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4261 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4262 stream() << mtext;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4263 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4264
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4265 bool m_tagIsOpen;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4266 bool m_needsNewline;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4267 std::vector<std::string> m_tags;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4268 std::string m_indent;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4269 std::ostream* m_os;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4270 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4271
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4272 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4273 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4274 class XmlReporter : public SharedImpl<IReporter> {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4275 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4276 XmlReporter( const IReporterConfig& config ) : m_config( config ) {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4277
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4278 static std::string getDescription() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4279 return "Reports test results as an XML document";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4280 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4281
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4282 private: // IReporter
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4283
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4284 virtual bool shouldRedirectStdout() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4285 return true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4286 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4287
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4288 virtual void StartTesting() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4289 m_xml = XmlWriter( m_config.stream() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4290 m_xml.startElement( "Catch" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4291 if( !m_config.getName().empty() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4292 m_xml.writeAttribute( "name", m_config.getName() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4293 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4294
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4295 virtual void EndTesting( const Totals& totals ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4296 m_xml.scopedElement( "OverallResults" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4297 .writeAttribute( "successes", totals.assertions.passed )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4298 .writeAttribute( "failures", totals.assertions.failed );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4299 m_xml.endElement();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4300 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4301
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4302 virtual void StartGroup( const std::string& groupName ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4303 m_xml.startElement( "Group" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4304 .writeAttribute( "name", groupName );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4305 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4306
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4307 virtual void EndGroup( const std::string&, const Totals& totals ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4308 m_xml.scopedElement( "OverallResults" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4309 .writeAttribute( "successes", totals.assertions.passed )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4310 .writeAttribute( "failures", totals.assertions.failed );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4311 m_xml.endElement();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4312 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4313
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4314 virtual void StartSection( const std::string& sectionName, const std::string& description ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4315 m_xml.startElement( "Section" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4316 .writeAttribute( "name", sectionName )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4317 .writeAttribute( "description", description );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4318 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4319
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4320 virtual void EndSection( const std::string& /*sectionName*/, const Counts& assertions ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4321 m_xml.scopedElement( "OverallResults" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4322 .writeAttribute( "successes", assertions.passed )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4323 .writeAttribute( "failures", assertions.failed );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4324 m_xml.endElement();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4325 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4326
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4327 virtual void StartTestCase( const Catch::TestCaseInfo& testInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4328 m_xml.startElement( "TestCase" ).writeAttribute( "name", testInfo.getName() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4329 m_currentTestSuccess = true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4330 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4331
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4332 virtual void Result( const Catch::ResultInfo& resultInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4333 if( !m_config.includeSuccessfulResults() && resultInfo.getResultType() == ResultWas::Ok )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4334 return;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4335
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4336 if( resultInfo.hasExpression() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4337 m_xml.startElement( "Expression" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4338 .writeAttribute( "success", resultInfo.ok() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4339 .writeAttribute( "filename", resultInfo.getFilename() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4340 .writeAttribute( "line", resultInfo.getLine() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4341
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4342 m_xml.scopedElement( "Original" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4343 .writeText( resultInfo.getExpression() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4344 m_xml.scopedElement( "Expanded" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4345 .writeText( resultInfo.getExpandedExpression() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4346 m_currentTestSuccess &= resultInfo.ok();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4347 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4348
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4349 switch( resultInfo.getResultType() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4350 case ResultWas::ThrewException:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4351 m_xml.scopedElement( "Exception" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4352 .writeAttribute( "filename", resultInfo.getFilename() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4353 .writeAttribute( "line", resultInfo.getLine() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4354 .writeText( resultInfo.getMessage() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4355 m_currentTestSuccess = false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4356 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4357 case ResultWas::Info:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4358 m_xml.scopedElement( "Info" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4359 .writeText( resultInfo.getMessage() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4360 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4361 case ResultWas::Warning:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4362 m_xml.scopedElement( "Warning" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4363 .writeText( resultInfo.getMessage() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4364 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4365 case ResultWas::ExplicitFailure:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4366 m_xml.scopedElement( "Failure" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4367 .writeText( resultInfo.getMessage() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4368 m_currentTestSuccess = false;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4369 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4370 case ResultWas::Unknown:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4371 case ResultWas::Ok:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4372 case ResultWas::FailureBit:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4373 case ResultWas::ExpressionFailed:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4374 case ResultWas::Exception:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4375 case ResultWas::DidntThrowException:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4376 default:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4377 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4378 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4379 if( resultInfo.hasExpression() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4380 m_xml.endElement();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4381 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4382
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4383 virtual void Aborted() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4384 // !TBD
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4385 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4386
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4387 virtual void EndTestCase( const Catch::TestCaseInfo&, const Totals&, const std::string&, const std::string& ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4388 m_xml.scopedElement( "OverallResult" ).writeAttribute( "success", m_currentTestSuccess );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4389 m_xml.endElement();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4390 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4391
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4392 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4393 const IReporterConfig& m_config;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4394 bool m_currentTestSuccess;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4395 XmlWriter m_xml;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4396 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4397
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4398 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4399
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4400 // #included from: reporters/catch_reporter_junit.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4401
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4402 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4403
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4404 class JunitReporter : public SharedImpl<IReporter> {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4405
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4406 struct TestStats {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4407 std::string m_element;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4408 std::string m_resultType;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4409 std::string m_message;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4410 std::string m_content;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4411 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4412
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4413 struct TestCaseStats {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4414
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4415 TestCaseStats( const std::string& name = std::string() ) :m_name( name ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4416
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4417 double m_timeInSeconds;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4418 std::string m_status;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4419 std::string m_className;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4420 std::string m_name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4421 std::vector<TestStats> m_testStats;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4422 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4423
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4424 struct Stats {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4425
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4426 Stats( const std::string& name = std::string() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4427 : m_testsCount( 0 ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4428 m_failuresCount( 0 ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4429 m_disabledCount( 0 ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4430 m_errorsCount( 0 ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4431 m_timeInSeconds( 0 ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4432 m_name( name )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4433 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4434
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4435 std::size_t m_testsCount;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4436 std::size_t m_failuresCount;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4437 std::size_t m_disabledCount;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4438 std::size_t m_errorsCount;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4439 double m_timeInSeconds;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4440 std::string m_name;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4441
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4442 std::vector<TestCaseStats> m_testCaseStats;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4443 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4444
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4445 public:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4446 JunitReporter( const IReporterConfig& config )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4447 : m_config( config ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4448 m_testSuiteStats( "AllTests" ),
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4449 m_currentStats( &m_testSuiteStats )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4450 {}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4451
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4452 static std::string getDescription() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4453 return "Reports test results in an XML format that looks like Ant's junitreport target";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4454 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4455
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4456 private: // IReporter
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4457
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4458 virtual bool shouldRedirectStdout() const {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4459 return true;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4460 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4461
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4462 virtual void StartTesting(){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4463
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4464 virtual void StartGroup( const std::string& groupName ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4465 m_statsForSuites.push_back( Stats( groupName ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4466 m_currentStats = &m_statsForSuites.back();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4467 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4468
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4469 virtual void EndGroup( const std::string&, const Totals& totals ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4470 m_currentStats->m_testsCount = totals.assertions.total();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4471 m_currentStats = &m_testSuiteStats;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4472 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4473
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4474 virtual void StartSection( const std::string&, const std::string& ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4475
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4476 virtual void EndSection( const std::string&, const Counts& ){}
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4477
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4478 virtual void StartTestCase( const Catch::TestCaseInfo& testInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4479 m_currentStats->m_testCaseStats.push_back( TestCaseStats( testInfo.getName() ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4480 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4481
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4482 virtual void Result( const Catch::ResultInfo& resultInfo ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4483 if( resultInfo.getResultType() != ResultWas::Ok || m_config.includeSuccessfulResults() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4484 TestCaseStats& testCaseStats = m_currentStats->m_testCaseStats.back();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4485 TestStats stats;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4486 std::ostringstream oss;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4487 if( !resultInfo.getMessage().empty() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4488 oss << resultInfo.getMessage() << " at ";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4489 oss << SourceLineInfo( resultInfo.getFilename(), resultInfo.getLine() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4490 stats.m_content = oss.str();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4491 stats.m_message = resultInfo.getExpandedExpression();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4492 stats.m_resultType = resultInfo.getTestMacroName();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4493
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4494 switch( resultInfo.getResultType() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4495 case ResultWas::ThrewException:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4496 stats.m_element = "error";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4497 m_currentStats->m_errorsCount++;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4498 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4499 case ResultWas::Info:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4500 stats.m_element = "info"; // !TBD ?
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4501 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4502 case ResultWas::Warning:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4503 stats.m_element = "warning"; // !TBD ?
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4504 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4505 case ResultWas::ExplicitFailure:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4506 stats.m_element = "failure";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4507 m_currentStats->m_failuresCount++;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4508 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4509 case ResultWas::ExpressionFailed:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4510 stats.m_element = "failure";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4511 m_currentStats->m_failuresCount++;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4512 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4513 case ResultWas::Ok:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4514 stats.m_element = "success";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4515 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4516 case ResultWas::Unknown:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4517 case ResultWas::FailureBit:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4518 case ResultWas::Exception:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4519 case ResultWas::DidntThrowException:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4520 default:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4521 stats.m_element = "unknown";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4522 break;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4523 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4524 testCaseStats.m_testStats.push_back( stats );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4525 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4526 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4527
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4528 virtual void EndTestCase( const Catch::TestCaseInfo&, const Totals&, const std::string& stdOut, const std::string& stdErr ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4529 if( !stdOut.empty() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4530 m_stdOut << stdOut << "\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4531 if( !stdErr.empty() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4532 m_stdErr << stdErr << "\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4533 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4534
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4535 virtual void Aborted() {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4536 // !TBD
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4537 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4538
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4539 virtual void EndTesting( const Totals& ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4540 std::ostream& str = m_config.stream();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4541 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4542 XmlWriter xml( str );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4543
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4544 if( m_statsForSuites.size() > 0 )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4545 xml.startElement( "testsuites" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4546
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4547 std::vector<Stats>::const_iterator it = m_statsForSuites.begin();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4548 std::vector<Stats>::const_iterator itEnd = m_statsForSuites.end();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4549
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4550 for(; it != itEnd; ++it ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4551 XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4552 xml.writeAttribute( "name", it->m_name );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4553 xml.writeAttribute( "errors", it->m_errorsCount );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4554 xml.writeAttribute( "failures", it->m_failuresCount );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4555 xml.writeAttribute( "tests", it->m_testsCount );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4556 xml.writeAttribute( "hostname", "tbd" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4557 xml.writeAttribute( "time", "tbd" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4558 xml.writeAttribute( "timestamp", "tbd" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4559
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4560 OutputTestCases( xml, *it );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4561 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4562
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4563 xml.scopedElement( "system-out" ).writeText( trim( m_stdOut.str() ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4564 xml.scopedElement( "system-err" ).writeText( trim( m_stdErr.str() ) );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4565 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4566 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4567
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4568 void OutputTestCases( XmlWriter& xml, const Stats& stats ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4569 std::vector<TestCaseStats>::const_iterator it = stats.m_testCaseStats.begin();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4570 std::vector<TestCaseStats>::const_iterator itEnd = stats.m_testCaseStats.end();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4571 for(; it != itEnd; ++it ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4572 xml.writeBlankLine();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4573 xml.writeComment( "Test case" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4574
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4575 XmlWriter::ScopedElement e = xml.scopedElement( "testcase" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4576 xml.writeAttribute( "classname", it->m_className );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4577 xml.writeAttribute( "name", it->m_name );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4578 xml.writeAttribute( "time", "tbd" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4579
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4580 OutputTestResult( xml, *it );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4581 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4582 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4583
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4584 void OutputTestResult( XmlWriter& xml, const TestCaseStats& stats ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4585 std::vector<TestStats>::const_iterator it = stats.m_testStats.begin();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4586 std::vector<TestStats>::const_iterator itEnd = stats.m_testStats.end();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4587 for(; it != itEnd; ++it ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4588 if( it->m_element != "success" ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4589 XmlWriter::ScopedElement e = xml.scopedElement( it->m_element );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4590
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4591 xml.writeAttribute( "message", it->m_message );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4592 xml.writeAttribute( "type", it->m_resultType );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4593 if( !it->m_content.empty() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4594 xml.writeText( it->m_content );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4595 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4596 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4597 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4598
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4599 private:
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4600 const IReporterConfig& m_config;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4601 bool m_currentTestSuccess;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4602
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4603 Stats m_testSuiteStats;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4604 Stats* m_currentStats;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4605 std::vector<Stats> m_statsForSuites;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4606 std::ostringstream m_stdOut;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4607 std::ostringstream m_stdErr;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4608 };
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4609
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4610 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4611
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4612 #include <fstream>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4613 #include <stdlib.h>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4614 #include <limits>
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4615
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4616 namespace Catch {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4617
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4618 INTERNAL_CATCH_REGISTER_REPORTER( "basic", BasicReporter )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4619 INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4620 INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4621
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4622 inline int Main( Config& config ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4623
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4624 // Handle list request
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4625 if( config.listWhat() != List::None )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4626 return List( config );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4627
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4628 // Open output file, if specified
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4629 std::ofstream ofs;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4630 if( !config.getFilename().empty() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4631 ofs.open( config.getFilename().c_str() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4632 if( ofs.fail() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4633 std::cerr << "Unable to open file: '" << config.getFilename() << "'" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4634 return (std::numeric_limits<int>::max)();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4635 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4636 config.setStreamBuf( ofs.rdbuf() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4637 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4638
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4639 int result = 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4640
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4641 // Scope here for the Runner so it can use the context before it is cleaned-up
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4642 {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4643 Runner runner( config );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4644
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4645 // Run test specs specified on the command line - or default to all
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4646 if( !config.testsSpecified() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4647 config.getReporter()->StartGroup( "" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4648 runner.runAll();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4649 config.getReporter()->EndGroup( "", runner.getTotals() );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4650 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4651 else {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4652 // !TBD We should get all the testcases upfront, report any missing,
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4653 // then just run them
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4654 std::vector<std::string>::const_iterator it = config.getTestSpecs().begin();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4655 std::vector<std::string>::const_iterator itEnd = config.getTestSpecs().end();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4656 for(; it != itEnd; ++it ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4657 Totals prevTotals = runner.getTotals();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4658 config.getReporter()->StartGroup( *it );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4659 if( runner.runMatching( *it ) == 0 ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4660 // Use reporter?
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4661 // std::cerr << "\n[Unable to match any test cases with: " << *it << "]" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4662 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4663 config.getReporter()->EndGroup( *it, runner.getTotals() - prevTotals );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4664 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4665 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4666 result = static_cast<int>( runner.getTotals().assertions.failed );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4667 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4668 Catch::Context::cleanUp();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4669 return result;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4670 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4671
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4672 inline void showUsage( std::ostream& os ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4673 os << "\t-l, --list <tests | reporters> [xml]\n"
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4674 << "\t-t, --test <testspec> [<testspec>...]\n"
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4675 << "\t-r, --reporter <reporter name>\n"
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4676 << "\t-o, --out <file name>|<%stream name>\n"
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4677 << "\t-s, --success\n"
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4678 << "\t-b, --break\n"
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4679 << "\t-n, --name <name>\n"
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4680 << "\t-a, --abort [#]\n\n"
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4681 << "For more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line" << std::endl;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4682 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4683 inline void showHelp( std::string exeName ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4684 std::string::size_type pos = exeName.find_last_of( "/\\" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4685 if( pos != std::string::npos ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4686 exeName = exeName.substr( pos+1 );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4687 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4688
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4689 std::cout << exeName << " is a CATCH host application. Options are as follows:\n\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4690 showUsage( std::cout );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4691 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4692
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4693 inline int Main( int argc, char* const argv[], Config& config ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4694
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4695 parseIntoConfig( CommandParser( argc, argv ), config );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4696
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4697 if( !config.getMessage().empty() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4698 std::cerr << config.getMessage() << + "\n\nUsage: ...\n\n";
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4699 showUsage( std::cerr );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4700 Catch::Context::cleanUp();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4701 return (std::numeric_limits<int>::max)();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4702 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4703
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4704 // Handle help
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4705 if( config.showHelp() ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4706 showHelp( argv[0] );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4707 Catch::Context::cleanUp();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4708 return 0;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4709 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4710 return Main( config );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4711 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4712
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4713 inline int Main( int argc, char* const argv[] ) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4714 Config config;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4715 // !TBD: This doesn't always work, for some reason
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4716 // if( isDebuggerActive() )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4717 // config.useStream( "debug" );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4718 return Main( argc, argv, config );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4719 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4720
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4721 } // end namespace Catch
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4722
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4723 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4724
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4725 #ifdef CATCH_CONFIG_MAIN
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4726 // #included from: internal/catch_default_main.hpp
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4727
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4728 #ifndef __OBJC__
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4729
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4730 // Standard C/C++ main entry point
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4731 int main (int argc, char * const argv[]) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4732 return Catch::Main( argc, argv );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4733 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4734
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4735 #else // __OBJC__
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4736
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4737 // Objective-C entry point
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4738 int main (int argc, char * const argv[]) {
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4739 #if !CATCH_ARC_ENABLED
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4740 NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4741 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4742
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4743 Catch::registerTestMethods();
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4744 int result = Catch::Main( argc, (char* const*)argv );
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4745
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4746 #if !CATCH_ARC_ENABLED
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4747 [pool drain];
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4748 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4749
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4750 return result;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4751 }
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4752
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4753 #endif // __OBJC__
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4754
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4755 #endif
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4756
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4757 //////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4758
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4759 #define REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, false, true, "REQUIRE" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4760 #define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, true, true, "REQUIRE_FALSE" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4761
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4762 #define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, ..., true, "REQUIRE_THROWS" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4763 #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, true, "REQUIRE_THROWS_AS" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4764 #define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, true, "REQUIRE_NOTHROW" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4765
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4766 #define CHECK( expr ) INTERNAL_CATCH_TEST( expr, false, false, "CHECK" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4767 #define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, true, false, "CHECK_FALSE" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4768 #define CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, false, false, "CHECKED_IF" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4769 #define CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, false, false, "CHECKED_ELSE" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4770
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4771 #define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, ..., false, "CHECK_THROWS" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4772 #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, false, "CHECK_THROWS_AS" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4773 #define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, false, "CHECK_NOTHROW" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4774
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4775 #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, false, "CHECK_THAT" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4776 #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, true, "REQUIRE_THAT" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4777
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4778 #define INFO( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Info, false, "INFO" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4779 #define WARN( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::Warning, false, "WARN" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4780 #define FAIL( msg ) INTERNAL_CATCH_MSG( msg, Catch::ResultWas::ExplicitFailure, true, "FAIL" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4781 #define SCOPED_INFO( msg ) INTERNAL_CATCH_SCOPED_INFO( msg )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4782 #define CAPTURE( msg ) INTERNAL_CATCH_MSG( #msg " := " << msg, Catch::ResultWas::Info, false, "CAPTURE" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4783
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4784 #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4785
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4786 #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4787 #define TEST_CASE_NORETURN( name, description ) INTERNAL_CATCH_TESTCASE_NORETURN( name, description )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4788 #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "Anonymous test case" )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4789 #define METHOD_AS_TEST_CASE( method, name, description ) CATCH_METHOD_AS_TEST_CASE( method, name, description )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4790
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4791 #define REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4792 #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4793
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4794 #define GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4795
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4796 ///////////////
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4797 // Still to be implemented
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4798 #define CHECK_NOFAIL( expr ) // !TBD - reports violation, but doesn't fail Test
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4799
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4800 using Catch::Detail::Approx;
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4801
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4802 #endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED
f0f800b95765 switched to Catch for the tests
Nicolas Saunier <nicolas.saunier@polymtl.ca>
parents:
diff changeset
4803