Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1 | /* |
Phil Nash | 02af70e | 2016-03-11 18:31:52 +0000 | [diff] [blame^] | 2 | * Catch v1.3.6 |
| 3 | * Generated: 2016-03-11 18:30:42.852700 |
Phil Nash | 4df051b | 2012-05-22 22:22:22 +0100 | [diff] [blame] | 4 | * ---------------------------------------------------------- |
Phil Nash | aec1e5e | 2012-05-09 19:37:51 +0100 | [diff] [blame] | 5 | * This file has been merged from multiple headers. Please don't edit it directly |
| 6 | * Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved. |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 7 | * |
| 8 | * Distributed under the Boost Software License, Version 1.0. (See accompanying |
| 9 | * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10 | */ |
Phil Nash | aec1e5e | 2012-05-09 19:37:51 +0100 | [diff] [blame] | 11 | #ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED |
| 12 | #define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 13 | |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 14 | #define TWOBLUECUBES_CATCH_HPP_INCLUDED |
Phil Nash | 0f9c551 | 2012-06-02 23:12:42 +0100 | [diff] [blame] | 15 | |
Phil Nash | c51e868 | 2015-05-21 06:16:15 +0100 | [diff] [blame] | 16 | #ifdef __clang__ |
| 17 | # pragma clang system_header |
| 18 | #elif defined __GNUC__ |
| 19 | # pragma GCC system_header |
| 20 | #endif |
| 21 | |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 22 | // #included from: internal/catch_suppress_warnings.h |
| 23 | |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 24 | #ifdef __clang__ |
Phil Nash | a806c3e | 2015-03-04 08:23:40 +0000 | [diff] [blame] | 25 | # ifdef __ICC // icpc defines the __clang__ macro |
| 26 | # pragma warning(push) |
| 27 | # pragma warning(disable: 161 1682) |
| 28 | # else // __ICC |
| 29 | # pragma clang diagnostic ignored "-Wglobal-constructors" |
| 30 | # pragma clang diagnostic ignored "-Wvariadic-macros" |
| 31 | # pragma clang diagnostic ignored "-Wc99-extensions" |
| 32 | # pragma clang diagnostic ignored "-Wunused-variable" |
| 33 | # pragma clang diagnostic push |
| 34 | # pragma clang diagnostic ignored "-Wpadded" |
| 35 | # pragma clang diagnostic ignored "-Wc++98-compat" |
| 36 | # pragma clang diagnostic ignored "-Wc++98-compat-pedantic" |
Phil Nash | c51e868 | 2015-05-21 06:16:15 +0100 | [diff] [blame] | 37 | # pragma clang diagnostic ignored "-Wswitch-enum" |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 38 | # pragma clang diagnostic ignored "-Wcovered-switch-default" |
Phil Nash | a806c3e | 2015-03-04 08:23:40 +0000 | [diff] [blame] | 39 | # endif |
Fabien Caylus | ae76945 | 2014-07-27 15:16:10 +0200 | [diff] [blame] | 40 | #elif defined __GNUC__ |
Phil Nash | a806c3e | 2015-03-04 08:23:40 +0000 | [diff] [blame] | 41 | # pragma GCC diagnostic ignored "-Wvariadic-macros" |
| 42 | # pragma GCC diagnostic ignored "-Wunused-variable" |
| 43 | # pragma GCC diagnostic push |
| 44 | # pragma GCC diagnostic ignored "-Wpadded" |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 45 | #endif |
Phil Nash | 576aff6 | 2014-12-21 00:21:23 +0000 | [diff] [blame] | 46 | #if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) |
| 47 | # define CATCH_IMPL |
Phil Nash | f9df35b | 2014-03-10 18:02:18 +0000 | [diff] [blame] | 48 | #endif |
| 49 | |
Phil Nash | 576aff6 | 2014-12-21 00:21:23 +0000 | [diff] [blame] | 50 | #ifdef CATCH_IMPL |
Phil Nash | 9abb276 | 2014-03-06 21:53:34 +0000 | [diff] [blame] | 51 | # ifndef CLARA_CONFIG_MAIN |
| 52 | # define CLARA_CONFIG_MAIN_NOT_DEFINED |
| 53 | # define CLARA_CONFIG_MAIN |
| 54 | # endif |
| 55 | #endif |
| 56 | |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 57 | // #included from: internal/catch_notimplemented_exception.h |
| 58 | #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_H_INCLUDED |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 59 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 60 | // #included from: catch_common.h |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 61 | #define TWOBLUECUBES_CATCH_COMMON_H_INCLUDED |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 62 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 63 | #define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line |
| 64 | #define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) |
| 65 | #define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) |
| 66 | |
| 67 | #define INTERNAL_CATCH_STRINGIFY2( expr ) #expr |
| 68 | #define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr ) |
| 69 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 70 | #include <sstream> |
| 71 | #include <stdexcept> |
| 72 | #include <algorithm> |
| 73 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 74 | // #included from: catch_compiler_capabilities.h |
| 75 | #define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED |
| 76 | |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 77 | // Detect a number of compiler features - mostly C++11/14 conformance - by compiler |
| 78 | // The following features are defined: |
| 79 | // |
| 80 | // CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported? |
| 81 | // CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported? |
| 82 | // CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods |
| 83 | // CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported? |
| 84 | // CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 85 | // CATCH_CONFIG_CPP11_LONG_LONG : is long long supported? |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 86 | // CATCH_CONFIG_CPP11_OVERRIDE : is override supported? |
Phil Nash | d234ed1 | 2015-08-24 06:28:25 +0100 | [diff] [blame] | 87 | // CATCH_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr) |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 88 | |
| 89 | // CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported? |
| 90 | |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 91 | // CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported? |
| 92 | |
Phil Nash | d234ed1 | 2015-08-24 06:28:25 +0100 | [diff] [blame] | 93 | // **************** |
| 94 | // Note to maintainers: if new toggles are added please document them |
| 95 | // in configuration.md, too |
| 96 | // **************** |
| 97 | |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 98 | // In general each macro has a _NO_<feature name> form |
| 99 | // (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature. |
| 100 | // Many features, at point of detection, define an _INTERNAL_ macro, so they |
| 101 | // can be combined, en-mass, with the _NO_ forms later. |
| 102 | |
| 103 | // All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11 |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 104 | |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 105 | #if defined(__cplusplus) && __cplusplus >= 201103L |
| 106 | # define CATCH_CPP11_OR_GREATER |
| 107 | #endif |
| 108 | |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 109 | #ifdef __clang__ |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 110 | |
Phil Nash | 1740495 | 2014-04-23 18:19:49 +0100 | [diff] [blame] | 111 | # if __has_feature(cxx_nullptr) |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 112 | # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR |
Phil Nash | 1740495 | 2014-04-23 18:19:49 +0100 | [diff] [blame] | 113 | # endif |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 114 | |
Phil Nash | 1740495 | 2014-04-23 18:19:49 +0100 | [diff] [blame] | 115 | # if __has_feature(cxx_noexcept) |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 116 | # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT |
Phil Nash | 1740495 | 2014-04-23 18:19:49 +0100 | [diff] [blame] | 117 | # endif |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 118 | |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 119 | # if defined(CATCH_CPP11_OR_GREATER) |
| 120 | # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) |
| 121 | # endif |
| 122 | |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 123 | #endif // __clang__ |
| 124 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 125 | //////////////////////////////////////////////////////////////////////////////// |
| 126 | // Borland |
| 127 | #ifdef __BORLANDC__ |
| 128 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 129 | #endif // __BORLANDC__ |
| 130 | |
| 131 | //////////////////////////////////////////////////////////////////////////////// |
| 132 | // EDG |
| 133 | #ifdef __EDG_VERSION__ |
| 134 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 135 | #endif // __EDG_VERSION__ |
| 136 | |
| 137 | //////////////////////////////////////////////////////////////////////////////// |
| 138 | // Digital Mars |
| 139 | #ifdef __DMC__ |
| 140 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 141 | #endif // __DMC__ |
| 142 | |
| 143 | //////////////////////////////////////////////////////////////////////////////// |
| 144 | // GCC |
| 145 | #ifdef __GNUC__ |
| 146 | |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 147 | # if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__) |
| 148 | # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR |
| 149 | # endif |
| 150 | |
| 151 | # if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) && defined(CATCH_CPP11_OR_GREATER) |
Phil Nash | 02af70e | 2016-03-11 18:31:52 +0000 | [diff] [blame^] | 152 | # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS _Pragma( "GCC diagnostic ignored \"-Wparentheses\"" ) |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 153 | # endif |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 154 | |
Phil Nash | 8b1b7cd | 2015-08-03 07:40:52 +0100 | [diff] [blame] | 155 | // - otherwise more recent versions define __cplusplus >= 201103L |
| 156 | // and will get picked up below |
| 157 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 158 | #endif // __GNUC__ |
| 159 | |
| 160 | //////////////////////////////////////////////////////////////////////////////// |
| 161 | // Visual C++ |
| 162 | #ifdef _MSC_VER |
| 163 | |
Phil Nash | 43470b2 | 2015-05-19 22:37:23 +0100 | [diff] [blame] | 164 | #if (_MSC_VER >= 1600) |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 165 | # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR |
Phil Nash | d234ed1 | 2015-08-24 06:28:25 +0100 | [diff] [blame] | 166 | # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR |
Phil Nash | 43470b2 | 2015-05-19 22:37:23 +0100 | [diff] [blame] | 167 | #endif |
| 168 | |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 169 | #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015)) |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 170 | #define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT |
| 171 | #define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 172 | #endif |
| 173 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 174 | #endif // _MSC_VER |
| 175 | |
Phil Nash | d234ed1 | 2015-08-24 06:28:25 +0100 | [diff] [blame] | 176 | //////////////////////////////////////////////////////////////////////////////// |
| 177 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 178 | // Use variadic macros if the compiler supports them |
| 179 | #if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \ |
| 180 | ( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \ |
| 181 | ( defined __GNUC__ && __GNUC__ >= 3 ) || \ |
| 182 | ( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L ) |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 183 | |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 184 | #define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 185 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 186 | #endif |
| 187 | |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 188 | //////////////////////////////////////////////////////////////////////////////// |
| 189 | // C++ language feature support |
| 190 | |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 191 | // catch all support for C++11 |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 192 | #if defined(CATCH_CPP11_OR_GREATER) |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 193 | |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 194 | # if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) |
| 195 | # define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 196 | # endif |
| 197 | |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 198 | # ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT |
| 199 | # define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 200 | # endif |
| 201 | |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 202 | # ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS |
| 203 | # define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 204 | # endif |
| 205 | |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 206 | # ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM |
| 207 | # define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 208 | # endif |
| 209 | |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 210 | # ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE |
| 211 | # define CATCH_INTERNAL_CONFIG_CPP11_TUPLE |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 212 | # endif |
| 213 | |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 214 | # ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS |
| 215 | # define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 216 | # endif |
| 217 | |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 218 | # if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) |
| 219 | # define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG |
| 220 | # endif |
| 221 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 222 | # if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) |
| 223 | # define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE |
| 224 | # endif |
Phil Nash | d234ed1 | 2015-08-24 06:28:25 +0100 | [diff] [blame] | 225 | # if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) |
| 226 | # define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR |
| 227 | # endif |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 228 | |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 229 | #endif // __cplusplus >= 201103L |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 230 | |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 231 | // Now set the actual defines based on the above + anything the user has configured |
| 232 | #if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11) |
| 233 | # define CATCH_CONFIG_CPP11_NULLPTR |
| 234 | #endif |
| 235 | #if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11) |
| 236 | # define CATCH_CONFIG_CPP11_NOEXCEPT |
| 237 | #endif |
| 238 | #if defined(CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_NO_CPP11) |
| 239 | # define CATCH_CONFIG_CPP11_GENERATED_METHODS |
| 240 | #endif |
| 241 | #if defined(CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_NO_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_NO_CPP11) |
| 242 | # define CATCH_CONFIG_CPP11_IS_ENUM |
| 243 | #endif |
| 244 | #if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11) |
| 245 | # define CATCH_CONFIG_CPP11_TUPLE |
| 246 | #endif |
| 247 | #if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS) |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 248 | # define CATCH_CONFIG_VARIADIC_MACROS |
| 249 | #endif |
Phil Nash | d234ed1 | 2015-08-24 06:28:25 +0100 | [diff] [blame] | 250 | #if defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_CPP11) |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 251 | # define CATCH_CONFIG_CPP11_LONG_LONG |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 252 | #endif |
Phil Nash | d234ed1 | 2015-08-24 06:28:25 +0100 | [diff] [blame] | 253 | #if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11) |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 254 | # define CATCH_CONFIG_CPP11_OVERRIDE |
| 255 | #endif |
Phil Nash | d234ed1 | 2015-08-24 06:28:25 +0100 | [diff] [blame] | 256 | #if defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_CPP11) |
| 257 | # define CATCH_CONFIG_CPP11_UNIQUE_PTR |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 258 | #endif |
| 259 | |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 260 | #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) |
| 261 | # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS |
| 262 | #endif |
| 263 | |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 264 | // noexcept support: |
Phil Nash | 1740495 | 2014-04-23 18:19:49 +0100 | [diff] [blame] | 265 | #if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT) |
| 266 | # define CATCH_NOEXCEPT noexcept |
| 267 | # define CATCH_NOEXCEPT_IS(x) noexcept(x) |
| 268 | #else |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 269 | # define CATCH_NOEXCEPT throw() |
| 270 | # define CATCH_NOEXCEPT_IS(x) |
| 271 | #endif |
| 272 | |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 273 | // nullptr support |
| 274 | #ifdef CATCH_CONFIG_CPP11_NULLPTR |
| 275 | # define CATCH_NULL nullptr |
| 276 | #else |
| 277 | # define CATCH_NULL NULL |
| 278 | #endif |
| 279 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 280 | // override support |
| 281 | #ifdef CATCH_CONFIG_CPP11_OVERRIDE |
| 282 | # define CATCH_OVERRIDE override |
| 283 | #else |
| 284 | # define CATCH_OVERRIDE |
| 285 | #endif |
| 286 | |
Phil Nash | d234ed1 | 2015-08-24 06:28:25 +0100 | [diff] [blame] | 287 | // unique_ptr support |
| 288 | #ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR |
| 289 | # define CATCH_AUTO_PTR( T ) std::unique_ptr<T> |
| 290 | #else |
| 291 | # define CATCH_AUTO_PTR( T ) std::auto_ptr<T> |
| 292 | #endif |
| 293 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 294 | namespace Catch { |
| 295 | |
Phil Nash | 8f66e34 | 2015-07-02 23:03:13 +0100 | [diff] [blame] | 296 | struct IConfig; |
| 297 | |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 298 | struct CaseSensitive { enum Choice { |
| 299 | Yes, |
| 300 | No |
| 301 | }; }; |
| 302 | |
Phil Nash | a04981b | 2013-03-08 09:30:25 +0000 | [diff] [blame] | 303 | class NonCopyable { |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 304 | #ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 305 | NonCopyable( NonCopyable const& ) = delete; |
| 306 | NonCopyable( NonCopyable && ) = delete; |
| 307 | NonCopyable& operator = ( NonCopyable const& ) = delete; |
| 308 | NonCopyable& operator = ( NonCopyable && ) = delete; |
| 309 | #else |
| 310 | NonCopyable( NonCopyable const& info ); |
| 311 | NonCopyable& operator = ( NonCopyable const& ); |
| 312 | #endif |
| 313 | |
Phil Nash | a04981b | 2013-03-08 09:30:25 +0000 | [diff] [blame] | 314 | protected: |
| 315 | NonCopyable() {} |
| 316 | virtual ~NonCopyable(); |
| 317 | }; |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 318 | |
Phil Nash | 163088a | 2012-05-31 19:40:26 +0100 | [diff] [blame] | 319 | class SafeBool { |
| 320 | public: |
| 321 | typedef void (SafeBool::*type)() const; |
| 322 | |
| 323 | static type makeSafe( bool value ) { |
| 324 | return value ? &SafeBool::trueValue : 0; |
| 325 | } |
| 326 | private: |
| 327 | void trueValue() const {} |
| 328 | }; |
| 329 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 330 | template<typename ContainerT> |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 331 | inline void deleteAll( ContainerT& container ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 332 | typename ContainerT::const_iterator it = container.begin(); |
| 333 | typename ContainerT::const_iterator itEnd = container.end(); |
| 334 | for(; it != itEnd; ++it ) |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 335 | delete *it; |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 336 | } |
| 337 | template<typename AssociativeContainerT> |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 338 | inline void deleteAllValues( AssociativeContainerT& container ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 339 | typename AssociativeContainerT::const_iterator it = container.begin(); |
| 340 | typename AssociativeContainerT::const_iterator itEnd = container.end(); |
| 341 | for(; it != itEnd; ++it ) |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 342 | delete it->second; |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 343 | } |
| 344 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 345 | bool startsWith( std::string const& s, std::string const& prefix ); |
| 346 | bool endsWith( std::string const& s, std::string const& suffix ); |
| 347 | bool contains( std::string const& s, std::string const& infix ); |
| 348 | void toLowerInPlace( std::string& s ); |
| 349 | std::string toLower( std::string const& s ); |
| 350 | std::string trim( std::string const& str ); |
Phil Nash | 576aff6 | 2014-12-21 00:21:23 +0000 | [diff] [blame] | 351 | bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ); |
Phil Nash | 4c97fc5 | 2012-08-24 08:23:50 +0100 | [diff] [blame] | 352 | |
| 353 | struct pluralise { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 354 | pluralise( std::size_t count, std::string const& label ); |
Phil Nash | 4c97fc5 | 2012-08-24 08:23:50 +0100 | [diff] [blame] | 355 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 356 | friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ); |
Phil Nash | 4c97fc5 | 2012-08-24 08:23:50 +0100 | [diff] [blame] | 357 | |
| 358 | std::size_t m_count; |
| 359 | std::string m_label; |
| 360 | }; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 361 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 362 | struct SourceLineInfo { |
| 363 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 364 | SourceLineInfo(); |
Phil Nash | de49ec4 | 2013-12-04 20:25:14 +0000 | [diff] [blame] | 365 | SourceLineInfo( char const* _file, std::size_t _line ); |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 366 | SourceLineInfo( SourceLineInfo const& other ); |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 367 | # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 368 | SourceLineInfo( SourceLineInfo && ) = default; |
| 369 | SourceLineInfo& operator = ( SourceLineInfo const& ) = default; |
| 370 | SourceLineInfo& operator = ( SourceLineInfo && ) = default; |
| 371 | # endif |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 372 | bool empty() const; |
| 373 | bool operator == ( SourceLineInfo const& other ) const; |
Phil Nash | a806c3e | 2015-03-04 08:23:40 +0000 | [diff] [blame] | 374 | bool operator < ( SourceLineInfo const& other ) const; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 375 | |
Phil Nash | 6e0f58d | 2012-02-15 18:37:21 +0000 | [diff] [blame] | 376 | std::string file; |
| 377 | std::size_t line; |
| 378 | }; |
| 379 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 380 | std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); |
Phil Nash | 6e0f58d | 2012-02-15 18:37:21 +0000 | [diff] [blame] | 381 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 382 | // This is just here to avoid compiler warnings with macro constants and boolean literals |
| 383 | inline bool isTrue( bool value ){ return value; } |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 384 | inline bool alwaysTrue() { return true; } |
| 385 | inline bool alwaysFalse() { return false; } |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 386 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 387 | void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ); |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 388 | |
Phil Nash | 8f66e34 | 2015-07-02 23:03:13 +0100 | [diff] [blame] | 389 | void seedRng( IConfig const& config ); |
| 390 | unsigned int rngSeed(); |
| 391 | |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 392 | // Use this in variadic streaming macros to allow |
| 393 | // >> +StreamEndStop |
| 394 | // as well as |
| 395 | // >> stuff +StreamEndStop |
| 396 | struct StreamEndStop { |
| 397 | std::string operator+() { |
| 398 | return std::string(); |
| 399 | } |
| 400 | }; |
| 401 | template<typename T> |
| 402 | T const& operator + ( T const& value, StreamEndStop ) { |
| 403 | return value; |
| 404 | } |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 405 | } |
| 406 | |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 407 | #define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) ) |
| 408 | #define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 409 | |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 410 | #include <ostream> |
| 411 | |
| 412 | namespace Catch { |
| 413 | |
| 414 | class NotImplementedException : public std::exception |
| 415 | { |
| 416 | public: |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 417 | NotImplementedException( SourceLineInfo const& lineInfo ); |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 418 | NotImplementedException( NotImplementedException const& ) {} |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 419 | |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 420 | virtual ~NotImplementedException() CATCH_NOEXCEPT {} |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 421 | |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 422 | virtual const char* what() const CATCH_NOEXCEPT; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 423 | |
| 424 | private: |
| 425 | std::string m_what; |
| 426 | SourceLineInfo m_lineInfo; |
| 427 | }; |
| 428 | |
| 429 | } // end namespace Catch |
| 430 | |
| 431 | /////////////////////////////////////////////////////////////////////////////// |
| 432 | #define CATCH_NOT_IMPLEMENTED throw Catch::NotImplementedException( CATCH_INTERNAL_LINEINFO ) |
| 433 | |
| 434 | // #included from: internal/catch_context.h |
| 435 | #define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED |
| 436 | |
Phil Nash | a70fbe3 | 2012-08-31 08:10:36 +0100 | [diff] [blame] | 437 | // #included from: catch_interfaces_generators.h |
| 438 | #define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 439 | |
Phil Nash | a70fbe3 | 2012-08-31 08:10:36 +0100 | [diff] [blame] | 440 | #include <string> |
Phil Nash | f7299fc | 2012-02-25 09:39:45 +0000 | [diff] [blame] | 441 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 442 | namespace Catch { |
| 443 | |
Phil Nash | a70fbe3 | 2012-08-31 08:10:36 +0100 | [diff] [blame] | 444 | struct IGeneratorInfo { |
| 445 | virtual ~IGeneratorInfo(); |
| 446 | virtual bool moveNext() = 0; |
| 447 | virtual std::size_t getCurrentIndex() const = 0; |
Phil Nash | f7299fc | 2012-02-25 09:39:45 +0000 | [diff] [blame] | 448 | }; |
| 449 | |
Phil Nash | a70fbe3 | 2012-08-31 08:10:36 +0100 | [diff] [blame] | 450 | struct IGeneratorsForTest { |
| 451 | virtual ~IGeneratorsForTest(); |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 452 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 453 | virtual IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) = 0; |
Phil Nash | a70fbe3 | 2012-08-31 08:10:36 +0100 | [diff] [blame] | 454 | virtual bool moveNext() = 0; |
Phil Nash | f7299fc | 2012-02-25 09:39:45 +0000 | [diff] [blame] | 455 | }; |
Phil Nash | a70fbe3 | 2012-08-31 08:10:36 +0100 | [diff] [blame] | 456 | |
| 457 | IGeneratorsForTest* createGeneratorsForTest(); |
| 458 | |
| 459 | } // end namespace Catch |
| 460 | |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 461 | // #included from: catch_ptr.hpp |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 462 | #define TWOBLUECUBES_CATCH_PTR_HPP_INCLUDED |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 463 | |
Phil Nash | 37186a1 | 2013-03-13 12:19:30 +0000 | [diff] [blame] | 464 | #ifdef __clang__ |
| 465 | #pragma clang diagnostic push |
| 466 | #pragma clang diagnostic ignored "-Wpadded" |
| 467 | #endif |
| 468 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 469 | namespace Catch { |
| 470 | |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 471 | // An intrusive reference counting smart pointer. |
| 472 | // T must implement addRef() and release() methods |
| 473 | // typically implementing the IShared interface |
| 474 | template<typename T> |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 475 | class Ptr { |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 476 | public: |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 477 | Ptr() : m_p( CATCH_NULL ){} |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 478 | Ptr( T* p ) : m_p( p ){ |
Phil Nash | 6175697 | 2012-07-28 20:37:07 +0100 | [diff] [blame] | 479 | if( m_p ) |
| 480 | m_p->addRef(); |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 481 | } |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 482 | Ptr( Ptr const& other ) : m_p( other.m_p ){ |
Phil Nash | 6175697 | 2012-07-28 20:37:07 +0100 | [diff] [blame] | 483 | if( m_p ) |
| 484 | m_p->addRef(); |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 485 | } |
| 486 | ~Ptr(){ |
| 487 | if( m_p ) |
| 488 | m_p->release(); |
| 489 | } |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 490 | void reset() { |
| 491 | if( m_p ) |
| 492 | m_p->release(); |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 493 | m_p = CATCH_NULL; |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 494 | } |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 495 | Ptr& operator = ( T* p ){ |
| 496 | Ptr temp( p ); |
| 497 | swap( temp ); |
| 498 | return *this; |
| 499 | } |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 500 | Ptr& operator = ( Ptr const& other ){ |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 501 | Ptr temp( other ); |
| 502 | swap( temp ); |
| 503 | return *this; |
| 504 | } |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 505 | void swap( Ptr& other ) { std::swap( m_p, other.m_p ); } |
Phil Nash | 8b1b7cd | 2015-08-03 07:40:52 +0100 | [diff] [blame] | 506 | T* get() const{ return m_p; } |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 507 | T& operator*() const { return *m_p; } |
| 508 | T* operator->() const { return m_p; } |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 509 | bool operator !() const { return m_p == CATCH_NULL; } |
| 510 | operator SafeBool::type() const { return SafeBool::makeSafe( m_p != CATCH_NULL ); } |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 511 | |
| 512 | private: |
| 513 | T* m_p; |
| 514 | }; |
| 515 | |
| 516 | struct IShared : NonCopyable { |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 517 | virtual ~IShared(); |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 518 | virtual void addRef() const = 0; |
| 519 | virtual void release() const = 0; |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 520 | }; |
| 521 | |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 522 | template<typename T = IShared> |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 523 | struct SharedImpl : T { |
| 524 | |
| 525 | SharedImpl() : m_rc( 0 ){} |
| 526 | |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 527 | virtual void addRef() const { |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 528 | ++m_rc; |
| 529 | } |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 530 | virtual void release() const { |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 531 | if( --m_rc == 0 ) |
| 532 | delete this; |
| 533 | } |
| 534 | |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 535 | mutable unsigned int m_rc; |
Phil Nash | 49e6d53 | 2012-05-05 19:35:35 +0100 | [diff] [blame] | 536 | }; |
| 537 | |
| 538 | } // end namespace Catch |
| 539 | |
Phil Nash | 37186a1 | 2013-03-13 12:19:30 +0000 | [diff] [blame] | 540 | #ifdef __clang__ |
| 541 | #pragma clang diagnostic pop |
| 542 | #endif |
| 543 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 544 | #include <memory> |
| 545 | #include <vector> |
| 546 | #include <stdlib.h> |
| 547 | |
| 548 | namespace Catch { |
| 549 | |
| 550 | class TestCase; |
| 551 | class Stream; |
| 552 | struct IResultCapture; |
| 553 | struct IRunner; |
| 554 | struct IGeneratorsForTest; |
| 555 | struct IConfig; |
| 556 | |
| 557 | struct IContext |
| 558 | { |
| 559 | virtual ~IContext(); |
| 560 | |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 561 | virtual IResultCapture* getResultCapture() = 0; |
| 562 | virtual IRunner* getRunner() = 0; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 563 | virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0; |
| 564 | virtual bool advanceGeneratorsForCurrentTest() = 0; |
| 565 | virtual Ptr<IConfig const> getConfig() const = 0; |
| 566 | }; |
| 567 | |
| 568 | struct IMutableContext : IContext |
| 569 | { |
| 570 | virtual ~IMutableContext(); |
| 571 | virtual void setResultCapture( IResultCapture* resultCapture ) = 0; |
| 572 | virtual void setRunner( IRunner* runner ) = 0; |
| 573 | virtual void setConfig( Ptr<IConfig const> const& config ) = 0; |
| 574 | }; |
| 575 | |
| 576 | IContext& getCurrentContext(); |
| 577 | IMutableContext& getCurrentMutableContext(); |
| 578 | void cleanUpContext(); |
| 579 | Stream createStream( std::string const& streamName ); |
| 580 | |
| 581 | } |
| 582 | |
| 583 | // #included from: internal/catch_test_registry.hpp |
| 584 | #define TWOBLUECUBES_CATCH_TEST_REGISTRY_HPP_INCLUDED |
| 585 | |
| 586 | // #included from: catch_interfaces_testcase.h |
| 587 | #define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED |
| 588 | |
Phil Nash | 0f9c551 | 2012-06-02 23:12:42 +0100 | [diff] [blame] | 589 | #include <vector> |
| 590 | |
| 591 | namespace Catch { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 592 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 593 | class TestSpec; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 594 | |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 595 | struct ITestCase : IShared { |
Phil Nash | 0f9c551 | 2012-06-02 23:12:42 +0100 | [diff] [blame] | 596 | virtual void invoke () const = 0; |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 597 | protected: |
| 598 | virtual ~ITestCase(); |
Phil Nash | 0f9c551 | 2012-06-02 23:12:42 +0100 | [diff] [blame] | 599 | }; |
| 600 | |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 601 | class TestCase; |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 602 | struct IConfig; |
Phil Nash | 0f9c551 | 2012-06-02 23:12:42 +0100 | [diff] [blame] | 603 | |
| 604 | struct ITestCaseRegistry { |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 605 | virtual ~ITestCaseRegistry(); |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 606 | virtual std::vector<TestCase> const& getAllTests() const = 0; |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 607 | virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const = 0; |
Phil Nash | 0f9c551 | 2012-06-02 23:12:42 +0100 | [diff] [blame] | 608 | }; |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 609 | |
| 610 | bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); |
| 611 | std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ); |
| 612 | std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ); |
| 613 | |
Phil Nash | 0f9c551 | 2012-06-02 23:12:42 +0100 | [diff] [blame] | 614 | } |
| 615 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 616 | namespace Catch { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 617 | |
| 618 | template<typename C> |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 619 | class MethodTestCase : public SharedImpl<ITestCase> { |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 620 | |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 621 | public: |
| 622 | MethodTestCase( void (C::*method)() ) : m_method( method ) {} |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 623 | |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 624 | virtual void invoke() const { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 625 | C obj; |
| 626 | (obj.*m_method)(); |
| 627 | } |
| 628 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 629 | private: |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 630 | virtual ~MethodTestCase() {} |
| 631 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 632 | void (C::*m_method)(); |
| 633 | }; |
| 634 | |
| 635 | typedef void(*TestFunction)(); |
| 636 | |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 637 | struct NameAndDesc { |
| 638 | NameAndDesc( const char* _name = "", const char* _description= "" ) |
| 639 | : name( _name ), description( _description ) |
| 640 | {} |
| 641 | |
| 642 | const char* name; |
| 643 | const char* description; |
| 644 | }; |
| 645 | |
Phil Nash | 7e15d9b | 2015-11-20 16:59:14 +0000 | [diff] [blame] | 646 | void registerTestCase |
| 647 | ( ITestCase* testCase, |
| 648 | char const* className, |
| 649 | NameAndDesc const& nameAndDesc, |
| 650 | SourceLineInfo const& lineInfo ); |
| 651 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 652 | struct AutoReg { |
| 653 | |
Phil Nash | 7e15d9b | 2015-11-20 16:59:14 +0000 | [diff] [blame] | 654 | AutoReg |
| 655 | ( TestFunction function, |
| 656 | SourceLineInfo const& lineInfo, |
| 657 | NameAndDesc const& nameAndDesc ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 658 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 659 | template<typename C> |
Phil Nash | 7e15d9b | 2015-11-20 16:59:14 +0000 | [diff] [blame] | 660 | AutoReg |
| 661 | ( void (C::*method)(), |
| 662 | char const* className, |
| 663 | NameAndDesc const& nameAndDesc, |
| 664 | SourceLineInfo const& lineInfo ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 665 | |
Phil Nash | 7e15d9b | 2015-11-20 16:59:14 +0000 | [diff] [blame] | 666 | registerTestCase |
| 667 | ( new MethodTestCase<C>( method ), |
| 668 | className, |
| 669 | nameAndDesc, |
| 670 | lineInfo ); |
| 671 | } |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 672 | |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 673 | ~AutoReg(); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 674 | |
| 675 | private: |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 676 | AutoReg( AutoReg const& ); |
| 677 | void operator= ( AutoReg const& ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 678 | }; |
| 679 | |
Phil Nash | 7e15d9b | 2015-11-20 16:59:14 +0000 | [diff] [blame] | 680 | void registerTestCaseFunction |
| 681 | ( TestFunction function, |
| 682 | SourceLineInfo const& lineInfo, |
| 683 | NameAndDesc const& nameAndDesc ); |
| 684 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 685 | } // end namespace Catch |
| 686 | |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 687 | #ifdef CATCH_CONFIG_VARIADIC_MACROS |
| 688 | /////////////////////////////////////////////////////////////////////////////// |
| 689 | #define INTERNAL_CATCH_TESTCASE( ... ) \ |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 690 | static void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )(); \ |
| 691 | namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); }\ |
| 692 | static void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )() |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 693 | |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 694 | /////////////////////////////////////////////////////////////////////////////// |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 695 | #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \ |
| 696 | namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); } |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 697 | |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 698 | /////////////////////////////////////////////////////////////////////////////// |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 699 | #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... )\ |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 700 | namespace{ \ |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 701 | struct INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ) : ClassName{ \ |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 702 | void test(); \ |
| 703 | }; \ |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 704 | Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )::test, #ClassName, Catch::NameAndDesc( __VA_ARGS__ ), CATCH_INTERNAL_LINEINFO ); \ |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 705 | } \ |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 706 | void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )::test() |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 707 | |
Phil Nash | 7e15d9b | 2015-11-20 16:59:14 +0000 | [diff] [blame] | 708 | /////////////////////////////////////////////////////////////////////////////// |
| 709 | #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \ |
| 710 | Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( __VA_ARGS__ ) ); |
| 711 | |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 712 | #else |
| 713 | /////////////////////////////////////////////////////////////////////////////// |
| 714 | #define INTERNAL_CATCH_TESTCASE( Name, Desc ) \ |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 715 | static void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )(); \ |
| 716 | namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); }\ |
| 717 | static void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )() |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 718 | |
| 719 | /////////////////////////////////////////////////////////////////////////////// |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 720 | #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, Name, Desc ) \ |
| 721 | namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( &QualifiedMethod, "&" #QualifiedMethod, Catch::NameAndDesc( Name, Desc ), CATCH_INTERNAL_LINEINFO ); } |
| 722 | |
| 723 | /////////////////////////////////////////////////////////////////////////////// |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 724 | #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, TestName, Desc )\ |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 725 | namespace{ \ |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 726 | struct INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ) : ClassName{ \ |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 727 | void test(); \ |
| 728 | }; \ |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 729 | Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( &INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )::test, #ClassName, Catch::NameAndDesc( TestName, Desc ), CATCH_INTERNAL_LINEINFO ); \ |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 730 | } \ |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 731 | void INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ )::test() |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 732 | |
Phil Nash | 7e15d9b | 2015-11-20 16:59:14 +0000 | [diff] [blame] | 733 | /////////////////////////////////////////////////////////////////////////////// |
| 734 | #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, Name, Desc ) \ |
| 735 | Catch::AutoReg( Function, CATCH_INTERNAL_LINEINFO, Catch::NameAndDesc( Name, Desc ) ); |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 736 | #endif |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 737 | |
| 738 | // #included from: internal/catch_capture.hpp |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 739 | #define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 740 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 741 | // #included from: catch_result_builder.h |
| 742 | #define TWOBLUECUBES_CATCH_RESULT_BUILDER_H_INCLUDED |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 743 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 744 | // #included from: catch_result_type.h |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 745 | #define TWOBLUECUBES_CATCH_RESULT_TYPE_H_INCLUDED |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 746 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 747 | namespace Catch { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 748 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 749 | // ResultWas::OfType enum |
| 750 | struct ResultWas { enum OfType { |
| 751 | Unknown = -1, |
| 752 | Ok = 0, |
| 753 | Info = 1, |
| 754 | Warning = 2, |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 755 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 756 | FailureBit = 0x10, |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 757 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 758 | ExpressionFailed = FailureBit | 1, |
| 759 | ExplicitFailure = FailureBit | 2, |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 760 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 761 | Exception = 0x100 | FailureBit, |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 762 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 763 | ThrewException = Exception | 1, |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 764 | DidntThrowException = Exception | 2, |
| 765 | |
| 766 | FatalErrorCondition = 0x200 | FailureBit |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 767 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 768 | }; }; |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 769 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 770 | inline bool isOk( ResultWas::OfType resultType ) { |
| 771 | return ( resultType & ResultWas::FailureBit ) == 0; |
| 772 | } |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 773 | inline bool isJustInfo( int flags ) { |
| 774 | return flags == ResultWas::Info; |
| 775 | } |
Phil Nash | 6730512 | 2012-10-09 11:48:55 +0100 | [diff] [blame] | 776 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 777 | // ResultDisposition::Flags enum |
| 778 | struct ResultDisposition { enum Flags { |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 779 | Normal = 0x01, |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 780 | |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 781 | ContinueOnFailure = 0x02, // Failures fail test, but execution continues |
| 782 | FalseTest = 0x04, // Prefix expression with ! |
| 783 | SuppressFail = 0x08 // Failures are reported but do not fail the test |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 784 | }; }; |
| 785 | |
| 786 | inline ResultDisposition::Flags operator | ( ResultDisposition::Flags lhs, ResultDisposition::Flags rhs ) { |
| 787 | return static_cast<ResultDisposition::Flags>( static_cast<int>( lhs ) | static_cast<int>( rhs ) ); |
| 788 | } |
| 789 | |
Phil Nash | 3e2e318 | 2012-11-17 10:49:24 +0000 | [diff] [blame] | 790 | inline bool shouldContinueOnFailure( int flags ) { return ( flags & ResultDisposition::ContinueOnFailure ) != 0; } |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 791 | inline bool isFalseTest( int flags ) { return ( flags & ResultDisposition::FalseTest ) != 0; } |
Phil Nash | 3e2e318 | 2012-11-17 10:49:24 +0000 | [diff] [blame] | 792 | inline bool shouldSuppressFailure( int flags ) { return ( flags & ResultDisposition::SuppressFail ) != 0; } |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 793 | |
| 794 | } // end namespace Catch |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 795 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 796 | // #included from: catch_assertionresult.h |
| 797 | #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED |
| 798 | |
| 799 | #include <string> |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 800 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 801 | namespace Catch { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 802 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 803 | struct AssertionInfo |
Phil Nash | 6730512 | 2012-10-09 11:48:55 +0100 | [diff] [blame] | 804 | { |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 805 | AssertionInfo() {} |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 806 | AssertionInfo( std::string const& _macroName, |
| 807 | SourceLineInfo const& _lineInfo, |
| 808 | std::string const& _capturedExpression, |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 809 | ResultDisposition::Flags _resultDisposition ); |
Phil Nash | 6730512 | 2012-10-09 11:48:55 +0100 | [diff] [blame] | 810 | |
| 811 | std::string macroName; |
| 812 | SourceLineInfo lineInfo; |
| 813 | std::string capturedExpression; |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 814 | ResultDisposition::Flags resultDisposition; |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 815 | }; |
| 816 | |
| 817 | struct AssertionResultData |
| 818 | { |
| 819 | AssertionResultData() : resultType( ResultWas::Unknown ) {} |
| 820 | |
Phil Nash | 6730512 | 2012-10-09 11:48:55 +0100 | [diff] [blame] | 821 | std::string reconstructedExpression; |
| 822 | std::string message; |
| 823 | ResultWas::OfType resultType; |
| 824 | }; |
| 825 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 826 | class AssertionResult { |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 827 | public: |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 828 | AssertionResult(); |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 829 | AssertionResult( AssertionInfo const& info, AssertionResultData const& data ); |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 830 | ~AssertionResult(); |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 831 | # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 832 | AssertionResult( AssertionResult const& ) = default; |
| 833 | AssertionResult( AssertionResult && ) = default; |
| 834 | AssertionResult& operator = ( AssertionResult const& ) = default; |
| 835 | AssertionResult& operator = ( AssertionResult && ) = default; |
| 836 | # endif |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 837 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 838 | bool isOk() const; |
| 839 | bool succeeded() const; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 840 | ResultWas::OfType getResultType() const; |
| 841 | bool hasExpression() const; |
| 842 | bool hasMessage() const; |
| 843 | std::string getExpression() const; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 844 | std::string getExpressionInMacro() const; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 845 | bool hasExpandedExpression() const; |
| 846 | std::string getExpandedExpression() const; |
| 847 | std::string getMessage() const; |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 848 | SourceLineInfo getSourceInfo() const; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 849 | std::string getTestMacroName() const; |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 850 | |
| 851 | protected: |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 852 | AssertionInfo m_info; |
| 853 | AssertionResultData m_resultData; |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 854 | }; |
| 855 | |
| 856 | } // end namespace Catch |
| 857 | |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 858 | // #included from: catch_matchers.hpp |
| 859 | #define TWOBLUECUBES_CATCH_MATCHERS_HPP_INCLUDED |
| 860 | |
| 861 | namespace Catch { |
| 862 | namespace Matchers { |
| 863 | namespace Impl { |
| 864 | |
Phil Nash | 08844e7 | 2015-11-05 18:52:18 +0000 | [diff] [blame] | 865 | namespace Generic { |
| 866 | template<typename ExpressionT> class AllOf; |
| 867 | template<typename ExpressionT> class AnyOf; |
| 868 | template<typename ExpressionT> class Not; |
| 869 | } |
| 870 | |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 871 | template<typename ExpressionT> |
| 872 | struct Matcher : SharedImpl<IShared> |
| 873 | { |
| 874 | typedef ExpressionT ExpressionType; |
| 875 | |
| 876 | virtual ~Matcher() {} |
| 877 | virtual Ptr<Matcher> clone() const = 0; |
| 878 | virtual bool match( ExpressionT const& expr ) const = 0; |
| 879 | virtual std::string toString() const = 0; |
Phil Nash | 08844e7 | 2015-11-05 18:52:18 +0000 | [diff] [blame] | 880 | |
| 881 | Generic::AllOf<ExpressionT> operator && ( Matcher<ExpressionT> const& other ) const; |
| 882 | Generic::AnyOf<ExpressionT> operator || ( Matcher<ExpressionT> const& other ) const; |
| 883 | Generic::Not<ExpressionT> operator ! () const; |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 884 | }; |
| 885 | |
| 886 | template<typename DerivedT, typename ExpressionT> |
| 887 | struct MatcherImpl : Matcher<ExpressionT> { |
| 888 | |
| 889 | virtual Ptr<Matcher<ExpressionT> > clone() const { |
| 890 | return Ptr<Matcher<ExpressionT> >( new DerivedT( static_cast<DerivedT const&>( *this ) ) ); |
| 891 | } |
| 892 | }; |
| 893 | |
| 894 | namespace Generic { |
Phil Nash | d234ed1 | 2015-08-24 06:28:25 +0100 | [diff] [blame] | 895 | template<typename ExpressionT> |
Phil Nash | 9235676 | 2015-11-06 18:06:56 +0000 | [diff] [blame] | 896 | class Not : public MatcherImpl<Not<ExpressionT>, ExpressionT> { |
| 897 | public: |
Phil Nash | 08844e7 | 2015-11-05 18:52:18 +0000 | [diff] [blame] | 898 | explicit Not( Matcher<ExpressionT> const& matcher ) : m_matcher(matcher.clone()) {} |
Phil Nash | d234ed1 | 2015-08-24 06:28:25 +0100 | [diff] [blame] | 899 | Not( Not const& other ) : m_matcher( other.m_matcher ) {} |
| 900 | |
| 901 | virtual bool match( ExpressionT const& expr ) const CATCH_OVERRIDE { |
| 902 | return !m_matcher->match( expr ); |
| 903 | } |
| 904 | |
| 905 | virtual std::string toString() const CATCH_OVERRIDE { |
| 906 | return "not " + m_matcher->toString(); |
| 907 | } |
Phil Nash | 9235676 | 2015-11-06 18:06:56 +0000 | [diff] [blame] | 908 | private: |
Phil Nash | d234ed1 | 2015-08-24 06:28:25 +0100 | [diff] [blame] | 909 | Ptr< Matcher<ExpressionT> > m_matcher; |
| 910 | }; |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 911 | |
| 912 | template<typename ExpressionT> |
| 913 | class AllOf : public MatcherImpl<AllOf<ExpressionT>, ExpressionT> { |
| 914 | public: |
| 915 | |
| 916 | AllOf() {} |
| 917 | AllOf( AllOf const& other ) : m_matchers( other.m_matchers ) {} |
| 918 | |
| 919 | AllOf& add( Matcher<ExpressionT> const& matcher ) { |
| 920 | m_matchers.push_back( matcher.clone() ); |
| 921 | return *this; |
| 922 | } |
| 923 | virtual bool match( ExpressionT const& expr ) const |
| 924 | { |
| 925 | for( std::size_t i = 0; i < m_matchers.size(); ++i ) |
| 926 | if( !m_matchers[i]->match( expr ) ) |
| 927 | return false; |
| 928 | return true; |
| 929 | } |
| 930 | virtual std::string toString() const { |
| 931 | std::ostringstream oss; |
| 932 | oss << "( "; |
| 933 | for( std::size_t i = 0; i < m_matchers.size(); ++i ) { |
| 934 | if( i != 0 ) |
| 935 | oss << " and "; |
| 936 | oss << m_matchers[i]->toString(); |
| 937 | } |
| 938 | oss << " )"; |
| 939 | return oss.str(); |
| 940 | } |
| 941 | |
Phil Nash | 08844e7 | 2015-11-05 18:52:18 +0000 | [diff] [blame] | 942 | AllOf operator && ( Matcher<ExpressionT> const& other ) const { |
| 943 | AllOf allOfExpr( *this ); |
| 944 | allOfExpr.add( other ); |
| 945 | return allOfExpr; |
| 946 | } |
| 947 | |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 948 | private: |
| 949 | std::vector<Ptr<Matcher<ExpressionT> > > m_matchers; |
| 950 | }; |
| 951 | |
| 952 | template<typename ExpressionT> |
| 953 | class AnyOf : public MatcherImpl<AnyOf<ExpressionT>, ExpressionT> { |
| 954 | public: |
| 955 | |
| 956 | AnyOf() {} |
| 957 | AnyOf( AnyOf const& other ) : m_matchers( other.m_matchers ) {} |
| 958 | |
| 959 | AnyOf& add( Matcher<ExpressionT> const& matcher ) { |
| 960 | m_matchers.push_back( matcher.clone() ); |
| 961 | return *this; |
| 962 | } |
| 963 | virtual bool match( ExpressionT const& expr ) const |
| 964 | { |
| 965 | for( std::size_t i = 0; i < m_matchers.size(); ++i ) |
| 966 | if( m_matchers[i]->match( expr ) ) |
| 967 | return true; |
| 968 | return false; |
| 969 | } |
| 970 | virtual std::string toString() const { |
| 971 | std::ostringstream oss; |
| 972 | oss << "( "; |
| 973 | for( std::size_t i = 0; i < m_matchers.size(); ++i ) { |
| 974 | if( i != 0 ) |
| 975 | oss << " or "; |
| 976 | oss << m_matchers[i]->toString(); |
| 977 | } |
| 978 | oss << " )"; |
| 979 | return oss.str(); |
| 980 | } |
| 981 | |
Phil Nash | 08844e7 | 2015-11-05 18:52:18 +0000 | [diff] [blame] | 982 | AnyOf operator || ( Matcher<ExpressionT> const& other ) const { |
| 983 | AnyOf anyOfExpr( *this ); |
| 984 | anyOfExpr.add( other ); |
| 985 | return anyOfExpr; |
| 986 | } |
| 987 | |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 988 | private: |
| 989 | std::vector<Ptr<Matcher<ExpressionT> > > m_matchers; |
| 990 | }; |
Phil Nash | 08844e7 | 2015-11-05 18:52:18 +0000 | [diff] [blame] | 991 | |
| 992 | } // namespace Generic |
| 993 | |
| 994 | template<typename ExpressionT> |
| 995 | Generic::AllOf<ExpressionT> Matcher<ExpressionT>::operator && ( Matcher<ExpressionT> const& other ) const { |
| 996 | Generic::AllOf<ExpressionT> allOfExpr; |
| 997 | allOfExpr.add( *this ); |
| 998 | allOfExpr.add( other ); |
| 999 | return allOfExpr; |
| 1000 | } |
| 1001 | |
| 1002 | template<typename ExpressionT> |
| 1003 | Generic::AnyOf<ExpressionT> Matcher<ExpressionT>::operator || ( Matcher<ExpressionT> const& other ) const { |
| 1004 | Generic::AnyOf<ExpressionT> anyOfExpr; |
| 1005 | anyOfExpr.add( *this ); |
| 1006 | anyOfExpr.add( other ); |
| 1007 | return anyOfExpr; |
| 1008 | } |
| 1009 | |
| 1010 | template<typename ExpressionT> |
| 1011 | Generic::Not<ExpressionT> Matcher<ExpressionT>::operator ! () const { |
| 1012 | return Generic::Not<ExpressionT>( *this ); |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | namespace StdString { |
| 1016 | |
| 1017 | inline std::string makeString( std::string const& str ) { return str; } |
| 1018 | inline std::string makeString( const char* str ) { return str ? std::string( str ) : std::string(); } |
| 1019 | |
| 1020 | struct CasedString |
| 1021 | { |
| 1022 | CasedString( std::string const& str, CaseSensitive::Choice caseSensitivity ) |
| 1023 | : m_caseSensitivity( caseSensitivity ), |
| 1024 | m_str( adjustString( str ) ) |
| 1025 | {} |
| 1026 | std::string adjustString( std::string const& str ) const { |
| 1027 | return m_caseSensitivity == CaseSensitive::No |
| 1028 | ? toLower( str ) |
| 1029 | : str; |
| 1030 | |
| 1031 | } |
| 1032 | std::string toStringSuffix() const |
| 1033 | { |
| 1034 | return m_caseSensitivity == CaseSensitive::No |
| 1035 | ? " (case insensitive)" |
| 1036 | : ""; |
| 1037 | } |
| 1038 | CaseSensitive::Choice m_caseSensitivity; |
| 1039 | std::string m_str; |
| 1040 | }; |
| 1041 | |
| 1042 | struct Equals : MatcherImpl<Equals, std::string> { |
| 1043 | Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) |
| 1044 | : m_data( str, caseSensitivity ) |
| 1045 | {} |
| 1046 | Equals( Equals const& other ) : m_data( other.m_data ){} |
| 1047 | |
| 1048 | virtual ~Equals(); |
| 1049 | |
| 1050 | virtual bool match( std::string const& expr ) const { |
| 1051 | return m_data.m_str == m_data.adjustString( expr );; |
| 1052 | } |
| 1053 | virtual std::string toString() const { |
| 1054 | return "equals: \"" + m_data.m_str + "\"" + m_data.toStringSuffix(); |
| 1055 | } |
| 1056 | |
| 1057 | CasedString m_data; |
| 1058 | }; |
| 1059 | |
| 1060 | struct Contains : MatcherImpl<Contains, std::string> { |
| 1061 | Contains( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) |
| 1062 | : m_data( substr, caseSensitivity ){} |
| 1063 | Contains( Contains const& other ) : m_data( other.m_data ){} |
| 1064 | |
| 1065 | virtual ~Contains(); |
| 1066 | |
| 1067 | virtual bool match( std::string const& expr ) const { |
| 1068 | return m_data.adjustString( expr ).find( m_data.m_str ) != std::string::npos; |
| 1069 | } |
| 1070 | virtual std::string toString() const { |
| 1071 | return "contains: \"" + m_data.m_str + "\"" + m_data.toStringSuffix(); |
| 1072 | } |
| 1073 | |
| 1074 | CasedString m_data; |
| 1075 | }; |
| 1076 | |
| 1077 | struct StartsWith : MatcherImpl<StartsWith, std::string> { |
| 1078 | StartsWith( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) |
| 1079 | : m_data( substr, caseSensitivity ){} |
| 1080 | |
| 1081 | StartsWith( StartsWith const& other ) : m_data( other.m_data ){} |
| 1082 | |
| 1083 | virtual ~StartsWith(); |
| 1084 | |
| 1085 | virtual bool match( std::string const& expr ) const { |
Phil Nash | c724356 | 2016-01-22 07:52:07 +0000 | [diff] [blame] | 1086 | return startsWith( m_data.adjustString( expr ), m_data.m_str ); |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 1087 | } |
| 1088 | virtual std::string toString() const { |
| 1089 | return "starts with: \"" + m_data.m_str + "\"" + m_data.toStringSuffix(); |
| 1090 | } |
| 1091 | |
| 1092 | CasedString m_data; |
| 1093 | }; |
| 1094 | |
| 1095 | struct EndsWith : MatcherImpl<EndsWith, std::string> { |
| 1096 | EndsWith( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) |
| 1097 | : m_data( substr, caseSensitivity ){} |
| 1098 | EndsWith( EndsWith const& other ) : m_data( other.m_data ){} |
| 1099 | |
| 1100 | virtual ~EndsWith(); |
| 1101 | |
| 1102 | virtual bool match( std::string const& expr ) const { |
Phil Nash | c724356 | 2016-01-22 07:52:07 +0000 | [diff] [blame] | 1103 | return endsWith( m_data.adjustString( expr ), m_data.m_str ); |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 1104 | } |
| 1105 | virtual std::string toString() const { |
| 1106 | return "ends with: \"" + m_data.m_str + "\"" + m_data.toStringSuffix(); |
| 1107 | } |
| 1108 | |
| 1109 | CasedString m_data; |
| 1110 | }; |
| 1111 | } // namespace StdString |
| 1112 | } // namespace Impl |
| 1113 | |
| 1114 | // The following functions create the actual matcher objects. |
| 1115 | // This allows the types to be inferred |
| 1116 | template<typename ExpressionT> |
Phil Nash | d234ed1 | 2015-08-24 06:28:25 +0100 | [diff] [blame] | 1117 | inline Impl::Generic::Not<ExpressionT> Not( Impl::Matcher<ExpressionT> const& m ) { |
| 1118 | return Impl::Generic::Not<ExpressionT>( m ); |
| 1119 | } |
| 1120 | |
| 1121 | template<typename ExpressionT> |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 1122 | inline Impl::Generic::AllOf<ExpressionT> AllOf( Impl::Matcher<ExpressionT> const& m1, |
| 1123 | Impl::Matcher<ExpressionT> const& m2 ) { |
| 1124 | return Impl::Generic::AllOf<ExpressionT>().add( m1 ).add( m2 ); |
| 1125 | } |
| 1126 | template<typename ExpressionT> |
| 1127 | inline Impl::Generic::AllOf<ExpressionT> AllOf( Impl::Matcher<ExpressionT> const& m1, |
| 1128 | Impl::Matcher<ExpressionT> const& m2, |
| 1129 | Impl::Matcher<ExpressionT> const& m3 ) { |
| 1130 | return Impl::Generic::AllOf<ExpressionT>().add( m1 ).add( m2 ).add( m3 ); |
| 1131 | } |
| 1132 | template<typename ExpressionT> |
| 1133 | inline Impl::Generic::AnyOf<ExpressionT> AnyOf( Impl::Matcher<ExpressionT> const& m1, |
| 1134 | Impl::Matcher<ExpressionT> const& m2 ) { |
| 1135 | return Impl::Generic::AnyOf<ExpressionT>().add( m1 ).add( m2 ); |
| 1136 | } |
| 1137 | template<typename ExpressionT> |
| 1138 | inline Impl::Generic::AnyOf<ExpressionT> AnyOf( Impl::Matcher<ExpressionT> const& m1, |
| 1139 | Impl::Matcher<ExpressionT> const& m2, |
| 1140 | Impl::Matcher<ExpressionT> const& m3 ) { |
| 1141 | return Impl::Generic::AnyOf<ExpressionT>().add( m1 ).add( m2 ).add( m3 ); |
| 1142 | } |
| 1143 | |
| 1144 | inline Impl::StdString::Equals Equals( std::string const& str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) { |
| 1145 | return Impl::StdString::Equals( str, caseSensitivity ); |
| 1146 | } |
| 1147 | inline Impl::StdString::Equals Equals( const char* str, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) { |
| 1148 | return Impl::StdString::Equals( Impl::StdString::makeString( str ), caseSensitivity ); |
| 1149 | } |
| 1150 | inline Impl::StdString::Contains Contains( std::string const& substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) { |
| 1151 | return Impl::StdString::Contains( substr, caseSensitivity ); |
| 1152 | } |
| 1153 | inline Impl::StdString::Contains Contains( const char* substr, CaseSensitive::Choice caseSensitivity = CaseSensitive::Yes ) { |
| 1154 | return Impl::StdString::Contains( Impl::StdString::makeString( substr ), caseSensitivity ); |
| 1155 | } |
| 1156 | inline Impl::StdString::StartsWith StartsWith( std::string const& substr ) { |
| 1157 | return Impl::StdString::StartsWith( substr ); |
| 1158 | } |
| 1159 | inline Impl::StdString::StartsWith StartsWith( const char* substr ) { |
| 1160 | return Impl::StdString::StartsWith( Impl::StdString::makeString( substr ) ); |
| 1161 | } |
| 1162 | inline Impl::StdString::EndsWith EndsWith( std::string const& substr ) { |
| 1163 | return Impl::StdString::EndsWith( substr ); |
| 1164 | } |
| 1165 | inline Impl::StdString::EndsWith EndsWith( const char* substr ) { |
| 1166 | return Impl::StdString::EndsWith( Impl::StdString::makeString( substr ) ); |
| 1167 | } |
| 1168 | |
| 1169 | } // namespace Matchers |
| 1170 | |
| 1171 | using namespace Matchers; |
| 1172 | |
| 1173 | } // namespace Catch |
| 1174 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1175 | namespace Catch { |
| 1176 | |
| 1177 | struct TestFailureException{}; |
| 1178 | |
| 1179 | template<typename T> class ExpressionLhs; |
| 1180 | |
| 1181 | struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison; |
| 1182 | |
| 1183 | struct CopyableStream { |
| 1184 | CopyableStream() {} |
| 1185 | CopyableStream( CopyableStream const& other ) { |
| 1186 | oss << other.oss.str(); |
| 1187 | } |
| 1188 | CopyableStream& operator=( CopyableStream const& other ) { |
| 1189 | oss.str(""); |
| 1190 | oss << other.oss.str(); |
| 1191 | return *this; |
| 1192 | } |
| 1193 | std::ostringstream oss; |
| 1194 | }; |
| 1195 | |
| 1196 | class ResultBuilder { |
| 1197 | public: |
| 1198 | ResultBuilder( char const* macroName, |
| 1199 | SourceLineInfo const& lineInfo, |
| 1200 | char const* capturedExpression, |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 1201 | ResultDisposition::Flags resultDisposition, |
| 1202 | char const* secondArg = "" ); |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1203 | |
| 1204 | template<typename T> |
Phil Nash | 21f7ef6 | 2015-06-29 18:05:23 +0100 | [diff] [blame] | 1205 | ExpressionLhs<T const&> operator <= ( T const& operand ); |
| 1206 | ExpressionLhs<bool> operator <= ( bool value ); |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1207 | |
| 1208 | template<typename T> |
| 1209 | ResultBuilder& operator << ( T const& value ) { |
| 1210 | m_stream.oss << value; |
| 1211 | return *this; |
| 1212 | } |
| 1213 | |
| 1214 | template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& ); |
| 1215 | template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& ); |
| 1216 | |
| 1217 | ResultBuilder& setResultType( ResultWas::OfType result ); |
| 1218 | ResultBuilder& setResultType( bool result ); |
| 1219 | ResultBuilder& setLhs( std::string const& lhs ); |
| 1220 | ResultBuilder& setRhs( std::string const& rhs ); |
| 1221 | ResultBuilder& setOp( std::string const& op ); |
| 1222 | |
| 1223 | void endExpression(); |
| 1224 | |
| 1225 | std::string reconstructExpression() const; |
| 1226 | AssertionResult build() const; |
| 1227 | |
| 1228 | void useActiveException( ResultDisposition::Flags resultDisposition = ResultDisposition::Normal ); |
| 1229 | void captureResult( ResultWas::OfType resultType ); |
| 1230 | void captureExpression(); |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 1231 | void captureExpectedException( std::string const& expectedMessage ); |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 1232 | void captureExpectedException( Matchers::Impl::Matcher<std::string> const& matcher ); |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 1233 | void handleResult( AssertionResult const& result ); |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1234 | void react(); |
| 1235 | bool shouldDebugBreak() const; |
| 1236 | bool allowThrows() const; |
| 1237 | |
| 1238 | private: |
| 1239 | AssertionInfo m_assertionInfo; |
| 1240 | AssertionResultData m_data; |
| 1241 | struct ExprComponents { |
| 1242 | ExprComponents() : testFalse( false ) {} |
| 1243 | bool testFalse; |
| 1244 | std::string lhs, rhs, op; |
| 1245 | } m_exprComponents; |
| 1246 | CopyableStream m_stream; |
| 1247 | |
| 1248 | bool m_shouldDebugBreak; |
| 1249 | bool m_shouldThrow; |
| 1250 | }; |
| 1251 | |
| 1252 | } // namespace Catch |
| 1253 | |
| 1254 | // Include after due to circular dependency: |
| 1255 | // #included from: catch_expression_lhs.hpp |
| 1256 | #define TWOBLUECUBES_CATCH_EXPRESSION_LHS_HPP_INCLUDED |
| 1257 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1258 | // #included from: catch_evaluate.hpp |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 1259 | #define TWOBLUECUBES_CATCH_EVALUATE_HPP_INCLUDED |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1260 | |
Phil Nash | dd26e88 | 2013-03-25 09:25:31 +0000 | [diff] [blame] | 1261 | #ifdef _MSC_VER |
| 1262 | #pragma warning(push) |
| 1263 | #pragma warning(disable:4389) // '==' : signed/unsigned mismatch |
| 1264 | #endif |
| 1265 | |
Phil Nash | 1740495 | 2014-04-23 18:19:49 +0100 | [diff] [blame] | 1266 | #include <cstddef> |
| 1267 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1268 | namespace Catch { |
| 1269 | namespace Internal { |
| 1270 | |
| 1271 | enum Operator { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1272 | IsEqualTo, |
| 1273 | IsNotEqualTo, |
| 1274 | IsLessThan, |
| 1275 | IsGreaterThan, |
| 1276 | IsLessThanOrEqualTo, |
| 1277 | IsGreaterThanOrEqualTo |
| 1278 | }; |
| 1279 | |
Phil Nash | 371db8b | 2012-05-21 18:52:09 +0100 | [diff] [blame] | 1280 | template<Operator Op> struct OperatorTraits { static const char* getName(){ return "*error*"; } }; |
| 1281 | template<> struct OperatorTraits<IsEqualTo> { static const char* getName(){ return "=="; } }; |
| 1282 | template<> struct OperatorTraits<IsNotEqualTo> { static const char* getName(){ return "!="; } }; |
| 1283 | template<> struct OperatorTraits<IsLessThan> { static const char* getName(){ return "<"; } }; |
| 1284 | template<> struct OperatorTraits<IsGreaterThan> { static const char* getName(){ return ">"; } }; |
| 1285 | template<> struct OperatorTraits<IsLessThanOrEqualTo> { static const char* getName(){ return "<="; } }; |
| 1286 | template<> struct OperatorTraits<IsGreaterThanOrEqualTo>{ static const char* getName(){ return ">="; } }; |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1287 | |
Phil Nash | 471eba2 | 2013-04-22 18:55:12 +0100 | [diff] [blame] | 1288 | template<typename T> |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 1289 | inline T& opCast(T const& t) { return const_cast<T&>(t); } |
Phil Nash | 471eba2 | 2013-04-22 18:55:12 +0100 | [diff] [blame] | 1290 | |
| 1291 | // nullptr_t support based on pull request #154 from Konstantin Baumann |
| 1292 | #ifdef CATCH_CONFIG_CPP11_NULLPTR |
| 1293 | inline std::nullptr_t opCast(std::nullptr_t) { return nullptr; } |
| 1294 | #endif // CATCH_CONFIG_CPP11_NULLPTR |
| 1295 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1296 | // So the compare overloads can be operator agnostic we convey the operator as a template |
| 1297 | // enum, which is used to specialise an Evaluator for doing the comparison. |
| 1298 | template<typename T1, typename T2, Operator Op> |
| 1299 | class Evaluator{}; |
| 1300 | |
| 1301 | template<typename T1, typename T2> |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1302 | struct Evaluator<T1, T2, IsEqualTo> { |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 1303 | static bool evaluate( T1 const& lhs, T2 const& rhs) { |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 1304 | return bool( opCast( lhs ) == opCast( rhs ) ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1305 | } |
| 1306 | }; |
| 1307 | template<typename T1, typename T2> |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1308 | struct Evaluator<T1, T2, IsNotEqualTo> { |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 1309 | static bool evaluate( T1 const& lhs, T2 const& rhs ) { |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 1310 | return bool( opCast( lhs ) != opCast( rhs ) ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1311 | } |
| 1312 | }; |
| 1313 | template<typename T1, typename T2> |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1314 | struct Evaluator<T1, T2, IsLessThan> { |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 1315 | static bool evaluate( T1 const& lhs, T2 const& rhs ) { |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 1316 | return bool( opCast( lhs ) < opCast( rhs ) ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1317 | } |
| 1318 | }; |
| 1319 | template<typename T1, typename T2> |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1320 | struct Evaluator<T1, T2, IsGreaterThan> { |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 1321 | static bool evaluate( T1 const& lhs, T2 const& rhs ) { |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 1322 | return bool( opCast( lhs ) > opCast( rhs ) ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1323 | } |
| 1324 | }; |
| 1325 | template<typename T1, typename T2> |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1326 | struct Evaluator<T1, T2, IsGreaterThanOrEqualTo> { |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 1327 | static bool evaluate( T1 const& lhs, T2 const& rhs ) { |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 1328 | return bool( opCast( lhs ) >= opCast( rhs ) ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1329 | } |
| 1330 | }; |
| 1331 | template<typename T1, typename T2> |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1332 | struct Evaluator<T1, T2, IsLessThanOrEqualTo> { |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 1333 | static bool evaluate( T1 const& lhs, T2 const& rhs ) { |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 1334 | return bool( opCast( lhs ) <= opCast( rhs ) ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1335 | } |
| 1336 | }; |
| 1337 | |
| 1338 | template<Operator Op, typename T1, typename T2> |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 1339 | bool applyEvaluator( T1 const& lhs, T2 const& rhs ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1340 | return Evaluator<T1, T2, Op>::evaluate( lhs, rhs ); |
| 1341 | } |
| 1342 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 1343 | // This level of indirection allows us to specialise for integer types |
| 1344 | // to avoid signed/ unsigned warnings |
| 1345 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1346 | // "base" overload |
| 1347 | template<Operator Op, typename T1, typename T2> |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 1348 | bool compare( T1 const& lhs, T2 const& rhs ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1349 | return Evaluator<T1, T2, Op>::evaluate( lhs, rhs ); |
| 1350 | } |
| 1351 | |
| 1352 | // unsigned X to int |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1353 | template<Operator Op> bool compare( unsigned int lhs, int rhs ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1354 | return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) ); |
| 1355 | } |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1356 | template<Operator Op> bool compare( unsigned long lhs, int rhs ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1357 | return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) ); |
| 1358 | } |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1359 | template<Operator Op> bool compare( unsigned char lhs, int rhs ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1360 | return applyEvaluator<Op>( lhs, static_cast<unsigned int>( rhs ) ); |
| 1361 | } |
| 1362 | |
| 1363 | // unsigned X to long |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1364 | template<Operator Op> bool compare( unsigned int lhs, long rhs ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1365 | return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) ); |
| 1366 | } |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1367 | template<Operator Op> bool compare( unsigned long lhs, long rhs ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1368 | return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) ); |
| 1369 | } |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1370 | template<Operator Op> bool compare( unsigned char lhs, long rhs ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1371 | return applyEvaluator<Op>( lhs, static_cast<unsigned long>( rhs ) ); |
| 1372 | } |
| 1373 | |
| 1374 | // int to unsigned X |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1375 | template<Operator Op> bool compare( int lhs, unsigned int rhs ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1376 | return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs ); |
| 1377 | } |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1378 | template<Operator Op> bool compare( int lhs, unsigned long rhs ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1379 | return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs ); |
| 1380 | } |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1381 | template<Operator Op> bool compare( int lhs, unsigned char rhs ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1382 | return applyEvaluator<Op>( static_cast<unsigned int>( lhs ), rhs ); |
| 1383 | } |
| 1384 | |
| 1385 | // long to unsigned X |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1386 | template<Operator Op> bool compare( long lhs, unsigned int rhs ) { |
Jardel Weyrich | 11dca66 | 2012-04-27 14:42:40 -0300 | [diff] [blame] | 1387 | return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1388 | } |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1389 | template<Operator Op> bool compare( long lhs, unsigned long rhs ) { |
Jardel Weyrich | 11dca66 | 2012-04-27 14:42:40 -0300 | [diff] [blame] | 1390 | return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1391 | } |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1392 | template<Operator Op> bool compare( long lhs, unsigned char rhs ) { |
Jardel Weyrich | 11dca66 | 2012-04-27 14:42:40 -0300 | [diff] [blame] | 1393 | return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1394 | } |
| 1395 | |
Phil Nash | 06e959b | 2012-05-25 08:52:05 +0100 | [diff] [blame] | 1396 | // pointer to long (when comparing against NULL) |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 1397 | template<Operator Op, typename T> bool compare( long lhs, T* rhs ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1398 | return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs ); |
Phil Nash | 6f1543b | 2012-05-07 19:46:19 +0100 | [diff] [blame] | 1399 | } |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 1400 | template<Operator Op, typename T> bool compare( T* lhs, long rhs ) { |
Phil Nash | 6f1543b | 2012-05-07 19:46:19 +0100 | [diff] [blame] | 1401 | return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1402 | } |
| 1403 | |
Phil Nash | 06e959b | 2012-05-25 08:52:05 +0100 | [diff] [blame] | 1404 | // pointer to int (when comparing against NULL) |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 1405 | template<Operator Op, typename T> bool compare( int lhs, T* rhs ) { |
Phil Nash | 06e959b | 2012-05-25 08:52:05 +0100 | [diff] [blame] | 1406 | return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs ); |
| 1407 | } |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 1408 | template<Operator Op, typename T> bool compare( T* lhs, int rhs ) { |
Phil Nash | 06e959b | 2012-05-25 08:52:05 +0100 | [diff] [blame] | 1409 | return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) ); |
| 1410 | } |
| 1411 | |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 1412 | #ifdef CATCH_CONFIG_CPP11_LONG_LONG |
| 1413 | // long long to unsigned X |
| 1414 | template<Operator Op> bool compare( long long lhs, unsigned int rhs ) { |
| 1415 | return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); |
| 1416 | } |
| 1417 | template<Operator Op> bool compare( long long lhs, unsigned long rhs ) { |
| 1418 | return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); |
| 1419 | } |
| 1420 | template<Operator Op> bool compare( long long lhs, unsigned long long rhs ) { |
| 1421 | return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); |
| 1422 | } |
| 1423 | template<Operator Op> bool compare( long long lhs, unsigned char rhs ) { |
| 1424 | return applyEvaluator<Op>( static_cast<unsigned long>( lhs ), rhs ); |
| 1425 | } |
| 1426 | |
| 1427 | // unsigned long long to X |
| 1428 | template<Operator Op> bool compare( unsigned long long lhs, int rhs ) { |
| 1429 | return applyEvaluator<Op>( static_cast<long>( lhs ), rhs ); |
| 1430 | } |
| 1431 | template<Operator Op> bool compare( unsigned long long lhs, long rhs ) { |
| 1432 | return applyEvaluator<Op>( static_cast<long>( lhs ), rhs ); |
| 1433 | } |
| 1434 | template<Operator Op> bool compare( unsigned long long lhs, long long rhs ) { |
| 1435 | return applyEvaluator<Op>( static_cast<long>( lhs ), rhs ); |
| 1436 | } |
| 1437 | template<Operator Op> bool compare( unsigned long long lhs, char rhs ) { |
| 1438 | return applyEvaluator<Op>( static_cast<long>( lhs ), rhs ); |
| 1439 | } |
| 1440 | |
| 1441 | // pointer to long long (when comparing against NULL) |
| 1442 | template<Operator Op, typename T> bool compare( long long lhs, T* rhs ) { |
| 1443 | return Evaluator<T*, T*, Op>::evaluate( reinterpret_cast<T*>( lhs ), rhs ); |
| 1444 | } |
| 1445 | template<Operator Op, typename T> bool compare( T* lhs, long long rhs ) { |
| 1446 | return Evaluator<T*, T*, Op>::evaluate( lhs, reinterpret_cast<T*>( rhs ) ); |
| 1447 | } |
| 1448 | #endif // CATCH_CONFIG_CPP11_LONG_LONG |
| 1449 | |
Phil Nash | 471eba2 | 2013-04-22 18:55:12 +0100 | [diff] [blame] | 1450 | #ifdef CATCH_CONFIG_CPP11_NULLPTR |
| 1451 | // pointer to nullptr_t (when comparing against nullptr) |
| 1452 | template<Operator Op, typename T> bool compare( std::nullptr_t, T* rhs ) { |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 1453 | return Evaluator<T*, T*, Op>::evaluate( nullptr, rhs ); |
Phil Nash | 471eba2 | 2013-04-22 18:55:12 +0100 | [diff] [blame] | 1454 | } |
| 1455 | template<Operator Op, typename T> bool compare( T* lhs, std::nullptr_t ) { |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 1456 | return Evaluator<T*, T*, Op>::evaluate( lhs, nullptr ); |
Phil Nash | 471eba2 | 2013-04-22 18:55:12 +0100 | [diff] [blame] | 1457 | } |
| 1458 | #endif // CATCH_CONFIG_CPP11_NULLPTR |
| 1459 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1460 | } // end of namespace Internal |
| 1461 | } // end of namespace Catch |
| 1462 | |
Phil Nash | dd26e88 | 2013-03-25 09:25:31 +0000 | [diff] [blame] | 1463 | #ifdef _MSC_VER |
| 1464 | #pragma warning(pop) |
| 1465 | #endif |
| 1466 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1467 | // #included from: catch_tostring.h |
| 1468 | #define TWOBLUECUBES_CATCH_TOSTRING_H_INCLUDED |
| 1469 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1470 | #include <sstream> |
| 1471 | #include <iomanip> |
| 1472 | #include <limits> |
| 1473 | #include <vector> |
| 1474 | #include <cstddef> |
| 1475 | |
| 1476 | #ifdef __OBJC__ |
| 1477 | // #included from: catch_objc_arc.hpp |
| 1478 | #define TWOBLUECUBES_CATCH_OBJC_ARC_HPP_INCLUDED |
| 1479 | |
| 1480 | #import <Foundation/Foundation.h> |
| 1481 | |
| 1482 | #ifdef __has_feature |
| 1483 | #define CATCH_ARC_ENABLED __has_feature(objc_arc) |
| 1484 | #else |
| 1485 | #define CATCH_ARC_ENABLED 0 |
| 1486 | #endif |
| 1487 | |
| 1488 | void arcSafeRelease( NSObject* obj ); |
| 1489 | id performOptionalSelector( id obj, SEL sel ); |
| 1490 | |
| 1491 | #if !CATCH_ARC_ENABLED |
| 1492 | inline void arcSafeRelease( NSObject* obj ) { |
| 1493 | [obj release]; |
| 1494 | } |
| 1495 | inline id performOptionalSelector( id obj, SEL sel ) { |
| 1496 | if( [obj respondsToSelector: sel] ) |
| 1497 | return [obj performSelector: sel]; |
| 1498 | return nil; |
| 1499 | } |
| 1500 | #define CATCH_UNSAFE_UNRETAINED |
| 1501 | #define CATCH_ARC_STRONG |
| 1502 | #else |
| 1503 | inline void arcSafeRelease( NSObject* ){} |
| 1504 | inline id performOptionalSelector( id obj, SEL sel ) { |
| 1505 | #ifdef __clang__ |
| 1506 | #pragma clang diagnostic push |
| 1507 | #pragma clang diagnostic ignored "-Warc-performSelector-leaks" |
| 1508 | #endif |
| 1509 | if( [obj respondsToSelector: sel] ) |
| 1510 | return [obj performSelector: sel]; |
| 1511 | #ifdef __clang__ |
| 1512 | #pragma clang diagnostic pop |
| 1513 | #endif |
| 1514 | return nil; |
| 1515 | } |
| 1516 | #define CATCH_UNSAFE_UNRETAINED __unsafe_unretained |
| 1517 | #define CATCH_ARC_STRONG __strong |
| 1518 | #endif |
| 1519 | |
| 1520 | #endif |
| 1521 | |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 1522 | #ifdef CATCH_CONFIG_CPP11_TUPLE |
Phil Nash | 7f56152 | 2014-12-30 18:47:29 +0000 | [diff] [blame] | 1523 | #include <tuple> |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 1524 | #endif |
| 1525 | |
| 1526 | #ifdef CATCH_CONFIG_CPP11_IS_ENUM |
Phil Nash | 7f56152 | 2014-12-30 18:47:29 +0000 | [diff] [blame] | 1527 | #include <type_traits> |
| 1528 | #endif |
| 1529 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1530 | namespace Catch { |
Phil Nash | 4caabfa | 2014-09-03 19:23:22 +0100 | [diff] [blame] | 1531 | |
| 1532 | // Why we're here. |
| 1533 | template<typename T> |
| 1534 | std::string toString( T const& value ); |
| 1535 | |
Phil Nash | 7f56152 | 2014-12-30 18:47:29 +0000 | [diff] [blame] | 1536 | // Built in overloads |
| 1537 | |
| 1538 | std::string toString( std::string const& value ); |
| 1539 | std::string toString( std::wstring const& value ); |
| 1540 | std::string toString( const char* const value ); |
| 1541 | std::string toString( char* const value ); |
| 1542 | std::string toString( const wchar_t* const value ); |
| 1543 | std::string toString( wchar_t* const value ); |
| 1544 | std::string toString( int value ); |
| 1545 | std::string toString( unsigned long value ); |
| 1546 | std::string toString( unsigned int value ); |
| 1547 | std::string toString( const double value ); |
| 1548 | std::string toString( const float value ); |
| 1549 | std::string toString( bool value ); |
| 1550 | std::string toString( char value ); |
| 1551 | std::string toString( signed char value ); |
| 1552 | std::string toString( unsigned char value ); |
| 1553 | |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 1554 | #ifdef CATCH_CONFIG_CPP11_LONG_LONG |
| 1555 | std::string toString( long long value ); |
| 1556 | std::string toString( unsigned long long value ); |
| 1557 | #endif |
| 1558 | |
Phil Nash | 7f56152 | 2014-12-30 18:47:29 +0000 | [diff] [blame] | 1559 | #ifdef CATCH_CONFIG_CPP11_NULLPTR |
| 1560 | std::string toString( std::nullptr_t ); |
| 1561 | #endif |
| 1562 | |
| 1563 | #ifdef __OBJC__ |
| 1564 | std::string toString( NSString const * const& nsstring ); |
| 1565 | std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ); |
| 1566 | std::string toString( NSObject* const& nsObject ); |
| 1567 | #endif |
| 1568 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1569 | namespace Detail { |
| 1570 | |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 1571 | extern const std::string unprintableString; |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 1572 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1573 | struct BorgType { |
| 1574 | template<typename T> BorgType( T const& ); |
| 1575 | }; |
| 1576 | |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 1577 | struct TrueType { char sizer[1]; }; |
| 1578 | struct FalseType { char sizer[2]; }; |
| 1579 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1580 | TrueType& testStreamable( std::ostream& ); |
| 1581 | FalseType testStreamable( FalseType ); |
| 1582 | |
| 1583 | FalseType operator<<( std::ostream const&, BorgType const& ); |
| 1584 | |
| 1585 | template<typename T> |
| 1586 | struct IsStreamInsertable { |
| 1587 | static std::ostream &s; |
| 1588 | static T const&t; |
| 1589 | enum { value = sizeof( testStreamable(s << t) ) == sizeof( TrueType ) }; |
| 1590 | }; |
| 1591 | |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 1592 | #if defined(CATCH_CONFIG_CPP11_IS_ENUM) |
Phil Nash | 4caabfa | 2014-09-03 19:23:22 +0100 | [diff] [blame] | 1593 | template<typename T, |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 1594 | bool IsEnum = std::is_enum<T>::value |
Phil Nash | 4caabfa | 2014-09-03 19:23:22 +0100 | [diff] [blame] | 1595 | > |
| 1596 | struct EnumStringMaker |
| 1597 | { |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 1598 | static std::string convert( T const& ) { return unprintableString; } |
Phil Nash | 4caabfa | 2014-09-03 19:23:22 +0100 | [diff] [blame] | 1599 | }; |
| 1600 | |
| 1601 | template<typename T> |
| 1602 | struct EnumStringMaker<T,true> |
| 1603 | { |
| 1604 | static std::string convert( T const& v ) |
| 1605 | { |
| 1606 | return ::Catch::toString( |
| 1607 | static_cast<typename std::underlying_type<T>::type>(v) |
| 1608 | ); |
| 1609 | } |
| 1610 | }; |
| 1611 | #endif |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1612 | template<bool C> |
| 1613 | struct StringMakerBase { |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 1614 | #if defined(CATCH_CONFIG_CPP11_IS_ENUM) |
Phil Nash | 4caabfa | 2014-09-03 19:23:22 +0100 | [diff] [blame] | 1615 | template<typename T> |
| 1616 | static std::string convert( T const& v ) |
| 1617 | { |
| 1618 | return EnumStringMaker<T>::convert( v ); |
| 1619 | } |
| 1620 | #else |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1621 | template<typename T> |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 1622 | static std::string convert( T const& ) { return unprintableString; } |
Phil Nash | 4caabfa | 2014-09-03 19:23:22 +0100 | [diff] [blame] | 1623 | #endif |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1624 | }; |
| 1625 | |
| 1626 | template<> |
| 1627 | struct StringMakerBase<true> { |
| 1628 | template<typename T> |
| 1629 | static std::string convert( T const& _value ) { |
| 1630 | std::ostringstream oss; |
| 1631 | oss << _value; |
| 1632 | return oss.str(); |
| 1633 | } |
| 1634 | }; |
| 1635 | |
| 1636 | std::string rawMemoryToString( const void *object, std::size_t size ); |
| 1637 | |
| 1638 | template<typename T> |
| 1639 | inline std::string rawMemoryToString( const T& object ) { |
| 1640 | return rawMemoryToString( &object, sizeof(object) ); |
Phil Nash | 6730512 | 2012-10-09 11:48:55 +0100 | [diff] [blame] | 1641 | } |
| 1642 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1643 | } // end namespace Detail |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 1644 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1645 | template<typename T> |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1646 | struct StringMaker : |
| 1647 | Detail::StringMakerBase<Detail::IsStreamInsertable<T>::value> {}; |
Phil Nash | cd68830 | 2013-06-29 12:11:32 +0100 | [diff] [blame] | 1648 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1649 | template<typename T> |
| 1650 | struct StringMaker<T*> { |
| 1651 | template<typename U> |
| 1652 | static std::string convert( U* p ) { |
| 1653 | if( !p ) |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 1654 | return "NULL"; |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1655 | else |
| 1656 | return Detail::rawMemoryToString( p ); |
| 1657 | } |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 1658 | }; |
| 1659 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1660 | template<typename R, typename C> |
| 1661 | struct StringMaker<R C::*> { |
| 1662 | static std::string convert( R C::* p ) { |
| 1663 | if( !p ) |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 1664 | return "NULL"; |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1665 | else |
| 1666 | return Detail::rawMemoryToString( p ); |
| 1667 | } |
| 1668 | }; |
| 1669 | |
| 1670 | namespace Detail { |
| 1671 | template<typename InputIterator> |
| 1672 | std::string rangeToString( InputIterator first, InputIterator last ); |
| 1673 | } |
| 1674 | |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 1675 | //template<typename T, typename Allocator> |
| 1676 | //struct StringMaker<std::vector<T, Allocator> > { |
| 1677 | // static std::string convert( std::vector<T,Allocator> const& v ) { |
| 1678 | // return Detail::rangeToString( v.begin(), v.end() ); |
| 1679 | // } |
| 1680 | //}; |
| 1681 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1682 | template<typename T, typename Allocator> |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 1683 | std::string toString( std::vector<T,Allocator> const& v ) { |
| 1684 | return Detail::rangeToString( v.begin(), v.end() ); |
| 1685 | } |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1686 | |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 1687 | #ifdef CATCH_CONFIG_CPP11_TUPLE |
Phil Nash | 572911d | 2015-03-04 18:33:31 +0000 | [diff] [blame] | 1688 | |
| 1689 | // toString for tuples |
Phil Nash | 7f56152 | 2014-12-30 18:47:29 +0000 | [diff] [blame] | 1690 | namespace TupleDetail { |
| 1691 | template< |
| 1692 | typename Tuple, |
| 1693 | std::size_t N = 0, |
| 1694 | bool = (N < std::tuple_size<Tuple>::value) |
| 1695 | > |
| 1696 | struct ElementPrinter { |
| 1697 | static void print( const Tuple& tuple, std::ostream& os ) |
| 1698 | { |
| 1699 | os << ( N ? ", " : " " ) |
| 1700 | << Catch::toString(std::get<N>(tuple)); |
| 1701 | ElementPrinter<Tuple,N+1>::print(tuple,os); |
| 1702 | } |
| 1703 | }; |
| 1704 | |
| 1705 | template< |
| 1706 | typename Tuple, |
| 1707 | std::size_t N |
| 1708 | > |
| 1709 | struct ElementPrinter<Tuple,N,false> { |
| 1710 | static void print( const Tuple&, std::ostream& ) {} |
| 1711 | }; |
| 1712 | |
| 1713 | } |
| 1714 | |
| 1715 | template<typename ...Types> |
| 1716 | struct StringMaker<std::tuple<Types...>> { |
| 1717 | |
| 1718 | static std::string convert( const std::tuple<Types...>& tuple ) |
| 1719 | { |
| 1720 | std::ostringstream os; |
| 1721 | os << '{'; |
| 1722 | TupleDetail::ElementPrinter<std::tuple<Types...>>::print( tuple, os ); |
| 1723 | os << " }"; |
| 1724 | return os.str(); |
| 1725 | } |
| 1726 | }; |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 1727 | #endif // CATCH_CONFIG_CPP11_TUPLE |
Phil Nash | 7f56152 | 2014-12-30 18:47:29 +0000 | [diff] [blame] | 1728 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1729 | namespace Detail { |
| 1730 | template<typename T> |
| 1731 | std::string makeString( T const& value ) { |
| 1732 | return StringMaker<T>::convert( value ); |
| 1733 | } |
| 1734 | } // end namespace Detail |
| 1735 | |
| 1736 | /// \brief converts any type to a string |
| 1737 | /// |
| 1738 | /// The default template forwards on to ostringstream - except when an |
| 1739 | /// ostringstream overload does not exist - in which case it attempts to detect |
| 1740 | /// that and writes {?}. |
| 1741 | /// Overload (not specialise) this template for custom typs that you don't want |
| 1742 | /// to provide an ostream overload for. |
| 1743 | template<typename T> |
| 1744 | std::string toString( T const& value ) { |
| 1745 | return StringMaker<T>::convert( value ); |
| 1746 | } |
| 1747 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1748 | namespace Detail { |
| 1749 | template<typename InputIterator> |
| 1750 | std::string rangeToString( InputIterator first, InputIterator last ) { |
| 1751 | std::ostringstream oss; |
| 1752 | oss << "{ "; |
| 1753 | if( first != last ) { |
Phil Nash | 13f9843 | 2014-12-12 08:11:18 +0000 | [diff] [blame] | 1754 | oss << Catch::toString( *first ); |
| 1755 | for( ++first ; first != last ; ++first ) |
| 1756 | oss << ", " << Catch::toString( *first ); |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1757 | } |
| 1758 | oss << " }"; |
| 1759 | return oss.str(); |
| 1760 | } |
| 1761 | } |
| 1762 | |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1763 | } // end namespace Catch |
| 1764 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1765 | namespace Catch { |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1766 | |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 1767 | // Wraps the LHS of an expression and captures the operator and RHS (if any) - |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1768 | // wrapping them all in a ResultBuilder object |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1769 | template<typename T> |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 1770 | class ExpressionLhs { |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 1771 | ExpressionLhs& operator = ( ExpressionLhs const& ); |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 1772 | # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 1773 | ExpressionLhs& operator = ( ExpressionLhs && ) = delete; |
| 1774 | # endif |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1775 | |
| 1776 | public: |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1777 | ExpressionLhs( ResultBuilder& rb, T lhs ) : m_rb( rb ), m_lhs( lhs ) {} |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 1778 | # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 1779 | ExpressionLhs( ExpressionLhs const& ) = default; |
| 1780 | ExpressionLhs( ExpressionLhs && ) = default; |
| 1781 | # endif |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1782 | |
| 1783 | template<typename RhsT> |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1784 | ResultBuilder& operator == ( RhsT const& rhs ) { |
Phil Nash | 9902ac9 | 2012-10-09 20:58:33 +0100 | [diff] [blame] | 1785 | return captureExpression<Internal::IsEqualTo>( rhs ); |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | template<typename RhsT> |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1789 | ResultBuilder& operator != ( RhsT const& rhs ) { |
Phil Nash | 9902ac9 | 2012-10-09 20:58:33 +0100 | [diff] [blame] | 1790 | return captureExpression<Internal::IsNotEqualTo>( rhs ); |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1791 | } |
| 1792 | |
| 1793 | template<typename RhsT> |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1794 | ResultBuilder& operator < ( RhsT const& rhs ) { |
Phil Nash | 9902ac9 | 2012-10-09 20:58:33 +0100 | [diff] [blame] | 1795 | return captureExpression<Internal::IsLessThan>( rhs ); |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1796 | } |
| 1797 | |
| 1798 | template<typename RhsT> |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1799 | ResultBuilder& operator > ( RhsT const& rhs ) { |
Phil Nash | 9902ac9 | 2012-10-09 20:58:33 +0100 | [diff] [blame] | 1800 | return captureExpression<Internal::IsGreaterThan>( rhs ); |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | template<typename RhsT> |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1804 | ResultBuilder& operator <= ( RhsT const& rhs ) { |
Phil Nash | 9902ac9 | 2012-10-09 20:58:33 +0100 | [diff] [blame] | 1805 | return captureExpression<Internal::IsLessThanOrEqualTo>( rhs ); |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1806 | } |
| 1807 | |
| 1808 | template<typename RhsT> |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1809 | ResultBuilder& operator >= ( RhsT const& rhs ) { |
Phil Nash | 9902ac9 | 2012-10-09 20:58:33 +0100 | [diff] [blame] | 1810 | return captureExpression<Internal::IsGreaterThanOrEqualTo>( rhs ); |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1811 | } |
| 1812 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1813 | ResultBuilder& operator == ( bool rhs ) { |
Phil Nash | 9902ac9 | 2012-10-09 20:58:33 +0100 | [diff] [blame] | 1814 | return captureExpression<Internal::IsEqualTo>( rhs ); |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1815 | } |
| 1816 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1817 | ResultBuilder& operator != ( bool rhs ) { |
Phil Nash | 9902ac9 | 2012-10-09 20:58:33 +0100 | [diff] [blame] | 1818 | return captureExpression<Internal::IsNotEqualTo>( rhs ); |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1819 | } |
| 1820 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1821 | void endExpression() { |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 1822 | bool value = m_lhs ? true : false; |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1823 | m_rb |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 1824 | .setLhs( Catch::toString( value ) ) |
| 1825 | .setResultType( value ) |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1826 | .endExpression(); |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1827 | } |
| 1828 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 1829 | // Only simple binary expressions are allowed on the LHS. |
| 1830 | // If more complex compositions are required then place the sub expression in parentheses |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 1831 | template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( RhsT const& ); |
| 1832 | template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( RhsT const& ); |
| 1833 | template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( RhsT const& ); |
| 1834 | template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( RhsT const& ); |
Phil Nash | cd68830 | 2013-06-29 12:11:32 +0100 | [diff] [blame] | 1835 | template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( RhsT const& ); |
| 1836 | template<typename RhsT> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( RhsT const& ); |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1837 | |
| 1838 | private: |
Phil Nash | 9902ac9 | 2012-10-09 20:58:33 +0100 | [diff] [blame] | 1839 | template<Internal::Operator Op, typename RhsT> |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1840 | ResultBuilder& captureExpression( RhsT const& rhs ) { |
| 1841 | return m_rb |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 1842 | .setResultType( Internal::compare<Op>( m_lhs, rhs ) ) |
| 1843 | .setLhs( Catch::toString( m_lhs ) ) |
Phil Nash | 9902ac9 | 2012-10-09 20:58:33 +0100 | [diff] [blame] | 1844 | .setRhs( Catch::toString( rhs ) ) |
| 1845 | .setOp( Internal::OperatorTraits<Op>::getName() ); |
| 1846 | } |
| 1847 | |
| 1848 | private: |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1849 | ResultBuilder& m_rb; |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1850 | T m_lhs; |
| 1851 | }; |
| 1852 | |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 1853 | } // end namespace Catch |
| 1854 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1855 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1856 | namespace Catch { |
| 1857 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1858 | template<typename T> |
Phil Nash | 21f7ef6 | 2015-06-29 18:05:23 +0100 | [diff] [blame] | 1859 | inline ExpressionLhs<T const&> ResultBuilder::operator <= ( T const& operand ) { |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1860 | return ExpressionLhs<T const&>( *this, operand ); |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1861 | } |
| 1862 | |
Phil Nash | 21f7ef6 | 2015-06-29 18:05:23 +0100 | [diff] [blame] | 1863 | inline ExpressionLhs<bool> ResultBuilder::operator <= ( bool value ) { |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1864 | return ExpressionLhs<bool>( *this, value ); |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1865 | } |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1866 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1867 | } // namespace Catch |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1868 | |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 1869 | // #included from: catch_message.h |
| 1870 | #define TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED |
| 1871 | |
| 1872 | #include <string> |
| 1873 | |
| 1874 | namespace Catch { |
| 1875 | |
| 1876 | struct MessageInfo { |
| 1877 | MessageInfo( std::string const& _macroName, |
| 1878 | SourceLineInfo const& _lineInfo, |
| 1879 | ResultWas::OfType _type ); |
| 1880 | |
| 1881 | std::string macroName; |
| 1882 | SourceLineInfo lineInfo; |
| 1883 | ResultWas::OfType type; |
| 1884 | std::string message; |
| 1885 | unsigned int sequence; |
| 1886 | |
| 1887 | bool operator == ( MessageInfo const& other ) const { |
| 1888 | return sequence == other.sequence; |
| 1889 | } |
| 1890 | bool operator < ( MessageInfo const& other ) const { |
| 1891 | return sequence < other.sequence; |
| 1892 | } |
| 1893 | private: |
| 1894 | static unsigned int globalCount; |
| 1895 | }; |
| 1896 | |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 1897 | struct MessageBuilder { |
| 1898 | MessageBuilder( std::string const& macroName, |
| 1899 | SourceLineInfo const& lineInfo, |
| 1900 | ResultWas::OfType type ) |
| 1901 | : m_info( macroName, lineInfo, type ) |
| 1902 | {} |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 1903 | |
| 1904 | template<typename T> |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 1905 | MessageBuilder& operator << ( T const& value ) { |
| 1906 | m_stream << value; |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 1907 | return *this; |
| 1908 | } |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 1909 | |
| 1910 | MessageInfo m_info; |
| 1911 | std::ostringstream m_stream; |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 1912 | }; |
| 1913 | |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 1914 | class ScopedMessage { |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 1915 | public: |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 1916 | ScopedMessage( MessageBuilder const& builder ); |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 1917 | ScopedMessage( ScopedMessage const& other ); |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 1918 | ~ScopedMessage(); |
| 1919 | |
| 1920 | MessageInfo m_info; |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 1921 | }; |
| 1922 | |
| 1923 | } // end namespace Catch |
| 1924 | |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1925 | // #included from: catch_interfaces_capture.h |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 1926 | #define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1927 | |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1928 | #include <string> |
| 1929 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1930 | namespace Catch { |
| 1931 | |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 1932 | class TestCase; |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 1933 | class AssertionResult; |
| 1934 | struct AssertionInfo; |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 1935 | struct SectionInfo; |
Phil Nash | 0c1c9fa | 2015-09-27 03:28:14 -0700 | [diff] [blame] | 1936 | struct SectionEndInfo; |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 1937 | struct MessageInfo; |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 1938 | class ScopedMessageBuilder; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 1939 | struct Counts; |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1940 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1941 | struct IResultCapture { |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1942 | |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 1943 | virtual ~IResultCapture(); |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1944 | |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 1945 | virtual void assertionEnded( AssertionResult const& result ) = 0; |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 1946 | virtual bool sectionStarted( SectionInfo const& sectionInfo, |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1947 | Counts& assertions ) = 0; |
Phil Nash | 0c1c9fa | 2015-09-27 03:28:14 -0700 | [diff] [blame] | 1948 | virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0; |
| 1949 | virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0; |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 1950 | virtual void pushScopedMessage( MessageInfo const& message ) = 0; |
| 1951 | virtual void popScopedMessage( MessageInfo const& message ) = 0; |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 1952 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 1953 | virtual std::string getCurrentTestName() const = 0; |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 1954 | virtual const AssertionResult* getLastResult() const = 0; |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 1955 | |
| 1956 | virtual void handleFatalErrorCondition( std::string const& message ) = 0; |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1957 | }; |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 1958 | |
| 1959 | IResultCapture& getResultCapture(); |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1960 | } |
| 1961 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 1962 | // #included from: catch_debugger.h |
| 1963 | #define TWOBLUECUBES_CATCH_DEBUGGER_H_INCLUDED |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1964 | |
Phil Nash | 04a3364 | 2013-08-16 19:09:09 +0100 | [diff] [blame] | 1965 | // #included from: catch_platform.h |
| 1966 | #define TWOBLUECUBES_CATCH_PLATFORM_H_INCLUDED |
| 1967 | |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1968 | #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) |
| 1969 | #define CATCH_PLATFORM_MAC |
| 1970 | #elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED) |
| 1971 | #define CATCH_PLATFORM_IPHONE |
Phil Nash | 04a3364 | 2013-08-16 19:09:09 +0100 | [diff] [blame] | 1972 | #elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1973 | #define CATCH_PLATFORM_WINDOWS |
| 1974 | #endif |
| 1975 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 1976 | #include <string> |
| 1977 | |
| 1978 | namespace Catch{ |
| 1979 | |
| 1980 | bool isDebuggerActive(); |
| 1981 | void writeToDebugConsole( std::string const& text ); |
| 1982 | } |
| 1983 | |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1984 | #ifdef CATCH_PLATFORM_MAC |
| 1985 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 1986 | // The following code snippet based on: |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1987 | // http://cocoawithlove.com/2008/03/break-into-debugger.html |
| 1988 | #ifdef DEBUG |
| 1989 | #if defined(__ppc64__) || defined(__ppc__) |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 1990 | #define CATCH_BREAK_INTO_DEBUGGER() \ |
| 1991 | if( Catch::isDebuggerActive() ) { \ |
| 1992 | __asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \ |
| 1993 | : : : "memory","r0","r3","r4" ); \ |
| 1994 | } |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1995 | #else |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 1996 | #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) {__asm__("int $3\n" : : );} |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1997 | #endif |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 1998 | #endif |
| 1999 | |
| 2000 | #elif defined(_MSC_VER) |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2001 | #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { __debugbreak(); } |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 2002 | #elif defined(__MINGW32__) |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 2003 | extern "C" __declspec(dllimport) void __stdcall DebugBreak(); |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2004 | #define CATCH_BREAK_INTO_DEBUGGER() if( Catch::isDebuggerActive() ) { DebugBreak(); } |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 2005 | #endif |
| 2006 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2007 | #ifndef CATCH_BREAK_INTO_DEBUGGER |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2008 | #define CATCH_BREAK_INTO_DEBUGGER() Catch::alwaysTrue(); |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2009 | #endif |
Phil Nash | d31737f | 2012-05-09 19:04:00 +0100 | [diff] [blame] | 2010 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2011 | // #included from: catch_interfaces_runner.h |
| 2012 | #define TWOBLUECUBES_CATCH_INTERFACES_RUNNER_H_INCLUDED |
Phil Nash | 37186a1 | 2013-03-13 12:19:30 +0000 | [diff] [blame] | 2013 | |
Phil Nash | a70fbe3 | 2012-08-31 08:10:36 +0100 | [diff] [blame] | 2014 | namespace Catch { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2015 | class TestCase; |
Phil Nash | a70fbe3 | 2012-08-31 08:10:36 +0100 | [diff] [blame] | 2016 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2017 | struct IRunner { |
| 2018 | virtual ~IRunner(); |
| 2019 | virtual bool aborting() const = 0; |
Phil Nash | a70fbe3 | 2012-08-31 08:10:36 +0100 | [diff] [blame] | 2020 | }; |
| 2021 | } |
| 2022 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2023 | /////////////////////////////////////////////////////////////////////////////// |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2024 | // In the event of a failure works out if the debugger needs to be invoked |
| 2025 | // and/or an exception thrown and takes appropriate action. |
| 2026 | // This needs to be done as a macro so the debugger will stop in the user |
| 2027 | // source code rather than in Catch library code |
| 2028 | #define INTERNAL_CATCH_REACT( resultBuilder ) \ |
| 2029 | if( resultBuilder.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \ |
| 2030 | resultBuilder.react(); |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2031 | |
| 2032 | /////////////////////////////////////////////////////////////////////////////// |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 2033 | #define INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ) \ |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2034 | do { \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2035 | Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2036 | try { \ |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 2037 | CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ |
Phil Nash | 21f7ef6 | 2015-06-29 18:05:23 +0100 | [diff] [blame] | 2038 | ( __catchResult <= expr ).endExpression(); \ |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2039 | } \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2040 | catch( ... ) { \ |
| 2041 | __catchResult.useActiveException( Catch::ResultDisposition::Normal ); \ |
| 2042 | } \ |
| 2043 | INTERNAL_CATCH_REACT( __catchResult ) \ |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 2044 | } while( Catch::isTrue( false && static_cast<bool>(expr) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2045 | |
| 2046 | /////////////////////////////////////////////////////////////////////////////// |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 2047 | #define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \ |
| 2048 | INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \ |
| 2049 | if( Catch::getResultCapture().getLastResult()->succeeded() ) |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2050 | |
| 2051 | /////////////////////////////////////////////////////////////////////////////// |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 2052 | #define INTERNAL_CATCH_ELSE( expr, resultDisposition, macroName ) \ |
| 2053 | INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \ |
| 2054 | if( !Catch::getResultCapture().getLastResult()->succeeded() ) |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2055 | |
| 2056 | /////////////////////////////////////////////////////////////////////////////// |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 2057 | #define INTERNAL_CATCH_NO_THROW( expr, resultDisposition, macroName ) \ |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2058 | do { \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2059 | Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2060 | try { \ |
| 2061 | expr; \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2062 | __catchResult.captureResult( Catch::ResultWas::Ok ); \ |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2063 | } \ |
| 2064 | catch( ... ) { \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2065 | __catchResult.useActiveException( resultDisposition ); \ |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2066 | } \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2067 | INTERNAL_CATCH_REACT( __catchResult ) \ |
| 2068 | } while( Catch::alwaysFalse() ) |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2069 | |
| 2070 | /////////////////////////////////////////////////////////////////////////////// |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 2071 | #define INTERNAL_CATCH_THROWS( expr, resultDisposition, matcher, macroName ) \ |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2072 | do { \ |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 2073 | Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition, #matcher ); \ |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 2074 | if( __catchResult.allowThrows() ) \ |
| 2075 | try { \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2076 | expr; \ |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 2077 | __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ |
| 2078 | } \ |
| 2079 | catch( ... ) { \ |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 2080 | __catchResult.captureExpectedException( matcher ); \ |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 2081 | } \ |
| 2082 | else \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2083 | __catchResult.captureResult( Catch::ResultWas::Ok ); \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2084 | INTERNAL_CATCH_REACT( __catchResult ) \ |
| 2085 | } while( Catch::alwaysFalse() ) |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2086 | |
| 2087 | /////////////////////////////////////////////////////////////////////////////// |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 2088 | #define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, resultDisposition, macroName ) \ |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2089 | do { \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2090 | Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \ |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 2091 | if( __catchResult.allowThrows() ) \ |
| 2092 | try { \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2093 | expr; \ |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 2094 | __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ |
| 2095 | } \ |
| 2096 | catch( exceptionType ) { \ |
| 2097 | __catchResult.captureResult( Catch::ResultWas::Ok ); \ |
| 2098 | } \ |
| 2099 | catch( ... ) { \ |
| 2100 | __catchResult.useActiveException( resultDisposition ); \ |
| 2101 | } \ |
| 2102 | else \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2103 | __catchResult.captureResult( Catch::ResultWas::Ok ); \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2104 | INTERNAL_CATCH_REACT( __catchResult ) \ |
| 2105 | } while( Catch::alwaysFalse() ) |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2106 | |
| 2107 | /////////////////////////////////////////////////////////////////////////////// |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 2108 | #ifdef CATCH_CONFIG_VARIADIC_MACROS |
| 2109 | #define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, ... ) \ |
| 2110 | do { \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2111 | Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ |
| 2112 | __catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \ |
| 2113 | __catchResult.captureResult( messageType ); \ |
| 2114 | INTERNAL_CATCH_REACT( __catchResult ) \ |
| 2115 | } while( Catch::alwaysFalse() ) |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 2116 | #else |
| 2117 | #define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, log ) \ |
| 2118 | do { \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2119 | Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \ |
| 2120 | __catchResult << log + ::Catch::StreamEndStop(); \ |
| 2121 | __catchResult.captureResult( messageType ); \ |
| 2122 | INTERNAL_CATCH_REACT( __catchResult ) \ |
| 2123 | } while( Catch::alwaysFalse() ) |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 2124 | #endif |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2125 | |
| 2126 | /////////////////////////////////////////////////////////////////////////////// |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 2127 | #define INTERNAL_CATCH_INFO( log, macroName ) \ |
| 2128 | Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log; |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2129 | |
| 2130 | /////////////////////////////////////////////////////////////////////////////// |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 2131 | #define INTERNAL_CHECK_THAT( arg, matcher, resultDisposition, macroName ) \ |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2132 | do { \ |
Phil Nash | 7424b23 | 2015-12-28 15:07:32 +0000 | [diff] [blame] | 2133 | Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #arg ", " #matcher, resultDisposition ); \ |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2134 | try { \ |
Phil Nash | 08844e7 | 2015-11-05 18:52:18 +0000 | [diff] [blame] | 2135 | std::string matcherAsString = (matcher).toString(); \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2136 | __catchResult \ |
| 2137 | .setLhs( Catch::toString( arg ) ) \ |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 2138 | .setRhs( matcherAsString == Catch::Detail::unprintableString ? #matcher : matcherAsString ) \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2139 | .setOp( "matches" ) \ |
Phil Nash | 08844e7 | 2015-11-05 18:52:18 +0000 | [diff] [blame] | 2140 | .setResultType( (matcher).match( arg ) ); \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2141 | __catchResult.captureExpression(); \ |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2142 | } catch( ... ) { \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2143 | __catchResult.useActiveException( resultDisposition | Catch::ResultDisposition::ContinueOnFailure ); \ |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2144 | } \ |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2145 | INTERNAL_CATCH_REACT( __catchResult ) \ |
| 2146 | } while( Catch::alwaysFalse() ) |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2147 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2148 | // #included from: internal/catch_section.h |
| 2149 | #define TWOBLUECUBES_CATCH_SECTION_H_INCLUDED |
| 2150 | |
| 2151 | // #included from: catch_section_info.h |
| 2152 | #define TWOBLUECUBES_CATCH_SECTION_INFO_H_INCLUDED |
| 2153 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2154 | // #included from: catch_totals.hpp |
| 2155 | #define TWOBLUECUBES_CATCH_TOTALS_HPP_INCLUDED |
| 2156 | |
| 2157 | #include <cstddef> |
| 2158 | |
| 2159 | namespace Catch { |
| 2160 | |
| 2161 | struct Counts { |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 2162 | Counts() : passed( 0 ), failed( 0 ), failedButOk( 0 ) {} |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2163 | |
| 2164 | Counts operator - ( Counts const& other ) const { |
| 2165 | Counts diff; |
| 2166 | diff.passed = passed - other.passed; |
| 2167 | diff.failed = failed - other.failed; |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 2168 | diff.failedButOk = failedButOk - other.failedButOk; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2169 | return diff; |
| 2170 | } |
| 2171 | Counts& operator += ( Counts const& other ) { |
| 2172 | passed += other.passed; |
| 2173 | failed += other.failed; |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 2174 | failedButOk += other.failedButOk; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2175 | return *this; |
| 2176 | } |
| 2177 | |
| 2178 | std::size_t total() const { |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 2179 | return passed + failed + failedButOk; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2180 | } |
Phil Nash | 28c2e07 | 2014-07-09 19:22:49 +0100 | [diff] [blame] | 2181 | bool allPassed() const { |
| 2182 | return failed == 0 && failedButOk == 0; |
| 2183 | } |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 2184 | bool allOk() const { |
| 2185 | return failed == 0; |
| 2186 | } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2187 | |
| 2188 | std::size_t passed; |
| 2189 | std::size_t failed; |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 2190 | std::size_t failedButOk; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2191 | }; |
| 2192 | |
| 2193 | struct Totals { |
| 2194 | |
| 2195 | Totals operator - ( Totals const& other ) const { |
| 2196 | Totals diff; |
| 2197 | diff.assertions = assertions - other.assertions; |
| 2198 | diff.testCases = testCases - other.testCases; |
| 2199 | return diff; |
| 2200 | } |
| 2201 | |
| 2202 | Totals delta( Totals const& prevTotals ) const { |
| 2203 | Totals diff = *this - prevTotals; |
| 2204 | if( diff.assertions.failed > 0 ) |
| 2205 | ++diff.testCases.failed; |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 2206 | else if( diff.assertions.failedButOk > 0 ) |
| 2207 | ++diff.testCases.failedButOk; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2208 | else |
| 2209 | ++diff.testCases.passed; |
| 2210 | return diff; |
| 2211 | } |
| 2212 | |
| 2213 | Totals& operator += ( Totals const& other ) { |
| 2214 | assertions += other.assertions; |
| 2215 | testCases += other.testCases; |
| 2216 | return *this; |
| 2217 | } |
| 2218 | |
| 2219 | Counts assertions; |
| 2220 | Counts testCases; |
| 2221 | }; |
| 2222 | } |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2223 | |
Phil Nash | 0c1c9fa | 2015-09-27 03:28:14 -0700 | [diff] [blame] | 2224 | namespace Catch { |
| 2225 | |
| 2226 | struct SectionInfo { |
| 2227 | SectionInfo |
| 2228 | ( SourceLineInfo const& _lineInfo, |
| 2229 | std::string const& _name, |
| 2230 | std::string const& _description = std::string() ); |
| 2231 | |
| 2232 | std::string name; |
| 2233 | std::string description; |
| 2234 | SourceLineInfo lineInfo; |
| 2235 | }; |
| 2236 | |
| 2237 | struct SectionEndInfo { |
| 2238 | SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds ) |
| 2239 | : sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds ) |
| 2240 | {} |
| 2241 | |
| 2242 | SectionInfo sectionInfo; |
| 2243 | Counts prevAssertions; |
| 2244 | double durationInSeconds; |
| 2245 | }; |
| 2246 | |
| 2247 | } // end namespace Catch |
| 2248 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 2249 | // #included from: catch_timer.h |
| 2250 | #define TWOBLUECUBES_CATCH_TIMER_H_INCLUDED |
| 2251 | |
Phil Nash | 04a3364 | 2013-08-16 19:09:09 +0100 | [diff] [blame] | 2252 | #ifdef CATCH_PLATFORM_WINDOWS |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 2253 | typedef unsigned long long uint64_t; |
| 2254 | #else |
| 2255 | #include <stdint.h> |
| 2256 | #endif |
| 2257 | |
| 2258 | namespace Catch { |
| 2259 | |
| 2260 | class Timer { |
| 2261 | public: |
| 2262 | Timer() : m_ticks( 0 ) {} |
| 2263 | void start(); |
Phil Nash | 4caabfa | 2014-09-03 19:23:22 +0100 | [diff] [blame] | 2264 | unsigned int getElapsedMicroseconds() const; |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 2265 | unsigned int getElapsedMilliseconds() const; |
| 2266 | double getElapsedSeconds() const; |
| 2267 | |
| 2268 | private: |
| 2269 | uint64_t m_ticks; |
| 2270 | }; |
| 2271 | |
| 2272 | } // namespace Catch |
| 2273 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2274 | #include <string> |
| 2275 | |
| 2276 | namespace Catch { |
| 2277 | |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 2278 | class Section : NonCopyable { |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2279 | public: |
Phil Nash | ce56209 | 2014-07-09 07:40:37 +0100 | [diff] [blame] | 2280 | Section( SectionInfo const& info ); |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2281 | ~Section(); |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2282 | |
| 2283 | // This indicates whether the section should be executed or not |
Phil Nash | ce56209 | 2014-07-09 07:40:37 +0100 | [diff] [blame] | 2284 | operator bool() const; |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2285 | |
| 2286 | private: |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 2287 | SectionInfo m_info; |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2288 | |
| 2289 | std::string m_name; |
| 2290 | Counts m_assertions; |
| 2291 | bool m_sectionIncluded; |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 2292 | Timer m_timer; |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2293 | }; |
| 2294 | |
| 2295 | } // end namespace Catch |
| 2296 | |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 2297 | #ifdef CATCH_CONFIG_VARIADIC_MACROS |
| 2298 | #define INTERNAL_CATCH_SECTION( ... ) \ |
Phil Nash | ce56209 | 2014-07-09 07:40:37 +0100 | [diff] [blame] | 2299 | if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 2300 | #else |
| 2301 | #define INTERNAL_CATCH_SECTION( name, desc ) \ |
Phil Nash | ce56209 | 2014-07-09 07:40:37 +0100 | [diff] [blame] | 2302 | if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, name, desc ) ) |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 2303 | #endif |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2304 | |
| 2305 | // #included from: internal/catch_generators.hpp |
| 2306 | #define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED |
| 2307 | |
| 2308 | #include <iterator> |
| 2309 | #include <vector> |
| 2310 | #include <string> |
| 2311 | #include <stdlib.h> |
| 2312 | |
| 2313 | namespace Catch { |
| 2314 | |
| 2315 | template<typename T> |
| 2316 | struct IGenerator { |
| 2317 | virtual ~IGenerator() {} |
| 2318 | virtual T getValue( std::size_t index ) const = 0; |
| 2319 | virtual std::size_t size () const = 0; |
| 2320 | }; |
| 2321 | |
| 2322 | template<typename T> |
| 2323 | class BetweenGenerator : public IGenerator<T> { |
| 2324 | public: |
| 2325 | BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){} |
| 2326 | |
| 2327 | virtual T getValue( std::size_t index ) const { |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 2328 | return m_from+static_cast<int>( index ); |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | virtual std::size_t size() const { |
| 2332 | return static_cast<std::size_t>( 1+m_to-m_from ); |
| 2333 | } |
| 2334 | |
| 2335 | private: |
| 2336 | |
| 2337 | T m_from; |
| 2338 | T m_to; |
| 2339 | }; |
| 2340 | |
| 2341 | template<typename T> |
| 2342 | class ValuesGenerator : public IGenerator<T> { |
| 2343 | public: |
| 2344 | ValuesGenerator(){} |
| 2345 | |
| 2346 | void add( T value ) { |
| 2347 | m_values.push_back( value ); |
| 2348 | } |
| 2349 | |
| 2350 | virtual T getValue( std::size_t index ) const { |
| 2351 | return m_values[index]; |
| 2352 | } |
| 2353 | |
| 2354 | virtual std::size_t size() const { |
| 2355 | return m_values.size(); |
| 2356 | } |
| 2357 | |
| 2358 | private: |
| 2359 | std::vector<T> m_values; |
| 2360 | }; |
| 2361 | |
| 2362 | template<typename T> |
| 2363 | class CompositeGenerator { |
| 2364 | public: |
| 2365 | CompositeGenerator() : m_totalSize( 0 ) {} |
| 2366 | |
Phil Nash | a04981b | 2013-03-08 09:30:25 +0000 | [diff] [blame] | 2367 | // *** Move semantics, similar to auto_ptr *** |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2368 | CompositeGenerator( CompositeGenerator& other ) |
| 2369 | : m_fileInfo( other.m_fileInfo ), |
| 2370 | m_totalSize( 0 ) |
| 2371 | { |
Phil Nash | a04981b | 2013-03-08 09:30:25 +0000 | [diff] [blame] | 2372 | move( other ); |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2373 | } |
| 2374 | |
| 2375 | CompositeGenerator& setFileInfo( const char* fileInfo ) { |
| 2376 | m_fileInfo = fileInfo; |
| 2377 | return *this; |
| 2378 | } |
| 2379 | |
| 2380 | ~CompositeGenerator() { |
| 2381 | deleteAll( m_composed ); |
| 2382 | } |
| 2383 | |
| 2384 | operator T () const { |
| 2385 | size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize ); |
| 2386 | |
| 2387 | typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin(); |
| 2388 | typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end(); |
| 2389 | for( size_t index = 0; it != itEnd; ++it ) |
| 2390 | { |
| 2391 | const IGenerator<T>* generator = *it; |
| 2392 | if( overallIndex >= index && overallIndex < index + generator->size() ) |
| 2393 | { |
| 2394 | return generator->getValue( overallIndex-index ); |
| 2395 | } |
| 2396 | index += generator->size(); |
| 2397 | } |
| 2398 | CATCH_INTERNAL_ERROR( "Indexed past end of generated range" ); |
Phil Nash | a04981b | 2013-03-08 09:30:25 +0000 | [diff] [blame] | 2399 | 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 |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | void add( const IGenerator<T>* generator ) { |
| 2403 | m_totalSize += generator->size(); |
| 2404 | m_composed.push_back( generator ); |
| 2405 | } |
| 2406 | |
| 2407 | CompositeGenerator& then( CompositeGenerator& other ) { |
| 2408 | move( other ); |
| 2409 | return *this; |
| 2410 | } |
| 2411 | |
| 2412 | CompositeGenerator& then( T value ) { |
| 2413 | ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); |
| 2414 | valuesGen->add( value ); |
| 2415 | add( valuesGen ); |
| 2416 | return *this; |
| 2417 | } |
| 2418 | |
| 2419 | private: |
| 2420 | |
| 2421 | void move( CompositeGenerator& other ) { |
| 2422 | std::copy( other.m_composed.begin(), other.m_composed.end(), std::back_inserter( m_composed ) ); |
| 2423 | m_totalSize += other.m_totalSize; |
| 2424 | other.m_composed.clear(); |
| 2425 | } |
| 2426 | |
| 2427 | std::vector<const IGenerator<T>*> m_composed; |
| 2428 | std::string m_fileInfo; |
| 2429 | size_t m_totalSize; |
| 2430 | }; |
| 2431 | |
| 2432 | namespace Generators |
| 2433 | { |
| 2434 | template<typename T> |
| 2435 | CompositeGenerator<T> between( T from, T to ) { |
| 2436 | CompositeGenerator<T> generators; |
| 2437 | generators.add( new BetweenGenerator<T>( from, to ) ); |
| 2438 | return generators; |
| 2439 | } |
| 2440 | |
| 2441 | template<typename T> |
| 2442 | CompositeGenerator<T> values( T val1, T val2 ) { |
| 2443 | CompositeGenerator<T> generators; |
| 2444 | ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); |
| 2445 | valuesGen->add( val1 ); |
| 2446 | valuesGen->add( val2 ); |
| 2447 | generators.add( valuesGen ); |
| 2448 | return generators; |
| 2449 | } |
| 2450 | |
| 2451 | template<typename T> |
| 2452 | CompositeGenerator<T> values( T val1, T val2, T val3 ){ |
| 2453 | CompositeGenerator<T> generators; |
| 2454 | ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); |
| 2455 | valuesGen->add( val1 ); |
| 2456 | valuesGen->add( val2 ); |
| 2457 | valuesGen->add( val3 ); |
| 2458 | generators.add( valuesGen ); |
| 2459 | return generators; |
| 2460 | } |
| 2461 | |
| 2462 | template<typename T> |
| 2463 | CompositeGenerator<T> values( T val1, T val2, T val3, T val4 ) { |
| 2464 | CompositeGenerator<T> generators; |
| 2465 | ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>(); |
| 2466 | valuesGen->add( val1 ); |
| 2467 | valuesGen->add( val2 ); |
| 2468 | valuesGen->add( val3 ); |
| 2469 | valuesGen->add( val4 ); |
| 2470 | generators.add( valuesGen ); |
| 2471 | return generators; |
| 2472 | } |
| 2473 | |
| 2474 | } // end namespace Generators |
| 2475 | |
| 2476 | using namespace Generators; |
| 2477 | |
| 2478 | } // end namespace Catch |
| 2479 | |
| 2480 | #define INTERNAL_CATCH_LINESTR2( line ) #line |
| 2481 | #define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line ) |
| 2482 | |
| 2483 | #define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" ) |
| 2484 | |
| 2485 | // #included from: internal/catch_interfaces_exception.h |
| 2486 | #define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED |
| 2487 | |
| 2488 | #include <string> |
Phil Nash | e4fa62a | 2015-11-18 08:39:54 +0000 | [diff] [blame] | 2489 | #include <vector> |
| 2490 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2491 | // #included from: catch_interfaces_registry_hub.h |
| 2492 | #define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED |
| 2493 | |
| 2494 | #include <string> |
| 2495 | |
| 2496 | namespace Catch { |
| 2497 | |
| 2498 | class TestCase; |
| 2499 | struct ITestCaseRegistry; |
| 2500 | struct IExceptionTranslatorRegistry; |
| 2501 | struct IExceptionTranslator; |
| 2502 | struct IReporterRegistry; |
| 2503 | struct IReporterFactory; |
| 2504 | |
| 2505 | struct IRegistryHub { |
| 2506 | virtual ~IRegistryHub(); |
| 2507 | |
| 2508 | virtual IReporterRegistry const& getReporterRegistry() const = 0; |
| 2509 | virtual ITestCaseRegistry const& getTestCaseRegistry() const = 0; |
| 2510 | virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0; |
| 2511 | }; |
| 2512 | |
| 2513 | struct IMutableRegistryHub { |
| 2514 | virtual ~IMutableRegistryHub(); |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 2515 | virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) = 0; |
| 2516 | virtual void registerListener( Ptr<IReporterFactory> const& factory ) = 0; |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 2517 | virtual void registerTest( TestCase const& testInfo ) = 0; |
| 2518 | virtual void registerTranslator( const IExceptionTranslator* translator ) = 0; |
| 2519 | }; |
| 2520 | |
| 2521 | IRegistryHub& getRegistryHub(); |
| 2522 | IMutableRegistryHub& getMutableRegistryHub(); |
| 2523 | void cleanUp(); |
| 2524 | std::string translateActiveException(); |
| 2525 | |
| 2526 | } |
| 2527 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2528 | namespace Catch { |
| 2529 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2530 | typedef std::string(*exceptionTranslateFunction)(); |
| 2531 | |
Phil Nash | e4fa62a | 2015-11-18 08:39:54 +0000 | [diff] [blame] | 2532 | struct IExceptionTranslator; |
| 2533 | typedef std::vector<const IExceptionTranslator*> ExceptionTranslators; |
| 2534 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2535 | struct IExceptionTranslator { |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 2536 | virtual ~IExceptionTranslator(); |
Phil Nash | e4fa62a | 2015-11-18 08:39:54 +0000 | [diff] [blame] | 2537 | virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const = 0; |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2538 | }; |
| 2539 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2540 | struct IExceptionTranslatorRegistry { |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 2541 | virtual ~IExceptionTranslatorRegistry(); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2542 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2543 | virtual std::string translateActiveException() const = 0; |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2544 | }; |
| 2545 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2546 | class ExceptionTranslatorRegistrar { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2547 | template<typename T> |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2548 | class ExceptionTranslator : public IExceptionTranslator { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2549 | public: |
| 2550 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2551 | ExceptionTranslator( std::string(*translateFunction)( T& ) ) |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2552 | : m_translateFunction( translateFunction ) |
| 2553 | {} |
| 2554 | |
Phil Nash | e4fa62a | 2015-11-18 08:39:54 +0000 | [diff] [blame] | 2555 | virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const CATCH_OVERRIDE { |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2556 | try { |
Phil Nash | e4fa62a | 2015-11-18 08:39:54 +0000 | [diff] [blame] | 2557 | if( it == itEnd ) |
| 2558 | throw; |
| 2559 | else |
| 2560 | return (*it)->translate( it+1, itEnd ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2561 | } |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2562 | catch( T& ex ) { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2563 | return m_translateFunction( ex ); |
| 2564 | } |
| 2565 | } |
| 2566 | |
| 2567 | protected: |
| 2568 | std::string(*m_translateFunction)( T& ); |
| 2569 | }; |
| 2570 | |
| 2571 | public: |
| 2572 | template<typename T> |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2573 | ExceptionTranslatorRegistrar( std::string(*translateFunction)( T& ) ) { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 2574 | getMutableRegistryHub().registerTranslator |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2575 | ( new ExceptionTranslator<T>( translateFunction ) ); |
| 2576 | } |
| 2577 | }; |
| 2578 | } |
| 2579 | |
| 2580 | /////////////////////////////////////////////////////////////////////////////// |
| 2581 | #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) \ |
| 2582 | static std::string INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator )( signature ); \ |
| 2583 | namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ) ); }\ |
| 2584 | static std::string INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator )( signature ) |
| 2585 | |
| 2586 | // #included from: internal/catch_approx.hpp |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 2587 | #define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2588 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2589 | #include <cmath> |
| 2590 | #include <limits> |
| 2591 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2592 | namespace Catch { |
| 2593 | namespace Detail { |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2594 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2595 | class Approx { |
| 2596 | public: |
| 2597 | explicit Approx ( double value ) |
| 2598 | : m_epsilon( std::numeric_limits<float>::epsilon()*100 ), |
| 2599 | m_scale( 1.0 ), |
| 2600 | m_value( value ) |
| 2601 | {} |
Phil Nash | f721a96 | 2011-06-07 14:13:57 +0100 | [diff] [blame] | 2602 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 2603 | Approx( Approx const& other ) |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2604 | : m_epsilon( other.m_epsilon ), |
| 2605 | m_scale( other.m_scale ), |
| 2606 | m_value( other.m_value ) |
| 2607 | {} |
Phil Nash | f721a96 | 2011-06-07 14:13:57 +0100 | [diff] [blame] | 2608 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2609 | static Approx custom() { |
| 2610 | return Approx( 0 ); |
| 2611 | } |
Phil Nash | f721a96 | 2011-06-07 14:13:57 +0100 | [diff] [blame] | 2612 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2613 | Approx operator()( double value ) { |
| 2614 | Approx approx( value ); |
| 2615 | approx.epsilon( m_epsilon ); |
| 2616 | approx.scale( m_scale ); |
| 2617 | return approx; |
| 2618 | } |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2619 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 2620 | friend bool operator == ( double lhs, Approx const& rhs ) { |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2621 | // Thanks to Richard Harris for his help refining this formula |
| 2622 | return fabs( lhs - rhs.m_value ) < rhs.m_epsilon * (rhs.m_scale + (std::max)( fabs(lhs), fabs(rhs.m_value) ) ); |
| 2623 | } |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2624 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 2625 | friend bool operator == ( Approx const& lhs, double rhs ) { |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2626 | return operator==( rhs, lhs ); |
| 2627 | } |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2628 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 2629 | friend bool operator != ( double lhs, Approx const& rhs ) { |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2630 | return !operator==( lhs, rhs ); |
| 2631 | } |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2632 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 2633 | friend bool operator != ( Approx const& lhs, double rhs ) { |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2634 | return !operator==( rhs, lhs ); |
| 2635 | } |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2636 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2637 | Approx& epsilon( double newEpsilon ) { |
| 2638 | m_epsilon = newEpsilon; |
| 2639 | return *this; |
| 2640 | } |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2641 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2642 | Approx& scale( double newScale ) { |
| 2643 | m_scale = newScale; |
| 2644 | return *this; |
| 2645 | } |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2646 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2647 | std::string toString() const { |
| 2648 | std::ostringstream oss; |
Phil Nash | f385a0b | 2013-12-19 18:42:25 +0000 | [diff] [blame] | 2649 | oss << "Approx( " << Catch::toString( m_value ) << " )"; |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2650 | return oss.str(); |
| 2651 | } |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2652 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2653 | private: |
| 2654 | double m_epsilon; |
| 2655 | double m_scale; |
| 2656 | double m_value; |
| 2657 | }; |
| 2658 | } |
| 2659 | |
| 2660 | template<> |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 2661 | inline std::string toString<Detail::Approx>( Detail::Approx const& value ) { |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2662 | return value.toString(); |
| 2663 | } |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 2664 | |
| 2665 | } // end namespace Catch |
| 2666 | |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 2667 | // #included from: internal/catch_interfaces_tag_alias_registry.h |
| 2668 | #define TWOBLUECUBES_CATCH_INTERFACES_TAG_ALIAS_REGISTRY_H_INCLUDED |
| 2669 | |
| 2670 | // #included from: catch_tag_alias.h |
| 2671 | #define TWOBLUECUBES_CATCH_TAG_ALIAS_H_INCLUDED |
| 2672 | |
| 2673 | #include <string> |
| 2674 | |
| 2675 | namespace Catch { |
| 2676 | |
| 2677 | struct TagAlias { |
| 2678 | TagAlias( std::string _tag, SourceLineInfo _lineInfo ) : tag( _tag ), lineInfo( _lineInfo ) {} |
| 2679 | |
| 2680 | std::string tag; |
| 2681 | SourceLineInfo lineInfo; |
| 2682 | }; |
| 2683 | |
| 2684 | struct RegistrarForTagAliases { |
| 2685 | RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); |
| 2686 | }; |
| 2687 | |
| 2688 | } // end namespace Catch |
| 2689 | |
| 2690 | #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } |
| 2691 | // #included from: catch_option.hpp |
| 2692 | #define TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED |
| 2693 | |
| 2694 | namespace Catch { |
| 2695 | |
| 2696 | // An optional type |
| 2697 | template<typename T> |
| 2698 | class Option { |
| 2699 | public: |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 2700 | Option() : nullableValue( CATCH_NULL ) {} |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 2701 | Option( T const& _value ) |
| 2702 | : nullableValue( new( storage ) T( _value ) ) |
| 2703 | {} |
| 2704 | Option( Option const& _other ) |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 2705 | : nullableValue( _other ? new( storage ) T( *_other ) : CATCH_NULL ) |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 2706 | {} |
| 2707 | |
| 2708 | ~Option() { |
| 2709 | reset(); |
| 2710 | } |
| 2711 | |
| 2712 | Option& operator= ( Option const& _other ) { |
| 2713 | if( &_other != this ) { |
| 2714 | reset(); |
| 2715 | if( _other ) |
| 2716 | nullableValue = new( storage ) T( *_other ); |
| 2717 | } |
| 2718 | return *this; |
| 2719 | } |
| 2720 | Option& operator = ( T const& _value ) { |
| 2721 | reset(); |
| 2722 | nullableValue = new( storage ) T( _value ); |
| 2723 | return *this; |
| 2724 | } |
| 2725 | |
| 2726 | void reset() { |
| 2727 | if( nullableValue ) |
| 2728 | nullableValue->~T(); |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 2729 | nullableValue = CATCH_NULL; |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | T& operator*() { return *nullableValue; } |
| 2733 | T const& operator*() const { return *nullableValue; } |
| 2734 | T* operator->() { return nullableValue; } |
| 2735 | const T* operator->() const { return nullableValue; } |
| 2736 | |
| 2737 | T valueOr( T const& defaultValue ) const { |
| 2738 | return nullableValue ? *nullableValue : defaultValue; |
| 2739 | } |
| 2740 | |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 2741 | bool some() const { return nullableValue != CATCH_NULL; } |
| 2742 | bool none() const { return nullableValue == CATCH_NULL; } |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 2743 | |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 2744 | bool operator !() const { return nullableValue == CATCH_NULL; } |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 2745 | operator SafeBool::type() const { |
| 2746 | return SafeBool::makeSafe( some() ); |
| 2747 | } |
| 2748 | |
| 2749 | private: |
| 2750 | T* nullableValue; |
| 2751 | char storage[sizeof(T)]; |
| 2752 | }; |
| 2753 | |
| 2754 | } // end namespace Catch |
| 2755 | |
| 2756 | namespace Catch { |
| 2757 | |
| 2758 | struct ITagAliasRegistry { |
| 2759 | virtual ~ITagAliasRegistry(); |
| 2760 | virtual Option<TagAlias> find( std::string const& alias ) const = 0; |
| 2761 | virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0; |
| 2762 | |
| 2763 | static ITagAliasRegistry const& get(); |
| 2764 | }; |
| 2765 | |
| 2766 | } // end namespace Catch |
| 2767 | |
Phil Nash | 0f9c551 | 2012-06-02 23:12:42 +0100 | [diff] [blame] | 2768 | // These files are included here so the single_include script doesn't put them |
| 2769 | // in the conditionally compiled sections |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2770 | // #included from: internal/catch_test_case_info.h |
| 2771 | #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED |
Phil Nash | 0f9c551 | 2012-06-02 23:12:42 +0100 | [diff] [blame] | 2772 | |
| 2773 | #include <string> |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2774 | #include <set> |
| 2775 | |
| 2776 | #ifdef __clang__ |
| 2777 | #pragma clang diagnostic push |
| 2778 | #pragma clang diagnostic ignored "-Wpadded" |
| 2779 | #endif |
| 2780 | |
| 2781 | namespace Catch { |
| 2782 | |
| 2783 | struct ITestCase; |
| 2784 | |
| 2785 | struct TestCaseInfo { |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 2786 | enum SpecialProperties{ |
| 2787 | None = 0, |
| 2788 | IsHidden = 1 << 1, |
| 2789 | ShouldFail = 1 << 2, |
| 2790 | MayFail = 1 << 3, |
| 2791 | Throws = 1 << 4 |
| 2792 | }; |
| 2793 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2794 | TestCaseInfo( std::string const& _name, |
| 2795 | std::string const& _className, |
| 2796 | std::string const& _description, |
| 2797 | std::set<std::string> const& _tags, |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2798 | SourceLineInfo const& _lineInfo ); |
| 2799 | |
| 2800 | TestCaseInfo( TestCaseInfo const& other ); |
| 2801 | |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 2802 | friend void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags ); |
| 2803 | |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 2804 | bool isHidden() const; |
| 2805 | bool throws() const; |
| 2806 | bool okToFail() const; |
| 2807 | bool expectedToFail() const; |
| 2808 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2809 | std::string name; |
| 2810 | std::string className; |
| 2811 | std::string description; |
| 2812 | std::set<std::string> tags; |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 2813 | std::set<std::string> lcaseTags; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2814 | std::string tagsAsString; |
| 2815 | SourceLineInfo lineInfo; |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 2816 | SpecialProperties properties; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2817 | }; |
| 2818 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 2819 | class TestCase : public TestCaseInfo { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2820 | public: |
| 2821 | |
| 2822 | TestCase( ITestCase* testCase, TestCaseInfo const& info ); |
| 2823 | TestCase( TestCase const& other ); |
| 2824 | |
| 2825 | TestCase withName( std::string const& _newName ) const; |
| 2826 | |
| 2827 | void invoke() const; |
| 2828 | |
| 2829 | TestCaseInfo const& getTestCaseInfo() const; |
| 2830 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2831 | void swap( TestCase& other ); |
| 2832 | bool operator == ( TestCase const& other ) const; |
| 2833 | bool operator < ( TestCase const& other ) const; |
| 2834 | TestCase& operator = ( TestCase const& other ); |
| 2835 | |
| 2836 | private: |
| 2837 | Ptr<ITestCase> test; |
| 2838 | }; |
| 2839 | |
| 2840 | TestCase makeTestCase( ITestCase* testCase, |
| 2841 | std::string const& className, |
| 2842 | std::string const& name, |
| 2843 | std::string const& description, |
| 2844 | SourceLineInfo const& lineInfo ); |
| 2845 | } |
| 2846 | |
| 2847 | #ifdef __clang__ |
| 2848 | #pragma clang diagnostic pop |
| 2849 | #endif |
| 2850 | |
Phil Nash | 0f9c551 | 2012-06-02 23:12:42 +0100 | [diff] [blame] | 2851 | |
Phil Nash | 371db8b | 2012-05-21 18:52:09 +0100 | [diff] [blame] | 2852 | #ifdef __OBJC__ |
| 2853 | // #included from: internal/catch_objc.hpp |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 2854 | #define TWOBLUECUBES_CATCH_OBJC_HPP_INCLUDED |
Phil Nash | 371db8b | 2012-05-21 18:52:09 +0100 | [diff] [blame] | 2855 | |
Phil Nash | 371db8b | 2012-05-21 18:52:09 +0100 | [diff] [blame] | 2856 | #import <objc/runtime.h> |
| 2857 | |
| 2858 | #include <string> |
| 2859 | |
| 2860 | // NB. Any general catch headers included here must be included |
| 2861 | // in catch.hpp first to make sure they are included by the single |
| 2862 | // header for non obj-usage |
Phil Nash | 8152825 | 2011-08-15 09:06:31 +0100 | [diff] [blame] | 2863 | |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2864 | /////////////////////////////////////////////////////////////////////////////// |
| 2865 | // This protocol is really only here for (self) documenting purposes, since |
| 2866 | // all its methods are optional. |
| 2867 | @protocol OcFixture |
| 2868 | |
| 2869 | @optional |
| 2870 | |
| 2871 | -(void) setUp; |
| 2872 | -(void) tearDown; |
| 2873 | |
| 2874 | @end |
| 2875 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2876 | namespace Catch { |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2877 | |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 2878 | class OcMethod : public SharedImpl<ITestCase> { |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2879 | |
| 2880 | public: |
| 2881 | OcMethod( Class cls, SEL sel ) : m_cls( cls ), m_sel( sel ) {} |
| 2882 | |
| 2883 | virtual void invoke() const { |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 2884 | id obj = [[m_cls alloc] init]; |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2885 | |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 2886 | performOptionalSelector( obj, @selector(setUp) ); |
| 2887 | performOptionalSelector( obj, m_sel ); |
| 2888 | performOptionalSelector( obj, @selector(tearDown) ); |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2889 | |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 2890 | arcSafeRelease( obj ); |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2891 | } |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2892 | private: |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 2893 | virtual ~OcMethod() {} |
| 2894 | |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2895 | Class m_cls; |
| 2896 | SEL m_sel; |
| 2897 | }; |
| 2898 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2899 | namespace Detail{ |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2900 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2901 | inline std::string getAnnotation( Class cls, |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 2902 | std::string const& annotationName, |
| 2903 | std::string const& testCaseName ) { |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2904 | NSString* selStr = [[NSString alloc] initWithFormat:@"Catch_%s_%s", annotationName.c_str(), testCaseName.c_str()]; |
| 2905 | SEL sel = NSSelectorFromString( selStr ); |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 2906 | arcSafeRelease( selStr ); |
| 2907 | id value = performOptionalSelector( cls, sel ); |
| 2908 | if( value ) |
| 2909 | return [(NSString*)value UTF8String]; |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2910 | return ""; |
| 2911 | } |
| 2912 | } |
| 2913 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2914 | inline size_t registerTestMethods() { |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2915 | size_t noTestMethods = 0; |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 2916 | int noClasses = objc_getClassList( CATCH_NULL, 0 ); |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2917 | |
Phil Nash | 861a1e7 | 2012-04-28 12:29:52 +0100 | [diff] [blame] | 2918 | Class* classes = (CATCH_UNSAFE_UNRETAINED Class *)malloc( sizeof(Class) * noClasses); |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 2919 | objc_getClassList( classes, noClasses ); |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2920 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2921 | for( int c = 0; c < noClasses; c++ ) { |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2922 | Class cls = classes[c]; |
| 2923 | { |
| 2924 | u_int count; |
| 2925 | Method* methods = class_copyMethodList( cls, &count ); |
Phil Nash | 7004f4a | 2012-05-22 08:56:59 +0100 | [diff] [blame] | 2926 | for( u_int m = 0; m < count ; m++ ) { |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2927 | SEL selector = method_getName(methods[m]); |
| 2928 | std::string methodName = sel_getName(selector); |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 2929 | if( startsWith( methodName, "Catch_TestCase_" ) ) { |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2930 | std::string testCaseName = methodName.substr( 15 ); |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 2931 | std::string name = Detail::getAnnotation( cls, "Name", testCaseName ); |
| 2932 | std::string desc = Detail::getAnnotation( cls, "Description", testCaseName ); |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 2933 | const char* className = class_getName( cls ); |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2934 | |
Phil Nash | 5bdae84 | 2013-02-19 19:47:18 +0000 | [diff] [blame] | 2935 | getMutableRegistryHub().registerTest( makeTestCase( new OcMethod( cls, selector ), className, name.c_str(), desc.c_str(), SourceLineInfo() ) ); |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2936 | noTestMethods++; |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 2937 | } |
| 2938 | } |
| 2939 | free(methods); |
| 2940 | } |
| 2941 | } |
| 2942 | return noTestMethods; |
| 2943 | } |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 2944 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2945 | namespace Matchers { |
| 2946 | namespace Impl { |
| 2947 | namespace NSStringMatchers { |
| 2948 | |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 2949 | template<typename MatcherT> |
| 2950 | struct StringHolder : MatcherImpl<MatcherT, NSString*>{ |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 2951 | StringHolder( NSString* substr ) : m_substr( [substr copy] ){} |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 2952 | StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){} |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 2953 | StringHolder() { |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 2954 | arcSafeRelease( m_substr ); |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 2955 | } |
| 2956 | |
| 2957 | NSString* m_substr; |
| 2958 | }; |
| 2959 | |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 2960 | struct Equals : StringHolder<Equals> { |
Phil Nash | 8d18d16 | 2012-03-14 20:06:14 +0000 | [diff] [blame] | 2961 | Equals( NSString* substr ) : StringHolder( substr ){} |
| 2962 | |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 2963 | virtual bool match( ExpressionType const& str ) const { |
Phil Nash | 372a6c6 | 2013-07-23 08:15:34 +0100 | [diff] [blame] | 2964 | return (str != nil || m_substr == nil ) && |
| 2965 | [str isEqualToString:m_substr]; |
Phil Nash | 8d18d16 | 2012-03-14 20:06:14 +0000 | [diff] [blame] | 2966 | } |
| 2967 | |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 2968 | virtual std::string toString() const { |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 2969 | return "equals string: " + Catch::toString( m_substr ); |
Phil Nash | 8d18d16 | 2012-03-14 20:06:14 +0000 | [diff] [blame] | 2970 | } |
| 2971 | }; |
| 2972 | |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 2973 | struct Contains : StringHolder<Contains> { |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 2974 | Contains( NSString* substr ) : StringHolder( substr ){} |
| 2975 | |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 2976 | virtual bool match( ExpressionType const& str ) const { |
Phil Nash | 372a6c6 | 2013-07-23 08:15:34 +0100 | [diff] [blame] | 2977 | return (str != nil || m_substr == nil ) && |
| 2978 | [str rangeOfString:m_substr].location != NSNotFound; |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 2979 | } |
| 2980 | |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 2981 | virtual std::string toString() const { |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 2982 | return "contains string: " + Catch::toString( m_substr ); |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 2983 | } |
| 2984 | }; |
| 2985 | |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 2986 | struct StartsWith : StringHolder<StartsWith> { |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 2987 | StartsWith( NSString* substr ) : StringHolder( substr ){} |
| 2988 | |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 2989 | virtual bool match( ExpressionType const& str ) const { |
Phil Nash | 372a6c6 | 2013-07-23 08:15:34 +0100 | [diff] [blame] | 2990 | return (str != nil || m_substr == nil ) && |
| 2991 | [str rangeOfString:m_substr].location == 0; |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 2992 | } |
| 2993 | |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 2994 | virtual std::string toString() const { |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 2995 | return "starts with: " + Catch::toString( m_substr ); |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 2996 | } |
| 2997 | }; |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 2998 | struct EndsWith : StringHolder<EndsWith> { |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 2999 | EndsWith( NSString* substr ) : StringHolder( substr ){} |
| 3000 | |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 3001 | virtual bool match( ExpressionType const& str ) const { |
Phil Nash | 372a6c6 | 2013-07-23 08:15:34 +0100 | [diff] [blame] | 3002 | return (str != nil || m_substr == nil ) && |
| 3003 | [str rangeOfString:m_substr].location == [str length] - [m_substr length]; |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 3004 | } |
| 3005 | |
Phil Nash | a8c6543 | 2013-02-19 08:46:09 +0000 | [diff] [blame] | 3006 | virtual std::string toString() const { |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 3007 | return "ends with: " + Catch::toString( m_substr ); |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 3008 | } |
| 3009 | }; |
| 3010 | |
| 3011 | } // namespace NSStringMatchers |
| 3012 | } // namespace Impl |
| 3013 | |
Phil Nash | 8d18d16 | 2012-03-14 20:06:14 +0000 | [diff] [blame] | 3014 | inline Impl::NSStringMatchers::Equals |
| 3015 | Equals( NSString* substr ){ return Impl::NSStringMatchers::Equals( substr ); } |
| 3016 | |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 3017 | inline Impl::NSStringMatchers::Contains |
| 3018 | Contains( NSString* substr ){ return Impl::NSStringMatchers::Contains( substr ); } |
Phil Nash | 8d18d16 | 2012-03-14 20:06:14 +0000 | [diff] [blame] | 3019 | |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 3020 | inline Impl::NSStringMatchers::StartsWith |
| 3021 | StartsWith( NSString* substr ){ return Impl::NSStringMatchers::StartsWith( substr ); } |
Phil Nash | 8d18d16 | 2012-03-14 20:06:14 +0000 | [diff] [blame] | 3022 | |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 3023 | inline Impl::NSStringMatchers::EndsWith |
| 3024 | EndsWith( NSString* substr ){ return Impl::NSStringMatchers::EndsWith( substr ); } |
| 3025 | |
| 3026 | } // namespace Matchers |
| 3027 | |
| 3028 | using namespace Matchers; |
| 3029 | |
| 3030 | } // namespace Catch |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 3031 | |
| 3032 | /////////////////////////////////////////////////////////////////////////////// |
| 3033 | #define OC_TEST_CASE( name, desc )\ |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 3034 | +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Name_test ) \ |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 3035 | {\ |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 3036 | return @ name; \ |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 3037 | }\ |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 3038 | +(NSString*) INTERNAL_CATCH_UNIQUE_NAME( Catch_Description_test ) \ |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 3039 | { \ |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 3040 | return @ desc; \ |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 3041 | } \ |
| 3042 | -(void) INTERNAL_CATCH_UNIQUE_NAME( Catch_TestCase_test ) |
| 3043 | |
| 3044 | #endif |
| 3045 | |
Phil Nash | 576aff6 | 2014-12-21 00:21:23 +0000 | [diff] [blame] | 3046 | #ifdef CATCH_IMPL |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3047 | // #included from: internal/catch_impl.hpp |
Matt Wozniski | f29c898 | 2012-09-17 01:42:29 -0400 | [diff] [blame] | 3048 | #define TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3049 | |
| 3050 | // Collect all the implementation files together here |
| 3051 | // These are the equivalent of what would usually be cpp files |
| 3052 | |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 3053 | #ifdef __clang__ |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3054 | #pragma clang diagnostic push |
| 3055 | #pragma clang diagnostic ignored "-Wweak-vtables" |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 3056 | #endif |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3057 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 3058 | // #included from: ../catch_session.hpp |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 3059 | #define TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED |
Phil Nash | 83224e6 | 2011-08-12 18:53:28 +0100 | [diff] [blame] | 3060 | |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3061 | // #included from: internal/catch_commandline.hpp |
| 3062 | #define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED |
| 3063 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3064 | // #included from: catch_config.hpp |
| 3065 | #define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED |
| 3066 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3067 | // #included from: catch_test_spec_parser.hpp |
| 3068 | #define TWOBLUECUBES_CATCH_TEST_SPEC_PARSER_HPP_INCLUDED |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3069 | |
| 3070 | #ifdef __clang__ |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3071 | #pragma clang diagnostic push |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3072 | #pragma clang diagnostic ignored "-Wpadded" |
| 3073 | #endif |
| 3074 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3075 | // #included from: catch_test_spec.hpp |
| 3076 | #define TWOBLUECUBES_CATCH_TEST_SPEC_HPP_INCLUDED |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3077 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3078 | #ifdef __clang__ |
| 3079 | #pragma clang diagnostic push |
| 3080 | #pragma clang diagnostic ignored "-Wpadded" |
| 3081 | #endif |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3082 | |
Phil Nash | 8342ae8 | 2015-07-13 15:03:26 +0100 | [diff] [blame] | 3083 | // #included from: catch_wildcard_pattern.hpp |
| 3084 | #define TWOBLUECUBES_CATCH_WILDCARD_PATTERN_HPP_INCLUDED |
| 3085 | |
| 3086 | namespace Catch |
| 3087 | { |
| 3088 | class WildcardPattern { |
| 3089 | enum WildcardPosition { |
| 3090 | NoWildcard = 0, |
| 3091 | WildcardAtStart = 1, |
| 3092 | WildcardAtEnd = 2, |
| 3093 | WildcardAtBothEnds = WildcardAtStart | WildcardAtEnd |
| 3094 | }; |
| 3095 | |
| 3096 | public: |
| 3097 | |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 3098 | WildcardPattern( std::string const& pattern, CaseSensitive::Choice caseSensitivity ) |
Phil Nash | 8342ae8 | 2015-07-13 15:03:26 +0100 | [diff] [blame] | 3099 | : m_caseSensitivity( caseSensitivity ), |
| 3100 | m_wildcard( NoWildcard ), |
| 3101 | m_pattern( adjustCase( pattern ) ) |
| 3102 | { |
| 3103 | if( startsWith( m_pattern, "*" ) ) { |
| 3104 | m_pattern = m_pattern.substr( 1 ); |
| 3105 | m_wildcard = WildcardAtStart; |
| 3106 | } |
| 3107 | if( endsWith( m_pattern, "*" ) ) { |
| 3108 | m_pattern = m_pattern.substr( 0, m_pattern.size()-1 ); |
| 3109 | m_wildcard = static_cast<WildcardPosition>( m_wildcard | WildcardAtEnd ); |
| 3110 | } |
| 3111 | } |
| 3112 | virtual ~WildcardPattern(); |
| 3113 | virtual bool matches( std::string const& str ) const { |
| 3114 | switch( m_wildcard ) { |
| 3115 | case NoWildcard: |
| 3116 | return m_pattern == adjustCase( str ); |
| 3117 | case WildcardAtStart: |
| 3118 | return endsWith( adjustCase( str ), m_pattern ); |
| 3119 | case WildcardAtEnd: |
| 3120 | return startsWith( adjustCase( str ), m_pattern ); |
| 3121 | case WildcardAtBothEnds: |
| 3122 | return contains( adjustCase( str ), m_pattern ); |
| 3123 | } |
| 3124 | |
| 3125 | #ifdef __clang__ |
| 3126 | #pragma clang diagnostic push |
| 3127 | #pragma clang diagnostic ignored "-Wunreachable-code" |
| 3128 | #endif |
| 3129 | throw std::logic_error( "Unknown enum" ); |
| 3130 | #ifdef __clang__ |
| 3131 | #pragma clang diagnostic pop |
| 3132 | #endif |
| 3133 | } |
| 3134 | private: |
| 3135 | std::string adjustCase( std::string const& str ) const { |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 3136 | return m_caseSensitivity == CaseSensitive::No ? toLower( str ) : str; |
Phil Nash | 8342ae8 | 2015-07-13 15:03:26 +0100 | [diff] [blame] | 3137 | } |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 3138 | CaseSensitive::Choice m_caseSensitivity; |
Phil Nash | 8342ae8 | 2015-07-13 15:03:26 +0100 | [diff] [blame] | 3139 | WildcardPosition m_wildcard; |
| 3140 | std::string m_pattern; |
| 3141 | }; |
| 3142 | } |
| 3143 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3144 | #include <string> |
| 3145 | #include <vector> |
| 3146 | |
| 3147 | namespace Catch { |
| 3148 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3149 | class TestSpec { |
| 3150 | struct Pattern : SharedImpl<> { |
| 3151 | virtual ~Pattern(); |
| 3152 | virtual bool matches( TestCaseInfo const& testCase ) const = 0; |
| 3153 | }; |
| 3154 | class NamePattern : public Pattern { |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3155 | public: |
Phil Nash | 8342ae8 | 2015-07-13 15:03:26 +0100 | [diff] [blame] | 3156 | NamePattern( std::string const& name ) |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 3157 | : m_wildcardPattern( toLower( name ), CaseSensitive::No ) |
Phil Nash | 8342ae8 | 2015-07-13 15:03:26 +0100 | [diff] [blame] | 3158 | {} |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3159 | virtual ~NamePattern(); |
| 3160 | virtual bool matches( TestCaseInfo const& testCase ) const { |
Phil Nash | 8342ae8 | 2015-07-13 15:03:26 +0100 | [diff] [blame] | 3161 | return m_wildcardPattern.matches( toLower( testCase.name ) ); |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3162 | } |
| 3163 | private: |
Phil Nash | 8342ae8 | 2015-07-13 15:03:26 +0100 | [diff] [blame] | 3164 | WildcardPattern m_wildcardPattern; |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3165 | }; |
Phil Nash | 8342ae8 | 2015-07-13 15:03:26 +0100 | [diff] [blame] | 3166 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3167 | class TagPattern : public Pattern { |
| 3168 | public: |
| 3169 | TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {} |
| 3170 | virtual ~TagPattern(); |
| 3171 | virtual bool matches( TestCaseInfo const& testCase ) const { |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 3172 | return testCase.lcaseTags.find( m_tag ) != testCase.lcaseTags.end(); |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3173 | } |
| 3174 | private: |
| 3175 | std::string m_tag; |
| 3176 | }; |
Phil Nash | 8342ae8 | 2015-07-13 15:03:26 +0100 | [diff] [blame] | 3177 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3178 | class ExcludedPattern : public Pattern { |
| 3179 | public: |
| 3180 | ExcludedPattern( Ptr<Pattern> const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {} |
| 3181 | virtual ~ExcludedPattern(); |
| 3182 | virtual bool matches( TestCaseInfo const& testCase ) const { return !m_underlyingPattern->matches( testCase ); } |
| 3183 | private: |
| 3184 | Ptr<Pattern> m_underlyingPattern; |
| 3185 | }; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3186 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3187 | struct Filter { |
| 3188 | std::vector<Ptr<Pattern> > m_patterns; |
| 3189 | |
| 3190 | bool matches( TestCaseInfo const& testCase ) const { |
| 3191 | // All patterns in a filter must match for the filter to be a match |
| 3192 | for( std::vector<Ptr<Pattern> >::const_iterator it = m_patterns.begin(), itEnd = m_patterns.end(); it != itEnd; ++it ) |
| 3193 | if( !(*it)->matches( testCase ) ) |
| 3194 | return false; |
| 3195 | return true; |
| 3196 | } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3197 | }; |
| 3198 | |
| 3199 | public: |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3200 | bool hasFilters() const { |
| 3201 | return !m_filters.empty(); |
| 3202 | } |
| 3203 | bool matches( TestCaseInfo const& testCase ) const { |
| 3204 | // A TestSpec matches if any filter matches |
| 3205 | for( std::vector<Filter>::const_iterator it = m_filters.begin(), itEnd = m_filters.end(); it != itEnd; ++it ) |
| 3206 | if( it->matches( testCase ) ) |
| 3207 | return true; |
| 3208 | return false; |
| 3209 | } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3210 | |
| 3211 | private: |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3212 | std::vector<Filter> m_filters; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3213 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3214 | friend class TestSpecParser; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3215 | }; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3216 | } |
| 3217 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3218 | #ifdef __clang__ |
| 3219 | #pragma clang diagnostic pop |
| 3220 | #endif |
| 3221 | |
| 3222 | namespace Catch { |
| 3223 | |
| 3224 | class TestSpecParser { |
| 3225 | enum Mode{ None, Name, QuotedName, Tag }; |
| 3226 | Mode m_mode; |
| 3227 | bool m_exclusion; |
| 3228 | std::size_t m_start, m_pos; |
| 3229 | std::string m_arg; |
| 3230 | TestSpec::Filter m_currentFilter; |
| 3231 | TestSpec m_testSpec; |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 3232 | ITagAliasRegistry const* m_tagAliases; |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3233 | |
| 3234 | public: |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 3235 | TestSpecParser( ITagAliasRegistry const& tagAliases ) : m_tagAliases( &tagAliases ) {} |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 3236 | |
| 3237 | TestSpecParser& parse( std::string const& arg ) { |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3238 | m_mode = None; |
| 3239 | m_exclusion = false; |
| 3240 | m_start = std::string::npos; |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 3241 | m_arg = m_tagAliases->expandAliases( arg ); |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3242 | for( m_pos = 0; m_pos < m_arg.size(); ++m_pos ) |
| 3243 | visitChar( m_arg[m_pos] ); |
| 3244 | if( m_mode == Name ) |
| 3245 | addPattern<TestSpec::NamePattern>(); |
| 3246 | return *this; |
| 3247 | } |
| 3248 | TestSpec testSpec() { |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 3249 | addFilter(); |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3250 | return m_testSpec; |
| 3251 | } |
| 3252 | private: |
| 3253 | void visitChar( char c ) { |
| 3254 | if( m_mode == None ) { |
| 3255 | switch( c ) { |
| 3256 | case ' ': return; |
| 3257 | case '~': m_exclusion = true; return; |
| 3258 | case '[': return startNewMode( Tag, ++m_pos ); |
| 3259 | case '"': return startNewMode( QuotedName, ++m_pos ); |
| 3260 | default: startNewMode( Name, m_pos ); break; |
| 3261 | } |
| 3262 | } |
| 3263 | if( m_mode == Name ) { |
| 3264 | if( c == ',' ) { |
| 3265 | addPattern<TestSpec::NamePattern>(); |
| 3266 | addFilter(); |
| 3267 | } |
| 3268 | else if( c == '[' ) { |
| 3269 | if( subString() == "exclude:" ) |
| 3270 | m_exclusion = true; |
| 3271 | else |
| 3272 | addPattern<TestSpec::NamePattern>(); |
| 3273 | startNewMode( Tag, ++m_pos ); |
| 3274 | } |
| 3275 | } |
| 3276 | else if( m_mode == QuotedName && c == '"' ) |
| 3277 | addPattern<TestSpec::NamePattern>(); |
| 3278 | else if( m_mode == Tag && c == ']' ) |
| 3279 | addPattern<TestSpec::TagPattern>(); |
| 3280 | } |
| 3281 | void startNewMode( Mode mode, std::size_t start ) { |
| 3282 | m_mode = mode; |
| 3283 | m_start = start; |
| 3284 | } |
| 3285 | std::string subString() const { return m_arg.substr( m_start, m_pos - m_start ); } |
| 3286 | template<typename T> |
| 3287 | void addPattern() { |
| 3288 | std::string token = subString(); |
| 3289 | if( startsWith( token, "exclude:" ) ) { |
| 3290 | m_exclusion = true; |
| 3291 | token = token.substr( 8 ); |
| 3292 | } |
| 3293 | if( !token.empty() ) { |
| 3294 | Ptr<TestSpec::Pattern> pattern = new T( token ); |
| 3295 | if( m_exclusion ) |
| 3296 | pattern = new TestSpec::ExcludedPattern( pattern ); |
| 3297 | m_currentFilter.m_patterns.push_back( pattern ); |
| 3298 | } |
| 3299 | m_exclusion = false; |
| 3300 | m_mode = None; |
| 3301 | } |
| 3302 | void addFilter() { |
| 3303 | if( !m_currentFilter.m_patterns.empty() ) { |
| 3304 | m_testSpec.m_filters.push_back( m_currentFilter ); |
| 3305 | m_currentFilter = TestSpec::Filter(); |
| 3306 | } |
| 3307 | } |
| 3308 | }; |
| 3309 | inline TestSpec parseTestSpec( std::string const& arg ) { |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 3310 | return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec(); |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | } // namespace Catch |
| 3314 | |
| 3315 | #ifdef __clang__ |
| 3316 | #pragma clang diagnostic pop |
| 3317 | #endif |
| 3318 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 3319 | // #included from: catch_interfaces_config.h |
| 3320 | #define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED |
| 3321 | |
| 3322 | #include <iostream> |
| 3323 | #include <string> |
| 3324 | #include <vector> |
| 3325 | |
| 3326 | namespace Catch { |
| 3327 | |
| 3328 | struct Verbosity { enum Level { |
| 3329 | NoOutput = 0, |
| 3330 | Quiet, |
| 3331 | Normal |
| 3332 | }; }; |
| 3333 | |
| 3334 | struct WarnAbout { enum What { |
| 3335 | Nothing = 0x00, |
| 3336 | NoAssertions = 0x01 |
| 3337 | }; }; |
| 3338 | |
| 3339 | struct ShowDurations { enum OrNot { |
| 3340 | DefaultForReporter, |
| 3341 | Always, |
| 3342 | Never |
| 3343 | }; }; |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 3344 | struct RunTests { enum InWhatOrder { |
| 3345 | InDeclarationOrder, |
| 3346 | InLexicographicalOrder, |
| 3347 | InRandomOrder |
| 3348 | }; }; |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 3349 | struct UseColour { enum YesOrNo { |
| 3350 | Auto, |
| 3351 | Yes, |
| 3352 | No |
| 3353 | }; }; |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 3354 | |
| 3355 | class TestSpec; |
| 3356 | |
| 3357 | struct IConfig : IShared { |
| 3358 | |
| 3359 | virtual ~IConfig(); |
| 3360 | |
| 3361 | virtual bool allowThrows() const = 0; |
| 3362 | virtual std::ostream& stream() const = 0; |
| 3363 | virtual std::string name() const = 0; |
| 3364 | virtual bool includeSuccessfulResults() const = 0; |
| 3365 | virtual bool shouldDebugBreak() const = 0; |
| 3366 | virtual bool warnAboutMissingAssertions() const = 0; |
| 3367 | virtual int abortAfter() const = 0; |
| 3368 | virtual bool showInvisibles() const = 0; |
| 3369 | virtual ShowDurations::OrNot showDurations() const = 0; |
| 3370 | virtual TestSpec const& testSpec() const = 0; |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 3371 | virtual RunTests::InWhatOrder runOrder() const = 0; |
| 3372 | virtual unsigned int rngSeed() const = 0; |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 3373 | virtual UseColour::YesOrNo useColour() const = 0; |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 3374 | }; |
| 3375 | } |
| 3376 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3377 | // #included from: catch_stream.h |
| 3378 | #define TWOBLUECUBES_CATCH_STREAM_H_INCLUDED |
| 3379 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 3380 | // #included from: catch_streambuf.h |
| 3381 | #define TWOBLUECUBES_CATCH_STREAMBUF_H_INCLUDED |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3382 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 3383 | #include <streambuf> |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3384 | |
| 3385 | namespace Catch { |
| 3386 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 3387 | class StreamBufBase : public std::streambuf { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3388 | public: |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 3389 | virtual ~StreamBufBase() CATCH_NOEXCEPT; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3390 | }; |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 3391 | } |
| 3392 | |
| 3393 | #include <streambuf> |
| 3394 | #include <ostream> |
| 3395 | #include <fstream> |
| 3396 | |
| 3397 | namespace Catch { |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 3398 | |
| 3399 | std::ostream& cout(); |
| 3400 | std::ostream& cerr(); |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 3401 | |
| 3402 | struct IStream { |
| 3403 | virtual ~IStream() CATCH_NOEXCEPT; |
| 3404 | virtual std::ostream& stream() const = 0; |
| 3405 | }; |
| 3406 | |
| 3407 | class FileStream : public IStream { |
| 3408 | mutable std::ofstream m_ofs; |
| 3409 | public: |
| 3410 | FileStream( std::string const& filename ); |
Phil Nash | ece529a | 2015-11-03 17:37:43 +0000 | [diff] [blame] | 3411 | virtual ~FileStream() CATCH_NOEXCEPT; |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 3412 | public: // IStream |
| 3413 | virtual std::ostream& stream() const CATCH_OVERRIDE; |
| 3414 | }; |
| 3415 | |
| 3416 | class CoutStream : public IStream { |
| 3417 | mutable std::ostream m_os; |
| 3418 | public: |
| 3419 | CoutStream(); |
Phil Nash | ece529a | 2015-11-03 17:37:43 +0000 | [diff] [blame] | 3420 | virtual ~CoutStream() CATCH_NOEXCEPT; |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 3421 | |
| 3422 | public: // IStream |
| 3423 | virtual std::ostream& stream() const CATCH_OVERRIDE; |
| 3424 | }; |
| 3425 | |
| 3426 | class DebugOutStream : public IStream { |
| 3427 | std::auto_ptr<StreamBufBase> m_streamBuf; |
| 3428 | mutable std::ostream m_os; |
| 3429 | public: |
| 3430 | DebugOutStream(); |
Phil Nash | ece529a | 2015-11-03 17:37:43 +0000 | [diff] [blame] | 3431 | virtual ~DebugOutStream() CATCH_NOEXCEPT; |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 3432 | |
| 3433 | public: // IStream |
| 3434 | virtual std::ostream& stream() const CATCH_OVERRIDE; |
| 3435 | }; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3436 | } |
| 3437 | |
| 3438 | #include <memory> |
| 3439 | #include <vector> |
| 3440 | #include <string> |
| 3441 | #include <iostream> |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 3442 | #include <ctime> |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3443 | |
| 3444 | #ifndef CATCH_CONFIG_CONSOLE_WIDTH |
| 3445 | #define CATCH_CONFIG_CONSOLE_WIDTH 80 |
| 3446 | #endif |
| 3447 | |
| 3448 | namespace Catch { |
| 3449 | |
| 3450 | struct ConfigData { |
| 3451 | |
| 3452 | ConfigData() |
| 3453 | : listTests( false ), |
| 3454 | listTags( false ), |
| 3455 | listReporters( false ), |
| 3456 | listTestNamesOnly( false ), |
| 3457 | showSuccessfulTests( false ), |
| 3458 | shouldDebugBreak( false ), |
| 3459 | noThrow( false ), |
| 3460 | showHelp( false ), |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 3461 | showInvisibles( false ), |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 3462 | filenamesAsTags( false ), |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3463 | abortAfter( -1 ), |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 3464 | rngSeed( 0 ), |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3465 | verbosity( Verbosity::Normal ), |
| 3466 | warnings( WarnAbout::Nothing ), |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 3467 | showDurations( ShowDurations::DefaultForReporter ), |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 3468 | runOrder( RunTests::InDeclarationOrder ), |
| 3469 | useColour( UseColour::Auto ) |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3470 | {} |
| 3471 | |
| 3472 | bool listTests; |
| 3473 | bool listTags; |
| 3474 | bool listReporters; |
| 3475 | bool listTestNamesOnly; |
| 3476 | |
| 3477 | bool showSuccessfulTests; |
| 3478 | bool shouldDebugBreak; |
| 3479 | bool noThrow; |
| 3480 | bool showHelp; |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 3481 | bool showInvisibles; |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 3482 | bool filenamesAsTags; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3483 | |
| 3484 | int abortAfter; |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 3485 | unsigned int rngSeed; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3486 | |
| 3487 | Verbosity::Level verbosity; |
| 3488 | WarnAbout::What warnings; |
| 3489 | ShowDurations::OrNot showDurations; |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 3490 | RunTests::InWhatOrder runOrder; |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 3491 | UseColour::YesOrNo useColour; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3492 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3493 | std::string outputFilename; |
| 3494 | std::string name; |
| 3495 | std::string processName; |
| 3496 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 3497 | std::vector<std::string> reporterNames; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3498 | std::vector<std::string> testsOrTags; |
| 3499 | }; |
| 3500 | |
| 3501 | class Config : public SharedImpl<IConfig> { |
| 3502 | private: |
| 3503 | Config( Config const& other ); |
| 3504 | Config& operator = ( Config const& other ); |
| 3505 | virtual void dummy(); |
| 3506 | public: |
| 3507 | |
| 3508 | Config() |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3509 | {} |
| 3510 | |
| 3511 | Config( ConfigData const& data ) |
| 3512 | : m_data( data ), |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 3513 | m_stream( openStream() ) |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3514 | { |
| 3515 | if( !data.testsOrTags.empty() ) { |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 3516 | TestSpecParser parser( ITagAliasRegistry::get() ); |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3517 | for( std::size_t i = 0; i < data.testsOrTags.size(); ++i ) |
| 3518 | parser.parse( data.testsOrTags[i] ); |
| 3519 | m_testSpec = parser.testSpec(); |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3520 | } |
| 3521 | } |
| 3522 | |
| 3523 | virtual ~Config() { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3524 | } |
| 3525 | |
| 3526 | std::string const& getFilename() const { |
| 3527 | return m_data.outputFilename ; |
| 3528 | } |
| 3529 | |
| 3530 | bool listTests() const { return m_data.listTests; } |
| 3531 | bool listTestNamesOnly() const { return m_data.listTestNamesOnly; } |
| 3532 | bool listTags() const { return m_data.listTags; } |
| 3533 | bool listReporters() const { return m_data.listReporters; } |
| 3534 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3535 | std::string getProcessName() const { return m_data.processName; } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3536 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3537 | bool shouldDebugBreak() const { return m_data.shouldDebugBreak; } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3538 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 3539 | std::vector<std::string> getReporterNames() const { return m_data.reporterNames; } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3540 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3541 | int abortAfter() const { return m_data.abortAfter; } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3542 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3543 | TestSpec const& testSpec() const { return m_testSpec; } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3544 | |
| 3545 | bool showHelp() const { return m_data.showHelp; } |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 3546 | bool showInvisibles() const { return m_data.showInvisibles; } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3547 | |
| 3548 | // IConfig interface |
| 3549 | virtual bool allowThrows() const { return !m_data.noThrow; } |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 3550 | virtual std::ostream& stream() const { return m_stream->stream(); } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3551 | virtual std::string name() const { return m_data.name.empty() ? m_data.processName : m_data.name; } |
| 3552 | virtual bool includeSuccessfulResults() const { return m_data.showSuccessfulTests; } |
| 3553 | virtual bool warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; } |
| 3554 | virtual ShowDurations::OrNot showDurations() const { return m_data.showDurations; } |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 3555 | virtual RunTests::InWhatOrder runOrder() const { return m_data.runOrder; } |
| 3556 | virtual unsigned int rngSeed() const { return m_data.rngSeed; } |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 3557 | virtual UseColour::YesOrNo useColour() const { return m_data.useColour; } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3558 | |
| 3559 | private: |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 3560 | |
| 3561 | IStream const* openStream() { |
| 3562 | if( m_data.outputFilename.empty() ) |
| 3563 | return new CoutStream(); |
| 3564 | else if( m_data.outputFilename[0] == '%' ) { |
| 3565 | if( m_data.outputFilename == "%debug" ) |
| 3566 | return new DebugOutStream(); |
| 3567 | else |
| 3568 | throw std::domain_error( "Unrecognised stream: " + m_data.outputFilename ); |
| 3569 | } |
| 3570 | else |
| 3571 | return new FileStream( m_data.outputFilename ); |
| 3572 | } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3573 | ConfigData m_data; |
| 3574 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 3575 | std::auto_ptr<IStream const> m_stream; |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 3576 | TestSpec m_testSpec; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 3577 | }; |
| 3578 | |
| 3579 | } // end namespace Catch |
| 3580 | |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3581 | // #included from: catch_clara.h |
| 3582 | #define TWOBLUECUBES_CATCH_CLARA_H_INCLUDED |
| 3583 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 3584 | // Use Catch's value for console width (store Clara's off to the side, if present) |
| 3585 | #ifdef CLARA_CONFIG_CONSOLE_WIDTH |
| 3586 | #define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH |
| 3587 | #undef CLARA_CONFIG_CONSOLE_WIDTH |
| 3588 | #endif |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3589 | #define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH |
| 3590 | |
| 3591 | // Declare Clara inside the Catch namespace |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 3592 | #define STITCH_CLARA_OPEN_NAMESPACE namespace Catch { |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 3593 | // #included from: ../external/clara.h |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3594 | |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 3595 | // Version 0.0.1.1 |
| 3596 | |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3597 | // Only use header guard if we are not using an outer namespace |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 3598 | #if !defined(TWOBLUECUBES_CLARA_H_INCLUDED) || defined(STITCH_CLARA_OPEN_NAMESPACE) |
| 3599 | |
| 3600 | #ifndef STITCH_CLARA_OPEN_NAMESPACE |
Phil Nash | 1f1ee3c | 2014-03-01 10:38:14 +0000 | [diff] [blame] | 3601 | #define TWOBLUECUBES_CLARA_H_INCLUDED |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 3602 | #define STITCH_CLARA_OPEN_NAMESPACE |
| 3603 | #define STITCH_CLARA_CLOSE_NAMESPACE |
| 3604 | #else |
| 3605 | #define STITCH_CLARA_CLOSE_NAMESPACE } |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3606 | #endif |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 3607 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 3608 | #define STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE STITCH_CLARA_OPEN_NAMESPACE |
Phil Nash | 1f1ee3c | 2014-03-01 10:38:14 +0000 | [diff] [blame] | 3609 | |
| 3610 | // ----------- #included from tbc_text_format.h ----------- |
| 3611 | |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3612 | // Only use header guard if we are not using an outer namespace |
Phil Nash | 1f1ee3c | 2014-03-01 10:38:14 +0000 | [diff] [blame] | 3613 | #if !defined(TBC_TEXT_FORMAT_H_INCLUDED) || defined(STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE) |
| 3614 | #ifndef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE |
| 3615 | #define TBC_TEXT_FORMAT_H_INCLUDED |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3616 | #endif |
Phil Nash | 1f1ee3c | 2014-03-01 10:38:14 +0000 | [diff] [blame] | 3617 | |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 3618 | #include <string> |
| 3619 | #include <vector> |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3620 | #include <sstream> |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 3621 | #include <algorithm> |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 3622 | |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3623 | // Use optional outer namespace |
Phil Nash | 1f1ee3c | 2014-03-01 10:38:14 +0000 | [diff] [blame] | 3624 | #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE |
| 3625 | namespace STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE { |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3626 | #endif |
| 3627 | |
| 3628 | namespace Tbc { |
| 3629 | |
| 3630 | #ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH |
| 3631 | const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH; |
| 3632 | #else |
| 3633 | const unsigned int consoleWidth = 80; |
| 3634 | #endif |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 3635 | |
Phil Nash | 1927925 | 2013-04-20 21:07:32 +0100 | [diff] [blame] | 3636 | struct TextAttributes { |
| 3637 | TextAttributes() |
| 3638 | : initialIndent( std::string::npos ), |
| 3639 | indent( 0 ), |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3640 | width( consoleWidth-1 ), |
Phil Nash | 1927925 | 2013-04-20 21:07:32 +0100 | [diff] [blame] | 3641 | tabChar( '\t' ) |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 3642 | {} |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 3643 | |
Phil Nash | 1927925 | 2013-04-20 21:07:32 +0100 | [diff] [blame] | 3644 | TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; } |
| 3645 | TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; } |
| 3646 | TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; } |
| 3647 | TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; } |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 3648 | |
Phil Nash | 1927925 | 2013-04-20 21:07:32 +0100 | [diff] [blame] | 3649 | std::size_t initialIndent; // indent of first line, or npos |
| 3650 | std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos |
| 3651 | std::size_t width; // maximum width of text, including indent. Longer text will wrap |
| 3652 | char tabChar; // If this char is seen the indent is changed to current pos |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 3653 | }; |
| 3654 | |
Phil Nash | 1927925 | 2013-04-20 21:07:32 +0100 | [diff] [blame] | 3655 | class Text { |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3656 | public: |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3657 | Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) |
| 3658 | : attr( _attr ) |
| 3659 | { |
| 3660 | std::string wrappableChars = " [({.,/|\\-"; |
| 3661 | std::size_t indent = _attr.initialIndent != std::string::npos |
| 3662 | ? _attr.initialIndent |
| 3663 | : _attr.indent; |
| 3664 | std::string remainder = _str; |
| 3665 | |
| 3666 | while( !remainder.empty() ) { |
| 3667 | if( lines.size() >= 1000 ) { |
| 3668 | lines.push_back( "... message truncated due to excessive size" ); |
| 3669 | return; |
| 3670 | } |
| 3671 | std::size_t tabPos = std::string::npos; |
| 3672 | std::size_t width = (std::min)( remainder.size(), _attr.width - indent ); |
| 3673 | std::size_t pos = remainder.find_first_of( '\n' ); |
| 3674 | if( pos <= width ) { |
| 3675 | width = pos; |
| 3676 | } |
| 3677 | pos = remainder.find_last_of( _attr.tabChar, width ); |
| 3678 | if( pos != std::string::npos ) { |
| 3679 | tabPos = pos; |
| 3680 | if( remainder[width] == '\n' ) |
| 3681 | width--; |
| 3682 | remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); |
| 3683 | } |
| 3684 | |
| 3685 | if( width == remainder.size() ) { |
| 3686 | spliceLine( indent, remainder, width ); |
| 3687 | } |
| 3688 | else if( remainder[width] == '\n' ) { |
| 3689 | spliceLine( indent, remainder, width ); |
| 3690 | if( width <= 1 || remainder.size() != 1 ) |
| 3691 | remainder = remainder.substr( 1 ); |
| 3692 | indent = _attr.indent; |
| 3693 | } |
| 3694 | else { |
| 3695 | pos = remainder.find_last_of( wrappableChars, width ); |
| 3696 | if( pos != std::string::npos && pos > 0 ) { |
| 3697 | spliceLine( indent, remainder, pos ); |
| 3698 | if( remainder[0] == ' ' ) |
| 3699 | remainder = remainder.substr( 1 ); |
| 3700 | } |
| 3701 | else { |
| 3702 | spliceLine( indent, remainder, width-1 ); |
| 3703 | lines.back() += "-"; |
| 3704 | } |
| 3705 | if( lines.size() == 1 ) |
| 3706 | indent = _attr.indent; |
| 3707 | if( tabPos != std::string::npos ) |
| 3708 | indent += tabPos; |
| 3709 | } |
| 3710 | } |
| 3711 | } |
| 3712 | |
| 3713 | void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) { |
| 3714 | lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) ); |
| 3715 | _remainder = _remainder.substr( _pos ); |
| 3716 | } |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3717 | |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 3718 | typedef std::vector<std::string>::const_iterator const_iterator; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3719 | |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 3720 | const_iterator begin() const { return lines.begin(); } |
| 3721 | const_iterator end() const { return lines.end(); } |
| 3722 | std::string const& last() const { return lines.back(); } |
| 3723 | std::size_t size() const { return lines.size(); } |
| 3724 | std::string const& operator[]( std::size_t _index ) const { return lines[_index]; } |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3725 | std::string toString() const { |
| 3726 | std::ostringstream oss; |
| 3727 | oss << *this; |
| 3728 | return oss.str(); |
| 3729 | } |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3730 | |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3731 | inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { |
| 3732 | for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); |
| 3733 | it != itEnd; ++it ) { |
| 3734 | if( it != _text.begin() ) |
| 3735 | _stream << "\n"; |
| 3736 | _stream << *it; |
| 3737 | } |
| 3738 | return _stream; |
| 3739 | } |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3740 | |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3741 | private: |
Phil Nash | 1927925 | 2013-04-20 21:07:32 +0100 | [diff] [blame] | 3742 | std::string str; |
| 3743 | TextAttributes attr; |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 3744 | std::vector<std::string> lines; |
| 3745 | }; |
| 3746 | |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3747 | } // end namespace Tbc |
| 3748 | |
Phil Nash | 1f1ee3c | 2014-03-01 10:38:14 +0000 | [diff] [blame] | 3749 | #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3750 | } // end outer namespace |
| 3751 | #endif |
| 3752 | |
Phil Nash | 1f1ee3c | 2014-03-01 10:38:14 +0000 | [diff] [blame] | 3753 | #endif // TBC_TEXT_FORMAT_H_INCLUDED |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3754 | |
Phil Nash | 1f1ee3c | 2014-03-01 10:38:14 +0000 | [diff] [blame] | 3755 | // ----------- end of #include from tbc_text_format.h ----------- |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 3756 | // ........... back in clara.h |
Phil Nash | 1f1ee3c | 2014-03-01 10:38:14 +0000 | [diff] [blame] | 3757 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 3758 | #undef STITCH_TBC_TEXT_FORMAT_OPEN_NAMESPACE |
Phil Nash | 1f1ee3c | 2014-03-01 10:38:14 +0000 | [diff] [blame] | 3759 | |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 3760 | // ----------- #included from clara_compilers.h ----------- |
| 3761 | |
| 3762 | #ifndef TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED |
| 3763 | #define TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED |
| 3764 | |
| 3765 | // Detect a number of compiler features - mostly C++11/14 conformance - by compiler |
| 3766 | // The following features are defined: |
| 3767 | // |
| 3768 | // CLARA_CONFIG_CPP11_NULLPTR : is nullptr supported? |
| 3769 | // CLARA_CONFIG_CPP11_NOEXCEPT : is noexcept supported? |
| 3770 | // CLARA_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods |
| 3771 | // CLARA_CONFIG_CPP11_OVERRIDE : is override supported? |
| 3772 | // CLARA_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr) |
| 3773 | |
| 3774 | // CLARA_CONFIG_CPP11_OR_GREATER : Is C++11 supported? |
| 3775 | |
| 3776 | // CLARA_CONFIG_VARIADIC_MACROS : are variadic macros supported? |
| 3777 | |
| 3778 | // In general each macro has a _NO_<feature name> form |
| 3779 | // (e.g. CLARA_CONFIG_CPP11_NO_NULLPTR) which disables the feature. |
| 3780 | // Many features, at point of detection, define an _INTERNAL_ macro, so they |
| 3781 | // can be combined, en-mass, with the _NO_ forms later. |
| 3782 | |
| 3783 | // All the C++11 features can be disabled with CLARA_CONFIG_NO_CPP11 |
| 3784 | |
| 3785 | #ifdef __clang__ |
| 3786 | |
| 3787 | #if __has_feature(cxx_nullptr) |
| 3788 | #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR |
| 3789 | #endif |
| 3790 | |
| 3791 | #if __has_feature(cxx_noexcept) |
| 3792 | #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT |
| 3793 | #endif |
| 3794 | |
| 3795 | #endif // __clang__ |
| 3796 | |
| 3797 | //////////////////////////////////////////////////////////////////////////////// |
| 3798 | // GCC |
| 3799 | #ifdef __GNUC__ |
| 3800 | |
| 3801 | #if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__) |
| 3802 | #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR |
| 3803 | #endif |
| 3804 | |
| 3805 | // - otherwise more recent versions define __cplusplus >= 201103L |
| 3806 | // and will get picked up below |
| 3807 | |
| 3808 | #endif // __GNUC__ |
| 3809 | |
| 3810 | //////////////////////////////////////////////////////////////////////////////// |
| 3811 | // Visual C++ |
| 3812 | #ifdef _MSC_VER |
| 3813 | |
| 3814 | #if (_MSC_VER >= 1600) |
| 3815 | #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR |
| 3816 | #define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR |
| 3817 | #endif |
| 3818 | |
| 3819 | #if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015)) |
| 3820 | #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT |
| 3821 | #define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS |
| 3822 | #endif |
| 3823 | |
| 3824 | #endif // _MSC_VER |
| 3825 | |
| 3826 | //////////////////////////////////////////////////////////////////////////////// |
| 3827 | // C++ language feature support |
| 3828 | |
| 3829 | // catch all support for C++11 |
| 3830 | #if defined(__cplusplus) && __cplusplus >= 201103L |
| 3831 | |
| 3832 | #define CLARA_CPP11_OR_GREATER |
| 3833 | |
| 3834 | #if !defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR) |
| 3835 | #define CLARA_INTERNAL_CONFIG_CPP11_NULLPTR |
| 3836 | #endif |
| 3837 | |
| 3838 | #ifndef CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT |
| 3839 | #define CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT |
| 3840 | #endif |
| 3841 | |
| 3842 | #ifndef CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS |
| 3843 | #define CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS |
| 3844 | #endif |
| 3845 | |
| 3846 | #if !defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE) |
| 3847 | #define CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE |
| 3848 | #endif |
| 3849 | #if !defined(CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) |
| 3850 | #define CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR |
| 3851 | #endif |
| 3852 | |
| 3853 | #endif // __cplusplus >= 201103L |
| 3854 | |
| 3855 | // Now set the actual defines based on the above + anything the user has configured |
| 3856 | #if defined(CLARA_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NO_NULLPTR) && !defined(CLARA_CONFIG_CPP11_NULLPTR) && !defined(CLARA_CONFIG_NO_CPP11) |
| 3857 | #define CLARA_CONFIG_CPP11_NULLPTR |
| 3858 | #endif |
| 3859 | #if defined(CLARA_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_CONFIG_NO_CPP11) |
| 3860 | #define CLARA_CONFIG_CPP11_NOEXCEPT |
| 3861 | #endif |
| 3862 | #if defined(CLARA_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CLARA_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CLARA_CONFIG_CPP11_GENERATED_METHODS) && !defined(CLARA_CONFIG_NO_CPP11) |
| 3863 | #define CLARA_CONFIG_CPP11_GENERATED_METHODS |
| 3864 | #endif |
| 3865 | #if defined(CLARA_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_OVERRIDE) && !defined(CLARA_CONFIG_CPP11_OVERRIDE) && !defined(CLARA_CONFIG_NO_CPP11) |
| 3866 | #define CLARA_CONFIG_CPP11_OVERRIDE |
| 3867 | #endif |
| 3868 | #if defined(CLARA_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CLARA_CONFIG_NO_UNIQUE_PTR) && !defined(CLARA_CONFIG_CPP11_UNIQUE_PTR) && !defined(CLARA_CONFIG_NO_CPP11) |
| 3869 | #define CLARA_CONFIG_CPP11_UNIQUE_PTR |
| 3870 | #endif |
| 3871 | |
| 3872 | // noexcept support: |
| 3873 | #if defined(CLARA_CONFIG_CPP11_NOEXCEPT) && !defined(CLARA_NOEXCEPT) |
| 3874 | #define CLARA_NOEXCEPT noexcept |
| 3875 | # define CLARA_NOEXCEPT_IS(x) noexcept(x) |
| 3876 | #else |
| 3877 | #define CLARA_NOEXCEPT throw() |
| 3878 | # define CLARA_NOEXCEPT_IS(x) |
| 3879 | #endif |
| 3880 | |
| 3881 | // nullptr support |
| 3882 | #ifdef CLARA_CONFIG_CPP11_NULLPTR |
| 3883 | #define CLARA_NULL nullptr |
| 3884 | #else |
| 3885 | #define CLARA_NULL NULL |
| 3886 | #endif |
| 3887 | |
| 3888 | // override support |
| 3889 | #ifdef CLARA_CONFIG_CPP11_OVERRIDE |
| 3890 | #define CLARA_OVERRIDE override |
| 3891 | #else |
| 3892 | #define CLARA_OVERRIDE |
| 3893 | #endif |
| 3894 | |
| 3895 | // unique_ptr support |
| 3896 | #ifdef CLARA_CONFIG_CPP11_UNIQUE_PTR |
| 3897 | # define CLARA_AUTO_PTR( T ) std::unique_ptr<T> |
| 3898 | #else |
| 3899 | # define CLARA_AUTO_PTR( T ) std::auto_ptr<T> |
| 3900 | #endif |
| 3901 | |
| 3902 | #endif // TWOBLUECUBES_CLARA_COMPILERS_H_INCLUDED |
| 3903 | |
| 3904 | // ----------- end of #include from clara_compilers.h ----------- |
| 3905 | // ........... back in clara.h |
| 3906 | |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3907 | #include <map> |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3908 | #include <stdexcept> |
| 3909 | #include <memory> |
| 3910 | |
| 3911 | // Use optional outer namespace |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 3912 | #ifdef STITCH_CLARA_OPEN_NAMESPACE |
| 3913 | STITCH_CLARA_OPEN_NAMESPACE |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3914 | #endif |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 3915 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 3916 | namespace Clara { |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 3917 | |
| 3918 | struct UnpositionalTag {}; |
| 3919 | |
| 3920 | extern UnpositionalTag _; |
| 3921 | |
| 3922 | #ifdef CLARA_CONFIG_MAIN |
| 3923 | UnpositionalTag _; |
| 3924 | #endif |
| 3925 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 3926 | namespace Detail { |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3927 | |
| 3928 | #ifdef CLARA_CONSOLE_WIDTH |
| 3929 | const unsigned int consoleWidth = CLARA_CONFIG_CONSOLE_WIDTH; |
| 3930 | #else |
| 3931 | const unsigned int consoleWidth = 80; |
| 3932 | #endif |
| 3933 | |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 3934 | // Use this to try and stop compiler from warning about unreachable code |
| 3935 | inline bool isTrue( bool value ) { return value; } |
| 3936 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 3937 | using namespace Tbc; |
| 3938 | |
| 3939 | inline bool startsWith( std::string const& str, std::string const& prefix ) { |
| 3940 | return str.size() >= prefix.size() && str.substr( 0, prefix.size() ) == prefix; |
| 3941 | } |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 3942 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 3943 | template<typename T> struct RemoveConstRef{ typedef T type; }; |
| 3944 | template<typename T> struct RemoveConstRef<T&>{ typedef T type; }; |
| 3945 | template<typename T> struct RemoveConstRef<T const&>{ typedef T type; }; |
| 3946 | template<typename T> struct RemoveConstRef<T const>{ typedef T type; }; |
| 3947 | |
| 3948 | template<typename T> struct IsBool { static const bool value = false; }; |
| 3949 | template<> struct IsBool<bool> { static const bool value = true; }; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3950 | |
| 3951 | template<typename T> |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 3952 | void convertInto( std::string const& _source, T& _dest ) { |
| 3953 | std::stringstream ss; |
| 3954 | ss << _source; |
| 3955 | ss >> _dest; |
| 3956 | if( ss.fail() ) |
| 3957 | throw std::runtime_error( "Unable to convert " + _source + " to destination type" ); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3958 | } |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 3959 | inline void convertInto( std::string const& _source, std::string& _dest ) { |
| 3960 | _dest = _source; |
| 3961 | } |
| 3962 | inline void convertInto( std::string const& _source, bool& _dest ) { |
| 3963 | std::string sourceLC = _source; |
| 3964 | std::transform( sourceLC.begin(), sourceLC.end(), sourceLC.begin(), ::tolower ); |
Phil Nash | 4611871 | 2013-08-16 19:01:32 +0100 | [diff] [blame] | 3965 | if( sourceLC == "y" || sourceLC == "1" || sourceLC == "true" || sourceLC == "yes" || sourceLC == "on" ) |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 3966 | _dest = true; |
Phil Nash | 4611871 | 2013-08-16 19:01:32 +0100 | [diff] [blame] | 3967 | else if( sourceLC == "n" || sourceLC == "0" || sourceLC == "false" || sourceLC == "no" || sourceLC == "off" ) |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 3968 | _dest = false; |
| 3969 | else |
Phil Nash | 4611871 | 2013-08-16 19:01:32 +0100 | [diff] [blame] | 3970 | throw std::runtime_error( "Expected a boolean value but did not recognise:\n '" + _source + "'" ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 3971 | } |
| 3972 | inline void convertInto( bool _source, bool& _dest ) { |
| 3973 | _dest = _source; |
| 3974 | } |
| 3975 | template<typename T> |
| 3976 | inline void convertInto( bool, T& ) { |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 3977 | if( isTrue( true ) ) |
| 3978 | throw std::runtime_error( "Invalid conversion" ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 3979 | } |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 3980 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 3981 | template<typename ConfigT> |
| 3982 | struct IArgFunction { |
| 3983 | virtual ~IArgFunction() {} |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 3984 | #ifdef CLARA_CONFIG_CPP11_GENERATED_METHODS |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 3985 | IArgFunction() = default; |
| 3986 | IArgFunction( IArgFunction const& ) = default; |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 3987 | #endif |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 3988 | virtual void set( ConfigT& config, std::string const& value ) const = 0; |
| 3989 | virtual void setFlag( ConfigT& config ) const = 0; |
| 3990 | virtual bool takesArg() const = 0; |
| 3991 | virtual IArgFunction* clone() const = 0; |
| 3992 | }; |
| 3993 | |
| 3994 | template<typename ConfigT> |
| 3995 | class BoundArgFunction { |
| 3996 | public: |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 3997 | BoundArgFunction() : functionObj( CLARA_NULL ) {} |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 3998 | BoundArgFunction( IArgFunction<ConfigT>* _functionObj ) : functionObj( _functionObj ) {} |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 3999 | BoundArgFunction( BoundArgFunction const& other ) : functionObj( other.functionObj ? other.functionObj->clone() : CLARA_NULL ) {} |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4000 | BoundArgFunction& operator = ( BoundArgFunction const& other ) { |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 4001 | IArgFunction<ConfigT>* newFunctionObj = other.functionObj ? other.functionObj->clone() : CLARA_NULL; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4002 | delete functionObj; |
| 4003 | functionObj = newFunctionObj; |
| 4004 | return *this; |
| 4005 | } |
| 4006 | ~BoundArgFunction() { delete functionObj; } |
| 4007 | |
| 4008 | void set( ConfigT& config, std::string const& value ) const { |
| 4009 | functionObj->set( config, value ); |
| 4010 | } |
| 4011 | void setFlag( ConfigT& config ) const { |
| 4012 | functionObj->setFlag( config ); |
| 4013 | } |
| 4014 | bool takesArg() const { return functionObj->takesArg(); } |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4015 | |
| 4016 | bool isSet() const { |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 4017 | return functionObj != CLARA_NULL; |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4018 | } |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4019 | private: |
| 4020 | IArgFunction<ConfigT>* functionObj; |
| 4021 | }; |
| 4022 | |
| 4023 | template<typename C> |
| 4024 | struct NullBinder : IArgFunction<C>{ |
| 4025 | virtual void set( C&, std::string const& ) const {} |
| 4026 | virtual void setFlag( C& ) const {} |
| 4027 | virtual bool takesArg() const { return true; } |
| 4028 | virtual IArgFunction<C>* clone() const { return new NullBinder( *this ); } |
| 4029 | }; |
| 4030 | |
| 4031 | template<typename C, typename M> |
| 4032 | struct BoundDataMember : IArgFunction<C>{ |
| 4033 | BoundDataMember( M C::* _member ) : member( _member ) {} |
| 4034 | virtual void set( C& p, std::string const& stringValue ) const { |
| 4035 | convertInto( stringValue, p.*member ); |
| 4036 | } |
| 4037 | virtual void setFlag( C& p ) const { |
| 4038 | convertInto( true, p.*member ); |
| 4039 | } |
| 4040 | virtual bool takesArg() const { return !IsBool<M>::value; } |
| 4041 | virtual IArgFunction<C>* clone() const { return new BoundDataMember( *this ); } |
| 4042 | M C::* member; |
| 4043 | }; |
| 4044 | template<typename C, typename M> |
| 4045 | struct BoundUnaryMethod : IArgFunction<C>{ |
| 4046 | BoundUnaryMethod( void (C::*_member)( M ) ) : member( _member ) {} |
| 4047 | virtual void set( C& p, std::string const& stringValue ) const { |
| 4048 | typename RemoveConstRef<M>::type value; |
| 4049 | convertInto( stringValue, value ); |
| 4050 | (p.*member)( value ); |
| 4051 | } |
| 4052 | virtual void setFlag( C& p ) const { |
| 4053 | typename RemoveConstRef<M>::type value; |
| 4054 | convertInto( true, value ); |
| 4055 | (p.*member)( value ); |
| 4056 | } |
| 4057 | virtual bool takesArg() const { return !IsBool<M>::value; } |
| 4058 | virtual IArgFunction<C>* clone() const { return new BoundUnaryMethod( *this ); } |
| 4059 | void (C::*member)( M ); |
| 4060 | }; |
| 4061 | template<typename C> |
| 4062 | struct BoundNullaryMethod : IArgFunction<C>{ |
| 4063 | BoundNullaryMethod( void (C::*_member)() ) : member( _member ) {} |
| 4064 | virtual void set( C& p, std::string const& stringValue ) const { |
| 4065 | bool value; |
| 4066 | convertInto( stringValue, value ); |
| 4067 | if( value ) |
| 4068 | (p.*member)(); |
| 4069 | } |
| 4070 | virtual void setFlag( C& p ) const { |
| 4071 | (p.*member)(); |
| 4072 | } |
| 4073 | virtual bool takesArg() const { return false; } |
| 4074 | virtual IArgFunction<C>* clone() const { return new BoundNullaryMethod( *this ); } |
| 4075 | void (C::*member)(); |
| 4076 | }; |
| 4077 | |
| 4078 | template<typename C> |
| 4079 | struct BoundUnaryFunction : IArgFunction<C>{ |
| 4080 | BoundUnaryFunction( void (*_function)( C& ) ) : function( _function ) {} |
| 4081 | virtual void set( C& obj, std::string const& stringValue ) const { |
| 4082 | bool value; |
| 4083 | convertInto( stringValue, value ); |
| 4084 | if( value ) |
| 4085 | function( obj ); |
| 4086 | } |
| 4087 | virtual void setFlag( C& p ) const { |
| 4088 | function( p ); |
| 4089 | } |
| 4090 | virtual bool takesArg() const { return false; } |
| 4091 | virtual IArgFunction<C>* clone() const { return new BoundUnaryFunction( *this ); } |
| 4092 | void (*function)( C& ); |
| 4093 | }; |
| 4094 | |
| 4095 | template<typename C, typename T> |
| 4096 | struct BoundBinaryFunction : IArgFunction<C>{ |
| 4097 | BoundBinaryFunction( void (*_function)( C&, T ) ) : function( _function ) {} |
| 4098 | virtual void set( C& obj, std::string const& stringValue ) const { |
| 4099 | typename RemoveConstRef<T>::type value; |
| 4100 | convertInto( stringValue, value ); |
| 4101 | function( obj, value ); |
| 4102 | } |
| 4103 | virtual void setFlag( C& obj ) const { |
| 4104 | typename RemoveConstRef<T>::type value; |
| 4105 | convertInto( true, value ); |
| 4106 | function( obj, value ); |
| 4107 | } |
| 4108 | virtual bool takesArg() const { return !IsBool<T>::value; } |
| 4109 | virtual IArgFunction<C>* clone() const { return new BoundBinaryFunction( *this ); } |
| 4110 | void (*function)( C&, T ); |
| 4111 | }; |
| 4112 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4113 | } // namespace Detail |
| 4114 | |
| 4115 | struct Parser { |
| 4116 | Parser() : separators( " \t=:" ) {} |
| 4117 | |
| 4118 | struct Token { |
| 4119 | enum Type { Positional, ShortOpt, LongOpt }; |
| 4120 | Token( Type _type, std::string const& _data ) : type( _type ), data( _data ) {} |
| 4121 | Type type; |
| 4122 | std::string data; |
| 4123 | }; |
| 4124 | |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 4125 | void parseIntoTokens( int argc, char const* const argv[], std::vector<Parser::Token>& tokens ) const { |
Phil Nash | e45e3a1 | 2013-12-23 10:24:06 +0000 | [diff] [blame] | 4126 | const std::string doubleDash = "--"; |
| 4127 | for( int i = 1; i < argc && argv[i] != doubleDash; ++i ) |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4128 | parseIntoTokens( argv[i] , tokens); |
| 4129 | } |
| 4130 | void parseIntoTokens( std::string arg, std::vector<Parser::Token>& tokens ) const { |
| 4131 | while( !arg.empty() ) { |
| 4132 | Parser::Token token( Parser::Token::Positional, arg ); |
| 4133 | arg = ""; |
| 4134 | if( token.data[0] == '-' ) { |
| 4135 | if( token.data.size() > 1 && token.data[1] == '-' ) { |
| 4136 | token = Parser::Token( Parser::Token::LongOpt, token.data.substr( 2 ) ); |
| 4137 | } |
| 4138 | else { |
| 4139 | token = Parser::Token( Parser::Token::ShortOpt, token.data.substr( 1 ) ); |
| 4140 | if( token.data.size() > 1 && separators.find( token.data[1] ) == std::string::npos ) { |
| 4141 | arg = "-" + token.data.substr( 1 ); |
| 4142 | token.data = token.data.substr( 0, 1 ); |
| 4143 | } |
| 4144 | } |
| 4145 | } |
| 4146 | if( token.type != Parser::Token::Positional ) { |
| 4147 | std::size_t pos = token.data.find_first_of( separators ); |
| 4148 | if( pos != std::string::npos ) { |
| 4149 | arg = token.data.substr( pos+1 ); |
| 4150 | token.data = token.data.substr( 0, pos ); |
| 4151 | } |
| 4152 | } |
| 4153 | tokens.push_back( token ); |
| 4154 | } |
| 4155 | } |
| 4156 | std::string separators; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 4157 | }; |
| 4158 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4159 | template<typename ConfigT> |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4160 | struct CommonArgProperties { |
| 4161 | CommonArgProperties() {} |
| 4162 | CommonArgProperties( Detail::BoundArgFunction<ConfigT> const& _boundField ) : boundField( _boundField ) {} |
| 4163 | |
| 4164 | Detail::BoundArgFunction<ConfigT> boundField; |
| 4165 | std::string description; |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4166 | std::string detail; |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4167 | std::string placeholder; // Only value if boundField takes an arg |
| 4168 | |
| 4169 | bool takesArg() const { |
| 4170 | return !placeholder.empty(); |
| 4171 | } |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4172 | void validate() const { |
| 4173 | if( !boundField.isSet() ) |
| 4174 | throw std::logic_error( "option not bound" ); |
| 4175 | } |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4176 | }; |
| 4177 | struct OptionArgProperties { |
| 4178 | std::vector<std::string> shortNames; |
| 4179 | std::string longName; |
| 4180 | |
| 4181 | bool hasShortName( std::string const& shortName ) const { |
| 4182 | return std::find( shortNames.begin(), shortNames.end(), shortName ) != shortNames.end(); |
| 4183 | } |
| 4184 | bool hasLongName( std::string const& _longName ) const { |
| 4185 | return _longName == longName; |
| 4186 | } |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4187 | }; |
| 4188 | struct PositionalArgProperties { |
| 4189 | PositionalArgProperties() : position( -1 ) {} |
| 4190 | int position; // -1 means non-positional (floating) |
| 4191 | |
| 4192 | bool isFixedPositional() const { |
| 4193 | return position != -1; |
| 4194 | } |
| 4195 | }; |
| 4196 | |
| 4197 | template<typename ConfigT> |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4198 | class CommandLine { |
| 4199 | |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4200 | struct Arg : CommonArgProperties<ConfigT>, OptionArgProperties, PositionalArgProperties { |
| 4201 | Arg() {} |
| 4202 | Arg( Detail::BoundArgFunction<ConfigT> const& _boundField ) : CommonArgProperties<ConfigT>( _boundField ) {} |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4203 | |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4204 | using CommonArgProperties<ConfigT>::placeholder; // !TBD |
| 4205 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4206 | std::string dbgName() const { |
| 4207 | if( !longName.empty() ) |
| 4208 | return "--" + longName; |
| 4209 | if( !shortNames.empty() ) |
| 4210 | return "-" + shortNames[0]; |
| 4211 | return "positional args"; |
| 4212 | } |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4213 | std::string commands() const { |
| 4214 | std::ostringstream oss; |
| 4215 | bool first = true; |
| 4216 | std::vector<std::string>::const_iterator it = shortNames.begin(), itEnd = shortNames.end(); |
| 4217 | for(; it != itEnd; ++it ) { |
| 4218 | if( first ) |
| 4219 | first = false; |
| 4220 | else |
| 4221 | oss << ", "; |
| 4222 | oss << "-" << *it; |
| 4223 | } |
| 4224 | if( !longName.empty() ) { |
| 4225 | if( !first ) |
| 4226 | oss << ", "; |
| 4227 | oss << "--" << longName; |
| 4228 | } |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4229 | if( !placeholder.empty() ) |
| 4230 | oss << " <" << placeholder << ">"; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4231 | return oss.str(); |
| 4232 | } |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4233 | }; |
| 4234 | |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 4235 | typedef CLARA_AUTO_PTR( Arg ) ArgAutoPtr; |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 4236 | |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4237 | friend void addOptName( Arg& arg, std::string const& optName ) |
| 4238 | { |
| 4239 | if( optName.empty() ) |
| 4240 | return; |
| 4241 | if( Detail::startsWith( optName, "--" ) ) { |
| 4242 | if( !arg.longName.empty() ) |
| 4243 | throw std::logic_error( "Only one long opt may be specified. '" |
| 4244 | + arg.longName |
| 4245 | + "' already specified, now attempting to add '" |
| 4246 | + optName + "'" ); |
| 4247 | arg.longName = optName.substr( 2 ); |
| 4248 | } |
| 4249 | else if( Detail::startsWith( optName, "-" ) ) |
| 4250 | arg.shortNames.push_back( optName.substr( 1 ) ); |
| 4251 | else |
| 4252 | throw std::logic_error( "option must begin with - or --. Option was: '" + optName + "'" ); |
| 4253 | } |
| 4254 | friend void setPositionalArg( Arg& arg, int position ) |
| 4255 | { |
| 4256 | arg.position = position; |
| 4257 | } |
| 4258 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4259 | class ArgBuilder { |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4260 | public: |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4261 | ArgBuilder( Arg* arg ) : m_arg( arg ) {} |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4262 | |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4263 | // Bind a non-boolean data member (requires placeholder string) |
| 4264 | template<typename C, typename M> |
| 4265 | void bind( M C::* field, std::string const& placeholder ) { |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4266 | m_arg->boundField = new Detail::BoundDataMember<C,M>( field ); |
| 4267 | m_arg->placeholder = placeholder; |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4268 | } |
| 4269 | // Bind a boolean data member (no placeholder required) |
| 4270 | template<typename C> |
| 4271 | void bind( bool C::* field ) { |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4272 | m_arg->boundField = new Detail::BoundDataMember<C,bool>( field ); |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4273 | } |
| 4274 | |
| 4275 | // Bind a method taking a single, non-boolean argument (requires a placeholder string) |
| 4276 | template<typename C, typename M> |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4277 | void bind( void (C::* unaryMethod)( M ), std::string const& placeholder ) { |
| 4278 | m_arg->boundField = new Detail::BoundUnaryMethod<C,M>( unaryMethod ); |
| 4279 | m_arg->placeholder = placeholder; |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4280 | } |
| 4281 | |
| 4282 | // Bind a method taking a single, boolean argument (no placeholder string required) |
| 4283 | template<typename C> |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4284 | void bind( void (C::* unaryMethod)( bool ) ) { |
| 4285 | m_arg->boundField = new Detail::BoundUnaryMethod<C,bool>( unaryMethod ); |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4286 | } |
| 4287 | |
| 4288 | // Bind a method that takes no arguments (will be called if opt is present) |
| 4289 | template<typename C> |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4290 | void bind( void (C::* nullaryMethod)() ) { |
| 4291 | m_arg->boundField = new Detail::BoundNullaryMethod<C>( nullaryMethod ); |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4292 | } |
| 4293 | |
| 4294 | // Bind a free function taking a single argument - the object to operate on (no placeholder string required) |
| 4295 | template<typename C> |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4296 | void bind( void (* unaryFunction)( C& ) ) { |
| 4297 | m_arg->boundField = new Detail::BoundUnaryFunction<C>( unaryFunction ); |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4298 | } |
| 4299 | |
| 4300 | // Bind a free function taking a single argument - the object to operate on (requires a placeholder string) |
| 4301 | template<typename C, typename T> |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4302 | void bind( void (* binaryFunction)( C&, T ), std::string const& placeholder ) { |
| 4303 | m_arg->boundField = new Detail::BoundBinaryFunction<C, T>( binaryFunction ); |
| 4304 | m_arg->placeholder = placeholder; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4305 | } |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4306 | |
| 4307 | ArgBuilder& describe( std::string const& description ) { |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4308 | m_arg->description = description; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4309 | return *this; |
| 4310 | } |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 4311 | ArgBuilder& detail( std::string const& detail ) { |
| 4312 | m_arg->detail = detail; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4313 | return *this; |
| 4314 | } |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4315 | |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4316 | protected: |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4317 | Arg* m_arg; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4318 | }; |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4319 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4320 | class OptBuilder : public ArgBuilder { |
| 4321 | public: |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4322 | OptBuilder( Arg* arg ) : ArgBuilder( arg ) {} |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4323 | OptBuilder( OptBuilder& other ) : ArgBuilder( other ) {} |
| 4324 | |
| 4325 | OptBuilder& operator[]( std::string const& optName ) { |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4326 | addOptName( *ArgBuilder::m_arg, optName ); |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4327 | return *this; |
| 4328 | } |
| 4329 | }; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4330 | |
| 4331 | public: |
| 4332 | |
| 4333 | CommandLine() |
| 4334 | : m_boundProcessName( new Detail::NullBinder<ConfigT>() ), |
Phil Nash | 91ef5f7 | 2013-12-20 19:06:26 +0000 | [diff] [blame] | 4335 | m_highestSpecifiedArgPosition( 0 ), |
| 4336 | m_throwOnUnrecognisedTokens( false ) |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4337 | {} |
| 4338 | CommandLine( CommandLine const& other ) |
| 4339 | : m_boundProcessName( other.m_boundProcessName ), |
| 4340 | m_options ( other.m_options ), |
| 4341 | m_positionalArgs( other.m_positionalArgs ), |
Phil Nash | 91ef5f7 | 2013-12-20 19:06:26 +0000 | [diff] [blame] | 4342 | m_highestSpecifiedArgPosition( other.m_highestSpecifiedArgPosition ), |
| 4343 | m_throwOnUnrecognisedTokens( other.m_throwOnUnrecognisedTokens ) |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4344 | { |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4345 | if( other.m_floatingArg.get() ) |
Phil Nash | 85b4e94 | 2014-10-02 18:51:05 +0100 | [diff] [blame] | 4346 | m_floatingArg.reset( new Arg( *other.m_floatingArg ) ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4347 | } |
| 4348 | |
Phil Nash | 91ef5f7 | 2013-12-20 19:06:26 +0000 | [diff] [blame] | 4349 | CommandLine& setThrowOnUnrecognisedTokens( bool shouldThrow = true ) { |
| 4350 | m_throwOnUnrecognisedTokens = shouldThrow; |
| 4351 | return *this; |
| 4352 | } |
| 4353 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4354 | OptBuilder operator[]( std::string const& optName ) { |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4355 | m_options.push_back( Arg() ); |
| 4356 | addOptName( m_options.back(), optName ); |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4357 | OptBuilder builder( &m_options.back() ); |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4358 | return builder; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4359 | } |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4360 | |
| 4361 | ArgBuilder operator[]( int position ) { |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4362 | m_positionalArgs.insert( std::make_pair( position, Arg() ) ); |
| 4363 | if( position > m_highestSpecifiedArgPosition ) |
| 4364 | m_highestSpecifiedArgPosition = position; |
| 4365 | setPositionalArg( m_positionalArgs[position], position ); |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4366 | ArgBuilder builder( &m_positionalArgs[position] ); |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4367 | return builder; |
| 4368 | } |
| 4369 | |
| 4370 | // Invoke this with the _ instance |
| 4371 | ArgBuilder operator[]( UnpositionalTag ) { |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4372 | if( m_floatingArg.get() ) |
| 4373 | throw std::logic_error( "Only one unpositional argument can be added" ); |
Phil Nash | 85b4e94 | 2014-10-02 18:51:05 +0100 | [diff] [blame] | 4374 | m_floatingArg.reset( new Arg() ); |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4375 | ArgBuilder builder( m_floatingArg.get() ); |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4376 | return builder; |
| 4377 | } |
| 4378 | |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4379 | template<typename C, typename M> |
| 4380 | void bindProcessName( M C::* field ) { |
| 4381 | m_boundProcessName = new Detail::BoundDataMember<C,M>( field ); |
| 4382 | } |
| 4383 | template<typename C, typename M> |
| 4384 | void bindProcessName( void (C::*_unaryMethod)( M ) ) { |
| 4385 | m_boundProcessName = new Detail::BoundUnaryMethod<C,M>( _unaryMethod ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4386 | } |
| 4387 | |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 4388 | void optUsage( std::ostream& os, std::size_t indent = 0, std::size_t width = Detail::consoleWidth ) const { |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4389 | typename std::vector<Arg>::const_iterator itBegin = m_options.begin(), itEnd = m_options.end(), it; |
| 4390 | std::size_t maxWidth = 0; |
| 4391 | for( it = itBegin; it != itEnd; ++it ) |
| 4392 | maxWidth = (std::max)( maxWidth, it->commands().size() ); |
| 4393 | |
| 4394 | for( it = itBegin; it != itEnd; ++it ) { |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 4395 | Detail::Text usage( it->commands(), Detail::TextAttributes() |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4396 | .setWidth( maxWidth+indent ) |
| 4397 | .setIndent( indent ) ); |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 4398 | Detail::Text desc( it->description, Detail::TextAttributes() |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4399 | .setWidth( width - maxWidth - 3 ) ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4400 | |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 4401 | for( std::size_t i = 0; i < (std::max)( usage.size(), desc.size() ); ++i ) { |
| 4402 | std::string usageCol = i < usage.size() ? usage[i] : ""; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4403 | os << usageCol; |
| 4404 | |
| 4405 | if( i < desc.size() && !desc[i].empty() ) |
| 4406 | os << std::string( indent + 2 + maxWidth - usageCol.size(), ' ' ) |
| 4407 | << desc[i]; |
| 4408 | os << "\n"; |
| 4409 | } |
| 4410 | } |
| 4411 | } |
| 4412 | std::string optUsage() const { |
| 4413 | std::ostringstream oss; |
| 4414 | optUsage( oss ); |
| 4415 | return oss.str(); |
| 4416 | } |
| 4417 | |
| 4418 | void argSynopsis( std::ostream& os ) const { |
| 4419 | for( int i = 1; i <= m_highestSpecifiedArgPosition; ++i ) { |
| 4420 | if( i > 1 ) |
| 4421 | os << " "; |
| 4422 | typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( i ); |
| 4423 | if( it != m_positionalArgs.end() ) |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4424 | os << "<" << it->second.placeholder << ">"; |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4425 | else if( m_floatingArg.get() ) |
| 4426 | os << "<" << m_floatingArg->placeholder << ">"; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4427 | else |
| 4428 | throw std::logic_error( "non consecutive positional arguments with no floating args" ); |
| 4429 | } |
| 4430 | // !TBD No indication of mandatory args |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4431 | if( m_floatingArg.get() ) { |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4432 | if( m_highestSpecifiedArgPosition > 1 ) |
| 4433 | os << " "; |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4434 | os << "[<" << m_floatingArg->placeholder << "> ...]"; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4435 | } |
| 4436 | } |
| 4437 | std::string argSynopsis() const { |
| 4438 | std::ostringstream oss; |
| 4439 | argSynopsis( oss ); |
| 4440 | return oss.str(); |
| 4441 | } |
| 4442 | |
| 4443 | void usage( std::ostream& os, std::string const& procName ) const { |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4444 | validate(); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4445 | os << "usage:\n " << procName << " "; |
| 4446 | argSynopsis( os ); |
| 4447 | if( !m_options.empty() ) { |
| 4448 | os << " [options]\n\nwhere options are: \n"; |
| 4449 | optUsage( os, 2 ); |
| 4450 | } |
| 4451 | os << "\n"; |
| 4452 | } |
| 4453 | std::string usage( std::string const& procName ) const { |
| 4454 | std::ostringstream oss; |
| 4455 | usage( oss, procName ); |
| 4456 | return oss.str(); |
| 4457 | } |
| 4458 | |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 4459 | ConfigT parse( int argc, char const* const argv[] ) const { |
Phil Nash | 1f1ee3c | 2014-03-01 10:38:14 +0000 | [diff] [blame] | 4460 | ConfigT config; |
| 4461 | parseInto( argc, argv, config ); |
| 4462 | return config; |
| 4463 | } |
| 4464 | |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 4465 | std::vector<Parser::Token> parseInto( int argc, char const* argv[], ConfigT& config ) const { |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4466 | std::string processName = argv[0]; |
| 4467 | std::size_t lastSlash = processName.find_last_of( "/\\" ); |
| 4468 | if( lastSlash != std::string::npos ) |
| 4469 | processName = processName.substr( lastSlash+1 ); |
| 4470 | m_boundProcessName.set( config, processName ); |
| 4471 | std::vector<Parser::Token> tokens; |
| 4472 | Parser parser; |
| 4473 | parser.parseIntoTokens( argc, argv, tokens ); |
| 4474 | return populate( tokens, config ); |
| 4475 | } |
| 4476 | |
| 4477 | std::vector<Parser::Token> populate( std::vector<Parser::Token> const& tokens, ConfigT& config ) const { |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4478 | validate(); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4479 | std::vector<Parser::Token> unusedTokens = populateOptions( tokens, config ); |
| 4480 | unusedTokens = populateFixedArgs( unusedTokens, config ); |
| 4481 | unusedTokens = populateFloatingArgs( unusedTokens, config ); |
| 4482 | return unusedTokens; |
| 4483 | } |
| 4484 | |
| 4485 | std::vector<Parser::Token> populateOptions( std::vector<Parser::Token> const& tokens, ConfigT& config ) const { |
| 4486 | std::vector<Parser::Token> unusedTokens; |
Phil Nash | 91ef5f7 | 2013-12-20 19:06:26 +0000 | [diff] [blame] | 4487 | std::vector<std::string> errors; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4488 | for( std::size_t i = 0; i < tokens.size(); ++i ) { |
| 4489 | Parser::Token const& token = tokens[i]; |
| 4490 | typename std::vector<Arg>::const_iterator it = m_options.begin(), itEnd = m_options.end(); |
| 4491 | for(; it != itEnd; ++it ) { |
| 4492 | Arg const& arg = *it; |
| 4493 | |
| 4494 | try { |
| 4495 | if( ( token.type == Parser::Token::ShortOpt && arg.hasShortName( token.data ) ) || |
| 4496 | ( token.type == Parser::Token::LongOpt && arg.hasLongName( token.data ) ) ) { |
| 4497 | if( arg.takesArg() ) { |
| 4498 | if( i == tokens.size()-1 || tokens[i+1].type != Parser::Token::Positional ) |
Phil Nash | 91ef5f7 | 2013-12-20 19:06:26 +0000 | [diff] [blame] | 4499 | errors.push_back( "Expected argument to option: " + token.data ); |
| 4500 | else |
| 4501 | arg.boundField.set( config, tokens[++i].data ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4502 | } |
| 4503 | else { |
| 4504 | arg.boundField.setFlag( config ); |
| 4505 | } |
| 4506 | break; |
| 4507 | } |
| 4508 | } |
| 4509 | catch( std::exception& ex ) { |
Phil Nash | 91ef5f7 | 2013-12-20 19:06:26 +0000 | [diff] [blame] | 4510 | errors.push_back( std::string( ex.what() ) + "\n- while parsing: (" + arg.commands() + ")" ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4511 | } |
| 4512 | } |
Phil Nash | 91ef5f7 | 2013-12-20 19:06:26 +0000 | [diff] [blame] | 4513 | if( it == itEnd ) { |
| 4514 | if( token.type == Parser::Token::Positional || !m_throwOnUnrecognisedTokens ) |
| 4515 | unusedTokens.push_back( token ); |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 4516 | else if( errors.empty() && m_throwOnUnrecognisedTokens ) |
Phil Nash | 91ef5f7 | 2013-12-20 19:06:26 +0000 | [diff] [blame] | 4517 | errors.push_back( "unrecognised option: " + token.data ); |
| 4518 | } |
| 4519 | } |
| 4520 | if( !errors.empty() ) { |
| 4521 | std::ostringstream oss; |
| 4522 | for( std::vector<std::string>::const_iterator it = errors.begin(), itEnd = errors.end(); |
| 4523 | it != itEnd; |
| 4524 | ++it ) { |
| 4525 | if( it != errors.begin() ) |
| 4526 | oss << "\n"; |
| 4527 | oss << *it; |
| 4528 | } |
| 4529 | throw std::runtime_error( oss.str() ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4530 | } |
| 4531 | return unusedTokens; |
| 4532 | } |
| 4533 | std::vector<Parser::Token> populateFixedArgs( std::vector<Parser::Token> const& tokens, ConfigT& config ) const { |
| 4534 | std::vector<Parser::Token> unusedTokens; |
| 4535 | int position = 1; |
| 4536 | for( std::size_t i = 0; i < tokens.size(); ++i ) { |
| 4537 | Parser::Token const& token = tokens[i]; |
| 4538 | typename std::map<int, Arg>::const_iterator it = m_positionalArgs.find( position ); |
| 4539 | if( it != m_positionalArgs.end() ) |
| 4540 | it->second.boundField.set( config, token.data ); |
| 4541 | else |
| 4542 | unusedTokens.push_back( token ); |
| 4543 | if( token.type == Parser::Token::Positional ) |
| 4544 | position++; |
| 4545 | } |
| 4546 | return unusedTokens; |
| 4547 | } |
| 4548 | std::vector<Parser::Token> populateFloatingArgs( std::vector<Parser::Token> const& tokens, ConfigT& config ) const { |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4549 | if( !m_floatingArg.get() ) |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4550 | return tokens; |
| 4551 | std::vector<Parser::Token> unusedTokens; |
| 4552 | for( std::size_t i = 0; i < tokens.size(); ++i ) { |
| 4553 | Parser::Token const& token = tokens[i]; |
| 4554 | if( token.type == Parser::Token::Positional ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4555 | m_floatingArg->boundField.set( config, token.data ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4556 | else |
| 4557 | unusedTokens.push_back( token ); |
| 4558 | } |
| 4559 | return unusedTokens; |
| 4560 | } |
| 4561 | |
Phil Nash | af8cd98 | 2014-03-24 18:15:04 +0000 | [diff] [blame] | 4562 | void validate() const |
| 4563 | { |
| 4564 | if( m_options.empty() && m_positionalArgs.empty() && !m_floatingArg.get() ) |
| 4565 | throw std::logic_error( "No options or arguments specified" ); |
| 4566 | |
| 4567 | for( typename std::vector<Arg>::const_iterator it = m_options.begin(), |
| 4568 | itEnd = m_options.end(); |
| 4569 | it != itEnd; ++it ) |
| 4570 | it->validate(); |
| 4571 | } |
| 4572 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4573 | private: |
| 4574 | Detail::BoundArgFunction<ConfigT> m_boundProcessName; |
| 4575 | std::vector<Arg> m_options; |
| 4576 | std::map<int, Arg> m_positionalArgs; |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4577 | ArgAutoPtr m_floatingArg; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4578 | int m_highestSpecifiedArgPosition; |
Phil Nash | 91ef5f7 | 2013-12-20 19:06:26 +0000 | [diff] [blame] | 4579 | bool m_throwOnUnrecognisedTokens; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4580 | }; |
| 4581 | |
| 4582 | } // end namespace Clara |
| 4583 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4584 | STITCH_CLARA_CLOSE_NAMESPACE |
| 4585 | #undef STITCH_CLARA_OPEN_NAMESPACE |
| 4586 | #undef STITCH_CLARA_CLOSE_NAMESPACE |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 4587 | |
Phil Nash | 1f1ee3c | 2014-03-01 10:38:14 +0000 | [diff] [blame] | 4588 | #endif // TWOBLUECUBES_CLARA_H_INCLUDED |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4589 | #undef STITCH_CLARA_OPEN_NAMESPACE |
| 4590 | |
| 4591 | // Restore Clara's value for console width, if present |
| 4592 | #ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH |
| 4593 | #define CLARA_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH |
| 4594 | #undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH |
| 4595 | #endif |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 4596 | |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 4597 | #include <fstream> |
| 4598 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4599 | namespace Catch { |
| 4600 | |
| 4601 | inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; } |
| 4602 | inline void abortAfterX( ConfigData& config, int x ) { |
| 4603 | if( x < 1 ) |
| 4604 | throw std::runtime_error( "Value after -x or --abortAfter must be greater than zero" ); |
| 4605 | config.abortAfter = x; |
| 4606 | } |
| 4607 | inline void addTestOrTags( ConfigData& config, std::string const& _testSpec ) { config.testsOrTags.push_back( _testSpec ); } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 4608 | inline void addReporterName( ConfigData& config, std::string const& _reporterName ) { config.reporterNames.push_back( _reporterName ); } |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4609 | |
| 4610 | inline void addWarning( ConfigData& config, std::string const& _warning ) { |
| 4611 | if( _warning == "NoAssertions" ) |
Phil Nash | ce56209 | 2014-07-09 07:40:37 +0100 | [diff] [blame] | 4612 | config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4613 | else |
| 4614 | throw std::runtime_error( "Unrecognised warning: '" + _warning + "'" ); |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 4615 | } |
| 4616 | inline void setOrder( ConfigData& config, std::string const& order ) { |
| 4617 | if( startsWith( "declared", order ) ) |
| 4618 | config.runOrder = RunTests::InDeclarationOrder; |
| 4619 | else if( startsWith( "lexical", order ) ) |
| 4620 | config.runOrder = RunTests::InLexicographicalOrder; |
| 4621 | else if( startsWith( "random", order ) ) |
| 4622 | config.runOrder = RunTests::InRandomOrder; |
| 4623 | else |
| 4624 | throw std::runtime_error( "Unrecognised ordering: '" + order + "'" ); |
| 4625 | } |
| 4626 | inline void setRngSeed( ConfigData& config, std::string const& seed ) { |
| 4627 | if( seed == "time" ) { |
| 4628 | config.rngSeed = static_cast<unsigned int>( std::time(0) ); |
| 4629 | } |
| 4630 | else { |
| 4631 | std::stringstream ss; |
| 4632 | ss << seed; |
| 4633 | ss >> config.rngSeed; |
| 4634 | if( ss.fail() ) |
| 4635 | throw std::runtime_error( "Argment to --rng-seed should be the word 'time' or a number" ); |
| 4636 | } |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4637 | } |
| 4638 | inline void setVerbosity( ConfigData& config, int level ) { |
| 4639 | // !TBD: accept strings? |
Phil Nash | ce56209 | 2014-07-09 07:40:37 +0100 | [diff] [blame] | 4640 | config.verbosity = static_cast<Verbosity::Level>( level ); |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 4641 | } |
| 4642 | inline void setShowDurations( ConfigData& config, bool _showDurations ) { |
| 4643 | config.showDurations = _showDurations |
| 4644 | ? ShowDurations::Always |
| 4645 | : ShowDurations::Never; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4646 | } |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 4647 | inline void setUseColour( ConfigData& config, std::string const& value ) { |
| 4648 | std::string mode = toLower( value ); |
| 4649 | |
| 4650 | if( mode == "yes" ) |
| 4651 | config.useColour = UseColour::Yes; |
| 4652 | else if( mode == "no" ) |
| 4653 | config.useColour = UseColour::No; |
| 4654 | else if( mode == "auto" ) |
| 4655 | config.useColour = UseColour::Auto; |
| 4656 | else |
| 4657 | throw std::runtime_error( "colour mode must be one of: auto, yes or no" ); |
| 4658 | } |
| 4659 | inline void forceColour( ConfigData& config ) { |
| 4660 | config.useColour = UseColour::Yes; |
| 4661 | } |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 4662 | inline void loadTestNamesFromFile( ConfigData& config, std::string const& _filename ) { |
| 4663 | std::ifstream f( _filename.c_str() ); |
| 4664 | if( !f.is_open() ) |
| 4665 | throw std::domain_error( "Unable to load input file: " + _filename ); |
| 4666 | |
| 4667 | std::string line; |
| 4668 | while( std::getline( f, line ) ) { |
| 4669 | line = trim(line); |
| 4670 | if( !line.empty() && !startsWith( line, "#" ) ) |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 4671 | addTestOrTags( config, "\"" + line + "\"," ); |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 4672 | } |
| 4673 | } |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4674 | |
| 4675 | inline Clara::CommandLine<ConfigData> makeCommandLineParser() { |
| 4676 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4677 | using namespace Clara; |
| 4678 | CommandLine<ConfigData> cli; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4679 | |
| 4680 | cli.bindProcessName( &ConfigData::processName ); |
| 4681 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4682 | cli["-?"]["-h"]["--help"] |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4683 | .describe( "display usage information" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4684 | .bind( &ConfigData::showHelp ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4685 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4686 | cli["-l"]["--list-tests"] |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 4687 | .describe( "list all/matching test cases" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4688 | .bind( &ConfigData::listTests ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4689 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4690 | cli["-t"]["--list-tags"] |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 4691 | .describe( "list all/matching tags" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4692 | .bind( &ConfigData::listTags ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4693 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4694 | cli["-s"]["--success"] |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4695 | .describe( "include successful tests in output" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4696 | .bind( &ConfigData::showSuccessfulTests ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4697 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4698 | cli["-b"]["--break"] |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4699 | .describe( "break into debugger on failure" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4700 | .bind( &ConfigData::shouldDebugBreak ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4701 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4702 | cli["-e"]["--nothrow"] |
Phil Nash | 7d5f271 | 2013-06-07 21:15:25 +0100 | [diff] [blame] | 4703 | .describe( "skip exception tests" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4704 | .bind( &ConfigData::noThrow ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4705 | |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 4706 | cli["-i"]["--invisibles"] |
| 4707 | .describe( "show invisibles (tabs, newlines)" ) |
| 4708 | .bind( &ConfigData::showInvisibles ); |
| 4709 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4710 | cli["-o"]["--out"] |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4711 | .describe( "output filename" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4712 | .bind( &ConfigData::outputFilename, "filename" ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4713 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4714 | cli["-r"]["--reporter"] |
| 4715 | // .placeholder( "name[:filename]" ) |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 4716 | .describe( "reporter to use (defaults to console)" ) |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 4717 | .bind( &addReporterName, "name" ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4718 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4719 | cli["-n"]["--name"] |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4720 | .describe( "suite name" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4721 | .bind( &ConfigData::name, "name" ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4722 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4723 | cli["-a"]["--abort"] |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4724 | .describe( "abort at first failure" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4725 | .bind( &abortAfterFirst ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4726 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4727 | cli["-x"]["--abortx"] |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4728 | .describe( "abort after x failures" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4729 | .bind( &abortAfterX, "no. failures" ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4730 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4731 | cli["-w"]["--warn"] |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4732 | .describe( "enable warnings" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4733 | .bind( &addWarning, "warning name" ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4734 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4735 | // - needs updating if reinstated |
| 4736 | // cli.into( &setVerbosity ) |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4737 | // .describe( "level of verbosity (0=no output)" ) |
| 4738 | // .shortOpt( "v") |
| 4739 | // .longOpt( "verbosity" ) |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4740 | // .placeholder( "level" ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4741 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4742 | cli[_] |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4743 | .describe( "which test or tests to use" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4744 | .bind( &addTestOrTags, "test name, pattern or tags" ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4745 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4746 | cli["-d"]["--durations"] |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 4747 | .describe( "show test durations" ) |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 4748 | .bind( &setShowDurations, "yes|no" ); |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 4749 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4750 | cli["-f"]["--input-file"] |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 4751 | .describe( "load test names to run from a file" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4752 | .bind( &loadTestNamesFromFile, "filename" ); |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 4753 | |
Phil Nash | e6b365d | 2015-07-07 08:25:15 +0100 | [diff] [blame] | 4754 | cli["-#"]["--filenames-as-tags"] |
| 4755 | .describe( "adds a tag for the filename" ) |
| 4756 | .bind( &ConfigData::filenamesAsTags ); |
| 4757 | |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 4758 | // Less common commands which don't have a short form |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4759 | cli["--list-test-names-only"] |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 4760 | .describe( "list all/matching test cases names only" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4761 | .bind( &ConfigData::listTestNamesOnly ); |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 4762 | |
Phil Nash | b9fea75 | 2014-03-06 08:16:06 +0000 | [diff] [blame] | 4763 | cli["--list-reporters"] |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 4764 | .describe( "list all reporters" ) |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4765 | .bind( &ConfigData::listReporters ); |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 4766 | |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 4767 | cli["--order"] |
| 4768 | .describe( "test case order (defaults to decl)" ) |
| 4769 | .bind( &setOrder, "decl|lex|rand" ); |
| 4770 | |
| 4771 | cli["--rng-seed"] |
| 4772 | .describe( "set a specific seed for random numbers" ) |
| 4773 | .bind( &setRngSeed, "'time'|number" ); |
| 4774 | |
Phil Nash | a806c3e | 2015-03-04 08:23:40 +0000 | [diff] [blame] | 4775 | cli["--force-colour"] |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 4776 | .describe( "force colourised output (deprecated)" ) |
| 4777 | .bind( &forceColour ); |
| 4778 | |
| 4779 | cli["--use-colour"] |
| 4780 | .describe( "should output be colourised" ) |
| 4781 | .bind( &setUseColour, "yes|no" ); |
Phil Nash | a806c3e | 2015-03-04 08:23:40 +0000 | [diff] [blame] | 4782 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 4783 | return cli; |
| 4784 | } |
| 4785 | |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 4786 | } // end namespace Catch |
| 4787 | |
| 4788 | // #included from: internal/catch_list.hpp |
| 4789 | #define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED |
| 4790 | |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 4791 | // #included from: catch_text.h |
| 4792 | #define TWOBLUECUBES_CATCH_TEXT_H_INCLUDED |
| 4793 | |
| 4794 | #define TBC_TEXT_FORMAT_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH |
| 4795 | |
| 4796 | #define CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE Catch |
Phil Nash | 472dc2a | 2014-03-17 18:40:58 +0000 | [diff] [blame] | 4797 | // #included from: ../external/tbc_text_format.h |
Phil Nash | 1c2fbe1 | 2014-02-11 18:12:41 +0000 | [diff] [blame] | 4798 | // Only use header guard if we are not using an outer namespace |
| 4799 | #ifndef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE |
| 4800 | # ifdef TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED |
| 4801 | # ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED |
| 4802 | # define TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED |
| 4803 | # endif |
| 4804 | # else |
| 4805 | # define TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED |
| 4806 | # endif |
| 4807 | #endif |
| 4808 | #ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED |
| 4809 | #include <string> |
| 4810 | #include <vector> |
| 4811 | #include <sstream> |
| 4812 | |
| 4813 | // Use optional outer namespace |
| 4814 | #ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE |
| 4815 | namespace CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE { |
| 4816 | #endif |
| 4817 | |
| 4818 | namespace Tbc { |
| 4819 | |
| 4820 | #ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH |
| 4821 | const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH; |
| 4822 | #else |
| 4823 | const unsigned int consoleWidth = 80; |
| 4824 | #endif |
| 4825 | |
| 4826 | struct TextAttributes { |
| 4827 | TextAttributes() |
| 4828 | : initialIndent( std::string::npos ), |
| 4829 | indent( 0 ), |
| 4830 | width( consoleWidth-1 ), |
| 4831 | tabChar( '\t' ) |
| 4832 | {} |
| 4833 | |
| 4834 | TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; } |
| 4835 | TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; } |
| 4836 | TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; } |
| 4837 | TextAttributes& setTabChar( char _value ) { tabChar = _value; return *this; } |
| 4838 | |
| 4839 | std::size_t initialIndent; // indent of first line, or npos |
| 4840 | std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos |
| 4841 | std::size_t width; // maximum width of text, including indent. Longer text will wrap |
| 4842 | char tabChar; // If this char is seen the indent is changed to current pos |
| 4843 | }; |
| 4844 | |
| 4845 | class Text { |
| 4846 | public: |
| 4847 | Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() ) |
| 4848 | : attr( _attr ) |
| 4849 | { |
| 4850 | std::string wrappableChars = " [({.,/|\\-"; |
| 4851 | std::size_t indent = _attr.initialIndent != std::string::npos |
| 4852 | ? _attr.initialIndent |
| 4853 | : _attr.indent; |
| 4854 | std::string remainder = _str; |
| 4855 | |
| 4856 | while( !remainder.empty() ) { |
| 4857 | if( lines.size() >= 1000 ) { |
| 4858 | lines.push_back( "... message truncated due to excessive size" ); |
| 4859 | return; |
| 4860 | } |
| 4861 | std::size_t tabPos = std::string::npos; |
| 4862 | std::size_t width = (std::min)( remainder.size(), _attr.width - indent ); |
| 4863 | std::size_t pos = remainder.find_first_of( '\n' ); |
| 4864 | if( pos <= width ) { |
| 4865 | width = pos; |
| 4866 | } |
| 4867 | pos = remainder.find_last_of( _attr.tabChar, width ); |
| 4868 | if( pos != std::string::npos ) { |
| 4869 | tabPos = pos; |
| 4870 | if( remainder[width] == '\n' ) |
| 4871 | width--; |
| 4872 | remainder = remainder.substr( 0, tabPos ) + remainder.substr( tabPos+1 ); |
| 4873 | } |
| 4874 | |
| 4875 | if( width == remainder.size() ) { |
| 4876 | spliceLine( indent, remainder, width ); |
| 4877 | } |
| 4878 | else if( remainder[width] == '\n' ) { |
| 4879 | spliceLine( indent, remainder, width ); |
| 4880 | if( width <= 1 || remainder.size() != 1 ) |
| 4881 | remainder = remainder.substr( 1 ); |
| 4882 | indent = _attr.indent; |
| 4883 | } |
| 4884 | else { |
| 4885 | pos = remainder.find_last_of( wrappableChars, width ); |
| 4886 | if( pos != std::string::npos && pos > 0 ) { |
| 4887 | spliceLine( indent, remainder, pos ); |
| 4888 | if( remainder[0] == ' ' ) |
| 4889 | remainder = remainder.substr( 1 ); |
| 4890 | } |
| 4891 | else { |
| 4892 | spliceLine( indent, remainder, width-1 ); |
| 4893 | lines.back() += "-"; |
| 4894 | } |
| 4895 | if( lines.size() == 1 ) |
| 4896 | indent = _attr.indent; |
| 4897 | if( tabPos != std::string::npos ) |
| 4898 | indent += tabPos; |
| 4899 | } |
| 4900 | } |
| 4901 | } |
| 4902 | |
| 4903 | void spliceLine( std::size_t _indent, std::string& _remainder, std::size_t _pos ) { |
| 4904 | lines.push_back( std::string( _indent, ' ' ) + _remainder.substr( 0, _pos ) ); |
| 4905 | _remainder = _remainder.substr( _pos ); |
| 4906 | } |
| 4907 | |
| 4908 | typedef std::vector<std::string>::const_iterator const_iterator; |
| 4909 | |
| 4910 | const_iterator begin() const { return lines.begin(); } |
| 4911 | const_iterator end() const { return lines.end(); } |
| 4912 | std::string const& last() const { return lines.back(); } |
| 4913 | std::size_t size() const { return lines.size(); } |
| 4914 | std::string const& operator[]( std::size_t _index ) const { return lines[_index]; } |
| 4915 | std::string toString() const { |
| 4916 | std::ostringstream oss; |
| 4917 | oss << *this; |
| 4918 | return oss.str(); |
| 4919 | } |
| 4920 | |
| 4921 | inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) { |
| 4922 | for( Text::const_iterator it = _text.begin(), itEnd = _text.end(); |
| 4923 | it != itEnd; ++it ) { |
| 4924 | if( it != _text.begin() ) |
| 4925 | _stream << "\n"; |
| 4926 | _stream << *it; |
| 4927 | } |
| 4928 | return _stream; |
| 4929 | } |
| 4930 | |
| 4931 | private: |
| 4932 | std::string str; |
| 4933 | TextAttributes attr; |
| 4934 | std::vector<std::string> lines; |
| 4935 | }; |
| 4936 | |
| 4937 | } // end namespace Tbc |
| 4938 | |
| 4939 | #ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE |
| 4940 | } // end outer namespace |
| 4941 | #endif |
| 4942 | |
| 4943 | #endif // TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED |
| 4944 | #undef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE |
| 4945 | |
| 4946 | namespace Catch { |
| 4947 | using Tbc::Text; |
| 4948 | using Tbc::TextAttributes; |
| 4949 | } |
| 4950 | |
Phil Nash | 5c7d3d7 | 2013-04-01 11:27:10 +0100 | [diff] [blame] | 4951 | // #included from: catch_console_colour.hpp |
| 4952 | #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_HPP_INCLUDED |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 4953 | |
| 4954 | namespace Catch { |
Phil Nash | 5c7d3d7 | 2013-04-01 11:27:10 +0100 | [diff] [blame] | 4955 | |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 4956 | struct Colour { |
| 4957 | enum Code { |
| 4958 | None = 0, |
Phil Nash | 5c7d3d7 | 2013-04-01 11:27:10 +0100 | [diff] [blame] | 4959 | |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 4960 | White, |
| 4961 | Red, |
| 4962 | Green, |
| 4963 | Blue, |
| 4964 | Cyan, |
| 4965 | Yellow, |
| 4966 | Grey, |
Phil Nash | 5c7d3d7 | 2013-04-01 11:27:10 +0100 | [diff] [blame] | 4967 | |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 4968 | Bright = 0x10, |
Phil Nash | 5c7d3d7 | 2013-04-01 11:27:10 +0100 | [diff] [blame] | 4969 | |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 4970 | BrightRed = Bright | Red, |
| 4971 | BrightGreen = Bright | Green, |
| 4972 | LightGrey = Bright | Grey, |
| 4973 | BrightWhite = Bright | White, |
| 4974 | |
| 4975 | // By intention |
| 4976 | FileName = LightGrey, |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 4977 | Warning = Yellow, |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 4978 | ResultError = BrightRed, |
| 4979 | ResultSuccess = BrightGreen, |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 4980 | ResultExpectedFailure = Warning, |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 4981 | |
| 4982 | Error = BrightRed, |
| 4983 | Success = Green, |
| 4984 | |
| 4985 | OriginalExpression = Cyan, |
| 4986 | ReconstructedExpression = Yellow, |
| 4987 | |
| 4988 | SecondaryText = LightGrey, |
| 4989 | Headers = White |
Phil Nash | 5c7d3d7 | 2013-04-01 11:27:10 +0100 | [diff] [blame] | 4990 | }; |
| 4991 | |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 4992 | // Use constructed object for RAII guard |
| 4993 | Colour( Code _colourCode ); |
Phil Nash | ce56209 | 2014-07-09 07:40:37 +0100 | [diff] [blame] | 4994 | Colour( Colour const& other ); |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 4995 | ~Colour(); |
Phil Nash | 5c7d3d7 | 2013-04-01 11:27:10 +0100 | [diff] [blame] | 4996 | |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 4997 | // Use static method for one-shot changes |
| 4998 | static void use( Code _colourCode ); |
Phil Nash | 5c7d3d7 | 2013-04-01 11:27:10 +0100 | [diff] [blame] | 4999 | |
| 5000 | private: |
Phil Nash | ce56209 | 2014-07-09 07:40:37 +0100 | [diff] [blame] | 5001 | bool m_moved; |
Phil Nash | 5c7d3d7 | 2013-04-01 11:27:10 +0100 | [diff] [blame] | 5002 | }; |
| 5003 | |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 5004 | inline std::ostream& operator << ( std::ostream& os, Colour const& ) { return os; } |
| 5005 | |
Phil Nash | 5c7d3d7 | 2013-04-01 11:27:10 +0100 | [diff] [blame] | 5006 | } // end namespace Catch |
| 5007 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5008 | // #included from: catch_interfaces_reporter.h |
| 5009 | #define TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED |
| 5010 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5011 | #include <string> |
| 5012 | #include <ostream> |
| 5013 | #include <map> |
| 5014 | #include <assert.h> |
| 5015 | |
| 5016 | namespace Catch |
| 5017 | { |
| 5018 | struct ReporterConfig { |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5019 | explicit ReporterConfig( Ptr<IConfig const> const& _fullConfig ) |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5020 | : m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {} |
| 5021 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5022 | ReporterConfig( Ptr<IConfig const> const& _fullConfig, std::ostream& _stream ) |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5023 | : m_stream( &_stream ), m_fullConfig( _fullConfig ) {} |
| 5024 | |
| 5025 | std::ostream& stream() const { return *m_stream; } |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5026 | Ptr<IConfig const> fullConfig() const { return m_fullConfig; } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5027 | |
| 5028 | private: |
| 5029 | std::ostream* m_stream; |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5030 | Ptr<IConfig const> m_fullConfig; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5031 | }; |
| 5032 | |
| 5033 | struct ReporterPreferences { |
| 5034 | ReporterPreferences() |
| 5035 | : shouldRedirectStdOut( false ) |
| 5036 | {} |
| 5037 | |
| 5038 | bool shouldRedirectStdOut; |
| 5039 | }; |
| 5040 | |
| 5041 | template<typename T> |
| 5042 | struct LazyStat : Option<T> { |
| 5043 | LazyStat() : used( false ) {} |
| 5044 | LazyStat& operator=( T const& _value ) { |
| 5045 | Option<T>::operator=( _value ); |
| 5046 | used = false; |
| 5047 | return *this; |
| 5048 | } |
| 5049 | void reset() { |
| 5050 | Option<T>::reset(); |
| 5051 | used = false; |
| 5052 | } |
| 5053 | bool used; |
| 5054 | }; |
| 5055 | |
| 5056 | struct TestRunInfo { |
| 5057 | TestRunInfo( std::string const& _name ) : name( _name ) {} |
| 5058 | std::string name; |
| 5059 | }; |
| 5060 | struct GroupInfo { |
| 5061 | GroupInfo( std::string const& _name, |
| 5062 | std::size_t _groupIndex, |
| 5063 | std::size_t _groupsCount ) |
| 5064 | : name( _name ), |
| 5065 | groupIndex( _groupIndex ), |
| 5066 | groupsCounts( _groupsCount ) |
| 5067 | {} |
| 5068 | |
| 5069 | std::string name; |
| 5070 | std::size_t groupIndex; |
| 5071 | std::size_t groupsCounts; |
| 5072 | }; |
| 5073 | |
| 5074 | struct AssertionStats { |
| 5075 | AssertionStats( AssertionResult const& _assertionResult, |
| 5076 | std::vector<MessageInfo> const& _infoMessages, |
| 5077 | Totals const& _totals ) |
| 5078 | : assertionResult( _assertionResult ), |
| 5079 | infoMessages( _infoMessages ), |
| 5080 | totals( _totals ) |
| 5081 | { |
| 5082 | if( assertionResult.hasMessage() ) { |
| 5083 | // Copy message into messages list. |
| 5084 | // !TBD This should have been done earlier, somewhere |
| 5085 | MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() ); |
| 5086 | builder << assertionResult.getMessage(); |
| 5087 | builder.m_info.message = builder.m_stream.str(); |
| 5088 | |
| 5089 | infoMessages.push_back( builder.m_info ); |
| 5090 | } |
| 5091 | } |
| 5092 | virtual ~AssertionStats(); |
| 5093 | |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 5094 | # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 5095 | AssertionStats( AssertionStats const& ) = default; |
| 5096 | AssertionStats( AssertionStats && ) = default; |
| 5097 | AssertionStats& operator = ( AssertionStats const& ) = default; |
| 5098 | AssertionStats& operator = ( AssertionStats && ) = default; |
| 5099 | # endif |
| 5100 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5101 | AssertionResult assertionResult; |
| 5102 | std::vector<MessageInfo> infoMessages; |
| 5103 | Totals totals; |
| 5104 | }; |
| 5105 | |
| 5106 | struct SectionStats { |
| 5107 | SectionStats( SectionInfo const& _sectionInfo, |
| 5108 | Counts const& _assertions, |
| 5109 | double _durationInSeconds, |
| 5110 | bool _missingAssertions ) |
| 5111 | : sectionInfo( _sectionInfo ), |
| 5112 | assertions( _assertions ), |
| 5113 | durationInSeconds( _durationInSeconds ), |
| 5114 | missingAssertions( _missingAssertions ) |
| 5115 | {} |
| 5116 | virtual ~SectionStats(); |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 5117 | # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 5118 | SectionStats( SectionStats const& ) = default; |
| 5119 | SectionStats( SectionStats && ) = default; |
| 5120 | SectionStats& operator = ( SectionStats const& ) = default; |
| 5121 | SectionStats& operator = ( SectionStats && ) = default; |
| 5122 | # endif |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5123 | |
| 5124 | SectionInfo sectionInfo; |
| 5125 | Counts assertions; |
| 5126 | double durationInSeconds; |
| 5127 | bool missingAssertions; |
| 5128 | }; |
| 5129 | |
| 5130 | struct TestCaseStats { |
| 5131 | TestCaseStats( TestCaseInfo const& _testInfo, |
| 5132 | Totals const& _totals, |
| 5133 | std::string const& _stdOut, |
| 5134 | std::string const& _stdErr, |
| 5135 | bool _aborting ) |
| 5136 | : testInfo( _testInfo ), |
| 5137 | totals( _totals ), |
| 5138 | stdOut( _stdOut ), |
| 5139 | stdErr( _stdErr ), |
| 5140 | aborting( _aborting ) |
| 5141 | {} |
| 5142 | virtual ~TestCaseStats(); |
| 5143 | |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 5144 | # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 5145 | TestCaseStats( TestCaseStats const& ) = default; |
| 5146 | TestCaseStats( TestCaseStats && ) = default; |
| 5147 | TestCaseStats& operator = ( TestCaseStats const& ) = default; |
| 5148 | TestCaseStats& operator = ( TestCaseStats && ) = default; |
| 5149 | # endif |
| 5150 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5151 | TestCaseInfo testInfo; |
| 5152 | Totals totals; |
| 5153 | std::string stdOut; |
| 5154 | std::string stdErr; |
| 5155 | bool aborting; |
| 5156 | }; |
| 5157 | |
| 5158 | struct TestGroupStats { |
| 5159 | TestGroupStats( GroupInfo const& _groupInfo, |
| 5160 | Totals const& _totals, |
| 5161 | bool _aborting ) |
| 5162 | : groupInfo( _groupInfo ), |
| 5163 | totals( _totals ), |
| 5164 | aborting( _aborting ) |
| 5165 | {} |
| 5166 | TestGroupStats( GroupInfo const& _groupInfo ) |
| 5167 | : groupInfo( _groupInfo ), |
| 5168 | aborting( false ) |
| 5169 | {} |
| 5170 | virtual ~TestGroupStats(); |
| 5171 | |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 5172 | # ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 5173 | TestGroupStats( TestGroupStats const& ) = default; |
| 5174 | TestGroupStats( TestGroupStats && ) = default; |
| 5175 | TestGroupStats& operator = ( TestGroupStats const& ) = default; |
| 5176 | TestGroupStats& operator = ( TestGroupStats && ) = default; |
| 5177 | # endif |
| 5178 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5179 | GroupInfo groupInfo; |
| 5180 | Totals totals; |
| 5181 | bool aborting; |
| 5182 | }; |
| 5183 | |
| 5184 | struct TestRunStats { |
| 5185 | TestRunStats( TestRunInfo const& _runInfo, |
| 5186 | Totals const& _totals, |
| 5187 | bool _aborting ) |
| 5188 | : runInfo( _runInfo ), |
| 5189 | totals( _totals ), |
| 5190 | aborting( _aborting ) |
| 5191 | {} |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 5192 | virtual ~TestRunStats(); |
| 5193 | |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 5194 | # ifndef CATCH_CONFIG_CPP11_GENERATED_METHODS |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5195 | TestRunStats( TestRunStats const& _other ) |
| 5196 | : runInfo( _other.runInfo ), |
| 5197 | totals( _other.totals ), |
| 5198 | aborting( _other.aborting ) |
| 5199 | {} |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 5200 | # else |
| 5201 | TestRunStats( TestRunStats const& ) = default; |
| 5202 | TestRunStats( TestRunStats && ) = default; |
| 5203 | TestRunStats& operator = ( TestRunStats const& ) = default; |
| 5204 | TestRunStats& operator = ( TestRunStats && ) = default; |
| 5205 | # endif |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5206 | |
| 5207 | TestRunInfo runInfo; |
| 5208 | Totals totals; |
| 5209 | bool aborting; |
| 5210 | }; |
| 5211 | |
| 5212 | struct IStreamingReporter : IShared { |
| 5213 | virtual ~IStreamingReporter(); |
| 5214 | |
| 5215 | // Implementing class must also provide the following static method: |
| 5216 | // static std::string getDescription(); |
| 5217 | |
| 5218 | virtual ReporterPreferences getPreferences() const = 0; |
| 5219 | |
| 5220 | virtual void noMatchingTestCases( std::string const& spec ) = 0; |
| 5221 | |
| 5222 | virtual void testRunStarting( TestRunInfo const& testRunInfo ) = 0; |
| 5223 | virtual void testGroupStarting( GroupInfo const& groupInfo ) = 0; |
| 5224 | |
| 5225 | virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0; |
| 5226 | virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0; |
| 5227 | |
| 5228 | virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0; |
| 5229 | |
Phil Nash | 576aff6 | 2014-12-21 00:21:23 +0000 | [diff] [blame] | 5230 | // The return value indicates if the messages buffer should be cleared: |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5231 | virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0; |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 5232 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5233 | virtual void sectionEnded( SectionStats const& sectionStats ) = 0; |
| 5234 | virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0; |
| 5235 | virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0; |
| 5236 | virtual void testRunEnded( TestRunStats const& testRunStats ) = 0; |
Phil Nash | 92f0836 | 2014-12-22 20:18:05 +0000 | [diff] [blame] | 5237 | |
| 5238 | virtual void skipTest( TestCaseInfo const& testInfo ) = 0; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5239 | }; |
| 5240 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 5241 | struct IReporterFactory : IShared { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5242 | virtual ~IReporterFactory(); |
| 5243 | virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0; |
| 5244 | virtual std::string getDescription() const = 0; |
| 5245 | }; |
| 5246 | |
| 5247 | struct IReporterRegistry { |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 5248 | typedef std::map<std::string, Ptr<IReporterFactory> > FactoryMap; |
| 5249 | typedef std::vector<Ptr<IReporterFactory> > Listeners; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5250 | |
| 5251 | virtual ~IReporterRegistry(); |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5252 | virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const = 0; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5253 | virtual FactoryMap const& getFactories() const = 0; |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 5254 | virtual Listeners const& getListeners() const = 0; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5255 | }; |
| 5256 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 5257 | Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter ); |
| 5258 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 5259 | } |
| 5260 | |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5261 | #include <limits> |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5262 | #include <algorithm> |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5263 | |
| 5264 | namespace Catch { |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5265 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5266 | inline std::size_t listTests( Config const& config ) { |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 5267 | |
| 5268 | TestSpec testSpec = config.testSpec(); |
| 5269 | if( config.testSpec().hasFilters() ) |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 5270 | Catch::cout() << "Matching test cases:\n"; |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 5271 | else { |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 5272 | Catch::cout() << "All available test cases:\n"; |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 5273 | testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 5274 | } |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5275 | |
| 5276 | std::size_t matchedTests = 0; |
Phil Nash | 8d44f2d | 2013-11-13 08:10:45 +0000 | [diff] [blame] | 5277 | TextAttributes nameAttr, tagsAttr; |
| 5278 | nameAttr.setInitialIndent( 2 ).setIndent( 4 ); |
| 5279 | tagsAttr.setIndent( 6 ); |
| 5280 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 5281 | std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 5282 | for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); |
Phil Nash | 8d44f2d | 2013-11-13 08:10:45 +0000 | [diff] [blame] | 5283 | it != itEnd; |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 5284 | ++it ) { |
| 5285 | matchedTests++; |
| 5286 | TestCaseInfo const& testCaseInfo = it->getTestCaseInfo(); |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 5287 | Colour::Code colour = testCaseInfo.isHidden() |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 5288 | ? Colour::SecondaryText |
| 5289 | : Colour::None; |
| 5290 | Colour colourGuard( colour ); |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5291 | |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 5292 | Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl; |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 5293 | if( !testCaseInfo.tags.empty() ) |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 5294 | Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl; |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 5295 | } |
Phil Nash | 8d44f2d | 2013-11-13 08:10:45 +0000 | [diff] [blame] | 5296 | |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 5297 | if( !config.testSpec().hasFilters() ) |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 5298 | Catch::cout() << pluralise( matchedTests, "test case" ) << "\n" << std::endl; |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5299 | else |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 5300 | Catch::cout() << pluralise( matchedTests, "matching test case" ) << "\n" << std::endl; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5301 | return matchedTests; |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5302 | } |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5303 | |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 5304 | inline std::size_t listTestsNamesOnly( Config const& config ) { |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 5305 | TestSpec testSpec = config.testSpec(); |
| 5306 | if( !config.testSpec().hasFilters() ) |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 5307 | testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 5308 | std::size_t matchedTests = 0; |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 5309 | std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 5310 | for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 5311 | it != itEnd; |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 5312 | ++it ) { |
| 5313 | matchedTests++; |
| 5314 | TestCaseInfo const& testCaseInfo = it->getTestCaseInfo(); |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 5315 | Catch::cout() << testCaseInfo.name << std::endl; |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 5316 | } |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 5317 | return matchedTests; |
| 5318 | } |
| 5319 | |
Phil Nash | 48fac9c | 2014-05-20 19:02:37 +0100 | [diff] [blame] | 5320 | struct TagInfo { |
| 5321 | TagInfo() : count ( 0 ) {} |
| 5322 | void add( std::string const& spelling ) { |
| 5323 | ++count; |
| 5324 | spellings.insert( spelling ); |
| 5325 | } |
| 5326 | std::string all() const { |
| 5327 | std::string out; |
| 5328 | for( std::set<std::string>::const_iterator it = spellings.begin(), itEnd = spellings.end(); |
| 5329 | it != itEnd; |
| 5330 | ++it ) |
| 5331 | out += "[" + *it + "]"; |
| 5332 | return out; |
| 5333 | } |
| 5334 | std::set<std::string> spellings; |
| 5335 | std::size_t count; |
| 5336 | }; |
| 5337 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5338 | inline std::size_t listTags( Config const& config ) { |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 5339 | TestSpec testSpec = config.testSpec(); |
| 5340 | if( config.testSpec().hasFilters() ) |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 5341 | Catch::cout() << "Tags for matching test cases:\n"; |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 5342 | else { |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 5343 | Catch::cout() << "All available tags:\n"; |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 5344 | testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec(); |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 5345 | } |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5346 | |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 5347 | std::map<std::string, TagInfo> tagCounts; |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5348 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 5349 | std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config ); |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 5350 | for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end(); |
Phil Nash | 8d44f2d | 2013-11-13 08:10:45 +0000 | [diff] [blame] | 5351 | it != itEnd; |
| 5352 | ++it ) { |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 5353 | for( std::set<std::string>::const_iterator tagIt = it->getTestCaseInfo().tags.begin(), |
| 5354 | tagItEnd = it->getTestCaseInfo().tags.end(); |
| 5355 | tagIt != tagItEnd; |
| 5356 | ++tagIt ) { |
| 5357 | std::string tagName = *tagIt; |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 5358 | std::string lcaseTagName = toLower( tagName ); |
| 5359 | std::map<std::string, TagInfo>::iterator countIt = tagCounts.find( lcaseTagName ); |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 5360 | if( countIt == tagCounts.end() ) |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 5361 | countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first; |
| 5362 | countIt->second.add( tagName ); |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5363 | } |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5364 | } |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5365 | |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 5366 | for( std::map<std::string, TagInfo>::const_iterator countIt = tagCounts.begin(), |
| 5367 | countItEnd = tagCounts.end(); |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5368 | countIt != countItEnd; |
| 5369 | ++countIt ) { |
Phil Nash | 8d44f2d | 2013-11-13 08:10:45 +0000 | [diff] [blame] | 5370 | std::ostringstream oss; |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 5371 | oss << " " << std::setw(2) << countIt->second.count << " "; |
| 5372 | Text wrapper( countIt->second.all(), TextAttributes() |
| 5373 | .setInitialIndent( 0 ) |
| 5374 | .setIndent( oss.str().size() ) |
| 5375 | .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) ); |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 5376 | Catch::cout() << oss.str() << wrapper << "\n"; |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5377 | } |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 5378 | Catch::cout() << pluralise( tagCounts.size(), "tag" ) << "\n" << std::endl; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5379 | return tagCounts.size(); |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5380 | } |
| 5381 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5382 | inline std::size_t listReporters( Config const& /*config*/ ) { |
Phil Nash | 576aff6 | 2014-12-21 00:21:23 +0000 | [diff] [blame] | 5383 | Catch::cout() << "Available reporters:\n"; |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5384 | IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5385 | IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it; |
| 5386 | std::size_t maxNameLen = 0; |
| 5387 | for(it = itBegin; it != itEnd; ++it ) |
| 5388 | maxNameLen = (std::max)( maxNameLen, it->first.size() ); |
| 5389 | |
| 5390 | for(it = itBegin; it != itEnd; ++it ) { |
| 5391 | Text wrapper( it->second->getDescription(), TextAttributes() |
| 5392 | .setInitialIndent( 0 ) |
| 5393 | .setIndent( 7+maxNameLen ) |
| 5394 | .setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) ); |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 5395 | Catch::cout() << " " |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5396 | << it->first |
| 5397 | << ":" |
| 5398 | << std::string( maxNameLen - it->first.size() + 2, ' ' ) |
| 5399 | << wrapper << "\n"; |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5400 | } |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 5401 | Catch::cout() << std::endl; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5402 | return factories.size(); |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 5403 | } |
| 5404 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5405 | inline Option<std::size_t> list( Config const& config ) { |
| 5406 | Option<std::size_t> listedCount; |
| 5407 | if( config.listTests() ) |
| 5408 | listedCount = listedCount.valueOr(0) + listTests( config ); |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 5409 | if( config.listTestNamesOnly() ) |
| 5410 | listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5411 | if( config.listTags() ) |
| 5412 | listedCount = listedCount.valueOr(0) + listTags( config ); |
| 5413 | if( config.listReporters() ) |
| 5414 | listedCount = listedCount.valueOr(0) + listReporters( config ); |
| 5415 | return listedCount; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5416 | } |
| 5417 | |
| 5418 | } // end namespace Catch |
| 5419 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 5420 | // #included from: internal/catch_run_context.hpp |
Matt Wozniski | f29c898 | 2012-09-17 01:42:29 -0400 | [diff] [blame] | 5421 | #define TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5422 | |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 5423 | // #included from: catch_test_case_tracker.hpp |
| 5424 | #define TWOBLUECUBES_CATCH_TEST_CASE_TRACKER_HPP_INCLUDED |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5425 | |
| 5426 | #include <map> |
| 5427 | #include <string> |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 5428 | #include <assert.h> |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5429 | #include <vector> |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5430 | |
| 5431 | namespace Catch { |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5432 | namespace TestCaseTracking { |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5433 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5434 | struct ITracker : SharedImpl<> { |
| 5435 | virtual ~ITracker(); |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 5436 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5437 | // static queries |
| 5438 | virtual std::string name() const = 0; |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 5439 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5440 | // dynamic queries |
| 5441 | virtual bool isComplete() const = 0; // Successfully completed or failed |
| 5442 | virtual bool isSuccessfullyCompleted() const = 0; |
| 5443 | virtual bool isOpen() const = 0; // Started but not complete |
| 5444 | virtual bool hasChildren() const = 0; |
| 5445 | |
| 5446 | virtual ITracker& parent() = 0; |
| 5447 | |
| 5448 | // actions |
| 5449 | virtual void close() = 0; // Successfully complete |
| 5450 | virtual void fail() = 0; |
| 5451 | virtual void markAsNeedingAnotherRun() = 0; |
| 5452 | |
| 5453 | virtual void addChild( Ptr<ITracker> const& child ) = 0; |
| 5454 | virtual ITracker* findChild( std::string const& name ) = 0; |
| 5455 | virtual void openChild() = 0; |
| 5456 | }; |
| 5457 | |
| 5458 | class TrackerContext { |
| 5459 | |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 5460 | enum RunState { |
| 5461 | NotStarted, |
| 5462 | Executing, |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5463 | CompletedCycle |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5464 | }; |
| 5465 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5466 | Ptr<ITracker> m_rootTracker; |
| 5467 | ITracker* m_currentTracker; |
| 5468 | RunState m_runState; |
| 5469 | |
| 5470 | public: |
| 5471 | |
| 5472 | static TrackerContext& instance() { |
| 5473 | static TrackerContext s_instance; |
| 5474 | return s_instance; |
| 5475 | } |
| 5476 | |
| 5477 | TrackerContext() |
| 5478 | : m_currentTracker( CATCH_NULL ), |
| 5479 | m_runState( NotStarted ) |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5480 | {} |
| 5481 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5482 | ITracker& startRun(); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5483 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5484 | void endRun() { |
| 5485 | m_rootTracker.reset(); |
| 5486 | m_currentTracker = CATCH_NULL; |
| 5487 | m_runState = NotStarted; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5488 | } |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 5489 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5490 | void startCycle() { |
| 5491 | m_currentTracker = m_rootTracker.get(); |
| 5492 | m_runState = Executing; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5493 | } |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5494 | void completeCycle() { |
| 5495 | m_runState = CompletedCycle; |
| 5496 | } |
| 5497 | |
| 5498 | bool completedCycle() const { |
| 5499 | return m_runState == CompletedCycle; |
| 5500 | } |
| 5501 | ITracker& currentTracker() { |
| 5502 | return *m_currentTracker; |
| 5503 | } |
| 5504 | void setCurrentTracker( ITracker* tracker ) { |
| 5505 | m_currentTracker = tracker; |
| 5506 | } |
| 5507 | }; |
| 5508 | |
| 5509 | class TrackerBase : public ITracker { |
| 5510 | protected: |
| 5511 | enum CycleState { |
| 5512 | NotStarted, |
| 5513 | Executing, |
| 5514 | ExecutingChildren, |
| 5515 | NeedsAnotherRun, |
| 5516 | CompletedSuccessfully, |
| 5517 | Failed |
| 5518 | }; |
| 5519 | class TrackerHasName { |
| 5520 | std::string m_name; |
| 5521 | public: |
| 5522 | TrackerHasName( std::string const& name ) : m_name( name ) {} |
| 5523 | bool operator ()( Ptr<ITracker> const& tracker ) { |
| 5524 | return tracker->name() == m_name; |
| 5525 | } |
| 5526 | }; |
| 5527 | typedef std::vector<Ptr<ITracker> > Children; |
| 5528 | std::string m_name; |
| 5529 | TrackerContext& m_ctx; |
| 5530 | ITracker* m_parent; |
| 5531 | Children m_children; |
| 5532 | CycleState m_runState; |
| 5533 | public: |
| 5534 | TrackerBase( std::string const& name, TrackerContext& ctx, ITracker* parent ) |
| 5535 | : m_name( name ), |
| 5536 | m_ctx( ctx ), |
| 5537 | m_parent( parent ), |
| 5538 | m_runState( NotStarted ) |
| 5539 | {} |
| 5540 | virtual ~TrackerBase(); |
| 5541 | |
| 5542 | virtual std::string name() const CATCH_OVERRIDE { |
| 5543 | return m_name; |
| 5544 | } |
| 5545 | virtual bool isComplete() const CATCH_OVERRIDE { |
| 5546 | return m_runState == CompletedSuccessfully || m_runState == Failed; |
| 5547 | } |
| 5548 | virtual bool isSuccessfullyCompleted() const CATCH_OVERRIDE { |
| 5549 | return m_runState == CompletedSuccessfully; |
| 5550 | } |
| 5551 | virtual bool isOpen() const CATCH_OVERRIDE { |
| 5552 | return m_runState != NotStarted && !isComplete(); |
| 5553 | } |
| 5554 | virtual bool hasChildren() const CATCH_OVERRIDE { |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 5555 | return !m_children.empty(); |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 5556 | } |
| 5557 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5558 | virtual void addChild( Ptr<ITracker> const& child ) CATCH_OVERRIDE { |
| 5559 | m_children.push_back( child ); |
| 5560 | } |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5561 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5562 | virtual ITracker* findChild( std::string const& name ) CATCH_OVERRIDE { |
| 5563 | Children::const_iterator it = std::find_if( m_children.begin(), m_children.end(), TrackerHasName( name ) ); |
| 5564 | return( it != m_children.end() ) |
| 5565 | ? it->get() |
| 5566 | : CATCH_NULL; |
| 5567 | } |
| 5568 | virtual ITracker& parent() CATCH_OVERRIDE { |
| 5569 | assert( m_parent ); // Should always be non-null except for root |
| 5570 | return *m_parent; |
| 5571 | } |
| 5572 | |
| 5573 | virtual void openChild() CATCH_OVERRIDE { |
| 5574 | if( m_runState != ExecutingChildren ) { |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 5575 | m_runState = ExecutingChildren; |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5576 | if( m_parent ) |
| 5577 | m_parent->openChild(); |
Phil Nash | 3b18d9e | 2015-06-30 18:26:09 +0100 | [diff] [blame] | 5578 | } |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5579 | } |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5580 | void open() { |
| 5581 | m_runState = Executing; |
| 5582 | moveToThis(); |
| 5583 | if( m_parent ) |
| 5584 | m_parent->openChild(); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5585 | } |
| 5586 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5587 | virtual void close() CATCH_OVERRIDE { |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5588 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5589 | // Close any still open children (e.g. generators) |
| 5590 | while( &m_ctx.currentTracker() != this ) |
| 5591 | m_ctx.currentTracker().close(); |
| 5592 | |
| 5593 | switch( m_runState ) { |
| 5594 | case NotStarted: |
| 5595 | case CompletedSuccessfully: |
| 5596 | case Failed: |
| 5597 | throw std::logic_error( "Illogical state" ); |
| 5598 | |
| 5599 | case NeedsAnotherRun: |
| 5600 | break;; |
| 5601 | |
| 5602 | case Executing: |
| 5603 | m_runState = CompletedSuccessfully; |
| 5604 | break; |
| 5605 | case ExecutingChildren: |
| 5606 | if( m_children.empty() || m_children.back()->isComplete() ) |
| 5607 | m_runState = CompletedSuccessfully; |
| 5608 | break; |
| 5609 | |
| 5610 | default: |
| 5611 | throw std::logic_error( "Unexpected state" ); |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 5612 | } |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5613 | moveToParent(); |
| 5614 | m_ctx.completeCycle(); |
| 5615 | } |
| 5616 | virtual void fail() CATCH_OVERRIDE { |
| 5617 | m_runState = Failed; |
| 5618 | if( m_parent ) |
| 5619 | m_parent->markAsNeedingAnotherRun(); |
| 5620 | moveToParent(); |
| 5621 | m_ctx.completeCycle(); |
| 5622 | } |
| 5623 | virtual void markAsNeedingAnotherRun() CATCH_OVERRIDE { |
| 5624 | m_runState = NeedsAnotherRun; |
| 5625 | } |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5626 | private: |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5627 | void moveToParent() { |
| 5628 | assert( m_parent ); |
| 5629 | m_ctx.setCurrentTracker( m_parent ); |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 5630 | } |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5631 | void moveToThis() { |
| 5632 | m_ctx.setCurrentTracker( this ); |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 5633 | } |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5634 | }; |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 5635 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5636 | class SectionTracker : public TrackerBase { |
| 5637 | public: |
| 5638 | SectionTracker( std::string const& name, TrackerContext& ctx, ITracker* parent ) |
| 5639 | : TrackerBase( name, ctx, parent ) |
| 5640 | {} |
| 5641 | virtual ~SectionTracker(); |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 5642 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5643 | static SectionTracker& acquire( TrackerContext& ctx, std::string const& name ) { |
| 5644 | SectionTracker* section = CATCH_NULL; |
| 5645 | |
| 5646 | ITracker& currentTracker = ctx.currentTracker(); |
| 5647 | if( ITracker* childTracker = currentTracker.findChild( name ) ) { |
| 5648 | section = dynamic_cast<SectionTracker*>( childTracker ); |
| 5649 | assert( section ); |
| 5650 | } |
| 5651 | else { |
| 5652 | section = new SectionTracker( name, ctx, ¤tTracker ); |
| 5653 | currentTracker.addChild( section ); |
| 5654 | } |
| 5655 | if( !ctx.completedCycle() && !section->isComplete() ) { |
| 5656 | |
| 5657 | section->open(); |
| 5658 | } |
| 5659 | return *section; |
| 5660 | } |
| 5661 | }; |
| 5662 | |
| 5663 | class IndexTracker : public TrackerBase { |
| 5664 | int m_size; |
| 5665 | int m_index; |
| 5666 | public: |
| 5667 | IndexTracker( std::string const& name, TrackerContext& ctx, ITracker* parent, int size ) |
| 5668 | : TrackerBase( name, ctx, parent ), |
| 5669 | m_size( size ), |
| 5670 | m_index( -1 ) |
| 5671 | {} |
| 5672 | virtual ~IndexTracker(); |
| 5673 | |
| 5674 | static IndexTracker& acquire( TrackerContext& ctx, std::string const& name, int size ) { |
| 5675 | IndexTracker* tracker = CATCH_NULL; |
| 5676 | |
| 5677 | ITracker& currentTracker = ctx.currentTracker(); |
| 5678 | if( ITracker* childTracker = currentTracker.findChild( name ) ) { |
| 5679 | tracker = dynamic_cast<IndexTracker*>( childTracker ); |
| 5680 | assert( tracker ); |
| 5681 | } |
| 5682 | else { |
| 5683 | tracker = new IndexTracker( name, ctx, ¤tTracker, size ); |
| 5684 | currentTracker.addChild( tracker ); |
| 5685 | } |
| 5686 | |
| 5687 | if( !ctx.completedCycle() && !tracker->isComplete() ) { |
| 5688 | if( tracker->m_runState != ExecutingChildren && tracker->m_runState != NeedsAnotherRun ) |
| 5689 | tracker->moveNext(); |
| 5690 | tracker->open(); |
| 5691 | } |
| 5692 | |
| 5693 | return *tracker; |
| 5694 | } |
| 5695 | |
| 5696 | int index() const { return m_index; } |
| 5697 | |
| 5698 | void moveNext() { |
| 5699 | m_index++; |
| 5700 | m_children.clear(); |
| 5701 | } |
| 5702 | |
| 5703 | virtual void close() CATCH_OVERRIDE { |
| 5704 | TrackerBase::close(); |
| 5705 | if( m_runState == CompletedSuccessfully && m_index < m_size-1 ) |
| 5706 | m_runState = Executing; |
| 5707 | } |
| 5708 | }; |
| 5709 | |
| 5710 | inline ITracker& TrackerContext::startRun() { |
| 5711 | m_rootTracker = new SectionTracker( "{root}", *this, CATCH_NULL ); |
| 5712 | m_currentTracker = CATCH_NULL; |
| 5713 | m_runState = Executing; |
| 5714 | return *m_rootTracker; |
| 5715 | } |
| 5716 | |
| 5717 | } // namespace TestCaseTracking |
| 5718 | |
| 5719 | using TestCaseTracking::ITracker; |
| 5720 | using TestCaseTracking::TrackerContext; |
| 5721 | using TestCaseTracking::SectionTracker; |
| 5722 | using TestCaseTracking::IndexTracker; |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 5723 | |
| 5724 | } // namespace Catch |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5725 | |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 5726 | // #included from: catch_fatal_condition.hpp |
| 5727 | #define TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED |
| 5728 | |
| 5729 | namespace Catch { |
| 5730 | |
| 5731 | // Report the error condition then exit the process |
| 5732 | inline void fatal( std::string const& message, int exitCode ) { |
| 5733 | IContext& context = Catch::getCurrentContext(); |
| 5734 | IResultCapture* resultCapture = context.getResultCapture(); |
| 5735 | resultCapture->handleFatalErrorCondition( message ); |
| 5736 | |
| 5737 | if( Catch::alwaysTrue() ) // avoids "no return" warnings |
| 5738 | exit( exitCode ); |
| 5739 | } |
| 5740 | |
| 5741 | } // namespace Catch |
| 5742 | |
| 5743 | #if defined ( CATCH_PLATFORM_WINDOWS ) ///////////////////////////////////////// |
| 5744 | |
| 5745 | namespace Catch { |
| 5746 | |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 5747 | struct FatalConditionHandler { |
| 5748 | void reset() {} |
| 5749 | }; |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 5750 | |
| 5751 | } // namespace Catch |
| 5752 | |
| 5753 | #else // Not Windows - assumed to be POSIX compatible ////////////////////////// |
| 5754 | |
| 5755 | #include <signal.h> |
| 5756 | |
| 5757 | namespace Catch { |
| 5758 | |
| 5759 | struct SignalDefs { int id; const char* name; }; |
| 5760 | extern SignalDefs signalDefs[]; |
| 5761 | SignalDefs signalDefs[] = { |
| 5762 | { SIGINT, "SIGINT - Terminal interrupt signal" }, |
| 5763 | { SIGILL, "SIGILL - Illegal instruction signal" }, |
| 5764 | { SIGFPE, "SIGFPE - Floating point error signal" }, |
| 5765 | { SIGSEGV, "SIGSEGV - Segmentation violation signal" }, |
| 5766 | { SIGTERM, "SIGTERM - Termination request signal" }, |
| 5767 | { SIGABRT, "SIGABRT - Abort (abnormal termination) signal" } |
| 5768 | }; |
| 5769 | |
| 5770 | struct FatalConditionHandler { |
| 5771 | |
| 5772 | static void handleSignal( int sig ) { |
| 5773 | for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) |
| 5774 | if( sig == signalDefs[i].id ) |
| 5775 | fatal( signalDefs[i].name, -sig ); |
| 5776 | fatal( "<unknown signal>", -sig ); |
| 5777 | } |
| 5778 | |
Phil Nash | 85b4e94 | 2014-10-02 18:51:05 +0100 | [diff] [blame] | 5779 | FatalConditionHandler() : m_isSet( true ) { |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 5780 | for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) |
| 5781 | signal( signalDefs[i].id, handleSignal ); |
| 5782 | } |
| 5783 | ~FatalConditionHandler() { |
Phil Nash | 85b4e94 | 2014-10-02 18:51:05 +0100 | [diff] [blame] | 5784 | reset(); |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 5785 | } |
Phil Nash | 85b4e94 | 2014-10-02 18:51:05 +0100 | [diff] [blame] | 5786 | void reset() { |
| 5787 | if( m_isSet ) { |
| 5788 | for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) |
| 5789 | signal( signalDefs[i].id, SIG_DFL ); |
| 5790 | m_isSet = false; |
| 5791 | } |
| 5792 | } |
| 5793 | |
| 5794 | bool m_isSet; |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 5795 | }; |
| 5796 | |
| 5797 | } // namespace Catch |
| 5798 | |
| 5799 | #endif // not Windows |
| 5800 | |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5801 | #include <set> |
| 5802 | #include <string> |
| 5803 | |
| 5804 | namespace Catch { |
| 5805 | |
| 5806 | class StreamRedirect { |
| 5807 | |
| 5808 | public: |
| 5809 | StreamRedirect( std::ostream& stream, std::string& targetString ) |
| 5810 | : m_stream( stream ), |
| 5811 | m_prevBuf( stream.rdbuf() ), |
| 5812 | m_targetString( targetString ) |
| 5813 | { |
| 5814 | stream.rdbuf( m_oss.rdbuf() ); |
| 5815 | } |
| 5816 | |
| 5817 | ~StreamRedirect() { |
| 5818 | m_targetString += m_oss.str(); |
| 5819 | m_stream.rdbuf( m_prevBuf ); |
| 5820 | } |
| 5821 | |
| 5822 | private: |
| 5823 | std::ostream& m_stream; |
| 5824 | std::streambuf* m_prevBuf; |
| 5825 | std::ostringstream m_oss; |
| 5826 | std::string& m_targetString; |
| 5827 | }; |
| 5828 | |
| 5829 | /////////////////////////////////////////////////////////////////////////// |
| 5830 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5831 | class RunContext : public IResultCapture, public IRunner { |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5832 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5833 | RunContext( RunContext const& ); |
| 5834 | void operator =( RunContext const& ); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5835 | |
| 5836 | public: |
| 5837 | |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 5838 | explicit RunContext( Ptr<IConfig const> const& _config, Ptr<IStreamingReporter> const& reporter ) |
| 5839 | : m_runInfo( _config->name() ), |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 5840 | m_context( getCurrentMutableContext() ), |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 5841 | m_activeTestCase( CATCH_NULL ), |
| 5842 | m_config( _config ), |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5843 | m_reporter( reporter ) |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5844 | { |
| 5845 | m_context.setRunner( this ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5846 | m_context.setConfig( m_config ); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5847 | m_context.setResultCapture( this ); |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 5848 | m_reporter->testRunStarting( m_runInfo ); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5849 | } |
| 5850 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5851 | virtual ~RunContext() { |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 5852 | m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) ); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5853 | } |
| 5854 | |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 5855 | void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount ) { |
| 5856 | m_reporter->testGroupStarting( GroupInfo( testSpec, groupIndex, groupsCount ) ); |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 5857 | } |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 5858 | void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount ) { |
| 5859 | m_reporter->testGroupEnded( TestGroupStats( GroupInfo( testSpec, groupIndex, groupsCount ), totals, aborting() ) ); |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 5860 | } |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5861 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 5862 | Totals runTest( TestCase const& testCase ) { |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5863 | Totals prevTotals = m_totals; |
| 5864 | |
| 5865 | std::string redirectedCout; |
| 5866 | std::string redirectedCerr; |
| 5867 | |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 5868 | TestCaseInfo testInfo = testCase.getTestCaseInfo(); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5869 | |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 5870 | m_reporter->testCaseStarting( testInfo ); |
| 5871 | |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 5872 | m_activeTestCase = &testCase; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5873 | |
| 5874 | do { |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5875 | m_trackerContext.startRun(); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5876 | do { |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5877 | m_trackerContext.startCycle(); |
| 5878 | m_testCaseTracker = &SectionTracker::acquire( m_trackerContext, testInfo.name ); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5879 | runCurrentTest( redirectedCout, redirectedCerr ); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5880 | } |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5881 | while( !m_testCaseTracker->isSuccessfullyCompleted() && !aborting() ); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5882 | } |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5883 | // !TBD: deprecated - this will be replaced by indexed trackers |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5884 | while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() ); |
| 5885 | |
Phil Nash | 2846367 | 2012-11-21 18:06:13 +0000 | [diff] [blame] | 5886 | Totals deltaTotals = m_totals.delta( prevTotals ); |
Phil Nash | 2846367 | 2012-11-21 18:06:13 +0000 | [diff] [blame] | 5887 | m_totals.testCases += deltaTotals.testCases; |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 5888 | m_reporter->testCaseEnded( TestCaseStats( testInfo, |
| 5889 | deltaTotals, |
| 5890 | redirectedCout, |
| 5891 | redirectedCerr, |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 5892 | aborting() ) ); |
Phil Nash | 2846367 | 2012-11-21 18:06:13 +0000 | [diff] [blame] | 5893 | |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 5894 | m_activeTestCase = CATCH_NULL; |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5895 | m_testCaseTracker = CATCH_NULL; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5896 | |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 5897 | return deltaTotals; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5898 | } |
| 5899 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 5900 | Ptr<IConfig const> config() const { |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5901 | return m_config; |
| 5902 | } |
| 5903 | |
| 5904 | private: // IResultCapture |
| 5905 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 5906 | virtual void assertionEnded( AssertionResult const& result ) { |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5907 | if( result.getResultType() == ResultWas::Ok ) { |
| 5908 | m_totals.assertions.passed++; |
| 5909 | } |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 5910 | else if( !result.isOk() ) { |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5911 | m_totals.assertions.failed++; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5912 | } |
| 5913 | |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 5914 | if( m_reporter->assertionEnded( AssertionStats( result, m_messages, m_totals ) ) ) |
| 5915 | m_messages.clear(); |
Phil Nash | a90a88a | 2012-11-19 19:59:10 +0000 | [diff] [blame] | 5916 | |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 5917 | // Reset working state |
| 5918 | m_lastAssertionInfo = AssertionInfo( "", m_lastAssertionInfo.lineInfo, "{Unknown expression after the reported line}" , m_lastAssertionInfo.resultDisposition ); |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 5919 | m_lastResult = result; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5920 | } |
| 5921 | |
| 5922 | virtual bool sectionStarted ( |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 5923 | SectionInfo const& sectionInfo, |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5924 | Counts& assertions |
| 5925 | ) |
| 5926 | { |
| 5927 | std::ostringstream oss; |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 5928 | oss << sectionInfo.name << "@" << sectionInfo.lineInfo; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5929 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5930 | ITracker& sectionTracker = SectionTracker::acquire( m_trackerContext, oss.str() ); |
| 5931 | if( !sectionTracker.isOpen() ) |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5932 | return false; |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5933 | m_activeSections.push_back( §ionTracker ); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5934 | |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 5935 | m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo; |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 5936 | |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 5937 | m_reporter->sectionStarting( sectionInfo ); |
| 5938 | |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5939 | assertions = m_totals.assertions; |
| 5940 | |
| 5941 | return true; |
| 5942 | } |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 5943 | bool testForMissingAssertions( Counts& assertions ) { |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5944 | if( assertions.total() != 0 ) |
| 5945 | return false; |
Phil Nash | 9e42153 | 2015-11-03 17:06:54 +0000 | [diff] [blame] | 5946 | if( !m_config->warnAboutMissingAssertions() ) |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5947 | return false; |
| 5948 | if( m_trackerContext.currentTracker().hasChildren() ) |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 5949 | return false; |
| 5950 | m_totals.assertions.failed++; |
| 5951 | assertions.failed++; |
| 5952 | return true; |
| 5953 | } |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5954 | |
Phil Nash | 0c1c9fa | 2015-09-27 03:28:14 -0700 | [diff] [blame] | 5955 | virtual void sectionEnded( SectionEndInfo const& endInfo ) { |
| 5956 | Counts assertions = m_totals.assertions - endInfo.prevAssertions; |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 5957 | bool missingAssertions = testForMissingAssertions( assertions ); |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 5958 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5959 | if( !m_activeSections.empty() ) { |
| 5960 | m_activeSections.back()->close(); |
| 5961 | m_activeSections.pop_back(); |
| 5962 | } |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 5963 | |
Phil Nash | 0c1c9fa | 2015-09-27 03:28:14 -0700 | [diff] [blame] | 5964 | m_reporter->sectionEnded( SectionStats( endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions ) ); |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 5965 | m_messages.clear(); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5966 | } |
| 5967 | |
Phil Nash | 0c1c9fa | 2015-09-27 03:28:14 -0700 | [diff] [blame] | 5968 | virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) { |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 5969 | if( m_unfinishedSections.empty() ) |
| 5970 | m_activeSections.back()->fail(); |
| 5971 | else |
| 5972 | m_activeSections.back()->close(); |
| 5973 | m_activeSections.pop_back(); |
| 5974 | |
Phil Nash | 0c1c9fa | 2015-09-27 03:28:14 -0700 | [diff] [blame] | 5975 | m_unfinishedSections.push_back( endInfo ); |
| 5976 | } |
| 5977 | |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 5978 | virtual void pushScopedMessage( MessageInfo const& message ) { |
| 5979 | m_messages.push_back( message ); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5980 | } |
| 5981 | |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 5982 | virtual void popScopedMessage( MessageInfo const& message ) { |
| 5983 | m_messages.erase( std::remove( m_messages.begin(), m_messages.end(), message ), m_messages.end() ); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5984 | } |
| 5985 | |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5986 | virtual std::string getCurrentTestName() const { |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 5987 | return m_activeTestCase |
| 5988 | ? m_activeTestCase->getTestCaseInfo().name |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5989 | : ""; |
| 5990 | } |
| 5991 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 5992 | virtual const AssertionResult* getLastResult() const { |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 5993 | return &m_lastResult; |
| 5994 | } |
| 5995 | |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 5996 | virtual void handleFatalErrorCondition( std::string const& message ) { |
| 5997 | ResultBuilder resultBuilder = makeUnexpectedResultBuilder(); |
| 5998 | resultBuilder.setResultType( ResultWas::FatalErrorCondition ); |
| 5999 | resultBuilder << message; |
| 6000 | resultBuilder.captureExpression(); |
| 6001 | |
| 6002 | handleUnfinishedSections(); |
| 6003 | |
| 6004 | // Recreate section for test case (as we will lose the one that was in scope) |
| 6005 | TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); |
| 6006 | SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description ); |
| 6007 | |
| 6008 | Counts assertions; |
| 6009 | assertions.failed = 1; |
| 6010 | SectionStats testCaseSectionStats( testCaseSection, assertions, 0, false ); |
| 6011 | m_reporter->sectionEnded( testCaseSectionStats ); |
| 6012 | |
| 6013 | TestCaseInfo testInfo = m_activeTestCase->getTestCaseInfo(); |
| 6014 | |
| 6015 | Totals deltaTotals; |
| 6016 | deltaTotals.testCases.failed = 1; |
| 6017 | m_reporter->testCaseEnded( TestCaseStats( testInfo, |
| 6018 | deltaTotals, |
| 6019 | "", |
| 6020 | "", |
| 6021 | false ) ); |
| 6022 | m_totals.testCases.failed++; |
| 6023 | testGroupEnded( "", m_totals, 1, 1 ); |
| 6024 | m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, false ) ); |
| 6025 | } |
| 6026 | |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 6027 | public: |
| 6028 | // !TBD We need to do this another way! |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6029 | bool aborting() const { |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6030 | return m_totals.assertions.failed == static_cast<std::size_t>( m_config->abortAfter() ); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6031 | } |
| 6032 | |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 6033 | private: |
| 6034 | |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6035 | void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr ) { |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 6036 | TestCaseInfo const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); |
Phil Nash | ce56209 | 2014-07-09 07:40:37 +0100 | [diff] [blame] | 6037 | SectionInfo testCaseSection( testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description ); |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 6038 | m_reporter->sectionStarting( testCaseSection ); |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 6039 | Counts prevAssertions = m_totals.assertions; |
| 6040 | double duration = 0; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6041 | try { |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 6042 | m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal ); |
Phil Nash | d768b1b | 2013-02-04 00:05:16 +0000 | [diff] [blame] | 6043 | |
Phil Nash | 8f66e34 | 2015-07-02 23:03:13 +0100 | [diff] [blame] | 6044 | seedRng( *m_config ); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6045 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 6046 | Timer timer; |
| 6047 | timer.start(); |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 6048 | if( m_reporter->getPreferences().shouldRedirectStdOut ) { |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 6049 | StreamRedirect coutRedir( Catch::cout(), redirectedCout ); |
| 6050 | StreamRedirect cerrRedir( Catch::cerr(), redirectedCerr ); |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 6051 | invokeActiveTestCase(); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6052 | } |
| 6053 | else { |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 6054 | invokeActiveTestCase(); |
Phil Nash | a70fbe3 | 2012-08-31 08:10:36 +0100 | [diff] [blame] | 6055 | } |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 6056 | duration = timer.getElapsedSeconds(); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6057 | } |
| 6058 | catch( TestFailureException& ) { |
| 6059 | // This just means the test was aborted due to failure |
| 6060 | } |
| 6061 | catch(...) { |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 6062 | makeUnexpectedResultBuilder().useActiveException(); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6063 | } |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6064 | m_testCaseTracker->close(); |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 6065 | handleUnfinishedSections(); |
Phil Nash | d768b1b | 2013-02-04 00:05:16 +0000 | [diff] [blame] | 6066 | m_messages.clear(); |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 6067 | |
| 6068 | Counts assertions = m_totals.assertions - prevAssertions; |
| 6069 | bool missingAssertions = testForMissingAssertions( assertions ); |
| 6070 | |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 6071 | if( testCaseInfo.okToFail() ) { |
| 6072 | std::swap( assertions.failedButOk, assertions.failed ); |
| 6073 | m_totals.assertions.failed -= assertions.failedButOk; |
| 6074 | m_totals.assertions.failedButOk += assertions.failedButOk; |
| 6075 | } |
| 6076 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 6077 | SectionStats testCaseSectionStats( testCaseSection, assertions, duration, missingAssertions ); |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 6078 | m_reporter->sectionEnded( testCaseSectionStats ); |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6079 | } |
| 6080 | |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 6081 | void invokeActiveTestCase() { |
| 6082 | FatalConditionHandler fatalConditionHandler; // Handle signals |
| 6083 | m_activeTestCase->invoke(); |
Phil Nash | 85b4e94 | 2014-10-02 18:51:05 +0100 | [diff] [blame] | 6084 | fatalConditionHandler.reset(); |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 6085 | } |
| 6086 | |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6087 | private: |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 6088 | |
| 6089 | ResultBuilder makeUnexpectedResultBuilder() const { |
| 6090 | return ResultBuilder( m_lastAssertionInfo.macroName.c_str(), |
| 6091 | m_lastAssertionInfo.lineInfo, |
| 6092 | m_lastAssertionInfo.capturedExpression.c_str(), |
| 6093 | m_lastAssertionInfo.resultDisposition ); |
| 6094 | } |
| 6095 | |
| 6096 | void handleUnfinishedSections() { |
| 6097 | // If sections ended prematurely due to an exception we stored their |
| 6098 | // infos here so we can tear them down outside the unwind process. |
Phil Nash | 0c1c9fa | 2015-09-27 03:28:14 -0700 | [diff] [blame] | 6099 | for( std::vector<SectionEndInfo>::const_reverse_iterator it = m_unfinishedSections.rbegin(), |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 6100 | itEnd = m_unfinishedSections.rend(); |
| 6101 | it != itEnd; |
| 6102 | ++it ) |
Phil Nash | 0c1c9fa | 2015-09-27 03:28:14 -0700 | [diff] [blame] | 6103 | sectionEnded( *it ); |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 6104 | m_unfinishedSections.clear(); |
| 6105 | } |
| 6106 | |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 6107 | TestRunInfo m_runInfo; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6108 | IMutableContext& m_context; |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 6109 | TestCase const* m_activeTestCase; |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6110 | ITracker* m_testCaseTracker; |
| 6111 | ITracker* m_currentSectionTracker; |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 6112 | AssertionResult m_lastResult; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6113 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6114 | Ptr<IConfig const> m_config; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6115 | Totals m_totals; |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 6116 | Ptr<IStreamingReporter> m_reporter; |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 6117 | std::vector<MessageInfo> m_messages; |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 6118 | AssertionInfo m_lastAssertionInfo; |
Phil Nash | 0c1c9fa | 2015-09-27 03:28:14 -0700 | [diff] [blame] | 6119 | std::vector<SectionEndInfo> m_unfinishedSections; |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6120 | std::vector<ITracker*> m_activeSections; |
| 6121 | TrackerContext m_trackerContext; |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6122 | }; |
| 6123 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 6124 | IResultCapture& getResultCapture() { |
| 6125 | if( IResultCapture* capture = getCurrentContext().getResultCapture() ) |
| 6126 | return *capture; |
| 6127 | else |
| 6128 | throw std::logic_error( "No result capture instance" ); |
| 6129 | } |
| 6130 | |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 6131 | } // end namespace Catch |
| 6132 | |
Phil Nash | 7673a30 | 2012-11-15 22:15:41 +0000 | [diff] [blame] | 6133 | // #included from: internal/catch_version.h |
| 6134 | #define TWOBLUECUBES_CATCH_VERSION_H_INCLUDED |
| 6135 | |
| 6136 | namespace Catch { |
| 6137 | |
| 6138 | // Versioning information |
| 6139 | struct Version { |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 6140 | Version( unsigned int _majorVersion, |
| 6141 | unsigned int _minorVersion, |
Phil Nash | 21f7ef6 | 2015-06-29 18:05:23 +0100 | [diff] [blame] | 6142 | unsigned int _patchNumber, |
| 6143 | std::string const& _branchName, |
| 6144 | unsigned int _buildNumber ); |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 6145 | |
Phil Nash | 9d469b6 | 2014-04-18 08:30:31 +0100 | [diff] [blame] | 6146 | unsigned int const majorVersion; |
| 6147 | unsigned int const minorVersion; |
Phil Nash | 21f7ef6 | 2015-06-29 18:05:23 +0100 | [diff] [blame] | 6148 | unsigned int const patchNumber; |
| 6149 | |
| 6150 | // buildNumber is only used if branchName is not null |
| 6151 | std::string const branchName; |
Phil Nash | 9d469b6 | 2014-04-18 08:30:31 +0100 | [diff] [blame] | 6152 | unsigned int const buildNumber; |
Phil Nash | 21f7ef6 | 2015-06-29 18:05:23 +0100 | [diff] [blame] | 6153 | |
| 6154 | friend std::ostream& operator << ( std::ostream& os, Version const& version ); |
Phil Nash | dd26e88 | 2013-03-25 09:25:31 +0000 | [diff] [blame] | 6155 | |
Phil Nash | 503d5d0 | 2013-07-03 08:25:11 +0100 | [diff] [blame] | 6156 | private: |
| 6157 | void operator=( Version const& ); |
Phil Nash | 7673a30 | 2012-11-15 22:15:41 +0000 | [diff] [blame] | 6158 | }; |
| 6159 | |
| 6160 | extern Version libraryVersion; |
| 6161 | } |
| 6162 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 6163 | #include <fstream> |
| 6164 | #include <stdlib.h> |
| 6165 | #include <limits> |
| 6166 | |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 6167 | namespace Catch { |
| 6168 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6169 | Ptr<IStreamingReporter> createReporter( std::string const& reporterName, Ptr<Config> const& config ) { |
Phil Nash | 8b1b7cd | 2015-08-03 07:40:52 +0100 | [diff] [blame] | 6170 | Ptr<IStreamingReporter> reporter = getRegistryHub().getReporterRegistry().create( reporterName, config.get() ); |
| 6171 | if( !reporter ) { |
| 6172 | std::ostringstream oss; |
| 6173 | oss << "No reporter registered with name: '" << reporterName << "'"; |
| 6174 | throw std::domain_error( oss.str() ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 6175 | } |
Phil Nash | 8b1b7cd | 2015-08-03 07:40:52 +0100 | [diff] [blame] | 6176 | return reporter; |
| 6177 | } |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 6178 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6179 | Ptr<IStreamingReporter> makeReporter( Ptr<Config> const& config ) { |
| 6180 | std::vector<std::string> reporters = config->getReporterNames(); |
| 6181 | if( reporters.empty() ) |
| 6182 | reporters.push_back( "console" ); |
| 6183 | |
| 6184 | Ptr<IStreamingReporter> reporter; |
| 6185 | for( std::vector<std::string>::const_iterator it = reporters.begin(), itEnd = reporters.end(); |
| 6186 | it != itEnd; |
| 6187 | ++it ) |
| 6188 | reporter = addReporter( reporter, createReporter( *it, config ) ); |
| 6189 | return reporter; |
| 6190 | } |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6191 | Ptr<IStreamingReporter> addListeners( Ptr<IConfig const> const& config, Ptr<IStreamingReporter> reporters ) { |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6192 | IReporterRegistry::Listeners listeners = getRegistryHub().getReporterRegistry().getListeners(); |
| 6193 | for( IReporterRegistry::Listeners::const_iterator it = listeners.begin(), itEnd = listeners.end(); |
| 6194 | it != itEnd; |
| 6195 | ++it ) |
| 6196 | reporters = addReporter(reporters, (*it)->create( ReporterConfig( config ) ) ); |
| 6197 | return reporters; |
| 6198 | } |
| 6199 | |
Phil Nash | 8b1b7cd | 2015-08-03 07:40:52 +0100 | [diff] [blame] | 6200 | Totals runTests( Ptr<Config> const& config ) { |
| 6201 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6202 | Ptr<IConfig const> iconfig = config.get(); |
Phil Nash | 8b1b7cd | 2015-08-03 07:40:52 +0100 | [diff] [blame] | 6203 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6204 | Ptr<IStreamingReporter> reporter = makeReporter( config ); |
| 6205 | reporter = addListeners( iconfig, reporter ); |
| 6206 | |
| 6207 | RunContext context( iconfig, reporter ); |
Phil Nash | 8b1b7cd | 2015-08-03 07:40:52 +0100 | [diff] [blame] | 6208 | |
| 6209 | Totals totals; |
| 6210 | |
| 6211 | context.testGroupStarting( config->name(), 1, 1 ); |
| 6212 | |
| 6213 | TestSpec testSpec = config->testSpec(); |
| 6214 | if( !testSpec.hasFilters() ) |
| 6215 | testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "~[.]" ).testSpec(); // All not hidden tests |
| 6216 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6217 | std::vector<TestCase> const& allTestCases = getAllTestCasesSorted( *iconfig ); |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6218 | for( std::vector<TestCase>::const_iterator it = allTestCases.begin(), itEnd = allTestCases.end(); |
Phil Nash | 8b1b7cd | 2015-08-03 07:40:52 +0100 | [diff] [blame] | 6219 | it != itEnd; |
| 6220 | ++it ) { |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6221 | if( !context.aborting() && matchTest( *it, testSpec, *iconfig ) ) |
Phil Nash | 8b1b7cd | 2015-08-03 07:40:52 +0100 | [diff] [blame] | 6222 | totals += context.runTest( *it ); |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6223 | else |
| 6224 | reporter->skipTest( *it ); |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 6225 | } |
Phil Nash | 06e959b | 2012-05-25 08:52:05 +0100 | [diff] [blame] | 6226 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6227 | context.testGroupEnded( iconfig->name(), totals, 1, 1 ); |
Phil Nash | 8b1b7cd | 2015-08-03 07:40:52 +0100 | [diff] [blame] | 6228 | return totals; |
| 6229 | } |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 6230 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6231 | void applyFilenamesAsTags( IConfig const& config ) { |
| 6232 | std::vector<TestCase> const& tests = getAllTestCasesSorted( config ); |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 6233 | for(std::size_t i = 0; i < tests.size(); ++i ) { |
| 6234 | TestCase& test = const_cast<TestCase&>( tests[i] ); |
| 6235 | std::set<std::string> tags = test.tags; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6236 | |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 6237 | std::string filename = test.lineInfo.file; |
Phil Nash | c1ca0fd | 2015-07-03 18:30:25 +0100 | [diff] [blame] | 6238 | std::string::size_type lastSlash = filename.find_last_of( "\\/" ); |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 6239 | if( lastSlash != std::string::npos ) |
| 6240 | filename = filename.substr( lastSlash+1 ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 6241 | |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 6242 | std::string::size_type lastDot = filename.find_last_of( "." ); |
| 6243 | if( lastDot != std::string::npos ) |
| 6244 | filename = filename.substr( 0, lastDot ); |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 6245 | |
Phil Nash | e6b365d | 2015-07-07 08:25:15 +0100 | [diff] [blame] | 6246 | tags.insert( "#" + filename ); |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 6247 | setTags( test, tags ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 6248 | } |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 6249 | } |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 6250 | |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 6251 | class Session : NonCopyable { |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6252 | static bool alreadyInstantiated; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 6253 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6254 | public: |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 6255 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6256 | struct OnUnusedOptions { enum DoWhat { Ignore, Fail }; }; |
| 6257 | |
| 6258 | Session() |
| 6259 | : m_cli( makeCommandLineParser() ) { |
| 6260 | if( alreadyInstantiated ) { |
| 6261 | std::string msg = "Only one instance of Catch::Session can ever be used"; |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 6262 | Catch::cerr() << msg << std::endl; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6263 | throw std::logic_error( msg ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 6264 | } |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6265 | alreadyInstantiated = true; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 6266 | } |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6267 | ~Session() { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6268 | Catch::cleanUp(); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 6269 | } |
| 6270 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6271 | void showHelp( std::string const& processName ) { |
Phil Nash | 21f7ef6 | 2015-06-29 18:05:23 +0100 | [diff] [blame] | 6272 | Catch::cout() << "\nCatch v" << libraryVersion << "\n"; |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 6273 | |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 6274 | m_cli.usage( Catch::cout(), processName ); |
| 6275 | Catch::cout() << "For more detail usage please see the project docs\n" << std::endl; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6276 | } |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6277 | |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 6278 | int applyCommandLine( int argc, char const* argv[], OnUnusedOptions::DoWhat unusedOptionBehaviour = OnUnusedOptions::Fail ) { |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6279 | try { |
Phil Nash | 91ef5f7 | 2013-12-20 19:06:26 +0000 | [diff] [blame] | 6280 | m_cli.setThrowOnUnrecognisedTokens( unusedOptionBehaviour == OnUnusedOptions::Fail ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6281 | m_unusedTokens = m_cli.parseInto( argc, argv, m_configData ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6282 | if( m_configData.showHelp ) |
| 6283 | showHelp( m_configData.processName ); |
| 6284 | m_config.reset(); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6285 | } |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6286 | catch( std::exception& ex ) { |
Phil Nash | 4611871 | 2013-08-16 19:01:32 +0100 | [diff] [blame] | 6287 | { |
| 6288 | Colour colourGuard( Colour::Red ); |
Phil Nash | 21f7ef6 | 2015-06-29 18:05:23 +0100 | [diff] [blame] | 6289 | Catch::cerr() |
| 6290 | << "\nError(s) in input:\n" |
| 6291 | << Text( ex.what(), TextAttributes().setIndent(2) ) |
| 6292 | << "\n\n"; |
Phil Nash | 4611871 | 2013-08-16 19:01:32 +0100 | [diff] [blame] | 6293 | } |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 6294 | m_cli.usage( Catch::cout(), m_configData.processName ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6295 | return (std::numeric_limits<int>::max)(); |
| 6296 | } |
| 6297 | return 0; |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 6298 | } |
Phil Nash | 89d2a3f | 2012-05-16 15:09:17 +0100 | [diff] [blame] | 6299 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6300 | void useConfigData( ConfigData const& _configData ) { |
| 6301 | m_configData = _configData; |
| 6302 | m_config.reset(); |
| 6303 | } |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 6304 | |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 6305 | int run( int argc, char const* argv[] ) { |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6306 | |
| 6307 | int returnCode = applyCommandLine( argc, argv ); |
| 6308 | if( returnCode == 0 ) |
| 6309 | returnCode = run(); |
| 6310 | return returnCode; |
| 6311 | } |
Phil Nash | 3b4edd7 | 2016-02-10 19:24:48 +0000 | [diff] [blame] | 6312 | int run( int argc, char* argv[] ) { |
| 6313 | return run( argc, const_cast<char const**>( argv ) ); |
| 6314 | } |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6315 | |
| 6316 | int run() { |
| 6317 | if( m_configData.showHelp ) |
| 6318 | return 0; |
| 6319 | |
| 6320 | try |
| 6321 | { |
| 6322 | config(); // Force config to be constructed |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 6323 | |
Phil Nash | 8f66e34 | 2015-07-02 23:03:13 +0100 | [diff] [blame] | 6324 | seedRng( *m_config ); |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 6325 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6326 | if( m_configData.filenamesAsTags ) |
| 6327 | applyFilenamesAsTags( *m_config ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6328 | |
| 6329 | // Handle list request |
| 6330 | if( Option<std::size_t> listed = list( config() ) ) |
| 6331 | return static_cast<int>( *listed ); |
| 6332 | |
Phil Nash | 8b1b7cd | 2015-08-03 07:40:52 +0100 | [diff] [blame] | 6333 | return static_cast<int>( runTests( m_config ).assertions.failed ); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6334 | } |
| 6335 | catch( std::exception& ex ) { |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 6336 | Catch::cerr() << ex.what() << std::endl; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6337 | return (std::numeric_limits<int>::max)(); |
| 6338 | } |
| 6339 | } |
| 6340 | |
| 6341 | Clara::CommandLine<ConfigData> const& cli() const { |
| 6342 | return m_cli; |
| 6343 | } |
| 6344 | std::vector<Clara::Parser::Token> const& unusedTokens() const { |
| 6345 | return m_unusedTokens; |
| 6346 | } |
| 6347 | ConfigData& configData() { |
| 6348 | return m_configData; |
| 6349 | } |
| 6350 | Config& config() { |
| 6351 | if( !m_config ) |
| 6352 | m_config = new Config( m_configData ); |
| 6353 | return *m_config; |
| 6354 | } |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6355 | private: |
| 6356 | Clara::CommandLine<ConfigData> m_cli; |
| 6357 | std::vector<Clara::Parser::Token> m_unusedTokens; |
| 6358 | ConfigData m_configData; |
| 6359 | Ptr<Config> m_config; |
| 6360 | }; |
| 6361 | |
| 6362 | bool Session::alreadyInstantiated = false; |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 6363 | |
| 6364 | } // end namespace Catch |
| 6365 | |
| 6366 | // #included from: catch_registry_hub.hpp |
Matt Wozniski | f29c898 | 2012-09-17 01:42:29 -0400 | [diff] [blame] | 6367 | #define TWOBLUECUBES_CATCH_REGISTRY_HUB_HPP_INCLUDED |
Phil Nash | 371db8b | 2012-05-21 18:52:09 +0100 | [diff] [blame] | 6368 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 6369 | // #included from: catch_test_case_registry_impl.hpp |
Matt Wozniski | f29c898 | 2012-09-17 01:42:29 -0400 | [diff] [blame] | 6370 | #define TWOBLUECUBES_CATCH_TEST_CASE_REGISTRY_IMPL_HPP_INCLUDED |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 6371 | |
| 6372 | #include <vector> |
| 6373 | #include <set> |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6374 | #include <sstream> |
| 6375 | #include <iostream> |
Phil Nash | 9630454 | 2014-09-15 23:32:13 +0100 | [diff] [blame] | 6376 | #include <algorithm> |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6377 | |
| 6378 | namespace Catch { |
| 6379 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6380 | struct LexSort { |
| 6381 | bool operator() (TestCase i,TestCase j) const { return (i<j);} |
| 6382 | }; |
| 6383 | struct RandomNumberGenerator { |
| 6384 | int operator()( int n ) const { return std::rand() % n; } |
| 6385 | }; |
Phil Nash | ee3b265 | 2014-09-18 18:25:10 +0100 | [diff] [blame] | 6386 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6387 | inline std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) { |
| 6388 | |
| 6389 | std::vector<TestCase> sorted = unsortedTestCases; |
| 6390 | |
| 6391 | switch( config.runOrder() ) { |
| 6392 | case RunTests::InLexicographicalOrder: |
| 6393 | std::sort( sorted.begin(), sorted.end(), LexSort() ); |
| 6394 | break; |
| 6395 | case RunTests::InRandomOrder: |
| 6396 | { |
| 6397 | seedRng( config ); |
| 6398 | |
| 6399 | RandomNumberGenerator rng; |
| 6400 | std::random_shuffle( sorted.begin(), sorted.end(), rng ); |
| 6401 | } |
| 6402 | break; |
| 6403 | case RunTests::InDeclarationOrder: |
| 6404 | // already in declaration order |
| 6405 | break; |
| 6406 | } |
| 6407 | return sorted; |
| 6408 | } |
| 6409 | bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ) { |
| 6410 | return testSpec.matches( testCase ) && ( config.allowThrows() || !testCase.throws() ); |
| 6411 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6412 | |
| 6413 | void enforceNoDuplicateTestCases( std::vector<TestCase> const& functions ) { |
| 6414 | std::set<TestCase> seenFunctions; |
| 6415 | for( std::vector<TestCase>::const_iterator it = functions.begin(), itEnd = functions.end(); |
| 6416 | it != itEnd; |
| 6417 | ++it ) { |
| 6418 | std::pair<std::set<TestCase>::const_iterator, bool> prev = seenFunctions.insert( *it ); |
| 6419 | if( !prev.second ){ |
| 6420 | Catch::cerr() |
| 6421 | << Colour( Colour::Red ) |
| 6422 | << "error: TEST_CASE( \"" << it->name << "\" ) already defined.\n" |
| 6423 | << "\tFirst seen at " << prev.first->getTestCaseInfo().lineInfo << "\n" |
| 6424 | << "\tRedefined at " << it->getTestCaseInfo().lineInfo << std::endl; |
| 6425 | exit(1); |
| 6426 | } |
| 6427 | } |
| 6428 | } |
| 6429 | |
| 6430 | std::vector<TestCase> filterTests( std::vector<TestCase> const& testCases, TestSpec const& testSpec, IConfig const& config ) { |
| 6431 | std::vector<TestCase> filtered; |
Phil Nash | 8a05f46 | 2015-08-07 17:53:29 +0100 | [diff] [blame] | 6432 | filtered.reserve( testCases.size() ); |
| 6433 | for( std::vector<TestCase>::const_iterator it = testCases.begin(), itEnd = testCases.end(); |
| 6434 | it != itEnd; |
| 6435 | ++it ) |
| 6436 | if( matchTest( *it, testSpec, config ) ) |
| 6437 | filtered.push_back( *it ); |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6438 | return filtered; |
| 6439 | } |
| 6440 | std::vector<TestCase> const& getAllTestCasesSorted( IConfig const& config ) { |
| 6441 | return getRegistryHub().getTestCaseRegistry().getAllTestsSorted( config ); |
| 6442 | } |
| 6443 | |
| 6444 | class TestRegistry : public ITestCaseRegistry { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6445 | public: |
Phil Nash | 981347b | 2015-12-09 18:11:48 +0000 | [diff] [blame] | 6446 | TestRegistry() |
| 6447 | : m_currentSortOrder( RunTests::InDeclarationOrder ), |
| 6448 | m_unnamedCount( 0 ) |
| 6449 | {} |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6450 | virtual ~TestRegistry(); |
| 6451 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 6452 | virtual void registerTest( TestCase const& testCase ) { |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 6453 | std::string name = testCase.getTestCaseInfo().name; |
| 6454 | if( name == "" ) { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6455 | std::ostringstream oss; |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 6456 | oss << "Anonymous test case " << ++m_unnamedCount; |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 6457 | return registerTest( testCase.withName( oss.str() ) ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6458 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6459 | m_functions.push_back( testCase ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6460 | } |
| 6461 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 6462 | virtual std::vector<TestCase> const& getAllTests() const { |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6463 | return m_functions; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6464 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6465 | virtual std::vector<TestCase> const& getAllTestsSorted( IConfig const& config ) const { |
| 6466 | if( m_sortedFunctions.empty() ) |
| 6467 | enforceNoDuplicateTestCases( m_functions ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6468 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6469 | if( m_currentSortOrder != config.runOrder() || m_sortedFunctions.empty() ) { |
| 6470 | m_sortedFunctions = sortTests( config, m_functions ); |
| 6471 | m_currentSortOrder = config.runOrder(); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6472 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6473 | return m_sortedFunctions; |
Phil Nash | 92f0836 | 2014-12-22 20:18:05 +0000 | [diff] [blame] | 6474 | } |
| 6475 | |
| 6476 | private: |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6477 | std::vector<TestCase> m_functions; |
| 6478 | mutable RunTests::InWhatOrder m_currentSortOrder; |
| 6479 | mutable std::vector<TestCase> m_sortedFunctions; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6480 | size_t m_unnamedCount; |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 6481 | std::ios_base::Init m_ostreamInit; // Forces cout/ cerr to be initialised |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6482 | }; |
| 6483 | |
| 6484 | /////////////////////////////////////////////////////////////////////////// |
| 6485 | |
| 6486 | class FreeFunctionTestCase : public SharedImpl<ITestCase> { |
| 6487 | public: |
| 6488 | |
| 6489 | FreeFunctionTestCase( TestFunction fun ) : m_fun( fun ) {} |
| 6490 | |
| 6491 | virtual void invoke() const { |
| 6492 | m_fun(); |
| 6493 | } |
| 6494 | |
| 6495 | private: |
| 6496 | virtual ~FreeFunctionTestCase(); |
| 6497 | |
| 6498 | TestFunction m_fun; |
| 6499 | }; |
| 6500 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 6501 | inline std::string extractClassName( std::string const& classOrQualifiedMethodName ) { |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 6502 | std::string className = classOrQualifiedMethodName; |
Phil Nash | f7378ee | 2013-09-07 12:07:38 +0100 | [diff] [blame] | 6503 | if( startsWith( className, "&" ) ) |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 6504 | { |
| 6505 | std::size_t lastColons = className.rfind( "::" ); |
| 6506 | std::size_t penultimateColons = className.rfind( "::", lastColons-1 ); |
| 6507 | if( penultimateColons == std::string::npos ) |
| 6508 | penultimateColons = 1; |
| 6509 | className = className.substr( penultimateColons, lastColons-penultimateColons ); |
| 6510 | } |
| 6511 | return className; |
| 6512 | } |
| 6513 | |
Phil Nash | 7e15d9b | 2015-11-20 16:59:14 +0000 | [diff] [blame] | 6514 | void registerTestCase |
| 6515 | ( ITestCase* testCase, |
| 6516 | char const* classOrQualifiedMethodName, |
| 6517 | NameAndDesc const& nameAndDesc, |
| 6518 | SourceLineInfo const& lineInfo ) { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6519 | |
Phil Nash | 7e15d9b | 2015-11-20 16:59:14 +0000 | [diff] [blame] | 6520 | getMutableRegistryHub().registerTest |
| 6521 | ( makeTestCase |
| 6522 | ( testCase, |
| 6523 | extractClassName( classOrQualifiedMethodName ), |
| 6524 | nameAndDesc.name, |
| 6525 | nameAndDesc.description, |
| 6526 | lineInfo ) ); |
| 6527 | } |
| 6528 | void registerTestCaseFunction |
| 6529 | ( TestFunction function, |
| 6530 | SourceLineInfo const& lineInfo, |
| 6531 | NameAndDesc const& nameAndDesc ) { |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 6532 | registerTestCase( new FreeFunctionTestCase( function ), "", nameAndDesc, lineInfo ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6533 | } |
| 6534 | |
Phil Nash | 7e15d9b | 2015-11-20 16:59:14 +0000 | [diff] [blame] | 6535 | /////////////////////////////////////////////////////////////////////////// |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6536 | |
Phil Nash | 7e15d9b | 2015-11-20 16:59:14 +0000 | [diff] [blame] | 6537 | AutoReg::AutoReg |
| 6538 | ( TestFunction function, |
| 6539 | SourceLineInfo const& lineInfo, |
| 6540 | NameAndDesc const& nameAndDesc ) { |
| 6541 | registerTestCaseFunction( function, lineInfo, nameAndDesc ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6542 | } |
| 6543 | |
Phil Nash | 7e15d9b | 2015-11-20 16:59:14 +0000 | [diff] [blame] | 6544 | AutoReg::~AutoReg() {} |
| 6545 | |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6546 | } // end namespace Catch |
| 6547 | |
| 6548 | // #included from: catch_reporter_registry.hpp |
| 6549 | #define TWOBLUECUBES_CATCH_REPORTER_REGISTRY_HPP_INCLUDED |
| 6550 | |
| 6551 | #include <map> |
| 6552 | |
| 6553 | namespace Catch { |
| 6554 | |
| 6555 | class ReporterRegistry : public IReporterRegistry { |
| 6556 | |
| 6557 | public: |
| 6558 | |
Phil Nash | 1952015 | 2015-08-10 07:32:48 +0100 | [diff] [blame] | 6559 | virtual ~ReporterRegistry() CATCH_OVERRIDE {} |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6560 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6561 | virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const CATCH_OVERRIDE { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6562 | FactoryMap::const_iterator it = m_factories.find( name ); |
| 6563 | if( it == m_factories.end() ) |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 6564 | return CATCH_NULL; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6565 | return it->second->create( ReporterConfig( config ) ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6566 | } |
| 6567 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6568 | void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6569 | m_factories.insert( std::make_pair( name, factory ) ); |
| 6570 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6571 | void registerListener( Ptr<IReporterFactory> const& factory ) { |
| 6572 | m_listeners.push_back( factory ); |
| 6573 | } |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6574 | |
Phil Nash | 1952015 | 2015-08-10 07:32:48 +0100 | [diff] [blame] | 6575 | virtual FactoryMap const& getFactories() const CATCH_OVERRIDE { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6576 | return m_factories; |
| 6577 | } |
Phil Nash | 1952015 | 2015-08-10 07:32:48 +0100 | [diff] [blame] | 6578 | virtual Listeners const& getListeners() const CATCH_OVERRIDE { |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6579 | return m_listeners; |
| 6580 | } |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6581 | |
| 6582 | private: |
| 6583 | FactoryMap m_factories; |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6584 | Listeners m_listeners; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6585 | }; |
| 6586 | } |
| 6587 | |
| 6588 | // #included from: catch_exception_translator_registry.hpp |
Matt Wozniski | f29c898 | 2012-09-17 01:42:29 -0400 | [diff] [blame] | 6589 | #define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6590 | |
| 6591 | #ifdef __OBJC__ |
| 6592 | #import "Foundation/Foundation.h" |
| 6593 | #endif |
| 6594 | |
| 6595 | namespace Catch { |
| 6596 | |
| 6597 | class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry { |
| 6598 | public: |
| 6599 | ~ExceptionTranslatorRegistry() { |
| 6600 | deleteAll( m_translators ); |
| 6601 | } |
| 6602 | |
| 6603 | virtual void registerTranslator( const IExceptionTranslator* translator ) { |
| 6604 | m_translators.push_back( translator ); |
| 6605 | } |
| 6606 | |
| 6607 | virtual std::string translateActiveException() const { |
| 6608 | try { |
| 6609 | #ifdef __OBJC__ |
| 6610 | // In Objective-C try objective-c exceptions first |
| 6611 | @try { |
Phil Nash | e4fa62a | 2015-11-18 08:39:54 +0000 | [diff] [blame] | 6612 | return tryTranslators(); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6613 | } |
| 6614 | @catch (NSException *exception) { |
Phil Nash | 13f9843 | 2014-12-12 08:11:18 +0000 | [diff] [blame] | 6615 | return Catch::toString( [exception description] ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6616 | } |
| 6617 | #else |
Phil Nash | e4fa62a | 2015-11-18 08:39:54 +0000 | [diff] [blame] | 6618 | return tryTranslators(); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6619 | #endif |
| 6620 | } |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 6621 | catch( TestFailureException& ) { |
| 6622 | throw; |
| 6623 | } |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6624 | catch( std::exception& ex ) { |
| 6625 | return ex.what(); |
| 6626 | } |
| 6627 | catch( std::string& msg ) { |
| 6628 | return msg; |
| 6629 | } |
| 6630 | catch( const char* msg ) { |
| 6631 | return msg; |
| 6632 | } |
| 6633 | catch(...) { |
Phil Nash | e4fa62a | 2015-11-18 08:39:54 +0000 | [diff] [blame] | 6634 | return "Unknown exception"; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6635 | } |
| 6636 | } |
| 6637 | |
Phil Nash | e4fa62a | 2015-11-18 08:39:54 +0000 | [diff] [blame] | 6638 | std::string tryTranslators() const { |
| 6639 | if( m_translators.empty() ) |
| 6640 | throw; |
| 6641 | else |
| 6642 | return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6643 | } |
| 6644 | |
| 6645 | private: |
| 6646 | std::vector<const IExceptionTranslator*> m_translators; |
| 6647 | }; |
| 6648 | } |
| 6649 | |
| 6650 | namespace Catch { |
| 6651 | |
| 6652 | namespace { |
| 6653 | |
| 6654 | class RegistryHub : public IRegistryHub, public IMutableRegistryHub { |
| 6655 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 6656 | RegistryHub( RegistryHub const& ); |
| 6657 | void operator=( RegistryHub const& ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6658 | |
| 6659 | public: // IRegistryHub |
| 6660 | RegistryHub() { |
| 6661 | } |
Phil Nash | 1952015 | 2015-08-10 07:32:48 +0100 | [diff] [blame] | 6662 | virtual IReporterRegistry const& getReporterRegistry() const CATCH_OVERRIDE { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6663 | return m_reporterRegistry; |
| 6664 | } |
Phil Nash | 1952015 | 2015-08-10 07:32:48 +0100 | [diff] [blame] | 6665 | virtual ITestCaseRegistry const& getTestCaseRegistry() const CATCH_OVERRIDE { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6666 | return m_testCaseRegistry; |
| 6667 | } |
Phil Nash | 1952015 | 2015-08-10 07:32:48 +0100 | [diff] [blame] | 6668 | virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() CATCH_OVERRIDE { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6669 | return m_exceptionTranslatorRegistry; |
| 6670 | } |
| 6671 | |
| 6672 | public: // IMutableRegistryHub |
Phil Nash | 1952015 | 2015-08-10 07:32:48 +0100 | [diff] [blame] | 6673 | virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) CATCH_OVERRIDE { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6674 | m_reporterRegistry.registerReporter( name, factory ); |
| 6675 | } |
Phil Nash | 1952015 | 2015-08-10 07:32:48 +0100 | [diff] [blame] | 6676 | virtual void registerListener( Ptr<IReporterFactory> const& factory ) CATCH_OVERRIDE { |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 6677 | m_reporterRegistry.registerListener( factory ); |
| 6678 | } |
Phil Nash | 1952015 | 2015-08-10 07:32:48 +0100 | [diff] [blame] | 6679 | virtual void registerTest( TestCase const& testInfo ) CATCH_OVERRIDE { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6680 | m_testCaseRegistry.registerTest( testInfo ); |
| 6681 | } |
Phil Nash | 1952015 | 2015-08-10 07:32:48 +0100 | [diff] [blame] | 6682 | virtual void registerTranslator( const IExceptionTranslator* translator ) CATCH_OVERRIDE { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6683 | m_exceptionTranslatorRegistry.registerTranslator( translator ); |
| 6684 | } |
| 6685 | |
| 6686 | private: |
| 6687 | TestRegistry m_testCaseRegistry; |
| 6688 | ReporterRegistry m_reporterRegistry; |
| 6689 | ExceptionTranslatorRegistry m_exceptionTranslatorRegistry; |
| 6690 | }; |
| 6691 | |
| 6692 | // Single, global, instance |
| 6693 | inline RegistryHub*& getTheRegistryHub() { |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 6694 | static RegistryHub* theRegistryHub = CATCH_NULL; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6695 | if( !theRegistryHub ) |
| 6696 | theRegistryHub = new RegistryHub(); |
| 6697 | return theRegistryHub; |
| 6698 | } |
| 6699 | } |
| 6700 | |
| 6701 | IRegistryHub& getRegistryHub() { |
| 6702 | return *getTheRegistryHub(); |
| 6703 | } |
| 6704 | IMutableRegistryHub& getMutableRegistryHub() { |
| 6705 | return *getTheRegistryHub(); |
| 6706 | } |
| 6707 | void cleanUp() { |
| 6708 | delete getTheRegistryHub(); |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 6709 | getTheRegistryHub() = CATCH_NULL; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6710 | cleanUpContext(); |
| 6711 | } |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 6712 | std::string translateActiveException() { |
| 6713 | return getRegistryHub().getExceptionTranslatorRegistry().translateActiveException(); |
| 6714 | } |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6715 | |
| 6716 | } // end namespace Catch |
Matt Wozniski | f29c898 | 2012-09-17 01:42:29 -0400 | [diff] [blame] | 6717 | |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6718 | // #included from: catch_notimplemented_exception.hpp |
| 6719 | #define TWOBLUECUBES_CATCH_NOTIMPLEMENTED_EXCEPTION_HPP_INCLUDED |
| 6720 | |
| 6721 | #include <ostream> |
| 6722 | |
| 6723 | namespace Catch { |
| 6724 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 6725 | NotImplementedException::NotImplementedException( SourceLineInfo const& lineInfo ) |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6726 | : m_lineInfo( lineInfo ) { |
| 6727 | std::ostringstream oss; |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 6728 | oss << lineInfo << ": function "; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6729 | oss << "not implemented"; |
| 6730 | m_what = oss.str(); |
| 6731 | } |
| 6732 | |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 6733 | const char* NotImplementedException::what() const CATCH_NOEXCEPT { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6734 | return m_what.c_str(); |
| 6735 | } |
| 6736 | |
| 6737 | } // end namespace Catch |
| 6738 | |
| 6739 | // #included from: catch_context_impl.hpp |
Matt Wozniski | f29c898 | 2012-09-17 01:42:29 -0400 | [diff] [blame] | 6740 | #define TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6741 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 6742 | // #included from: catch_stream.hpp |
| 6743 | #define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED |
| 6744 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 6745 | #include <stdexcept> |
| 6746 | #include <cstdio> |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 6747 | #include <iostream> |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 6748 | |
| 6749 | namespace Catch { |
| 6750 | |
| 6751 | template<typename WriterF, size_t bufferSize=256> |
| 6752 | class StreamBufImpl : public StreamBufBase { |
| 6753 | char data[bufferSize]; |
| 6754 | WriterF m_writer; |
| 6755 | |
| 6756 | public: |
| 6757 | StreamBufImpl() { |
| 6758 | setp( data, data + sizeof(data) ); |
| 6759 | } |
| 6760 | |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 6761 | ~StreamBufImpl() CATCH_NOEXCEPT { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 6762 | sync(); |
| 6763 | } |
| 6764 | |
| 6765 | private: |
| 6766 | int overflow( int c ) { |
| 6767 | sync(); |
| 6768 | |
| 6769 | if( c != EOF ) { |
| 6770 | if( pbase() == epptr() ) |
| 6771 | m_writer( std::string( 1, static_cast<char>( c ) ) ); |
| 6772 | else |
| 6773 | sputc( static_cast<char>( c ) ); |
| 6774 | } |
| 6775 | return 0; |
| 6776 | } |
| 6777 | |
| 6778 | int sync() { |
| 6779 | if( pbase() != pptr() ) { |
| 6780 | m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) ); |
| 6781 | setp( pbase(), epptr() ); |
| 6782 | } |
| 6783 | return 0; |
| 6784 | } |
| 6785 | }; |
| 6786 | |
| 6787 | /////////////////////////////////////////////////////////////////////////// |
| 6788 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6789 | FileStream::FileStream( std::string const& filename ) { |
| 6790 | m_ofs.open( filename.c_str() ); |
| 6791 | if( m_ofs.fail() ) { |
| 6792 | std::ostringstream oss; |
| 6793 | oss << "Unable to open file: '" << filename << "'"; |
| 6794 | throw std::domain_error( oss.str() ); |
| 6795 | } |
| 6796 | } |
| 6797 | |
| 6798 | std::ostream& FileStream::stream() const { |
| 6799 | return m_ofs; |
| 6800 | } |
| 6801 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 6802 | struct OutputDebugWriter { |
| 6803 | |
| 6804 | void operator()( std::string const&str ) { |
| 6805 | writeToDebugConsole( str ); |
| 6806 | } |
| 6807 | }; |
| 6808 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6809 | DebugOutStream::DebugOutStream() |
| 6810 | : m_streamBuf( new StreamBufImpl<OutputDebugWriter>() ), |
| 6811 | m_os( m_streamBuf.get() ) |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 6812 | {} |
| 6813 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6814 | std::ostream& DebugOutStream::stream() const { |
| 6815 | return m_os; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 6816 | } |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 6817 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6818 | // Store the streambuf from cout up-front because |
| 6819 | // cout may get redirected when running tests |
| 6820 | CoutStream::CoutStream() |
| 6821 | : m_os( Catch::cout().rdbuf() ) |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 6822 | {} |
| 6823 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 6824 | std::ostream& CoutStream::stream() const { |
| 6825 | return m_os; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 6826 | } |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 6827 | |
Phil Nash | fdc42d0 | 2015-12-04 10:19:08 +0000 | [diff] [blame] | 6828 | #ifndef CATCH_CONFIG_NOSTDOUT // If you #define this you must implement these functions |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 6829 | std::ostream& cout() { |
| 6830 | return std::cout; |
| 6831 | } |
| 6832 | std::ostream& cerr() { |
| 6833 | return std::cerr; |
| 6834 | } |
| 6835 | #endif |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 6836 | } |
| 6837 | |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6838 | namespace Catch { |
| 6839 | |
| 6840 | class Context : public IMutableContext { |
| 6841 | |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 6842 | Context() : m_config( CATCH_NULL ), m_runner( CATCH_NULL ), m_resultCapture( CATCH_NULL ) {} |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 6843 | Context( Context const& ); |
| 6844 | void operator=( Context const& ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6845 | |
| 6846 | public: // IContext |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 6847 | virtual IResultCapture* getResultCapture() { |
| 6848 | return m_resultCapture; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6849 | } |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 6850 | virtual IRunner* getRunner() { |
| 6851 | return m_runner; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6852 | } |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 6853 | virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6854 | return getGeneratorsForCurrentTest() |
| 6855 | .getGeneratorInfo( fileInfo, totalSize ) |
| 6856 | .getCurrentIndex(); |
| 6857 | } |
| 6858 | virtual bool advanceGeneratorsForCurrentTest() { |
| 6859 | IGeneratorsForTest* generators = findGeneratorsForCurrentTest(); |
| 6860 | return generators && generators->moveNext(); |
| 6861 | } |
| 6862 | |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6863 | virtual Ptr<IConfig const> getConfig() const { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6864 | return m_config; |
| 6865 | } |
| 6866 | |
| 6867 | public: // IMutableContext |
| 6868 | virtual void setResultCapture( IResultCapture* resultCapture ) { |
| 6869 | m_resultCapture = resultCapture; |
| 6870 | } |
| 6871 | virtual void setRunner( IRunner* runner ) { |
| 6872 | m_runner = runner; |
| 6873 | } |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 6874 | virtual void setConfig( Ptr<IConfig const> const& config ) { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6875 | m_config = config; |
| 6876 | } |
| 6877 | |
| 6878 | friend IMutableContext& getCurrentMutableContext(); |
| 6879 | |
| 6880 | private: |
| 6881 | IGeneratorsForTest* findGeneratorsForCurrentTest() { |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 6882 | std::string testName = getResultCapture()->getCurrentTestName(); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6883 | |
| 6884 | std::map<std::string, IGeneratorsForTest*>::const_iterator it = |
Phil Nash | a806c3e | 2015-03-04 08:23:40 +0000 | [diff] [blame] | 6885 | m_generatorsByTestName.find( testName ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6886 | return it != m_generatorsByTestName.end() |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 6887 | ? it->second |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 6888 | : CATCH_NULL; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6889 | } |
| 6890 | |
| 6891 | IGeneratorsForTest& getGeneratorsForCurrentTest() { |
| 6892 | IGeneratorsForTest* generators = findGeneratorsForCurrentTest(); |
| 6893 | if( !generators ) { |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 6894 | std::string testName = getResultCapture()->getCurrentTestName(); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6895 | generators = createGeneratorsForTest(); |
| 6896 | m_generatorsByTestName.insert( std::make_pair( testName, generators ) ); |
| 6897 | } |
| 6898 | return *generators; |
| 6899 | } |
| 6900 | |
| 6901 | private: |
Phil Nash | 93a945c | 2013-10-23 15:35:07 +0100 | [diff] [blame] | 6902 | Ptr<IConfig const> m_config; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6903 | IRunner* m_runner; |
| 6904 | IResultCapture* m_resultCapture; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6905 | std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName; |
| 6906 | }; |
| 6907 | |
| 6908 | namespace { |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 6909 | Context* currentContext = CATCH_NULL; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6910 | } |
| 6911 | IMutableContext& getCurrentMutableContext() { |
| 6912 | if( !currentContext ) |
| 6913 | currentContext = new Context(); |
| 6914 | return *currentContext; |
| 6915 | } |
| 6916 | IContext& getCurrentContext() { |
| 6917 | return getCurrentMutableContext(); |
| 6918 | } |
| 6919 | |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6920 | void cleanUpContext() { |
| 6921 | delete currentContext; |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 6922 | currentContext = CATCH_NULL; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6923 | } |
| 6924 | } |
Matt Wozniski | f29c898 | 2012-09-17 01:42:29 -0400 | [diff] [blame] | 6925 | |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6926 | // #included from: catch_console_colour_impl.hpp |
| 6927 | #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED |
| 6928 | |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 6929 | namespace Catch { |
| 6930 | namespace { |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 6931 | |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 6932 | struct IColourImpl { |
| 6933 | virtual ~IColourImpl() {} |
| 6934 | virtual void use( Colour::Code _colourCode ) = 0; |
| 6935 | }; |
| 6936 | |
| 6937 | struct NoColourImpl : IColourImpl { |
| 6938 | void use( Colour::Code ) {} |
| 6939 | |
| 6940 | static IColourImpl* instance() { |
| 6941 | static NoColourImpl s_instance; |
| 6942 | return &s_instance; |
| 6943 | } |
| 6944 | }; |
| 6945 | |
| 6946 | } // anon namespace |
| 6947 | } // namespace Catch |
| 6948 | |
| 6949 | #if !defined( CATCH_CONFIG_COLOUR_NONE ) && !defined( CATCH_CONFIG_COLOUR_WINDOWS ) && !defined( CATCH_CONFIG_COLOUR_ANSI ) |
| 6950 | # ifdef CATCH_PLATFORM_WINDOWS |
| 6951 | # define CATCH_CONFIG_COLOUR_WINDOWS |
| 6952 | # else |
| 6953 | # define CATCH_CONFIG_COLOUR_ANSI |
| 6954 | # endif |
| 6955 | #endif |
| 6956 | |
| 6957 | #if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) ///////////////////////////////////////// |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6958 | |
Phil Nash | 4b5e008 | 2013-06-29 20:31:17 +0100 | [diff] [blame] | 6959 | #ifndef NOMINMAX |
Phil Nash | 2352043 | 2013-06-28 14:11:28 +0100 | [diff] [blame] | 6960 | #define NOMINMAX |
Phil Nash | 4b5e008 | 2013-06-29 20:31:17 +0100 | [diff] [blame] | 6961 | #endif |
Phil Nash | 3907559 | 2013-07-01 19:02:29 +0100 | [diff] [blame] | 6962 | |
| 6963 | #ifdef __AFXDLL |
| 6964 | #include <AfxWin.h> |
| 6965 | #else |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6966 | #include <windows.h> |
Phil Nash | 3907559 | 2013-07-01 19:02:29 +0100 | [diff] [blame] | 6967 | #endif |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6968 | |
| 6969 | namespace Catch { |
Phil Nash | 3df6c0d | 2013-03-11 18:38:29 +0000 | [diff] [blame] | 6970 | namespace { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6971 | |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 6972 | class Win32ColourImpl : public IColourImpl { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6973 | public: |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 6974 | Win32ColourImpl() : stdoutHandle( GetStdHandle(STD_OUTPUT_HANDLE) ) |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6975 | { |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 6976 | CONSOLE_SCREEN_BUFFER_INFO csbiInfo; |
| 6977 | GetConsoleScreenBufferInfo( stdoutHandle, &csbiInfo ); |
Phil Nash | 584032d | 2015-07-06 06:22:28 +0100 | [diff] [blame] | 6978 | originalForegroundAttributes = csbiInfo.wAttributes & ~( BACKGROUND_GREEN | BACKGROUND_RED | BACKGROUND_BLUE | BACKGROUND_INTENSITY ); |
| 6979 | originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6980 | } |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6981 | |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 6982 | virtual void use( Colour::Code _colourCode ) { |
| 6983 | switch( _colourCode ) { |
Phil Nash | 584032d | 2015-07-06 06:22:28 +0100 | [diff] [blame] | 6984 | case Colour::None: return setTextAttribute( originalForegroundAttributes ); |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 6985 | case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); |
| 6986 | case Colour::Red: return setTextAttribute( FOREGROUND_RED ); |
| 6987 | case Colour::Green: return setTextAttribute( FOREGROUND_GREEN ); |
| 6988 | case Colour::Blue: return setTextAttribute( FOREGROUND_BLUE ); |
| 6989 | case Colour::Cyan: return setTextAttribute( FOREGROUND_BLUE | FOREGROUND_GREEN ); |
| 6990 | case Colour::Yellow: return setTextAttribute( FOREGROUND_RED | FOREGROUND_GREEN ); |
| 6991 | case Colour::Grey: return setTextAttribute( 0 ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6992 | |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 6993 | case Colour::LightGrey: return setTextAttribute( FOREGROUND_INTENSITY ); |
| 6994 | case Colour::BrightRed: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_RED ); |
| 6995 | case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN ); |
Phil Nash | 2352043 | 2013-06-28 14:11:28 +0100 | [diff] [blame] | 6996 | case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 6997 | |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 6998 | case Colour::Bright: throw std::logic_error( "not a colour" ); |
| 6999 | } |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7000 | } |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7001 | |
| 7002 | private: |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 7003 | void setTextAttribute( WORD _textAttribute ) { |
Phil Nash | 584032d | 2015-07-06 06:22:28 +0100 | [diff] [blame] | 7004 | SetConsoleTextAttribute( stdoutHandle, _textAttribute | originalBackgroundAttributes ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7005 | } |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 7006 | HANDLE stdoutHandle; |
Phil Nash | 584032d | 2015-07-06 06:22:28 +0100 | [diff] [blame] | 7007 | WORD originalForegroundAttributes; |
| 7008 | WORD originalBackgroundAttributes; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7009 | }; |
| 7010 | |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 7011 | IColourImpl* platformColourInstance() { |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 7012 | static Win32ColourImpl s_instance; |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 7013 | |
| 7014 | Ptr<IConfig const> config = getCurrentContext().getConfig(); |
| 7015 | UseColour::YesOrNo colourMode = config |
| 7016 | ? config->useColour() |
| 7017 | : UseColour::Auto; |
| 7018 | if( colourMode == UseColour::Auto ) |
| 7019 | colourMode = !isDebuggerActive() |
| 7020 | ? UseColour::Yes |
| 7021 | : UseColour::No; |
| 7022 | return colourMode == UseColour::Yes |
| 7023 | ? &s_instance |
| 7024 | : NoColourImpl::instance(); |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 7025 | } |
Phil Nash | 3df6c0d | 2013-03-11 18:38:29 +0000 | [diff] [blame] | 7026 | |
| 7027 | } // end anon namespace |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7028 | } // end namespace Catch |
| 7029 | |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 7030 | #elif defined( CATCH_CONFIG_COLOUR_ANSI ) ////////////////////////////////////// |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7031 | |
| 7032 | #include <unistd.h> |
| 7033 | |
| 7034 | namespace Catch { |
Phil Nash | 3df6c0d | 2013-03-11 18:38:29 +0000 | [diff] [blame] | 7035 | namespace { |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7036 | |
| 7037 | // use POSIX/ ANSI console terminal codes |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 7038 | // Thanks to Adam Strzelecki for original contribution |
| 7039 | // (http://github.com/nanoant) |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7040 | // https://github.com/philsquared/Catch/pull/131 |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 7041 | class PosixColourImpl : public IColourImpl { |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 7042 | public: |
| 7043 | virtual void use( Colour::Code _colourCode ) { |
| 7044 | switch( _colourCode ) { |
| 7045 | case Colour::None: |
| 7046 | case Colour::White: return setColour( "[0m" ); |
| 7047 | case Colour::Red: return setColour( "[0;31m" ); |
| 7048 | case Colour::Green: return setColour( "[0;32m" ); |
| 7049 | case Colour::Blue: return setColour( "[0:34m" ); |
| 7050 | case Colour::Cyan: return setColour( "[0;36m" ); |
| 7051 | case Colour::Yellow: return setColour( "[0;33m" ); |
| 7052 | case Colour::Grey: return setColour( "[1;30m" ); |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7053 | |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 7054 | case Colour::LightGrey: return setColour( "[0;37m" ); |
| 7055 | case Colour::BrightRed: return setColour( "[1;31m" ); |
Phil Nash | 243f2d2 | 2013-04-12 10:43:06 +0100 | [diff] [blame] | 7056 | case Colour::BrightGreen: return setColour( "[1;32m" ); |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 7057 | case Colour::BrightWhite: return setColour( "[1;37m" ); |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7058 | |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 7059 | case Colour::Bright: throw std::logic_error( "not a colour" ); |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7060 | } |
| 7061 | } |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 7062 | static IColourImpl* instance() { |
| 7063 | static PosixColourImpl s_instance; |
| 7064 | return &s_instance; |
| 7065 | } |
| 7066 | |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 7067 | private: |
| 7068 | void setColour( const char* _escapeCode ) { |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 7069 | Catch::cout() << '\033' << _escapeCode; |
Phil Nash | 3df6c0d | 2013-03-11 18:38:29 +0000 | [diff] [blame] | 7070 | } |
| 7071 | }; |
| 7072 | |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 7073 | IColourImpl* platformColourInstance() { |
Phil Nash | a806c3e | 2015-03-04 08:23:40 +0000 | [diff] [blame] | 7074 | Ptr<IConfig const> config = getCurrentContext().getConfig(); |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 7075 | UseColour::YesOrNo colourMode = config |
| 7076 | ? config->useColour() |
| 7077 | : UseColour::Auto; |
| 7078 | if( colourMode == UseColour::Auto ) |
| 7079 | colourMode = (!isDebuggerActive() && isatty(STDOUT_FILENO) ) |
| 7080 | ? UseColour::Yes |
| 7081 | : UseColour::No; |
| 7082 | return colourMode == UseColour::Yes |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 7083 | ? PosixColourImpl::instance() |
| 7084 | : NoColourImpl::instance(); |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 7085 | } |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7086 | |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 7087 | } // end anon namespace |
| 7088 | } // end namespace Catch |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7089 | |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 7090 | #else // not Windows or ANSI /////////////////////////////////////////////// |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7091 | |
| 7092 | namespace Catch { |
| 7093 | |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 7094 | static IColourImpl* platformColourInstance() { return NoColourImpl::instance(); } |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 7095 | |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 7096 | } // end namespace Catch |
| 7097 | |
| 7098 | #endif // Windows/ ANSI/ None |
| 7099 | |
| 7100 | namespace Catch { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7101 | |
Phil Nash | ce56209 | 2014-07-09 07:40:37 +0100 | [diff] [blame] | 7102 | Colour::Colour( Code _colourCode ) : m_moved( false ) { use( _colourCode ); } |
| 7103 | Colour::Colour( Colour const& _other ) : m_moved( false ) { const_cast<Colour&>( _other ).m_moved = true; } |
| 7104 | Colour::~Colour(){ if( !m_moved ) use( None ); } |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7105 | |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 7106 | void Colour::use( Code _colourCode ) { |
Phil Nash | ae5ee2c | 2016-02-29 08:17:18 +0000 | [diff] [blame] | 7107 | static IColourImpl* impl = platformColourInstance(); |
Phil Nash | e54ac70 | 2014-10-21 07:25:26 +0100 | [diff] [blame] | 7108 | impl->use( _colourCode ); |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 7109 | } |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7110 | |
| 7111 | } // end namespace Catch |
| 7112 | |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7113 | // #included from: catch_generators_impl.hpp |
| 7114 | #define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED |
| 7115 | |
| 7116 | #include <vector> |
| 7117 | #include <string> |
| 7118 | #include <map> |
| 7119 | |
| 7120 | namespace Catch { |
| 7121 | |
| 7122 | struct GeneratorInfo : IGeneratorInfo { |
| 7123 | |
| 7124 | GeneratorInfo( std::size_t size ) |
| 7125 | : m_size( size ), |
| 7126 | m_currentIndex( 0 ) |
| 7127 | {} |
| 7128 | |
| 7129 | bool moveNext() { |
| 7130 | if( ++m_currentIndex == m_size ) { |
| 7131 | m_currentIndex = 0; |
| 7132 | return false; |
| 7133 | } |
| 7134 | return true; |
| 7135 | } |
| 7136 | |
| 7137 | std::size_t getCurrentIndex() const { |
| 7138 | return m_currentIndex; |
| 7139 | } |
| 7140 | |
| 7141 | std::size_t m_size; |
| 7142 | std::size_t m_currentIndex; |
| 7143 | }; |
| 7144 | |
| 7145 | /////////////////////////////////////////////////////////////////////////// |
| 7146 | |
| 7147 | class GeneratorsForTest : public IGeneratorsForTest { |
| 7148 | |
| 7149 | public: |
| 7150 | ~GeneratorsForTest() { |
| 7151 | deleteAll( m_generatorsInOrder ); |
| 7152 | } |
| 7153 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 7154 | IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) { |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7155 | std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo ); |
| 7156 | if( it == m_generatorsByName.end() ) { |
| 7157 | IGeneratorInfo* info = new GeneratorInfo( size ); |
| 7158 | m_generatorsByName.insert( std::make_pair( fileInfo, info ) ); |
| 7159 | m_generatorsInOrder.push_back( info ); |
| 7160 | return *info; |
| 7161 | } |
| 7162 | return *it->second; |
| 7163 | } |
| 7164 | |
| 7165 | bool moveNext() { |
| 7166 | std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin(); |
| 7167 | std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end(); |
| 7168 | for(; it != itEnd; ++it ) { |
| 7169 | if( (*it)->moveNext() ) |
| 7170 | return true; |
| 7171 | } |
| 7172 | return false; |
| 7173 | } |
| 7174 | |
| 7175 | private: |
| 7176 | std::map<std::string, IGeneratorInfo*> m_generatorsByName; |
| 7177 | std::vector<IGeneratorInfo*> m_generatorsInOrder; |
| 7178 | }; |
| 7179 | |
| 7180 | IGeneratorsForTest* createGeneratorsForTest() |
| 7181 | { |
| 7182 | return new GeneratorsForTest(); |
| 7183 | } |
| 7184 | |
| 7185 | } // end namespace Catch |
| 7186 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7187 | // #included from: catch_assertionresult.hpp |
| 7188 | #define TWOBLUECUBES_CATCH_ASSERTIONRESULT_HPP_INCLUDED |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7189 | |
| 7190 | namespace Catch { |
| 7191 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 7192 | AssertionInfo::AssertionInfo( std::string const& _macroName, |
| 7193 | SourceLineInfo const& _lineInfo, |
| 7194 | std::string const& _capturedExpression, |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 7195 | ResultDisposition::Flags _resultDisposition ) |
| 7196 | : macroName( _macroName ), |
| 7197 | lineInfo( _lineInfo ), |
| 7198 | capturedExpression( _capturedExpression ), |
| 7199 | resultDisposition( _resultDisposition ) |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 7200 | {} |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 7201 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7202 | AssertionResult::AssertionResult() {} |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7203 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 7204 | AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data ) |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7205 | : m_info( info ), |
| 7206 | m_resultData( data ) |
| 7207 | {} |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7208 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7209 | AssertionResult::~AssertionResult() {} |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7210 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 7211 | // Result was a success |
| 7212 | bool AssertionResult::succeeded() const { |
| 7213 | return Catch::isOk( m_resultData.resultType ); |
| 7214 | } |
| 7215 | |
| 7216 | // Result was a success, or failure is suppressed |
| 7217 | bool AssertionResult::isOk() const { |
| 7218 | return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition ); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7219 | } |
| 7220 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7221 | ResultWas::OfType AssertionResult::getResultType() const { |
| 7222 | return m_resultData.resultType; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7223 | } |
| 7224 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7225 | bool AssertionResult::hasExpression() const { |
| 7226 | return !m_info.capturedExpression.empty(); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7227 | } |
| 7228 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7229 | bool AssertionResult::hasMessage() const { |
| 7230 | return !m_resultData.message.empty(); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7231 | } |
| 7232 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7233 | std::string AssertionResult::getExpression() const { |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 7234 | if( isFalseTest( m_info.resultDisposition ) ) |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 7235 | return "!" + m_info.capturedExpression; |
| 7236 | else |
| 7237 | return m_info.capturedExpression; |
| 7238 | } |
| 7239 | std::string AssertionResult::getExpressionInMacro() const { |
| 7240 | if( m_info.macroName.empty() ) |
| 7241 | return m_info.capturedExpression; |
| 7242 | else |
| 7243 | return m_info.macroName + "( " + m_info.capturedExpression + " )"; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7244 | } |
| 7245 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7246 | bool AssertionResult::hasExpandedExpression() const { |
Phil Nash | 6730512 | 2012-10-09 11:48:55 +0100 | [diff] [blame] | 7247 | return hasExpression() && getExpandedExpression() != getExpression(); |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7248 | } |
| 7249 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7250 | std::string AssertionResult::getExpandedExpression() const { |
| 7251 | return m_resultData.reconstructedExpression; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7252 | } |
| 7253 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7254 | std::string AssertionResult::getMessage() const { |
| 7255 | return m_resultData.message; |
| 7256 | } |
| 7257 | SourceLineInfo AssertionResult::getSourceInfo() const { |
| 7258 | return m_info.lineInfo; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7259 | } |
| 7260 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 7261 | std::string AssertionResult::getTestMacroName() const { |
| 7262 | return m_info.macroName; |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 7263 | } |
| 7264 | |
| 7265 | } // end namespace Catch |
| 7266 | |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 7267 | // #included from: catch_test_case_info.hpp |
Matt Wozniski | f29c898 | 2012-09-17 01:42:29 -0400 | [diff] [blame] | 7268 | #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_HPP_INCLUDED |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 7269 | |
| 7270 | namespace Catch { |
| 7271 | |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 7272 | inline TestCaseInfo::SpecialProperties parseSpecialTag( std::string const& tag ) { |
Phil Nash | 91c17f3 | 2014-12-15 07:26:31 +0000 | [diff] [blame] | 7273 | if( startsWith( tag, "." ) || |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 7274 | tag == "hide" || |
| 7275 | tag == "!hide" ) |
| 7276 | return TestCaseInfo::IsHidden; |
| 7277 | else if( tag == "!throws" ) |
| 7278 | return TestCaseInfo::Throws; |
| 7279 | else if( tag == "!shouldfail" ) |
| 7280 | return TestCaseInfo::ShouldFail; |
| 7281 | else if( tag == "!mayfail" ) |
| 7282 | return TestCaseInfo::MayFail; |
| 7283 | else |
| 7284 | return TestCaseInfo::None; |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 7285 | } |
| 7286 | inline bool isReservedTag( std::string const& tag ) { |
Phil Nash | 37e5561 | 2015-03-27 18:02:28 +0000 | [diff] [blame] | 7287 | return parseSpecialTag( tag ) == TestCaseInfo::None && tag.size() > 0 && !isalnum( tag[0] ); |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 7288 | } |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 7289 | inline void enforceNotReservedTag( std::string const& tag, SourceLineInfo const& _lineInfo ) { |
| 7290 | if( isReservedTag( tag ) ) { |
| 7291 | { |
| 7292 | Colour colourGuard( Colour::Red ); |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 7293 | Catch::cerr() |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 7294 | << "Tag name [" << tag << "] not allowed.\n" |
| 7295 | << "Tag names starting with non alpha-numeric characters are reserved\n"; |
| 7296 | } |
| 7297 | { |
| 7298 | Colour colourGuard( Colour::FileName ); |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 7299 | Catch::cerr() << _lineInfo << std::endl; |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 7300 | } |
| 7301 | exit(1); |
| 7302 | } |
| 7303 | } |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 7304 | |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 7305 | TestCase makeTestCase( ITestCase* _testCase, |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 7306 | std::string const& _className, |
| 7307 | std::string const& _name, |
| 7308 | std::string const& _descOrTags, |
| 7309 | SourceLineInfo const& _lineInfo ) |
Phil Nash | fc1baac | 2012-09-15 17:53:27 +0100 | [diff] [blame] | 7310 | { |
Phil Nash | 5ecb72b | 2013-11-26 20:57:45 +0000 | [diff] [blame] | 7311 | bool isHidden( startsWith( _name, "./" ) ); // Legacy support |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 7312 | |
| 7313 | // Parse out tags |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 7314 | std::set<std::string> tags; |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 7315 | std::string desc, tag; |
| 7316 | bool inTag = false; |
| 7317 | for( std::size_t i = 0; i < _descOrTags.size(); ++i ) { |
| 7318 | char c = _descOrTags[i]; |
| 7319 | if( !inTag ) { |
| 7320 | if( c == '[' ) |
| 7321 | inTag = true; |
| 7322 | else |
| 7323 | desc += c; |
Phil Nash | 20cad7c | 2014-04-15 18:44:37 +0100 | [diff] [blame] | 7324 | } |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 7325 | else { |
| 7326 | if( c == ']' ) { |
Phil Nash | 91c17f3 | 2014-12-15 07:26:31 +0000 | [diff] [blame] | 7327 | TestCaseInfo::SpecialProperties prop = parseSpecialTag( tag ); |
| 7328 | if( prop == TestCaseInfo::IsHidden ) |
Phil Nash | ebd4888 | 2014-05-19 18:22:59 +0100 | [diff] [blame] | 7329 | isHidden = true; |
Phil Nash | 91c17f3 | 2014-12-15 07:26:31 +0000 | [diff] [blame] | 7330 | else if( prop == TestCaseInfo::None ) |
| 7331 | enforceNotReservedTag( tag, _lineInfo ); |
| 7332 | |
| 7333 | tags.insert( tag ); |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 7334 | tag.clear(); |
Phil Nash | 91c17f3 | 2014-12-15 07:26:31 +0000 | [diff] [blame] | 7335 | inTag = false; |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 7336 | } |
| 7337 | else |
| 7338 | tag += c; |
| 7339 | } |
Phil Nash | de49ec4 | 2013-12-04 20:25:14 +0000 | [diff] [blame] | 7340 | } |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 7341 | if( isHidden ) { |
| 7342 | tags.insert( "hide" ); |
| 7343 | tags.insert( "." ); |
| 7344 | } |
| 7345 | |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 7346 | TestCaseInfo info( _name, _className, desc, tags, _lineInfo ); |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 7347 | return TestCase( _testCase, info ); |
Phil Nash | fc1baac | 2012-09-15 17:53:27 +0100 | [diff] [blame] | 7348 | } |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 7349 | |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 7350 | void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags ) |
| 7351 | { |
| 7352 | testCaseInfo.tags = tags; |
| 7353 | testCaseInfo.lcaseTags.clear(); |
| 7354 | |
| 7355 | std::ostringstream oss; |
| 7356 | for( std::set<std::string>::const_iterator it = tags.begin(), itEnd = tags.end(); it != itEnd; ++it ) { |
| 7357 | oss << "[" << *it << "]"; |
| 7358 | std::string lcaseTag = toLower( *it ); |
| 7359 | testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) ); |
| 7360 | testCaseInfo.lcaseTags.insert( lcaseTag ); |
| 7361 | } |
| 7362 | testCaseInfo.tagsAsString = oss.str(); |
| 7363 | } |
| 7364 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 7365 | TestCaseInfo::TestCaseInfo( std::string const& _name, |
| 7366 | std::string const& _className, |
| 7367 | std::string const& _description, |
| 7368 | std::set<std::string> const& _tags, |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 7369 | SourceLineInfo const& _lineInfo ) |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 7370 | : name( _name ), |
| 7371 | className( _className ), |
| 7372 | description( _description ), |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 7373 | lineInfo( _lineInfo ), |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 7374 | properties( None ) |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 7375 | { |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 7376 | setTags( *this, _tags ); |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 7377 | } |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 7378 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 7379 | TestCaseInfo::TestCaseInfo( TestCaseInfo const& other ) |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 7380 | : name( other.name ), |
| 7381 | className( other.className ), |
| 7382 | description( other.description ), |
| 7383 | tags( other.tags ), |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 7384 | lcaseTags( other.lcaseTags ), |
Phil Nash | 38f7eef | 2013-03-29 13:44:33 +0000 | [diff] [blame] | 7385 | tagsAsString( other.tagsAsString ), |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 7386 | lineInfo( other.lineInfo ), |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 7387 | properties( other.properties ) |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 7388 | {} |
| 7389 | |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 7390 | bool TestCaseInfo::isHidden() const { |
| 7391 | return ( properties & IsHidden ) != 0; |
| 7392 | } |
| 7393 | bool TestCaseInfo::throws() const { |
| 7394 | return ( properties & Throws ) != 0; |
| 7395 | } |
| 7396 | bool TestCaseInfo::okToFail() const { |
| 7397 | return ( properties & (ShouldFail | MayFail ) ) != 0; |
| 7398 | } |
| 7399 | bool TestCaseInfo::expectedToFail() const { |
| 7400 | return ( properties & (ShouldFail ) ) != 0; |
| 7401 | } |
| 7402 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 7403 | TestCase::TestCase( ITestCase* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {} |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 7404 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 7405 | TestCase::TestCase( TestCase const& other ) |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 7406 | : TestCaseInfo( other ), |
| 7407 | test( other.test ) |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 7408 | {} |
| 7409 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 7410 | TestCase TestCase::withName( std::string const& _newName ) const { |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 7411 | TestCase other( *this ); |
| 7412 | other.name = _newName; |
| 7413 | return other; |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 7414 | } |
| 7415 | |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 7416 | void TestCase::swap( TestCase& other ) { |
| 7417 | test.swap( other.test ); |
| 7418 | name.swap( other.name ); |
| 7419 | className.swap( other.className ); |
| 7420 | description.swap( other.description ); |
| 7421 | tags.swap( other.tags ); |
| 7422 | lcaseTags.swap( other.lcaseTags ); |
| 7423 | tagsAsString.swap( other.tagsAsString ); |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 7424 | std::swap( TestCaseInfo::properties, static_cast<TestCaseInfo&>( other ).properties ); |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 7425 | std::swap( lineInfo, other.lineInfo ); |
| 7426 | } |
| 7427 | |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 7428 | void TestCase::invoke() const { |
| 7429 | test->invoke(); |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 7430 | } |
| 7431 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 7432 | bool TestCase::operator == ( TestCase const& other ) const { |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 7433 | return test.get() == other.test.get() && |
| 7434 | name == other.name && |
| 7435 | className == other.className; |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 7436 | } |
| 7437 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 7438 | bool TestCase::operator < ( TestCase const& other ) const { |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 7439 | return name < other.name; |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 7440 | } |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 7441 | TestCase& TestCase::operator = ( TestCase const& other ) { |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 7442 | TestCase temp( other ); |
Phil Nash | d2ec849 | 2012-08-23 19:48:57 +0100 | [diff] [blame] | 7443 | swap( temp ); |
| 7444 | return *this; |
| 7445 | } |
Phil Nash | 799ecf9 | 2012-09-24 08:30:13 +0100 | [diff] [blame] | 7446 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 7447 | TestCaseInfo const& TestCase::getTestCaseInfo() const |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 7448 | { |
| 7449 | return *this; |
| 7450 | } |
| 7451 | |
Phil Nash | 799ecf9 | 2012-09-24 08:30:13 +0100 | [diff] [blame] | 7452 | } // end namespace Catch |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 7453 | |
Phil Nash | 7673a30 | 2012-11-15 22:15:41 +0000 | [diff] [blame] | 7454 | // #included from: catch_version.hpp |
| 7455 | #define TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED |
| 7456 | |
| 7457 | namespace Catch { |
| 7458 | |
Phil Nash | 21f7ef6 | 2015-06-29 18:05:23 +0100 | [diff] [blame] | 7459 | Version::Version |
| 7460 | ( unsigned int _majorVersion, |
| 7461 | unsigned int _minorVersion, |
| 7462 | unsigned int _patchNumber, |
| 7463 | std::string const& _branchName, |
| 7464 | unsigned int _buildNumber ) |
| 7465 | : majorVersion( _majorVersion ), |
| 7466 | minorVersion( _minorVersion ), |
| 7467 | patchNumber( _patchNumber ), |
| 7468 | branchName( _branchName ), |
| 7469 | buildNumber( _buildNumber ) |
| 7470 | {} |
| 7471 | |
| 7472 | std::ostream& operator << ( std::ostream& os, Version const& version ) { |
| 7473 | os << version.majorVersion << "." |
| 7474 | << version.minorVersion << "." |
| 7475 | << version.patchNumber; |
| 7476 | |
| 7477 | if( !version.branchName.empty() ) { |
| 7478 | os << "-" << version.branchName |
| 7479 | << "." << version.buildNumber; |
| 7480 | } |
| 7481 | return os; |
| 7482 | } |
| 7483 | |
Phil Nash | 02af70e | 2016-03-11 18:31:52 +0000 | [diff] [blame^] | 7484 | Version libraryVersion( 1, 3, 6, "", 0 ); |
Phil Nash | 21f7ef6 | 2015-06-29 18:05:23 +0100 | [diff] [blame] | 7485 | |
Phil Nash | 7673a30 | 2012-11-15 22:15:41 +0000 | [diff] [blame] | 7486 | } |
| 7487 | |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 7488 | // #included from: catch_message.hpp |
| 7489 | #define TWOBLUECUBES_CATCH_MESSAGE_HPP_INCLUDED |
| 7490 | |
| 7491 | namespace Catch { |
| 7492 | |
| 7493 | MessageInfo::MessageInfo( std::string const& _macroName, |
| 7494 | SourceLineInfo const& _lineInfo, |
| 7495 | ResultWas::OfType _type ) |
| 7496 | : macroName( _macroName ), |
| 7497 | lineInfo( _lineInfo ), |
| 7498 | type( _type ), |
| 7499 | sequence( ++globalCount ) |
| 7500 | {} |
| 7501 | |
| 7502 | // This may need protecting if threading support is added |
| 7503 | unsigned int MessageInfo::globalCount = 0; |
| 7504 | |
| 7505 | //////////////////////////////////////////////////////////////////////////// |
| 7506 | |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 7507 | ScopedMessage::ScopedMessage( MessageBuilder const& builder ) |
| 7508 | : m_info( builder.m_info ) |
| 7509 | { |
| 7510 | m_info.message = builder.m_stream.str(); |
| 7511 | getResultCapture().pushScopedMessage( m_info ); |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 7512 | } |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 7513 | ScopedMessage::ScopedMessage( ScopedMessage const& other ) |
| 7514 | : m_info( other.m_info ) |
| 7515 | {} |
| 7516 | |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 7517 | ScopedMessage::~ScopedMessage() { |
| 7518 | getResultCapture().popScopedMessage( m_info ); |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 7519 | } |
| 7520 | |
| 7521 | } // end namespace Catch |
| 7522 | |
Phil Nash | 243f2d2 | 2013-04-12 10:43:06 +0100 | [diff] [blame] | 7523 | // #included from: catch_legacy_reporter_adapter.hpp |
Phil Nash | 8764177 | 2013-04-08 11:50:41 +0100 | [diff] [blame] | 7524 | #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED |
| 7525 | |
| 7526 | // #included from: catch_legacy_reporter_adapter.h |
| 7527 | #define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED |
| 7528 | |
| 7529 | namespace Catch |
| 7530 | { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 7531 | // Deprecated |
| 7532 | struct IReporter : IShared { |
| 7533 | virtual ~IReporter(); |
| 7534 | |
| 7535 | virtual bool shouldRedirectStdout() const = 0; |
| 7536 | |
| 7537 | virtual void StartTesting() = 0; |
| 7538 | virtual void EndTesting( Totals const& totals ) = 0; |
| 7539 | virtual void StartGroup( std::string const& groupName ) = 0; |
| 7540 | virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0; |
| 7541 | virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0; |
| 7542 | virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0; |
| 7543 | virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0; |
| 7544 | virtual void EndSection( std::string const& sectionName, Counts const& assertions ) = 0; |
| 7545 | virtual void NoAssertionsInSection( std::string const& sectionName ) = 0; |
| 7546 | virtual void NoAssertionsInTestCase( std::string const& testName ) = 0; |
| 7547 | virtual void Aborted() = 0; |
| 7548 | virtual void Result( AssertionResult const& result ) = 0; |
| 7549 | }; |
| 7550 | |
Phil Nash | 8764177 | 2013-04-08 11:50:41 +0100 | [diff] [blame] | 7551 | class LegacyReporterAdapter : public SharedImpl<IStreamingReporter> |
| 7552 | { |
| 7553 | public: |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 7554 | LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter ); |
Phil Nash | 8764177 | 2013-04-08 11:50:41 +0100 | [diff] [blame] | 7555 | virtual ~LegacyReporterAdapter(); |
| 7556 | |
| 7557 | virtual ReporterPreferences getPreferences() const; |
| 7558 | virtual void noMatchingTestCases( std::string const& ); |
| 7559 | virtual void testRunStarting( TestRunInfo const& ); |
| 7560 | virtual void testGroupStarting( GroupInfo const& groupInfo ); |
| 7561 | virtual void testCaseStarting( TestCaseInfo const& testInfo ); |
| 7562 | virtual void sectionStarting( SectionInfo const& sectionInfo ); |
| 7563 | virtual void assertionStarting( AssertionInfo const& ); |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 7564 | virtual bool assertionEnded( AssertionStats const& assertionStats ); |
Phil Nash | 8764177 | 2013-04-08 11:50:41 +0100 | [diff] [blame] | 7565 | virtual void sectionEnded( SectionStats const& sectionStats ); |
| 7566 | virtual void testCaseEnded( TestCaseStats const& testCaseStats ); |
| 7567 | virtual void testGroupEnded( TestGroupStats const& testGroupStats ); |
| 7568 | virtual void testRunEnded( TestRunStats const& testRunStats ); |
Phil Nash | 92f0836 | 2014-12-22 20:18:05 +0000 | [diff] [blame] | 7569 | virtual void skipTest( TestCaseInfo const& ); |
Phil Nash | 8764177 | 2013-04-08 11:50:41 +0100 | [diff] [blame] | 7570 | |
| 7571 | private: |
| 7572 | Ptr<IReporter> m_legacyReporter; |
Phil Nash | 8764177 | 2013-04-08 11:50:41 +0100 | [diff] [blame] | 7573 | }; |
| 7574 | } |
| 7575 | |
| 7576 | namespace Catch |
| 7577 | { |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 7578 | LegacyReporterAdapter::LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter ) |
| 7579 | : m_legacyReporter( legacyReporter ) |
Phil Nash | 8764177 | 2013-04-08 11:50:41 +0100 | [diff] [blame] | 7580 | {} |
| 7581 | LegacyReporterAdapter::~LegacyReporterAdapter() {} |
| 7582 | |
| 7583 | ReporterPreferences LegacyReporterAdapter::getPreferences() const { |
| 7584 | ReporterPreferences prefs; |
| 7585 | prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout(); |
| 7586 | return prefs; |
| 7587 | } |
| 7588 | |
| 7589 | void LegacyReporterAdapter::noMatchingTestCases( std::string const& ) {} |
| 7590 | void LegacyReporterAdapter::testRunStarting( TestRunInfo const& ) { |
| 7591 | m_legacyReporter->StartTesting(); |
| 7592 | } |
| 7593 | void LegacyReporterAdapter::testGroupStarting( GroupInfo const& groupInfo ) { |
| 7594 | m_legacyReporter->StartGroup( groupInfo.name ); |
| 7595 | } |
| 7596 | void LegacyReporterAdapter::testCaseStarting( TestCaseInfo const& testInfo ) { |
| 7597 | m_legacyReporter->StartTestCase( testInfo ); |
| 7598 | } |
| 7599 | void LegacyReporterAdapter::sectionStarting( SectionInfo const& sectionInfo ) { |
| 7600 | m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description ); |
| 7601 | } |
| 7602 | void LegacyReporterAdapter::assertionStarting( AssertionInfo const& ) { |
| 7603 | // Not on legacy interface |
| 7604 | } |
| 7605 | |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 7606 | bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) { |
Phil Nash | 8764177 | 2013-04-08 11:50:41 +0100 | [diff] [blame] | 7607 | if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) { |
| 7608 | for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); |
| 7609 | it != itEnd; |
| 7610 | ++it ) { |
| 7611 | if( it->type == ResultWas::Info ) { |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 7612 | ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal ); |
| 7613 | rb << it->message; |
| 7614 | rb.setResultType( ResultWas::Info ); |
| 7615 | AssertionResult result = rb.build(); |
Phil Nash | 8764177 | 2013-04-08 11:50:41 +0100 | [diff] [blame] | 7616 | m_legacyReporter->Result( result ); |
| 7617 | } |
| 7618 | } |
| 7619 | } |
| 7620 | m_legacyReporter->Result( assertionStats.assertionResult ); |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 7621 | return true; |
Phil Nash | 8764177 | 2013-04-08 11:50:41 +0100 | [diff] [blame] | 7622 | } |
| 7623 | void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) { |
| 7624 | if( sectionStats.missingAssertions ) |
| 7625 | m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name ); |
| 7626 | m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions ); |
| 7627 | } |
| 7628 | void LegacyReporterAdapter::testCaseEnded( TestCaseStats const& testCaseStats ) { |
Phil Nash | 8764177 | 2013-04-08 11:50:41 +0100 | [diff] [blame] | 7629 | m_legacyReporter->EndTestCase |
| 7630 | ( testCaseStats.testInfo, |
| 7631 | testCaseStats.totals, |
| 7632 | testCaseStats.stdOut, |
| 7633 | testCaseStats.stdErr ); |
| 7634 | } |
| 7635 | void LegacyReporterAdapter::testGroupEnded( TestGroupStats const& testGroupStats ) { |
| 7636 | if( testGroupStats.aborting ) |
| 7637 | m_legacyReporter->Aborted(); |
| 7638 | m_legacyReporter->EndGroup( testGroupStats.groupInfo.name, testGroupStats.totals ); |
| 7639 | } |
| 7640 | void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) { |
| 7641 | m_legacyReporter->EndTesting( testRunStats.totals ); |
| 7642 | } |
Phil Nash | 92f0836 | 2014-12-22 20:18:05 +0000 | [diff] [blame] | 7643 | void LegacyReporterAdapter::skipTest( TestCaseInfo const& ) { |
| 7644 | } |
Phil Nash | 8764177 | 2013-04-08 11:50:41 +0100 | [diff] [blame] | 7645 | } |
| 7646 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 7647 | // #included from: catch_timer.hpp |
| 7648 | |
| 7649 | #ifdef __clang__ |
| 7650 | #pragma clang diagnostic push |
| 7651 | #pragma clang diagnostic ignored "-Wc++11-long-long" |
| 7652 | #endif |
| 7653 | |
Phil Nash | 04a3364 | 2013-08-16 19:09:09 +0100 | [diff] [blame] | 7654 | #ifdef CATCH_PLATFORM_WINDOWS |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 7655 | #include <windows.h> |
| 7656 | #else |
| 7657 | #include <sys/time.h> |
| 7658 | #endif |
| 7659 | |
| 7660 | namespace Catch { |
| 7661 | |
| 7662 | namespace { |
Phil Nash | 04a3364 | 2013-08-16 19:09:09 +0100 | [diff] [blame] | 7663 | #ifdef CATCH_PLATFORM_WINDOWS |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 7664 | uint64_t getCurrentTicks() { |
| 7665 | static uint64_t hz=0, hzo=0; |
| 7666 | if (!hz) { |
Phil Nash | 37e5561 | 2015-03-27 18:02:28 +0000 | [diff] [blame] | 7667 | QueryPerformanceFrequency( reinterpret_cast<LARGE_INTEGER*>( &hz ) ); |
| 7668 | QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &hzo ) ); |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 7669 | } |
| 7670 | uint64_t t; |
Phil Nash | 37e5561 | 2015-03-27 18:02:28 +0000 | [diff] [blame] | 7671 | QueryPerformanceCounter( reinterpret_cast<LARGE_INTEGER*>( &t ) ); |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 7672 | return ((t-hzo)*1000000)/hz; |
| 7673 | } |
| 7674 | #else |
| 7675 | uint64_t getCurrentTicks() { |
| 7676 | timeval t; |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 7677 | gettimeofday(&t,CATCH_NULL); |
Phil Nash | ce56209 | 2014-07-09 07:40:37 +0100 | [diff] [blame] | 7678 | return static_cast<uint64_t>( t.tv_sec ) * 1000000ull + static_cast<uint64_t>( t.tv_usec ); |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 7679 | } |
| 7680 | #endif |
| 7681 | } |
| 7682 | |
| 7683 | void Timer::start() { |
| 7684 | m_ticks = getCurrentTicks(); |
| 7685 | } |
Phil Nash | 4caabfa | 2014-09-03 19:23:22 +0100 | [diff] [blame] | 7686 | unsigned int Timer::getElapsedMicroseconds() const { |
Phil Nash | ce56209 | 2014-07-09 07:40:37 +0100 | [diff] [blame] | 7687 | return static_cast<unsigned int>(getCurrentTicks() - m_ticks); |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 7688 | } |
| 7689 | unsigned int Timer::getElapsedMilliseconds() const { |
Phil Nash | 4caabfa | 2014-09-03 19:23:22 +0100 | [diff] [blame] | 7690 | return static_cast<unsigned int>(getElapsedMicroseconds()/1000); |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 7691 | } |
| 7692 | double Timer::getElapsedSeconds() const { |
Phil Nash | 4caabfa | 2014-09-03 19:23:22 +0100 | [diff] [blame] | 7693 | return getElapsedMicroseconds()/1000000.0; |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 7694 | } |
| 7695 | |
| 7696 | } // namespace Catch |
| 7697 | |
| 7698 | #ifdef __clang__ |
| 7699 | #pragma clang diagnostic pop |
| 7700 | #endif |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 7701 | // #included from: catch_common.hpp |
| 7702 | #define TWOBLUECUBES_CATCH_COMMON_HPP_INCLUDED |
| 7703 | |
| 7704 | namespace Catch { |
| 7705 | |
| 7706 | bool startsWith( std::string const& s, std::string const& prefix ) { |
| 7707 | return s.size() >= prefix.size() && s.substr( 0, prefix.size() ) == prefix; |
| 7708 | } |
| 7709 | bool endsWith( std::string const& s, std::string const& suffix ) { |
| 7710 | return s.size() >= suffix.size() && s.substr( s.size()-suffix.size(), suffix.size() ) == suffix; |
| 7711 | } |
| 7712 | bool contains( std::string const& s, std::string const& infix ) { |
| 7713 | return s.find( infix ) != std::string::npos; |
| 7714 | } |
| 7715 | void toLowerInPlace( std::string& s ) { |
| 7716 | std::transform( s.begin(), s.end(), s.begin(), ::tolower ); |
| 7717 | } |
| 7718 | std::string toLower( std::string const& s ) { |
| 7719 | std::string lc = s; |
| 7720 | toLowerInPlace( lc ); |
| 7721 | return lc; |
| 7722 | } |
| 7723 | std::string trim( std::string const& str ) { |
| 7724 | static char const* whitespaceChars = "\n\r\t "; |
| 7725 | std::string::size_type start = str.find_first_not_of( whitespaceChars ); |
| 7726 | std::string::size_type end = str.find_last_not_of( whitespaceChars ); |
| 7727 | |
| 7728 | return start != std::string::npos ? str.substr( start, 1+end-start ) : ""; |
| 7729 | } |
| 7730 | |
Phil Nash | 576aff6 | 2014-12-21 00:21:23 +0000 | [diff] [blame] | 7731 | bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis ) { |
| 7732 | bool replaced = false; |
| 7733 | std::size_t i = str.find( replaceThis ); |
| 7734 | while( i != std::string::npos ) { |
| 7735 | replaced = true; |
| 7736 | str = str.substr( 0, i ) + withThis + str.substr( i+replaceThis.size() ); |
| 7737 | if( i < str.size()-withThis.size() ) |
| 7738 | i = str.find( replaceThis, i+withThis.size() ); |
| 7739 | else |
| 7740 | i = std::string::npos; |
| 7741 | } |
| 7742 | return replaced; |
| 7743 | } |
| 7744 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 7745 | pluralise::pluralise( std::size_t count, std::string const& label ) |
| 7746 | : m_count( count ), |
| 7747 | m_label( label ) |
| 7748 | {} |
| 7749 | |
| 7750 | std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser ) { |
| 7751 | os << pluraliser.m_count << " " << pluraliser.m_label; |
| 7752 | if( pluraliser.m_count != 1 ) |
| 7753 | os << "s"; |
| 7754 | return os; |
| 7755 | } |
| 7756 | |
| 7757 | SourceLineInfo::SourceLineInfo() : line( 0 ){} |
Phil Nash | de49ec4 | 2013-12-04 20:25:14 +0000 | [diff] [blame] | 7758 | SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line ) |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 7759 | : file( _file ), |
| 7760 | line( _line ) |
| 7761 | {} |
| 7762 | SourceLineInfo::SourceLineInfo( SourceLineInfo const& other ) |
| 7763 | : file( other.file ), |
| 7764 | line( other.line ) |
| 7765 | {} |
| 7766 | bool SourceLineInfo::empty() const { |
| 7767 | return file.empty(); |
| 7768 | } |
| 7769 | bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const { |
| 7770 | return line == other.line && file == other.file; |
| 7771 | } |
Phil Nash | a806c3e | 2015-03-04 08:23:40 +0000 | [diff] [blame] | 7772 | bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const { |
| 7773 | return line < other.line || ( line == other.line && file < other.file ); |
| 7774 | } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 7775 | |
Phil Nash | 8f66e34 | 2015-07-02 23:03:13 +0100 | [diff] [blame] | 7776 | void seedRng( IConfig const& config ) { |
| 7777 | if( config.rngSeed() != 0 ) |
| 7778 | std::srand( config.rngSeed() ); |
| 7779 | } |
| 7780 | unsigned int rngSeed() { |
| 7781 | return getCurrentContext().getConfig()->rngSeed(); |
| 7782 | } |
| 7783 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 7784 | std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) { |
| 7785 | #ifndef __GNUG__ |
| 7786 | os << info.file << "(" << info.line << ")"; |
| 7787 | #else |
| 7788 | os << info.file << ":" << info.line; |
| 7789 | #endif |
| 7790 | return os; |
| 7791 | } |
| 7792 | |
| 7793 | void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo ) { |
| 7794 | std::ostringstream oss; |
| 7795 | oss << locationInfo << ": Internal Catch error: '" << message << "'"; |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 7796 | if( alwaysTrue() ) |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 7797 | throw std::logic_error( oss.str() ); |
| 7798 | } |
| 7799 | } |
| 7800 | |
| 7801 | // #included from: catch_section.hpp |
| 7802 | #define TWOBLUECUBES_CATCH_SECTION_HPP_INCLUDED |
| 7803 | |
| 7804 | namespace Catch { |
| 7805 | |
Phil Nash | ce56209 | 2014-07-09 07:40:37 +0100 | [diff] [blame] | 7806 | SectionInfo::SectionInfo |
| 7807 | ( SourceLineInfo const& _lineInfo, |
| 7808 | std::string const& _name, |
| 7809 | std::string const& _description ) |
| 7810 | : name( _name ), |
| 7811 | description( _description ), |
| 7812 | lineInfo( _lineInfo ) |
| 7813 | {} |
| 7814 | |
| 7815 | Section::Section( SectionInfo const& info ) |
| 7816 | : m_info( info ), |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 7817 | m_sectionIncluded( getResultCapture().sectionStarted( m_info, m_assertions ) ) |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 7818 | { |
| 7819 | m_timer.start(); |
| 7820 | } |
| 7821 | |
| 7822 | Section::~Section() { |
Phil Nash | 0c1c9fa | 2015-09-27 03:28:14 -0700 | [diff] [blame] | 7823 | if( m_sectionIncluded ) { |
| 7824 | SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() ); |
| 7825 | if( std::uncaught_exception() ) |
| 7826 | getResultCapture().sectionEndedEarly( endInfo ); |
| 7827 | else |
| 7828 | getResultCapture().sectionEnded( endInfo ); |
| 7829 | } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 7830 | } |
| 7831 | |
| 7832 | // This indicates whether the section should be executed or not |
Phil Nash | ce56209 | 2014-07-09 07:40:37 +0100 | [diff] [blame] | 7833 | Section::operator bool() const { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 7834 | return m_sectionIncluded; |
| 7835 | } |
| 7836 | |
| 7837 | } // end namespace Catch |
| 7838 | |
| 7839 | // #included from: catch_debugger.hpp |
| 7840 | #define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED |
| 7841 | |
| 7842 | #include <iostream> |
| 7843 | |
| 7844 | #ifdef CATCH_PLATFORM_MAC |
| 7845 | |
| 7846 | #include <assert.h> |
| 7847 | #include <stdbool.h> |
| 7848 | #include <sys/types.h> |
| 7849 | #include <unistd.h> |
| 7850 | #include <sys/sysctl.h> |
| 7851 | |
| 7852 | namespace Catch{ |
| 7853 | |
| 7854 | // The following function is taken directly from the following technical note: |
| 7855 | // http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html |
| 7856 | |
| 7857 | // Returns true if the current process is being debugged (either |
| 7858 | // running under the debugger or has a debugger attached post facto). |
| 7859 | bool isDebuggerActive(){ |
| 7860 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 7861 | int mib[4]; |
| 7862 | struct kinfo_proc info; |
| 7863 | size_t size; |
| 7864 | |
| 7865 | // Initialize the flags so that, if sysctl fails for some bizarre |
| 7866 | // reason, we get a predictable result. |
| 7867 | |
| 7868 | info.kp_proc.p_flag = 0; |
| 7869 | |
| 7870 | // Initialize mib, which tells sysctl the info we want, in this case |
| 7871 | // we're looking for information about a specific process ID. |
| 7872 | |
| 7873 | mib[0] = CTL_KERN; |
| 7874 | mib[1] = KERN_PROC; |
| 7875 | mib[2] = KERN_PROC_PID; |
| 7876 | mib[3] = getpid(); |
| 7877 | |
| 7878 | // Call sysctl. |
| 7879 | |
| 7880 | size = sizeof(info); |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 7881 | if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, CATCH_NULL, 0) != 0 ) { |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 7882 | Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl; |
Phil Nash | 7eb5acc | 2014-01-08 17:17:31 +0000 | [diff] [blame] | 7883 | return false; |
| 7884 | } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 7885 | |
| 7886 | // We're being debugged if the P_TRACED flag is set. |
| 7887 | |
| 7888 | return ( (info.kp_proc.p_flag & P_TRACED) != 0 ); |
| 7889 | } |
| 7890 | } // namespace Catch |
| 7891 | |
| 7892 | #elif defined(_MSC_VER) |
| 7893 | extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); |
| 7894 | namespace Catch { |
| 7895 | bool isDebuggerActive() { |
| 7896 | return IsDebuggerPresent() != 0; |
| 7897 | } |
| 7898 | } |
| 7899 | #elif defined(__MINGW32__) |
| 7900 | extern "C" __declspec(dllimport) int __stdcall IsDebuggerPresent(); |
| 7901 | namespace Catch { |
| 7902 | bool isDebuggerActive() { |
| 7903 | return IsDebuggerPresent() != 0; |
| 7904 | } |
| 7905 | } |
| 7906 | #else |
| 7907 | namespace Catch { |
| 7908 | inline bool isDebuggerActive() { return false; } |
| 7909 | } |
| 7910 | #endif // Platform |
| 7911 | |
| 7912 | #ifdef CATCH_PLATFORM_WINDOWS |
| 7913 | extern "C" __declspec(dllimport) void __stdcall OutputDebugStringA( const char* ); |
| 7914 | namespace Catch { |
| 7915 | void writeToDebugConsole( std::string const& text ) { |
| 7916 | ::OutputDebugStringA( text.c_str() ); |
| 7917 | } |
| 7918 | } |
| 7919 | #else |
| 7920 | namespace Catch { |
| 7921 | void writeToDebugConsole( std::string const& text ) { |
| 7922 | // !TBD: Need a version for Mac/ XCode and other IDEs |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 7923 | Catch::cout() << text; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 7924 | } |
| 7925 | } |
| 7926 | #endif // Platform |
| 7927 | |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 7928 | // #included from: catch_tostring.hpp |
| 7929 | #define TWOBLUECUBES_CATCH_TOSTRING_HPP_INCLUDED |
| 7930 | |
| 7931 | namespace Catch { |
| 7932 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 7933 | namespace Detail { |
| 7934 | |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 7935 | const std::string unprintableString = "{?}"; |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 7936 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 7937 | namespace { |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 7938 | const int hexThreshold = 255; |
| 7939 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 7940 | struct Endianness { |
| 7941 | enum Arch { Big, Little }; |
| 7942 | |
| 7943 | static Arch which() { |
| 7944 | union _{ |
| 7945 | int asInt; |
| 7946 | char asChar[sizeof (int)]; |
| 7947 | } u; |
| 7948 | |
| 7949 | u.asInt = 1; |
| 7950 | return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little; |
| 7951 | } |
| 7952 | }; |
| 7953 | } |
| 7954 | |
| 7955 | std::string rawMemoryToString( const void *object, std::size_t size ) |
| 7956 | { |
| 7957 | // Reverse order for little endian architectures |
| 7958 | int i = 0, end = static_cast<int>( size ), inc = 1; |
| 7959 | if( Endianness::which() == Endianness::Little ) { |
| 7960 | i = end-1; |
| 7961 | end = inc = -1; |
| 7962 | } |
| 7963 | |
| 7964 | unsigned char const *bytes = static_cast<unsigned char const *>(object); |
| 7965 | std::ostringstream os; |
| 7966 | os << "0x" << std::setfill('0') << std::hex; |
| 7967 | for( ; i != end; i += inc ) |
| 7968 | os << std::setw(2) << static_cast<unsigned>(bytes[i]); |
| 7969 | return os.str(); |
| 7970 | } |
| 7971 | } |
| 7972 | |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 7973 | std::string toString( std::string const& value ) { |
| 7974 | std::string s = value; |
| 7975 | if( getCurrentContext().getConfig()->showInvisibles() ) { |
| 7976 | for(size_t i = 0; i < s.size(); ++i ) { |
| 7977 | std::string subs; |
| 7978 | switch( s[i] ) { |
| 7979 | case '\n': subs = "\\n"; break; |
| 7980 | case '\t': subs = "\\t"; break; |
| 7981 | default: break; |
| 7982 | } |
| 7983 | if( !subs.empty() ) { |
| 7984 | s = s.substr( 0, i ) + subs + s.substr( i+1 ); |
| 7985 | ++i; |
| 7986 | } |
| 7987 | } |
| 7988 | } |
| 7989 | return "\"" + s + "\""; |
| 7990 | } |
| 7991 | std::string toString( std::wstring const& value ) { |
| 7992 | |
| 7993 | std::string s; |
| 7994 | s.reserve( value.size() ); |
| 7995 | for(size_t i = 0; i < value.size(); ++i ) |
| 7996 | s += value[i] <= 0xff ? static_cast<char>( value[i] ) : '?'; |
Phil Nash | 13f9843 | 2014-12-12 08:11:18 +0000 | [diff] [blame] | 7997 | return Catch::toString( s ); |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 7998 | } |
| 7999 | |
| 8000 | std::string toString( const char* const value ) { |
| 8001 | return value ? Catch::toString( std::string( value ) ) : std::string( "{null string}" ); |
| 8002 | } |
| 8003 | |
| 8004 | std::string toString( char* const value ) { |
| 8005 | return Catch::toString( static_cast<const char*>( value ) ); |
| 8006 | } |
| 8007 | |
Phil Nash | 544bf33 | 2014-08-20 08:09:32 +0100 | [diff] [blame] | 8008 | std::string toString( const wchar_t* const value ) |
| 8009 | { |
| 8010 | return value ? Catch::toString( std::wstring(value) ) : std::string( "{null string}" ); |
| 8011 | } |
| 8012 | |
| 8013 | std::string toString( wchar_t* const value ) |
| 8014 | { |
| 8015 | return Catch::toString( static_cast<const wchar_t*>( value ) ); |
| 8016 | } |
| 8017 | |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 8018 | std::string toString( int value ) { |
| 8019 | std::ostringstream oss; |
Phil Nash | c51e868 | 2015-05-21 06:16:15 +0100 | [diff] [blame] | 8020 | oss << value; |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 8021 | if( value > Detail::hexThreshold ) |
Phil Nash | c51e868 | 2015-05-21 06:16:15 +0100 | [diff] [blame] | 8022 | oss << " (0x" << std::hex << value << ")"; |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 8023 | return oss.str(); |
| 8024 | } |
| 8025 | |
| 8026 | std::string toString( unsigned long value ) { |
| 8027 | std::ostringstream oss; |
Phil Nash | c51e868 | 2015-05-21 06:16:15 +0100 | [diff] [blame] | 8028 | oss << value; |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 8029 | if( value > Detail::hexThreshold ) |
Phil Nash | c51e868 | 2015-05-21 06:16:15 +0100 | [diff] [blame] | 8030 | oss << " (0x" << std::hex << value << ")"; |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 8031 | return oss.str(); |
| 8032 | } |
| 8033 | |
| 8034 | std::string toString( unsigned int value ) { |
Phil Nash | 13f9843 | 2014-12-12 08:11:18 +0000 | [diff] [blame] | 8035 | return Catch::toString( static_cast<unsigned long>( value ) ); |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 8036 | } |
| 8037 | |
Phil Nash | 28c2e07 | 2014-07-09 19:22:49 +0100 | [diff] [blame] | 8038 | template<typename T> |
| 8039 | std::string fpToString( T value, int precision ) { |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 8040 | std::ostringstream oss; |
Phil Nash | 28c2e07 | 2014-07-09 19:22:49 +0100 | [diff] [blame] | 8041 | oss << std::setprecision( precision ) |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 8042 | << std::fixed |
| 8043 | << value; |
| 8044 | std::string d = oss.str(); |
| 8045 | std::size_t i = d.find_last_not_of( '0' ); |
| 8046 | if( i != std::string::npos && i != d.size()-1 ) { |
| 8047 | if( d[i] == '.' ) |
| 8048 | i++; |
| 8049 | d = d.substr( 0, i+1 ); |
| 8050 | } |
| 8051 | return d; |
| 8052 | } |
| 8053 | |
Phil Nash | 28c2e07 | 2014-07-09 19:22:49 +0100 | [diff] [blame] | 8054 | std::string toString( const double value ) { |
| 8055 | return fpToString( value, 10 ); |
| 8056 | } |
| 8057 | std::string toString( const float value ) { |
| 8058 | return fpToString( value, 5 ) + "f"; |
| 8059 | } |
| 8060 | |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 8061 | std::string toString( bool value ) { |
| 8062 | return value ? "true" : "false"; |
| 8063 | } |
| 8064 | |
| 8065 | std::string toString( char value ) { |
| 8066 | return value < ' ' |
| 8067 | ? toString( static_cast<unsigned int>( value ) ) |
| 8068 | : Detail::makeString( value ); |
| 8069 | } |
| 8070 | |
| 8071 | std::string toString( signed char value ) { |
| 8072 | return toString( static_cast<char>( value ) ); |
| 8073 | } |
| 8074 | |
| 8075 | std::string toString( unsigned char value ) { |
| 8076 | return toString( static_cast<char>( value ) ); |
| 8077 | } |
| 8078 | |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 8079 | #ifdef CATCH_CONFIG_CPP11_LONG_LONG |
| 8080 | std::string toString( long long value ) { |
| 8081 | std::ostringstream oss; |
| 8082 | oss << value; |
| 8083 | if( value > Detail::hexThreshold ) |
| 8084 | oss << " (0x" << std::hex << value << ")"; |
| 8085 | return oss.str(); |
| 8086 | } |
| 8087 | std::string toString( unsigned long long value ) { |
| 8088 | std::ostringstream oss; |
| 8089 | oss << value; |
| 8090 | if( value > Detail::hexThreshold ) |
| 8091 | oss << " (0x" << std::hex << value << ")"; |
| 8092 | return oss.str(); |
| 8093 | } |
| 8094 | #endif |
| 8095 | |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 8096 | #ifdef CATCH_CONFIG_CPP11_NULLPTR |
| 8097 | std::string toString( std::nullptr_t ) { |
| 8098 | return "nullptr"; |
| 8099 | } |
| 8100 | #endif |
| 8101 | |
| 8102 | #ifdef __OBJC__ |
| 8103 | std::string toString( NSString const * const& nsstring ) { |
| 8104 | if( !nsstring ) |
| 8105 | return "nil"; |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 8106 | return "@" + toString([nsstring UTF8String]); |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 8107 | } |
| 8108 | std::string toString( NSString * CATCH_ARC_STRONG const& nsstring ) { |
| 8109 | if( !nsstring ) |
| 8110 | return "nil"; |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 8111 | return "@" + toString([nsstring UTF8String]); |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 8112 | } |
| 8113 | std::string toString( NSObject* const& nsObject ) { |
| 8114 | return toString( [nsObject description] ); |
| 8115 | } |
| 8116 | #endif |
| 8117 | |
| 8118 | } // end namespace Catch |
| 8119 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 8120 | // #included from: catch_result_builder.hpp |
| 8121 | #define TWOBLUECUBES_CATCH_RESULT_BUILDER_HPP_INCLUDED |
| 8122 | |
| 8123 | namespace Catch { |
| 8124 | |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 8125 | std::string capturedExpressionWithSecondArgument( std::string const& capturedExpression, std::string const& secondArg ) { |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 8126 | return secondArg.empty() || secondArg == "\"\"" |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 8127 | ? capturedExpression |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 8128 | : capturedExpression + ", " + secondArg; |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 8129 | } |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 8130 | ResultBuilder::ResultBuilder( char const* macroName, |
| 8131 | SourceLineInfo const& lineInfo, |
| 8132 | char const* capturedExpression, |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 8133 | ResultDisposition::Flags resultDisposition, |
| 8134 | char const* secondArg ) |
| 8135 | : m_assertionInfo( macroName, lineInfo, capturedExpressionWithSecondArgument( capturedExpression, secondArg ), resultDisposition ), |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 8136 | m_shouldDebugBreak( false ), |
| 8137 | m_shouldThrow( false ) |
| 8138 | {} |
| 8139 | |
| 8140 | ResultBuilder& ResultBuilder::setResultType( ResultWas::OfType result ) { |
| 8141 | m_data.resultType = result; |
| 8142 | return *this; |
| 8143 | } |
| 8144 | ResultBuilder& ResultBuilder::setResultType( bool result ) { |
| 8145 | m_data.resultType = result ? ResultWas::Ok : ResultWas::ExpressionFailed; |
| 8146 | return *this; |
| 8147 | } |
| 8148 | ResultBuilder& ResultBuilder::setLhs( std::string const& lhs ) { |
| 8149 | m_exprComponents.lhs = lhs; |
| 8150 | return *this; |
| 8151 | } |
| 8152 | ResultBuilder& ResultBuilder::setRhs( std::string const& rhs ) { |
| 8153 | m_exprComponents.rhs = rhs; |
| 8154 | return *this; |
| 8155 | } |
| 8156 | ResultBuilder& ResultBuilder::setOp( std::string const& op ) { |
| 8157 | m_exprComponents.op = op; |
| 8158 | return *this; |
| 8159 | } |
| 8160 | |
| 8161 | void ResultBuilder::endExpression() { |
| 8162 | m_exprComponents.testFalse = isFalseTest( m_assertionInfo.resultDisposition ); |
| 8163 | captureExpression(); |
| 8164 | } |
| 8165 | |
| 8166 | void ResultBuilder::useActiveException( ResultDisposition::Flags resultDisposition ) { |
| 8167 | m_assertionInfo.resultDisposition = resultDisposition; |
| 8168 | m_stream.oss << Catch::translateActiveException(); |
| 8169 | captureResult( ResultWas::ThrewException ); |
| 8170 | } |
| 8171 | |
| 8172 | void ResultBuilder::captureResult( ResultWas::OfType resultType ) { |
| 8173 | setResultType( resultType ); |
| 8174 | captureExpression(); |
| 8175 | } |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 8176 | void ResultBuilder::captureExpectedException( std::string const& expectedMessage ) { |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 8177 | if( expectedMessage.empty() ) |
| 8178 | captureExpectedException( Matchers::Impl::Generic::AllOf<std::string>() ); |
| 8179 | else |
| 8180 | captureExpectedException( Matchers::Equals( expectedMessage ) ); |
| 8181 | } |
| 8182 | |
| 8183 | void ResultBuilder::captureExpectedException( Matchers::Impl::Matcher<std::string> const& matcher ) { |
| 8184 | |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 8185 | assert( m_exprComponents.testFalse == false ); |
| 8186 | AssertionResultData data = m_data; |
| 8187 | data.resultType = ResultWas::Ok; |
| 8188 | data.reconstructedExpression = m_assertionInfo.capturedExpression; |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 8189 | |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 8190 | std::string actualMessage = Catch::translateActiveException(); |
| 8191 | if( !matcher.match( actualMessage ) ) { |
| 8192 | data.resultType = ResultWas::ExpressionFailed; |
| 8193 | data.reconstructedExpression = actualMessage; |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 8194 | } |
| 8195 | AssertionResult result( m_assertionInfo, data ); |
| 8196 | handleResult( result ); |
| 8197 | } |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 8198 | |
| 8199 | void ResultBuilder::captureExpression() { |
| 8200 | AssertionResult result = build(); |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 8201 | handleResult( result ); |
| 8202 | } |
| 8203 | void ResultBuilder::handleResult( AssertionResult const& result ) |
| 8204 | { |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 8205 | getResultCapture().assertionEnded( result ); |
| 8206 | |
| 8207 | if( !result.isOk() ) { |
| 8208 | if( getCurrentContext().getConfig()->shouldDebugBreak() ) |
| 8209 | m_shouldDebugBreak = true; |
Phil Nash | 318c936 | 2015-05-19 18:40:00 +0100 | [diff] [blame] | 8210 | if( getCurrentContext().getRunner()->aborting() || (m_assertionInfo.resultDisposition & ResultDisposition::Normal) ) |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 8211 | m_shouldThrow = true; |
| 8212 | } |
| 8213 | } |
| 8214 | void ResultBuilder::react() { |
| 8215 | if( m_shouldThrow ) |
| 8216 | throw Catch::TestFailureException(); |
| 8217 | } |
| 8218 | |
| 8219 | bool ResultBuilder::shouldDebugBreak() const { return m_shouldDebugBreak; } |
| 8220 | bool ResultBuilder::allowThrows() const { return getCurrentContext().getConfig()->allowThrows(); } |
| 8221 | |
| 8222 | AssertionResult ResultBuilder::build() const |
| 8223 | { |
| 8224 | assert( m_data.resultType != ResultWas::Unknown ); |
| 8225 | |
| 8226 | AssertionResultData data = m_data; |
| 8227 | |
| 8228 | // Flip bool results if testFalse is set |
| 8229 | if( m_exprComponents.testFalse ) { |
| 8230 | if( data.resultType == ResultWas::Ok ) |
| 8231 | data.resultType = ResultWas::ExpressionFailed; |
| 8232 | else if( data.resultType == ResultWas::ExpressionFailed ) |
| 8233 | data.resultType = ResultWas::Ok; |
| 8234 | } |
| 8235 | |
| 8236 | data.message = m_stream.oss.str(); |
| 8237 | data.reconstructedExpression = reconstructExpression(); |
| 8238 | if( m_exprComponents.testFalse ) { |
| 8239 | if( m_exprComponents.op == "" ) |
| 8240 | data.reconstructedExpression = "!" + data.reconstructedExpression; |
| 8241 | else |
| 8242 | data.reconstructedExpression = "!(" + data.reconstructedExpression + ")"; |
| 8243 | } |
| 8244 | return AssertionResult( m_assertionInfo, data ); |
| 8245 | } |
| 8246 | std::string ResultBuilder::reconstructExpression() const { |
| 8247 | if( m_exprComponents.op == "" ) |
| 8248 | return m_exprComponents.lhs.empty() ? m_assertionInfo.capturedExpression : m_exprComponents.op + m_exprComponents.lhs; |
| 8249 | else if( m_exprComponents.op == "matches" ) |
| 8250 | return m_exprComponents.lhs + " " + m_exprComponents.rhs; |
| 8251 | else if( m_exprComponents.op != "!" ) { |
| 8252 | if( m_exprComponents.lhs.size() + m_exprComponents.rhs.size() < 40 && |
| 8253 | m_exprComponents.lhs.find("\n") == std::string::npos && |
| 8254 | m_exprComponents.rhs.find("\n") == std::string::npos ) |
| 8255 | return m_exprComponents.lhs + " " + m_exprComponents.op + " " + m_exprComponents.rhs; |
| 8256 | else |
| 8257 | return m_exprComponents.lhs + "\n" + m_exprComponents.op + "\n" + m_exprComponents.rhs; |
| 8258 | } |
| 8259 | else |
| 8260 | return "{can't expand - use " + m_assertionInfo.macroName + "_FALSE( " + m_assertionInfo.capturedExpression.substr(1) + " ) instead of " + m_assertionInfo.macroName + "( " + m_assertionInfo.capturedExpression + " ) for better diagnostics}"; |
| 8261 | } |
| 8262 | |
| 8263 | } // end namespace Catch |
| 8264 | |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 8265 | // #included from: catch_tag_alias_registry.hpp |
| 8266 | #define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_HPP_INCLUDED |
| 8267 | |
| 8268 | // #included from: catch_tag_alias_registry.h |
| 8269 | #define TWOBLUECUBES_CATCH_TAG_ALIAS_REGISTRY_H_INCLUDED |
| 8270 | |
| 8271 | #include <map> |
| 8272 | |
| 8273 | namespace Catch { |
| 8274 | |
| 8275 | class TagAliasRegistry : public ITagAliasRegistry { |
| 8276 | public: |
| 8277 | virtual ~TagAliasRegistry(); |
| 8278 | virtual Option<TagAlias> find( std::string const& alias ) const; |
| 8279 | virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const; |
| 8280 | void add( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); |
| 8281 | static TagAliasRegistry& get(); |
| 8282 | |
| 8283 | private: |
| 8284 | std::map<std::string, TagAlias> m_registry; |
| 8285 | }; |
| 8286 | |
| 8287 | } // end namespace Catch |
| 8288 | |
| 8289 | #include <map> |
| 8290 | #include <iostream> |
| 8291 | |
| 8292 | namespace Catch { |
| 8293 | |
| 8294 | TagAliasRegistry::~TagAliasRegistry() {} |
| 8295 | |
| 8296 | Option<TagAlias> TagAliasRegistry::find( std::string const& alias ) const { |
| 8297 | std::map<std::string, TagAlias>::const_iterator it = m_registry.find( alias ); |
| 8298 | if( it != m_registry.end() ) |
| 8299 | return it->second; |
| 8300 | else |
| 8301 | return Option<TagAlias>(); |
| 8302 | } |
| 8303 | |
| 8304 | std::string TagAliasRegistry::expandAliases( std::string const& unexpandedTestSpec ) const { |
| 8305 | std::string expandedTestSpec = unexpandedTestSpec; |
| 8306 | for( std::map<std::string, TagAlias>::const_iterator it = m_registry.begin(), itEnd = m_registry.end(); |
| 8307 | it != itEnd; |
| 8308 | ++it ) { |
| 8309 | std::size_t pos = expandedTestSpec.find( it->first ); |
| 8310 | if( pos != std::string::npos ) { |
| 8311 | expandedTestSpec = expandedTestSpec.substr( 0, pos ) + |
| 8312 | it->second.tag + |
| 8313 | expandedTestSpec.substr( pos + it->first.size() ); |
| 8314 | } |
| 8315 | } |
| 8316 | return expandedTestSpec; |
| 8317 | } |
| 8318 | |
| 8319 | void TagAliasRegistry::add( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) { |
| 8320 | |
| 8321 | if( !startsWith( alias, "[@" ) || !endsWith( alias, "]" ) ) { |
| 8322 | std::ostringstream oss; |
| 8323 | oss << "error: tag alias, \"" << alias << "\" is not of the form [@alias name].\n" << lineInfo; |
| 8324 | throw std::domain_error( oss.str().c_str() ); |
| 8325 | } |
| 8326 | if( !m_registry.insert( std::make_pair( alias, TagAlias( tag, lineInfo ) ) ).second ) { |
| 8327 | std::ostringstream oss; |
| 8328 | oss << "error: tag alias, \"" << alias << "\" already registered.\n" |
| 8329 | << "\tFirst seen at " << find(alias)->lineInfo << "\n" |
| 8330 | << "\tRedefined at " << lineInfo; |
| 8331 | throw std::domain_error( oss.str().c_str() ); |
| 8332 | } |
| 8333 | } |
| 8334 | |
| 8335 | TagAliasRegistry& TagAliasRegistry::get() { |
| 8336 | static TagAliasRegistry instance; |
| 8337 | return instance; |
| 8338 | |
| 8339 | } |
| 8340 | |
| 8341 | ITagAliasRegistry::~ITagAliasRegistry() {} |
| 8342 | ITagAliasRegistry const& ITagAliasRegistry::get() { return TagAliasRegistry::get(); } |
| 8343 | |
| 8344 | RegistrarForTagAliases::RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ) { |
| 8345 | try { |
| 8346 | TagAliasRegistry::get().add( alias, tag, lineInfo ); |
| 8347 | } |
| 8348 | catch( std::exception& ex ) { |
| 8349 | Colour colourGuard( Colour::Red ); |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 8350 | Catch::cerr() << ex.what() << std::endl; |
Phil Nash | acdd3b5 | 2014-06-30 07:35:36 +0100 | [diff] [blame] | 8351 | exit(1); |
| 8352 | } |
| 8353 | } |
| 8354 | |
| 8355 | } // end namespace Catch |
| 8356 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8357 | // #included from: ../reporters/catch_reporter_multi.hpp |
| 8358 | #define TWOBLUECUBES_CATCH_REPORTER_MULTI_HPP_INCLUDED |
| 8359 | |
| 8360 | namespace Catch { |
| 8361 | |
| 8362 | class MultipleReporters : public SharedImpl<IStreamingReporter> { |
| 8363 | typedef std::vector<Ptr<IStreamingReporter> > Reporters; |
| 8364 | Reporters m_reporters; |
| 8365 | |
| 8366 | public: |
| 8367 | void add( Ptr<IStreamingReporter> const& reporter ) { |
| 8368 | m_reporters.push_back( reporter ); |
| 8369 | } |
| 8370 | |
| 8371 | public: // IStreamingReporter |
| 8372 | |
| 8373 | virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE { |
| 8374 | return m_reporters[0]->getPreferences(); |
| 8375 | } |
| 8376 | |
| 8377 | virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE { |
| 8378 | for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); |
| 8379 | it != itEnd; |
| 8380 | ++it ) |
| 8381 | (*it)->noMatchingTestCases( spec ); |
| 8382 | } |
| 8383 | |
| 8384 | virtual void testRunStarting( TestRunInfo const& testRunInfo ) CATCH_OVERRIDE { |
| 8385 | for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); |
| 8386 | it != itEnd; |
| 8387 | ++it ) |
| 8388 | (*it)->testRunStarting( testRunInfo ); |
| 8389 | } |
| 8390 | |
| 8391 | virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE { |
| 8392 | for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); |
| 8393 | it != itEnd; |
| 8394 | ++it ) |
| 8395 | (*it)->testGroupStarting( groupInfo ); |
| 8396 | } |
| 8397 | |
| 8398 | virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE { |
| 8399 | for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); |
| 8400 | it != itEnd; |
| 8401 | ++it ) |
| 8402 | (*it)->testCaseStarting( testInfo ); |
| 8403 | } |
| 8404 | |
| 8405 | virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE { |
| 8406 | for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); |
| 8407 | it != itEnd; |
| 8408 | ++it ) |
| 8409 | (*it)->sectionStarting( sectionInfo ); |
| 8410 | } |
| 8411 | |
| 8412 | virtual void assertionStarting( AssertionInfo const& assertionInfo ) CATCH_OVERRIDE { |
| 8413 | for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); |
| 8414 | it != itEnd; |
| 8415 | ++it ) |
| 8416 | (*it)->assertionStarting( assertionInfo ); |
| 8417 | } |
| 8418 | |
| 8419 | // The return value indicates if the messages buffer should be cleared: |
| 8420 | virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE { |
| 8421 | bool clearBuffer = false; |
| 8422 | for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); |
| 8423 | it != itEnd; |
| 8424 | ++it ) |
| 8425 | clearBuffer |= (*it)->assertionEnded( assertionStats ); |
| 8426 | return clearBuffer; |
| 8427 | } |
| 8428 | |
| 8429 | virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE { |
| 8430 | for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); |
| 8431 | it != itEnd; |
| 8432 | ++it ) |
| 8433 | (*it)->sectionEnded( sectionStats ); |
| 8434 | } |
| 8435 | |
| 8436 | virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE { |
| 8437 | for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); |
| 8438 | it != itEnd; |
| 8439 | ++it ) |
| 8440 | (*it)->testCaseEnded( testCaseStats ); |
| 8441 | } |
| 8442 | |
| 8443 | virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE { |
| 8444 | for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); |
| 8445 | it != itEnd; |
| 8446 | ++it ) |
| 8447 | (*it)->testGroupEnded( testGroupStats ); |
| 8448 | } |
| 8449 | |
| 8450 | virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE { |
| 8451 | for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); |
| 8452 | it != itEnd; |
| 8453 | ++it ) |
| 8454 | (*it)->testRunEnded( testRunStats ); |
| 8455 | } |
| 8456 | |
| 8457 | virtual void skipTest( TestCaseInfo const& testInfo ) CATCH_OVERRIDE { |
| 8458 | for( Reporters::const_iterator it = m_reporters.begin(), itEnd = m_reporters.end(); |
| 8459 | it != itEnd; |
| 8460 | ++it ) |
| 8461 | (*it)->skipTest( testInfo ); |
| 8462 | } |
| 8463 | }; |
| 8464 | |
| 8465 | Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter ) { |
| 8466 | Ptr<IStreamingReporter> resultingReporter; |
| 8467 | |
| 8468 | if( existingReporter ) { |
| 8469 | MultipleReporters* multi = dynamic_cast<MultipleReporters*>( existingReporter.get() ); |
| 8470 | if( !multi ) { |
| 8471 | multi = new MultipleReporters; |
| 8472 | resultingReporter = Ptr<IStreamingReporter>( multi ); |
| 8473 | if( existingReporter ) |
| 8474 | multi->add( existingReporter ); |
| 8475 | } |
| 8476 | else |
| 8477 | resultingReporter = existingReporter; |
| 8478 | multi->add( additionalReporter ); |
| 8479 | } |
| 8480 | else |
| 8481 | resultingReporter = additionalReporter; |
| 8482 | |
| 8483 | return resultingReporter; |
| 8484 | } |
| 8485 | |
| 8486 | } // end namespace Catch |
| 8487 | |
Phil Nash | 3faa412 | 2013-08-15 19:09:07 +0100 | [diff] [blame] | 8488 | // #included from: ../reporters/catch_reporter_xml.hpp |
| 8489 | #define TWOBLUECUBES_CATCH_REPORTER_XML_HPP_INCLUDED |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8490 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8491 | // #included from: catch_reporter_bases.hpp |
| 8492 | #define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED |
| 8493 | |
Phil Nash | b771394 | 2014-12-22 07:42:57 +0000 | [diff] [blame] | 8494 | #include <cstring> |
| 8495 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8496 | namespace Catch { |
| 8497 | |
| 8498 | struct StreamingReporterBase : SharedImpl<IStreamingReporter> { |
| 8499 | |
| 8500 | StreamingReporterBase( ReporterConfig const& _config ) |
| 8501 | : m_config( _config.fullConfig() ), |
| 8502 | stream( _config.stream() ) |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8503 | { |
| 8504 | m_reporterPrefs.shouldRedirectStdOut = false; |
| 8505 | } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8506 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8507 | virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE { |
| 8508 | return m_reporterPrefs; |
| 8509 | } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8510 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8511 | virtual ~StreamingReporterBase() CATCH_OVERRIDE; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8512 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8513 | virtual void noMatchingTestCases( std::string const& ) CATCH_OVERRIDE {} |
| 8514 | |
| 8515 | virtual void testRunStarting( TestRunInfo const& _testRunInfo ) CATCH_OVERRIDE { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8516 | currentTestRunInfo = _testRunInfo; |
| 8517 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8518 | virtual void testGroupStarting( GroupInfo const& _groupInfo ) CATCH_OVERRIDE { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8519 | currentGroupInfo = _groupInfo; |
| 8520 | } |
| 8521 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8522 | virtual void testCaseStarting( TestCaseInfo const& _testInfo ) CATCH_OVERRIDE { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8523 | currentTestCaseInfo = _testInfo; |
| 8524 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8525 | virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8526 | m_sectionStack.push_back( _sectionInfo ); |
| 8527 | } |
| 8528 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8529 | virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) CATCH_OVERRIDE { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8530 | m_sectionStack.pop_back(); |
| 8531 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8532 | virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) CATCH_OVERRIDE { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8533 | currentTestCaseInfo.reset(); |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8534 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8535 | virtual void testGroupEnded( TestGroupStats const& /* _testGroupStats */ ) CATCH_OVERRIDE { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8536 | currentGroupInfo.reset(); |
| 8537 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8538 | virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) CATCH_OVERRIDE { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8539 | currentTestCaseInfo.reset(); |
| 8540 | currentGroupInfo.reset(); |
| 8541 | currentTestRunInfo.reset(); |
| 8542 | } |
| 8543 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8544 | virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE { |
Phil Nash | 92f0836 | 2014-12-22 20:18:05 +0000 | [diff] [blame] | 8545 | // Don't do anything with this by default. |
| 8546 | // It can optionally be overridden in the derived class. |
| 8547 | } |
| 8548 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 8549 | Ptr<IConfig const> m_config; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8550 | std::ostream& stream; |
| 8551 | |
| 8552 | LazyStat<TestRunInfo> currentTestRunInfo; |
| 8553 | LazyStat<GroupInfo> currentGroupInfo; |
| 8554 | LazyStat<TestCaseInfo> currentTestCaseInfo; |
| 8555 | |
| 8556 | std::vector<SectionInfo> m_sectionStack; |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8557 | ReporterPreferences m_reporterPrefs; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8558 | }; |
| 8559 | |
| 8560 | struct CumulativeReporterBase : SharedImpl<IStreamingReporter> { |
| 8561 | template<typename T, typename ChildNodeT> |
| 8562 | struct Node : SharedImpl<> { |
| 8563 | explicit Node( T const& _value ) : value( _value ) {} |
| 8564 | virtual ~Node() {} |
| 8565 | |
| 8566 | typedef std::vector<Ptr<ChildNodeT> > ChildNodes; |
| 8567 | T value; |
| 8568 | ChildNodes children; |
| 8569 | }; |
| 8570 | struct SectionNode : SharedImpl<> { |
| 8571 | explicit SectionNode( SectionStats const& _stats ) : stats( _stats ) {} |
| 8572 | virtual ~SectionNode(); |
| 8573 | |
| 8574 | bool operator == ( SectionNode const& other ) const { |
| 8575 | return stats.sectionInfo.lineInfo == other.stats.sectionInfo.lineInfo; |
| 8576 | } |
| 8577 | bool operator == ( Ptr<SectionNode> const& other ) const { |
| 8578 | return operator==( *other ); |
| 8579 | } |
| 8580 | |
| 8581 | SectionStats stats; |
| 8582 | typedef std::vector<Ptr<SectionNode> > ChildSections; |
| 8583 | typedef std::vector<AssertionStats> Assertions; |
| 8584 | ChildSections childSections; |
| 8585 | Assertions assertions; |
| 8586 | std::string stdOut; |
| 8587 | std::string stdErr; |
| 8588 | }; |
Phil Nash | eb760f6 | 2013-12-18 08:38:33 +0000 | [diff] [blame] | 8589 | |
| 8590 | struct BySectionInfo { |
| 8591 | BySectionInfo( SectionInfo const& other ) : m_other( other ) {} |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 8592 | BySectionInfo( BySectionInfo const& other ) : m_other( other.m_other ) {} |
Phil Nash | eb760f6 | 2013-12-18 08:38:33 +0000 | [diff] [blame] | 8593 | bool operator() ( Ptr<SectionNode> const& node ) const { |
| 8594 | return node->stats.sectionInfo.lineInfo == m_other.lineInfo; |
| 8595 | } |
| 8596 | private: |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 8597 | void operator=( BySectionInfo const& ); |
Phil Nash | eb760f6 | 2013-12-18 08:38:33 +0000 | [diff] [blame] | 8598 | SectionInfo const& m_other; |
| 8599 | }; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8600 | |
| 8601 | typedef Node<TestCaseStats, SectionNode> TestCaseNode; |
| 8602 | typedef Node<TestGroupStats, TestCaseNode> TestGroupNode; |
| 8603 | typedef Node<TestRunStats, TestGroupNode> TestRunNode; |
| 8604 | |
| 8605 | CumulativeReporterBase( ReporterConfig const& _config ) |
| 8606 | : m_config( _config.fullConfig() ), |
| 8607 | stream( _config.stream() ) |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8608 | { |
| 8609 | m_reporterPrefs.shouldRedirectStdOut = false; |
| 8610 | } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8611 | ~CumulativeReporterBase(); |
| 8612 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8613 | virtual ReporterPreferences getPreferences() const CATCH_OVERRIDE { |
| 8614 | return m_reporterPrefs; |
| 8615 | } |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8616 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8617 | virtual void testRunStarting( TestRunInfo const& ) CATCH_OVERRIDE {} |
| 8618 | virtual void testGroupStarting( GroupInfo const& ) CATCH_OVERRIDE {} |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8619 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8620 | virtual void testCaseStarting( TestCaseInfo const& ) CATCH_OVERRIDE {} |
| 8621 | |
| 8622 | virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8623 | SectionStats incompleteStats( sectionInfo, Counts(), 0, false ); |
| 8624 | Ptr<SectionNode> node; |
| 8625 | if( m_sectionStack.empty() ) { |
| 8626 | if( !m_rootSection ) |
| 8627 | m_rootSection = new SectionNode( incompleteStats ); |
| 8628 | node = m_rootSection; |
| 8629 | } |
| 8630 | else { |
| 8631 | SectionNode& parentNode = *m_sectionStack.back(); |
| 8632 | SectionNode::ChildSections::const_iterator it = |
Phil Nash | eb760f6 | 2013-12-18 08:38:33 +0000 | [diff] [blame] | 8633 | std::find_if( parentNode.childSections.begin(), |
| 8634 | parentNode.childSections.end(), |
| 8635 | BySectionInfo( sectionInfo ) ); |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8636 | if( it == parentNode.childSections.end() ) { |
| 8637 | node = new SectionNode( incompleteStats ); |
| 8638 | parentNode.childSections.push_back( node ); |
| 8639 | } |
| 8640 | else |
| 8641 | node = *it; |
| 8642 | } |
| 8643 | m_sectionStack.push_back( node ); |
| 8644 | m_deepestSection = node; |
| 8645 | } |
| 8646 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8647 | virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {} |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8648 | |
| 8649 | virtual bool assertionEnded( AssertionStats const& assertionStats ) { |
| 8650 | assert( !m_sectionStack.empty() ); |
| 8651 | SectionNode& sectionNode = *m_sectionStack.back(); |
| 8652 | sectionNode.assertions.push_back( assertionStats ); |
| 8653 | return true; |
| 8654 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8655 | virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8656 | assert( !m_sectionStack.empty() ); |
| 8657 | SectionNode& node = *m_sectionStack.back(); |
| 8658 | node.stats = sectionStats; |
| 8659 | m_sectionStack.pop_back(); |
| 8660 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8661 | virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8662 | Ptr<TestCaseNode> node = new TestCaseNode( testCaseStats ); |
| 8663 | assert( m_sectionStack.size() == 0 ); |
| 8664 | node->children.push_back( m_rootSection ); |
| 8665 | m_testCases.push_back( node ); |
| 8666 | m_rootSection.reset(); |
| 8667 | |
| 8668 | assert( m_deepestSection ); |
| 8669 | m_deepestSection->stdOut = testCaseStats.stdOut; |
| 8670 | m_deepestSection->stdErr = testCaseStats.stdErr; |
| 8671 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8672 | virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8673 | Ptr<TestGroupNode> node = new TestGroupNode( testGroupStats ); |
| 8674 | node->children.swap( m_testCases ); |
| 8675 | m_testGroups.push_back( node ); |
| 8676 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8677 | virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE { |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8678 | Ptr<TestRunNode> node = new TestRunNode( testRunStats ); |
| 8679 | node->children.swap( m_testGroups ); |
| 8680 | m_testRuns.push_back( node ); |
Phil Nash | a6d74bd | 2013-12-11 08:28:15 +0000 | [diff] [blame] | 8681 | testRunEndedCumulative(); |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8682 | } |
Phil Nash | a6d74bd | 2013-12-11 08:28:15 +0000 | [diff] [blame] | 8683 | virtual void testRunEndedCumulative() = 0; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8684 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8685 | virtual void skipTest( TestCaseInfo const& ) CATCH_OVERRIDE {} |
Phil Nash | 92f0836 | 2014-12-22 20:18:05 +0000 | [diff] [blame] | 8686 | |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 8687 | Ptr<IConfig const> m_config; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8688 | std::ostream& stream; |
| 8689 | std::vector<AssertionStats> m_assertions; |
| 8690 | std::vector<std::vector<Ptr<SectionNode> > > m_sections; |
| 8691 | std::vector<Ptr<TestCaseNode> > m_testCases; |
| 8692 | std::vector<Ptr<TestGroupNode> > m_testGroups; |
| 8693 | |
| 8694 | std::vector<Ptr<TestRunNode> > m_testRuns; |
| 8695 | |
| 8696 | Ptr<SectionNode> m_rootSection; |
| 8697 | Ptr<SectionNode> m_deepestSection; |
| 8698 | std::vector<Ptr<SectionNode> > m_sectionStack; |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8699 | ReporterPreferences m_reporterPrefs; |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8700 | |
| 8701 | }; |
| 8702 | |
Phil Nash | 576aff6 | 2014-12-21 00:21:23 +0000 | [diff] [blame] | 8703 | template<char C> |
| 8704 | char const* getLineOfChars() { |
| 8705 | static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0}; |
| 8706 | if( !*line ) { |
| 8707 | memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 ); |
| 8708 | line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0; |
| 8709 | } |
| 8710 | return line; |
| 8711 | } |
| 8712 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8713 | struct TestEventListenerBase : StreamingReporterBase { |
| 8714 | TestEventListenerBase( ReporterConfig const& _config ) |
| 8715 | : StreamingReporterBase( _config ) |
| 8716 | {} |
| 8717 | |
| 8718 | virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE {} |
Phil Nash | 08844e7 | 2015-11-05 18:52:18 +0000 | [diff] [blame] | 8719 | virtual bool assertionEnded( AssertionStats const& ) CATCH_OVERRIDE { |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8720 | return false; |
| 8721 | } |
| 8722 | }; |
| 8723 | |
Phil Nash | 3649fdf | 2013-12-03 18:53:55 +0000 | [diff] [blame] | 8724 | } // end namespace Catch |
| 8725 | |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8726 | // #included from: ../internal/catch_reporter_registrars.hpp |
| 8727 | #define TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED |
| 8728 | |
| 8729 | namespace Catch { |
| 8730 | |
| 8731 | template<typename T> |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 8732 | class LegacyReporterRegistrar { |
| 8733 | |
| 8734 | class ReporterFactory : public IReporterFactory { |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 8735 | virtual IStreamingReporter* create( ReporterConfig const& config ) const { |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 8736 | return new LegacyReporterAdapter( new T( config ) ); |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 8737 | } |
| 8738 | |
| 8739 | virtual std::string getDescription() const { |
| 8740 | return T::getDescription(); |
| 8741 | } |
| 8742 | }; |
| 8743 | |
| 8744 | public: |
| 8745 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 8746 | LegacyReporterRegistrar( std::string const& name ) { |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 8747 | getMutableRegistryHub().registerReporter( name, new ReporterFactory() ); |
| 8748 | } |
| 8749 | }; |
| 8750 | |
| 8751 | template<typename T> |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8752 | class ReporterRegistrar { |
| 8753 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8754 | class ReporterFactory : public SharedImpl<IReporterFactory> { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8755 | |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 8756 | // *** Please Note ***: |
| 8757 | // - If you end up here looking at a compiler error because it's trying to register |
| 8758 | // your custom reporter class be aware that the native reporter interface has changed |
| 8759 | // to IStreamingReporter. The "legacy" interface, IReporter, is still supported via |
| 8760 | // an adapter. Just use REGISTER_LEGACY_REPORTER to take advantage of the adapter. |
| 8761 | // However please consider updating to the new interface as the old one is now |
| 8762 | // deprecated and will probably be removed quite soon! |
| 8763 | // Please contact me via github if you have any questions at all about this. |
| 8764 | // In fact, ideally, please contact me anyway to let me know you've hit this - as I have |
| 8765 | // no idea who is actually using custom reporters at all (possibly no-one!). |
| 8766 | // The new interface is designed to minimise exposure to interface changes in the future. |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 8767 | virtual IStreamingReporter* create( ReporterConfig const& config ) const { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8768 | return new T( config ); |
| 8769 | } |
| 8770 | |
| 8771 | virtual std::string getDescription() const { |
| 8772 | return T::getDescription(); |
| 8773 | } |
| 8774 | }; |
| 8775 | |
| 8776 | public: |
| 8777 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 8778 | ReporterRegistrar( std::string const& name ) { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8779 | getMutableRegistryHub().registerReporter( name, new ReporterFactory() ); |
| 8780 | } |
| 8781 | }; |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8782 | |
| 8783 | template<typename T> |
| 8784 | class ListenerRegistrar { |
| 8785 | |
| 8786 | class ListenerFactory : public SharedImpl<IReporterFactory> { |
| 8787 | |
| 8788 | virtual IStreamingReporter* create( ReporterConfig const& config ) const { |
| 8789 | return new T( config ); |
| 8790 | } |
| 8791 | virtual std::string getDescription() const { |
| 8792 | return ""; |
| 8793 | } |
| 8794 | }; |
| 8795 | |
| 8796 | public: |
| 8797 | |
| 8798 | ListenerRegistrar() { |
| 8799 | getMutableRegistryHub().registerListener( new ListenerFactory() ); |
| 8800 | } |
| 8801 | }; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8802 | } |
| 8803 | |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 8804 | #define INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) \ |
Phil Nash | 380f98e | 2013-10-17 22:45:21 +0100 | [diff] [blame] | 8805 | namespace{ Catch::LegacyReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8806 | |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8807 | #define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \ |
Phil Nash | 380f98e | 2013-10-17 22:45:21 +0100 | [diff] [blame] | 8808 | namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8809 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 8810 | #define INTERNAL_CATCH_REGISTER_LISTENER( listenerType ) \ |
| 8811 | namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } |
| 8812 | |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8813 | // #included from: ../internal/catch_xmlwriter.hpp |
| 8814 | #define TWOBLUECUBES_CATCH_XMLWRITER_HPP_INCLUDED |
| 8815 | |
| 8816 | #include <sstream> |
| 8817 | #include <string> |
| 8818 | #include <vector> |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 8819 | #include <iomanip> |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8820 | |
| 8821 | namespace Catch { |
| 8822 | |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 8823 | class XmlEncode { |
| 8824 | public: |
| 8825 | enum ForWhat { ForTextNodes, ForAttributes }; |
| 8826 | |
| 8827 | XmlEncode( std::string const& str, ForWhat forWhat = ForTextNodes ) |
| 8828 | : m_str( str ), |
| 8829 | m_forWhat( forWhat ) |
| 8830 | {} |
| 8831 | |
| 8832 | void encodeTo( std::ostream& os ) const { |
| 8833 | |
| 8834 | // Apostrophe escaping not necessary if we always use " to write attributes |
| 8835 | // (see: http://www.w3.org/TR/xml/#syntax) |
| 8836 | |
| 8837 | for( std::size_t i = 0; i < m_str.size(); ++ i ) { |
| 8838 | char c = m_str[i]; |
| 8839 | switch( c ) { |
| 8840 | case '<': os << "<"; break; |
| 8841 | case '&': os << "&"; break; |
| 8842 | |
| 8843 | case '>': |
| 8844 | // See: http://www.w3.org/TR/xml/#syntax |
| 8845 | if( i > 2 && m_str[i-1] == ']' && m_str[i-2] == ']' ) |
| 8846 | os << ">"; |
| 8847 | else |
| 8848 | os << c; |
| 8849 | break; |
| 8850 | |
| 8851 | case '\"': |
| 8852 | if( m_forWhat == ForAttributes ) |
| 8853 | os << """; |
| 8854 | else |
| 8855 | os << c; |
| 8856 | break; |
| 8857 | |
| 8858 | default: |
| 8859 | // Escape control chars - based on contribution by @espenalb in PR #465 |
| 8860 | if ( ( c < '\x09' ) || ( c > '\x0D' && c < '\x20') || c=='\x7F' ) |
| 8861 | os << "&#x" << std::uppercase << std::hex << static_cast<int>( c ); |
| 8862 | else |
| 8863 | os << c; |
| 8864 | } |
| 8865 | } |
| 8866 | } |
| 8867 | |
| 8868 | friend std::ostream& operator << ( std::ostream& os, XmlEncode const& xmlEncode ) { |
| 8869 | xmlEncode.encodeTo( os ); |
| 8870 | return os; |
| 8871 | } |
| 8872 | |
| 8873 | private: |
| 8874 | std::string m_str; |
| 8875 | ForWhat m_forWhat; |
| 8876 | }; |
| 8877 | |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8878 | class XmlWriter { |
| 8879 | public: |
| 8880 | |
| 8881 | class ScopedElement { |
| 8882 | public: |
| 8883 | ScopedElement( XmlWriter* writer ) |
| 8884 | : m_writer( writer ) |
| 8885 | {} |
| 8886 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 8887 | ScopedElement( ScopedElement const& other ) |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8888 | : m_writer( other.m_writer ){ |
Phil Nash | b971fe7 | 2015-07-02 08:21:38 +0100 | [diff] [blame] | 8889 | other.m_writer = CATCH_NULL; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8890 | } |
| 8891 | |
| 8892 | ~ScopedElement() { |
| 8893 | if( m_writer ) |
| 8894 | m_writer->endElement(); |
| 8895 | } |
| 8896 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 8897 | ScopedElement& writeText( std::string const& text, bool indent = true ) { |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 8898 | m_writer->writeText( text, indent ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8899 | return *this; |
| 8900 | } |
| 8901 | |
| 8902 | template<typename T> |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 8903 | ScopedElement& writeAttribute( std::string const& name, T const& attribute ) { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8904 | m_writer->writeAttribute( name, attribute ); |
| 8905 | return *this; |
| 8906 | } |
| 8907 | |
| 8908 | private: |
| 8909 | mutable XmlWriter* m_writer; |
| 8910 | }; |
| 8911 | |
| 8912 | XmlWriter() |
| 8913 | : m_tagIsOpen( false ), |
| 8914 | m_needsNewline( false ), |
Phil Nash | 383d7c0 | 2014-10-02 19:08:19 +0100 | [diff] [blame] | 8915 | m_os( &Catch::cout() ) |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8916 | {} |
| 8917 | |
| 8918 | XmlWriter( std::ostream& os ) |
| 8919 | : m_tagIsOpen( false ), |
| 8920 | m_needsNewline( false ), |
| 8921 | m_os( &os ) |
| 8922 | {} |
| 8923 | |
| 8924 | ~XmlWriter() { |
| 8925 | while( !m_tags.empty() ) |
| 8926 | endElement(); |
| 8927 | } |
| 8928 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 8929 | XmlWriter& startElement( std::string const& name ) { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8930 | ensureTagClosed(); |
| 8931 | newlineIfNecessary(); |
| 8932 | stream() << m_indent << "<" << name; |
| 8933 | m_tags.push_back( name ); |
| 8934 | m_indent += " "; |
| 8935 | m_tagIsOpen = true; |
| 8936 | return *this; |
| 8937 | } |
| 8938 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 8939 | ScopedElement scopedElement( std::string const& name ) { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8940 | ScopedElement scoped( this ); |
| 8941 | startElement( name ); |
| 8942 | return scoped; |
| 8943 | } |
| 8944 | |
| 8945 | XmlWriter& endElement() { |
| 8946 | newlineIfNecessary(); |
| 8947 | m_indent = m_indent.substr( 0, m_indent.size()-2 ); |
| 8948 | if( m_tagIsOpen ) { |
| 8949 | stream() << "/>\n"; |
| 8950 | m_tagIsOpen = false; |
| 8951 | } |
| 8952 | else { |
| 8953 | stream() << m_indent << "</" << m_tags.back() << ">\n"; |
| 8954 | } |
| 8955 | m_tags.pop_back(); |
| 8956 | return *this; |
| 8957 | } |
| 8958 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 8959 | XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ) { |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 8960 | if( !name.empty() && !attribute.empty() ) |
| 8961 | stream() << " " << name << "=\"" << XmlEncode( attribute, XmlEncode::ForAttributes ) << "\""; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8962 | return *this; |
| 8963 | } |
| 8964 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 8965 | XmlWriter& writeAttribute( std::string const& name, bool attribute ) { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8966 | stream() << " " << name << "=\"" << ( attribute ? "true" : "false" ) << "\""; |
| 8967 | return *this; |
| 8968 | } |
| 8969 | |
| 8970 | template<typename T> |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 8971 | XmlWriter& writeAttribute( std::string const& name, T const& attribute ) { |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 8972 | std::ostringstream oss; |
| 8973 | oss << attribute; |
| 8974 | return writeAttribute( name, oss.str() ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8975 | } |
| 8976 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 8977 | XmlWriter& writeText( std::string const& text, bool indent = true ) { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8978 | if( !text.empty() ){ |
| 8979 | bool tagWasOpen = m_tagIsOpen; |
| 8980 | ensureTagClosed(); |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 8981 | if( tagWasOpen && indent ) |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8982 | stream() << m_indent; |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 8983 | stream() << XmlEncode( text ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8984 | m_needsNewline = true; |
| 8985 | } |
| 8986 | return *this; |
| 8987 | } |
| 8988 | |
Phil Nash | 8defc71 | 2013-04-24 19:10:02 +0100 | [diff] [blame] | 8989 | XmlWriter& writeComment( std::string const& text ) { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 8990 | ensureTagClosed(); |
| 8991 | stream() << m_indent << "<!--" << text << "-->"; |
| 8992 | m_needsNewline = true; |
| 8993 | return *this; |
| 8994 | } |
| 8995 | |
| 8996 | XmlWriter& writeBlankLine() { |
| 8997 | ensureTagClosed(); |
| 8998 | stream() << "\n"; |
| 8999 | return *this; |
| 9000 | } |
| 9001 | |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 9002 | void setStream( std::ostream& os ) { |
| 9003 | m_os = &os; |
| 9004 | } |
| 9005 | |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9006 | private: |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 9007 | XmlWriter( XmlWriter const& ); |
| 9008 | void operator=( XmlWriter const& ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9009 | |
| 9010 | std::ostream& stream() { |
| 9011 | return *m_os; |
| 9012 | } |
| 9013 | |
| 9014 | void ensureTagClosed() { |
| 9015 | if( m_tagIsOpen ) { |
| 9016 | stream() << ">\n"; |
| 9017 | m_tagIsOpen = false; |
| 9018 | } |
| 9019 | } |
| 9020 | |
| 9021 | void newlineIfNecessary() { |
| 9022 | if( m_needsNewline ) { |
| 9023 | stream() << "\n"; |
| 9024 | m_needsNewline = false; |
| 9025 | } |
| 9026 | } |
| 9027 | |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9028 | bool m_tagIsOpen; |
| 9029 | bool m_needsNewline; |
| 9030 | std::vector<std::string> m_tags; |
| 9031 | std::string m_indent; |
| 9032 | std::ostream* m_os; |
| 9033 | }; |
| 9034 | |
| 9035 | } |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 9036 | // #included from: catch_reenable_warnings.h |
| 9037 | |
| 9038 | #define TWOBLUECUBES_CATCH_REENABLE_WARNINGS_H_INCLUDED |
| 9039 | |
| 9040 | #ifdef __clang__ |
| 9041 | # ifdef __ICC // icpc defines the __clang__ macro |
| 9042 | # pragma warning(pop) |
| 9043 | # else |
| 9044 | # pragma clang diagnostic pop |
| 9045 | # endif |
| 9046 | #elif defined __GNUC__ |
| 9047 | # pragma GCC diagnostic pop |
| 9048 | #endif |
| 9049 | |
| 9050 | |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9051 | namespace Catch { |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9052 | class XmlReporter : public StreamingReporterBase { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9053 | public: |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9054 | XmlReporter( ReporterConfig const& _config ) |
| 9055 | : StreamingReporterBase( _config ), |
| 9056 | m_sectionDepth( 0 ) |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9057 | { |
| 9058 | m_reporterPrefs.shouldRedirectStdOut = true; |
| 9059 | } |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9060 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9061 | virtual ~XmlReporter() CATCH_OVERRIDE; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9062 | |
| 9063 | static std::string getDescription() { |
| 9064 | return "Reports test results as an XML document"; |
| 9065 | } |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9066 | |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9067 | public: // StreamingReporterBase |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9068 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9069 | virtual void noMatchingTestCases( std::string const& s ) CATCH_OVERRIDE { |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9070 | StreamingReporterBase::noMatchingTestCases( s ); |
| 9071 | } |
| 9072 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9073 | virtual void testRunStarting( TestRunInfo const& testInfo ) CATCH_OVERRIDE { |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9074 | StreamingReporterBase::testRunStarting( testInfo ); |
| 9075 | m_xml.setStream( stream ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9076 | m_xml.startElement( "Catch" ); |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9077 | if( !m_config->name().empty() ) |
| 9078 | m_xml.writeAttribute( "name", m_config->name() ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9079 | } |
| 9080 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9081 | virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE { |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9082 | StreamingReporterBase::testGroupStarting( groupInfo ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9083 | m_xml.startElement( "Group" ) |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9084 | .writeAttribute( "name", groupInfo.name ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9085 | } |
| 9086 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9087 | virtual void testCaseStarting( TestCaseInfo const& testInfo ) CATCH_OVERRIDE { |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9088 | StreamingReporterBase::testCaseStarting(testInfo); |
| 9089 | m_xml.startElement( "TestCase" ).writeAttribute( "name", trim( testInfo.name ) ); |
| 9090 | |
| 9091 | if ( m_config->showDurations() == ShowDurations::Always ) |
| 9092 | m_testCaseTimer.start(); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9093 | } |
| 9094 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9095 | virtual void sectionStarting( SectionInfo const& sectionInfo ) CATCH_OVERRIDE { |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9096 | StreamingReporterBase::sectionStarting( sectionInfo ); |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 9097 | if( m_sectionDepth++ > 0 ) { |
| 9098 | m_xml.startElement( "Section" ) |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9099 | .writeAttribute( "name", trim( sectionInfo.name ) ) |
| 9100 | .writeAttribute( "description", sectionInfo.description ); |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 9101 | } |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9102 | } |
| 9103 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9104 | virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE { } |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9105 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9106 | virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE { |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9107 | const AssertionResult& assertionResult = assertionStats.assertionResult; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9108 | |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9109 | // Print any info messages in <Info> tags. |
| 9110 | if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) { |
| 9111 | for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); |
| 9112 | it != itEnd; |
| 9113 | ++it ) { |
| 9114 | if( it->type == ResultWas::Info ) { |
| 9115 | m_xml.scopedElement( "Info" ) |
| 9116 | .writeText( it->message ); |
| 9117 | } else if ( it->type == ResultWas::Warning ) { |
| 9118 | m_xml.scopedElement( "Warning" ) |
| 9119 | .writeText( it->message ); |
| 9120 | } |
| 9121 | } |
| 9122 | } |
| 9123 | |
| 9124 | // Drop out if result was successful but we're not printing them. |
| 9125 | if( !m_config->includeSuccessfulResults() && isOk(assertionResult.getResultType()) ) |
| 9126 | return true; |
| 9127 | |
| 9128 | // Print the expression if there is one. |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 9129 | if( assertionResult.hasExpression() ) { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9130 | m_xml.startElement( "Expression" ) |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 9131 | .writeAttribute( "success", assertionResult.succeeded() ) |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9132 | .writeAttribute( "type", assertionResult.getTestMacroName() ) |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 9133 | .writeAttribute( "filename", assertionResult.getSourceInfo().file ) |
| 9134 | .writeAttribute( "line", assertionResult.getSourceInfo().line ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9135 | |
| 9136 | m_xml.scopedElement( "Original" ) |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 9137 | .writeText( assertionResult.getExpression() ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9138 | m_xml.scopedElement( "Expanded" ) |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 9139 | .writeText( assertionResult.getExpandedExpression() ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9140 | } |
| 9141 | |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9142 | // And... Print a result applicable to each result type. |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 9143 | switch( assertionResult.getResultType() ) { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9144 | case ResultWas::ThrewException: |
| 9145 | m_xml.scopedElement( "Exception" ) |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 9146 | .writeAttribute( "filename", assertionResult.getSourceInfo().file ) |
| 9147 | .writeAttribute( "line", assertionResult.getSourceInfo().line ) |
| 9148 | .writeText( assertionResult.getMessage() ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9149 | break; |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 9150 | case ResultWas::FatalErrorCondition: |
| 9151 | m_xml.scopedElement( "Fatal Error Condition" ) |
| 9152 | .writeAttribute( "filename", assertionResult.getSourceInfo().file ) |
| 9153 | .writeAttribute( "line", assertionResult.getSourceInfo().line ) |
| 9154 | .writeText( assertionResult.getMessage() ); |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 9155 | break; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9156 | case ResultWas::Info: |
| 9157 | m_xml.scopedElement( "Info" ) |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 9158 | .writeText( assertionResult.getMessage() ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9159 | break; |
| 9160 | case ResultWas::Warning: |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9161 | // Warning will already have been written |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9162 | break; |
| 9163 | case ResultWas::ExplicitFailure: |
| 9164 | m_xml.scopedElement( "Failure" ) |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 9165 | .writeText( assertionResult.getMessage() ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9166 | break; |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9167 | default: |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9168 | break; |
| 9169 | } |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9170 | |
Phil Nash | ce612bf | 2012-11-01 08:27:09 +0000 | [diff] [blame] | 9171 | if( assertionResult.hasExpression() ) |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9172 | m_xml.endElement(); |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9173 | |
| 9174 | return true; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9175 | } |
| 9176 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9177 | virtual void sectionEnded( SectionStats const& sectionStats ) CATCH_OVERRIDE { |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9178 | StreamingReporterBase::sectionEnded( sectionStats ); |
| 9179 | if( --m_sectionDepth > 0 ) { |
| 9180 | XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResults" ); |
| 9181 | e.writeAttribute( "successes", sectionStats.assertions.passed ); |
| 9182 | e.writeAttribute( "failures", sectionStats.assertions.failed ); |
| 9183 | e.writeAttribute( "expectedFailures", sectionStats.assertions.failedButOk ); |
| 9184 | |
| 9185 | if ( m_config->showDurations() == ShowDurations::Always ) |
| 9186 | e.writeAttribute( "durationInSeconds", sectionStats.durationInSeconds ); |
| 9187 | |
| 9188 | m_xml.endElement(); |
| 9189 | } |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9190 | } |
| 9191 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9192 | virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE { |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9193 | StreamingReporterBase::testCaseEnded( testCaseStats ); |
| 9194 | XmlWriter::ScopedElement e = m_xml.scopedElement( "OverallResult" ); |
| 9195 | e.writeAttribute( "success", testCaseStats.totals.assertions.allOk() ); |
| 9196 | |
| 9197 | if ( m_config->showDurations() == ShowDurations::Always ) |
| 9198 | e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() ); |
| 9199 | |
| 9200 | m_xml.endElement(); |
| 9201 | } |
| 9202 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9203 | virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE { |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9204 | StreamingReporterBase::testGroupEnded( testGroupStats ); |
| 9205 | // TODO: Check testGroupStats.aborting and act accordingly. |
| 9206 | m_xml.scopedElement( "OverallResults" ) |
| 9207 | .writeAttribute( "successes", testGroupStats.totals.assertions.passed ) |
| 9208 | .writeAttribute( "failures", testGroupStats.totals.assertions.failed ) |
| 9209 | .writeAttribute( "expectedFailures", testGroupStats.totals.assertions.failedButOk ); |
| 9210 | m_xml.endElement(); |
| 9211 | } |
| 9212 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9213 | virtual void testRunEnded( TestRunStats const& testRunStats ) CATCH_OVERRIDE { |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9214 | StreamingReporterBase::testRunEnded( testRunStats ); |
| 9215 | m_xml.scopedElement( "OverallResults" ) |
| 9216 | .writeAttribute( "successes", testRunStats.totals.assertions.passed ) |
| 9217 | .writeAttribute( "failures", testRunStats.totals.assertions.failed ) |
| 9218 | .writeAttribute( "expectedFailures", testRunStats.totals.assertions.failedButOk ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9219 | m_xml.endElement(); |
| 9220 | } |
| 9221 | |
| 9222 | private: |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9223 | Timer m_testCaseTimer; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9224 | XmlWriter m_xml; |
Phil Nash | 8a52a39 | 2013-07-25 08:12:03 +0100 | [diff] [blame] | 9225 | int m_sectionDepth; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9226 | }; |
| 9227 | |
Phil Nash | d76e081 | 2014-12-30 18:26:07 +0000 | [diff] [blame] | 9228 | INTERNAL_CATCH_REGISTER_REPORTER( "xml", XmlReporter ) |
| 9229 | |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9230 | } // end namespace Catch |
| 9231 | |
| 9232 | // #included from: ../reporters/catch_reporter_junit.hpp |
| 9233 | #define TWOBLUECUBES_CATCH_REPORTER_JUNIT_HPP_INCLUDED |
| 9234 | |
Phil Nash | f276a05 | 2012-12-02 00:05:51 +0000 | [diff] [blame] | 9235 | #include <assert.h> |
| 9236 | |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9237 | namespace Catch { |
| 9238 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9239 | class JunitReporter : public CumulativeReporterBase { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9240 | public: |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9241 | JunitReporter( ReporterConfig const& _config ) |
| 9242 | : CumulativeReporterBase( _config ), |
| 9243 | xml( _config.stream() ) |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9244 | { |
| 9245 | m_reporterPrefs.shouldRedirectStdOut = true; |
| 9246 | } |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9247 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9248 | virtual ~JunitReporter() CATCH_OVERRIDE; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9249 | |
| 9250 | static std::string getDescription() { |
| 9251 | return "Reports test results in an XML format that looks like Ant's junitreport target"; |
| 9252 | } |
| 9253 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9254 | virtual void noMatchingTestCases( std::string const& /*spec*/ ) CATCH_OVERRIDE {} |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9255 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9256 | virtual void testRunStarting( TestRunInfo const& runInfo ) CATCH_OVERRIDE { |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9257 | CumulativeReporterBase::testRunStarting( runInfo ); |
| 9258 | xml.startElement( "testsuites" ); |
| 9259 | } |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9260 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9261 | virtual void testGroupStarting( GroupInfo const& groupInfo ) CATCH_OVERRIDE { |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9262 | suiteTimer.start(); |
| 9263 | stdOutForSuite.str(""); |
| 9264 | stdErrForSuite.str(""); |
| 9265 | unexpectedExceptions = 0; |
| 9266 | CumulativeReporterBase::testGroupStarting( groupInfo ); |
| 9267 | } |
| 9268 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9269 | virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE { |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9270 | if( assertionStats.assertionResult.getResultType() == ResultWas::ThrewException ) |
| 9271 | unexpectedExceptions++; |
| 9272 | return CumulativeReporterBase::assertionEnded( assertionStats ); |
| 9273 | } |
| 9274 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9275 | virtual void testCaseEnded( TestCaseStats const& testCaseStats ) CATCH_OVERRIDE { |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9276 | stdOutForSuite << testCaseStats.stdOut; |
| 9277 | stdErrForSuite << testCaseStats.stdErr; |
| 9278 | CumulativeReporterBase::testCaseEnded( testCaseStats ); |
| 9279 | } |
| 9280 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9281 | virtual void testGroupEnded( TestGroupStats const& testGroupStats ) CATCH_OVERRIDE { |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9282 | double suiteTime = suiteTimer.getElapsedSeconds(); |
| 9283 | CumulativeReporterBase::testGroupEnded( testGroupStats ); |
| 9284 | writeGroup( *m_testGroups.back(), suiteTime ); |
| 9285 | } |
| 9286 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9287 | virtual void testRunEndedCumulative() CATCH_OVERRIDE { |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9288 | xml.endElement(); |
| 9289 | } |
| 9290 | |
| 9291 | void writeGroup( TestGroupNode const& groupNode, double suiteTime ) { |
| 9292 | XmlWriter::ScopedElement e = xml.scopedElement( "testsuite" ); |
| 9293 | TestGroupStats const& stats = groupNode.value; |
| 9294 | xml.writeAttribute( "name", stats.groupInfo.name ); |
| 9295 | xml.writeAttribute( "errors", unexpectedExceptions ); |
| 9296 | xml.writeAttribute( "failures", stats.totals.assertions.failed-unexpectedExceptions ); |
| 9297 | xml.writeAttribute( "tests", stats.totals.assertions.total() ); |
| 9298 | xml.writeAttribute( "hostname", "tbd" ); // !TBD |
| 9299 | if( m_config->showDurations() == ShowDurations::Never ) |
| 9300 | xml.writeAttribute( "time", "" ); |
Phil Nash | ef60d54 | 2012-11-16 08:47:03 +0000 | [diff] [blame] | 9301 | else |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9302 | xml.writeAttribute( "time", suiteTime ); |
| 9303 | xml.writeAttribute( "timestamp", "tbd" ); // !TBD |
| 9304 | |
| 9305 | // Write test cases |
| 9306 | for( TestGroupNode::ChildNodes::const_iterator |
| 9307 | it = groupNode.children.begin(), itEnd = groupNode.children.end(); |
| 9308 | it != itEnd; |
| 9309 | ++it ) |
| 9310 | writeTestCase( **it ); |
| 9311 | |
| 9312 | xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite.str() ), false ); |
| 9313 | xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9314 | } |
| 9315 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9316 | void writeTestCase( TestCaseNode const& testCaseNode ) { |
| 9317 | TestCaseStats const& stats = testCaseNode.value; |
| 9318 | |
| 9319 | // All test cases have exactly one section - which represents the |
| 9320 | // test case itself. That section may have 0-n nested sections |
| 9321 | assert( testCaseNode.children.size() == 1 ); |
| 9322 | SectionNode const& rootSection = *testCaseNode.children.front(); |
| 9323 | |
| 9324 | std::string className = stats.testInfo.className; |
| 9325 | |
| 9326 | if( className.empty() ) { |
| 9327 | if( rootSection.childSections.empty() ) |
| 9328 | className = "global"; |
| 9329 | } |
| 9330 | writeSection( className, "", rootSection ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9331 | } |
| 9332 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9333 | void writeSection( std::string const& className, |
| 9334 | std::string const& rootName, |
| 9335 | SectionNode const& sectionNode ) { |
| 9336 | std::string name = trim( sectionNode.stats.sectionInfo.name ); |
| 9337 | if( !rootName.empty() ) |
| 9338 | name = rootName + "/" + name; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9339 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9340 | if( !sectionNode.assertions.empty() || |
| 9341 | !sectionNode.stdOut.empty() || |
| 9342 | !sectionNode.stdErr.empty() ) { |
| 9343 | XmlWriter::ScopedElement e = xml.scopedElement( "testcase" ); |
| 9344 | if( className.empty() ) { |
| 9345 | xml.writeAttribute( "classname", name ); |
| 9346 | xml.writeAttribute( "name", "root" ); |
| 9347 | } |
| 9348 | else { |
| 9349 | xml.writeAttribute( "classname", className ); |
| 9350 | xml.writeAttribute( "name", name ); |
| 9351 | } |
Phil Nash | 13f9843 | 2014-12-12 08:11:18 +0000 | [diff] [blame] | 9352 | xml.writeAttribute( "time", Catch::toString( sectionNode.stats.durationInSeconds ) ); |
Phil Nash | a70fbe3 | 2012-08-31 08:10:36 +0100 | [diff] [blame] | 9353 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9354 | writeAssertions( sectionNode ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9355 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9356 | if( !sectionNode.stdOut.empty() ) |
| 9357 | xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false ); |
| 9358 | if( !sectionNode.stdErr.empty() ) |
| 9359 | xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false ); |
| 9360 | } |
| 9361 | for( SectionNode::ChildSections::const_iterator |
| 9362 | it = sectionNode.childSections.begin(), |
| 9363 | itEnd = sectionNode.childSections.end(); |
| 9364 | it != itEnd; |
| 9365 | ++it ) |
| 9366 | if( className.empty() ) |
| 9367 | writeSection( name, "", **it ); |
| 9368 | else |
| 9369 | writeSection( className, name, **it ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9370 | } |
| 9371 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9372 | void writeAssertions( SectionNode const& sectionNode ) { |
| 9373 | for( SectionNode::Assertions::const_iterator |
| 9374 | it = sectionNode.assertions.begin(), itEnd = sectionNode.assertions.end(); |
| 9375 | it != itEnd; |
| 9376 | ++it ) |
| 9377 | writeAssertion( *it ); |
| 9378 | } |
| 9379 | void writeAssertion( AssertionStats const& stats ) { |
| 9380 | AssertionResult const& result = stats.assertionResult; |
| 9381 | if( !result.isOk() ) { |
| 9382 | std::string elementName; |
| 9383 | switch( result.getResultType() ) { |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9384 | case ResultWas::ThrewException: |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 9385 | case ResultWas::FatalErrorCondition: |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9386 | elementName = "error"; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9387 | break; |
| 9388 | case ResultWas::ExplicitFailure: |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9389 | elementName = "failure"; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9390 | break; |
| 9391 | case ResultWas::ExpressionFailed: |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9392 | elementName = "failure"; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9393 | break; |
Phil Nash | 243f2d2 | 2013-04-12 10:43:06 +0100 | [diff] [blame] | 9394 | case ResultWas::DidntThrowException: |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9395 | elementName = "failure"; |
Phil Nash | 243f2d2 | 2013-04-12 10:43:06 +0100 | [diff] [blame] | 9396 | break; |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9397 | |
| 9398 | // We should never see these here: |
| 9399 | case ResultWas::Info: |
| 9400 | case ResultWas::Warning: |
| 9401 | case ResultWas::Ok: |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9402 | case ResultWas::Unknown: |
| 9403 | case ResultWas::FailureBit: |
| 9404 | case ResultWas::Exception: |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9405 | elementName = "internalError"; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9406 | break; |
| 9407 | } |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9408 | |
| 9409 | XmlWriter::ScopedElement e = xml.scopedElement( elementName ); |
| 9410 | |
| 9411 | xml.writeAttribute( "message", result.getExpandedExpression() ); |
| 9412 | xml.writeAttribute( "type", result.getTestMacroName() ); |
| 9413 | |
| 9414 | std::ostringstream oss; |
| 9415 | if( !result.getMessage().empty() ) |
| 9416 | oss << result.getMessage() << "\n"; |
| 9417 | for( std::vector<MessageInfo>::const_iterator |
| 9418 | it = stats.infoMessages.begin(), |
| 9419 | itEnd = stats.infoMessages.end(); |
| 9420 | it != itEnd; |
| 9421 | ++it ) |
| 9422 | if( it->type == ResultWas::Info ) |
| 9423 | oss << it->message << "\n"; |
| 9424 | |
| 9425 | oss << "at " << result.getSourceInfo(); |
| 9426 | xml.writeText( oss.str(), false ); |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9427 | } |
| 9428 | } |
| 9429 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9430 | XmlWriter xml; |
| 9431 | Timer suiteTimer; |
| 9432 | std::ostringstream stdOutForSuite; |
| 9433 | std::ostringstream stdErrForSuite; |
| 9434 | unsigned int unexpectedExceptions; |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9435 | }; |
| 9436 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9437 | INTERNAL_CATCH_REGISTER_REPORTER( "junit", JunitReporter ) |
| 9438 | |
Phil Nash | 56d5c42 | 2012-08-23 20:08:50 +0100 | [diff] [blame] | 9439 | } // end namespace Catch |
| 9440 | |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 9441 | // #included from: ../reporters/catch_reporter_console.hpp |
| 9442 | #define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_HPP_INCLUDED |
| 9443 | |
| 9444 | namespace Catch { |
| 9445 | |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9446 | struct ConsoleReporter : StreamingReporterBase { |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 9447 | ConsoleReporter( ReporterConfig const& _config ) |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9448 | : StreamingReporterBase( _config ), |
Phil Nash | 08e5296 | 2014-07-03 19:08:44 +0100 | [diff] [blame] | 9449 | m_headerPrinted( false ) |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 9450 | {} |
| 9451 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9452 | virtual ~ConsoleReporter() CATCH_OVERRIDE; |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 9453 | static std::string getDescription() { |
| 9454 | return "Reports test results as plain lines of text"; |
| 9455 | } |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 9456 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9457 | virtual void noMatchingTestCases( std::string const& spec ) CATCH_OVERRIDE { |
Phil Nash | 37186a1 | 2013-03-13 12:19:30 +0000 | [diff] [blame] | 9458 | stream << "No test cases matched '" << spec << "'" << std::endl; |
| 9459 | } |
| 9460 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9461 | virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE { |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 9462 | } |
Phil Nash | bcad093 | 2012-12-10 08:54:57 +0000 | [diff] [blame] | 9463 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9464 | virtual bool assertionEnded( AssertionStats const& _assertionStats ) CATCH_OVERRIDE { |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9465 | AssertionResult const& result = _assertionStats.assertionResult; |
Phil Nash | bcad093 | 2012-12-10 08:54:57 +0000 | [diff] [blame] | 9466 | |
Phil Nash | 8d44f2d | 2013-11-13 08:10:45 +0000 | [diff] [blame] | 9467 | bool printInfoMessages = true; |
| 9468 | |
Phil Nash | bcad093 | 2012-12-10 08:54:57 +0000 | [diff] [blame] | 9469 | // Drop out if result was successful and we're not printing those |
Phil Nash | 8d44f2d | 2013-11-13 08:10:45 +0000 | [diff] [blame] | 9470 | if( !m_config->includeSuccessfulResults() && result.isOk() ) { |
| 9471 | if( result.getResultType() != ResultWas::Warning ) |
| 9472 | return false; |
| 9473 | printInfoMessages = false; |
| 9474 | } |
Phil Nash | bcad093 | 2012-12-10 08:54:57 +0000 | [diff] [blame] | 9475 | |
| 9476 | lazyPrint(); |
| 9477 | |
Phil Nash | 8d44f2d | 2013-11-13 08:10:45 +0000 | [diff] [blame] | 9478 | AssertionPrinter printer( stream, _assertionStats, printInfoMessages ); |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9479 | printer.print(); |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9480 | stream << std::endl; |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 9481 | return true; |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9482 | } |
| 9483 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9484 | virtual void sectionStarting( SectionInfo const& _sectionInfo ) CATCH_OVERRIDE { |
Phil Nash | a04981b | 2013-03-08 09:30:25 +0000 | [diff] [blame] | 9485 | m_headerPrinted = false; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9486 | StreamingReporterBase::sectionStarting( _sectionInfo ); |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9487 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9488 | virtual void sectionEnded( SectionStats const& _sectionStats ) CATCH_OVERRIDE { |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9489 | if( _sectionStats.missingAssertions ) { |
| 9490 | lazyPrint(); |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9491 | Colour colour( Colour::ResultError ); |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9492 | if( m_sectionStack.size() > 1 ) |
| 9493 | stream << "\nNo assertions in section"; |
| 9494 | else |
| 9495 | stream << "\nNo assertions in test case"; |
| 9496 | stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl; |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9497 | } |
Phil Nash | 4611871 | 2013-08-16 19:01:32 +0100 | [diff] [blame] | 9498 | if( m_headerPrinted ) { |
| 9499 | if( m_config->showDurations() == ShowDurations::Always ) |
| 9500 | stream << "Completed in " << _sectionStats.durationInSeconds << "s" << std::endl; |
| 9501 | m_headerPrinted = false; |
| 9502 | } |
Phil Nash | f7378ee | 2013-09-07 12:07:38 +0100 | [diff] [blame] | 9503 | else { |
| 9504 | if( m_config->showDurations() == ShowDurations::Always ) |
| 9505 | stream << _sectionStats.sectionInfo.name << " completed in " << _sectionStats.durationInSeconds << "s" << std::endl; |
| 9506 | } |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9507 | StreamingReporterBase::sectionEnded( _sectionStats ); |
| 9508 | } |
| 9509 | |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9510 | virtual void testCaseEnded( TestCaseStats const& _testCaseStats ) CATCH_OVERRIDE { |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9511 | StreamingReporterBase::testCaseEnded( _testCaseStats ); |
Phil Nash | a04981b | 2013-03-08 09:30:25 +0000 | [diff] [blame] | 9512 | m_headerPrinted = false; |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9513 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9514 | virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) CATCH_OVERRIDE { |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9515 | if( currentGroupInfo.used ) { |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9516 | printSummaryDivider(); |
| 9517 | stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n"; |
| 9518 | printTotals( _testGroupStats.totals ); |
| 9519 | stream << "\n" << std::endl; |
| 9520 | } |
| 9521 | StreamingReporterBase::testGroupEnded( _testGroupStats ); |
| 9522 | } |
Phil Nash | e73583d | 2015-08-07 17:30:34 +0100 | [diff] [blame] | 9523 | virtual void testRunEnded( TestRunStats const& _testRunStats ) CATCH_OVERRIDE { |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 9524 | printTotalsDivider( _testRunStats.totals ); |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9525 | printTotals( _testRunStats.totals ); |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 9526 | stream << std::endl; |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9527 | StreamingReporterBase::testRunEnded( _testRunStats ); |
| 9528 | } |
| 9529 | |
| 9530 | private: |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9531 | |
| 9532 | class AssertionPrinter { |
Phil Nash | 503d5d0 | 2013-07-03 08:25:11 +0100 | [diff] [blame] | 9533 | void operator= ( AssertionPrinter const& ); |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9534 | public: |
Phil Nash | 8d44f2d | 2013-11-13 08:10:45 +0000 | [diff] [blame] | 9535 | AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages ) |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9536 | : stream( _stream ), |
| 9537 | stats( _stats ), |
| 9538 | result( _stats.assertionResult ), |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9539 | colour( Colour::None ), |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 9540 | message( result.getMessage() ), |
Phil Nash | 8d44f2d | 2013-11-13 08:10:45 +0000 | [diff] [blame] | 9541 | messages( _stats.infoMessages ), |
| 9542 | printInfoMessages( _printInfoMessages ) |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9543 | { |
| 9544 | switch( result.getResultType() ) { |
| 9545 | case ResultWas::Ok: |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9546 | colour = Colour::Success; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9547 | passOrFail = "PASSED"; |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 9548 | //if( result.hasMessage() ) |
| 9549 | if( _stats.infoMessages.size() == 1 ) |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9550 | messageLabel = "with message"; |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 9551 | if( _stats.infoMessages.size() > 1 ) |
| 9552 | messageLabel = "with messages"; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9553 | break; |
| 9554 | case ResultWas::ExpressionFailed: |
| 9555 | if( result.isOk() ) { |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9556 | colour = Colour::Success; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9557 | passOrFail = "FAILED - but was ok"; |
| 9558 | } |
| 9559 | else { |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9560 | colour = Colour::Error; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9561 | passOrFail = "FAILED"; |
| 9562 | } |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 9563 | if( _stats.infoMessages.size() == 1 ) |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9564 | messageLabel = "with message"; |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 9565 | if( _stats.infoMessages.size() > 1 ) |
| 9566 | messageLabel = "with messages"; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9567 | break; |
| 9568 | case ResultWas::ThrewException: |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9569 | colour = Colour::Error; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9570 | passOrFail = "FAILED"; |
| 9571 | messageLabel = "due to unexpected exception with message"; |
| 9572 | break; |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 9573 | case ResultWas::FatalErrorCondition: |
| 9574 | colour = Colour::Error; |
| 9575 | passOrFail = "FAILED"; |
| 9576 | messageLabel = "due to a fatal error condition"; |
| 9577 | break; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9578 | case ResultWas::DidntThrowException: |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9579 | colour = Colour::Error; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9580 | passOrFail = "FAILED"; |
| 9581 | messageLabel = "because no exception was thrown where one was expected"; |
| 9582 | break; |
| 9583 | case ResultWas::Info: |
| 9584 | messageLabel = "info"; |
| 9585 | break; |
| 9586 | case ResultWas::Warning: |
| 9587 | messageLabel = "warning"; |
| 9588 | break; |
| 9589 | case ResultWas::ExplicitFailure: |
| 9590 | passOrFail = "FAILED"; |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9591 | colour = Colour::Error; |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 9592 | if( _stats.infoMessages.size() == 1 ) |
| 9593 | messageLabel = "explicitly with message"; |
| 9594 | if( _stats.infoMessages.size() > 1 ) |
| 9595 | messageLabel = "explicitly with messages"; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9596 | break; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9597 | // These cases are here to prevent compiler warnings |
| 9598 | case ResultWas::Unknown: |
| 9599 | case ResultWas::FailureBit: |
Phil Nash | 243f2d2 | 2013-04-12 10:43:06 +0100 | [diff] [blame] | 9600 | case ResultWas::Exception: |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9601 | passOrFail = "** internal error **"; |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9602 | colour = Colour::Error; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9603 | break; |
| 9604 | } |
| 9605 | } |
| 9606 | |
| 9607 | void print() const { |
Phil Nash | 767f158 | 2013-03-04 12:19:15 +0100 | [diff] [blame] | 9608 | printSourceInfo(); |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9609 | if( stats.totals.assertions.total() > 0 ) { |
Phil Nash | 767f158 | 2013-03-04 12:19:15 +0100 | [diff] [blame] | 9610 | if( result.isOk() ) |
| 9611 | stream << "\n"; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9612 | printResultType(); |
| 9613 | printOriginalExpression(); |
| 9614 | printReconstructedExpression(); |
| 9615 | } |
Phil Nash | 767f158 | 2013-03-04 12:19:15 +0100 | [diff] [blame] | 9616 | else { |
| 9617 | stream << "\n"; |
| 9618 | } |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9619 | printMessage(); |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9620 | } |
| 9621 | |
| 9622 | private: |
| 9623 | void printResultType() const { |
| 9624 | if( !passOrFail.empty() ) { |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9625 | Colour colourGuard( colour ); |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9626 | stream << passOrFail << ":\n"; |
| 9627 | } |
| 9628 | } |
| 9629 | void printOriginalExpression() const { |
| 9630 | if( result.hasExpression() ) { |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9631 | Colour colourGuard( Colour::OriginalExpression ); |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9632 | stream << " "; |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 9633 | stream << result.getExpressionInMacro(); |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9634 | stream << "\n"; |
| 9635 | } |
| 9636 | } |
| 9637 | void printReconstructedExpression() const { |
| 9638 | if( result.hasExpandedExpression() ) { |
| 9639 | stream << "with expansion:\n"; |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9640 | Colour colourGuard( Colour::ReconstructedExpression ); |
Phil Nash | 1927925 | 2013-04-20 21:07:32 +0100 | [diff] [blame] | 9641 | stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << "\n"; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9642 | } |
| 9643 | } |
| 9644 | void printMessage() const { |
| 9645 | if( !messageLabel.empty() ) |
| 9646 | stream << messageLabel << ":" << "\n"; |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 9647 | for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end(); |
| 9648 | it != itEnd; |
| 9649 | ++it ) { |
Phil Nash | 8d44f2d | 2013-11-13 08:10:45 +0000 | [diff] [blame] | 9650 | // If this assertion is a warning ignore any INFO messages |
| 9651 | if( printInfoMessages || it->type != ResultWas::Info ) |
| 9652 | stream << Text( it->message, TextAttributes().setIndent(2) ) << "\n"; |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 9653 | } |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9654 | } |
| 9655 | void printSourceInfo() const { |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9656 | Colour colourGuard( Colour::FileName ); |
Phil Nash | 767f158 | 2013-03-04 12:19:15 +0100 | [diff] [blame] | 9657 | stream << result.getSourceInfo() << ": "; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9658 | } |
| 9659 | |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9660 | std::ostream& stream; |
| 9661 | AssertionStats const& stats; |
| 9662 | AssertionResult const& result; |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9663 | Colour::Code colour; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9664 | std::string passOrFail; |
| 9665 | std::string messageLabel; |
| 9666 | std::string message; |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 9667 | std::vector<MessageInfo> messages; |
Phil Nash | 8d44f2d | 2013-11-13 08:10:45 +0000 | [diff] [blame] | 9668 | bool printInfoMessages; |
Phil Nash | e475645 | 2013-01-26 20:18:30 +0000 | [diff] [blame] | 9669 | }; |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9670 | |
| 9671 | void lazyPrint() { |
| 9672 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9673 | if( !currentTestRunInfo.used ) |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9674 | lazyPrintRunInfo(); |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9675 | if( !currentGroupInfo.used ) |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9676 | lazyPrintGroupInfo(); |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9677 | |
Phil Nash | a04981b | 2013-03-08 09:30:25 +0000 | [diff] [blame] | 9678 | if( !m_headerPrinted ) { |
| 9679 | printTestCaseAndSectionHeader(); |
| 9680 | m_headerPrinted = true; |
| 9681 | } |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9682 | } |
| 9683 | void lazyPrintRunInfo() { |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 9684 | stream << "\n" << getLineOfChars<'~'>() << "\n"; |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9685 | Colour colour( Colour::SecondaryText ); |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9686 | stream << currentTestRunInfo->name |
Phil Nash | 21f7ef6 | 2015-06-29 18:05:23 +0100 | [diff] [blame] | 9687 | << " is a Catch v" << libraryVersion << " host application.\n" |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9688 | << "Run with -? for options\n\n"; |
| 9689 | |
Phil Nash | 6a8e8ad | 2014-09-15 18:40:24 +0100 | [diff] [blame] | 9690 | if( m_config->rngSeed() != 0 ) |
| 9691 | stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n"; |
| 9692 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9693 | currentTestRunInfo.used = true; |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9694 | } |
| 9695 | void lazyPrintGroupInfo() { |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9696 | if( !currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1 ) { |
| 9697 | printClosedHeader( "Group: " + currentGroupInfo->name ); |
| 9698 | currentGroupInfo.used = true; |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9699 | } |
| 9700 | } |
Phil Nash | a04981b | 2013-03-08 09:30:25 +0000 | [diff] [blame] | 9701 | void printTestCaseAndSectionHeader() { |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9702 | assert( !m_sectionStack.empty() ); |
| 9703 | printOpenHeader( currentTestCaseInfo->name ); |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9704 | |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9705 | if( m_sectionStack.size() > 1 ) { |
| 9706 | Colour colourGuard( Colour::Headers ); |
| 9707 | |
| 9708 | std::vector<SectionInfo>::const_iterator |
| 9709 | it = m_sectionStack.begin()+1, // Skip first section (test case) |
| 9710 | itEnd = m_sectionStack.end(); |
| 9711 | for( ; it != itEnd; ++it ) |
| 9712 | printHeaderString( it->name, 2 ); |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9713 | } |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 9714 | |
| 9715 | SourceLineInfo lineInfo = m_sectionStack.front().lineInfo; |
Phil Nash | 1927925 | 2013-04-20 21:07:32 +0100 | [diff] [blame] | 9716 | |
| 9717 | if( !lineInfo.empty() ){ |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 9718 | stream << getLineOfChars<'-'>() << "\n"; |
Phil Nash | 1927925 | 2013-04-20 21:07:32 +0100 | [diff] [blame] | 9719 | Colour colourGuard( Colour::FileName ); |
| 9720 | stream << lineInfo << "\n"; |
| 9721 | } |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 9722 | stream << getLineOfChars<'.'>() << "\n" << std::endl; |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9723 | } |
| 9724 | |
Phil Nash | a04981b | 2013-03-08 09:30:25 +0000 | [diff] [blame] | 9725 | void printClosedHeader( std::string const& _name ) { |
| 9726 | printOpenHeader( _name ); |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 9727 | stream << getLineOfChars<'.'>() << "\n"; |
Phil Nash | a04981b | 2013-03-08 09:30:25 +0000 | [diff] [blame] | 9728 | } |
Phil Nash | 1927925 | 2013-04-20 21:07:32 +0100 | [diff] [blame] | 9729 | void printOpenHeader( std::string const& _name ) { |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 9730 | stream << getLineOfChars<'-'>() << "\n"; |
Phil Nash | 5c7d3d7 | 2013-04-01 11:27:10 +0100 | [diff] [blame] | 9731 | { |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9732 | Colour colourGuard( Colour::Headers ); |
Phil Nash | 1927925 | 2013-04-20 21:07:32 +0100 | [diff] [blame] | 9733 | printHeaderString( _name ); |
Phil Nash | 5c7d3d7 | 2013-04-01 11:27:10 +0100 | [diff] [blame] | 9734 | } |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9735 | } |
| 9736 | |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9737 | // if string has a : in first line will set indent to follow it on |
| 9738 | // subsequent lines |
Phil Nash | 1927925 | 2013-04-20 21:07:32 +0100 | [diff] [blame] | 9739 | void printHeaderString( std::string const& _string, std::size_t indent = 0 ) { |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9740 | std::size_t i = _string.find( ": " ); |
| 9741 | if( i != std::string::npos ) |
| 9742 | i+=2; |
| 9743 | else |
| 9744 | i = 0; |
Phil Nash | 1927925 | 2013-04-20 21:07:32 +0100 | [diff] [blame] | 9745 | stream << Text( _string, TextAttributes() |
| 9746 | .setIndent( indent+i) |
| 9747 | .setInitialIndent( indent ) ) << "\n"; |
Phil Nash | 12c16ff | 2013-04-05 20:58:01 +0100 | [diff] [blame] | 9748 | } |
| 9749 | |
Phil Nash | 28c2e07 | 2014-07-09 19:22:49 +0100 | [diff] [blame] | 9750 | struct SummaryColumn { |
| 9751 | |
| 9752 | SummaryColumn( std::string const& _label, Colour::Code _colour ) |
| 9753 | : label( _label ), |
| 9754 | colour( _colour ) |
| 9755 | {} |
| 9756 | SummaryColumn addRow( std::size_t count ) { |
| 9757 | std::ostringstream oss; |
| 9758 | oss << count; |
| 9759 | std::string row = oss.str(); |
| 9760 | for( std::vector<std::string>::iterator it = rows.begin(); it != rows.end(); ++it ) { |
| 9761 | while( it->size() < row.size() ) |
Phil Nash | ca42b2c | 2014-07-10 09:18:50 +0100 | [diff] [blame] | 9762 | *it = " " + *it; |
Phil Nash | 28c2e07 | 2014-07-09 19:22:49 +0100 | [diff] [blame] | 9763 | while( it->size() > row.size() ) |
| 9764 | row = " " + row; |
| 9765 | } |
| 9766 | rows.push_back( row ); |
| 9767 | return *this; |
| 9768 | } |
| 9769 | |
| 9770 | std::string label; |
| 9771 | Colour::Code colour; |
| 9772 | std::vector<std::string> rows; |
| 9773 | |
| 9774 | }; |
| 9775 | |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 9776 | void printTotals( Totals const& totals ) { |
Phil Nash | 8d44f2d | 2013-11-13 08:10:45 +0000 | [diff] [blame] | 9777 | if( totals.testCases.total() == 0 ) { |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 9778 | stream << Colour( Colour::Warning ) << "No tests ran\n"; |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9779 | } |
Phil Nash | 28c2e07 | 2014-07-09 19:22:49 +0100 | [diff] [blame] | 9780 | else if( totals.assertions.total() > 0 && totals.assertions.allPassed() ) { |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 9781 | stream << Colour( Colour::ResultSuccess ) << "All tests passed"; |
| 9782 | stream << " (" |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9783 | << pluralise( totals.assertions.passed, "assertion" ) << " in " |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 9784 | << pluralise( totals.testCases.passed, "test case" ) << ")" |
| 9785 | << "\n"; |
Phil Nash | bcad093 | 2012-12-10 08:54:57 +0000 | [diff] [blame] | 9786 | } |
Phil Nash | 28c2e07 | 2014-07-09 19:22:49 +0100 | [diff] [blame] | 9787 | else { |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 9788 | |
Phil Nash | 28c2e07 | 2014-07-09 19:22:49 +0100 | [diff] [blame] | 9789 | std::vector<SummaryColumn> columns; |
| 9790 | columns.push_back( SummaryColumn( "", Colour::None ) |
| 9791 | .addRow( totals.testCases.total() ) |
| 9792 | .addRow( totals.assertions.total() ) ); |
| 9793 | columns.push_back( SummaryColumn( "passed", Colour::Success ) |
| 9794 | .addRow( totals.testCases.passed ) |
| 9795 | .addRow( totals.assertions.passed ) ); |
| 9796 | columns.push_back( SummaryColumn( "failed", Colour::ResultError ) |
| 9797 | .addRow( totals.testCases.failed ) |
| 9798 | .addRow( totals.assertions.failed ) ); |
| 9799 | columns.push_back( SummaryColumn( "failed as expected", Colour::ResultExpectedFailure ) |
| 9800 | .addRow( totals.testCases.failedButOk ) |
| 9801 | .addRow( totals.assertions.failedButOk ) ); |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 9802 | |
Phil Nash | 28c2e07 | 2014-07-09 19:22:49 +0100 | [diff] [blame] | 9803 | printSummaryRow( "test cases", columns, 0 ); |
| 9804 | printSummaryRow( "assertions", columns, 1 ); |
Phil Nash | f117812 | 2012-12-11 09:03:14 +0000 | [diff] [blame] | 9805 | } |
Phil Nash | 28c2e07 | 2014-07-09 19:22:49 +0100 | [diff] [blame] | 9806 | } |
| 9807 | void printSummaryRow( std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row ) { |
| 9808 | for( std::vector<SummaryColumn>::const_iterator it = cols.begin(); it != cols.end(); ++it ) { |
| 9809 | std::string value = it->rows[row]; |
| 9810 | if( it->label.empty() ) { |
| 9811 | stream << label << ": "; |
| 9812 | if( value != "0" ) |
| 9813 | stream << value; |
| 9814 | else |
| 9815 | stream << Colour( Colour::Warning ) << "- none -"; |
| 9816 | } |
| 9817 | else if( value != "0" ) { |
| 9818 | stream << Colour( Colour::LightGrey ) << " | "; |
| 9819 | stream << Colour( it->colour ) |
| 9820 | << value << " " << it->label; |
| 9821 | } |
| 9822 | } |
| 9823 | stream << "\n"; |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 9824 | } |
| 9825 | |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 9826 | static std::size_t makeRatio( std::size_t number, std::size_t total ) { |
| 9827 | std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0; |
| 9828 | return ( ratio == 0 && number > 0 ) ? 1 : ratio; |
| 9829 | } |
| 9830 | static std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) { |
| 9831 | if( i > j && i > k ) |
| 9832 | return i; |
| 9833 | else if( j > k ) |
| 9834 | return j; |
| 9835 | else |
| 9836 | return k; |
| 9837 | } |
| 9838 | |
| 9839 | void printTotalsDivider( Totals const& totals ) { |
| 9840 | if( totals.testCases.total() > 0 ) { |
| 9841 | std::size_t failedRatio = makeRatio( totals.testCases.failed, totals.testCases.total() ); |
| 9842 | std::size_t failedButOkRatio = makeRatio( totals.testCases.failedButOk, totals.testCases.total() ); |
| 9843 | std::size_t passedRatio = makeRatio( totals.testCases.passed, totals.testCases.total() ); |
| 9844 | while( failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH-1 ) |
| 9845 | findMax( failedRatio, failedButOkRatio, passedRatio )++; |
| 9846 | while( failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH-1 ) |
| 9847 | findMax( failedRatio, failedButOkRatio, passedRatio )--; |
| 9848 | |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 9849 | stream << Colour( Colour::Error ) << std::string( failedRatio, '=' ); |
| 9850 | stream << Colour( Colour::ResultExpectedFailure ) << std::string( failedButOkRatio, '=' ); |
Phil Nash | 28c2e07 | 2014-07-09 19:22:49 +0100 | [diff] [blame] | 9851 | if( totals.testCases.allPassed() ) |
| 9852 | stream << Colour( Colour::ResultSuccess ) << std::string( passedRatio, '=' ); |
| 9853 | else |
| 9854 | stream << Colour( Colour::Success ) << std::string( passedRatio, '=' ); |
Phil Nash | 52e1e74 | 2014-07-03 08:11:38 +0100 | [diff] [blame] | 9855 | } |
| 9856 | else { |
| 9857 | stream << Colour( Colour::Warning ) << std::string( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' ); |
| 9858 | } |
| 9859 | stream << "\n"; |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 9860 | } |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 9861 | void printSummaryDivider() { |
Phil Nash | aef6cd5 | 2014-04-23 07:10:10 +0100 | [diff] [blame] | 9862 | stream << getLineOfChars<'-'>() << "\n"; |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 9863 | } |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 9864 | |
Phil Nash | cf5ced5 | 2012-12-14 07:50:08 +0000 | [diff] [blame] | 9865 | private: |
Phil Nash | a04981b | 2013-03-08 09:30:25 +0000 | [diff] [blame] | 9866 | bool m_headerPrinted; |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 9867 | }; |
| 9868 | |
| 9869 | INTERNAL_CATCH_REGISTER_REPORTER( "console", ConsoleReporter ) |
| 9870 | |
| 9871 | } // end namespace Catch |
| 9872 | |
Phil Nash | 5a2df71 | 2014-05-01 19:07:02 +0100 | [diff] [blame] | 9873 | // #included from: ../reporters/catch_reporter_compact.hpp |
| 9874 | #define TWOBLUECUBES_CATCH_REPORTER_COMPACT_HPP_INCLUDED |
| 9875 | |
| 9876 | namespace Catch { |
| 9877 | |
| 9878 | struct CompactReporter : StreamingReporterBase { |
| 9879 | |
| 9880 | CompactReporter( ReporterConfig const& _config ) |
| 9881 | : StreamingReporterBase( _config ) |
| 9882 | {} |
| 9883 | |
| 9884 | virtual ~CompactReporter(); |
| 9885 | |
| 9886 | static std::string getDescription() { |
| 9887 | return "Reports test results on a single line, suitable for IDEs"; |
| 9888 | } |
| 9889 | |
| 9890 | virtual ReporterPreferences getPreferences() const { |
| 9891 | ReporterPreferences prefs; |
| 9892 | prefs.shouldRedirectStdOut = false; |
| 9893 | return prefs; |
| 9894 | } |
| 9895 | |
| 9896 | virtual void noMatchingTestCases( std::string const& spec ) { |
| 9897 | stream << "No test cases matched '" << spec << "'" << std::endl; |
| 9898 | } |
| 9899 | |
| 9900 | virtual void assertionStarting( AssertionInfo const& ) { |
| 9901 | } |
| 9902 | |
| 9903 | virtual bool assertionEnded( AssertionStats const& _assertionStats ) { |
| 9904 | AssertionResult const& result = _assertionStats.assertionResult; |
| 9905 | |
| 9906 | bool printInfoMessages = true; |
| 9907 | |
| 9908 | // Drop out if result was successful and we're not printing those |
| 9909 | if( !m_config->includeSuccessfulResults() && result.isOk() ) { |
| 9910 | if( result.getResultType() != ResultWas::Warning ) |
| 9911 | return false; |
| 9912 | printInfoMessages = false; |
| 9913 | } |
| 9914 | |
| 9915 | AssertionPrinter printer( stream, _assertionStats, printInfoMessages ); |
| 9916 | printer.print(); |
| 9917 | |
| 9918 | stream << std::endl; |
| 9919 | return true; |
| 9920 | } |
| 9921 | |
| 9922 | virtual void testRunEnded( TestRunStats const& _testRunStats ) { |
| 9923 | printTotals( _testRunStats.totals ); |
| 9924 | stream << "\n" << std::endl; |
| 9925 | StreamingReporterBase::testRunEnded( _testRunStats ); |
| 9926 | } |
| 9927 | |
| 9928 | private: |
| 9929 | class AssertionPrinter { |
| 9930 | void operator= ( AssertionPrinter const& ); |
| 9931 | public: |
| 9932 | AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages ) |
| 9933 | : stream( _stream ) |
| 9934 | , stats( _stats ) |
| 9935 | , result( _stats.assertionResult ) |
| 9936 | , messages( _stats.infoMessages ) |
| 9937 | , itMessage( _stats.infoMessages.begin() ) |
| 9938 | , printInfoMessages( _printInfoMessages ) |
| 9939 | {} |
| 9940 | |
| 9941 | void print() { |
| 9942 | printSourceInfo(); |
| 9943 | |
| 9944 | itMessage = messages.begin(); |
| 9945 | |
| 9946 | switch( result.getResultType() ) { |
| 9947 | case ResultWas::Ok: |
| 9948 | printResultType( Colour::ResultSuccess, passedString() ); |
| 9949 | printOriginalExpression(); |
| 9950 | printReconstructedExpression(); |
| 9951 | if ( ! result.hasExpression() ) |
| 9952 | printRemainingMessages( Colour::None ); |
| 9953 | else |
| 9954 | printRemainingMessages(); |
| 9955 | break; |
| 9956 | case ResultWas::ExpressionFailed: |
| 9957 | if( result.isOk() ) |
| 9958 | printResultType( Colour::ResultSuccess, failedString() + std::string( " - but was ok" ) ); |
| 9959 | else |
| 9960 | printResultType( Colour::Error, failedString() ); |
| 9961 | printOriginalExpression(); |
| 9962 | printReconstructedExpression(); |
| 9963 | printRemainingMessages(); |
| 9964 | break; |
| 9965 | case ResultWas::ThrewException: |
| 9966 | printResultType( Colour::Error, failedString() ); |
| 9967 | printIssue( "unexpected exception with message:" ); |
| 9968 | printMessage(); |
| 9969 | printExpressionWas(); |
| 9970 | printRemainingMessages(); |
| 9971 | break; |
Phil Nash | 93b61e1 | 2014-08-22 19:35:41 +0100 | [diff] [blame] | 9972 | case ResultWas::FatalErrorCondition: |
| 9973 | printResultType( Colour::Error, failedString() ); |
| 9974 | printIssue( "fatal error condition with message:" ); |
| 9975 | printMessage(); |
| 9976 | printExpressionWas(); |
| 9977 | printRemainingMessages(); |
| 9978 | break; |
Phil Nash | 5a2df71 | 2014-05-01 19:07:02 +0100 | [diff] [blame] | 9979 | case ResultWas::DidntThrowException: |
| 9980 | printResultType( Colour::Error, failedString() ); |
| 9981 | printIssue( "expected exception, got none" ); |
| 9982 | printExpressionWas(); |
| 9983 | printRemainingMessages(); |
| 9984 | break; |
| 9985 | case ResultWas::Info: |
| 9986 | printResultType( Colour::None, "info" ); |
| 9987 | printMessage(); |
| 9988 | printRemainingMessages(); |
| 9989 | break; |
| 9990 | case ResultWas::Warning: |
| 9991 | printResultType( Colour::None, "warning" ); |
| 9992 | printMessage(); |
| 9993 | printRemainingMessages(); |
| 9994 | break; |
| 9995 | case ResultWas::ExplicitFailure: |
| 9996 | printResultType( Colour::Error, failedString() ); |
| 9997 | printIssue( "explicitly" ); |
| 9998 | printRemainingMessages( Colour::None ); |
| 9999 | break; |
| 10000 | // These cases are here to prevent compiler warnings |
| 10001 | case ResultWas::Unknown: |
| 10002 | case ResultWas::FailureBit: |
| 10003 | case ResultWas::Exception: |
| 10004 | printResultType( Colour::Error, "** internal error **" ); |
| 10005 | break; |
| 10006 | } |
| 10007 | } |
| 10008 | |
| 10009 | private: |
| 10010 | // Colour::LightGrey |
| 10011 | |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 10012 | static Colour::Code dimColour() { return Colour::FileName; } |
Phil Nash | 5a2df71 | 2014-05-01 19:07:02 +0100 | [diff] [blame] | 10013 | |
| 10014 | #ifdef CATCH_PLATFORM_MAC |
| 10015 | static const char* failedString() { return "FAILED"; } |
| 10016 | static const char* passedString() { return "PASSED"; } |
| 10017 | #else |
| 10018 | static const char* failedString() { return "failed"; } |
| 10019 | static const char* passedString() { return "passed"; } |
| 10020 | #endif |
| 10021 | |
| 10022 | void printSourceInfo() const { |
| 10023 | Colour colourGuard( Colour::FileName ); |
| 10024 | stream << result.getSourceInfo() << ":"; |
| 10025 | } |
| 10026 | |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 10027 | void printResultType( Colour::Code colour, std::string passOrFail ) const { |
Phil Nash | 5a2df71 | 2014-05-01 19:07:02 +0100 | [diff] [blame] | 10028 | if( !passOrFail.empty() ) { |
| 10029 | { |
| 10030 | Colour colourGuard( colour ); |
| 10031 | stream << " " << passOrFail; |
| 10032 | } |
| 10033 | stream << ":"; |
| 10034 | } |
| 10035 | } |
| 10036 | |
| 10037 | void printIssue( std::string issue ) const { |
| 10038 | stream << " " << issue; |
| 10039 | } |
| 10040 | |
| 10041 | void printExpressionWas() { |
| 10042 | if( result.hasExpression() ) { |
| 10043 | stream << ";"; |
| 10044 | { |
| 10045 | Colour colour( dimColour() ); |
| 10046 | stream << " expression was:"; |
| 10047 | } |
| 10048 | printOriginalExpression(); |
| 10049 | } |
| 10050 | } |
| 10051 | |
| 10052 | void printOriginalExpression() const { |
| 10053 | if( result.hasExpression() ) { |
| 10054 | stream << " " << result.getExpression(); |
| 10055 | } |
| 10056 | } |
| 10057 | |
| 10058 | void printReconstructedExpression() const { |
| 10059 | if( result.hasExpandedExpression() ) { |
| 10060 | { |
| 10061 | Colour colour( dimColour() ); |
| 10062 | stream << " for: "; |
| 10063 | } |
| 10064 | stream << result.getExpandedExpression(); |
| 10065 | } |
| 10066 | } |
| 10067 | |
| 10068 | void printMessage() { |
| 10069 | if ( itMessage != messages.end() ) { |
| 10070 | stream << " '" << itMessage->message << "'"; |
| 10071 | ++itMessage; |
| 10072 | } |
| 10073 | } |
| 10074 | |
Phil Nash | 9241e43 | 2014-05-20 18:50:59 +0100 | [diff] [blame] | 10075 | void printRemainingMessages( Colour::Code colour = dimColour() ) { |
Phil Nash | 5a2df71 | 2014-05-01 19:07:02 +0100 | [diff] [blame] | 10076 | if ( itMessage == messages.end() ) |
| 10077 | return; |
| 10078 | |
| 10079 | // using messages.end() directly yields compilation error: |
| 10080 | std::vector<MessageInfo>::const_iterator itEnd = messages.end(); |
| 10081 | const std::size_t N = static_cast<std::size_t>( std::distance( itMessage, itEnd ) ); |
| 10082 | |
| 10083 | { |
| 10084 | Colour colourGuard( colour ); |
| 10085 | stream << " with " << pluralise( N, "message" ) << ":"; |
| 10086 | } |
| 10087 | |
| 10088 | for(; itMessage != itEnd; ) { |
| 10089 | // If this assertion is a warning ignore any INFO messages |
| 10090 | if( printInfoMessages || itMessage->type != ResultWas::Info ) { |
| 10091 | stream << " '" << itMessage->message << "'"; |
| 10092 | if ( ++itMessage != itEnd ) { |
| 10093 | Colour colourGuard( dimColour() ); |
| 10094 | stream << " and"; |
| 10095 | } |
| 10096 | } |
| 10097 | } |
| 10098 | } |
| 10099 | |
| 10100 | private: |
| 10101 | std::ostream& stream; |
| 10102 | AssertionStats const& stats; |
| 10103 | AssertionResult const& result; |
| 10104 | std::vector<MessageInfo> messages; |
| 10105 | std::vector<MessageInfo>::const_iterator itMessage; |
| 10106 | bool printInfoMessages; |
| 10107 | }; |
| 10108 | |
| 10109 | // Colour, message variants: |
| 10110 | // - white: No tests ran. |
| 10111 | // - red: Failed [both/all] N test cases, failed [both/all] M assertions. |
| 10112 | // - white: Passed [both/all] N test cases (no assertions). |
| 10113 | // - red: Failed N tests cases, failed M assertions. |
| 10114 | // - green: Passed [both/all] N tests cases with M assertions. |
| 10115 | |
| 10116 | std::string bothOrAll( std::size_t count ) const { |
| 10117 | return count == 1 ? "" : count == 2 ? "both " : "all " ; |
| 10118 | } |
| 10119 | |
| 10120 | void printTotals( const Totals& totals ) const { |
| 10121 | if( totals.testCases.total() == 0 ) { |
| 10122 | stream << "No tests ran."; |
| 10123 | } |
| 10124 | else if( totals.testCases.failed == totals.testCases.total() ) { |
| 10125 | Colour colour( Colour::ResultError ); |
| 10126 | const std::string qualify_assertions_failed = |
| 10127 | totals.assertions.failed == totals.assertions.total() ? |
| 10128 | bothOrAll( totals.assertions.failed ) : ""; |
| 10129 | stream << |
| 10130 | "Failed " << bothOrAll( totals.testCases.failed ) |
| 10131 | << pluralise( totals.testCases.failed, "test case" ) << ", " |
| 10132 | "failed " << qualify_assertions_failed << |
| 10133 | pluralise( totals.assertions.failed, "assertion" ) << "."; |
| 10134 | } |
| 10135 | else if( totals.assertions.total() == 0 ) { |
| 10136 | stream << |
| 10137 | "Passed " << bothOrAll( totals.testCases.total() ) |
| 10138 | << pluralise( totals.testCases.total(), "test case" ) |
| 10139 | << " (no assertions)."; |
| 10140 | } |
| 10141 | else if( totals.assertions.failed ) { |
| 10142 | Colour colour( Colour::ResultError ); |
| 10143 | stream << |
| 10144 | "Failed " << pluralise( totals.testCases.failed, "test case" ) << ", " |
| 10145 | "failed " << pluralise( totals.assertions.failed, "assertion" ) << "."; |
| 10146 | } |
| 10147 | else { |
| 10148 | Colour colour( Colour::ResultSuccess ); |
| 10149 | stream << |
| 10150 | "Passed " << bothOrAll( totals.testCases.passed ) |
| 10151 | << pluralise( totals.testCases.passed, "test case" ) << |
| 10152 | " with " << pluralise( totals.assertions.passed, "assertion" ) << "."; |
| 10153 | } |
| 10154 | } |
| 10155 | }; |
| 10156 | |
| 10157 | INTERNAL_CATCH_REGISTER_REPORTER( "compact", CompactReporter ) |
| 10158 | |
| 10159 | } // end namespace Catch |
| 10160 | |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 10161 | namespace Catch { |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 10162 | // These are all here to avoid warnings about not having any out of line |
| 10163 | // virtual methods |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 10164 | NonCopyable::~NonCopyable() {} |
| 10165 | IShared::~IShared() {} |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 10166 | IStream::~IStream() CATCH_NOEXCEPT {} |
Phil Nash | ece529a | 2015-11-03 17:37:43 +0000 | [diff] [blame] | 10167 | FileStream::~FileStream() CATCH_NOEXCEPT {} |
| 10168 | CoutStream::~CoutStream() CATCH_NOEXCEPT {} |
| 10169 | DebugOutStream::~DebugOutStream() CATCH_NOEXCEPT {} |
Phil Nash | d7e1790 | 2014-04-18 08:49:35 +0100 | [diff] [blame] | 10170 | StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {} |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 10171 | IContext::~IContext() {} |
| 10172 | IResultCapture::~IResultCapture() {} |
| 10173 | ITestCase::~ITestCase() {} |
| 10174 | ITestCaseRegistry::~ITestCaseRegistry() {} |
| 10175 | IRegistryHub::~IRegistryHub() {} |
| 10176 | IMutableRegistryHub::~IMutableRegistryHub() {} |
| 10177 | IExceptionTranslator::~IExceptionTranslator() {} |
| 10178 | IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {} |
| 10179 | IReporter::~IReporter() {} |
| 10180 | IReporterFactory::~IReporterFactory() {} |
| 10181 | IReporterRegistry::~IReporterRegistry() {} |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 10182 | IStreamingReporter::~IStreamingReporter() {} |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 10183 | AssertionStats::~AssertionStats() {} |
| 10184 | SectionStats::~SectionStats() {} |
| 10185 | TestCaseStats::~TestCaseStats() {} |
| 10186 | TestGroupStats::~TestGroupStats() {} |
| 10187 | TestRunStats::~TestRunStats() {} |
Phil Nash | aa7123b | 2013-08-15 19:01:00 +0100 | [diff] [blame] | 10188 | CumulativeReporterBase::SectionNode::~SectionNode() {} |
| 10189 | CumulativeReporterBase::~CumulativeReporterBase() {} |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 10190 | |
Phil Nash | 2e7d966 | 2013-01-16 09:44:43 +0000 | [diff] [blame] | 10191 | StreamingReporterBase::~StreamingReporterBase() {} |
Phil Nash | ff03cdf | 2012-12-06 08:44:51 +0000 | [diff] [blame] | 10192 | ConsoleReporter::~ConsoleReporter() {} |
Phil Nash | 5a2df71 | 2014-05-01 19:07:02 +0100 | [diff] [blame] | 10193 | CompactReporter::~CompactReporter() {} |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 10194 | IRunner::~IRunner() {} |
| 10195 | IMutableContext::~IMutableContext() {} |
| 10196 | IConfig::~IConfig() {} |
| 10197 | XmlReporter::~XmlReporter() {} |
| 10198 | JunitReporter::~JunitReporter() {} |
| 10199 | TestRegistry::~TestRegistry() {} |
| 10200 | FreeFunctionTestCase::~FreeFunctionTestCase() {} |
| 10201 | IGeneratorInfo::~IGeneratorInfo() {} |
| 10202 | IGeneratorsForTest::~IGeneratorsForTest() {} |
Phil Nash | 8342ae8 | 2015-07-13 15:03:26 +0100 | [diff] [blame] | 10203 | WildcardPattern::~WildcardPattern() {} |
Phil Nash | 65cc14c | 2014-05-16 18:54:48 +0100 | [diff] [blame] | 10204 | TestSpec::Pattern::~Pattern() {} |
| 10205 | TestSpec::NamePattern::~NamePattern() {} |
| 10206 | TestSpec::TagPattern::~TagPattern() {} |
| 10207 | TestSpec::ExcludedPattern::~ExcludedPattern() {} |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 10208 | |
Phil Nash | 9444bbc | 2012-10-12 07:58:17 +0100 | [diff] [blame] | 10209 | Matchers::Impl::StdString::Equals::~Equals() {} |
| 10210 | Matchers::Impl::StdString::Contains::~Contains() {} |
| 10211 | Matchers::Impl::StdString::StartsWith::~StartsWith() {} |
| 10212 | Matchers::Impl::StdString::EndsWith::~EndsWith() {} |
| 10213 | |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 10214 | void Config::dummy() {} |
Phil Nash | 7e34619 | 2015-11-03 08:00:43 +0000 | [diff] [blame] | 10215 | |
| 10216 | namespace TestCaseTracking { |
| 10217 | ITracker::~ITracker() {} |
| 10218 | TrackerBase::~TrackerBase() {} |
| 10219 | SectionTracker::~SectionTracker() {} |
| 10220 | IndexTracker::~IndexTracker() {} |
| 10221 | } |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 10222 | } |
| 10223 | |
Phil Nash | 5bc030d | 2012-08-16 18:48:50 +0100 | [diff] [blame] | 10224 | #ifdef __clang__ |
Phil Nash | a695eb9 | 2012-08-13 07:46:10 +0100 | [diff] [blame] | 10225 | #pragma clang diagnostic pop |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10226 | #endif |
Matt Wozniski | f29c898 | 2012-09-17 01:42:29 -0400 | [diff] [blame] | 10227 | |
Phil Nash | 9abb276 | 2014-03-06 21:53:34 +0000 | [diff] [blame] | 10228 | #endif |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10229 | |
Phil Nash | de49ec4 | 2013-12-04 20:25:14 +0000 | [diff] [blame] | 10230 | #ifdef CATCH_CONFIG_MAIN |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10231 | // #included from: internal/catch_default_main.hpp |
Phil Nash | 3b80af7 | 2012-08-09 07:47:30 +0100 | [diff] [blame] | 10232 | #define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10233 | |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 10234 | #ifndef __OBJC__ |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10235 | |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 10236 | // Standard C/C++ main entry point |
Phil Nash | 981347b | 2015-12-09 18:11:48 +0000 | [diff] [blame] | 10237 | int main (int argc, char * argv[]) { |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 10238 | return Catch::Session().run( argc, argv ); |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 10239 | } |
| 10240 | |
| 10241 | #else // __OBJC__ |
| 10242 | |
| 10243 | // Objective-C entry point |
| 10244 | int main (int argc, char * const argv[]) { |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 10245 | #if !CATCH_ARC_ENABLED |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10246 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 10247 | #endif |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10248 | |
| 10249 | Catch::registerTestMethods(); |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 10250 | int result = Catch::Session().run( argc, (char* const*)argv ); |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10251 | |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 10252 | #if !CATCH_ARC_ENABLED |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10253 | [pool drain]; |
Phil Nash | 53c990a | 2012-03-17 18:20:06 +0000 | [diff] [blame] | 10254 | #endif |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10255 | |
Phil Nash | dd5b9c2 | 2012-02-18 09:58:30 +0000 | [diff] [blame] | 10256 | return result; |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10257 | } |
| 10258 | |
Phil Nash | 176eb81 | 2012-05-11 08:17:16 +0100 | [diff] [blame] | 10259 | #endif // __OBJC__ |
| 10260 | |
Phil Nash | 9abb276 | 2014-03-06 21:53:34 +0000 | [diff] [blame] | 10261 | #endif |
| 10262 | |
| 10263 | #ifdef CLARA_CONFIG_MAIN_NOT_DEFINED |
| 10264 | # undef CLARA_CONFIG_MAIN |
| 10265 | #endif |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10266 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10267 | ////// |
| 10268 | |
Phil Nash | 46bcd4b | 2012-07-20 18:43:48 +0100 | [diff] [blame] | 10269 | // If this config identifier is defined then all CATCH macros are prefixed with CATCH_ |
| 10270 | #ifdef CATCH_CONFIG_PREFIX_ALL |
| 10271 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10272 | #define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE" ) |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 10273 | #define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, "CATCH_REQUIRE_FALSE" ) |
Phil Nash | 46bcd4b | 2012-07-20 18:43:48 +0100 | [diff] [blame] | 10274 | |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 10275 | #define CATCH_REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "", "CATCH_REQUIRE_THROWS" ) |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10276 | #define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THROWS_AS" ) |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 10277 | #define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, matcher, "CATCH_REQUIRE_THROWS_WITH" ) |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10278 | #define CATCH_REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_NOTHROW" ) |
Phil Nash | 46bcd4b | 2012-07-20 18:43:48 +0100 | [diff] [blame] | 10279 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10280 | #define CATCH_CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK" ) |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 10281 | #define CATCH_CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, "CATCH_CHECK_FALSE" ) |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10282 | #define CATCH_CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_IF" ) |
| 10283 | #define CATCH_CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECKED_ELSE" ) |
| 10284 | #define CATCH_CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CATCH_CHECK_NOFAIL" ) |
Phil Nash | 46bcd4b | 2012-07-20 18:43:48 +0100 | [diff] [blame] | 10285 | |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 10286 | #define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS" ) |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10287 | #define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THROWS_AS" ) |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 10288 | #define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, matcher, "CATCH_CHECK_THROWS_WITH" ) |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10289 | #define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_NOTHROW" ) |
Phil Nash | 46bcd4b | 2012-07-20 18:43:48 +0100 | [diff] [blame] | 10290 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10291 | #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CATCH_CHECK_THAT" ) |
| 10292 | #define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "CATCH_REQUIRE_THAT" ) |
Phil Nash | 46bcd4b | 2012-07-20 18:43:48 +0100 | [diff] [blame] | 10293 | |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 10294 | #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" ) |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 10295 | #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "CATCH_WARN", msg ) |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 10296 | #define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" ) |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 10297 | #define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" ) |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 10298 | #define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" ) |
Phil Nash | 46bcd4b | 2012-07-20 18:43:48 +0100 | [diff] [blame] | 10299 | |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 10300 | #ifdef CATCH_CONFIG_VARIADIC_MACROS |
| 10301 | #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 10302 | #define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 10303 | #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) |
Phil Nash | c724356 | 2016-01-22 07:52:07 +0000 | [diff] [blame] | 10304 | #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 10305 | #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 10306 | #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", __VA_ARGS__ ) |
Phil Nash | 66d641a | 2013-12-14 23:16:44 +0000 | [diff] [blame] | 10307 | #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", __VA_ARGS__ ) |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 10308 | #else |
| 10309 | #define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description ) |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 10310 | #define CATCH_TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description ) |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 10311 | #define CATCH_METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description ) |
Phil Nash | 7e15d9b | 2015-11-20 16:59:14 +0000 | [diff] [blame] | 10312 | #define CATCH_REGISTER_TEST_CASE( function, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( function, name, description ) |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 10313 | #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 10314 | #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", msg ) |
Phil Nash | 66d641a | 2013-12-14 23:16:44 +0000 | [diff] [blame] | 10315 | #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", msg ) |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 10316 | #endif |
| 10317 | #define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" ) |
Phil Nash | 46bcd4b | 2012-07-20 18:43:48 +0100 | [diff] [blame] | 10318 | |
| 10319 | #define CATCH_REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 10320 | #define CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) |
Phil Nash | 46bcd4b | 2012-07-20 18:43:48 +0100 | [diff] [blame] | 10321 | |
| 10322 | #define CATCH_GENERATE( expr) INTERNAL_CATCH_GENERATE( expr ) |
| 10323 | |
Phil Nash | 37186a1 | 2013-03-13 12:19:30 +0000 | [diff] [blame] | 10324 | // "BDD-style" convenience wrappers |
Phil Nash | bd7f797 | 2013-03-21 09:00:24 +0000 | [diff] [blame] | 10325 | #ifdef CATCH_CONFIG_VARIADIC_MACROS |
| 10326 | #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ ) |
Phil Nash | 544bf33 | 2014-08-20 08:09:32 +0100 | [diff] [blame] | 10327 | #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) |
Phil Nash | bd7f797 | 2013-03-21 09:00:24 +0000 | [diff] [blame] | 10328 | #else |
Phil Nash | 37186a1 | 2013-03-13 12:19:30 +0000 | [diff] [blame] | 10329 | #define CATCH_SCENARIO( name, tags ) CATCH_TEST_CASE( "Scenario: " name, tags ) |
Phil Nash | 544bf33 | 2014-08-20 08:09:32 +0100 | [diff] [blame] | 10330 | #define CATCH_SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags ) |
Phil Nash | bd7f797 | 2013-03-21 09:00:24 +0000 | [diff] [blame] | 10331 | #endif |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 10332 | #define CATCH_GIVEN( desc ) CATCH_SECTION( std::string( "Given: ") + desc, "" ) |
| 10333 | #define CATCH_WHEN( desc ) CATCH_SECTION( std::string( " When: ") + desc, "" ) |
| 10334 | #define CATCH_AND_WHEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" ) |
| 10335 | #define CATCH_THEN( desc ) CATCH_SECTION( std::string( " Then: ") + desc, "" ) |
| 10336 | #define CATCH_AND_THEN( desc ) CATCH_SECTION( std::string( " And: ") + desc, "" ) |
Phil Nash | 37186a1 | 2013-03-13 12:19:30 +0000 | [diff] [blame] | 10337 | |
Phil Nash | 46bcd4b | 2012-07-20 18:43:48 +0100 | [diff] [blame] | 10338 | // If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required |
| 10339 | #else |
| 10340 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10341 | #define REQUIRE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal, "REQUIRE" ) |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 10342 | #define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, "REQUIRE_FALSE" ) |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10343 | |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 10344 | #define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, "", "REQUIRE_THROWS" ) |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10345 | #define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::Normal, "REQUIRE_THROWS_AS" ) |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 10346 | #define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::Normal, matcher, "REQUIRE_THROWS_WITH" ) |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10347 | #define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::Normal, "REQUIRE_NOTHROW" ) |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10348 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10349 | #define CHECK( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK" ) |
Phil Nash | ab03668 | 2014-06-02 07:48:03 +0100 | [diff] [blame] | 10350 | #define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, "CHECK_FALSE" ) |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10351 | #define CHECKED_IF( expr ) INTERNAL_CATCH_IF( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECKED_IF" ) |
| 10352 | #define CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECKED_ELSE" ) |
| 10353 | #define CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( expr, Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, "CHECK_NOFAIL" ) |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10354 | |
Phil Nash | 93a842e | 2015-07-13 06:36:07 +0100 | [diff] [blame] | 10355 | #define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, "", "CHECK_THROWS" ) |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10356 | #define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( expr, exceptionType, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THROWS_AS" ) |
Phil Nash | 5bbdc8f | 2015-07-15 23:03:11 +0100 | [diff] [blame] | 10357 | #define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( expr, Catch::ResultDisposition::ContinueOnFailure, matcher, "CHECK_THROWS_WITH" ) |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10358 | #define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( expr, Catch::ResultDisposition::ContinueOnFailure, "CHECK_NOTHROW" ) |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10359 | |
Phil Nash | 90a3594 | 2012-11-13 22:04:29 +0000 | [diff] [blame] | 10360 | #define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::ContinueOnFailure, "CHECK_THAT" ) |
| 10361 | #define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( arg, matcher, Catch::ResultDisposition::Normal, "REQUIRE_THAT" ) |
Phil Nash | 78d95a0 | 2012-03-04 21:22:36 +0000 | [diff] [blame] | 10362 | |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 10363 | #define INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" ) |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 10364 | #define WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "WARN", msg ) |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 10365 | #define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" ) |
Phil Nash | a277381 | 2013-02-02 20:37:58 +0000 | [diff] [blame] | 10366 | #define CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" ) |
Phil Nash | b5fd5a6 | 2013-06-28 17:09:57 +0100 | [diff] [blame] | 10367 | #define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" ) |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10368 | |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 10369 | #ifdef CATCH_CONFIG_VARIADIC_MACROS |
| 10370 | #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 10371 | #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 10372 | #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) |
Phil Nash | c724356 | 2016-01-22 07:52:07 +0000 | [diff] [blame] | 10373 | #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 10374 | #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 10375 | #define FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", __VA_ARGS__ ) |
Phil Nash | 66d641a | 2013-12-14 23:16:44 +0000 | [diff] [blame] | 10376 | #define SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", __VA_ARGS__ ) |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 10377 | #else |
| 10378 | #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description ) |
Phil Nash | 786959d | 2013-06-07 19:07:50 +0100 | [diff] [blame] | 10379 | #define TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description ) |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 10380 | #define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description ) |
Phil Nash | 7424b23 | 2015-12-28 15:07:32 +0000 | [diff] [blame] | 10381 | #define REGISTER_TEST_CASE( method, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( method, name, description ) |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 10382 | #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) |
Phil Nash | 859760a | 2013-12-14 14:34:05 +0000 | [diff] [blame] | 10383 | #define FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", msg ) |
Phil Nash | 66d641a | 2013-12-14 23:16:44 +0000 | [diff] [blame] | 10384 | #define SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", msg ) |
Phil Nash | 9390675 | 2013-03-16 20:21:51 +0000 | [diff] [blame] | 10385 | #endif |
| 10386 | #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" ) |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10387 | |
| 10388 | #define REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) |
Phil Nash | a1fbfea | 2012-12-01 23:57:18 +0000 | [diff] [blame] | 10389 | #define REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10390 | |
| 10391 | #define GENERATE( expr) INTERNAL_CATCH_GENERATE( expr ) |
| 10392 | |
Phil Nash | 46bcd4b | 2012-07-20 18:43:48 +0100 | [diff] [blame] | 10393 | #endif |
| 10394 | |
| 10395 | #define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10396 | |
Phil Nash | 37186a1 | 2013-03-13 12:19:30 +0000 | [diff] [blame] | 10397 | // "BDD-style" convenience wrappers |
Phil Nash | bd7f797 | 2013-03-21 09:00:24 +0000 | [diff] [blame] | 10398 | #ifdef CATCH_CONFIG_VARIADIC_MACROS |
| 10399 | #define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ ) |
Phil Nash | 544bf33 | 2014-08-20 08:09:32 +0100 | [diff] [blame] | 10400 | #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) |
Phil Nash | bd7f797 | 2013-03-21 09:00:24 +0000 | [diff] [blame] | 10401 | #else |
Phil Nash | 37186a1 | 2013-03-13 12:19:30 +0000 | [diff] [blame] | 10402 | #define SCENARIO( name, tags ) TEST_CASE( "Scenario: " name, tags ) |
Phil Nash | 544bf33 | 2014-08-20 08:09:32 +0100 | [diff] [blame] | 10403 | #define SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags ) |
Phil Nash | bd7f797 | 2013-03-21 09:00:24 +0000 | [diff] [blame] | 10404 | #endif |
Phil Nash | 2f6371f | 2015-07-23 23:06:26 +0100 | [diff] [blame] | 10405 | #define GIVEN( desc ) SECTION( std::string(" Given: ") + desc, "" ) |
| 10406 | #define WHEN( desc ) SECTION( std::string(" When: ") + desc, "" ) |
| 10407 | #define AND_WHEN( desc ) SECTION( std::string("And when: ") + desc, "" ) |
| 10408 | #define THEN( desc ) SECTION( std::string(" Then: ") + desc, "" ) |
| 10409 | #define AND_THEN( desc ) SECTION( std::string(" And: ") + desc, "" ) |
Phil Nash | 37186a1 | 2013-03-13 12:19:30 +0000 | [diff] [blame] | 10410 | |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10411 | using Catch::Detail::Approx; |
| 10412 | |
Phil Nash | aec1e5e | 2012-05-09 19:37:51 +0100 | [diff] [blame] | 10413 | #endif // TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED |
Phil Nash | 89d1e6c | 2011-05-24 08:23:02 +0100 | [diff] [blame] | 10414 | |