提交 e32fdc40 authored 作者: Iñaki Baz Castillo's avatar Iñaki Baz Castillo

Update dep Catch to 1.8.2

上级 ee6f4e8c
...@@ -135,6 +135,7 @@ set(INTERNAL_HEADERS ...@@ -135,6 +135,7 @@ set(INTERNAL_HEADERS
${HEADER_DIR}/internal/catch_debugger.h ${HEADER_DIR}/internal/catch_debugger.h
${HEADER_DIR}/internal/catch_debugger.hpp ${HEADER_DIR}/internal/catch_debugger.hpp
${HEADER_DIR}/internal/catch_default_main.hpp ${HEADER_DIR}/internal/catch_default_main.hpp
${HEADER_DIR}/internal/catch_errno_guard.hpp
${HEADER_DIR}/internal/catch_evaluate.hpp ${HEADER_DIR}/internal/catch_evaluate.hpp
${HEADER_DIR}/internal/catch_exception_translator_registry.hpp ${HEADER_DIR}/internal/catch_exception_translator_registry.hpp
${HEADER_DIR}/internal/catch_expression_lhs.hpp ${HEADER_DIR}/internal/catch_expression_lhs.hpp
...@@ -253,7 +254,7 @@ if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" ) ...@@ -253,7 +254,7 @@ if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
target_compile_options( Benchmark PRIVATE -Wall -Wextra ) target_compile_options( Benchmark PRIVATE -Wall -Wextra )
endif() endif()
if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" ) if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
target_compile_options( SelfTest PRIVATE /W4 ) target_compile_options( SelfTest PRIVATE /W4 /w44265 /WX )
target_compile_options( Benchmark PRIVATE /W4 ) target_compile_options( Benchmark PRIVATE /W4 )
endif() endif()
......
![catch logo](catch-logo-small.png) ![catch logo](catch-logo-small.png)
*v1.8.1* [![Github Releases](https://img.shields.io/github/release/philsquared/catch.svg)](https://github.com/philsquared/catch/releases)
[![Build Status](https://travis-ci.org/philsquared/Catch.svg?branch=master)](https://travis-ci.org/philsquared/Catch)
[![Build status](https://ci.appveyor.com/api/projects/status/hrtk60hv6tw6fght/branch/master?svg=true)](https://ci.appveyor.com/project/philsquared/catch/branch/master)
Build status (on Travis CI) [![Build Status](https://travis-ci.org/philsquared/Catch.svg?branch=master)](https://travis-ci.org/philsquared/Catch) <a href="https://github.com/philsquared/Catch/releases/download/v1.8.2/catch.hpp">The latest, single header, version can be downloaded directly using this link</a>
<a href="https://github.com/philsquared/Catch/releases/download/v1.8.1/catch.hpp">The latest, single header, version can be downloaded directly using this link</a>
## What's the Catch? ## What's the Catch?
......
...@@ -7,11 +7,12 @@ Before looking at this material be sure to read the [tutorial](tutorial.md) ...@@ -7,11 +7,12 @@ Before looking at this material be sure to read the [tutorial](tutorial.md)
* [Logging macros](logging.md) * [Logging macros](logging.md)
* [Test cases and sections](test-cases-and-sections.md) * [Test cases and sections](test-cases-and-sections.md)
* [Test fixtures](test-fixtures.md) * [Test fixtures](test-fixtures.md)
* [Command line](command-line.md)
* [Build systems](build-systems.md)
* [Supplying your own main()](own-main.md) * [Supplying your own main()](own-main.md)
* [Event Listeners](event-listeners.md)
* [Configuration](configuration.md) * [Configuration](configuration.md)
* [String Conversions](tostring.md) * [String Conversions](tostring.md)
* [Command line](command-line.md)
* [Build systems](build-systems.md)
* [Why are my tests slow to compile?](slow-compiles.md) * [Why are my tests slow to compile?](slow-compiles.md)
* [Known limitations](limitations.md) * [Known limitations](limitations.md)
......
# Event Listeners
A `Listener` is a class you can register with Catch that will then be passed events,
such as a test case starting or ending, as they happen during a test run.
`Listeners` are actually types of `Reporters`, with a few small differences:
1. Once registered in code they are automatically used - you don't need to specify them on the command line
2. They are called in addition to (just before) any reporters, and you can register multiple listeners.
3. They derive from `Catch::TestEventListenerBase`, which has default stubs for all the events,
so you are not forced to implement events you're not interested in.
4. You register a listener with `CATCH_REGISTER_LISTENER`
## Implementing a Listener
In your main source file (i.e. the one that has the `#define` for `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`),
simply derive a class from `Catch::TestEventListenerBase` and implement the methods you are interested in.
Then register it using `INTERNAL_CATCH_REGISTER_LISTENER`.
For example:
```c++
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
struct MyListener : Catch::TestEventListenerBase {
using TestEventListenerBase::TestEventListenerBase; // inherit constructor
virtual void testCaseStarting( Catch::TestCaseInfo const& testInfo ) override {
// Perform some setup before a test case is run
}
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) override {
// Tear-down after a test case is run
}
};
CATCH_REGISTER_LISTENER( MyListener )
```
_Note that you should not use any assertion macros within a Listener!_
## Events that can be hooked
The following are the methods that can be overriden in the Listener:
```c++
// The whole test run, starting and ending
virtual void testRunStarting( TestRunInfo const& testRunInfo );
virtual void testRunEnded( TestRunStats const& testRunStats );
// Test cases starting and ending
virtual void testCaseStarting( TestCaseInfo const& testInfo );
virtual void testCaseEnded( TestCaseStats const& testCaseStats );
// Sections starting and ending
virtual void sectionStarting( SectionInfo const& sectionInfo );
virtual void sectionEnded( SectionStats const& sectionStats );
// Assertions before/ after
virtual void assertionStarting( AssertionInfo const& assertionInfo );
virtual bool assertionEnded( AssertionStats const& assertionStats );
// A test is being skipped (because it is "hidden")
virtual void skipTest( TestCaseInfo const& testInfo );
```
More information about the events (e.g. name of the test case) is contained in the structs passed as arguments -
just look in the source code to see what fields are available.
---
[Home](Readme.md)
\ No newline at end of file
...@@ -26,6 +26,10 @@ The message is always reported but does not fail the test. ...@@ -26,6 +26,10 @@ The message is always reported but does not fail the test.
The message is reported and the test case fails. The message is reported and the test case fails.
**FAIL_CHECK(** _message expression_ **)**
AS `FAIL`, but does not abort the test
## Quickly capture a variable value ## Quickly capture a variable value
**CAPTURE(** _expression_ **)** **CAPTURE(** _expression_ **)**
......
...@@ -48,6 +48,9 @@ A thread safe header only mocking framework for C++14 ...@@ -48,6 +48,9 @@ A thread safe header only mocking framework for C++14
## Applications & Tools ## Applications & Tools
### [ArangoDB](https://github.com/arangodb/arangodb)
ArangoDB is a native multi-model database with flexible data models for documents, graphs, and key-values.
### [MAME](https://github.com/mamedev/mame) ### [MAME](https://github.com/mamedev/mame)
MAME originally stood for Multiple Arcade Machine Emulator MAME originally stood for Multiple Arcade Machine Emulator
......
# 1.8.2
### Improvements and minor changes
* TAP reporter now behaves as if `-s` was always set
* This should be more consistent with the protocol desired behaviour.
* Compact reporter now obeys `-d yes` argument (#780)
* The format is "XXX.123 s: <section-name>" (3 decimal places are always present).
* Before it did not report the durations at all.
* XML reporter now behaves the same way as Console reporter in regards to `INFO`
* This means it reports `INFO` messages on success, if output on success (`-s`) is enabled.
* Previously it only reported `INFO` messages on failure.
* `CAPTURE(expr)` now stringifies `expr` in the same way assertion macros do (#639)
* Listeners are now finally [documented](event-listeners.md).
* Listeners provide a way to hook into events generated by running your tests, including start and end of run, every test case, every section and every assertion.
### Fixes:
* Catch no longer attempts to reconstruct expression that led to a fatal error (#810)
* This fixes possible signal/SEH loop when processing expressions, where the signal was triggered by expression decomposition.
* Fixed (C4265) missing virtual destructor warning in Matchers (#844)
* `std::string`s are now taken by `const&` everywhere (#842).
* Previously some places were taking them by-value.
* Catch should no longer change errno (#835).
* This was caused by libstdc++ bug that we now work around.
* Catch now provides `FAIL_CHECK( ... )` macro (#765).
* Same as `FAIL( ... )`, but does not abort the test.
* Functions like `fabs`, `tolower`, `memset`, `isalnum` are now used with `std::` qualification (#543).
* Clara no longer assumes first argument (binary name) is always present (#729)
* If it is missing, empty string is used as default.
* Clara no longer reads 1 character past argument string (#830)
### Other notes:
* We have added VS 2013 and 2015 to our CI
* Catch Classic (1.x.x) now contains its own, forked, version of Clara (the argument parser).
# 1.8.1
### Fixes
Cygwin issue with `gettimeofday` - `#define` was not early enough
# 1.8.0 # 1.8.0
### New features/ minor changes ### New features/ minor changes
* Matchers have new, simpler (and documented) interface. * Matchers have new, simpler (and documented) interface.
* Catch provides string and vector matchers. * Catch provides string and vector matchers.
* For details see [Matchers documentation](matchers.md). * For details see [Matchers documentation](docs/matchers.md).
* Changed console reporter test duration reporting format (#322) * Changed console reporter test duration reporting format (#322)
* Old format: `Some simple comparisons between doubles completed in 0.000123s` * Old format: `Some simple comparisons between doubles completed in 0.000123s`
* New format: `xxx.123s: Some simple comparisons between doubles` _(There will always be exactly 3 decimal places)_ * New format: `xxx.123s: Some simple comparisons between doubles` _(There will always be exactly 3 decimal places)_
* Added opt-in leak detection under MSVC + Windows (#439) * Added opt-in leak detection under MSVC + Windows (#439)
* Enable it by compiling Catch's main with `CATCH_CONFIG_WINDOWS_CRTDBG` * Enable it by compiling Catch's main with `CATCH_CONFIG_WINDOWS_CRTDBG`
* Introduced new compile-time flag, `CATCH_CONFIG_FAST_COMPILE`, trading features for compilation speed. * Introduced new compile-time flag, `CATCH_CONFIG_FAST_COMPILE`, trading features for compilation speed.
* Moves debug breaks out of tests and into implementation, speeding up compilation time * Moves debug breaks out of tests and into implementation, speeding up test compilation time (~10% on linux).
* _More changes are coming_ * _More changes are coming_
* Added [TAP (Test Anything Protocol)](https://testanything.org/) and [Automake](https://www.gnu.org/software/automake/manual/html_node/Log-files-generation-and-test-results-recording.html#Log-files-generation-and-test-results-recording) reporters. * Added [TAP (Test Anything Protocol)](https://testanything.org/) and [Automake](https://www.gnu.org/software/automake/manual/html_node/Log-files-generation-and-test-results-recording.html#Log-files-generation-and-test-results-recording) reporters.
* These are not present in the default single-include header and need to be downloaded from GitHub separately. * These are not present in the default single-include header and need to be downloaded from GitHub separately.
* For details see [documentation about integrating with build systems](build-systems.md). * For details see [documentation about integrating with build systems](build-systems.md).
* XML reporter now reports filename as part of the `Section` and `TestCase` tags. * XML reporter now reports filename as part of the `Section` and `TestCase` tags.
* `Approx` now supports an optional margin of absolute error * `Approx` now supports an optional margin of absolute error
* It has also received [new documentation](). * It has also received [new documentation](docs/assertions.md).
### Fixes ### Fixes
* Silenced C4312 ("conversion from int to 'ClassName *") warnings in the evaluate layer. * Silenced C4312 ("conversion from int to 'ClassName *") warnings in the evaluate layer.
......
...@@ -38,10 +38,10 @@ All tag names beginning with non-alphanumeric characters are reserved by Catch. ...@@ -38,10 +38,10 @@ All tag names beginning with non-alphanumeric characters are reserved by Catch.
* `[!throws]` - lets Catch know that this test is likely to throw an exception even if successful. This causes the test to be excluded when running with `-e` or `--nothrow`. * `[!throws]` - lets Catch know that this test is likely to throw an exception even if successful. This causes the test to be excluded when running with `-e` or `--nothrow`.
* `[!shouldfail]` - reverse the failing logic of the test: if the test is successful if it fails, and vice-versa.
* `[!mayfail]` - doesn't fail the test if any given assertion fails (but still reports it). This can be useful to flag a work-in-progress, or a known issue that you don't want to immediately fix but still want to track in the your tests. * `[!mayfail]` - doesn't fail the test if any given assertion fails (but still reports it). This can be useful to flag a work-in-progress, or a known issue that you don't want to immediately fix but still want to track in the your tests.
* `[!shouldfail]` - like `[!mayfail]` but *fails* the test if it *passes*. This can be useful if you want to be notified of accidental, or third-party, fixes.
* `[!nonportable]` - Indicates that behaviour may vary between platforms or compilers. * `[!nonportable]` - Indicates that behaviour may vary between platforms or compilers.
* `[#<filename>]` - running with `-#` or `--filenames-as-tags` causes Catch to add the filename, prefixed with `#` (and with any extension stripped) as a tag. e.g. tests in testfile.cpp would all be tagged `[#testfile]`. * `[#<filename>]` - running with `-#` or `--filenames-as-tags` causes Catch to add the filename, prefixed with `#` (and with any extension stripped) as a tag. e.g. tests in testfile.cpp would all be tagged `[#testfile]`.
......
...@@ -116,8 +116,8 @@ LeakDetector leakDetector; ...@@ -116,8 +116,8 @@ LeakDetector leakDetector;
#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" ) #define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" )
#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "CATCH_WARN", msg ) #define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "CATCH_WARN", msg )
#define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" ) #define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "CATCH_INFO" )
#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" ) #define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << Catch::toString(msg), "CATCH_CAPTURE" )
#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CATCH_CAPTURE" ) #define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << Catch::toString(msg), "CATCH_CAPTURE" )
#ifdef CATCH_CONFIG_VARIADIC_MACROS #ifdef CATCH_CONFIG_VARIADIC_MACROS
#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) #define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
...@@ -126,6 +126,7 @@ LeakDetector leakDetector; ...@@ -126,6 +126,7 @@ LeakDetector leakDetector;
#define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
#define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
#define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", __VA_ARGS__ ) #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", __VA_ARGS__ )
#define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, "CATCH_FAIL_CHECK", __VA_ARGS__ )
#define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", __VA_ARGS__ ) #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", __VA_ARGS__ )
#else #else
#define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description ) #define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
...@@ -134,6 +135,7 @@ LeakDetector leakDetector; ...@@ -134,6 +135,7 @@ LeakDetector leakDetector;
#define CATCH_REGISTER_TEST_CASE( function, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( function, name, description ) #define CATCH_REGISTER_TEST_CASE( function, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( function, name, description )
#define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) #define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
#define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", msg ) #define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "CATCH_FAIL", msg )
#define CATCH_FAIL_CHECK( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, "CATCH_FAIL_CHECK", msg )
#define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", msg ) #define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "CATCH_SUCCEED", msg )
#endif #endif
#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" ) #define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
...@@ -185,24 +187,26 @@ LeakDetector leakDetector; ...@@ -185,24 +187,26 @@ LeakDetector leakDetector;
#define INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" ) #define INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" )
#define WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "WARN", msg ) #define WARN( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, "WARN", msg )
#define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" ) #define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( msg, "INFO" )
#define CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" ) #define CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << Catch::toString(msg), "CAPTURE" )
#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << msg, "CAPTURE" ) #define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( #msg " := " << Catch::toString(msg), "CAPTURE" )
#ifdef CATCH_CONFIG_VARIADIC_MACROS #ifdef CATCH_CONFIG_VARIADIC_MACROS
#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ ) #define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ ) #define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
#define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
#define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
#define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
#define FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", __VA_ARGS__ ) #define FAIL( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", __VA_ARGS__ )
#define SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", __VA_ARGS__ ) #define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, "FAIL_CHECK", __VA_ARGS__ )
#define SUCCEED( ... ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", __VA_ARGS__ )
#else #else
#define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description ) #define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
#define TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description ) #define TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
#define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description ) #define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
#define REGISTER_TEST_CASE( method, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( method, name, description ) #define REGISTER_TEST_CASE( method, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( method, name, description )
#define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description ) #define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
#define FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", msg ) #define FAIL( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, "FAIL", msg )
#define FAIL_CHECK( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, "FAIL_CHECK", msg )
#define SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", msg ) #define SUCCEED( msg ) INTERNAL_CATCH_MSG( Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, "SUCCEED", msg )
#endif #endif
#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" ) #define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include <vector> #include <vector>
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
#include <cctype>
// Use optional outer namespace // Use optional outer namespace
#ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE #ifdef STITCH_TBC_TEXT_FORMAT_OUTER_NAMESPACE
...@@ -397,7 +398,7 @@ namespace Clara { ...@@ -397,7 +398,7 @@ namespace Clara {
_dest = _source; _dest = _source;
} }
char toLowerCh(char c) { char toLowerCh(char c) {
return static_cast<char>( ::tolower( c ) ); return static_cast<char>( std::tolower( c ) );
} }
inline void convertInto( std::string const& _source, bool& _dest ) { inline void convertInto( std::string const& _source, bool& _dest ) {
std::string sourceLC = _source; std::string sourceLC = _source;
...@@ -553,12 +554,13 @@ namespace Clara { ...@@ -553,12 +554,13 @@ namespace Clara {
} }
void parseIntoTokens( std::string const& arg, std::vector<Token>& tokens ) { void parseIntoTokens( std::string const& arg, std::vector<Token>& tokens ) {
for( std::size_t i = 0; i <= arg.size(); ++i ) { for( std::size_t i = 0; i < arg.size(); ++i ) {
char c = arg[i]; char c = arg[i];
if( c == '"' ) if( c == '"' )
inQuotes = !inQuotes; inQuotes = !inQuotes;
mode = handleMode( i, c, arg, tokens ); mode = handleMode( i, c, arg, tokens );
} }
mode = handleMode( arg.size(), '\0', arg, tokens );
} }
Mode handleMode( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) { Mode handleMode( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
switch( mode ) { switch( mode ) {
...@@ -591,6 +593,7 @@ namespace Clara { ...@@ -591,6 +593,7 @@ namespace Clara {
default: from = i; return ShortOpt; default: from = i; return ShortOpt;
} }
} }
Mode handleOpt( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) { Mode handleOpt( std::size_t i, char c, std::string const& arg, std::vector<Token>& tokens ) {
if( std::string( ":=\0", 3 ).find( c ) == std::string::npos ) if( std::string( ":=\0", 3 ).find( c ) == std::string::npos )
return mode; return mode;
...@@ -924,7 +927,7 @@ namespace Clara { ...@@ -924,7 +927,7 @@ namespace Clara {
} }
std::vector<Parser::Token> parseInto( std::vector<std::string> const& args, ConfigT& config ) const { std::vector<Parser::Token> parseInto( std::vector<std::string> const& args, ConfigT& config ) const {
std::string processName = args[0]; std::string processName = args.empty() ? std::string() : args[0];
std::size_t lastSlash = processName.find_last_of( "/\\" ); std::size_t lastSlash = processName.find_last_of( "/\\" );
if( lastSlash != std::string::npos ) if( lastSlash != std::string::npos )
processName = processName.substr( lastSlash+1 ); processName = processName.substr( lastSlash+1 );
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED #define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
#include "catch_console_colour.hpp" #include "catch_console_colour.hpp"
#include "catch_errno_guard.hpp"
namespace Catch { namespace Catch {
namespace { namespace {
...@@ -148,6 +149,7 @@ namespace { ...@@ -148,6 +149,7 @@ namespace {
}; };
IColourImpl* platformColourInstance() { IColourImpl* platformColourInstance() {
ErrnoGuard guard;
Ptr<IConfig const> config = getCurrentContext().getConfig(); Ptr<IConfig const> config = getCurrentContext().getConfig();
UseColour::YesOrNo colourMode = config UseColour::YesOrNo colourMode = config
? config->useColour() ? config->useColour()
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED #define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED
#include "catch_debugger.h" #include "catch_debugger.h"
#include "catch_errno_guard.hpp"
#ifdef CATCH_PLATFORM_MAC #ifdef CATCH_PLATFORM_MAC
...@@ -72,6 +73,9 @@ ...@@ -72,6 +73,9 @@
// be strace, for example) in /proc/$PID/status, so just get it from // be strace, for example) in /proc/$PID/status, so just get it from
// there instead. // there instead.
bool isDebuggerActive(){ bool isDebuggerActive(){
// Libstdc++ has a bug, where std::ifstream sets errno to 0
// This way our users can properly assert over errno values
ErrnoGuard guard;
std::ifstream in("/proc/self/status"); std::ifstream in("/proc/self/status");
for( std::string line; std::getline(in, line); ) { for( std::string line; std::getline(in, line); ) {
static const int PREFIX_LEN = 11; static const int PREFIX_LEN = 11;
......
/*
* Created by Martin on 06/03/2017.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef TWOBLUECUBES_CATCH_ERRNO_GUARD_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_ERRNO_GUARD_HPP_INCLUDED
#include <cerrno>
namespace Catch {
class ErrnoGuard {
public:
ErrnoGuard():m_oldErrno(errno){}
~ErrnoGuard() { errno = m_oldErrno; }
private:
int m_oldErrno;
};
}
#endif // TWOBLUECUBES_CATCH_ERRNO_GUARD_HPP_INCLUDED
...@@ -53,7 +53,6 @@ namespace Catch { ...@@ -53,7 +53,6 @@ namespace Catch {
static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) { static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) {
for (int i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) { for (int i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
if (ExceptionInfo->ExceptionRecord->ExceptionCode == signalDefs[i].id) { if (ExceptionInfo->ExceptionRecord->ExceptionCode == signalDefs[i].id) {
reset();
reportFatal(signalDefs[i].name); reportFatal(signalDefs[i].name);
} }
} }
......
...@@ -91,6 +91,7 @@ namespace Catch { ...@@ -91,6 +91,7 @@ namespace Catch {
TestSpec::NamePattern::~NamePattern() {} TestSpec::NamePattern::~NamePattern() {}
TestSpec::TagPattern::~TagPattern() {} TestSpec::TagPattern::~TagPattern() {}
TestSpec::ExcludedPattern::~ExcludedPattern() {} TestSpec::ExcludedPattern::~ExcludedPattern() {}
Matchers::Impl::MatcherUntypedBase::~MatcherUntypedBase() {}
void Config::dummy() {} void Config::dummy() {}
......
...@@ -27,16 +27,25 @@ namespace Matchers { ...@@ -27,16 +27,25 @@ namespace Matchers {
} }
protected: protected:
virtual ~MatcherUntypedBase();
virtual std::string describe() const = 0; virtual std::string describe() const = 0;
mutable std::string m_cachedToString; mutable std::string m_cachedToString;
private: private:
MatcherUntypedBase& operator = ( MatcherUntypedBase const& ); MatcherUntypedBase& operator = ( MatcherUntypedBase const& );
}; };
template<typename ObjectT>
struct MatcherMethod {
virtual bool match( ObjectT const& arg ) const = 0;
};
template<typename PtrT>
struct MatcherMethod<PtrT*> {
virtual bool match( PtrT* arg ) const = 0;
};
template<typename ObjectT, typename ComparatorT = ObjectT> template<typename ObjectT, typename ComparatorT = ObjectT>
struct MatcherBase : MatcherUntypedBase { struct MatcherBase : MatcherUntypedBase, MatcherMethod<ObjectT> {
virtual bool match( ObjectT const& arg ) const = 0;
MatchAllOf<ComparatorT> operator && ( MatcherBase const& other ) const; MatchAllOf<ComparatorT> operator && ( MatcherBase const& other ) const;
MatchAnyOf<ComparatorT> operator || ( MatcherBase const& other ) const; MatchAnyOf<ComparatorT> operator || ( MatcherBase const& other ) const;
......
...@@ -26,7 +26,7 @@ namespace Matchers { ...@@ -26,7 +26,7 @@ namespace Matchers {
}; };
struct StringMatcherBase : MatcherBase<std::string> { struct StringMatcherBase : MatcherBase<std::string> {
StringMatcherBase( std::string operation, CasedString const& comparator ); StringMatcherBase( std::string const& operation, CasedString const& comparator );
virtual std::string describe() const CATCH_OVERRIDE; virtual std::string describe() const CATCH_OVERRIDE;
CasedString m_comparator; CasedString m_comparator;
......
...@@ -29,7 +29,7 @@ namespace Matchers { ...@@ -29,7 +29,7 @@ namespace Matchers {
} }
StringMatcherBase::StringMatcherBase( std::string operation, CasedString const& comparator ) StringMatcherBase::StringMatcherBase( std::string const& operation, CasedString const& comparator )
: m_comparator( comparator ), : m_comparator( comparator ),
m_operation( operation ) { m_operation( operation ) {
} }
......
...@@ -104,65 +104,68 @@ namespace Catch { ...@@ -104,65 +104,68 @@ namespace Catch {
namespace Matchers { namespace Matchers {
namespace Impl { namespace Impl {
namespace NSStringMatchers { namespace NSStringMatchers {
template<typename MatcherT> struct StringHolder : MatcherBase<NSString*>{
struct StringHolder : MatcherImpl<MatcherT, NSString*>{
StringHolder( NSString* substr ) : m_substr( [substr copy] ){} StringHolder( NSString* substr ) : m_substr( [substr copy] ){}
StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){} StringHolder( StringHolder const& other ) : m_substr( [other.m_substr copy] ){}
StringHolder() { StringHolder() {
arcSafeRelease( m_substr ); arcSafeRelease( m_substr );
} }
virtual bool match( NSString* arg ) const CATCH_OVERRIDE {
return false;
}
NSString* m_substr; NSString* m_substr;
}; };
struct Equals : StringHolder<Equals> { struct Equals : StringHolder {
Equals( NSString* substr ) : StringHolder( substr ){} Equals( NSString* substr ) : StringHolder( substr ){}
virtual bool match( ExpressionType const& str ) const { virtual bool match( NSString* str ) const CATCH_OVERRIDE {
return (str != nil || m_substr == nil ) && return (str != nil || m_substr == nil ) &&
[str isEqualToString:m_substr]; [str isEqualToString:m_substr];
} }
virtual std::string toString() const { virtual std::string describe() const CATCH_OVERRIDE {
return "equals string: " + Catch::toString( m_substr ); return "equals string: " + Catch::toString( m_substr );
} }
}; };
struct Contains : StringHolder<Contains> { struct Contains : StringHolder {
Contains( NSString* substr ) : StringHolder( substr ){} Contains( NSString* substr ) : StringHolder( substr ){}
virtual bool match( ExpressionType const& str ) const { virtual bool match( NSString* str ) const {
return (str != nil || m_substr == nil ) && return (str != nil || m_substr == nil ) &&
[str rangeOfString:m_substr].location != NSNotFound; [str rangeOfString:m_substr].location != NSNotFound;
} }
virtual std::string toString() const { virtual std::string describe() const CATCH_OVERRIDE {
return "contains string: " + Catch::toString( m_substr ); return "contains string: " + Catch::toString( m_substr );
} }
}; };
struct StartsWith : StringHolder<StartsWith> { struct StartsWith : StringHolder {
StartsWith( NSString* substr ) : StringHolder( substr ){} StartsWith( NSString* substr ) : StringHolder( substr ){}
virtual bool match( ExpressionType const& str ) const { virtual bool match( NSString* str ) const {
return (str != nil || m_substr == nil ) && return (str != nil || m_substr == nil ) &&
[str rangeOfString:m_substr].location == 0; [str rangeOfString:m_substr].location == 0;
} }
virtual std::string toString() const { virtual std::string describe() const CATCH_OVERRIDE {
return "starts with: " + Catch::toString( m_substr ); return "starts with: " + Catch::toString( m_substr );
} }
}; };
struct EndsWith : StringHolder<EndsWith> { struct EndsWith : StringHolder {
EndsWith( NSString* substr ) : StringHolder( substr ){} EndsWith( NSString* substr ) : StringHolder( substr ){}
virtual bool match( ExpressionType const& str ) const { virtual bool match( NSString* str ) const {
return (str != nil || m_substr == nil ) && return (str != nil || m_substr == nil ) &&
[str rangeOfString:m_substr].location == [str length] - [m_substr length]; [str rangeOfString:m_substr].location == [str length] - [m_substr length];
} }
virtual std::string toString() const { virtual std::string describe() const CATCH_OVERRIDE {
return "ends with: " + Catch::toString( m_substr ); return "ends with: " + Catch::toString( m_substr );
} }
}; };
......
...@@ -92,7 +92,11 @@ namespace Catch { ...@@ -92,7 +92,11 @@ namespace Catch {
#define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \ #define INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType ) \
namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); }
// Deprecated - use the form without INTERNAL_
#define INTERNAL_CATCH_REGISTER_LISTENER( listenerType ) \ #define INTERNAL_CATCH_REGISTER_LISTENER( listenerType ) \
namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; }
#define CATCH_REGISTER_LISTENER( listenerType ) \
namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; }
#endif // TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED #endif // TWOBLUECUBES_CATCH_REPORTER_REGISTRARS_HPP_INCLUDED
...@@ -224,10 +224,14 @@ namespace Catch { ...@@ -224,10 +224,14 @@ namespace Catch {
} }
virtual void handleFatalErrorCondition( std::string const& message ) { virtual void handleFatalErrorCondition( std::string const& message ) {
ResultBuilder resultBuilder = makeUnexpectedResultBuilder(); // Don't rebuild the result -- the stringification itself can cause more fatal errors
resultBuilder.setResultType( ResultWas::FatalErrorCondition ); // Instead, fake a result data.
resultBuilder << message; AssertionResultData tempResult;
resultBuilder.captureExpression(); tempResult.resultType = ResultWas::FatalErrorCondition;
tempResult.message = message;
AssertionResult result(m_lastAssertionInfo, tempResult);
getResultCapture().assertionEnded(result);
handleUnfinishedSections(); handleUnfinishedSections();
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
namespace Catch { namespace Catch {
struct TagAlias { struct TagAlias {
TagAlias( std::string _tag, SourceLineInfo _lineInfo ) : tag( _tag ), lineInfo( _lineInfo ) {} TagAlias( std::string const& _tag, SourceLineInfo _lineInfo ) : tag( _tag ), lineInfo( _lineInfo ) {}
std::string tag; std::string tag;
SourceLineInfo lineInfo; SourceLineInfo lineInfo;
......
...@@ -37,7 +37,7 @@ namespace Catch { ...@@ -37,7 +37,7 @@ namespace Catch {
return os; return os;
} }
Version libraryVersion( 1, 8, 1, "", 0 ); Version libraryVersion( 1, 8, 2, "", 0 );
} }
......
...@@ -9,12 +9,38 @@ ...@@ -9,12 +9,38 @@
#define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED #define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED
#include "../internal/catch_interfaces_reporter.h" #include "../internal/catch_interfaces_reporter.h"
#include "../internal/catch_errno_guard.hpp"
#include <cstring> #include <cstring>
#include <cfloat>
#include <cstdio>
#include <assert.h> #include <assert.h>
namespace Catch { namespace Catch {
namespace {
// Because formatting using c++ streams is stateful, drop down to C is required
// Alternatively we could use stringstream, but its performance is... not good.
std::string getFormattedDuration( double duration ) {
// Max exponent + 1 is required to represent the whole part
// + 1 for decimal point
// + 3 for the 3 decimal places
// + 1 for null terminator
const size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1;
char buffer[maxDoubleSize];
// Save previous errno, to prevent sprintf from overwriting it
ErrnoGuard guard;
#ifdef _MSC_VER
sprintf_s(buffer, "%.3f", duration);
#else
sprintf(buffer, "%.3f", duration);
#endif
return std::string(buffer);
}
}
struct StreamingReporterBase : SharedImpl<IStreamingReporter> { struct StreamingReporterBase : SharedImpl<IStreamingReporter> {
StreamingReporterBase( ReporterConfig const& _config ) StreamingReporterBase( ReporterConfig const& _config )
......
...@@ -37,8 +37,7 @@ namespace Catch { ...@@ -37,8 +37,7 @@ namespace Catch {
stream << "No test cases matched '" << spec << '\'' << std::endl; stream << "No test cases matched '" << spec << '\'' << std::endl;
} }
virtual void assertionStarting( AssertionInfo const& ) { virtual void assertionStarting( AssertionInfo const& ) {}
}
virtual bool assertionEnded( AssertionStats const& _assertionStats ) { virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
AssertionResult const& result = _assertionStats.assertionResult; AssertionResult const& result = _assertionStats.assertionResult;
...@@ -59,6 +58,12 @@ namespace Catch { ...@@ -59,6 +58,12 @@ namespace Catch {
return true; return true;
} }
virtual void sectionEnded(SectionStats const& _sectionStats) CATCH_OVERRIDE {
if (m_config->showDurations() == ShowDurations::Always) {
stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
}
}
virtual void testRunEnded( TestRunStats const& _testRunStats ) { virtual void testRunEnded( TestRunStats const& _testRunStats ) {
printTotals( _testRunStats.totals ); printTotals( _testRunStats.totals );
stream << '\n' << std::endl; stream << '\n' << std::endl;
...@@ -164,7 +169,7 @@ namespace Catch { ...@@ -164,7 +169,7 @@ namespace Catch {
stream << result.getSourceInfo() << ':'; stream << result.getSourceInfo() << ':';
} }
void printResultType( Colour::Code colour, std::string passOrFail ) const { void printResultType( Colour::Code colour, std::string const& passOrFail ) const {
if( !passOrFail.empty() ) { if( !passOrFail.empty() ) {
{ {
Colour colourGuard( colour ); Colour colourGuard( colour );
...@@ -174,7 +179,7 @@ namespace Catch { ...@@ -174,7 +179,7 @@ namespace Catch {
} }
} }
void printIssue( std::string issue ) const { void printIssue( std::string const& issue ) const {
stream << ' ' << issue; stream << ' ' << issue;
} }
......
...@@ -18,25 +18,6 @@ ...@@ -18,25 +18,6 @@
namespace Catch { namespace Catch {
namespace {
// Because formatting using c++ streams is stateful, drop down to C is required
// Alternatively we could use stringstream, but its performance is... not good.
std::string getFormattedDuration( double duration ) {
// Max exponent + 1 is required to represent the whole part
// + 1 for decimal point
// + 3 for the 3 decimal places
// + 1 for null terminator
const size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1;
char buffer[maxDoubleSize];
#ifdef _MSC_VER
sprintf_s(buffer, "%.3f", duration);
#else
sprintf(buffer, "%.3f", duration);
#endif
return std::string(buffer);
}
}
struct ConsoleReporter : StreamingReporterBase { struct ConsoleReporter : StreamingReporterBase {
ConsoleReporter( ReporterConfig const& _config ) ConsoleReporter( ReporterConfig const& _config )
...@@ -59,18 +40,15 @@ namespace Catch { ...@@ -59,18 +40,15 @@ namespace Catch {
virtual bool assertionEnded( AssertionStats const& _assertionStats ) CATCH_OVERRIDE { virtual bool assertionEnded( AssertionStats const& _assertionStats ) CATCH_OVERRIDE {
AssertionResult const& result = _assertionStats.assertionResult; AssertionResult const& result = _assertionStats.assertionResult;
bool printInfoMessages = true; bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
// Drop out if result was successful and we're not printing those // Drop out if result was successful but we're not printing them.
if( !m_config->includeSuccessfulResults() && result.isOk() ) { if( !includeResults && result.getResultType() != ResultWas::Warning )
if( result.getResultType() != ResultWas::Warning ) return false;
return false;
printInfoMessages = false;
}
lazyPrint(); lazyPrint();
AssertionPrinter printer( stream, _assertionStats, printInfoMessages ); AssertionPrinter printer( stream, _assertionStats, includeResults );
printer.print(); printer.print();
stream << std::endl; stream << std::endl;
return true; return true;
......
...@@ -45,18 +45,9 @@ namespace Catch { ...@@ -45,18 +45,9 @@ namespace Catch {
virtual void assertionStarting( AssertionInfo const& ) {} virtual void assertionStarting( AssertionInfo const& ) {}
virtual bool assertionEnded( AssertionStats const& _assertionStats ) { virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
AssertionResult const& result = _assertionStats.assertionResult; ++counter;
bool printInfoMessages = true; AssertionPrinter printer( stream, _assertionStats, counter );
// Drop out if result was successful and we're not printing those
if ( !m_config->includeSuccessfulResults() && result.isOk() ) {
if ( result.getResultType() != ResultWas::Warning )
return false;
printInfoMessages = false;
}
AssertionPrinter printer( stream, _assertionStats, printInfoMessages, ++counter );
printer.print(); printer.print();
stream << " # " << currentTestCaseInfo->name ; stream << " # " << currentTestCaseInfo->name ;
...@@ -75,13 +66,13 @@ namespace Catch { ...@@ -75,13 +66,13 @@ namespace Catch {
class AssertionPrinter { class AssertionPrinter {
void operator= ( AssertionPrinter const& ); void operator= ( AssertionPrinter const& );
public: public:
AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages, size_t counter = 0 ) AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, size_t counter )
: stream( _stream ) : stream( _stream )
, stats( _stats ) , stats( _stats )
, result( _stats.assertionResult ) , result( _stats.assertionResult )
, messages( _stats.infoMessages ) , messages( _stats.infoMessages )
, itMessage( _stats.infoMessages.begin() ) , itMessage( _stats.infoMessages.begin() )
, printInfoMessages( _printInfoMessages ) , printInfoMessages( true )
, counter(counter) , counter(counter)
{} {}
...@@ -156,28 +147,23 @@ namespace Catch { ...@@ -156,28 +147,23 @@ namespace Catch {
} }
private: private:
static Colour::Code dimColour() { return Colour::FileName; } static Colour::Code dimColour() { return Colour::FileName; }
static const char* failedString() { return "not ok"; } static const char* failedString() { return "not ok"; }
static const char* passedString() { return "ok"; } static const char* passedString() { return "ok"; }
void printSourceInfo() const { void printSourceInfo() const {
Colour colourGuard( Colour::FileName ); Colour colourGuard( dimColour() );
stream << result.getSourceInfo() << ":"; stream << result.getSourceInfo() << ":";
} }
void printResultType( std::string passOrFail ) const { void printResultType( std::string const& passOrFail ) const {
if( !passOrFail.empty() ) { if( !passOrFail.empty() ) {
{ stream << passOrFail << ' ' << counter << " -";
//Colour colourGuard( colour );
stream << passOrFail << " " << counter;
}
stream << " -";
} }
} }
void printIssue( std::string issue ) const { void printIssue( std::string const& issue ) const {
stream << " " << issue; stream << " " << issue;
} }
...@@ -218,8 +204,9 @@ namespace Catch { ...@@ -218,8 +204,9 @@ namespace Catch {
} }
void printRemainingMessages( Colour::Code colour = dimColour() ) { void printRemainingMessages( Colour::Code colour = dimColour() ) {
if ( itMessage == messages.end() ) if (itMessage == messages.end()) {
return; return;
}
// using messages.end() directly yields compilation error: // using messages.end() directly yields compilation error:
std::vector<MessageInfo>::const_iterator itEnd = messages.end(); std::vector<MessageInfo>::const_iterator itEnd = messages.end();
...@@ -252,17 +239,6 @@ namespace Catch { ...@@ -252,17 +239,6 @@ namespace Catch {
size_t counter; size_t counter;
}; };
// Colour, message variants:
// - white: No tests ran.
// - red: Failed [both/all] N test cases, failed [both/all] M assertions.
// - white: Passed [both/all] N test cases (no assertions).
// - red: Failed N tests cases, failed M assertions.
// - green: Passed [both/all] N tests cases with M assertions.
std::string bothOrAll( std::size_t count ) const {
return count == 1 ? "" : count == 2 ? "both " : "all " ;
}
void printTotals( const Totals& totals ) const { void printTotals( const Totals& totals ) const {
if( totals.testCases.total() == 0 ) { if( totals.testCases.total() == 0 ) {
stream << "1..0 # Skipped: No tests ran."; stream << "1..0 # Skipped: No tests ran.";
......
...@@ -92,73 +92,77 @@ namespace Catch { ...@@ -92,73 +92,77 @@ namespace Catch {
virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE { } virtual void assertionStarting( AssertionInfo const& ) CATCH_OVERRIDE { }
virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE { virtual bool assertionEnded( AssertionStats const& assertionStats ) CATCH_OVERRIDE {
const AssertionResult& assertionResult = assertionStats.assertionResult;
// Print any info messages in <Info> tags. AssertionResult const& result = assertionStats.assertionResult;
if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
if( includeResults ) {
// Print any info messages in <Info> tags.
for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end(); for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
it != itEnd; it != itEnd;
++it ) { ++it ) {
if( it->type == ResultWas::Info ) { if( it->type == ResultWas::Info ) {
m_xml.scopedElement( "Info" ) m_xml.scopedElement( "Info" )
.writeText( it->message ); .writeText( it->message );
} else if ( it->type == ResultWas::Warning ) { } else if ( it->type == ResultWas::Warning ) {
m_xml.scopedElement( "Warning" ) m_xml.scopedElement( "Warning" )
.writeText( it->message ); .writeText( it->message );
} }
} }
} }
// Drop out if result was successful but we're not printing them. // Drop out if result was successful but we're not printing them.
if( !m_config->includeSuccessfulResults() && isOk(assertionResult.getResultType()) ) if( !includeResults && result.getResultType() != ResultWas::Warning )
return true; return true;
// Print the expression if there is one. // Print the expression if there is one.
if( assertionResult.hasExpression() ) { if( result.hasExpression() ) {
m_xml.startElement( "Expression" ) m_xml.startElement( "Expression" )
.writeAttribute( "success", assertionResult.succeeded() ) .writeAttribute( "success", result.succeeded() )
.writeAttribute( "type", assertionResult.getTestMacroName() ); .writeAttribute( "type", result.getTestMacroName() );
writeSourceInfo( assertionResult.getSourceInfo() ); writeSourceInfo( result.getSourceInfo() );
m_xml.scopedElement( "Original" ) m_xml.scopedElement( "Original" )
.writeText( assertionResult.getExpression() ); .writeText( result.getExpression() );
m_xml.scopedElement( "Expanded" ) m_xml.scopedElement( "Expanded" )
.writeText( assertionResult.getExpandedExpression() ); .writeText( result.getExpandedExpression() );
} }
// And... Print a result applicable to each result type. // And... Print a result applicable to each result type.
switch( assertionResult.getResultType() ) { switch( result.getResultType() ) {
case ResultWas::ThrewException: case ResultWas::ThrewException:
m_xml.startElement( "Exception" ); m_xml.startElement( "Exception" );
writeSourceInfo( assertionResult.getSourceInfo() ); writeSourceInfo( result.getSourceInfo() );
m_xml.writeText( assertionResult.getMessage() ); m_xml.writeText( result.getMessage() );
m_xml.endElement(); m_xml.endElement();
break; break;
case ResultWas::FatalErrorCondition: case ResultWas::FatalErrorCondition:
m_xml.startElement( "FatalErrorCondition" ); m_xml.startElement( "FatalErrorCondition" );
writeSourceInfo( assertionResult.getSourceInfo() ); writeSourceInfo( result.getSourceInfo() );
m_xml.writeText( assertionResult.getMessage() ); m_xml.writeText( result.getMessage() );
m_xml.endElement(); m_xml.endElement();
break; break;
case ResultWas::Info: case ResultWas::Info:
m_xml.scopedElement( "Info" ) m_xml.scopedElement( "Info" )
.writeText( assertionResult.getMessage() ); .writeText( result.getMessage() );
break; break;
case ResultWas::Warning: case ResultWas::Warning:
// Warning will already have been written // Warning will already have been written
break; break;
case ResultWas::ExplicitFailure: case ResultWas::ExplicitFailure:
m_xml.startElement( "Failure" ); m_xml.startElement( "Failure" );
writeSourceInfo( assertionResult.getSourceInfo() ); writeSourceInfo( result.getSourceInfo() );
m_xml.writeText( assertionResult.getMessage() ); m_xml.writeText( result.getMessage() );
m_xml.endElement(); m_xml.endElement();
break; break;
default: default:
break; break;
} }
if( assertionResult.hasExpression() ) if( result.hasExpression() )
m_xml.endElement(); m_xml.endElement();
return true; return true;
......
...@@ -3,6 +3,17 @@ ...@@ -3,6 +3,17 @@
<exe-name> is a <version> host application. <exe-name> is a <version> host application.
Run with -? for options Run with -? for options
-------------------------------------------------------------------------------
#835 -- errno should not be touched by Catch
-------------------------------------------------------------------------------
MiscTests.cpp:<line number>
...............................................................................
MiscTests.cpp:<line number>: FAILED:
CHECK( f() == 0 )
with expansion:
1 == 0
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
'Not' checks that should fail 'Not' checks that should fail
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
...@@ -276,6 +287,20 @@ MessageTests.cpp:<line number> ...@@ -276,6 +287,20 @@ MessageTests.cpp:<line number>
MessageTests.cpp:<line number>: FAILED: MessageTests.cpp:<line number>: FAILED:
-------------------------------------------------------------------------------
FAIL_CHECK does not abort the test
-------------------------------------------------------------------------------
MessageTests.cpp:<line number>
...............................................................................
MessageTests.cpp:<line number>: FAILED:
explicitly with message:
This is a failure
MessageTests.cpp:<line number>:
warning:
This message appears in the output
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
INFO and WARN do not abort tests INFO and WARN do not abort tests
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
...@@ -890,6 +915,6 @@ with expansion: ...@@ -890,6 +915,6 @@ with expansion:
"first" == "second" "first" == "second"
=============================================================================== ===============================================================================
test cases: 163 | 118 passed | 43 failed | 2 failed as expected test cases: 166 | 119 passed | 44 failed | 3 failed as expected
assertions: 953 | 849 passed | 86 failed | 18 failed as expected assertions: 961 | 855 passed | 87 failed | 19 failed as expected
...@@ -48,6 +48,23 @@ PASSED: ...@@ -48,6 +48,23 @@ PASSED:
with expansion: with expansion:
42 == {?} 42 == {?}
-------------------------------------------------------------------------------
#835 -- errno should not be touched by Catch
-------------------------------------------------------------------------------
MiscTests.cpp:<line number>
...............................................................................
MiscTests.cpp:<line number>: FAILED:
CHECK( f() == 0 )
with expansion:
1 == 0
MiscTests.cpp:<line number>:
PASSED:
REQUIRE( (*__error()) == 1 )
with expansion:
1 == 1
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
'Not' checks that should fail 'Not' checks that should fail
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
...@@ -603,6 +620,32 @@ PASSED: ...@@ -603,6 +620,32 @@ PASSED:
with expansion: with expansion:
true true
-------------------------------------------------------------------------------
Capture and info messages
Capture should stringify like assertions
-------------------------------------------------------------------------------
ToStringGeneralTests.cpp:<line number>
...............................................................................
ToStringGeneralTests.cpp:<line number>:
PASSED:
REQUIRE( true )
with message:
i := 2
-------------------------------------------------------------------------------
Capture and info messages
Info should NOT stringify the way assertions do
-------------------------------------------------------------------------------
ToStringGeneralTests.cpp:<line number>
...............................................................................
ToStringGeneralTests.cpp:<line number>:
PASSED:
REQUIRE( true )
with message:
3
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Character pretty printing Character pretty printing
Specifically escaped Specifically escaped
...@@ -1173,6 +1216,20 @@ MessageTests.cpp:<line number> ...@@ -1173,6 +1216,20 @@ MessageTests.cpp:<line number>
MessageTests.cpp:<line number>: FAILED: MessageTests.cpp:<line number>: FAILED:
-------------------------------------------------------------------------------
FAIL_CHECK does not abort the test
-------------------------------------------------------------------------------
MessageTests.cpp:<line number>
...............................................................................
MessageTests.cpp:<line number>: FAILED:
explicitly with message:
This is a failure
MessageTests.cpp:<line number>:
warning:
This message appears in the output
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Factorials are computed Factorials are computed
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
...@@ -3292,7 +3349,7 @@ with expansion: ...@@ -3292,7 +3349,7 @@ with expansion:
re>" re>"
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Long text is truncted Long text is truncated
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
TestMain.cpp:<line number> TestMain.cpp:<line number>
............................................................................... ...............................................................................
...@@ -5814,6 +5871,23 @@ MessageTests.cpp:<line number>: ...@@ -5814,6 +5871,23 @@ MessageTests.cpp:<line number>:
warning: warning:
toString(p): 0x<hex digits> toString(p): 0x<hex digits>
-------------------------------------------------------------------------------
Process can be configured on command line
empty args don't cause a crash
-------------------------------------------------------------------------------
TestMain.cpp:<line number>
...............................................................................
TestMain.cpp:<line number>:
PASSED:
CHECK_NOTHROW( parser.parseInto( std::vector<std::string>(), config ) )
TestMain.cpp:<line number>:
PASSED:
CHECK( config.processName == "" )
with expansion:
"" == ""
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Process can be configured on command line Process can be configured on command line
default - no arguments default - no arguments
...@@ -5825,6 +5899,12 @@ TestMain.cpp:<line number>: ...@@ -5825,6 +5899,12 @@ TestMain.cpp:<line number>:
PASSED: PASSED:
CHECK_NOTHROW( parseIntoConfig( argv, config ) ) CHECK_NOTHROW( parseIntoConfig( argv, config ) )
TestMain.cpp:<line number>:
PASSED:
CHECK( config.processName == "test" )
with expansion:
"test" == "test"
TestMain.cpp:<line number>: TestMain.cpp:<line number>:
PASSED: PASSED:
CHECK( config.shouldDebugBreak == false ) CHECK( config.shouldDebugBreak == false )
...@@ -9324,6 +9404,6 @@ MiscTests.cpp:<line number>: ...@@ -9324,6 +9404,6 @@ MiscTests.cpp:<line number>:
PASSED: PASSED:
=============================================================================== ===============================================================================
test cases: 163 | 117 passed | 44 failed | 2 failed as expected test cases: 166 | 118 passed | 45 failed | 3 failed as expected
assertions: 955 | 849 passed | 88 failed | 18 failed as expected assertions: 963 | 855 passed | 89 failed | 19 failed as expected
...@@ -48,6 +48,23 @@ PASSED: ...@@ -48,6 +48,23 @@ PASSED:
with expansion: with expansion:
42 == {?} 42 == {?}
-------------------------------------------------------------------------------
#835 -- errno should not be touched by Catch
-------------------------------------------------------------------------------
MiscTests.cpp:<line number>
...............................................................................
MiscTests.cpp:<line number>: FAILED:
CHECK( f() == 0 )
with expansion:
1 == 0
MiscTests.cpp:<line number>:
PASSED:
REQUIRE( (*__error()) == 1 )
with expansion:
1 == 1
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
'Not' checks that should fail 'Not' checks that should fail
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
...@@ -69,6 +86,6 @@ ConditionTests.cpp:<line number>: FAILED: ...@@ -69,6 +86,6 @@ ConditionTests.cpp:<line number>: FAILED:
CHECK_FALSE( true ) CHECK_FALSE( true )
=============================================================================== ===============================================================================
test cases: 4 | 3 passed | 1 failed test cases: 5 | 3 passed | 1 failed | 1 failed as expected
assertions: 10 | 6 passed | 4 failed assertions: 12 | 7 passed | 4 failed | 1 failed as expected
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuitesspanner> <testsuitesspanner>
<testsuite name="<exe-name>" errors="13" failures="76" tests="956" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testsuite name="<exe-name>" errors="13" failures="77" tests="964" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testcase classname="global" name="# A test name that starts with a #" time="{duration}"/> <testcase classname="global" name="# A test name that starts with a #" time="{duration}"/>
<testcase classname="global" name="#542" time="{duration}"/> <testcase classname="global" name="#542" time="{duration}"/>
<testcase classname="global" name="#809" time="{duration}"/> <testcase classname="global" name="#809" time="{duration}"/>
<testcase classname="global" name="#835 -- errno should not be touched by Catch" time="{duration}">
<failure message="1 == 0" type="CHECK">
MiscTests.cpp:<line number>
</failure>
</testcase>
<testcase classname="global" name="'Not' checks that should fail" time="{duration}"> <testcase classname="global" name="'Not' checks that should fail" time="{duration}">
<failure message="false != false" type="CHECK"> <failure message="false != false" type="CHECK">
ConditionTests.cpp:<line number> ConditionTests.cpp:<line number>
...@@ -83,6 +88,8 @@ ExceptionTests.cpp:<line number> ...@@ -83,6 +88,8 @@ ExceptionTests.cpp:<line number>
<testcase classname="Assertions then sections" name="A section" time="{duration}"/> <testcase classname="Assertions then sections" name="A section" time="{duration}"/>
<testcase classname="Assertions then sections" name="A section/Another section" time="{duration}"/> <testcase classname="Assertions then sections" name="A section/Another section" time="{duration}"/>
<testcase classname="Assertions then sections" name="A section/Another other section" time="{duration}"/> <testcase classname="Assertions then sections" name="A section/Another other section" time="{duration}"/>
<testcase classname="Capture and info messages" name="Capture should stringify like assertions" time="{duration}"/>
<testcase classname="Capture and info messages" name="Info should NOT stringify the way assertions do" time="{duration}"/>
<testcase classname="Character pretty printing" name="Specifically escaped" time="{duration}"/> <testcase classname="Character pretty printing" name="Specifically escaped" time="{duration}"/>
<testcase classname="Character pretty printing" name="General chars" time="{duration}"/> <testcase classname="Character pretty printing" name="General chars" time="{duration}"/>
<testcase classname="Character pretty printing" name="Low ASCII" time="{duration}"/> <testcase classname="Character pretty printing" name="Low ASCII" time="{duration}"/>
...@@ -192,6 +199,12 @@ MessageTests.cpp:<line number> ...@@ -192,6 +199,12 @@ MessageTests.cpp:<line number>
</testcase> </testcase>
<testcase classname="global" name="FAIL does not require an argument" time="{duration}"> <testcase classname="global" name="FAIL does not require an argument" time="{duration}">
<failure type="FAIL"> <failure type="FAIL">
MessageTests.cpp:<line number>
</failure>
</testcase>
<testcase classname="global" name="FAIL_CHECK does not abort the test" time="{duration}">
<failure type="FAIL_CHECK">
This is a failure
MessageTests.cpp:<line number> MessageTests.cpp:<line number>
</failure> </failure>
</testcase> </testcase>
...@@ -250,7 +263,7 @@ ConditionTests.cpp:<line number> ...@@ -250,7 +263,7 @@ ConditionTests.cpp:<line number>
<testcase classname="Long strings can be wrapped" name="With wrap-before/ after characters/No wrapping" time="{duration}"/> <testcase classname="Long strings can be wrapped" name="With wrap-before/ after characters/No wrapping" time="{duration}"/>
<testcase classname="Long strings can be wrapped" name="With wrap-before/ after characters/Wrap before" time="{duration}"/> <testcase classname="Long strings can be wrapped" name="With wrap-before/ after characters/Wrap before" time="{duration}"/>
<testcase classname="Long strings can be wrapped" name="With wrap-before/ after characters/Wrap after" time="{duration}"/> <testcase classname="Long strings can be wrapped" name="With wrap-before/ after characters/Wrap after" time="{duration}"/>
<testcase classname="global" name="Long text is truncted" time="{duration}"/> <testcase classname="global" name="Long text is truncated" time="{duration}"/>
<testcase classname="global" name="ManuallyRegistered" time="{duration}"/> <testcase classname="global" name="ManuallyRegistered" time="{duration}"/>
<testcase classname="global" name="Matchers can be (AllOf) composed with the &amp;&amp; operator" time="{duration}"/> <testcase classname="global" name="Matchers can be (AllOf) composed with the &amp;&amp; operator" time="{duration}"/>
<testcase classname="global" name="Matchers can be (AnyOf) composed with the || operator" time="{duration}"/> <testcase classname="global" name="Matchers can be (AnyOf) composed with the || operator" time="{duration}"/>
...@@ -387,6 +400,7 @@ MessageTests.cpp:<line number> ...@@ -387,6 +400,7 @@ MessageTests.cpp:<line number>
<testcase classname="global" name="Parsing a std::pair" time="{duration}"/> <testcase classname="global" name="Parsing a std::pair" time="{duration}"/>
<testcase classname="global" name="Pointers can be compared to null" time="{duration}"/> <testcase classname="global" name="Pointers can be compared to null" time="{duration}"/>
<testcase classname="global" name="Pointers can be converted to strings" time="{duration}"/> <testcase classname="global" name="Pointers can be converted to strings" time="{duration}"/>
<testcase classname="Process can be configured on command line" name="empty args don't cause a crash" time="{duration}"/>
<testcase classname="Process can be configured on command line" name="default - no arguments" time="{duration}"/> <testcase classname="Process can be configured on command line" name="default - no arguments" time="{duration}"/>
<testcase classname="Process can be configured on command line" name="test lists/1 test" time="{duration}"/> <testcase classname="Process can be configured on command line" name="test lists/1 test" time="{duration}"/>
<testcase classname="Process can be configured on command line" name="test lists/Specify one test case exclusion using exclude:" time="{duration}"/> <testcase classname="Process can be configured on command line" name="test lists/Specify one test case exclusion using exclude:" time="{duration}"/>
......
...@@ -11,6 +11,10 @@ ...@@ -11,6 +11,10 @@
#include <string> #include <string>
#include <stdexcept> #include <stdexcept>
#ifdef _MSC_VER
#pragma warning(disable:4702) // Unreachable code -- MSVC 19 (VS 2015) sees right through the indirection
#endif
namespace namespace
{ {
inline int thisThrows() inline int thisThrows()
......
...@@ -53,6 +53,13 @@ TEST_CASE( "INFO gets logged on failure, even if captured before successful asse ...@@ -53,6 +53,13 @@ TEST_CASE( "INFO gets logged on failure, even if captured before successful asse
TEST_CASE( "FAIL aborts the test", "[failing][messages][.]" ) TEST_CASE( "FAIL aborts the test", "[failing][messages][.]" )
{ {
FAIL( "This is a " << "failure" ); // This should output the message and abort FAIL( "This is a " << "failure" ); // This should output the message and abort
WARN( "We should never see this");
}
TEST_CASE( "FAIL_CHECK does not abort the test", "[failing][messages][.]" )
{
FAIL_CHECK( "This is a " << "failure" ); // This should output the message then continue
WARN( "This message appears in the output");
} }
#ifdef CATCH_CONFIG_VARIADIC_MACROS #ifdef CATCH_CONFIG_VARIADIC_MACROS
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "../include/internal/catch_xmlwriter.hpp" #include "../include/internal/catch_xmlwriter.hpp"
#include <iostream> #include <iostream>
#include <cerrno>
TEST_CASE( "random SECTION tests", "[.][sections][failing]" ) TEST_CASE( "random SECTION tests", "[.][sections][failing]" )
{ {
...@@ -393,3 +394,14 @@ TEST_CASE( "This test 'should' fail but doesn't", "[.][failing][!shouldfail]" ) ...@@ -393,3 +394,14 @@ TEST_CASE( "This test 'should' fail but doesn't", "[.][failing][!shouldfail]" )
TEST_CASE( "# A test name that starts with a #" ) { TEST_CASE( "# A test name that starts with a #" ) {
SUCCEED( "yay" ); SUCCEED( "yay" );
} }
static int f() {
return 1;
}
TEST_CASE( "#835 -- errno should not be touched by Catch", "[!shouldfail]" ) {
errno = 1;
CHECK(f() == 0);
REQUIRE(errno == 1); // Check that f() doesn't touch errno.
}
...@@ -51,10 +51,18 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]" ...@@ -51,10 +51,18 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]"
Catch::ConfigData config; Catch::ConfigData config;
SECTION( "empty args don't cause a crash" ) {
Catch::Clara::CommandLine<Catch::ConfigData> parser = Catch::makeCommandLineParser();
CHECK_NOTHROW( parser.parseInto( std::vector<std::string>(), config ) );
CHECK( config.processName == "" );
}
SECTION( "default - no arguments", "" ) { SECTION( "default - no arguments", "" ) {
const char* argv[] = { "test" }; const char* argv[] = { "test" };
CHECK_NOTHROW( parseIntoConfig( argv, config ) ); CHECK_NOTHROW( parseIntoConfig( argv, config ) );
CHECK( config.processName == "test" );
CHECK( config.shouldDebugBreak == false ); CHECK( config.shouldDebugBreak == false );
CHECK( config.abortAfter == -1 ); CHECK( config.abortAfter == -1 );
CHECK( config.noThrow == false ); CHECK( config.noThrow == false );
......
...@@ -38,3 +38,17 @@ TEST_CASE( "Character pretty printing" ){ ...@@ -38,3 +38,17 @@ TEST_CASE( "Character pretty printing" ){
} }
} }
} }
TEST_CASE( "Capture and info messages" ) {
SECTION("Capture should stringify like assertions") {
int i = 2;
CAPTURE(i);
REQUIRE(true);
}
SECTION("Info should NOT stringify the way assertions do") {
int i = 3;
INFO(i);
REQUIRE(true);
}
}
...@@ -124,16 +124,18 @@ args = parser.parse_args() ...@@ -124,16 +124,18 @@ args = parser.parse_args()
compiler_path = args.compiler compiler_path = args.compiler
catch_path = args.catch_header catch_path = args.catch_header
os.chdir(dir_name)
if args.generate_files: if args.generate_files:
create_temp_dir() create_temp_dir()
copy_catch(catch_path) copy_catch(catch_path)
os.chdir(dir_name)
# now create the fake test files # now create the fake test files
generate_files() generate_files()
# Early exit # Early exit
print('Finished generating files') print('Finished generating files')
exit(1) exit(1)
os.chdir(dir_name)
if args.flags: if args.flags:
flags = args.flags flags = args.flags
......
...@@ -75,7 +75,6 @@ class Version: ...@@ -75,7 +75,6 @@ class Version:
f.write( line + "\n" ) f.write( line + "\n" )
def updateReadmeFile(self): def updateReadmeFile(self):
versionParser = re.compile( r'\*v\d+\.\d+\.\d+\*' )
downloadParser = re.compile( r'<a href=\"https://github.com/philsquared/Catch/releases/download/v\d+\.\d+\.\d+/catch.hpp\">' ) downloadParser = re.compile( r'<a href=\"https://github.com/philsquared/Catch/releases/download/v\d+\.\d+\.\d+/catch.hpp\">' )
f = open( readmePath, 'r' ) f = open( readmePath, 'r' )
lines = [] lines = []
...@@ -84,7 +83,6 @@ class Version: ...@@ -84,7 +83,6 @@ class Version:
f.close() f.close()
f = open( readmePath, 'w' ) f = open( readmePath, 'w' )
for line in lines: for line in lines:
line = versionParser.sub( '*v{0}*'.format(self.getVersionString()), line)
line = downloadParser.sub( r'<a href="https://github.com/philsquared/Catch/releases/download/v{0}/catch.hpp">'.format(self.getVersionString()) , line) line = downloadParser.sub( r'<a href="https://github.com/philsquared/Catch/releases/download/v{0}/catch.hpp">'.format(self.getVersionString()) , line)
f.write( line + "\n" ) f.write( line + "\n" )
...@@ -102,7 +102,7 @@ function get_libsrtp() ...@@ -102,7 +102,7 @@ function get_libsrtp()
function get_catch() function get_catch()
{ {
GIT_REPO="https://github.com/philsquared/Catch.git" GIT_REPO="https://github.com/philsquared/Catch.git"
GIT_TAG="v1.8.1" GIT_TAG="v1.8.2"
DEST="deps/catch" DEST="deps/catch"
get_dep "${GIT_REPO}" "${GIT_TAG}" "${DEST}" get_dep "${GIT_REPO}" "${GIT_TAG}" "${DEST}"
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论