Compare commits

...

53 Commits

Author SHA1 Message Date
Phil Nash
19ab2117c5 Remove spurious test following merge 2017-11-03 18:09:55 +00:00
Phil Nash
4acf112c19 Removed zombie files
These files were removed from the Catch2 branch, and crept back in when Catch2 merged with master
2017-11-03 16:56:11 +00:00
Phil Nash
53f6d3fc8e Locked release notes reference to v2.0.1 release 2017-11-03 13:31:59 +00:00
Phil Nash
cf76a795cc Added note about Catch2 to readme 2017-11-03 13:18:26 +00:00
Phil Nash
811f4d13d7 Updated links in readme 2017-11-03 13:15:22 +00:00
Phil Nash
7423a481eb Updated some Catch references to Catch2 2017-11-03 13:05:09 +00:00
Phil Nash
46c7c9d3a0 Merge branch 'catch2' 2017-11-03 12:05:38 +00:00
Phil Nash
b119ebdde1 v2.0.1 release 2017-11-03 12:01:52 +00:00
Phil Nash
1c43fb64c1 Added docs for extending command line with Clara 2017-11-02 18:01:24 +00:00
Phil Nash
8b40c26434 Removed handling of start-up exceptions from custom main docs 2017-11-02 18:01:24 +00:00
Phil Nash
fe05062f9e Print any start-up exceptions in Session's constructor, so custom main's don't need to worry about them 2017-11-02 17:58:07 +00:00
Martin Hořeňovský
31cc62e6b7 Updated release notes with Approx changes 2017-11-01 22:25:17 +01:00
Martin Hořeňovský
a49e6fdc27 Update Approx documentation 2017-11-01 13:45:21 +01:00
Pfiffikus
2d91035404 Update assertions.md
scale more detailed explained; have to be adapted to PR #1068 if necessary
2017-11-01 13:32:08 +01:00
Martin Hořeňovský
accf9859b4 Add OSX specific INFINITE macro parsing in approval tests 2017-11-01 08:46:49 +01:00
Martin Hořeňovský
22ac9d2184 Approx cleanup: More tests, INFINITY handling, etc 2017-11-01 07:30:11 +01:00
Pfiffikus
00af677577 Approx rework: default scale == 0, epsilon applies to Approx::value
Also adds check to Approx::epsilon that the new epsilon has a valid
(ie one between 0 and 1)

Based on
http://realtimecollisiondetection.net/blog/?p=89
https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html
https://en.wikipedia.org/wiki/Approximation_error#Formal_Definition

The given epsilon should refer to the target value, otherwise
the result would be unexpected, e.g. 101.02 == Approx(100).epsilon(0.01)
is true.
The default scale should be invisible, thus,
e.g. 101.01 == Approx(100).epsilon(0.01) gets false.
Finally even 101.000001 == Approx(100).epsilon(0.01) is false
2017-10-31 15:43:42 +01:00
Martin Hořeňovský
2a3606f8e3 v1.11.0 2017-10-31 13:55:48 +01:00
Martin Hořeňovský
a6cf19abff Make Approx::margin inclusive
Fixes #952, related to #980
2017-10-30 21:33:29 +01:00
Pfiffikus
06586b7180 Update test-cases-and-sections.md
some clarification and typo correction
2017-10-26 13:57:18 +02:00
Clare Macrae
93b3d2cb8f Fix very minor typo
it's -> its
2017-10-24 20:00:27 +02:00
Pfiffikus
a90473df28 Update build-systems.md
typo correction
2017-10-24 19:59:59 +02:00
Sebastian Grottel
c9d9699ca8 adds flushes to the output stream of teamcity reporter, making the test output more responsive. 2017-10-17 16:42:05 +02:00
Sebastian Grottel
296955c437 RandomNumberGenerator::result_type should be unsigned (#1050)
`result_type` must be unsigned:
http://en.cppreference.com/w/cpp/concept/UniformRandomBitGenerator

Using a signed type causes an infinite loop working with MS Visual Studio 2017, targetting: v140, WindowsTargetPlatformVersion 10.0.15063.0, Debug, x64
2017-10-15 18:30:40 +02:00
dvirtz
664cbf702c added PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS option 2017-10-15 17:58:39 +02:00
Martin Hořeňovský
fb6700df54 Fix documentation crosslink in configuration.md 2017-10-14 08:36:44 +02:00
Phil Nash
da6c2a6914 Fixed expansion of _FALSE binary expression
- see #1051
2017-10-13 19:44:20 +01:00
Dmitry Kozhevnikov
9c07718b5f Update handling of __JETBRAINS_IDE__ macro
1. Use it to conditionally define CATCH_INTERNAL_CONFIG_COUNTER, not
   CATCH_CONFIG_COUNTER, as __JETBRAINS_IDE__ is similar to
   compiler-provided macros, not to user-provided ones.

2. Since __COUNTER__ will work starting with CLion 2017.3, use it
   when possible (and hopefully remove this check altogether
   at some point).
2017-09-07 18:00:04 +02:00
solvingj
5ca44b6872 Minor - added header-only flag in conan
See header-only guidelines: 
http://conanio.readthedocs.io/en/latest/howtos/header_only.html?highlight=header%20only
Its borderline cosmetic, but it does have a purpose.
2017-08-28 12:18:54 +02:00
Sam Bristow
a04bd6d436 Remove duplicate CLI option
The "use-colour" option was accidentally duplicated as part of commit
feaf355 (Implemented libidentify support).
2017-08-28 12:16:23 +02:00
Martin Hořeňovský
784f6dfb34 Fix updateVcpkgPackage 2017-08-27 11:43:55 +02:00
Martin Hořeňovský
7818e2666d v1.10.0 2017-08-26 15:34:18 +02:00
Martin Hořeňovský
cd30dd1a70 Workaround raw string literal bug in VS2017 2017-08-26 15:14:27 +02:00
Phil Nash
8e8c0c1675 Tweaked how failedButOk assertions are recorded
- fixes issue where sections in !shouldfail or !mayfail test cases that have failing assertions where marked as failed instead of failedButOk
2017-08-25 11:37:49 +01:00
Phil Nash
b6e7c9bd7a Specialise removeConst for nullptr 2017-08-24 23:07:44 +02:00
Phil Nash
180d9242f5 Suppress more signed/ unsigned mismatches during Evaluator calls on MSVC 2017-08-24 23:07:03 +02:00
Phil Nash
b7bd52cc98 Cherry-picked "evaluate" refactoring from dev-modernize branch
- fixed up NULL comparisons to allow for NULL being a long
- should address #981
2017-08-24 23:07:03 +02:00
Martin Hořeňovský
b07a2bdf87 Refactor release scripts, automatically update Wandbox on release 2017-08-24 21:59:06 +02:00
Martin Hořeňovský
c03e8fce92 Explicitly ignore return value of getchar
This silences MSVC warning about ignored return value
2017-08-22 22:06:37 +02:00
Phil Nash
27640a5a96 Added Clara and TextFlowCpp to open source users 2017-08-17 10:49:56 +01:00
Phil Nash
dd3867bbcd Create CODE_OF_CONDUCT.md 2017-08-17 07:45:12 +01:00
Phil Nash
387f8d254d Removed unnecessary single quotes 2017-08-15 19:41:46 +01:00
Phil Nash
c65eccd68e Added --libidentify and --wait-for-keypress to docs 2017-08-15 19:39:38 +01:00
Phil Nash
61c5675c11 Removed inadvertent use of auto merged from dev-modernise 2017-08-15 19:34:10 +01:00
Phil Nash
70e4af9d44 Implemented wait-for-keypress option 2017-08-15 14:12:11 +01:00
Monocasual
8f41bdb92d Add open-source user 2017-08-13 17:55:50 +02:00
Phil Nash
7fa5d9ca94 Removed redundant processName argument from libIdentify call 2017-08-11 22:03:09 +01:00
Phil Nash
feaf355489 Implemented libidentify support
- see https://github.com/janwilmans/LibIdentify
2017-08-11 19:55:55 +01:00
Martin Hořeňovský
2ce6c74f8f v1.9.7 2017-08-11 00:01:20 +02:00
Phil Nash
9688891868 Fix issue with fatal errors and non-failing assertions
Fixes #990
2017-08-10 21:44:54 +02:00
Martin Hořeňovský
4f21bb72ff Add tests for #961 2017-08-10 21:38:07 +02:00
Martin Hořeňovský
b435e0d7c7 Make default reporter configurable at compile time
Closes #978
2017-08-10 16:45:38 +02:00
Martin Hořeňovský
ba0a09fd9e Update documentation with changes from 7e4038d 2017-08-10 16:43:17 +02:00
21 changed files with 382 additions and 136 deletions

View File

@@ -9,7 +9,7 @@ set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark)
set(HEADER_DIR ${CATCH_DIR}/include)
set(CATCH_VERSION_NUMBER 2.0.0-develop.6)
set(CATCH_VERSION_NUMBER 2.0.1)
if(USE_CPP14)
message(STATUS "Enabling C++14")

View File

@@ -1,17 +1,23 @@
<a id="top"></a>
![catch logo](catch-logo-small.png)
[![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=catch2)](https://travis-ci.org/philsquared/Catch?branch=catch2)
[![Build status](https://ci.appveyor.com/api/projects/status/hrtk60hv6tw6fght/branch/catch2?svg=true)](https://ci.appveyor.com/project/philsquared/catch/branch/catch2)
[![Github Releases](https://img.shields.io/github/release/philsquared/catch.svg)](https://github.com/catchorg/catch2/releases)
[![Build Status](https://travis-ci.org/philsquared/Catch.svg)](https://travis-ci.org/philsquared/Catch)
[![Build status](https://ci.appveyor.com/api/projects/status/hrtk60hv6tw6fght)](https://ci.appveyor.com/project/philsquared/catch)
<a href="https://github.com/philsquared/Catch/releases/download/v2.0.0-develop.6/catch.hpp">The latest version of the single header can be downloaded directly using this link</a>
<a href="https://github.com/catchorg/Catch2/releases/download/v2.0.1/catch.hpp">The latest version of the single header can be downloaded directly using this link</a>
## Catch2 is released!
If you've been using an earlier version of Catch, please see the
Breaking Changes section of [the release notes](https://github.com/catchorg/Catch2/releases/tag/v2.0.1)
before moving to Catch2.
## What's the Catch?
Catch stands for C++ Automated Test Cases in Headers and is a
Catch2 stands for C++ Automated Test Cases in a Header and is a
multi-paradigm test framework for C++. which also supports Objective-C
and, maybe, C.
(and maybe C).
It is primarily distributed as a single header file, although certain
extensions may require additional headers.
@@ -23,6 +29,6 @@ This documentation comprises these three parts:
* [Reference section](docs/Readme.md#top) - all the details
## More
* Issues and bugs can be raised on the [Issue tracker on GitHub](https://github.com/philsquared/Catch/issues)
* Issues and bugs can be raised on the [Issue tracker on GitHub](https://github.com/catchorg/Catch2/issues)
* For discussion or questions please use [the dedicated Google Groups forum](https://groups.google.com/forum/?fromgroups#!forum/catch-forum)
* See [who else is using Catch](docs/opensource-users.md#top)
* See [who else is using Catch2](docs/opensource-users.md#top)

View File

@@ -4,7 +4,7 @@ from conans import ConanFile
class CatchConan(ConanFile):
name = "Catch"
version = "2.0.0-develop.6"
version = "2.0.1"
description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD"
author = "philsquared"
generators = "cmake"

View File

@@ -1,7 +1,7 @@
<a id="top"></a>
# Reference
To get the most out of Catch, start with the [tutorial](tutorial.md#top).
To get the most out of Catch2, start with the [tutorial](tutorial.md#top).
Once you're up and running consider the following reference material.
Writing tests:

View File

@@ -64,7 +64,7 @@ This way `Approx` is constructed with reasonable defaults, covering most simple
* __epsilon__ - epsilon serves to set the percentage by which a result can be erroneous, before it is rejected. By default set to `std::numeric_limits<float>::epsilon()*100`.
* __margin__ - margin serves to set the the absolute value by which a result can be erroneous before it is rejected. By default set to `0.0`.
* __scale__ - scale serves to adjust the base for comparison used by epsilon, can be used when By default set to `1.0`.
* __scale__ - scale serves to adjust the epsilon's multiplicator. By default set to `0.0`.
#### epsilon example
```cpp
@@ -84,7 +84,12 @@ Approx target = Approx(100).margin(5);
```
#### scale
Scale can be useful if the computation leading to the result worked on different scale, than is used by the results (and thus expected errors are on a different scale than would be expected based on the results alone).
Scale can be useful if the computation leading to the result worked
on different scale than is used by the results. Since allowed difference
between Approx's value and compared value is based primarily on Approx's value
(the allowed difference is computed as
`(Approx::scale + Approx::value) * epsilon`), the resulting comparison could
need rescaling to be correct.
## Exceptions

View File

@@ -39,34 +39,20 @@ If you still want Catch to process the command line, but you want to programatic
int main( int argc, char* argv[] )
{
Catch::Session session; // There must be exactly one instance
// writing to session.configData() here sets defaults
// this is the preferred way to set them
// Verify that all tests, aliases, etc registered properly
const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions();
if ( !exceptions.empty() ) {
// iterate over all exceptions and notify user
for ( const auto& ex_ptr : exceptions ) {
try {
std::rethrow_exception(ex_ptr);
} catch (std::exception const& ex) {
Catch::cerr() << ex.what();
}
}
// Indicate that an error occured before main
return 1;
}
int returnCode = session.applyCommandLine( argc, argv );
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
return returnCode;
// writing to session.configData() or session.Config() here
// overrides command line args
// only do this if you know you need to
int numFailed = session.run();
// numFailed is clamped to 255 as some unices only use the lower 8 bits.
// This clamping has already been applied, so just return it here
// You can also do any post run clean-up here
@@ -80,7 +66,44 @@ To take full control of the config simply omit the call to ```applyCommandLine()
## Adding your own command line options
Catch embeds a powerful command line parser which you can also use to parse your own options out. This capability is still in active development but will be documented here when it is ready.
Catch embeds a powerful command line parser called [Clara](https://github.com/philsquared/Clara).
As of Catch2 (and Clara 1.0) Clara allows you to write _composable_ option and argument parsers,
so extending Catch's own command line options is now easy.
```c++
#define CATCH_CONFIG_RUNNER
#include "catch.hpp"
int main( int argc, char* argv[] )
{
Catch::Session session; // There must be exactly one instance
int height = 0; // Some user variable you want to be able to set
// Build a new parser on top of Catch's
auto cli
= session.cli() // Get Catch's composite command line parser
| Opt( height, "height" ) // bind variable to a new option, with a hint string
["-g"]["--height"] // the option names it will respond to
("how high?"); // description string for the help output
// Now pass the new composite back to Catch so it uses that
session.cli( cli );
// Let Catch (using Clara) parse the command line
int returnCode = session.applyCommandLine( argc, argv );
if( returnCode != 0 ) // Indicates a command line error
return returnCode;
// if set on the command line then 'height' is now set at this point
if( height > 0 )
std::cout << "height: " << height << std::endl;
return session.run();
}
```
See the [Clara documentation](https://github.com/philsquared/Clara/blob/master/README.md) for more details.
---

View File

@@ -1,5 +1,5 @@
<a id="top"></a>
# 2.0.0 (in progress)
# 2.0.1
## Breaking changes
* Removed C++98 support
@@ -25,6 +25,11 @@
* `std::pair` and `std::tuple` are no longer stringified by default
* This is done to avoid dragging in `<tuple>` and `<utility>` headers in common path
* Their stringification can be enabled per-file via new configuration macros
* `Approx` is subtly different and hopefully behaves more as users would expect
* `Approx::scale` defaults to `0.0`
* `Approx::epsilon` no longer applies to the larger of the two compared values, but only to the `Approx`'s value
* `INFINITY == Approx(INFINITY)` returns true
## Improvements
* Reporters and Listeners can be defined in files different from the main file

View File

@@ -2,7 +2,7 @@
# Tutorial
**Contents**<br>
[Getting Catch](#getting-catch)<br>
[Getting Catch2](#getting-catch2)<br>
[Where to put it?](#where-to-put-it)<br>
[Writing tests](#writing-tests)<br>
[Test cases and sections](#test-cases-and-sections)<br>
@@ -10,18 +10,18 @@
[Scaling up](#scaling-up)<br>
[Next steps](#next-steps)<br>
## Getting Catch
## Getting Catch2
The simplest way to get Catch is to download the latest [single header version](https://raw.githubusercontent.com/philsquared/Catch/master/single_include/catch.hpp). The single header is generated by merging a set of individual headers but it is still just normal source code in a header file.
The simplest way to get Catch2 is to download the latest [single header version](https://raw.githubusercontent.com/CatchOrg/Catch2/master/single_include/catch.hpp). The single header is generated by merging a set of individual headers but it is still just normal source code in a header file.
The full source for Catch, including test projects, documentation, and other things, is hosted on GitHub. [http://catch-lib.net](http://catch-lib.net) will redirect you there.
The full source for Catch2, including test projects, documentation, and other things, is hosted on GitHub. [http://catch-lib.net](http://catch-lib.net) will redirect you there.
## Where to put it?
Catch is header only. All you need to do is drop the file(s) somewhere reachable from your project - either in some central location you can set your header search path to find, or directly into your project tree itself! This is a particularly good option for other Open-Source projects that want to use Catch for their test suite. See [this blog entry for more on that](http://www.levelofindirection.com/journal/2011/5/27/unit-testing-in-c-and-objective-c-just-got-ridiculously-easi.html).
Catch2 is header only. All you need to do is drop the file somewhere reachable from your project - either in some central location you can set your header search path to find, or directly into your project tree itself! This is a particularly good option for other Open-Source projects that want to use Catch for their test suite. See [this blog entry for more on that](http://www.levelofindirection.com/journal/2011/5/27/unit-testing-in-c-and-objective-c-just-got-ridiculously-easi.html).
The rest of this tutorial will assume that the Catch single-include header (or the include folder) is available unqualified - but you may need to prefix it with a folder name if necessary.
The rest of this tutorial will assume that the Catch2 single-include header (or the include folder) is available unqualified - but you may need to prefix it with a folder name if necessary.
## Writing tests

View File

@@ -8,22 +8,26 @@
#include "catch_approx.h"
#include <cmath>
#include <limits>
namespace {
// Performs equivalent check of std::fabs(lhs - rhs) <= margin
// But without the subtraction to allow for INFINITY in comparison
bool marginComparison(double lhs, double rhs, double margin) {
return (lhs + margin >= rhs) && (rhs + margin >= lhs);
}
}
namespace Catch {
namespace Detail {
double dmax(double lhs, double rhs) {
if (lhs < rhs) {
return rhs;
}
return lhs;
}
Approx::Approx ( double value )
: m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
m_margin( 0.0 ),
m_scale( 1.0 ),
m_scale( 0.0 ),
m_value( value )
{}
@@ -37,6 +41,12 @@ namespace Detail {
return oss.str();
}
bool Approx::equalityComparisonImpl(const double other) const {
// First try with fixed margin, then compute margin based on epsilon, scale and Approx's value
// Thanks to Richard Harris for his help refining the scaled margin value
return marginComparison(m_value, other, m_margin) || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(m_value)));
}
} // end namespace Detail
std::string StringMaker<Catch::Detail::Approx>::convert(Catch::Detail::Approx const& value) {

View File

@@ -11,16 +11,15 @@
#include "catch_enforce.h"
#include "catch_tostring.h"
#include <cmath>
#include <type_traits>
namespace Catch {
namespace Detail {
double dmax(double lhs, double rhs);
class Approx {
private:
bool equalityComparisonImpl(double other) const;
public:
explicit Approx ( double value );
@@ -42,14 +41,8 @@ namespace Detail {
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
friend bool operator == ( const T& lhs, Approx const& rhs ) {
// Thanks to Richard Harris for his help refining this formula
auto lhs_v = static_cast<double>(lhs);
bool relativeOK = std::fabs(lhs_v - rhs.m_value) < rhs.m_epsilon * (rhs.m_scale +
dmax(std::fabs(lhs_v), std::fabs(rhs.m_value)));
if (relativeOK) {
return true;
}
return std::fabs(lhs_v - rhs.m_value) <= rhs.m_margin;
return rhs.equalityComparisonImpl(lhs_v);
}
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
@@ -89,14 +82,21 @@ namespace Detail {
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
Approx& epsilon( T const& newEpsilon ) {
m_epsilon = static_cast<double>(newEpsilon);
double epsilonAsDouble = static_cast<double>(newEpsilon);
CATCH_ENFORCE(epsilonAsDouble >= 0 && epsilonAsDouble <= 1.0,
"Invalid Approx::epsilon: " << epsilonAsDouble
<< ", Approx::epsilon has to be between 0 and 1");
m_epsilon = epsilonAsDouble;
return *this;
}
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
Approx& margin( T const& newMargin ) {
m_margin = static_cast<double>(newMargin);
CATCH_ENFORCE(m_margin >= 0, "Invalid Approx::margin: " << m_margin << ", Approx::Margin has to be non-negative.");
double marginAsDouble = static_cast<double>(newMargin);
CATCH_ENFORCE(marginAsDouble >= 0,
"Invalid Approx::margin: " << marginAsDouble
<< ", Approx::Margin has to be non-negative.");
m_margin = marginAsDouble;
return *this;
}

View File

@@ -116,8 +116,26 @@ namespace Catch {
Session::Session() {
static bool alreadyInstantiated = false;
if( alreadyInstantiated )
CATCH_INTERNAL_ERROR( "Only one instance of Catch::Session can ever be used" );
if( alreadyInstantiated ) {
try { CATCH_INTERNAL_ERROR( "Only one instance of Catch::Session can ever be used" ); }
catch(...) { getMutableRegistryHub().registerStartupException(); }
}
const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions();
if ( !exceptions.empty() ) {
m_startupExceptions = true;
Colour colourGuard( Colour::Red );
Catch::cerr() << "Errors occured during startup!" << '\n';
// iterate over all exceptions and notify user
for ( const auto& ex_ptr : exceptions ) {
try {
std::rethrow_exception(ex_ptr);
} catch ( std::exception const& ex ) {
Catch::cerr() << Column( ex.what() ).indent(2) << '\n';
}
}
}
alreadyInstantiated = true;
m_cli = makeCommandLineParser( m_configData );
}
@@ -140,6 +158,9 @@ namespace Catch {
}
int Session::applyCommandLine( int argc, char* argv[] ) {
if( m_startupExceptions )
return 1;
auto result = m_cli.parse( clara::Args( argc, argv ) );
if( !result ) {
Catch::cerr()
@@ -165,19 +186,8 @@ namespace Catch {
}
int Session::run( int argc, char* argv[] ) {
const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions();
if ( !exceptions.empty() ) {
Catch::cerr() << "Errors occured during startup!" << '\n';
// iterate over all exceptions and notify user
for ( const auto& ex_ptr : exceptions ) {
try {
std::rethrow_exception(ex_ptr);
} catch ( std::exception const& ex ) {
Catch::cerr() << ex.what() << '\n';
}
}
if( m_startupExceptions )
return 1;
}
int returnCode = applyCommandLine( argc, argv );
if( returnCode == 0 )
returnCode = run();
@@ -236,6 +246,9 @@ namespace Catch {
}
int Session::runInternal() {
if( m_startupExceptions )
return 1;
if( m_configData.showHelp || m_configData.libIdentify )
return 0;

View File

@@ -45,6 +45,7 @@ namespace Catch {
clara::Parser m_cli;
ConfigData m_configData;
std::shared_ptr<Config> m_config;
bool m_startupExceptions = false;
};
} // end namespace Catch

View File

@@ -37,7 +37,7 @@ namespace Catch {
}
Version const& libraryVersion() {
static Version version( 2, 0, 0, "develop", 6 );
static Version version( 2, 0, 1, "", 0 );
return version;
}

View File

@@ -8,6 +8,8 @@
#include "catch.hpp"
#include <cmath>
///////////////////////////////////////////////////////////////////////////////
TEST_CASE
(
@@ -25,7 +27,7 @@ TEST_CASE
REQUIRE( Approx( d ) != 1.22 );
REQUIRE( Approx( d ) != 1.24 );
REQUIRE( 0 == Approx(0) );
REQUIRE(INFINITY == Approx(INFINITY));
}
///////////////////////////////////////////////////////////////////////////////
@@ -106,7 +108,7 @@ TEST_CASE
REQUIRE( 1.0f == Approx( 1 ) );
REQUIRE( 0 == Approx( dZero) );
REQUIRE( 0 == Approx( dSmall ).epsilon( 0.001 ) );
REQUIRE( 0 == Approx( dSmall ).margin( 0.001 ) );
REQUIRE( 1.234f == Approx( dMedium ) );
REQUIRE( dMedium == Approx( 1.234f ) );
}
@@ -120,7 +122,7 @@ TEST_CASE
{
double d = 1.23;
Approx approx = Approx::custom().epsilon( 0.005 );
Approx approx = Approx::custom().epsilon( 0.01 );
REQUIRE( d == approx( 1.23 ) );
REQUIRE( d == approx( 1.22 ) );
@@ -169,9 +171,26 @@ TEST_CASE("Approx setters validate their arguments", "[Approx]") {
REQUIRE_NOTHROW(Approx(0).margin(1234656));
REQUIRE_THROWS_AS(Approx(0).margin(-2), std::domain_error);
REQUIRE_NOTHROW(Approx(0).epsilon(0));
REQUIRE_NOTHROW(Approx(0).epsilon(1));
REQUIRE_THROWS_AS(Approx(0).epsilon(-0.001), std::domain_error);
REQUIRE_THROWS_AS(Approx(0).epsilon(1.0001), std::domain_error);
}
////////////////////////////////////////////////////////////////////////////////
TEST_CASE("Default scale is invisible to comparison", "[Approx]") {
REQUIRE(101.000001 != Approx(100).epsilon(0.01));
REQUIRE(std::pow(10, -5) != Approx(std::pow(10, -7)));
}
TEST_CASE("Epsilon only applies to Approx's value", "[Approx]") {
REQUIRE(101.01 != Approx(100).epsilon(0.01));
}
TEST_CASE("Assorted miscellaneous tests", "[Approx]") {
REQUIRE(INFINITY == Approx(INFINITY));
}
class StrongDoubleTypedef
{
@@ -207,5 +226,3 @@ TEST_CASE( "Comparison with explicitly convertible types", "[Approx]" )
REQUIRE(Approx(11.0) >= td);
}
////////////////////////////////////////////////////////////////////////////////

View File

@@ -1003,6 +1003,6 @@ with expansion:
"{?}" == "1"
===============================================================================
test cases: 182 | 131 passed | 47 failed | 4 failed as expected
assertions: 896 | 779 passed | 96 failed | 21 failed as expected
test cases: 185 | 134 passed | 47 failed | 4 failed as expected
assertions: 904 | 787 passed | 96 failed | 21 failed as expected

View File

@@ -576,6 +576,22 @@ ApproxTests.cpp:<line number>:
PASSED:
REQUIRE_THROWS_AS( Approx(0).margin(-2), std::domain_error )
ApproxTests.cpp:<line number>:
PASSED:
REQUIRE_NOTHROW( Approx(0).epsilon(0) )
ApproxTests.cpp:<line number>:
PASSED:
REQUIRE_NOTHROW( Approx(0).epsilon(1) )
ApproxTests.cpp:<line number>:
PASSED:
REQUIRE_THROWS_AS( Approx(0).epsilon(-0.001), std::domain_error )
ApproxTests.cpp:<line number>:
PASSED:
REQUIRE_THROWS_AS( Approx(0).epsilon(1.0001), std::domain_error )
-------------------------------------------------------------------------------
Approx with exactly-representable margin
-------------------------------------------------------------------------------
@@ -704,7 +720,7 @@ with expansion:
ApproxTests.cpp:<line number>:
PASSED:
REQUIRE( 0 == Approx( dSmall ).epsilon( 0.001 ) )
REQUIRE( 0 == Approx( dSmall ).margin( 0.001 ) )
with expansion:
0 == Approx( 0.00001 )
@@ -798,6 +814,18 @@ PASSED:
with expansion:
true
-------------------------------------------------------------------------------
Assorted miscellaneous tests
-------------------------------------------------------------------------------
ApproxTests.cpp:<line number>
...............................................................................
ApproxTests.cpp:<line number>:
PASSED:
REQUIRE( INFINITY == Approx(INFINITY) )
with expansion:
inff == Approx( inf )
-------------------------------------------------------------------------------
Bitfields can be captured (#1027)
-------------------------------------------------------------------------------
@@ -1293,6 +1321,24 @@ ExceptionTests.cpp:<line number>: FAILED:
due to unexpected exception with message:
custom std exception
-------------------------------------------------------------------------------
Default scale is invisible to comparison
-------------------------------------------------------------------------------
ApproxTests.cpp:<line number>
...............................................................................
ApproxTests.cpp:<line number>:
PASSED:
REQUIRE( 101.000001 != Approx(100).epsilon(0.01) )
with expansion:
101.000001 != Approx( 100.0 )
ApproxTests.cpp:<line number>:
PASSED:
REQUIRE( std::pow(10, -5) != Approx(std::pow(10, -7)) )
with expansion:
0.00001 != Approx( 0.0000001 )
-------------------------------------------------------------------------------
EndsWith string matcher
-------------------------------------------------------------------------------
@@ -1304,6 +1350,18 @@ MatchersTests.cpp:<line number>: FAILED:
with expansion:
"this string contains 'abc' as a substring" ends with: "this"
-------------------------------------------------------------------------------
Epsilon only applies to Approx's value
-------------------------------------------------------------------------------
ApproxTests.cpp:<line number>
...............................................................................
ApproxTests.cpp:<line number>:
PASSED:
REQUIRE( 101.01 != Approx(100).epsilon(0.01) )
with expansion:
101.01 != Approx( 100.0 )
-------------------------------------------------------------------------------
Equality checks that should fail
-------------------------------------------------------------------------------
@@ -4263,9 +4321,9 @@ with expansion:
ApproxTests.cpp:<line number>:
PASSED:
REQUIRE( 0 == Approx(0) )
REQUIRE( INFINITY == Approx(INFINITY) )
with expansion:
0 == Approx( 0.0 )
inff == Approx( inf )
Message from section one
-------------------------------------------------------------------------------
@@ -7574,6 +7632,6 @@ MiscTests.cpp:<line number>:
PASSED:
===============================================================================
test cases: 182 | 129 passed | 49 failed | 4 failed as expected
assertions: 895 | 775 passed | 99 failed | 21 failed as expected
test cases: 185 | 132 passed | 49 failed | 4 failed as expected
assertions: 903 | 783 passed | 99 failed | 21 failed as expected

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact
>
<testsuite name="<exe-name>" errors="15" failures="85" tests="896" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testsuite name="<exe-name>" errors="15" failures="85" tests="904" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#748 - captures with unexpected exceptions/outside assertions" time="{duration}">
@@ -111,6 +111,7 @@ ExceptionTests.cpp:<line number>
<testcase classname="<exe-name>.global" name="Assertions then sections/A section" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Assertions then sections/A section/Another section" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Assertions then sections/A section/Another other section" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Assorted miscellaneous tests" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Bitfields can be captured (#1027)" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Capture and info messages/Capture should stringify like assertions" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Capture and info messages/Info should NOT stringify the way assertions do" time="{duration}"/>
@@ -146,11 +147,13 @@ custom std exception
ExceptionTests.cpp:<line number>
</error>
</testcase>
<testcase classname="<exe-name>.global" name="Default scale is invisible to comparison" time="{duration}"/>
<testcase classname="<exe-name>.global" name="EndsWith string matcher" time="{duration}">
<failure message="&quot;this string contains 'abc' as a substring&quot; ends with: &quot;this&quot;" type="CHECK_THAT">
MatchersTests.cpp:<line number>
</failure>
</testcase>
<testcase classname="<exe-name>.global" name="Epsilon only applies to Approx's value" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Equality checks that should fail" time="{duration}">
<failure message="7 == 6" type="CHECK">
ConditionTests.cpp:<line number>

View File

@@ -601,6 +601,38 @@
Approx(0).margin(-2), std::domain_error
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_NOTHROW" filename="projects/<exe-name>/ApproxTests.cpp" >
<Original>
Approx(0).epsilon(0)
</Original>
<Expanded>
Approx(0).epsilon(0)
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_NOTHROW" filename="projects/<exe-name>/ApproxTests.cpp" >
<Original>
Approx(0).epsilon(1)
</Original>
<Expanded>
Approx(0).epsilon(1)
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_THROWS_AS" filename="projects/<exe-name>/ApproxTests.cpp" >
<Original>
Approx(0).epsilon(-0.001), std::domain_error
</Original>
<Expanded>
Approx(0).epsilon(-0.001), std::domain_error
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE_THROWS_AS" filename="projects/<exe-name>/ApproxTests.cpp" >
<Original>
Approx(0).epsilon(1.0001), std::domain_error
</Original>
<Expanded>
Approx(0).epsilon(1.0001), std::domain_error
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Approx with exactly-representable margin" tags="[Approx]" filename="projects/<exe-name>/ApproxTests.cpp" >
@@ -741,7 +773,7 @@
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ApproxTests.cpp" >
<Original>
0 == Approx( dSmall ).epsilon( 0.001 )
0 == Approx( dSmall ).margin( 0.001 )
</Original>
<Expanded>
0 == Approx( 0.00001 )
@@ -828,6 +860,17 @@
</Section>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Assorted miscellaneous tests" tags="[Approx]" filename="projects/<exe-name>/ApproxTests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ApproxTests.cpp" >
<Original>
INFINITY == Approx(INFINITY)
</Original>
<Expanded>
inff == Approx( inf )
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Bitfields can be captured (#1027)" filename="projects/<exe-name>/TrickyTests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/TrickyTests.cpp" >
<Original>
@@ -1433,6 +1476,25 @@
</Exception>
<OverallResult success="false"/>
</TestCase>
<TestCase name="Default scale is invisible to comparison" tags="[Approx]" filename="projects/<exe-name>/ApproxTests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ApproxTests.cpp" >
<Original>
101.000001 != Approx(100).epsilon(0.01)
</Original>
<Expanded>
101.000001 != Approx( 100.0 )
</Expanded>
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ApproxTests.cpp" >
<Original>
std::pow(10, -5) != Approx(std::pow(10, -7))
</Original>
<Expanded>
0.00001 != Approx( 0.0000001 )
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="EndsWith string matcher" tags="[.][failing][matchers]" filename="projects/<exe-name>/MatchersTests.cpp" >
<Expression success="false" type="CHECK_THAT" filename="projects/<exe-name>/MatchersTests.cpp" >
<Original>
@@ -1444,6 +1506,17 @@
</Expression>
<OverallResult success="false"/>
</TestCase>
<TestCase name="Epsilon only applies to Approx's value" tags="[Approx]" filename="projects/<exe-name>/ApproxTests.cpp" >
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ApproxTests.cpp" >
<Original>
101.01 != Approx(100).epsilon(0.01)
</Original>
<Expanded>
101.01 != Approx( 100.0 )
</Expanded>
</Expression>
<OverallResult success="true"/>
</TestCase>
<TestCase name="Equality checks that should fail" tags="[!mayfail][.][failing]" filename="projects/<exe-name>/ConditionTests.cpp" >
<Expression success="false" type="CHECK" filename="projects/<exe-name>/ConditionTests.cpp" >
<Original>
@@ -4875,10 +4948,10 @@ A string sent directly to stderr
</Expression>
<Expression success="true" type="REQUIRE" filename="projects/<exe-name>/ApproxTests.cpp" >
<Original>
0 == Approx(0)
INFINITY == Approx(INFINITY)
</Original>
<Expanded>
0 == Approx( 0.0 )
inff == Approx( inf )
</Expanded>
</Expression>
<OverallResult success="true"/>
@@ -8373,7 +8446,7 @@ loose text artifact
</Section>
<OverallResult success="true"/>
</TestCase>
<OverallResults successes="775" failures="100" expectedFailures="21"/>
<OverallResults successes="783" failures="100" expectedFailures="21"/>
</Group>
<OverallResults successes="775" failures="99" expectedFailures="21"/>
<OverallResults successes="783" failures="99" expectedFailures="21"/>
</Catch>

View File

@@ -45,6 +45,13 @@ errnoParser = re.compile(r'''
\(\*_errno\(\)\)
''', re.VERBOSE)
sinceEpochParser = re.compile(r'\d+ .+ since epoch')
infParser = re.compile(r'''
\(\(float\)\(1e\+300\ \*\ 1e\+300\)\) # MSVC INFINITY macro
|
\(__builtin_inff\(\)\) # Linux (ubuntu) INFINITY macro
|
__builtin_huge_valf\(\) # OSX macro
''', re.VERBOSE)
if len(sys.argv) == 2:
cmdPath = sys.argv[1]
@@ -102,6 +109,7 @@ def filterLine(line):
line = specialCaseParser.sub('file:\g<1>', line)
line = errnoParser.sub('errno', line)
line = sinceEpochParser.sub('{since-epoch-report}', line)
line = infParser.sub('INFINITY', line)
return line

View File

@@ -1,6 +1,6 @@
/*
* Catch v2.0.0-develop.6
* Generated: 2017-10-31 15:09:47.277913
* Catch v2.0.1
* Generated: 2017-11-03 11:53:39.642003
* ----------------------------------------------------------
* This file has been merged from multiple headers. Please don't edit it directly
* Copyright (c) 2017 Two Blue Cubes Ltd. All rights reserved.
@@ -1835,16 +1835,15 @@ namespace Catch {
do{ if( !(condition) ) CATCH_ERROR( msg ); } while(false)
// end catch_enforce.h
#include <cmath>
#include <type_traits>
namespace Catch {
namespace Detail {
double dmax(double lhs, double rhs);
class Approx {
private:
bool equalityComparisonImpl(double other) const;
public:
explicit Approx ( double value );
@@ -1865,14 +1864,8 @@ namespace Detail {
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
friend bool operator == ( const T& lhs, Approx const& rhs ) {
// Thanks to Richard Harris for his help refining this formula
auto lhs_v = static_cast<double>(lhs);
bool relativeOK = std::fabs(lhs_v - rhs.m_value) < rhs.m_epsilon * (rhs.m_scale +
dmax(std::fabs(lhs_v), std::fabs(rhs.m_value)));
if (relativeOK) {
return true;
}
return std::fabs(lhs_v - rhs.m_value) <= rhs.m_margin;
return rhs.equalityComparisonImpl(lhs_v);
}
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
@@ -1912,14 +1905,21 @@ namespace Detail {
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
Approx& epsilon( T const& newEpsilon ) {
m_epsilon = static_cast<double>(newEpsilon);
double epsilonAsDouble = static_cast<double>(newEpsilon);
CATCH_ENFORCE(epsilonAsDouble >= 0 && epsilonAsDouble <= 1.0,
"Invalid Approx::epsilon: " << epsilonAsDouble
<< ", Approx::epsilon has to be between 0 and 1");
m_epsilon = epsilonAsDouble;
return *this;
}
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
Approx& margin( T const& newMargin ) {
m_margin = static_cast<double>(newMargin);
CATCH_ENFORCE(m_margin >= 0, "Invalid Approx::margin: " << m_margin << ", Approx::Margin has to be non-negative.");
double marginAsDouble = static_cast<double>(newMargin);
CATCH_ENFORCE(marginAsDouble >= 0,
"Invalid Approx::margin: " << marginAsDouble
<< ", Approx::Margin has to be non-negative.");
m_margin = marginAsDouble;
return *this;
}
@@ -3980,22 +3980,26 @@ namespace Catch {
// Cpp files will be included in the single-header file here
// start catch_approx.cpp
#include <cmath>
#include <limits>
namespace {
// Performs equivalent check of std::fabs(lhs - rhs) <= margin
// But without the subtraction to allow for INFINITY in comparison
bool marginComparison(double lhs, double rhs, double margin) {
return (lhs + margin >= rhs) && (rhs + margin >= lhs);
}
}
namespace Catch {
namespace Detail {
double dmax(double lhs, double rhs) {
if (lhs < rhs) {
return rhs;
}
return lhs;
}
Approx::Approx ( double value )
: m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
m_margin( 0.0 ),
m_scale( 1.0 ),
m_scale( 0.0 ),
m_value( value )
{}
@@ -4009,6 +4013,12 @@ namespace Detail {
return oss.str();
}
bool Approx::equalityComparisonImpl(const double other) const {
// First try with fixed margin, then compute margin based on epsilon, scale and Approx's value
// Thanks to Richard Harris for his help refining the scaled margin value
return marginComparison(m_value, other, m_margin) || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(m_value)));
}
} // end namespace Detail
std::string StringMaker<Catch::Detail::Approx>::convert(Catch::Detail::Approx const& value) {
@@ -8055,6 +8065,7 @@ namespace Catch {
clara::Parser m_cli;
ConfigData m_configData;
std::shared_ptr<Config> m_config;
bool m_startupExceptions = false;
};
} // end namespace Catch
@@ -8186,8 +8197,26 @@ namespace Catch {
Session::Session() {
static bool alreadyInstantiated = false;
if( alreadyInstantiated )
CATCH_INTERNAL_ERROR( "Only one instance of Catch::Session can ever be used" );
if( alreadyInstantiated ) {
try { CATCH_INTERNAL_ERROR( "Only one instance of Catch::Session can ever be used" ); }
catch(...) { getMutableRegistryHub().registerStartupException(); }
}
const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions();
if ( !exceptions.empty() ) {
m_startupExceptions = true;
Colour colourGuard( Colour::Red );
Catch::cerr() << "Errors occured during startup!" << '\n';
// iterate over all exceptions and notify user
for ( const auto& ex_ptr : exceptions ) {
try {
std::rethrow_exception(ex_ptr);
} catch ( std::exception const& ex ) {
Catch::cerr() << Column( ex.what() ).indent(2) << '\n';
}
}
}
alreadyInstantiated = true;
m_cli = makeCommandLineParser( m_configData );
}
@@ -8210,6 +8239,9 @@ namespace Catch {
}
int Session::applyCommandLine( int argc, char* argv[] ) {
if( m_startupExceptions )
return 1;
auto result = m_cli.parse( clara::Args( argc, argv ) );
if( !result ) {
Catch::cerr()
@@ -8235,19 +8267,8 @@ namespace Catch {
}
int Session::run( int argc, char* argv[] ) {
const auto& exceptions = getRegistryHub().getStartupExceptionRegistry().getExceptions();
if ( !exceptions.empty() ) {
Catch::cerr() << "Errors occured during startup!" << '\n';
// iterate over all exceptions and notify user
for ( const auto& ex_ptr : exceptions ) {
try {
std::rethrow_exception(ex_ptr);
} catch ( std::exception const& ex ) {
Catch::cerr() << ex.what() << '\n';
}
}
if( m_startupExceptions )
return 1;
}
int returnCode = applyCommandLine( argc, argv );
if( returnCode == 0 )
returnCode = run();
@@ -8306,6 +8327,9 @@ namespace Catch {
}
int Session::runInternal() {
if( m_startupExceptions )
return 1;
if( m_configData.showHelp || m_configData.libIdentify )
return 0;
@@ -9802,7 +9826,7 @@ namespace Catch {
}
Version const& libraryVersion() {
static Version version( 2, 0, 0, "develop", 6 );
static Version version( 2, 0, 1, "", 0 );
return version;
}

View File

@@ -10,7 +10,7 @@ class CatchConanTest(ConanFile):
settings = "os", "compiler", "arch", "build_type"
username = getenv("CONAN_USERNAME", "philsquared")
channel = getenv("CONAN_CHANNEL", "testing")
requires = "Catch/2.0.0-develop.6@%s/%s" % (username, channel)
requires = "Catch/2.0.1@%s/%s" % (username, channel)
def build(self):
cmake = CMake(self)