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

Merge branch 'v3' into issue-357

# Changelog # Changelog
### 3.5.9 (WIP)
* Update Node deps.
### 3.5.8 ### 3.5.8
* Enable `UV_UDP_RECVMMSG`: * Enable `UV_UDP_RECVMMSG`:
......
...@@ -56,20 +56,20 @@ ...@@ -56,20 +56,20 @@
"uuid": "^7.0.3" "uuid": "^7.0.3"
}, },
"devDependencies": { "devDependencies": {
"@types/node": "^13.13.0", "@types/node": "^13.13.2",
"@types/random-number": "0.0.0", "@types/random-number": "0.0.0",
"@types/uuid": "^7.0.2", "@types/uuid": "^7.0.2",
"@typescript-eslint/eslint-plugin": "^2.28.0", "@typescript-eslint/eslint-plugin": "^2.29.0",
"@typescript-eslint/parser": "^2.28.0", "@typescript-eslint/parser": "^2.29.0",
"cross-env": "^7.0.2", "cross-env": "^7.0.2",
"eslint": "^6.8.0", "eslint": "^6.8.0",
"eslint-plugin-jest": "^23.8.2", "eslint-plugin-jest": "^23.8.2",
"gulp": "^4.0.2", "gulp": "^4.0.2",
"gulp-clang-format": "^1.0.27", "gulp-clang-format": "^1.0.27",
"jest": "^25.3.0", "jest": "^25.4.0",
"jest-tobetype": "^1.2.3", "jest-tobetype": "^1.2.3",
"open-cli": "^6.0.1", "open-cli": "^6.0.1",
"sctp": "^0.0.19", "sctp": "^0.0.20",
"tsc-watch": "^4.2.3", "tsc-watch": "^4.2.3",
"typescript": "^3.8.3" "typescript": "^3.8.3"
}, },
......
...@@ -14,7 +14,7 @@ if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) ...@@ -14,7 +14,7 @@ if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
endif() endif()
project(Catch2 LANGUAGES CXX VERSION 2.11.3) project(Catch2 LANGUAGES CXX VERSION 2.12.1)
# Provide path for scripts # Provide path for scripts
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake")
......
...@@ -5,11 +5,11 @@ ...@@ -5,11 +5,11 @@
[![Build Status](https://travis-ci.org/catchorg/Catch2.svg?branch=master)](https://travis-ci.org/catchorg/Catch2) [![Build Status](https://travis-ci.org/catchorg/Catch2.svg?branch=master)](https://travis-ci.org/catchorg/Catch2)
[![Build status](https://ci.appveyor.com/api/projects/status/github/catchorg/Catch2?svg=true)](https://ci.appveyor.com/project/catchorg/catch2) [![Build status](https://ci.appveyor.com/api/projects/status/github/catchorg/Catch2?svg=true)](https://ci.appveyor.com/project/catchorg/catch2)
[![codecov](https://codecov.io/gh/catchorg/Catch2/branch/master/graph/badge.svg)](https://codecov.io/gh/catchorg/Catch2) [![codecov](https://codecov.io/gh/catchorg/Catch2/branch/master/graph/badge.svg)](https://codecov.io/gh/catchorg/Catch2)
[![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/p9Pcgple8QWwgNR0) [![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/DQL97fLLJLZXwB8d)
[![Join the chat in Discord: https://discord.gg/4CWS9zD](https://img.shields.io/badge/Discord-Chat!-brightgreen.svg)](https://discord.gg/4CWS9zD) [![Join the chat in Discord: https://discord.gg/4CWS9zD](https://img.shields.io/badge/Discord-Chat!-brightgreen.svg)](https://discord.gg/4CWS9zD)
<a href="https://github.com/catchorg/Catch2/releases/download/v2.11.3/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.12.1/catch.hpp">The latest version of the single header can be downloaded directly using this link</a>
## Catch2 is released! ## Catch2 is released!
......
...@@ -144,7 +144,7 @@ function(ParseAndAddCatchTests_ParseFile SourceFile TestTarget) ...@@ -144,7 +144,7 @@ function(ParseAndAddCatchTests_ParseFile SourceFile TestTarget)
if("${TestType}" STREQUAL "SCENARIO") if("${TestType}" STREQUAL "SCENARIO")
set(Name "Scenario: ${Name}") set(Name "Scenario: ${Name}")
endif() endif()
if(PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME AND TestFixture) if(PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME AND "${TestType}" MATCHES "(CATCH_)?TEST_CASE_METHOD" AND TestFixture )
set(CTestName "${TestFixture}:${Name}") set(CTestName "${TestFixture}:${Name}")
else() else()
set(CTestName "${Name}") set(CTestName "${Name}")
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
[Automatic test registration](#automatic-test-registration)<br> [Automatic test registration](#automatic-test-registration)<br>
[CMake project options](#cmake-project-options)<br> [CMake project options](#cmake-project-options)<br>
[Installing Catch2 from git repository](#installing-catch2-from-git-repository)<br> [Installing Catch2 from git repository](#installing-catch2-from-git-repository)<br>
[Installing Catch2 from vcpkg](#installing-catch2-from-vcpkg)<br>
Because we use CMake to build Catch2, we also provide a couple of Because we use CMake to build Catch2, we also provide a couple of
integration points for our users. integration points for our users.
...@@ -220,6 +221,19 @@ when configuring the build, and then modify your calls to ...@@ -220,6 +221,19 @@ when configuring the build, and then modify your calls to
[find_package](https://cmake.org/cmake/help/latest/command/find_package.html) [find_package](https://cmake.org/cmake/help/latest/command/find_package.html)
accordingly. accordingly.
## Installing Catch2 from vcpkg
Alternatively, you can build and install Catch2 using [vcpkg](https://github.com/microsoft/vcpkg/) dependency manager:
```
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg integrate install
./vcpkg install catch2
```
The catch2 port in vcpkg is kept up to date by microsoft team members and community contributors.
If the version is out of date, please [create an issue or pull request](https://github.com/Microsoft/vcpkg) on the vcpkg repository.
--- ---
......
...@@ -243,15 +243,25 @@ This option lists all available tests in a non-indented form, one on each line. ...@@ -243,15 +243,25 @@ This option lists all available tests in a non-indented form, one on each line.
Test cases are ordered one of three ways: Test cases are ordered one of three ways:
### decl ### decl
Declaration order (this is the default order if no --order argument is provided). The order the tests were originally declared in. Note that ordering between files is not guaranteed and is implementation dependent. Declaration order (this is the default order if no --order argument is provided).
Tests in the same TU are sorted using their declaration orders, different
TUs are in an implementation (linking) dependent order.
### lex ### lex
Lexicographically sorted. Tests are sorted, alpha-numerically, by name. Lexicographic order. Tests are sorted by their name, their tags are ignored.
### rand ### rand
Randomly sorted. Test names are sorted using ```std::random_shuffle()```. By default the random number generator is seeded with 0 - and so the order is repeatable. To control the random seed see <a href="#rng-seed">rng-seed</a>.
Randomly sorted. The order is dependent on Catch2's random seed (see
[`--rng-seed`](#rng-seed)), and is subset invariant. What this means
is that as long as the random seed is fixed, running only some tests
(e.g. via tag) does not change their relative order.
> The subset stability was introduced in Catch2 v2.12.0
<a id="rng-seed"></a> <a id="rng-seed"></a>
## Specify a seed for the Random Number Generator ## Specify a seed for the Random Number Generator
......
...@@ -20,18 +20,21 @@ Listing a project here does not imply endorsement and the plan is to keep these ...@@ -20,18 +20,21 @@ Listing a project here does not imply endorsement and the plan is to keep these
### [ApprovalTests.cpp](https://github.com/approvals/ApprovalTests.cpp) ### [ApprovalTests.cpp](https://github.com/approvals/ApprovalTests.cpp)
C++11 implementation of Approval Tests, for quick, convenient testing of legacy code. C++11 implementation of Approval Tests, for quick, convenient testing of legacy code.
### [args](https://github.com/Taywee/args)
A simple header-only C++ argument parser library.
### [Azmq](https://github.com/zeromq/azmq) ### [Azmq](https://github.com/zeromq/azmq)
Boost Asio style bindings for ZeroMQ. Boost Asio style bindings for ZeroMQ.
### [Cataclysm: Dark Days Ahead](https://github.com/CleverRaven/Cataclysm-DDA) ### [Cataclysm: Dark Days Ahead](https://github.com/CleverRaven/Cataclysm-DDA)
Post-apocalyptic survival RPG. Post-apocalyptic survival RPG.
### [ChakraCore](https://github.com/Microsoft/ChakraCore)
The core part of the Chakra JavaScript engine that powers Microsoft Edge.
### [ChaiScript](https://github.com/ChaiScript/ChaiScript) ### [ChaiScript](https://github.com/ChaiScript/ChaiScript)
A, header-only, embedded scripting language designed from the ground up to directly target C++ and take advantage of modern C++ development techniques. A, header-only, embedded scripting language designed from the ground up to directly target C++ and take advantage of modern C++ development techniques.
### [ChakraCore](https://github.com/Microsoft/ChakraCore)
The core part of the Chakra JavaScript engine that powers Microsoft Edge.
### [Clara](https://github.com/philsquared/Clara) ### [Clara](https://github.com/philsquared/Clara)
A, single-header-only, type-safe, command line parser - which also prints formatted usage strings. A, single-header-only, type-safe, command line parser - which also prints formatted usage strings.
...@@ -65,9 +68,6 @@ A small C++ library wrapper for the native C ODBC API. ...@@ -65,9 +68,6 @@ A small C++ library wrapper for the native C ODBC API.
### [Nonius](https://github.com/libnonius/nonius) ### [Nonius](https://github.com/libnonius/nonius)
A header-only framework for benchmarking small snippets of C++ code. A header-only framework for benchmarking small snippets of C++ code.
### [SOCI](https://github.com/SOCI/soci)
The C++ Database Access Library.
### [polymorphic_value](https://github.com/jbcoe/polymorphic_value) ### [polymorphic_value](https://github.com/jbcoe/polymorphic_value)
A polymorphic value-type for C++. A polymorphic value-type for C++.
...@@ -77,18 +77,21 @@ A C++ client library for Consul. Consul is a distributed tool for discovering an ...@@ -77,18 +77,21 @@ A C++ client library for Consul. Consul is a distributed tool for discovering an
### [Reactive-Extensions/ RxCpp](https://github.com/Reactive-Extensions/RxCpp) ### [Reactive-Extensions/ RxCpp](https://github.com/Reactive-Extensions/RxCpp)
A library of algorithms for values-distributed-in-time. A library of algorithms for values-distributed-in-time.
### [thor](https://github.com/xorz57/thor) ### [SOCI](https://github.com/SOCI/soci)
Wrapper Library for CUDA. The C++ Database Access Library.
### [TextFlowCpp](https://github.com/philsquared/textflowcpp) ### [TextFlowCpp](https://github.com/philsquared/textflowcpp)
A small, single-header-only, library for wrapping and composing columns of text. A small, single-header-only, library for wrapping and composing columns of text.
### [thor](https://github.com/xorz57/thor)
Wrapper Library for CUDA.
### [toml++](https://github.com/marzer/tomlplusplus)
A header-only TOML parser and serializer for modern C++.
### [Trompeloeil](https://github.com/rollbear/trompeloeil) ### [Trompeloeil](https://github.com/rollbear/trompeloeil)
A thread-safe header-only mocking framework for C++14. A thread-safe header-only mocking framework for C++14.
### [args](https://github.com/Taywee/args)
A simple header-only C++ argument parser library.
## Applications & Tools ## Applications & Tools
### [ArangoDB](https://github.com/arangodb/arangodb) ### [ArangoDB](https://github.com/arangodb/arangodb)
...@@ -103,6 +106,9 @@ MAME originally stood for Multiple Arcade Machine Emulator. ...@@ -103,6 +106,9 @@ MAME originally stood for Multiple Arcade Machine Emulator.
### [Newsbeuter](https://github.com/akrennmair/newsbeuter) ### [Newsbeuter](https://github.com/akrennmair/newsbeuter)
Newsbeuter is an open-source RSS/Atom feed reader for text terminals. Newsbeuter is an open-source RSS/Atom feed reader for text terminals.
### [PopHead](https://github.com/SPC-Some-Polish-Coders/PopHead)
A 2D, Zombie, RPG game which is being made on our own engine.
### [raspigcd](https://github.com/pantadeusz/raspigcd) ### [raspigcd](https://github.com/pantadeusz/raspigcd)
Low level CLI app and library for execution of GCODE on Raspberry Pi without any additional microcontrolers (just RPi + Stepsticks). Low level CLI app and library for execution of GCODE on Raspberry Pi without any additional microcontrolers (just RPi + Stepsticks).
...@@ -112,9 +118,6 @@ SpECTRE is a code for multi-scale, multi-physics problems in astrophysics and gr ...@@ -112,9 +118,6 @@ SpECTRE is a code for multi-scale, multi-physics problems in astrophysics and gr
### [Standardese](https://github.com/foonathan/standardese) ### [Standardese](https://github.com/foonathan/standardese)
Standardese aims to be a nextgen Doxygen. Standardese aims to be a nextgen Doxygen.
### [PopHead](https://github.com/SPC-Some-Polish-Coders/PopHead)
A 2D, Zombie, RPG game which is being made on our own engine.
--- ---
[Home](Readme.md#top) [Home](Readme.md#top)
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
# Release notes # Release notes
**Contents**<br> **Contents**<br>
[2.12.1](#2121)<br>
[2.12.0](#2120)<br>
[2.11.3](#2113)<br> [2.11.3](#2113)<br>
[2.11.2](#2112)<br> [2.11.2](#2112)<br>
[2.11.1](#2111)<br> [2.11.1](#2111)<br>
...@@ -34,6 +36,37 @@ ...@@ -34,6 +36,37 @@
[Older versions](#older-versions)<br> [Older versions](#older-versions)<br>
[Even Older versions](#even-older-versions)<br> [Even Older versions](#even-older-versions)<br>
## 2.12.1
### Fixes
* Vector matchers now support initializer list literals better
### Improvements
* Added support for `^` (bitwise xor) to `CHECK` and `REQUIRE`
## 2.12.0
### Improvements
* Running tests in random order (`--order rand`) has been reworked significantly (#1908)
* Given same seed, all platforms now produce the same order
* Given same seed, the relative order of tests does not change if you select only a subset of them
* Vector matchers support custom allocators (#1909)
* `|` and `&` (bitwise or and bitwise and) are now supported in `CHECK` and `REQUIRE`
* The resulting type must be convertible to `bool`
### Fixes
* Fixed computation of benchmarking column widths in ConsoleReporter (#1885, #1886)
* Suppressed clang-tidy's `cppcoreguidelines-pro-type-vararg` in assertions (#1901)
* It was a false positive trigered by the new warning support workaround
* Fixed bug in test specification parser handling of OR'd patterns using escaping (#1905)
### Miscellaneous
* Worked around IBM XL's codegen bug (#1907)
* It would emit code for _destructors_ of temporaries in an unevaluated context
* Improved detection of stdlib's support for `std::uncaught_exceptions` (#1911)
## 2.11.3 ## 2.11.3
### Fixes ### Fixes
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
#define TWOBLUECUBES_CATCH_HPP_INCLUDED #define TWOBLUECUBES_CATCH_HPP_INCLUDED
#define CATCH_VERSION_MAJOR 2 #define CATCH_VERSION_MAJOR 2
#define CATCH_VERSION_MINOR 11 #define CATCH_VERSION_MINOR 12
#define CATCH_VERSION_PATCH 3 #define CATCH_VERSION_PATCH 1
#ifdef __clang__ #ifdef __clang__
# pragma clang system_header # pragma clang system_header
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "catch_interfaces_registry_hub.h" #include "catch_interfaces_registry_hub.h"
#include "catch_capture_matchers.h" #include "catch_capture_matchers.h"
#include "catch_run_context.h" #include "catch_run_context.h"
#include "catch_enforce.h"
namespace Catch { namespace Catch {
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
#endif #endif
#if defined(CATCH_CPP17_OR_GREATER) #if defined(__cpp_lib_uncaught_exceptions)
# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
#endif #endif
...@@ -58,7 +58,20 @@ ...@@ -58,7 +58,20 @@
# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" ) # define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" )
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" ) # define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" )
# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) // As of this writing, IBM XL's implementation of __builtin_constant_p has a bug
// which results in calls to destructors being emitted for each temporary,
// without a matching initialization. In practice, this can result in something
// like `std::string::~string` being called on an uninitialized value.
//
// For example, this code will likely segfault under IBM XL:
// ```
// REQUIRE(std::string("12") + "34" == "1234")
// ```
//
// Therefore, `CATCH_INTERNAL_IGNORE_BUT_WARN` is not implemented.
# if !defined(__ibmxl__)
# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) /* NOLINT(cppcoreguidelines-pro-type-vararg) */
# endif
# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
......
...@@ -14,8 +14,7 @@ ...@@ -14,8 +14,7 @@
#if defined(CATCH_PLATFORM_MAC) || defined(CATCH_PLATFORM_IPHONE) #if defined(CATCH_PLATFORM_MAC) || defined(CATCH_PLATFORM_IPHONE)
# include <assert.h> # include <cassert>
# include <stdbool.h>
# include <sys/types.h> # include <sys/types.h>
# include <unistd.h> # include <unistd.h>
# include <cstddef> # include <cstddef>
......
...@@ -200,6 +200,18 @@ namespace Catch { ...@@ -200,6 +200,18 @@ namespace Catch {
auto operator <= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const { auto operator <= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
return { static_cast<bool>(m_lhs <= rhs), m_lhs, "<=", rhs }; return { static_cast<bool>(m_lhs <= rhs), m_lhs, "<=", rhs };
} }
template <typename RhsT>
auto operator | (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const {
return { static_cast<bool>(m_lhs | rhs), m_lhs, "|", rhs };
}
template <typename RhsT>
auto operator & (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const {
return { static_cast<bool>(m_lhs & rhs), m_lhs, "&", rhs };
}
template <typename RhsT>
auto operator ^ (RhsT const& rhs) -> BinaryExpr<LhsT, RhsT const&> const {
return { static_cast<bool>(m_lhs ^ rhs), m_lhs, "^", rhs };
}
template<typename RhsT> template<typename RhsT>
auto operator && ( RhsT const& ) -> BinaryExpr<LhsT, RhsT const&> const { auto operator && ( RhsT const& ) -> BinaryExpr<LhsT, RhsT const&> const {
......
...@@ -46,6 +46,9 @@ namespace Catch { ...@@ -46,6 +46,9 @@ namespace Catch {
{} {}
std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override { std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override {
#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
return "";
#else
try { try {
if( it == itEnd ) if( it == itEnd )
std::rethrow_exception(std::current_exception()); std::rethrow_exception(std::current_exception());
...@@ -55,6 +58,7 @@ namespace Catch { ...@@ -55,6 +58,7 @@ namespace Catch {
catch( T& ex ) { catch( T& ex ) {
return m_translateFunction( ex ); return m_translateFunction( ex );
} }
#endif
} }
protected: protected:
......
...@@ -17,12 +17,12 @@ namespace Catch { ...@@ -17,12 +17,12 @@ namespace Catch {
namespace Matchers { namespace Matchers {
namespace Vector { namespace Vector {
template<typename T> template<typename T, typename Alloc>
struct ContainsElementMatcher : MatcherBase<std::vector<T>> { struct ContainsElementMatcher : MatcherBase<std::vector<T, Alloc>> {
ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {} ContainsElementMatcher(T const &comparator) : m_comparator( comparator) {}
bool match(std::vector<T> const &v) const override { bool match(std::vector<T, Alloc> const &v) const override {
for (auto const& el : v) { for (auto const& el : v) {
if (el == m_comparator) { if (el == m_comparator) {
return true; return true;
...@@ -38,12 +38,12 @@ namespace Matchers { ...@@ -38,12 +38,12 @@ namespace Matchers {
T const& m_comparator; T const& m_comparator;
}; };
template<typename T> template<typename T, typename AllocComp, typename AllocMatch>
struct ContainsMatcher : MatcherBase<std::vector<T>> { struct ContainsMatcher : MatcherBase<std::vector<T, AllocMatch>> {
ContainsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {} ContainsMatcher(std::vector<T, AllocComp> const &comparator) : m_comparator( comparator ) {}
bool match(std::vector<T> const &v) const override { bool match(std::vector<T, AllocMatch> const &v) const override {
// !TBD: see note in EqualsMatcher // !TBD: see note in EqualsMatcher
if (m_comparator.size() > v.size()) if (m_comparator.size() > v.size())
return false; return false;
...@@ -65,18 +65,18 @@ namespace Matchers { ...@@ -65,18 +65,18 @@ namespace Matchers {
return "Contains: " + ::Catch::Detail::stringify( m_comparator ); return "Contains: " + ::Catch::Detail::stringify( m_comparator );
} }
std::vector<T> const& m_comparator; std::vector<T, AllocComp> const& m_comparator;
}; };
template<typename T> template<typename T, typename AllocComp, typename AllocMatch>
struct EqualsMatcher : MatcherBase<std::vector<T>> { struct EqualsMatcher : MatcherBase<std::vector<T, AllocMatch>> {
EqualsMatcher(std::vector<T> const &comparator) : m_comparator( comparator ) {} EqualsMatcher(std::vector<T, AllocComp> const &comparator) : m_comparator( comparator ) {}
bool match(std::vector<T> const &v) const override { bool match(std::vector<T, AllocMatch> const &v) const override {
// !TBD: This currently works if all elements can be compared using != // !TBD: This currently works if all elements can be compared using !=
// - a more general approach would be via a compare template that defaults // - a more general approach would be via a compare template that defaults
// to using !=. but could be specialised for, e.g. std::vector<T> etc // to using !=. but could be specialised for, e.g. std::vector<T, Alloc> etc
// - then just call that directly // - then just call that directly
if (m_comparator.size() != v.size()) if (m_comparator.size() != v.size())
return false; return false;
...@@ -88,15 +88,15 @@ namespace Matchers { ...@@ -88,15 +88,15 @@ namespace Matchers {
std::string describe() const override { std::string describe() const override {
return "Equals: " + ::Catch::Detail::stringify( m_comparator ); return "Equals: " + ::Catch::Detail::stringify( m_comparator );
} }
std::vector<T> const& m_comparator; std::vector<T, AllocComp> const& m_comparator;
}; };
template<typename T> template<typename T, typename AllocComp, typename AllocMatch>
struct ApproxMatcher : MatcherBase<std::vector<T>> { struct ApproxMatcher : MatcherBase<std::vector<T, AllocMatch>> {
ApproxMatcher(std::vector<T> const& comparator) : m_comparator( comparator ) {} ApproxMatcher(std::vector<T, AllocComp> const& comparator) : m_comparator( comparator ) {}
bool match(std::vector<T> const &v) const override { bool match(std::vector<T, AllocMatch> const &v) const override {
if (m_comparator.size() != v.size()) if (m_comparator.size() != v.size())
return false; return false;
for (std::size_t i = 0; i < v.size(); ++i) for (std::size_t i = 0; i < v.size(); ++i)
...@@ -123,14 +123,14 @@ namespace Matchers { ...@@ -123,14 +123,14 @@ namespace Matchers {
return *this; return *this;
} }
std::vector<T> const& m_comparator; std::vector<T, AllocComp> const& m_comparator;
mutable Catch::Detail::Approx approx = Catch::Detail::Approx::custom(); mutable Catch::Detail::Approx approx = Catch::Detail::Approx::custom();
}; };
template<typename T> template<typename T, typename AllocComp, typename AllocMatch>
struct UnorderedEqualsMatcher : MatcherBase<std::vector<T>> { struct UnorderedEqualsMatcher : MatcherBase<std::vector<T, AllocMatch>> {
UnorderedEqualsMatcher(std::vector<T> const& target) : m_target(target) {} UnorderedEqualsMatcher(std::vector<T, AllocComp> const& target) : m_target(target) {}
bool match(std::vector<T> const& vec) const override { bool match(std::vector<T, AllocMatch> const& vec) const override {
// Note: This is a reimplementation of std::is_permutation, // Note: This is a reimplementation of std::is_permutation,
// because I don't want to include <algorithm> inside the common path // because I don't want to include <algorithm> inside the common path
if (m_target.size() != vec.size()) { if (m_target.size() != vec.size()) {
...@@ -143,7 +143,7 @@ namespace Matchers { ...@@ -143,7 +143,7 @@ namespace Matchers {
return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target); return "UnorderedEquals: " + ::Catch::Detail::stringify(m_target);
} }
private: private:
std::vector<T> const& m_target; std::vector<T, AllocComp> const& m_target;
}; };
} // namespace Vector } // namespace Vector
...@@ -151,29 +151,29 @@ namespace Matchers { ...@@ -151,29 +151,29 @@ namespace Matchers {
// The following functions create the actual matcher objects. // The following functions create the actual matcher objects.
// This allows the types to be inferred // This allows the types to be inferred
template<typename T> template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
Vector::ContainsMatcher<T> Contains( std::vector<T> const& comparator ) { Vector::ContainsMatcher<T, AllocComp, AllocMatch> Contains( std::vector<T, AllocComp> const& comparator ) {
return Vector::ContainsMatcher<T>( comparator ); return Vector::ContainsMatcher<T, AllocComp, AllocMatch>( comparator );
} }
template<typename T> template<typename T, typename Alloc = std::allocator<T>>
Vector::ContainsElementMatcher<T> VectorContains( T const& comparator ) { Vector::ContainsElementMatcher<T, Alloc> VectorContains( T const& comparator ) {
return Vector::ContainsElementMatcher<T>( comparator ); return Vector::ContainsElementMatcher<T, Alloc>( comparator );
} }
template<typename T> template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
Vector::EqualsMatcher<T> Equals( std::vector<T> const& comparator ) { Vector::EqualsMatcher<T, AllocComp, AllocMatch> Equals( std::vector<T, AllocComp> const& comparator ) {
return Vector::EqualsMatcher<T>( comparator ); return Vector::EqualsMatcher<T, AllocComp, AllocMatch>( comparator );
} }
template<typename T> template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
Vector::ApproxMatcher<T> Approx( std::vector<T> const& comparator ) { Vector::ApproxMatcher<T, AllocComp, AllocMatch> Approx( std::vector<T, AllocComp> const& comparator ) {
return Vector::ApproxMatcher<T>( comparator ); return Vector::ApproxMatcher<T, AllocComp, AllocMatch>( comparator );
} }
template<typename T> template<typename T, typename AllocComp = std::allocator<T>, typename AllocMatch = AllocComp>
Vector::UnorderedEqualsMatcher<T> UnorderedEquals(std::vector<T> const& target) { Vector::UnorderedEqualsMatcher<T, AllocComp, AllocMatch> UnorderedEquals(std::vector<T, AllocComp> const& target) {
return Vector::UnorderedEqualsMatcher<T>(target); return Vector::UnorderedEqualsMatcher<T, AllocComp, AllocMatch>( target );
} }
} // namespace Matchers } // namespace Matchers
......
...@@ -15,28 +15,79 @@ ...@@ -15,28 +15,79 @@
#include "catch_string_manip.h" #include "catch_string_manip.h"
#include "catch_test_case_info.h" #include "catch_test_case_info.h"
#include <algorithm>
#include <sstream> #include <sstream>
namespace Catch { namespace Catch {
std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) { namespace {
struct TestHasher {
explicit TestHasher(Catch::SimplePcg32& rng) {
basis = rng();
basis <<= 32;
basis |= rng();
}
std::vector<TestCase> sorted = unsortedTestCases; uint64_t basis;
uint64_t operator()(TestCase const& t) const {
// Modified FNV-1a hash
static constexpr uint64_t prime = 1099511628211;
uint64_t hash = basis;
for (const char c : t.name) {
hash ^= c;
hash *= prime;
}
return hash;
}
};
} // end unnamed namespace
std::vector<TestCase> sortTests( IConfig const& config, std::vector<TestCase> const& unsortedTestCases ) {
switch( config.runOrder() ) { switch( config.runOrder() ) {
case RunTests::InLexicographicalOrder:
std::sort( sorted.begin(), sorted.end() );
break;
case RunTests::InRandomOrder:
seedRng( config );
std::shuffle( sorted.begin(), sorted.end(), rng() );
break;
case RunTests::InDeclarationOrder: case RunTests::InDeclarationOrder:
// already in declaration order // already in declaration order
break; break;
case RunTests::InLexicographicalOrder: {
std::vector<TestCase> sorted = unsortedTestCases;
std::sort( sorted.begin(), sorted.end() );
return sorted;
}
case RunTests::InRandomOrder: {
seedRng( config );
TestHasher h( rng() );
using hashedTest = std::pair<uint64_t, TestCase const*>;
std::vector<hashedTest> indexed_tests;
indexed_tests.reserve( unsortedTestCases.size() );
for (auto const& testCase : unsortedTestCases) {
indexed_tests.emplace_back(h(testCase), &testCase);
}
std::sort(indexed_tests.begin(), indexed_tests.end(),
[](hashedTest const& lhs, hashedTest const& rhs) {
if (lhs.first == rhs.first) {
return lhs.second->name < rhs.second->name;
}
return lhs.first < rhs.first;
});
std::vector<TestCase> sorted;
sorted.reserve( indexed_tests.size() );
for (auto const& hashed : indexed_tests) {
sorted.emplace_back(*hashed.second);
} }
return sorted; return sorted;
} }
}
return unsortedTestCases;
}
bool isThrowSafe( TestCase const& testCase, IConfig const& config ) { bool isThrowSafe( TestCase const& testCase, IConfig const& config ) {
return !testCase.throws() || config.allowThrows(); return !testCase.throws() || config.allowThrows();
......
...@@ -168,6 +168,7 @@ namespace Catch { ...@@ -168,6 +168,7 @@ namespace Catch {
m_pos = m_arg.size(); m_pos = m_arg.size();
m_substring.clear(); m_substring.clear();
m_patternName.clear(); m_patternName.clear();
m_realPatternPos = 0;
return false; return false;
} }
endMode(); endMode();
...@@ -186,6 +187,7 @@ namespace Catch { ...@@ -186,6 +187,7 @@ namespace Catch {
} }
m_patternName.clear(); m_patternName.clear();
m_realPatternPos = 0;
return token; return token;
} }
......
...@@ -37,7 +37,7 @@ namespace Catch { ...@@ -37,7 +37,7 @@ namespace Catch {
} }
Version const& libraryVersion() { Version const& libraryVersion() {
static Version version( 2, 11, 3, "", 0 ); static Version version( 2, 12, 1, "", 0 );
return version; return version;
} }
......
...@@ -362,7 +362,7 @@ ConsoleReporter::ConsoleReporter(ReporterConfig const& config) ...@@ -362,7 +362,7 @@ ConsoleReporter::ConsoleReporter(ReporterConfig const& config)
else else
{ {
return{ return{
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 32, ColumnInfo::Left }, { "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH - 43, ColumnInfo::Left },
{ "samples mean std dev", 14, ColumnInfo::Right }, { "samples mean std dev", 14, ColumnInfo::Right },
{ "iterations low mean low std dev", 14, ColumnInfo::Right }, { "iterations low mean low std dev", 14, ColumnInfo::Right },
{ "estimated high mean high std dev", 14, ColumnInfo::Right } { "estimated high mean high std dev", 14, ColumnInfo::Right }
......
...@@ -451,6 +451,8 @@ set_tests_properties(TestsInFile::InvalidTestNames-1 PROPERTIES PASS_REGULAR_EXP ...@@ -451,6 +451,8 @@ set_tests_properties(TestsInFile::InvalidTestNames-1 PROPERTIES PASS_REGULAR_EXP
add_test(NAME TestsInFile::InvalidTestNames-2 COMMAND $<TARGET_FILE:SelfTest> "-f ${CATCH_DIR}/projects/SelfTest/Misc/invalid-test-names.input") add_test(NAME TestsInFile::InvalidTestNames-2 COMMAND $<TARGET_FILE:SelfTest> "-f ${CATCH_DIR}/projects/SelfTest/Misc/invalid-test-names.input")
set_tests_properties(TestsInFile::InvalidTestNames-2 PROPERTIES PASS_REGULAR_EXPRESSION "No tests ran") set_tests_properties(TestsInFile::InvalidTestNames-2 PROPERTIES PASS_REGULAR_EXPRESSION "No tests ran")
add_test(NAME RandomTestOrdering COMMAND ${PYTHON_EXECUTABLE}
${CATCH_DIR}/projects/TestScripts/testRandomOrder.py $<TARGET_FILE:SelfTest>)
if (CATCH_USE_VALGRIND) if (CATCH_USE_VALGRIND)
add_test(NAME ValgrindRunTests COMMAND valgrind --leak-check=full --error-exitcode=1 $<TARGET_FILE:SelfTest>) add_test(NAME ValgrindRunTests COMMAND valgrind --leak-check=full --error-exitcode=1 $<TARGET_FILE:SelfTest>)
......
...@@ -123,7 +123,7 @@ add_test(NAME BenchmarkingMacros COMMAND BenchmarkingMacros -r console -s) ...@@ -123,7 +123,7 @@ add_test(NAME BenchmarkingMacros COMMAND BenchmarkingMacros -r console -s)
set_tests_properties( set_tests_properties(
BenchmarkingMacros BenchmarkingMacros
PROPERTIES PROPERTIES
PASS_REGULAR_EXPRESSION "benchmark name samples iterations estimated" PASS_REGULAR_EXPRESSION "benchmark name[\\r\\n\\t ]+samples[\\r\\n\\t ]+iterations[\\r\\n\\t ]+estimated"
) )
# This test touches windows.h, so it should only be compiled under msvc # This test touches windows.h, so it should only be compiled under msvc
......
...@@ -23,6 +23,13 @@ This would not be caught previously ...@@ -23,6 +23,13 @@ This would not be caught previously
Nor would this Nor would this
Tricky.tests.cpp:<line number>: failed: explicitly with 1 message: '1514' Tricky.tests.cpp:<line number>: failed: explicitly with 1 message: '1514'
Compilation.tests.cpp:<line number>: passed: std::is_same<TypeList<int>, TypeList<int>>::value for: true Compilation.tests.cpp:<line number>: passed: std::is_same<TypeList<int>, TypeList<int>>::value for: true
CmdLine.tests.cpp:<line number>: passed: spec.matches(fakeTestCase("spec . char")) for: true
CmdLine.tests.cpp:<line number>: passed: spec.matches(fakeTestCase("spec , char")) for: true
CmdLine.tests.cpp:<line number>: passed: !(spec.matches(fakeTestCase(R"(spec \, char)"))) for: !false
CmdLine.tests.cpp:<line number>: passed: spec.matches(fakeTestCase(R"(spec {a} char)")) for: true
CmdLine.tests.cpp:<line number>: passed: spec.matches(fakeTestCase(R"(spec [a] char)")) for: true
CmdLine.tests.cpp:<line number>: passed: !(spec.matches(fakeTestCase("differs but has similar tag", "[a]"))) for: !false
CmdLine.tests.cpp:<line number>: passed: spec.matches(fakeTestCase(R"(spec \ char)")) for: true
Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'answer := 42' with 1 message: 'expected exception' Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'answer := 42' with 1 message: 'expected exception'
Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'answer := 42'; expression was: thisThrows() with 1 message: 'expected exception' Exception.tests.cpp:<line number>: failed: unexpected exception with message: 'answer := 42'; expression was: thisThrows() with 1 message: 'expected exception'
Exception.tests.cpp:<line number>: passed: thisThrows() with 1 message: 'answer := 42' Exception.tests.cpp:<line number>: passed: thisThrows() with 1 message: 'answer := 42'
...@@ -237,6 +244,11 @@ Matchers.tests.cpp:<line number>: passed: 1, Predicate<int>(alwaysTrue, "always ...@@ -237,6 +244,11 @@ Matchers.tests.cpp:<line number>: passed: 1, Predicate<int>(alwaysTrue, "always
Matchers.tests.cpp:<line number>: passed: 1, !Predicate<int>(alwaysFalse, "always false") for: 1 not matches predicate: "always false" Matchers.tests.cpp:<line number>: passed: 1, !Predicate<int>(alwaysFalse, "always false") for: 1 not matches predicate: "always false"
Matchers.tests.cpp:<line number>: passed: "Hello olleH", Predicate<std::string>( [] (std::string const& str) -> bool { return str.front() == str.back(); }, "First and last character should be equal") for: "Hello olleH" matches predicate: "First and last character should be equal" Matchers.tests.cpp:<line number>: passed: "Hello olleH", Predicate<std::string>( [] (std::string const& str) -> bool { return str.front() == str.back(); }, "First and last character should be equal") for: "Hello olleH" matches predicate: "First and last character should be equal"
Matchers.tests.cpp:<line number>: passed: "This wouldn't pass", !Predicate<std::string>( [] (std::string const& str) -> bool { return str.front() == str.back(); } ) for: "This wouldn't pass" not matches undescribed predicate Matchers.tests.cpp:<line number>: passed: "This wouldn't pass", !Predicate<std::string>( [] (std::string const& str) -> bool { return str.front() == str.back(); } ) for: "This wouldn't pass" not matches undescribed predicate
Compilation.tests.cpp:<line number>: passed: lhs | rhs for: Val: 1 | Val: 2
Compilation.tests.cpp:<line number>: passed: !(lhs & rhs) for: !(Val: 1 & Val: 2)
Compilation.tests.cpp:<line number>: passed: HasBitOperators{ 1 } & HasBitOperators{ 1 } for: Val: 1 & Val: 1
Compilation.tests.cpp:<line number>: passed: lhs ^ rhs for: Val: 1 ^ Val: 2
Compilation.tests.cpp:<line number>: passed: !(lhs ^ lhs) for: !(Val: 1 ^ Val: 1)
Tricky.tests.cpp:<line number>: passed: true Tricky.tests.cpp:<line number>: passed: true
Tricky.tests.cpp:<line number>: passed: true Tricky.tests.cpp:<line number>: passed: true
Tricky.tests.cpp:<line number>: passed: true Tricky.tests.cpp:<line number>: passed: true
...@@ -1519,6 +1531,7 @@ Approx.tests.cpp:<line number>: passed: approx( d ) != 1.25 for: Approx( 1.23 ) ...@@ -1519,6 +1531,7 @@ Approx.tests.cpp:<line number>: passed: approx( d ) != 1.25 for: Approx( 1.23 )
VariadicMacros.tests.cpp:<line number>: passed: with 1 message: 'no assertions' VariadicMacros.tests.cpp:<line number>: passed: with 1 message: 'no assertions'
Matchers.tests.cpp:<line number>: passed: empty, Approx(empty) for: { } is approx: { } Matchers.tests.cpp:<line number>: passed: empty, Approx(empty) for: { } is approx: { }
Matchers.tests.cpp:<line number>: passed: v1, Approx(v1) for: { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 } Matchers.tests.cpp:<line number>: passed: v1, Approx(v1) for: { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 }
Matchers.tests.cpp:<line number>: passed: v1, Approx<double>({ 1., 2., 3. }) for: { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 }
Matchers.tests.cpp:<line number>: passed: v1, !Approx(temp) for: { 1.0, 2.0, 3.0 } not is approx: { 1.0, 2.0, 3.0, 4.0 } Matchers.tests.cpp:<line number>: passed: v1, !Approx(temp) for: { 1.0, 2.0, 3.0 } not is approx: { 1.0, 2.0, 3.0, 4.0 }
Matchers.tests.cpp:<line number>: passed: v1, !Approx(v2) for: { 1.0, 2.0, 3.0 } not is approx: { 1.5, 2.5, 3.5 } Matchers.tests.cpp:<line number>: passed: v1, !Approx(v2) for: { 1.0, 2.0, 3.0 } not is approx: { 1.5, 2.5, 3.5 }
Matchers.tests.cpp:<line number>: passed: v1, Approx(v2).margin(0.5) for: { 1.0, 2.0, 3.0 } is approx: { 1.5, 2.5, 3.5 } Matchers.tests.cpp:<line number>: passed: v1, Approx(v2).margin(0.5) for: { 1.0, 2.0, 3.0 } is approx: { 1.5, 2.5, 3.5 }
...@@ -1528,18 +1541,29 @@ Matchers.tests.cpp:<line number>: failed: empty, Approx(t1) for: { } is approx: ...@@ -1528,18 +1541,29 @@ Matchers.tests.cpp:<line number>: failed: empty, Approx(t1) for: { } is approx:
Matchers.tests.cpp:<line number>: failed: v1, Approx(v2) for: { 2.0, 4.0, 6.0 } is approx: { 1.0, 3.0, 5.0 } Matchers.tests.cpp:<line number>: failed: v1, Approx(v2) for: { 2.0, 4.0, 6.0 } is approx: { 1.0, 3.0, 5.0 }
Matchers.tests.cpp:<line number>: passed: v, VectorContains(1) for: { 1, 2, 3 } Contains: 1 Matchers.tests.cpp:<line number>: passed: v, VectorContains(1) for: { 1, 2, 3 } Contains: 1
Matchers.tests.cpp:<line number>: passed: v, VectorContains(2) for: { 1, 2, 3 } Contains: 2 Matchers.tests.cpp:<line number>: passed: v, VectorContains(2) for: { 1, 2, 3 } Contains: 2
Matchers.tests.cpp:<line number>: passed: v5, (VectorContains<int, CustomAllocator<int>>(2)) for: { 1, 2, 3 } Contains: 2
Matchers.tests.cpp:<line number>: passed: v, Contains(v2) for: { 1, 2, 3 } Contains: { 1, 2 } Matchers.tests.cpp:<line number>: passed: v, Contains(v2) for: { 1, 2, 3 } Contains: { 1, 2 }
Matchers.tests.cpp:<line number>: passed: v, Contains<int>({ 1, 2 }) for: { 1, 2, 3 } Contains: { 1, 2 }
Matchers.tests.cpp:<line number>: passed: v5, (Contains<int, std::allocator<int>, CustomAllocator<int>>(v2)) for: { 1, 2, 3 } Contains: { 1, 2 }
Matchers.tests.cpp:<line number>: passed: v, Contains(v2) for: { 1, 2, 3 } Contains: { 1, 2, 3 } Matchers.tests.cpp:<line number>: passed: v, Contains(v2) for: { 1, 2, 3 } Contains: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v, Contains(empty) for: { 1, 2, 3 } Contains: { } Matchers.tests.cpp:<line number>: passed: v, Contains(empty) for: { 1, 2, 3 } Contains: { }
Matchers.tests.cpp:<line number>: passed: empty, Contains(empty) for: { } Contains: { } Matchers.tests.cpp:<line number>: passed: empty, Contains(empty) for: { } Contains: { }
Matchers.tests.cpp:<line number>: passed: v5, (Contains<int, std::allocator<int>, CustomAllocator<int>>(v2)) for: { 1, 2, 3 } Contains: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v5, Contains(v6) for: { 1, 2, 3 } Contains: { 1, 2 }
Matchers.tests.cpp:<line number>: passed: v, VectorContains(1) && VectorContains(2) for: { 1, 2, 3 } ( Contains: 1 and Contains: 2 ) Matchers.tests.cpp:<line number>: passed: v, VectorContains(1) && VectorContains(2) for: { 1, 2, 3 } ( Contains: 1 and Contains: 2 )
Matchers.tests.cpp:<line number>: passed: v, Equals(v) for: { 1, 2, 3 } Equals: { 1, 2, 3 } Matchers.tests.cpp:<line number>: passed: v, Equals(v) for: { 1, 2, 3 } Equals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: empty, Equals(empty) for: { } Equals: { } Matchers.tests.cpp:<line number>: passed: empty, Equals(empty) for: { } Equals: { }
Matchers.tests.cpp:<line number>: passed: v, Equals<int>({ 1, 2, 3 }) for: { 1, 2, 3 } Equals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v, Equals(v2) for: { 1, 2, 3 } Equals: { 1, 2, 3 } Matchers.tests.cpp:<line number>: passed: v, Equals(v2) for: { 1, 2, 3 } Equals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v5, (Equals<int, std::allocator<int>, CustomAllocator<int>>(v2)) for: { 1, 2, 3 } Equals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v5, Equals(v6) for: { 1, 2, 3 } Equals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v, UnorderedEquals(v) for: { 1, 2, 3 } UnorderedEquals: { 1, 2, 3 } Matchers.tests.cpp:<line number>: passed: v, UnorderedEquals(v) for: { 1, 2, 3 } UnorderedEquals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v, UnorderedEquals<int>({ 3, 2, 1 }) for: { 1, 2, 3 } UnorderedEquals: { 3, 2, 1 }
Matchers.tests.cpp:<line number>: passed: empty, UnorderedEquals(empty) for: { } UnorderedEquals: { } Matchers.tests.cpp:<line number>: passed: empty, UnorderedEquals(empty) for: { } UnorderedEquals: { }
Matchers.tests.cpp:<line number>: passed: permuted, UnorderedEquals(v) for: { 1, 3, 2 } UnorderedEquals: { 1, 2, 3 } Matchers.tests.cpp:<line number>: passed: permuted, UnorderedEquals(v) for: { 1, 3, 2 } UnorderedEquals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: permuted, UnorderedEquals(v) for: { 2, 3, 1 } UnorderedEquals: { 1, 2, 3 } Matchers.tests.cpp:<line number>: passed: permuted, UnorderedEquals(v) for: { 2, 3, 1 } UnorderedEquals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: passed: v5, (UnorderedEquals<int, std::allocator<int>, CustomAllocator<int>>(permuted)) for: { 1, 2, 3 } UnorderedEquals: { 2, 3, 1 }
Matchers.tests.cpp:<line number>: passed: v5_permuted, UnorderedEquals(v5) for: { 1, 3, 2 } UnorderedEquals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: failed: v, VectorContains(-1) for: { 1, 2, 3 } Contains: -1 Matchers.tests.cpp:<line number>: failed: v, VectorContains(-1) for: { 1, 2, 3 } Contains: -1
Matchers.tests.cpp:<line number>: failed: empty, VectorContains(1) for: { } Contains: 1 Matchers.tests.cpp:<line number>: failed: empty, VectorContains(1) for: { } Contains: 1
Matchers.tests.cpp:<line number>: failed: empty, Contains(v) for: { } Contains: { 1, 2, 3 } Matchers.tests.cpp:<line number>: failed: empty, Contains(v) for: { } Contains: { 1, 2, 3 }
......
...@@ -1380,6 +1380,6 @@ due to unexpected exception with message: ...@@ -1380,6 +1380,6 @@ due to unexpected exception with message:
Why would you throw a std::string? Why would you throw a std::string?
=============================================================================== ===============================================================================
test cases: 307 | 233 passed | 70 failed | 4 failed as expected test cases: 310 | 236 passed | 70 failed | 4 failed as expected
assertions: 1677 | 1525 passed | 131 failed | 21 failed as expected assertions: 1701 | 1549 passed | 131 failed | 21 failed as expected
...@@ -188,6 +188,61 @@ Compilation.tests.cpp:<line number>: PASSED: ...@@ -188,6 +188,61 @@ Compilation.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
true true
-------------------------------------------------------------------------------
#1905 -- test spec parser properly clears internal state between compound tests
-------------------------------------------------------------------------------
CmdLine.tests.cpp:<line number>
...............................................................................
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE( spec.matches(fakeTestCase("spec . char")) )
with expansion:
true
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE( spec.matches(fakeTestCase("spec , char")) )
with expansion:
true
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( spec.matches(fakeTestCase(R"(spec \, char)")) )
with expansion:
!false
-------------------------------------------------------------------------------
#1912 -- test spec parser handles escaping
Various parentheses
-------------------------------------------------------------------------------
CmdLine.tests.cpp:<line number>
...............................................................................
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE( spec.matches(fakeTestCase(R"(spec {a} char)")) )
with expansion:
true
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE( spec.matches(fakeTestCase(R"(spec [a] char)")) )
with expansion:
true
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( spec.matches(fakeTestCase("differs but has similar tag", "[a]")) )
with expansion:
!false
-------------------------------------------------------------------------------
#1912 -- test spec parser handles escaping
backslash in test name
-------------------------------------------------------------------------------
CmdLine.tests.cpp:<line number>
...............................................................................
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE( spec.matches(fakeTestCase(R"(spec \ char)")) )
with expansion:
true
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
#748 - captures with unexpected exceptions #748 - captures with unexpected exceptions
outside assertions outside assertions
...@@ -1879,6 +1934,37 @@ Matchers.tests.cpp:<line number>: PASSED: ...@@ -1879,6 +1934,37 @@ Matchers.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
"This wouldn't pass" not matches undescribed predicate "This wouldn't pass" not matches undescribed predicate
-------------------------------------------------------------------------------
Assertion macros support bit operators and bool conversions
-------------------------------------------------------------------------------
Compilation.tests.cpp:<line number>
...............................................................................
Compilation.tests.cpp:<line number>: PASSED:
REQUIRE( lhs | rhs )
with expansion:
Val: 1 | Val: 2
Compilation.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( lhs & rhs )
with expansion:
!(Val: 1 & Val: 2)
Compilation.tests.cpp:<line number>: PASSED:
REQUIRE( HasBitOperators{ 1 } & HasBitOperators{ 1 } )
with expansion:
Val: 1 & Val: 1
Compilation.tests.cpp:<line number>: PASSED:
REQUIRE( lhs ^ rhs )
with expansion:
Val: 1 ^ Val: 2
Compilation.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( lhs ^ lhs )
with expansion:
!(Val: 1 ^ Val: 1)
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Assertions then sections Assertions then sections
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
...@@ -11101,6 +11187,11 @@ Matchers.tests.cpp:<line number>: PASSED: ...@@ -11101,6 +11187,11 @@ Matchers.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
{ 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 } { 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 }
Matchers.tests.cpp:<line number>: PASSED:
REQUIRE_THAT( v1, Approx<double>({ 1., 2., 3. }) )
with expansion:
{ 1.0, 2.0, 3.0 } is approx: { 1.0, 2.0, 3.0 }
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Vector Approx matcher Vector Approx matcher
Vectors with elements Vectors with elements
...@@ -11183,6 +11274,11 @@ Matchers.tests.cpp:<line number>: PASSED: ...@@ -11183,6 +11274,11 @@ Matchers.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
{ 1, 2, 3 } Contains: 2 { 1, 2, 3 } Contains: 2
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v5, (VectorContains<int, CustomAllocator<int>>(2)) )
with expansion:
{ 1, 2, 3 } Contains: 2
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Vector matchers Vector matchers
Contains (vector) Contains (vector)
...@@ -11195,6 +11291,16 @@ Matchers.tests.cpp:<line number>: PASSED: ...@@ -11195,6 +11291,16 @@ Matchers.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
{ 1, 2, 3 } Contains: { 1, 2 } { 1, 2, 3 } Contains: { 1, 2 }
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v, Contains<int>({ 1, 2 }) )
with expansion:
{ 1, 2, 3 } Contains: { 1, 2 }
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v5, (Contains<int, std::allocator<int>, CustomAllocator<int>>(v2)) )
with expansion:
{ 1, 2, 3 } Contains: { 1, 2 }
Matchers.tests.cpp:<line number>: PASSED: Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v, Contains(v2) ) CHECK_THAT( v, Contains(v2) )
with expansion: with expansion:
...@@ -11210,6 +11316,16 @@ Matchers.tests.cpp:<line number>: PASSED: ...@@ -11210,6 +11316,16 @@ Matchers.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
{ } Contains: { } { } Contains: { }
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v5, (Contains<int, std::allocator<int>, CustomAllocator<int>>(v2)) )
with expansion:
{ 1, 2, 3 } Contains: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v5, Contains(v6) )
with expansion:
{ 1, 2, 3 } Contains: { 1, 2 }
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Vector matchers Vector matchers
Contains (element), composed Contains (element), composed
...@@ -11239,11 +11355,26 @@ Matchers.tests.cpp:<line number>: PASSED: ...@@ -11239,11 +11355,26 @@ Matchers.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
{ } Equals: { } { } Equals: { }
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v, Equals<int>({ 1, 2, 3 }) )
with expansion:
{ 1, 2, 3 } Equals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: PASSED: Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v, Equals(v2) ) CHECK_THAT( v, Equals(v2) )
with expansion: with expansion:
{ 1, 2, 3 } Equals: { 1, 2, 3 } { 1, 2, 3 } Equals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v5, (Equals<int, std::allocator<int>, CustomAllocator<int>>(v2)) )
with expansion:
{ 1, 2, 3 } Equals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v5, Equals(v6) )
with expansion:
{ 1, 2, 3 } Equals: { 1, 2, 3 }
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Vector matchers Vector matchers
UnorderedEquals UnorderedEquals
...@@ -11256,6 +11387,11 @@ Matchers.tests.cpp:<line number>: PASSED: ...@@ -11256,6 +11387,11 @@ Matchers.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
{ 1, 2, 3 } UnorderedEquals: { 1, 2, 3 } { 1, 2, 3 } UnorderedEquals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v, UnorderedEquals<int>({ 3, 2, 1 }) )
with expansion:
{ 1, 2, 3 } UnorderedEquals: { 3, 2, 1 }
Matchers.tests.cpp:<line number>: PASSED: Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( empty, UnorderedEquals(empty) ) CHECK_THAT( empty, UnorderedEquals(empty) )
with expansion: with expansion:
...@@ -11271,6 +11407,16 @@ Matchers.tests.cpp:<line number>: PASSED: ...@@ -11271,6 +11407,16 @@ Matchers.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
{ 2, 3, 1 } UnorderedEquals: { 1, 2, 3 } { 2, 3, 1 } UnorderedEquals: { 1, 2, 3 }
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v5, (UnorderedEquals<int, std::allocator<int>, CustomAllocator<int>>(permuted)) )
with expansion:
{ 1, 2, 3 } UnorderedEquals: { 2, 3, 1 }
Matchers.tests.cpp:<line number>: PASSED:
CHECK_THAT( v5_permuted, UnorderedEquals(v5) )
with expansion:
{ 1, 3, 2 } UnorderedEquals: { 1, 2, 3 }
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
Vector matchers that fail Vector matchers that fail
Contains (element) Contains (element)
...@@ -13427,6 +13573,6 @@ Misc.tests.cpp:<line number> ...@@ -13427,6 +13573,6 @@ Misc.tests.cpp:<line number>
Misc.tests.cpp:<line number>: PASSED: Misc.tests.cpp:<line number>: PASSED:
=============================================================================== ===============================================================================
test cases: 307 | 217 passed | 86 failed | 4 failed as expected test cases: 310 | 220 passed | 86 failed | 4 failed as expected
assertions: 1694 | 1525 passed | 148 failed | 21 failed as expected assertions: 1718 | 1549 passed | 148 failed | 21 failed as expected
...@@ -188,6 +188,61 @@ Compilation.tests.cpp:<line number>: PASSED: ...@@ -188,6 +188,61 @@ Compilation.tests.cpp:<line number>: PASSED:
with expansion: with expansion:
true true
-------------------------------------------------------------------------------
#1905 -- test spec parser properly clears internal state between compound tests
-------------------------------------------------------------------------------
CmdLine.tests.cpp:<line number>
...............................................................................
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE( spec.matches(fakeTestCase("spec . char")) )
with expansion:
true
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE( spec.matches(fakeTestCase("spec , char")) )
with expansion:
true
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( spec.matches(fakeTestCase(R"(spec \, char)")) )
with expansion:
!false
-------------------------------------------------------------------------------
#1912 -- test spec parser handles escaping
Various parentheses
-------------------------------------------------------------------------------
CmdLine.tests.cpp:<line number>
...............................................................................
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE( spec.matches(fakeTestCase(R"(spec {a} char)")) )
with expansion:
true
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE( spec.matches(fakeTestCase(R"(spec [a] char)")) )
with expansion:
true
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE_FALSE( spec.matches(fakeTestCase("differs but has similar tag", "[a]")) )
with expansion:
!false
-------------------------------------------------------------------------------
#1912 -- test spec parser handles escaping
backslash in test name
-------------------------------------------------------------------------------
CmdLine.tests.cpp:<line number>
...............................................................................
CmdLine.tests.cpp:<line number>: PASSED:
REQUIRE( spec.matches(fakeTestCase(R"(spec \ char)")) )
with expansion:
true
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
#748 - captures with unexpected exceptions #748 - captures with unexpected exceptions
outside assertions outside assertions
...@@ -368,6 +423,6 @@ Condition.tests.cpp:<line number>: FAILED: ...@@ -368,6 +423,6 @@ Condition.tests.cpp:<line number>: FAILED:
CHECK( true != true ) CHECK( true != true )
=============================================================================== ===============================================================================
test cases: 19 | 14 passed | 3 failed | 2 failed as expected test cases: 21 | 16 passed | 3 failed | 2 failed as expected
assertions: 42 | 35 passed | 4 failed | 3 failed as expected assertions: 49 | 42 passed | 4 failed | 3 failed as expected
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<testsuitesloose text artifact <testsuitesloose text artifact
> >
<testsuite name="<exe-name>" errors="17" failures="132" tests="1695" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <testsuite name="<exe-name>" errors="17" failures="132" tests="1719" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
<properties> <properties>
<property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/> <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/>
<property name="random-seed" value="1"/> <property name="random-seed" value="1"/>
...@@ -30,6 +30,9 @@ Nor would this ...@@ -30,6 +30,9 @@ Nor would this
</system-err> </system-err>
</testcase> </testcase>
<testcase classname="<exe-name>.global" name="#1548" time="{duration}"/> <testcase classname="<exe-name>.global" name="#1548" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1905 -- test spec parser properly clears internal state between compound tests" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1912 -- test spec parser handles escaping/Various parentheses" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#1912 -- test spec parser handles escaping/backslash in test name" time="{duration}"/>
<testcase classname="<exe-name>.global" name="#748 - captures with unexpected exceptions/outside assertions" time="{duration}"> <testcase classname="<exe-name>.global" name="#748 - captures with unexpected exceptions/outside assertions" time="{duration}">
<error type="TEST_CASE"> <error type="TEST_CASE">
FAILED: FAILED:
...@@ -337,6 +340,7 @@ Exception.tests.cpp:<line number> ...@@ -337,6 +340,7 @@ Exception.tests.cpp:<line number>
<testcase classname="<exe-name>.global" name="Approximate comparisons with mixed numeric types" time="{duration}"/> <testcase classname="<exe-name>.global" name="Approximate comparisons with mixed numeric types" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Arbitrary predicate matcher/Function pointer" time="{duration}"/> <testcase classname="<exe-name>.global" name="Arbitrary predicate matcher/Function pointer" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Arbitrary predicate matcher/Lambdas + different type" time="{duration}"/> <testcase classname="<exe-name>.global" name="Arbitrary predicate matcher/Lambdas + different type" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Assertion macros support bit operators and bool conversions" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Assertions then sections" time="{duration}"/> <testcase classname="<exe-name>.global" name="Assertions then sections" time="{duration}"/>
<testcase classname="<exe-name>.global" name="Assertions then sections/A section" time="{duration}"/> <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 section" time="{duration}"/>
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
<testExecutions version="1"loose text artifact <testExecutions version="1"loose text artifact
> >
<file path="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp"> <file path="projects/<exe-name>/IntrospectiveTests/CmdLine.tests.cpp">
<testCase name="#1905 -- test spec parser properly clears internal state between compound tests" duration="{duration}"/>
<testCase name="#1912 -- test spec parser handles escaping/Various parentheses" duration="{duration}"/>
<testCase name="#1912 -- test spec parser handles escaping/backslash in test name" duration="{duration}"/>
<testCase name="Parse test names and tags/Empty test spec should have no filters" duration="{duration}"/> <testCase name="Parse test names and tags/Empty test spec should have no filters" duration="{duration}"/>
<testCase name="Parse test names and tags/Test spec from empty string should have no filters" duration="{duration}"/> <testCase name="Parse test names and tags/Test spec from empty string should have no filters" duration="{duration}"/>
<testCase name="Parse test names and tags/Test spec from just a comma should have no filters" duration="{duration}"/> <testCase name="Parse test names and tags/Test spec from just a comma should have no filters" duration="{duration}"/>
...@@ -369,6 +372,7 @@ Class.tests.cpp:<line number> ...@@ -369,6 +372,7 @@ Class.tests.cpp:<line number>
<testCase name="#809" duration="{duration}"/> <testCase name="#809" duration="{duration}"/>
<testCase name="#833" duration="{duration}"/> <testCase name="#833" duration="{duration}"/>
<testCase name="#872" duration="{duration}"/> <testCase name="#872" duration="{duration}"/>
<testCase name="Assertion macros support bit operators and bool conversions" duration="{duration}"/>
<testCase name="Lambdas in assertions" duration="{duration}"/> <testCase name="Lambdas in assertions" duration="{duration}"/>
<testCase name="Optionally static assertions" duration="{duration}"/> <testCase name="Optionally static assertions" duration="{duration}"/>
</file> </file>
......
...@@ -292,6 +292,35 @@ TEST_CASE( "Parse test names and tags", "[command-line][test-spec]" ) { ...@@ -292,6 +292,35 @@ TEST_CASE( "Parse test names and tags", "[command-line][test-spec]" ) {
} }
} }
TEST_CASE("#1905 -- test spec parser properly clears internal state between compound tests", "[command-line][test-spec]") {
using Catch::parseTestSpec;
using Catch::TestSpec;
// We ask for one of 2 different tests and the latter one of them has a , in name that needs escaping
TestSpec spec = parseTestSpec(R"("spec . char","spec \, char")");
REQUIRE(spec.matches(fakeTestCase("spec . char")));
REQUIRE(spec.matches(fakeTestCase("spec , char")));
REQUIRE_FALSE(spec.matches(fakeTestCase(R"(spec \, char)")));
}
TEST_CASE("#1912 -- test spec parser handles escaping", "[command-line][test-spec]") {
using Catch::parseTestSpec;
using Catch::TestSpec;
SECTION("Various parentheses") {
TestSpec spec = parseTestSpec(R"(spec {a} char,spec \[a] char)");
REQUIRE(spec.matches(fakeTestCase(R"(spec {a} char)")));
REQUIRE(spec.matches(fakeTestCase(R"(spec [a] char)")));
REQUIRE_FALSE(spec.matches(fakeTestCase("differs but has similar tag", "[a]")));
}
SECTION("backslash in test name") {
TestSpec spec = parseTestSpec(R"(spec \\ char)");
REQUIRE(spec.matches(fakeTestCase(R"(spec \ char)")));
}
}
TEST_CASE( "Process can be configured on command line", "[config][command-line]" ) { TEST_CASE( "Process can be configured on command line", "[config][command-line]" ) {
#ifndef CATCH_CONFIG_DISABLE_MATCHERS #ifndef CATCH_CONFIG_DISABLE_MATCHERS
......
...@@ -234,3 +234,36 @@ namespace { namespace CompilationTests { ...@@ -234,3 +234,36 @@ namespace { namespace CompilationTests {
}} // namespace CompilationTests }} // namespace CompilationTests
namespace {
struct HasBitOperators {
int value;
friend HasBitOperators operator| (HasBitOperators lhs, HasBitOperators rhs) {
return { lhs.value | rhs.value };
}
friend HasBitOperators operator& (HasBitOperators lhs, HasBitOperators rhs) {
return { lhs.value & rhs.value };
}
friend HasBitOperators operator^ (HasBitOperators lhs, HasBitOperators rhs) {
return { lhs.value ^ rhs.value };
}
explicit operator bool() const {
return !!value;
}
friend std::ostream& operator<<(std::ostream& out, HasBitOperators val) {
out << "Val: " << val.value;
return out;
}
};
}
TEST_CASE("Assertion macros support bit operators and bool conversions", "[compilation][bitops]") {
HasBitOperators lhs{ 1 }, rhs{ 2 };
REQUIRE(lhs | rhs);
REQUIRE_FALSE(lhs & rhs);
REQUIRE(HasBitOperators{ 1 } & HasBitOperators{ 1 });
REQUIRE(lhs ^ rhs);
REQUIRE_FALSE(lhs ^ lhs);
}
...@@ -214,6 +214,42 @@ namespace { namespace MatchersTests { ...@@ -214,6 +214,42 @@ namespace { namespace MatchersTests {
CHECK_THAT(testStringForMatching(), !Contains("substring")); CHECK_THAT(testStringForMatching(), !Contains("substring"));
} }
template<typename T>
struct CustomAllocator : private std::allocator<T>
{
using size_type = size_t;
using difference_type = ptrdiff_t;
using pointer = T*;
using const_pointer = const T*;
using reference = T&;
using const_reference = const T&;
using value_type = T;
template<typename U>
struct rebind
{ using other = CustomAllocator<U>; };
using propagate_on_container_move_assignment = std::true_type;
using is_always_equal = std::true_type;
CustomAllocator() = default;
CustomAllocator(const CustomAllocator& other)
: std::allocator<T>(other) { }
template<typename U>
CustomAllocator(const CustomAllocator<U>&) { }
~CustomAllocator() = default;
using std::allocator<T>::address;
using std::allocator<T>::allocate;
using std::allocator<T>::construct;
using std::allocator<T>::deallocate;
using std::allocator<T>::max_size;
using std::allocator<T>::destroy;
};
TEST_CASE("Vector matchers", "[matchers][vector]") { TEST_CASE("Vector matchers", "[matchers][vector]") {
std::vector<int> v; std::vector<int> v;
v.push_back(1); v.push_back(1);
...@@ -234,19 +270,35 @@ namespace { namespace MatchersTests { ...@@ -234,19 +270,35 @@ namespace { namespace MatchersTests {
v4.push_back(2 + 1e-8); v4.push_back(2 + 1e-8);
v4.push_back(3 + 1e-8); v4.push_back(3 + 1e-8);
std::vector<int, CustomAllocator<int>> v5;
v5.push_back(1);
v5.push_back(2);
v5.push_back(3);
std::vector<int, CustomAllocator<int>> v6;
v6.push_back(1);
v6.push_back(2);
std::vector<int> empty; std::vector<int> empty;
SECTION("Contains (element)") { SECTION("Contains (element)") {
CHECK_THAT(v, VectorContains(1)); CHECK_THAT(v, VectorContains(1));
CHECK_THAT(v, VectorContains(2)); CHECK_THAT(v, VectorContains(2));
CHECK_THAT(v5, (VectorContains<int, CustomAllocator<int>>(2)));
} }
SECTION("Contains (vector)") { SECTION("Contains (vector)") {
CHECK_THAT(v, Contains(v2)); CHECK_THAT(v, Contains(v2));
CHECK_THAT(v, Contains<int>({ 1, 2 }));
CHECK_THAT(v5, (Contains<int, std::allocator<int>, CustomAllocator<int>>(v2)));
v2.push_back(3); // now exactly matches v2.push_back(3); // now exactly matches
CHECK_THAT(v, Contains(v2)); CHECK_THAT(v, Contains(v2));
CHECK_THAT(v, Contains(empty)); CHECK_THAT(v, Contains(empty));
CHECK_THAT(empty, Contains(empty)); CHECK_THAT(empty, Contains(empty));
CHECK_THAT(v5, (Contains<int, std::allocator<int>, CustomAllocator<int>>(v2)));
CHECK_THAT(v5, Contains(v6));
} }
SECTION("Contains (element), composed") { SECTION("Contains (element), composed") {
CHECK_THAT(v, VectorContains(1) && VectorContains(2)); CHECK_THAT(v, VectorContains(1) && VectorContains(2));
...@@ -256,15 +308,21 @@ namespace { namespace MatchersTests { ...@@ -256,15 +308,21 @@ namespace { namespace MatchersTests {
// Same vector // Same vector
CHECK_THAT(v, Equals(v)); CHECK_THAT(v, Equals(v));
CHECK_THAT(empty, Equals(empty)); CHECK_THAT(empty, Equals(empty));
// Different vector with same elements // Different vector with same elements
CHECK_THAT(v, Equals<int>({ 1, 2, 3 }));
v2.push_back(3); v2.push_back(3);
CHECK_THAT(v, Equals(v2)); CHECK_THAT(v, Equals(v2));
CHECK_THAT(v5, (Equals<int, std::allocator<int>, CustomAllocator<int>>(v2)));
v6.push_back(3);
CHECK_THAT(v5, Equals(v6));
} }
SECTION("UnorderedEquals") { SECTION("UnorderedEquals") {
CHECK_THAT(v, UnorderedEquals(v)); CHECK_THAT(v, UnorderedEquals(v));
CHECK_THAT(v, UnorderedEquals<int>({ 3, 2, 1 }));
CHECK_THAT(empty, UnorderedEquals(empty)); CHECK_THAT(empty, UnorderedEquals(empty));
auto permuted = v; auto permuted = v;
...@@ -273,6 +331,12 @@ namespace { namespace MatchersTests { ...@@ -273,6 +331,12 @@ namespace { namespace MatchersTests {
std::reverse(begin(permuted), end(permuted)); std::reverse(begin(permuted), end(permuted));
REQUIRE_THAT(permuted, UnorderedEquals(v)); REQUIRE_THAT(permuted, UnorderedEquals(v));
CHECK_THAT(v5, (UnorderedEquals<int, std::allocator<int>, CustomAllocator<int>>(permuted)));
auto v5_permuted = v5;
std::next_permutation(begin(v5_permuted), end(v5_permuted));
CHECK_THAT(v5_permuted, UnorderedEquals(v5));
} }
} }
...@@ -518,6 +582,7 @@ namespace { namespace MatchersTests { ...@@ -518,6 +582,7 @@ namespace { namespace MatchersTests {
std::vector<double> v1({1., 2., 3.}); std::vector<double> v1({1., 2., 3.});
SECTION("A vector is approx equal to itself") { SECTION("A vector is approx equal to itself") {
REQUIRE_THAT(v1, Approx(v1)); REQUIRE_THAT(v1, Approx(v1));
REQUIRE_THAT(v1, Approx<double>({ 1., 2., 3. }));
} }
std::vector<double> v2({1.5, 2.5, 3.5}); std::vector<double> v2({1.5, 2.5, 3.5});
SECTION("Different length") { SECTION("Different length") {
......
#!/usr/bin/env python3
"""
This test script verifies that the random ordering of tests inside
Catch2 is invariant in regards to subsetting. This is done by running
the binary 3 times, once with all tests selected, and twice with smaller
subsets of tests selected, and verifying that the selected tests are in
the same relative order.
"""
import subprocess
import sys
import random
def list_tests(self_test_exe, tags, rng_seed):
cmd = [self_test_exe, '--list-test-names-only', '--order', 'rand',
'--rng-seed', str(rng_seed)]
tags_arg = ','.join('[{}]'.format(t) for t in tags)
if tags_arg:
cmd.append(tags_arg + '~[.]')
process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
if stderr:
raise RuntimeError("Unexpected error output:\n" + process.stderr)
result = stdout.split(b'\n')
result = [s for s in result if s]
if len(result) < 2:
raise RuntimeError("Unexpectedly few tests listed (got {})".format(
len(result)))
return result
def check_is_sublist_of(shorter, longer):
assert len(shorter) < len(longer)
assert len(set(longer)) == len(longer)
indexes_in_longer = {s: i for i, s in enumerate(longer)}
for s1, s2 in zip(shorter, shorter[1:]):
assert indexes_in_longer[s1] < indexes_in_longer[s2], (
'{} comes before {} in longer list.\n'
'Longer: {}\nShorter: {}'.format(s2, s1, longer, shorter))
def main():
self_test_exe, = sys.argv[1:]
# We want a random seed for the test, but want to avoid 0,
# because it has special meaning
seed = random.randint(1, 2 ** 32 - 1)
list_one_tag = list_tests(self_test_exe, ['generators'], seed)
list_two_tags = list_tests(self_test_exe, ['generators', 'matchers'], seed)
list_all = list_tests(self_test_exe, [], seed)
# First, verify that restricting to a subset yields the same order
check_is_sublist_of(list_two_tags, list_all)
check_is_sublist_of(list_one_tag, list_two_tags)
if __name__ == '__main__':
sys.exit(main())
...@@ -126,7 +126,7 @@ function get_abseil_cpp() ...@@ -126,7 +126,7 @@ function get_abseil_cpp()
function get_catch() function get_catch()
{ {
GIT_REPO="https://github.com/catchorg/Catch2.git" GIT_REPO="https://github.com/catchorg/Catch2.git"
GIT_TAG="v2.11.3" GIT_TAG="v2.12.1"
DEST="deps/catch" DEST="deps/catch"
get_dep "${GIT_REPO}" "${GIT_TAG}" "${DEST}" get_dep "${GIT_REPO}" "${GIT_TAG}" "${DEST}"
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论