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

Update catch and @types/node

上级 4cb740a2
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
}, },
"devDependencies": { "devDependencies": {
"@types/debug": "^4.1.5", "@types/debug": "^4.1.5",
"@types/node": "^12.12.7", "@types/node": "^12.12.8",
"@types/random-number": "0.0.0", "@types/random-number": "0.0.0",
"@types/uuid": "^3.4.6", "@types/uuid": "^3.4.6",
"@typescript-eslint/eslint-plugin": "^2.7.0", "@typescript-eslint/eslint-plugin": "^2.7.0",
......
...@@ -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.10.2) project(Catch2 LANGUAGES CXX VERSION 2.11.0)
# 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/LzYWgcPrcy9yQmed) [![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/HU1MkiBgFetFQJU4)
[![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.10.2/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.11.0/catch.hpp">The latest version of the single header can be downloaded directly using this link</a>
## Catch2 is released! ## Catch2 is released!
......
# version string format -- This will be overwritten later anyway # version string format -- This will be overwritten later anyway
version: "{build}" version: "{build}"
# We need a more up to date pip because Python 2.7 is EOL soon
init:
- set PATH=C:\Python35\Scripts;%PATH%
branches: branches:
except: except:
- /dev-travis.+/ - /dev-travis.+/
...@@ -62,7 +67,7 @@ matrix: ...@@ -62,7 +67,7 @@ matrix:
install: install:
- ps: if (($env:CONFIGURATION) -eq "Debug" -And ($env:coverage) -eq "1" ) { python -m pip --disable-pip-version-check install codecov } - ps: if (($env:CONFIGURATION) -eq "Debug" -And ($env:coverage) -eq "1" ) { pip --disable-pip-version-check install codecov }
- ps: if (($env:CONFIGURATION) -eq "Debug" -And ($env:coverage) -eq "1" ) { .\misc\installOpenCppCoverage.ps1 } - ps: if (($env:CONFIGURATION) -eq "Debug" -And ($env:coverage) -eq "1" ) { .\misc\installOpenCppCoverage.ps1 }
# Win32 and x64 are CMake-compatible solution platform names. # Win32 and x64 are CMake-compatible solution platform names.
......
...@@ -14,6 +14,7 @@ coverage: ...@@ -14,6 +14,7 @@ coverage:
- "**/catch_reporter_tap.hpp" - "**/catch_reporter_tap.hpp"
- "**/catch_reporter_automake.hpp" - "**/catch_reporter_automake.hpp"
- "**/catch_reporter_teamcity.hpp" - "**/catch_reporter_teamcity.hpp"
- "**/catch_reporter_sonarqube.hpp"
- "**/external/clara.hpp" - "**/external/clara.hpp"
......
...@@ -12,7 +12,7 @@ Build Systems may refer to low-level tools, like CMake, or larger systems that r ...@@ -12,7 +12,7 @@ Build Systems may refer to low-level tools, like CMake, or larger systems that r
## Continuous Integration systems ## Continuous Integration systems
Probably the most important aspect to using Catch with a build server is the use of different reporters. Catch comes bundled with three reporters that should cover the majority of build servers out there - although adding more for better integration with some is always a possibility (currently we also offer TeamCity, TAP and Automake reporters). Probably the most important aspect to using Catch with a build server is the use of different reporters. Catch comes bundled with three reporters that should cover the majority of build servers out there - although adding more for better integration with some is always a possibility (currently we also offer TeamCity, TAP, Automake and SonarQube reporters).
Two of these reporters are built in (XML and JUnit) and the third (TeamCity) is included as a separate header. It's possible that the other two may be split out in the future too - as that would make the core of Catch smaller for those that don't need them. Two of these reporters are built in (XML and JUnit) and the third (TeamCity) is included as a separate header. It's possible that the other two may be split out in the future too - as that would make the core of Catch smaller for those that don't need them.
...@@ -65,6 +65,10 @@ The Automake Reporter writes out the [meta tags](https://www.gnu.org/software/au ...@@ -65,6 +65,10 @@ The Automake Reporter writes out the [meta tags](https://www.gnu.org/software/au
Because of the incremental nature of Catch's test suites and ability to run specific tests, our implementation of TAP reporter writes out the number of tests in a suite last. Because of the incremental nature of Catch's test suites and ability to run specific tests, our implementation of TAP reporter writes out the number of tests in a suite last.
### SonarQube Reporter
```-r sonarqube```
[SonarQube Generic Test Data](https://docs.sonarqube.org/latest/analysis/generic-test/) XML format for tests metrics.
## Low-level tools ## Low-level tools
### Precompiled headers (PCHs) ### Precompiled headers (PCHs)
......
...@@ -93,6 +93,17 @@ positively match a testspec. ...@@ -93,6 +93,17 @@ positively match a testspec.
The API for Catch2's console colour will be changed to take an extra The API for Catch2's console colour will be changed to take an extra
argument, the stream to which the colour code should be applied. argument, the stream to which the colour code should be applied.
### Type erasure in the `PredicateMatcher`
Currently, the `PredicateMatcher` uses `std::function` for type erasure,
so that type of the matcher is always `PredicateMatcher<T>`, regardless
of the type of the predicate. Because of the high compilation overhead
of `std::function`, and the fact that the type erasure is used only rarely,
`PredicateMatcher` will no longer be type erased in the future. Instead,
the predicate type will be made part of the PredicateMatcher's type.
--- ---
[Home](Readme.md#top) [Home](Readme.md#top)
...@@ -49,7 +49,7 @@ a test case, ...@@ -49,7 +49,7 @@ a test case,
* 4 specific purpose generators * 4 specific purpose generators
* `RandomIntegerGenerator<Integral>` -- generates random Integrals from range * `RandomIntegerGenerator<Integral>` -- generates random Integrals from range
* `RandomFloatGenerator<Float>` -- generates random Floats from range * `RandomFloatGenerator<Float>` -- generates random Floats from range
* `RangeGenerator<T>` -- generates all values inside a specific range * `RangeGenerator<T>` -- generates all values inside an arithmetic range
* `IteratorGenerator<T>` -- copies and returns values from an iterator range * `IteratorGenerator<T>` -- copies and returns values from an iterator range
> `ChunkGenerator<T>`, `RandomIntegerGenerator<Integral>`, `RandomFloatGenerator<Float>` and `RangeGenerator<T>` were introduced in Catch 2.7.0. > `ChunkGenerator<T>`, `RandomIntegerGenerator<Integral>`, `RandomFloatGenerator<Float>` and `RangeGenerator<T>` were introduced in Catch 2.7.0.
...@@ -69,8 +69,8 @@ type, making their usage much nicer. These are ...@@ -69,8 +69,8 @@ type, making their usage much nicer. These are
* `map<T>(func, GeneratorWrapper<U>&&)` for `MapGenerator<T, U, Func>` (map `U` to `T`) * `map<T>(func, GeneratorWrapper<U>&&)` for `MapGenerator<T, U, Func>` (map `U` to `T`)
* `chunk(chunk-size, GeneratorWrapper<T>&&)` for `ChunkGenerator<T>` * `chunk(chunk-size, GeneratorWrapper<T>&&)` for `ChunkGenerator<T>`
* `random(IntegerOrFloat a, IntegerOrFloat b)` for `RandomIntegerGenerator` or `RandomFloatGenerator` * `random(IntegerOrFloat a, IntegerOrFloat b)` for `RandomIntegerGenerator` or `RandomFloatGenerator`
* `range(start, end)` for `RangeGenerator<T>` with a step size of `1` * `range(Arithemtic start, Arithmetic end)` for `RangeGenerator<Arithmetic>` with a step size of `1`
* `range(start, end, step)` for `RangeGenerator<T>` with a custom step size * `range(Arithmetic start, Arithmetic end, Arithmetic step)` for `RangeGenerator<Arithmetic>` with a custom step size
* `from_range(InputIterator from, InputIterator to)` for `IteratorGenerator<T>` * `from_range(InputIterator from, InputIterator to)` for `IteratorGenerator<T>`
* `from_range(Container const&)` for `IteratorGenerator<T>` * `from_range(Container const&)` for `IteratorGenerator<T>`
...@@ -78,6 +78,8 @@ type, making their usage much nicer. These are ...@@ -78,6 +78,8 @@ type, making their usage much nicer. These are
> `from_range` has been introduced in Catch 2.10.0 > `from_range` has been introduced in Catch 2.10.0
> `range()` for floating point numbers has been introduced in Catch 2.11.0
And can be used as shown in the example below to create a generator And can be used as shown in the example below to create a generator
that returns 100 odd random number: that returns 100 odd random number:
......
...@@ -17,7 +17,7 @@ For example, to assert that a string ends with a certain substring: ...@@ -17,7 +17,7 @@ For example, to assert that a string ends with a certain substring:
using Catch::Matchers::EndsWith; // or Catch::EndsWith using Catch::Matchers::EndsWith; // or Catch::EndsWith
std::string str = getStringFromSomewhere(); std::string str = getStringFromSomewhere();
REQUIRE_THAT( str, EndsWith( "as a service" ) ); REQUIRE_THAT( str, EndsWith( "as a service" ) );
``` ```
The matcher objects can take multiple arguments, allowing more fine tuning. The matcher objects can take multiple arguments, allowing more fine tuning.
The built-in string matchers, for example, take a second argument specifying whether the comparison is The built-in string matchers, for example, take a second argument specifying whether the comparison is
...@@ -35,6 +35,22 @@ REQUIRE_THAT( str, ...@@ -35,6 +35,22 @@ REQUIRE_THAT( str,
(StartsWith( "Big data" ) && !Contains( "web scale" ) ) ); (StartsWith( "Big data" ) && !Contains( "web scale" ) ) );
``` ```
_The combining operators do not take ownership of the matcher objects.
This means that if you store the combined object, you have to ensure that
the matcher objects outlive its last use. What this means is that code
like this leads to a use-after-free and (hopefully) a crash:_
```cpp
TEST_CASE("Bugs, bugs, bugs", "[Bug]"){
std::string str = "Bugs as a service";
auto match_expression = Catch::EndsWith( "as a service" ) ||
(Catch::StartsWith( "Big data" ) && !Catch::Contains( "web scale" ) );
REQUIRE_THAT(str, match_expression);
}
```
## Built in matchers ## Built in matchers
Catch2 provides some matchers by default. They can be found in the Catch2 provides some matchers by default. They can be found in the
`Catch::Matchers::foo` namespace and are imported into the `Catch` `Catch::Matchers::foo` namespace and are imported into the `Catch`
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
# Release notes # Release notes
**Contents**<br> **Contents**<br>
[2.11.0](#2110)<br>
[2.10.2](#2102)<br> [2.10.2](#2102)<br>
[2.10.1](#2101)<br> [2.10.1](#2101)<br>
[2.10.0](#2100)<br> [2.10.0](#2100)<br>
...@@ -31,6 +32,23 @@ ...@@ -31,6 +32,23 @@
[Even Older versions](#even-older-versions)<br> [Even Older versions](#even-older-versions)<br>
## 2.11.0
### Improvements
* JUnit reporter output now contains more details in case of failure (#1347, #1719)
* Added SonarQube Test Data reporter (#1738)
* It is in a separate header, just like the TAP, Automake, and TeamCity reporters
* `range` generator now allows floating point numbers (#1776)
* Reworked part of internals to increase throughput
### Fixes
* The single header version should contain full benchmarking support (#1800)
* `[.foo]` is now properly parsed as `[.][foo]` when used on the command line (#1798)
* Fixed compilation of benchmarking on platforms where `steady_clock::period` is not `std::nano` (#1794)
## 2.10.2 ## 2.10.2
### Improvements ### Improvements
......
...@@ -42,8 +42,8 @@ Tag version and release title should be same as the new version, ...@@ -42,8 +42,8 @@ Tag version and release title should be same as the new version,
description should contain the release notes for the current release. description should contain the release notes for the current release.
Single header version of `catch.hpp` *needs* to be attached as a binary, Single header version of `catch.hpp` *needs* to be attached as a binary,
as that is where the official download link links to. Preferably as that is where the official download link links to. Preferably
it should use linux line endings. All non-bundled reporters (Automake, it should use linux line endings. All non-bundled reporters (Automake, TAP,
TAP, TeamCity) should also be attached as binaries, as they might be TeamCity, SonarQube) should also be attached as binaries, as they might be
dependent on a specific version of the single-include header. dependent on a specific version of the single-include header.
Since 2.5.0, the release tag and the "binaries" (headers) should be PGP Since 2.5.0, the release tag and the "binaries" (headers) should be PGP
...@@ -67,6 +67,7 @@ $ gpg2 --armor --output catch.hpp.asc --detach-sig catch.hpp ...@@ -67,6 +67,7 @@ $ gpg2 --armor --output catch.hpp.asc --detach-sig catch.hpp
$ gpg2 --armor --output catch_reporter_automake.hpp.asc --detach-sig catch_reporter_automake.hpp $ gpg2 --armor --output catch_reporter_automake.hpp.asc --detach-sig catch_reporter_automake.hpp
$ gpg2 --armor --output catch_reporter_teamcity.hpp.asc --detach-sig catch_reporter_teamcity.hpp $ gpg2 --armor --output catch_reporter_teamcity.hpp.asc --detach-sig catch_reporter_teamcity.hpp
$ gpg2 --armor --output catch_reporter_tap.hpp.asc --detach-sig catch_reporter_tap.hpp $ gpg2 --armor --output catch_reporter_tap.hpp.asc --detach-sig catch_reporter_tap.hpp
$ gpg2 --armor --output catch_reporter_sonarqube.hpp.asc --detach-sig catch_reporter_sonarqube.hpp
``` ```
_GPG does not support signing multiple files in single invocation._ _GPG does not support signing multiple files in single invocation._
...@@ -29,6 +29,7 @@ Do this in one source file - the same one you have `CATCH_CONFIG_MAIN` or `CATCH ...@@ -29,6 +29,7 @@ Do this in one source file - the same one you have `CATCH_CONFIG_MAIN` or `CATCH
Use this when building as part of a TeamCity build to see results as they happen ([code example](../examples/207-Rpt-TeamCityReporter.cpp)). Use this when building as part of a TeamCity build to see results as they happen ([code example](../examples/207-Rpt-TeamCityReporter.cpp)).
* `tap` writes in the TAP ([Test Anything Protocol](https://en.wikipedia.org/wiki/Test_Anything_Protocol)) format. * `tap` writes in the TAP ([Test Anything Protocol](https://en.wikipedia.org/wiki/Test_Anything_Protocol)) format.
* `automake` writes in a format that correspond to [automake .trs](https://www.gnu.org/software/automake/manual/html_node/Log-files-generation-and-test-results-recording.html) files * `automake` writes in a format that correspond to [automake .trs](https://www.gnu.org/software/automake/manual/html_node/Log-files-generation-and-test-results-recording.html) files
* `sonarqube` writes the [SonarQube Generic Test Data](https://docs.sonarqube.org/latest/analysis/generic-test/) XML format.
You see what reporters are available from the command line by running with `--list-reporters`. You see what reporters are available from the command line by running with `--list-reporters`.
......
...@@ -10,11 +10,12 @@ ...@@ -10,11 +10,12 @@
#define CATCH_CONFIG_MAIN #define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp> #include <catch2/catch.hpp>
class out_buff : public std::stringbuf { class out_buff : public std::stringbuf {
std::FILE* m_stream; std::FILE* m_stream;
public: public:
out_buff(std::FILE* stream) :m_stream(stream) {} out_buff(std::FILE* stream):m_stream(stream) {}
~out_buff() { pubsync(); } ~out_buff();
int sync() { int sync() {
int ret = 0; int ret = 0;
for (unsigned char c : str()) { for (unsigned char c : str()) {
...@@ -29,6 +30,12 @@ public: ...@@ -29,6 +30,12 @@ public:
} }
}; };
out_buff::~out_buff() { pubsync(); }
#if defined(__clang__)
#pragma clang diagnostic ignored "-Wexit-time-destructors" // static variables in cout/cerr/clog
#endif
namespace Catch { namespace Catch {
std::ostream& cout() { std::ostream& cout() {
static std::ostream ret(new out_buff(stdout)); static std::ostream ret(new out_buff(stdout));
......
...@@ -22,15 +22,17 @@ public: ...@@ -22,15 +22,17 @@ public:
} }
} }
std::string const& get() const override { std::string const& get() const override;
return m_line;
}
bool next() override { bool next() override {
return !!std::getline(m_stream, m_line); return !!std::getline(m_stream, m_line);
} }
}; };
std::string const& LineGenerator::get() const {
return m_line;
}
// This helper function provides a nicer UX when instantiating the generator // This helper function provides a nicer UX when instantiating the generator
// Notice that it returns an instance of GeneratorWrapper<std::string>, which // Notice that it returns an instance of GeneratorWrapper<std::string>, which
// is a value-wrapper around std::unique_ptr<IGenerator<std::string>>. // is a value-wrapper around std::unique_ptr<IGenerator<std::string>>.
......
...@@ -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 10 #define CATCH_VERSION_MINOR 11
#define CATCH_VERSION_PATCH 2 #define CATCH_VERSION_PATCH 0
#ifdef __clang__ #ifdef __clang__
# pragma clang system_header # pragma clang system_header
...@@ -80,7 +80,7 @@ ...@@ -80,7 +80,7 @@
#endif #endif
#if defined(CATCH_CONFIG_ENABLE_BENCHMARKING) #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
#include "internal/benchmark/catch_benchmark.hpp" #include "internal/benchmark/catch_benchmarking_all.hpp"
#endif #endif
#endif // ! CATCH_CONFIG_IMPL_ONLY #endif // ! CATCH_CONFIG_IMPL_ONLY
......
...@@ -79,7 +79,7 @@ namespace Catch { ...@@ -79,7 +79,7 @@ namespace Catch {
}); });
auto analysis = Detail::analyse(*cfg, env, samples.begin(), samples.end()); auto analysis = Detail::analyse(*cfg, env, samples.begin(), samples.end());
BenchmarkStats<std::chrono::duration<double, std::nano>> stats{ info, analysis.samples, analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance }; BenchmarkStats<FloatDuration<Clock>> stats{ info, analysis.samples, analysis.mean, analysis.standard_deviation, analysis.outliers, analysis.outlier_variance };
getResultCapture().benchmarkEnded(stats); getResultCapture().benchmarkEnded(stats);
} CATCH_CATCH_ALL{ } CATCH_CATCH_ALL{
......
/*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
// A proxy header that includes all of the benchmarking headers to allow
// concise include of the benchmarking features. You should prefer the
// individual includes in standard use.
#include "catch_benchmark.hpp"
#include "catch_chronometer.hpp"
#include "catch_clock.hpp"
#include "catch_constructor.hpp"
#include "catch_environment.hpp"
#include "catch_estimate.hpp"
#include "catch_execution_plan.hpp"
#include "catch_optimizer.hpp"
#include "catch_outlier_classification.hpp"
#include "catch_sample_analysis.hpp"
#include "detail/catch_analyse.hpp"
#include "detail/catch_benchmark_function.hpp"
#include "detail/catch_complete_invoke.hpp"
#include "detail/catch_estimate_clock.hpp"
#include "detail/catch_measure.hpp"
#include "detail/catch_repeat.hpp"
#include "detail/catch_run_for_at_least.hpp"
#include "detail/catch_stats.hpp"
#include "detail/catch_timing.hpp"
...@@ -176,9 +176,10 @@ namespace Catch { ...@@ -176,9 +176,10 @@ namespace Catch {
bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last) { bootstrap_analysis analyse_samples(double confidence_level, int n_resamples, std::vector<double>::iterator first, std::vector<double>::iterator last) {
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
static std::random_device entropy; static std::random_device entropy;
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
auto n = static_cast<int>(last - first); // seriously, one can't use integral types without hell in C++ auto n = static_cast<int>(last - first); // seriously, one can't use integral types without hell in C++
......
...@@ -43,9 +43,10 @@ ...@@ -43,9 +43,10 @@
do { \ do { \
Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \ Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
INTERNAL_CATCH_TRY { \ INTERNAL_CATCH_TRY { \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \ catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
INTERNAL_CATCH_REACT( catchAssertionHandler ) \ INTERNAL_CATCH_REACT( catchAssertionHandler ) \
} while( (void)0, (false) && static_cast<bool>( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look } while( (void)0, (false) && static_cast<bool>( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look
......
...@@ -43,38 +43,34 @@ ...@@ -43,38 +43,34 @@
# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
#endif #endif
#ifdef __clang__ // We have to avoid both ICC and Clang, because they try to mask themselves
// as gcc, and we want only GCC in this block
#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC)
# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" )
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" )
#endif
#if defined(__clang__)
# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" )
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" )
# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
_Pragma( "clang diagnostic push" ) \
_Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \
_Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"")
# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
_Pragma( "clang diagnostic pop" )
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
_Pragma( "clang diagnostic push" ) \
_Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) _Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
_Pragma( "clang diagnostic pop" )
# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ # define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \
_Pragma( "clang diagnostic push" ) \
_Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" )
# define CATCH_INTERNAL_UNSUPPRESS_UNUSED_WARNINGS \
_Pragma( "clang diagnostic pop" )
# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ # define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
_Pragma( "clang diagnostic push" ) \
_Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" )
# define CATCH_INTERNAL_UNSUPPRESS_ZERO_VARIADIC_WARNINGS \
_Pragma( "clang diagnostic pop" )
# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ # define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
_Pragma( "clang diagnostic push" ) \
_Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) _Pragma( "clang diagnostic ignored \"-Wunused-template\"" )
# define CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS \
_Pragma( "clang diagnostic pop" )
#endif // __clang__ #endif // __clang__
...@@ -133,8 +129,10 @@ ...@@ -133,8 +129,10 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Visual C++ // Visual C++
#ifdef _MSC_VER #if defined(_MSC_VER)
# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) )
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) )
# if _MSC_VER >= 1900 // Visual Studio 2015 or newer # if _MSC_VER >= 1900 // Visual Studio 2015 or newer
# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS # define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS
...@@ -309,34 +307,37 @@ ...@@ -309,34 +307,37 @@
# define CATCH_CONFIG_GLOBAL_NEXTAFTER # define CATCH_CONFIG_GLOBAL_NEXTAFTER
#endif #endif
// Even if we do not think the compiler has that warning, we still have
// to provide a macro that can be used by the code.
#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION)
# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
#endif
#if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION)
# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
#endif
#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) #if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS)
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS # define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
#endif #endif
#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) #if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS)
# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS # define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
#endif #endif
#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS) #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS)
# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS # define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS
# define CATCH_INTERNAL_UNSUPPRESS_UNUSED_WARNINGS
#endif #endif
#if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS) #if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS)
# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS # define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS
# define CATCH_INTERNAL_UNSUPPRESS_ZERO_VARIADIC_WARNINGS
#endif #endif
#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) #if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10)
# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS # undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
# undef CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS
#elif defined(__clang__) && (__clang_major__ < 5) #elif defined(__clang__) && (__clang_major__ < 5)
# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS # undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
# undef CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS
#endif #endif
#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS) #if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS)
# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS # define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS
# define CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS
#endif #endif
#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) #if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#define TWOBLUECUBES_CATCH_GENERATORS_GENERIC_HPP_INCLUDED #define TWOBLUECUBES_CATCH_GENERATORS_GENERIC_HPP_INCLUDED
#include "catch_generators.hpp" #include "catch_generators.hpp"
#include "catch_meta.hpp"
namespace Catch { namespace Catch {
namespace Generators { namespace Generators {
...@@ -172,18 +173,7 @@ namespace Generators { ...@@ -172,18 +173,7 @@ namespace Generators {
} }
}; };
#if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703 template <typename Func, typename U, typename T = FunctionReturnType<Func, U>>
// std::result_of is deprecated in C++17 and removed in C++20. Hence, it is
// replaced with std::invoke_result here. Also *_t format is preferred over
// typename *::type format.
template <typename Func, typename U>
using MapFunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U>>>;
#else
template <typename Func, typename U>
using MapFunctionReturnType = typename std::remove_reference<typename std::remove_cv<typename std::result_of<Func(U)>::type>::type>::type;
#endif
template <typename Func, typename U, typename T = MapFunctionReturnType<Func, U>>
GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) { GeneratorWrapper<T> map(Func&& function, GeneratorWrapper<U>&& generator) {
return GeneratorWrapper<T>( return GeneratorWrapper<T>(
pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator)) pf::make_unique<MapGenerator<T, U, Func>>(std::forward<Func>(function), std::move(generator))
......
...@@ -117,7 +117,7 @@ public: ...@@ -117,7 +117,7 @@ public:
template <typename T> template <typename T>
GeneratorWrapper<T> range(T const& start, T const& end, T const& step) { GeneratorWrapper<T> range(T const& start, T const& end, T const& step) {
static_assert(std::is_integral<T>::value && !std::is_same<T, bool>::value, "Type must be an integer"); static_assert(std::is_arithmetic<T>::value && !std::is_same<T, bool>::value, "Type must be numeric");
return GeneratorWrapper<T>(pf::make_unique<RangeGenerator<T>>(start, end, step)); return GeneratorWrapper<T>(pf::make_unique<RangeGenerator<T>>(start, end, step));
} }
......
...@@ -73,9 +73,10 @@ namespace Catch { ...@@ -73,9 +73,10 @@ namespace Catch {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \ #define INTERNAL_CATCH_TRANSLATE_EXCEPTION2( translatorName, signature ) \
static std::string translatorName( signature ); \ static std::string translatorName( signature ); \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \ namespace{ Catch::ExceptionTranslatorRegistrar INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionRegistrar )( &translatorName ); } \
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
static std::string translatorName( signature ) static std::string translatorName( signature )
#define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature ) #define INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION2( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
......
...@@ -12,22 +12,34 @@ ...@@ -12,22 +12,34 @@
#include <type_traits> #include <type_traits>
namespace Catch { namespace Catch {
template<typename T> template<typename T>
struct always_false : std::false_type {}; struct always_false : std::false_type {};
template <typename> struct true_given : std::true_type {}; template <typename> struct true_given : std::true_type {};
struct is_callable_tester { struct is_callable_tester {
template <typename Fun, typename... Args> template <typename Fun, typename... Args>
true_given<decltype(std::declval<Fun>()(std::declval<Args>()...))> static test(int); true_given<decltype(std::declval<Fun>()(std::declval<Args>()...))> static test(int);
template <typename...> template <typename...>
std::false_type static test(...); std::false_type static test(...);
}; };
template <typename T> template <typename T>
struct is_callable; struct is_callable;
template <typename Fun, typename... Args> template <typename Fun, typename... Args>
struct is_callable<Fun(Args...)> : decltype(is_callable_tester::test<Fun, Args...>(0)) {}; struct is_callable<Fun(Args...)> : decltype(is_callable_tester::test<Fun, Args...>(0)) {};
#if defined(__cpp_lib_is_invocable) && __cpp_lib_is_invocable >= 201703
// std::result_of is deprecated in C++17 and removed in C++20. Hence, it is
// replaced with std::invoke_result here. Also *_t format is preferred over
// typename *::type format.
template <typename Func, typename U>
using FunctionReturnType = std::remove_reference_t<std::remove_cv_t<std::invoke_result_t<Func, U>>>;
#else
template <typename Func, typename U>
using FunctionReturnType = typename std::remove_reference<typename std::remove_cv<typename std::result_of<Func(U)>::type>::type>::type;
#endif
} // namespace Catch } // namespace Catch
......
...@@ -58,14 +58,16 @@ namespace Catch { ...@@ -58,14 +58,16 @@ namespace Catch {
#if !defined(CATCH_CONFIG_DISABLE) #if !defined(CATCH_CONFIG_DISABLE)
#define CATCH_REGISTER_REPORTER( name, reporterType ) \ #define CATCH_REGISTER_REPORTER( name, reporterType ) \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } \ namespace{ Catch::ReporterRegistrar<reporterType> catch_internal_RegistrarFor##reporterType( name ); } \
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
#define CATCH_REGISTER_LISTENER( listenerType ) \ #define CATCH_REGISTER_LISTENER( listenerType ) \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } \ namespace{ Catch::ListenerRegistrar<listenerType> catch_internal_RegistrarFor##listenerType; } \
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
#else // CATCH_CONFIG_DISABLE #else // CATCH_CONFIG_DISABLE
#define CATCH_REGISTER_REPORTER(name, reporterType) #define CATCH_REGISTER_REPORTER(name, reporterType)
......
...@@ -37,13 +37,15 @@ namespace Catch { ...@@ -37,13 +37,15 @@ namespace Catch {
} // end namespace Catch } // end namespace Catch
#define INTERNAL_CATCH_SECTION( ... ) \ #define INTERNAL_CATCH_SECTION( ... ) \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \
if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) \ if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) \
CATCH_INTERNAL_UNSUPPRESS_UNUSED_WARNINGS CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
#define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \ #define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \
if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, (Catch::ReusableStringStream() << __VA_ARGS__).str() ) ) \ if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, (Catch::ReusableStringStream() << __VA_ARGS__).str() ) ) \
CATCH_INTERNAL_UNSUPPRESS_UNUSED_WARNINGS CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
#endif // TWOBLUECUBES_CATCH_SECTION_H_INCLUDED #endif // TWOBLUECUBES_CATCH_SECTION_H_INCLUDED
...@@ -9,6 +9,8 @@ ...@@ -9,6 +9,8 @@
#ifndef TWOBLUECUBES_CATCH_STREAM_H_INCLUDED #ifndef TWOBLUECUBES_CATCH_STREAM_H_INCLUDED
#define TWOBLUECUBES_CATCH_STREAM_H_INCLUDED #define TWOBLUECUBES_CATCH_STREAM_H_INCLUDED
#include "catch_common.h"
#include <iosfwd> #include <iosfwd>
#include <cstddef> #include <cstddef>
#include <ostream> #include <ostream>
...@@ -28,7 +30,7 @@ namespace Catch { ...@@ -28,7 +30,7 @@ namespace Catch {
auto makeStream( StringRef const &filename ) -> IStream const*; auto makeStream( StringRef const &filename ) -> IStream const*;
class ReusableStringStream { class ReusableStringStream : NonCopyable {
std::size_t m_index; std::size_t m_index;
std::ostream* m_oss; std::ostream* m_oss;
public: public:
......
...@@ -5,14 +5,10 @@ ...@@ -5,14 +5,10 @@
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/ */
#include "catch_enforce.h"
#if defined(__clang__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wexit-time-destructors"
#endif
#include "catch_stringref.h" #include "catch_stringref.h"
#include <algorithm>
#include <ostream> #include <ostream>
#include <cstring> #include <cstring>
#include <cstdint> #include <cstdint>
...@@ -22,63 +18,33 @@ namespace Catch { ...@@ -22,63 +18,33 @@ namespace Catch {
: StringRef( rawChars, static_cast<StringRef::size_type>(std::strlen(rawChars) ) ) : StringRef( rawChars, static_cast<StringRef::size_type>(std::strlen(rawChars) ) )
{} {}
void StringRef::swap( StringRef& other ) noexcept {
std::swap( m_start, other.m_start );
std::swap( m_size, other.m_size );
std::swap( m_data, other.m_data );
}
auto StringRef::c_str() const -> char const* { auto StringRef::c_str() const -> char const* {
if( !isSubstring() ) CATCH_ENFORCE(isNullTerminated(), "Called StringRef::c_str() on a non-null-terminated instance");
return m_start; return m_start;
const_cast<StringRef *>( this )->takeOwnership();
return m_data;
} }
auto StringRef::currentData() const noexcept -> char const* { auto StringRef::data() const noexcept -> char const* {
return m_start; return m_start;
} }
auto StringRef::isOwned() const noexcept -> bool {
return m_data != nullptr;
}
auto StringRef::isSubstring() const noexcept -> bool {
return m_start[m_size] != '\0';
}
void StringRef::takeOwnership() {
if( !isOwned() ) {
m_data = new char[m_size+1];
memcpy( m_data, m_start, m_size );
m_data[m_size] = '\0';
}
}
auto StringRef::substr( size_type start, size_type size ) const noexcept -> StringRef { auto StringRef::substr( size_type start, size_type size ) const noexcept -> StringRef {
if( start < m_size ) if (start < m_size) {
return StringRef( m_start+start, size ); return StringRef(m_start + start, (std::min)(m_size - start, size));
else } else {
return StringRef(); return StringRef();
} }
auto StringRef::operator == ( StringRef const& other ) const noexcept -> bool {
return
size() == other.size() &&
(std::strncmp( m_start, other.m_start, size() ) == 0);
} }
auto StringRef::operator != ( StringRef const& other ) const noexcept -> bool { auto StringRef::operator == ( StringRef const& other ) const noexcept -> bool {
return !operator==( other ); return m_size == other.m_size
&& (std::memcmp( m_start, other.m_start, m_size ) == 0);
} }
auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& { auto operator << ( std::ostream& os, StringRef const& str ) -> std::ostream& {
return os.write(str.currentData(), str.size()); return os.write(str.data(), str.size());
} }
auto operator+=( std::string& lhs, StringRef const& rhs ) -> std::string& { auto operator+=( std::string& lhs, StringRef const& rhs ) -> std::string& {
lhs.append(rhs.currentData(), rhs.size()); lhs.append(rhs.data(), rhs.size());
return lhs; return lhs;
} }
} // namespace Catch } // namespace Catch
#if defined(__clang__)
# pragma clang diagnostic pop
#endif
...@@ -16,49 +16,24 @@ namespace Catch { ...@@ -16,49 +16,24 @@ namespace Catch {
/// A non-owning string class (similar to the forthcoming std::string_view) /// A non-owning string class (similar to the forthcoming std::string_view)
/// Note that, because a StringRef may be a substring of another string, /// Note that, because a StringRef may be a substring of another string,
/// it may not be null terminated. c_str() must return a null terminated /// it may not be null terminated.
/// string, however, and so the StringRef will internally take ownership
/// (taking a copy), if necessary. In theory this ownership is not externally
/// visible - but it does mean (substring) StringRefs should not be shared between
/// threads.
class StringRef { class StringRef {
public: public:
using size_type = std::size_t; using size_type = std::size_t;
using const_iterator = const char*; using const_iterator = const char*;
private: private:
friend struct StringRefTestAccess;
char const* m_start;
size_type m_size;
char* m_data = nullptr;
void takeOwnership();
static constexpr char const* const s_empty = ""; static constexpr char const* const s_empty = "";
public: // construction/ assignment char const* m_start = s_empty;
StringRef() noexcept size_type m_size = 0;
: StringRef( s_empty, 0 )
{}
StringRef( StringRef const& other ) noexcept public: // construction
: m_start( other.m_start ), constexpr StringRef() noexcept = default;
m_size( other.m_size )
{}
StringRef( StringRef&& other ) noexcept
: m_start( other.m_start ),
m_size( other.m_size ),
m_data( other.m_data )
{
other.m_data = nullptr;
}
StringRef( char const* rawChars ) noexcept; StringRef( char const* rawChars ) noexcept;
StringRef( char const* rawChars, size_type size ) noexcept constexpr StringRef( char const* rawChars, size_type size ) noexcept
: m_start( rawChars ), : m_start( rawChars ),
m_size( size ) m_size( size )
{} {}
...@@ -68,27 +43,15 @@ namespace Catch { ...@@ -68,27 +43,15 @@ namespace Catch {
m_size( stdString.size() ) m_size( stdString.size() )
{} {}
~StringRef() noexcept {
delete[] m_data;
}
auto operator = ( StringRef const &other ) noexcept -> StringRef& {
delete[] m_data;
m_data = nullptr;
m_start = other.m_start;
m_size = other.m_size;
return *this;
}
explicit operator std::string() const { explicit operator std::string() const {
return std::string(m_start, m_size); return std::string(m_start, m_size);
} }
void swap( StringRef& other ) noexcept;
public: // operators public: // operators
auto operator == ( StringRef const& other ) const noexcept -> bool; auto operator == ( StringRef const& other ) const noexcept -> bool;
auto operator != ( StringRef const& other ) const noexcept -> bool; auto operator != (StringRef const& other) const noexcept -> bool {
return !(*this == other);
}
auto operator[] ( size_type index ) const noexcept -> char { auto operator[] ( size_type index ) const noexcept -> char {
assert(index < m_size); assert(index < m_size);
...@@ -96,42 +59,45 @@ namespace Catch { ...@@ -96,42 +59,45 @@ namespace Catch {
} }
public: // named queries public: // named queries
auto empty() const noexcept -> bool { constexpr auto empty() const noexcept -> bool {
return m_size == 0; return m_size == 0;
} }
auto size() const noexcept -> size_type { constexpr auto size() const noexcept -> size_type {
return m_size; return m_size;
} }
// Returns the current start pointer. If the StringRef is not
// null-terminated, throws std::domain_exception
auto c_str() const -> char const*; auto c_str() const -> char const*;
public: // substrings and searches public: // substrings and searches
auto substr( size_type start, size_type size ) const noexcept -> StringRef; // Returns a substring of [start, start + length).
// If start + length > size(), then the substring is [start, size()).
// If start > size(), then the substring is empty.
auto substr( size_type start, size_type length ) const noexcept -> StringRef;
// Returns the current start pointer. // Returns the current start pointer. May not be null-terminated.
// Note that the pointer can change when if the StringRef is a substring auto data() const noexcept -> char const*;
auto currentData() const noexcept -> char const*;
public: // iterators constexpr auto isNullTerminated() const noexcept -> bool {
const_iterator begin() const { return m_start; } return m_start[m_size] == '\0';
const_iterator end() const { return m_start + m_size; } }
private: // ownership queries - may not be consistent between calls public: // iterators
auto isOwned() const noexcept -> bool; constexpr const_iterator begin() const { return m_start; }
auto isSubstring() const noexcept -> bool; constexpr const_iterator end() const { return m_start + m_size; }
}; };
auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&;
auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&;
inline auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
return StringRef( rawChars, size ); return StringRef( rawChars, size );
} }
} // namespace Catch } // namespace Catch
inline auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef { constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef {
return Catch::StringRef( rawChars, size ); return Catch::StringRef( rawChars, size );
} }
......
...@@ -18,8 +18,9 @@ namespace Catch { ...@@ -18,8 +18,9 @@ namespace Catch {
} // end namespace Catch } // end namespace Catch
#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ #define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
#endif // TWOBLUECUBES_CATCH_TAG_ALIAS_AUTOREGISTRAR_H_INCLUDED #endif // TWOBLUECUBES_CATCH_TAG_ALIAS_AUTOREGISTRAR_H_INCLUDED
...@@ -105,21 +105,24 @@ struct AutoReg : NonCopyable { ...@@ -105,21 +105,24 @@ struct AutoReg : NonCopyable {
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \ #define INTERNAL_CATCH_TESTCASE2( TestName, ... ) \
static void TestName(); \ static void TestName(); \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \ namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &TestName ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
static void TestName() static void TestName()
#define INTERNAL_CATCH_TESTCASE( ... ) \ #define INTERNAL_CATCH_TESTCASE( ... ) \
INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ ) INTERNAL_CATCH_TESTCASE2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), __VA_ARGS__ )
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \ #define INTERNAL_CATCH_METHOD_AS_TEST_CASE( QualifiedMethod, ... ) \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \ namespace{ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( &QualifiedMethod ), CATCH_INTERNAL_LINEINFO, "&" #QualifiedMethod, Catch::NameAndTags{ __VA_ARGS__ } ); } /* NOLINT */ \
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\ #define INTERNAL_CATCH_TEST_CASE_METHOD2( TestName, ClassName, ... )\
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
namespace{ \ namespace{ \
struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \ struct TestName : INTERNAL_CATCH_REMOVE_PARENS(ClassName) { \
...@@ -127,19 +130,21 @@ struct AutoReg : NonCopyable { ...@@ -127,19 +130,21 @@ struct AutoReg : NonCopyable {
}; \ }; \
Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar ) ( Catch::makeTestInvoker( &TestName::test ), CATCH_INTERNAL_LINEINFO, #ClassName, Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
} \ } \
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
void TestName::test() void TestName::test()
#define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \ #define INTERNAL_CATCH_TEST_CASE_METHOD( ClassName, ... ) \
INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ ) INTERNAL_CATCH_TEST_CASE_METHOD2( INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), ClassName, __VA_ARGS__ )
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \ #define INTERNAL_CATCH_REGISTER_TESTCASE( Function, ... ) \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \ Catch::AutoReg INTERNAL_CATCH_UNIQUE_NAME( autoRegistrar )( Catch::makeTestInvoker( Function ), CATCH_INTERNAL_LINEINFO, Catch::StringRef(), Catch::NameAndTags{ __VA_ARGS__ } ); /* NOLINT */ \
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#define INTERNAL_CATCH_TEMPLATE_TEST_CASE_2(TestName, TestFunc, Name, Tags, Signature, ... )\ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_2(TestName, TestFunc, Name, Tags, Signature, ... )\
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
...@@ -164,9 +169,7 @@ struct AutoReg : NonCopyable { ...@@ -164,9 +169,7 @@ struct AutoReg : NonCopyable {
}();\ }();\
}\ }\
}\ }\
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_UNSUPPRESS_ZERO_VARIADIC_WARNINGS \
CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS \
INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature)) INTERNAL_CATCH_DEFINE_SIG_TEST(TestFunc,INTERNAL_CATCH_REMOVE_PARENS(Signature))
#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
...@@ -186,6 +189,7 @@ struct AutoReg : NonCopyable { ...@@ -186,6 +189,7 @@ struct AutoReg : NonCopyable {
#endif #endif
#define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(TestName, TestFuncName, Name, Tags, Signature, TmplTypes, TypesList) \ #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE2(TestName, TestFuncName, Name, Tags, Signature, TmplTypes, TypesList) \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
...@@ -213,9 +217,7 @@ struct AutoReg : NonCopyable { ...@@ -213,9 +217,7 @@ struct AutoReg : NonCopyable {
}(); \ }(); \
} \ } \
} \ } \
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_UNSUPPRESS_ZERO_VARIADIC_WARNINGS \
CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS \
template<typename TestType> \ template<typename TestType> \
static void TestFuncName() static void TestFuncName()
...@@ -236,6 +238,7 @@ struct AutoReg : NonCopyable { ...@@ -236,6 +238,7 @@ struct AutoReg : NonCopyable {
#endif #endif
#define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2(TestName, TestFunc, Name, Tags, TmplList)\ #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_2(TestName, TestFunc, Name, Tags, TmplList)\
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
template<typename TestType> static void TestFunc(); \ template<typename TestType> static void TestFunc(); \
...@@ -257,8 +260,7 @@ struct AutoReg : NonCopyable { ...@@ -257,8 +260,7 @@ struct AutoReg : NonCopyable {
return 0; \ return 0; \
}(); \ }(); \
}}\ }}\
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS \
template<typename TestType> \ template<typename TestType> \
static void TestFunc() static void TestFunc()
...@@ -267,6 +269,7 @@ struct AutoReg : NonCopyable { ...@@ -267,6 +269,7 @@ struct AutoReg : NonCopyable {
#define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \ #define INTERNAL_CATCH_TEMPLATE_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, Signature, ... ) \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
...@@ -291,9 +294,7 @@ struct AutoReg : NonCopyable { ...@@ -291,9 +294,7 @@ struct AutoReg : NonCopyable {
}();\ }();\
}\ }\
}\ }\
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS\ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_UNSUPPRESS_ZERO_VARIADIC_WARNINGS\
CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS\
INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature)) INTERNAL_CATCH_DEFINE_SIG_TEST_METHOD(TestName, INTERNAL_CATCH_REMOVE_PARENS(Signature))
#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR #ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR
...@@ -313,6 +314,7 @@ struct AutoReg : NonCopyable { ...@@ -313,6 +314,7 @@ struct AutoReg : NonCopyable {
#endif #endif
#define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2(TestNameClass, TestName, ClassName, Name, Tags, Signature, TmplTypes, TypesList)\ #define INTERNAL_CATCH_TEMPLATE_PRODUCT_TEST_CASE_METHOD_2(TestNameClass, TestName, ClassName, Name, Tags, Signature, TmplTypes, TypesList)\
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \
CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
...@@ -343,9 +345,7 @@ struct AutoReg : NonCopyable { ...@@ -343,9 +345,7 @@ struct AutoReg : NonCopyable {
}(); \ }(); \
}\ }\
}\ }\
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_UNSUPPRESS_ZERO_VARIADIC_WARNINGS \
CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS \
template<typename TestType> \ template<typename TestType> \
void TestName<TestType>::test() void TestName<TestType>::test()
...@@ -366,6 +366,7 @@ struct AutoReg : NonCopyable { ...@@ -366,6 +366,7 @@ struct AutoReg : NonCopyable {
#endif #endif
#define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, TmplList) \ #define INTERNAL_CATCH_TEMPLATE_LIST_TEST_CASE_METHOD_2( TestNameClass, TestName, ClassName, Name, Tags, TmplList) \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \
template<typename TestType> \ template<typename TestType> \
...@@ -390,8 +391,7 @@ struct AutoReg : NonCopyable { ...@@ -390,8 +391,7 @@ struct AutoReg : NonCopyable {
return 0;\ return 0;\
}(); \ }(); \
}}\ }}\
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \ CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_UNSUPPRESS_UNUSED_TEMPLATE_WARNINGS \
template<typename TestType> \ template<typename TestType> \
void TestName<TestType>::test() void TestName<TestType>::test()
......
...@@ -113,9 +113,9 @@ namespace Catch { ...@@ -113,9 +113,9 @@ namespace Catch {
switch( m_mode ) { switch( m_mode ) {
case Name: case Name:
case QuotedName: case QuotedName:
return addPattern<TestSpec::NamePattern>(); return addNamePattern();
case Tag: case Tag:
return addPattern<TestSpec::TagPattern>(); return addTagPattern();
case EscapedName: case EscapedName:
revertBackToLastMode(); revertBackToLastMode();
return; return;
...@@ -175,6 +175,62 @@ namespace Catch { ...@@ -175,6 +175,62 @@ namespace Catch {
return true; //success return true; //success
} }
std::string TestSpecParser::preprocessPattern() {
std::string token = m_patternName;
for (std::size_t i = 0; i < m_escapeChars.size(); ++i)
token = token.substr(0, m_escapeChars[i] - i) + token.substr(m_escapeChars[i] - i + 1);
m_escapeChars.clear();
if (startsWith(token, "exclude:")) {
m_exclusion = true;
token = token.substr(8);
}
m_patternName.clear();
return token;
}
void TestSpecParser::addNamePattern() {
auto token = preprocessPattern();
if (!token.empty()) {
TestSpec::PatternPtr pattern = std::make_shared<TestSpec::NamePattern>(token, m_substring);
if (m_exclusion)
pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern);
m_currentFilter.m_patterns.push_back(pattern);
}
m_substring.clear();
m_exclusion = false;
m_mode = None;
}
void TestSpecParser::addTagPattern() {
auto token = preprocessPattern();
if (!token.empty()) {
// If the tag pattern is the "hide and tag" shorthand (e.g. [.foo])
// we have to create a separate hide tag and shorten the real one
if (token.size() > 1 && token[0] == '.') {
token.erase(token.begin());
TestSpec::PatternPtr pattern = std::make_shared<TestSpec::TagPattern>(".", m_substring);
if (m_exclusion) {
pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern);
}
m_currentFilter.m_patterns.push_back(pattern);
}
TestSpec::PatternPtr pattern = std::make_shared<TestSpec::TagPattern>(token, m_substring);
if (m_exclusion) {
pattern = std::make_shared<TestSpec::ExcludedPattern>(pattern);
}
m_currentFilter.m_patterns.push_back(pattern);
}
m_substring.clear();
m_exclusion = false;
m_mode = None;
}
TestSpec parseTestSpec( std::string const& arg ) { TestSpec parseTestSpec( std::string const& arg ) {
return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec(); return TestSpecParser( ITagAliasRegistry::get() ).parse( arg ).testSpec();
} }
......
...@@ -54,27 +54,12 @@ namespace Catch { ...@@ -54,27 +54,12 @@ namespace Catch {
void addFilter(); void addFilter();
bool separate(); bool separate();
template<typename T> // Handles common preprocessing of the pattern for name/tag patterns
void addPattern() { std::string preprocessPattern();
std::string token = m_patternName; // Adds the current pattern as a test name
for( std::size_t i = 0; i < m_escapeChars.size(); ++i ) void addNamePattern();
token = token.substr( 0, m_escapeChars[i] - i ) + token.substr( m_escapeChars[i] -i +1 ); // Adds the current pattern as a tag
m_escapeChars.clear(); void addTagPattern();
if( startsWith( token, "exclude:" ) ) {
m_exclusion = true;
token = token.substr( 8 );
}
if( !token.empty() ) {
TestSpec::PatternPtr pattern = std::make_shared<T>( token, m_substring );
if( m_exclusion )
pattern = std::make_shared<TestSpec::ExcludedPattern>( pattern );
m_currentFilter.m_patterns.push_back( pattern );
}
m_substring.clear();
m_patternName.clear();
m_exclusion = false;
m_mode = None;
}
inline void addCharToPattern(char c) { inline void addCharToPattern(char c) {
m_substring += c; m_substring += c;
......
...@@ -38,13 +38,11 @@ namespace Detail { ...@@ -38,13 +38,11 @@ namespace Detail {
enum Arch { Big, Little }; enum Arch { Big, Little };
static Arch which() { static Arch which() {
union _{ int one = 1;
int asInt; // If the lowest byte we read is non-zero, we can assume
char asChar[sizeof (int)]; // that little endian format is used.
} u; auto value = *reinterpret_cast<char*>(&one);
return value ? Little : Big;
u.asInt = 1;
return ( u.asChar[sizeof(int)-1] == 1 ) ? Big : Little;
} }
}; };
} }
......
...@@ -37,7 +37,7 @@ namespace Catch { ...@@ -37,7 +37,7 @@ namespace Catch {
} }
Version const& libraryVersion() { Version const& libraryVersion() {
static Version version( 2, 10, 2, "", 0 ); static Version version( 2, 11, 0, "", 0 );
return version; return version;
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "catch_enforce.h" #include "catch_enforce.h"
#include <iomanip> #include <iomanip>
#include <type_traits>
using uchar = unsigned char; using uchar = unsigned char;
...@@ -51,8 +52,31 @@ namespace { ...@@ -51,8 +52,31 @@ namespace {
os.flags(f); os.flags(f);
} }
bool shouldNewline(XmlFormatting fmt) {
return !!(static_cast<std::underlying_type<XmlFormatting>::type>(fmt & XmlFormatting::Newline));
}
bool shouldIndent(XmlFormatting fmt) {
return !!(static_cast<std::underlying_type<XmlFormatting>::type>(fmt & XmlFormatting::Indent));
}
} // anonymous namespace } // anonymous namespace
XmlFormatting operator | (XmlFormatting lhs, XmlFormatting rhs) {
return static_cast<XmlFormatting>(
static_cast<std::underlying_type<XmlFormatting>::type>(lhs) |
static_cast<std::underlying_type<XmlFormatting>::type>(rhs)
);
}
XmlFormatting operator & (XmlFormatting lhs, XmlFormatting rhs) {
return static_cast<XmlFormatting>(
static_cast<std::underlying_type<XmlFormatting>::type>(lhs) &
static_cast<std::underlying_type<XmlFormatting>::type>(rhs)
);
}
XmlEncode::XmlEncode( std::string const& str, ForWhat forWhat ) XmlEncode::XmlEncode( std::string const& str, ForWhat forWhat )
: m_str( str ), : m_str( str ),
m_forWhat( forWhat ) m_forWhat( forWhat )
...@@ -157,13 +181,17 @@ namespace { ...@@ -157,13 +181,17 @@ namespace {
return os; return os;
} }
XmlWriter::ScopedElement::ScopedElement( XmlWriter* writer ) XmlWriter::ScopedElement::ScopedElement( XmlWriter* writer, XmlFormatting fmt )
: m_writer( writer ) : m_writer( writer ),
m_fmt(fmt)
{} {}
XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) noexcept XmlWriter::ScopedElement::ScopedElement( ScopedElement&& other ) noexcept
: m_writer( other.m_writer ){ : m_writer( other.m_writer ),
m_fmt(other.m_fmt)
{
other.m_writer = nullptr; other.m_writer = nullptr;
other.m_fmt = XmlFormatting::None;
} }
XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) noexcept { XmlWriter::ScopedElement& XmlWriter::ScopedElement::operator=( ScopedElement&& other ) noexcept {
if ( m_writer ) { if ( m_writer ) {
...@@ -171,17 +199,20 @@ namespace { ...@@ -171,17 +199,20 @@ namespace {
} }
m_writer = other.m_writer; m_writer = other.m_writer;
other.m_writer = nullptr; other.m_writer = nullptr;
m_fmt = other.m_fmt;
other.m_fmt = XmlFormatting::None;
return *this; return *this;
} }
XmlWriter::ScopedElement::~ScopedElement() { XmlWriter::ScopedElement::~ScopedElement() {
if( m_writer ) if (m_writer) {
m_writer->endElement(); m_writer->endElement(m_fmt);
}
} }
XmlWriter::ScopedElement& XmlWriter::ScopedElement::writeText( std::string const& text, bool indent ) { XmlWriter::ScopedElement& XmlWriter::ScopedElement::writeText( std::string const& text, XmlFormatting fmt ) {
m_writer->writeText( text, indent ); m_writer->writeText( text, fmt );
return *this; return *this;
} }
...@@ -191,37 +222,47 @@ namespace { ...@@ -191,37 +222,47 @@ namespace {
} }
XmlWriter::~XmlWriter() { XmlWriter::~XmlWriter() {
while( !m_tags.empty() ) while (!m_tags.empty()) {
endElement(); endElement();
} }
newlineIfNecessary();
}
XmlWriter& XmlWriter::startElement( std::string const& name ) { XmlWriter& XmlWriter::startElement( std::string const& name, XmlFormatting fmt ) {
ensureTagClosed(); ensureTagClosed();
newlineIfNecessary(); newlineIfNecessary();
m_os << m_indent << '<' << name; if (shouldIndent(fmt)) {
m_tags.push_back( name ); m_os << m_indent;
m_indent += " "; m_indent += " ";
}
m_os << '<' << name;
m_tags.push_back( name );
m_tagIsOpen = true; m_tagIsOpen = true;
applyFormatting(fmt);
return *this; return *this;
} }
XmlWriter::ScopedElement XmlWriter::scopedElement( std::string const& name ) { XmlWriter::ScopedElement XmlWriter::scopedElement( std::string const& name, XmlFormatting fmt ) {
ScopedElement scoped( this ); ScopedElement scoped( this, fmt );
startElement( name ); startElement( name, fmt );
return scoped; return scoped;
} }
XmlWriter& XmlWriter::endElement() { XmlWriter& XmlWriter::endElement(XmlFormatting fmt) {
newlineIfNecessary(); m_indent = m_indent.substr(0, m_indent.size() - 2);
m_indent = m_indent.substr( 0, m_indent.size()-2 );
if( m_tagIsOpen ) { if( m_tagIsOpen ) {
m_os << "/>"; m_os << "/>";
m_tagIsOpen = false; m_tagIsOpen = false;
} else {
newlineIfNecessary();
if (shouldIndent(fmt)) {
m_os << m_indent;
} }
else { m_os << "</" << m_tags.back() << ">";
m_os << m_indent << "</" << m_tags.back() << ">";
} }
m_os << std::endl; m_os << std::flush;
applyFormatting(fmt);
m_tags.pop_back(); m_tags.pop_back();
return *this; return *this;
} }
...@@ -237,22 +278,26 @@ namespace { ...@@ -237,22 +278,26 @@ namespace {
return *this; return *this;
} }
XmlWriter& XmlWriter::writeText( std::string const& text, bool indent ) { XmlWriter& XmlWriter::writeText( std::string const& text, XmlFormatting fmt) {
if( !text.empty() ){ if( !text.empty() ){
bool tagWasOpen = m_tagIsOpen; bool tagWasOpen = m_tagIsOpen;
ensureTagClosed(); ensureTagClosed();
if( tagWasOpen && indent ) if (tagWasOpen && shouldIndent(fmt)) {
m_os << m_indent; m_os << m_indent;
}
m_os << XmlEncode( text ); m_os << XmlEncode( text );
m_needsNewline = true; applyFormatting(fmt);
} }
return *this; return *this;
} }
XmlWriter& XmlWriter::writeComment( std::string const& text ) { XmlWriter& XmlWriter::writeComment( std::string const& text, XmlFormatting fmt) {
ensureTagClosed(); ensureTagClosed();
m_os << m_indent << "<!--" << text << "-->"; if (shouldIndent(fmt)) {
m_needsNewline = true; m_os << m_indent;
}
m_os << "<!--" << text << "-->";
applyFormatting(fmt);
return *this; return *this;
} }
...@@ -268,11 +313,16 @@ namespace { ...@@ -268,11 +313,16 @@ namespace {
void XmlWriter::ensureTagClosed() { void XmlWriter::ensureTagClosed() {
if( m_tagIsOpen ) { if( m_tagIsOpen ) {
m_os << ">" << std::endl; m_os << '>' << std::flush;
newlineIfNecessary();
m_tagIsOpen = false; m_tagIsOpen = false;
} }
} }
void XmlWriter::applyFormatting(XmlFormatting fmt) {
m_needsNewline = shouldNewline(fmt);
}
void XmlWriter::writeDeclaration() { void XmlWriter::writeDeclaration() {
m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; m_os << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
} }
......
...@@ -14,6 +14,14 @@ ...@@ -14,6 +14,14 @@
#include <vector> #include <vector>
namespace Catch { namespace Catch {
enum class XmlFormatting {
None = 0x00,
Indent = 0x01,
Newline = 0x02,
};
XmlFormatting operator | (XmlFormatting lhs, XmlFormatting rhs);
XmlFormatting operator & (XmlFormatting lhs, XmlFormatting rhs);
class XmlEncode { class XmlEncode {
public: public:
...@@ -35,14 +43,14 @@ namespace Catch { ...@@ -35,14 +43,14 @@ namespace Catch {
class ScopedElement { class ScopedElement {
public: public:
ScopedElement( XmlWriter* writer ); ScopedElement( XmlWriter* writer, XmlFormatting fmt );
ScopedElement( ScopedElement&& other ) noexcept; ScopedElement( ScopedElement&& other ) noexcept;
ScopedElement& operator=( ScopedElement&& other ) noexcept; ScopedElement& operator=( ScopedElement&& other ) noexcept;
~ScopedElement(); ~ScopedElement();
ScopedElement& writeText( std::string const& text, bool indent = true ); ScopedElement& writeText( std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent );
template<typename T> template<typename T>
ScopedElement& writeAttribute( std::string const& name, T const& attribute ) { ScopedElement& writeAttribute( std::string const& name, T const& attribute ) {
...@@ -52,6 +60,7 @@ namespace Catch { ...@@ -52,6 +60,7 @@ namespace Catch {
private: private:
mutable XmlWriter* m_writer = nullptr; mutable XmlWriter* m_writer = nullptr;
XmlFormatting m_fmt;
}; };
XmlWriter( std::ostream& os = Catch::cout() ); XmlWriter( std::ostream& os = Catch::cout() );
...@@ -60,11 +69,11 @@ namespace Catch { ...@@ -60,11 +69,11 @@ namespace Catch {
XmlWriter( XmlWriter const& ) = delete; XmlWriter( XmlWriter const& ) = delete;
XmlWriter& operator=( XmlWriter const& ) = delete; XmlWriter& operator=( XmlWriter const& ) = delete;
XmlWriter& startElement( std::string const& name ); XmlWriter& startElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
ScopedElement scopedElement( std::string const& name ); ScopedElement scopedElement( std::string const& name, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
XmlWriter& endElement(); XmlWriter& endElement(XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
XmlWriter& writeAttribute( std::string const& name, std::string const& attribute ); XmlWriter& writeAttribute( std::string const& name, std::string const& attribute );
...@@ -77,9 +86,9 @@ namespace Catch { ...@@ -77,9 +86,9 @@ namespace Catch {
return writeAttribute( name, rss.str() ); return writeAttribute( name, rss.str() );
} }
XmlWriter& writeText( std::string const& text, bool indent = true ); XmlWriter& writeText( std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
XmlWriter& writeComment( std::string const& text ); XmlWriter& writeComment(std::string const& text, XmlFormatting fmt = XmlFormatting::Newline | XmlFormatting::Indent);
void writeStylesheetRef( std::string const& url ); void writeStylesheetRef( std::string const& url );
...@@ -89,6 +98,8 @@ namespace Catch { ...@@ -89,6 +98,8 @@ namespace Catch {
private: private:
void applyFormatting(XmlFormatting fmt);
void writeDeclaration(); void writeDeclaration();
void newlineIfNecessary(); void newlineIfNecessary();
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "../internal/catch_tostring.h" #include "../internal/catch_tostring.h"
#include "../internal/catch_reporter_registrars.hpp" #include "../internal/catch_reporter_registrars.hpp"
#include "../internal/catch_text.h"
#include <cassert> #include <cassert>
#include <sstream> #include <sstream>
...@@ -146,8 +147,8 @@ namespace Catch { ...@@ -146,8 +147,8 @@ namespace Catch {
for( auto const& child : groupNode.children ) for( auto const& child : groupNode.children )
writeTestCase( *child ); writeTestCase( *child );
xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite ), false ); xml.scopedElement( "system-out" ).writeText( trim( stdOutForSuite ), XmlFormatting::Newline );
xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite ), false ); xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite ), XmlFormatting::Newline );
} }
void JunitReporter::writeTestCase( TestCaseNode const& testCaseNode ) { void JunitReporter::writeTestCase( TestCaseNode const& testCaseNode ) {
...@@ -196,9 +197,9 @@ namespace Catch { ...@@ -196,9 +197,9 @@ namespace Catch {
writeAssertions( sectionNode ); writeAssertions( sectionNode );
if( !sectionNode.stdOut.empty() ) if( !sectionNode.stdOut.empty() )
xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false ); xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), XmlFormatting::Newline );
if( !sectionNode.stdErr.empty() ) if( !sectionNode.stdErr.empty() )
xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false ); xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), XmlFormatting::Newline );
} }
for( auto const& childNode : sectionNode.childSections ) for( auto const& childNode : sectionNode.childSections )
if( className.empty() ) if( className.empty() )
...@@ -244,10 +245,25 @@ namespace Catch { ...@@ -244,10 +245,25 @@ namespace Catch {
XmlWriter::ScopedElement e = xml.scopedElement( elementName ); XmlWriter::ScopedElement e = xml.scopedElement( elementName );
xml.writeAttribute( "message", result.getExpandedExpression() ); xml.writeAttribute( "message", result.getExpression() );
xml.writeAttribute( "type", result.getTestMacroName() ); xml.writeAttribute( "type", result.getTestMacroName() );
ReusableStringStream rss; ReusableStringStream rss;
if (stats.totals.assertions.total() > 0) {
rss << "FAILED" << ":\n";
if (result.hasExpression()) {
rss << " ";
rss << result.getExpressionInMacro();
rss << '\n';
}
if (result.hasExpandedExpression()) {
rss << "with expansion:\n";
rss << Column(result.getExpandedExpression()).indent(2) << '\n';
}
} else {
rss << '\n';
}
if( !result.getMessage().empty() ) if( !result.getMessage().empty() )
rss << result.getMessage() << '\n'; rss << result.getMessage() << '\n';
for( auto const& msg : stats.infoMessages ) for( auto const& msg : stats.infoMessages )
...@@ -255,7 +271,7 @@ namespace Catch { ...@@ -255,7 +271,7 @@ namespace Catch {
rss << msg.message << '\n'; rss << msg.message << '\n';
rss << "at " << result.getSourceInfo(); rss << "at " << result.getSourceInfo();
xml.writeText( rss.str(), false ); xml.writeText( rss.str(), XmlFormatting::Newline );
} }
} }
......
/*
* Created by Daniel Garcia on 2018-12-04.
* Copyright Social Point SL. All rights reserved.
*
* Distributed under the Boost Software License, Version 1.0. (See accompanying
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef CATCH_REPORTER_SONARQUBE_HPP_INCLUDED
#define CATCH_REPORTER_SONARQUBE_HPP_INCLUDED
// Don't #include any Catch headers here - we can assume they are already
// included before this header.
// This is not good practice in general but is necessary in this case so this
// file can be distributed as a single header that works with the main
// Catch single header.
#include <map>
namespace Catch {
struct SonarQubeReporter : CumulativeReporterBase<SonarQubeReporter> {
SonarQubeReporter(ReporterConfig const& config)
: CumulativeReporterBase(config)
, xml(config.stream()) {
m_reporterPrefs.shouldRedirectStdOut = true;
m_reporterPrefs.shouldReportAllAssertions = true;
}
~SonarQubeReporter() override;
static std::string getDescription() {
return "Reports test results in the Generic Test Data SonarQube XML format";
}
static std::set<Verbosity> getSupportedVerbosities() {
return { Verbosity::Normal };
}
void noMatchingTestCases(std::string const& /*spec*/) override {}
void testRunStarting(TestRunInfo const& testRunInfo) override {
CumulativeReporterBase::testRunStarting(testRunInfo);
xml.startElement("testExecutions");
xml.writeAttribute("version", "1");
}
void testGroupEnded(TestGroupStats const& testGroupStats) override {
CumulativeReporterBase::testGroupEnded(testGroupStats);
writeGroup(*m_testGroups.back());
}
void testRunEndedCumulative() override {
xml.endElement();
}
void writeGroup(TestGroupNode const& groupNode) {
std::map<std::string, TestGroupNode::ChildNodes> testsPerFile;
for(auto const& child : groupNode.children)
testsPerFile[child->value.testInfo.lineInfo.file].push_back(child);
for(auto const& kv : testsPerFile)
writeTestFile(kv.first.c_str(), kv.second);
}
void writeTestFile(const char* filename, TestGroupNode::ChildNodes const& testCaseNodes) {
XmlWriter::ScopedElement e = xml.scopedElement("file");
xml.writeAttribute("path", filename);
for(auto const& child : testCaseNodes)
writeTestCase(*child);
}
void writeTestCase(TestCaseNode const& testCaseNode) {
// All test cases have exactly one section - which represents the
// test case itself. That section may have 0-n nested sections
assert(testCaseNode.children.size() == 1);
SectionNode const& rootSection = *testCaseNode.children.front();
writeSection("", rootSection, testCaseNode.value.testInfo.okToFail());
}
void writeSection(std::string const& rootName, SectionNode const& sectionNode, bool okToFail) {
std::string name = trim(sectionNode.stats.sectionInfo.name);
if(!rootName.empty())
name = rootName + '/' + name;
if(!sectionNode.assertions.empty() || !sectionNode.stdOut.empty() || !sectionNode.stdErr.empty()) {
XmlWriter::ScopedElement e = xml.scopedElement("testCase");
xml.writeAttribute("name", name);
xml.writeAttribute("duration", static_cast<long>(sectionNode.stats.durationInSeconds * 1000));
writeAssertions(sectionNode, okToFail);
}
for(auto const& childNode : sectionNode.childSections)
writeSection(name, *childNode, okToFail);
}
void writeAssertions(SectionNode const& sectionNode, bool okToFail) {
for(auto const& assertion : sectionNode.assertions)
writeAssertion( assertion, okToFail);
}
void writeAssertion(AssertionStats const& stats, bool okToFail) {
AssertionResult const& result = stats.assertionResult;
if(!result.isOk()) {
std::string elementName;
if(okToFail) {
elementName = "skipped";
}
else {
switch(result.getResultType()) {
case ResultWas::ThrewException:
case ResultWas::FatalErrorCondition:
elementName = "error";
break;
case ResultWas::ExplicitFailure:
elementName = "failure";
break;
case ResultWas::ExpressionFailed:
elementName = "failure";
break;
case ResultWas::DidntThrowException:
elementName = "failure";
break;
// We should never see these here:
case ResultWas::Info:
case ResultWas::Warning:
case ResultWas::Ok:
case ResultWas::Unknown:
case ResultWas::FailureBit:
case ResultWas::Exception:
elementName = "internalError";
break;
}
}
XmlWriter::ScopedElement e = xml.scopedElement(elementName);
ReusableStringStream messageRss;
messageRss << result.getTestMacroName() << "(" << result.getExpression() << ")";
xml.writeAttribute("message", messageRss.str());
ReusableStringStream textRss;
if (stats.totals.assertions.total() > 0) {
textRss << "FAILED:\n";
if (result.hasExpression()) {
textRss << "\t" << result.getExpressionInMacro() << "\n";
}
if (result.hasExpandedExpression()) {
textRss << "with expansion:\n\t" << result.getExpandedExpression() << "\n";
}
}
if(!result.getMessage().empty())
textRss << result.getMessage() << "\n";
for(auto const& msg : stats.infoMessages)
if(msg.type == ResultWas::Info)
textRss << msg.message << "\n";
textRss << "at " << result.getSourceInfo();
xml.writeText(textRss.str(), XmlFormatting::Newline);
}
}
private:
XmlWriter xml;
};
#ifdef CATCH_IMPL
SonarQubeReporter::~SonarQubeReporter() {}
#endif
CATCH_REGISTER_REPORTER( "sonarqube", SonarQubeReporter )
} // end namespace Catch
#endif // CATCH_REPORTER_SONARQUBE_HPP_INCLUDED
\ No newline at end of file
...@@ -193,9 +193,9 @@ namespace Catch { ...@@ -193,9 +193,9 @@ namespace Catch {
e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() ); e.writeAttribute( "durationInSeconds", m_testCaseTimer.getElapsedSeconds() );
if( !testCaseStats.stdOut.empty() ) if( !testCaseStats.stdOut.empty() )
m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), false ); m_xml.scopedElement( "StdOut" ).writeText( trim( testCaseStats.stdOut ), XmlFormatting::Newline );
if( !testCaseStats.stdErr.empty() ) if( !testCaseStats.stdErr.empty() )
m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), false ); m_xml.scopedElement( "StdErr" ).writeText( trim( testCaseStats.stdErr ), XmlFormatting::Newline );
m_xml.endElement(); m_xml.endElement();
} }
......
...@@ -282,6 +282,7 @@ set(REPORTER_HEADERS ...@@ -282,6 +282,7 @@ set(REPORTER_HEADERS
${HEADER_DIR}/reporters/catch_reporter_tap.hpp ${HEADER_DIR}/reporters/catch_reporter_tap.hpp
${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp ${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
${HEADER_DIR}/reporters/catch_reporter_xml.h ${HEADER_DIR}/reporters/catch_reporter_xml.h
${HEADER_DIR}/reporters/catch_reporter_sonarqube.hpp
) )
set(REPORTER_SOURCES set(REPORTER_SOURCES
${HEADER_DIR}/reporters/catch_reporter_bases.cpp ${HEADER_DIR}/reporters/catch_reporter_bases.cpp
......
...@@ -26,14 +26,6 @@ TEST_CASE("Benchmark factorial", "[benchmark]") { ...@@ -26,14 +26,6 @@ TEST_CASE("Benchmark factorial", "[benchmark]") {
BENCHMARK("factorial 14") { BENCHMARK("factorial 14") {
return factorial(14); return factorial(14);
}; };
//
// BENCHMARK("factorial 20") {
// return factorial(20);
// };
//
// BENCHMARK("factorial 35") {
// return factorial(35);
// };
} }
TEST_CASE("Benchmark containers", "[.][benchmark]") { TEST_CASE("Benchmark containers", "[.][benchmark]") {
......
...@@ -1381,5 +1381,5 @@ due to unexpected exception with message: ...@@ -1381,5 +1381,5 @@ due to unexpected exception with message:
=============================================================================== ===============================================================================
test cases: 304 | 230 passed | 70 failed | 4 failed as expected test cases: 304 | 230 passed | 70 failed | 4 failed as expected
assertions: 1621 | 1469 passed | 131 failed | 21 failed as expected assertions: 1659 | 1507 passed | 131 failed | 21 failed as expected
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
inline Catch::TestCase fakeTestCase(const char* name, const char* desc = "") { return Catch::makeTestCase(nullptr, "", { name, desc }, CATCH_INTERNAL_LINEINFO); } inline Catch::TestCase fakeTestCase(const char* name, const char* desc = "") { return Catch::makeTestCase(nullptr, "", { name, desc }, CATCH_INTERNAL_LINEINFO); }
TEST_CASE( "Parse test names and tags" ) { TEST_CASE( "Parse test names and tags", "[command-line][test-spec]" ) {
using Catch::parseTestSpec; using Catch::parseTestSpec;
using Catch::TestSpec; using Catch::TestSpec;
...@@ -269,7 +269,6 @@ TEST_CASE( "Parse test names and tags" ) { ...@@ -269,7 +269,6 @@ TEST_CASE( "Parse test names and tags" ) {
CHECK( spec.matches( fakeTestCase( " aardvark " ) ) ); CHECK( spec.matches( fakeTestCase( " aardvark " ) ) );
CHECK( spec.matches( fakeTestCase( "aardvark " ) ) ); CHECK( spec.matches( fakeTestCase( "aardvark " ) ) );
CHECK( spec.matches( fakeTestCase( "aardvark" ) ) ); CHECK( spec.matches( fakeTestCase( "aardvark" ) ) );
} }
SECTION( "Leading and trailing spaces in test name" ) { SECTION( "Leading and trailing spaces in test name" ) {
TestSpec spec = parseTestSpec( "aardvark" ); TestSpec spec = parseTestSpec( "aardvark" );
...@@ -278,7 +277,18 @@ TEST_CASE( "Parse test names and tags" ) { ...@@ -278,7 +277,18 @@ TEST_CASE( "Parse test names and tags" ) {
CHECK( spec.matches( fakeTestCase( " aardvark " ) ) ); CHECK( spec.matches( fakeTestCase( " aardvark " ) ) );
CHECK( spec.matches( fakeTestCase( "aardvark " ) ) ); CHECK( spec.matches( fakeTestCase( "aardvark " ) ) );
CHECK( spec.matches( fakeTestCase( "aardvark" ) ) ); CHECK( spec.matches( fakeTestCase( "aardvark" ) ) );
}
SECTION("Shortened hide tags are split apart when parsing") {
TestSpec spec = parseTestSpec("[.foo]");
CHECK(spec.matches(fakeTestCase("hidden and foo", "[.][foo]")));
CHECK_FALSE(spec.matches(fakeTestCase("only foo", "[foo]")));
}
SECTION("Shortened hide tags also properly handle exclusion") {
TestSpec spec = parseTestSpec("~[.foo]");
CHECK_FALSE(spec.matches(fakeTestCase("hidden and foo", "[.][foo]")));
CHECK_FALSE(spec.matches(fakeTestCase("only foo", "[foo]")));
CHECK_FALSE(spec.matches(fakeTestCase("only hidden", "[.]")));
CHECK(spec.matches(fakeTestCase("neither foo nor hidden", "[bar]")));
} }
} }
......
...@@ -173,6 +173,58 @@ TEST_CASE("Generators internals", "[generators][internals]") { ...@@ -173,6 +173,58 @@ TEST_CASE("Generators internals", "[generators][internals]") {
REQUIRE_FALSE(gen.next()); REQUIRE_FALSE(gen.next());
} }
} }
SECTION("Floating Point") {
SECTION("Exact") {
const auto rangeStart = -1.;
const auto rangeEnd = 1.;
const auto step = .1;
auto gen = range(rangeStart, rangeEnd, step);
auto expected = rangeStart;
while( (rangeEnd - expected) > step ) {
INFO( "Current expected value is " << expected )
REQUIRE(gen.get() == Approx(expected));
REQUIRE(gen.next());
expected += step;
}
REQUIRE(gen.get() == Approx( rangeEnd ) );
REQUIRE_FALSE(gen.next());
}
SECTION("Slightly over end") {
const auto rangeStart = -1.;
const auto rangeEnd = 1.;
const auto step = .3;
auto gen = range(rangeStart, rangeEnd, step);
auto expected = rangeStart;
while( (rangeEnd - expected) > step ) {
INFO( "Current expected value is " << expected )
REQUIRE(gen.get() == Approx(expected));
REQUIRE(gen.next());
expected += step;
}
REQUIRE_FALSE(gen.next());
}
SECTION("Slightly under end") {
const auto rangeStart = -1.;
const auto rangeEnd = .9;
const auto step = .3;
auto gen = range(rangeStart, rangeEnd, step);
auto expected = rangeStart;
while( (rangeEnd - expected) > step ) {
INFO( "Current expected value is " << expected )
REQUIRE(gen.get() == Approx(expected));
REQUIRE(gen.next());
expected += step;
}
REQUIRE_FALSE(gen.next());
}
}
} }
SECTION("Negative manual step") { SECTION("Negative manual step") {
SECTION("Integer") { SECTION("Integer") {
......
...@@ -4,39 +4,15 @@ ...@@ -4,39 +4,15 @@
#include <cstring> #include <cstring>
namespace Catch {
// Implementation of test accessors
struct StringRefTestAccess {
static auto isOwned( StringRef const& stringRef ) -> bool {
return stringRef.isOwned();
}
static auto isSubstring( StringRef const& stringRef ) -> bool {
return stringRef.isSubstring();
}
};
namespace {
auto isOwned( StringRef const& stringRef ) -> bool {
return StringRefTestAccess::isOwned( stringRef );
}
auto isSubstring( StringRef const& stringRef ) -> bool {
return StringRefTestAccess::isSubstring( stringRef );
}
} // end anonymous namespace
} // namespace Catch
TEST_CASE( "StringRef", "[Strings][StringRef]" ) { TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
using Catch::StringRef; using Catch::StringRef;
using Catch::isOwned; using Catch::isSubstring;
SECTION( "Empty string" ) { SECTION( "Empty string" ) {
StringRef empty; StringRef empty;
REQUIRE( empty.empty() ); REQUIRE( empty.empty() );
REQUIRE( empty.size() == 0 ); REQUIRE( empty.size() == 0 );
REQUIRE( empty.isNullTerminated() );
REQUIRE( std::strcmp( empty.c_str(), "" ) == 0 ); REQUIRE( std::strcmp( empty.c_str(), "" ) == 0 );
} }
...@@ -44,28 +20,22 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) { ...@@ -44,28 +20,22 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
StringRef s = "hello"; StringRef s = "hello";
REQUIRE( s.empty() == false ); REQUIRE( s.empty() == false );
REQUIRE( s.size() == 5 ); REQUIRE( s.size() == 5 );
REQUIRE( isSubstring( s ) == false ); REQUIRE( s.isNullTerminated() );
auto rawChars = s.currentData(); auto rawChars = s.data();
REQUIRE( std::strcmp( rawChars, "hello" ) == 0 ); REQUIRE( std::strcmp( rawChars, "hello" ) == 0 );
SECTION( "c_str() does not cause copy" ) { REQUIRE_NOTHROW(s.c_str());
REQUIRE( isOwned( s ) == false ); REQUIRE(s.c_str() == rawChars);
REQUIRE(s.data() == rawChars);
REQUIRE( s.c_str() == rawChars );
REQUIRE( isOwned( s ) == false );
}
} }
SECTION( "From sub-string" ) { SECTION( "From sub-string" ) {
StringRef original = StringRef( "original string" ).substr(0, 8); StringRef original = StringRef( "original string" ).substr(0, 8);
REQUIRE( original == "original" ); REQUIRE( original == "original" );
REQUIRE( isSubstring( original ) );
REQUIRE( isOwned( original ) == false );
original.c_str(); // Forces it to take ownership
REQUIRE( isOwned( original ) ); REQUIRE_FALSE(original.isNullTerminated());
REQUIRE_THROWS(original.c_str());
REQUIRE_NOTHROW(original.data());
} }
...@@ -76,26 +46,9 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) { ...@@ -76,26 +46,9 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
SECTION( "zero-based substring" ) { SECTION( "zero-based substring" ) {
REQUIRE( ss.empty() == false ); REQUIRE( ss.empty() == false );
REQUIRE( ss.size() == 5 ); REQUIRE( ss.size() == 5 );
REQUIRE( std::strcmp( ss.c_str(), "hello" ) == 0 ); REQUIRE( std::strncmp( ss.data(), "hello", 5 ) == 0 );
REQUIRE( ss == "hello" ); REQUIRE( ss == "hello" );
} }
SECTION( "c_str() causes copy" ) {
REQUIRE( isSubstring( ss ) );
REQUIRE( isOwned( ss ) == false );
auto rawChars = ss.currentData();
REQUIRE( rawChars == s.currentData() ); // same pointer value
REQUIRE( ss.c_str() != rawChars );
REQUIRE( isOwned( ss ) );
SECTION( "Self-assignment after substring" ) {
ss = *&ss; // the *& are there to suppress warnings (see: "Improvements to Clang's diagnostics" in https://rev.ng/gitlab/revng-bar-2019/clang/raw/master/docs/ReleaseNotes.rst)
REQUIRE( isOwned(ss) == false );
REQUIRE( ss == "hello" );
REQUIRE( rawChars == ss.currentData() ); // same pointer value
}
}
SECTION( "non-zero-based substring") { SECTION( "non-zero-based substring") {
ss = s.substr( 6, 6 ); ss = s.substr( 6, 6 );
...@@ -105,21 +58,32 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) { ...@@ -105,21 +58,32 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
SECTION( "Pointer values of full refs should match" ) { SECTION( "Pointer values of full refs should match" ) {
StringRef s2 = s; StringRef s2 = s;
REQUIRE( s.c_str() == s2.c_str() ); REQUIRE( s.data() == s2.data() );
} }
SECTION( "Pointer values of substring refs should not match" ) { SECTION( "Pointer values of substring refs should also match" ) {
REQUIRE( s.c_str() != ss.c_str() ); REQUIRE( s.data() == ss.data() );
} }
SECTION("Past the end substring") { SECTION("Past the end substring") {
REQUIRE(s.substr(s.size() + 1, 123).empty()); REQUIRE(s.substr(s.size() + 1, 123).empty());
} }
SECTION("Substring off the end are trimmed") {
ss = s.substr(6, 123);
REQUIRE(std::strcmp(ss.c_str(), "world!") == 0);
} }
// TODO: substring into string + size is longer than end
}
SECTION( "Comparisons are deep" ) {
char buffer1[] = "Hello";
char buffer2[] = "Hello";
CHECK((char*)buffer1 != (char*)buffer2);
SECTION( "Comparisons" ) { StringRef left(buffer1), right(buffer2);
REQUIRE( StringRef("hello") == StringRef("hello") ); REQUIRE( left == right );
REQUIRE( StringRef("hello") != StringRef("cello") ); REQUIRE(left != left.substr(0, 3));
} }
SECTION( "from std::string" ) { SECTION( "from std::string" ) {
...@@ -159,3 +123,28 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) { ...@@ -159,3 +123,28 @@ TEST_CASE( "StringRef", "[Strings][StringRef]" ) {
} }
} }
} }
TEST_CASE("StringRef at compilation time", "[Strings][StringRef][constexpr]") {
using Catch::StringRef;
SECTION("Simple constructors") {
STATIC_REQUIRE(StringRef{}.size() == 0);
STATIC_REQUIRE(StringRef{ "abc", 3 }.size() == 3);
STATIC_REQUIRE(StringRef{ "abc", 3 }.isNullTerminated());
STATIC_REQUIRE(StringRef{ "abc", 2 }.size() == 2);
STATIC_REQUIRE_FALSE(StringRef{ "abc", 2 }.isNullTerminated());
}
SECTION("UDL construction") {
constexpr auto sr1 = "abc"_catch_sr;
STATIC_REQUIRE_FALSE(sr1.empty());
STATIC_REQUIRE(sr1.size() == 3);
STATIC_REQUIRE(sr1.isNullTerminated());
using Catch::operator"" _sr;
constexpr auto sr2 = ""_sr;
STATIC_REQUIRE(sr2.empty());
STATIC_REQUIRE(sr2.size() == 0);
STATIC_REQUIRE(sr2.isNullTerminated());
}
}
...@@ -40,10 +40,11 @@ TEST_CASE( "XmlEncode", "[XML]" ) { ...@@ -40,10 +40,11 @@ TEST_CASE( "XmlEncode", "[XML]" ) {
} }
// Thanks to Peter Bindels (dascandy) for some of the tests // Thanks to Peter Bindels (dascandy) for some of the tests
TEST_CASE("XmlEncode: UTF-8", "[XML][UTF-8]") { TEST_CASE("XmlEncode: UTF-8", "[XML][UTF-8][approvals]") {
#define ESC(lit) (char*)(lit)
SECTION("Valid utf-8 strings") { SECTION("Valid utf-8 strings") {
CHECK(encode(u8"Here be 👾") == u8"Here be 👾"); CHECK(encode(ESC(u8"Here be 👾")) == ESC(u8"Here be 👾"));
CHECK(encode(u8"šš") == u8"šš"); CHECK(encode(ESC(u8"šš")) == ESC(u8"šš"));
CHECK(encode("\xDF\xBF") == "\xDF\xBF"); // 0x7FF CHECK(encode("\xDF\xBF") == "\xDF\xBF"); // 0x7FF
CHECK(encode("\xE0\xA0\x80") == "\xE0\xA0\x80"); // 0x800 CHECK(encode("\xE0\xA0\x80") == "\xE0\xA0\x80"); // 0x800
...@@ -55,18 +56,18 @@ TEST_CASE("XmlEncode: UTF-8", "[XML][UTF-8]") { ...@@ -55,18 +56,18 @@ TEST_CASE("XmlEncode: UTF-8", "[XML][UTF-8]") {
} }
SECTION("Invalid utf-8 strings") { SECTION("Invalid utf-8 strings") {
SECTION("Various broken strings") { SECTION("Various broken strings") {
CHECK(encode("Here \xFF be 👾") == u8"Here \\xFF be 👾"); CHECK(encode(ESC("Here \xFF be \xF0\x9F\x91\xBE")) == ESC(u8"Here \\xFF be 👾"));
CHECK(encode("\xFF") == "\\xFF"); CHECK(encode("\xFF") == "\\xFF");
CHECK(encode("\xC5\xC5\xA0") == u8"\\xC5Š"); CHECK(encode("\xC5\xC5\xA0") == ESC(u8"\\xC5Š"));
CHECK(encode("\xF4\x90\x80\x80") == u8"\\xF4\\x90\\x80\\x80"); // 0x110000 -- out of unicode range CHECK(encode("\xF4\x90\x80\x80") == ESC(u8"\\xF4\\x90\\x80\\x80")); // 0x110000 -- out of unicode range
} }
SECTION("Overlong encodings") { SECTION("Overlong encodings") {
CHECK(encode("\xC0\x80") == u8"\\xC0\\x80"); // \0 CHECK(encode("\xC0\x80") == "\\xC0\\x80"); // \0
CHECK(encode("\xF0\x80\x80\x80") == u8"\\xF0\\x80\\x80\\x80"); // Super-over-long \0 CHECK(encode("\xF0\x80\x80\x80") == "\\xF0\\x80\\x80\\x80"); // Super-over-long \0
CHECK(encode("\xC1\xBF") == u8"\\xC1\\xBF"); // ASCII char as UTF-8 (0x7F) CHECK(encode("\xC1\xBF") == "\\xC1\\xBF"); // ASCII char as UTF-8 (0x7F)
CHECK(encode("\xE0\x9F\xBF") == u8"\\xE0\\x9F\\xBF"); // 0x7FF CHECK(encode("\xE0\x9F\xBF") == "\\xE0\\x9F\\xBF"); // 0x7FF
CHECK(encode("\xF0\x8F\xBF\xBF") == u8"\\xF0\\x8F\\xBF\\xBF"); // 0xFFFF CHECK(encode("\xF0\x8F\xBF\xBF") == "\\xF0\\x8F\\xBF\\xBF"); // 0xFFFF
} }
// Note that we actually don't modify surrogate pairs, as we do not do strict checking // Note that we actually don't modify surrogate pairs, as we do not do strict checking
...@@ -78,35 +79,36 @@ TEST_CASE("XmlEncode: UTF-8", "[XML][UTF-8]") { ...@@ -78,35 +79,36 @@ TEST_CASE("XmlEncode: UTF-8", "[XML][UTF-8]") {
} }
SECTION("Invalid start byte") { SECTION("Invalid start byte") {
CHECK(encode("\x80") == u8"\\x80"); CHECK(encode("\x80") == "\\x80");
CHECK(encode("\x81") == u8"\\x81"); CHECK(encode("\x81") == "\\x81");
CHECK(encode("\xBC") == u8"\\xBC"); CHECK(encode("\xBC") == "\\xBC");
CHECK(encode("\xBF") == u8"\\xBF"); CHECK(encode("\xBF") == "\\xBF");
// Out of range // Out of range
CHECK(encode("\xF5\x80\x80\x80") == u8"\\xF5\\x80\\x80\\x80"); CHECK(encode("\xF5\x80\x80\x80") == "\\xF5\\x80\\x80\\x80");
CHECK(encode("\xF6\x80\x80\x80") == u8"\\xF6\\x80\\x80\\x80"); CHECK(encode("\xF6\x80\x80\x80") == "\\xF6\\x80\\x80\\x80");
CHECK(encode("\xF7\x80\x80\x80") == u8"\\xF7\\x80\\x80\\x80"); CHECK(encode("\xF7\x80\x80\x80") == "\\xF7\\x80\\x80\\x80");
} }
SECTION("Missing continuation byte(s)") { SECTION("Missing continuation byte(s)") {
// Missing first continuation byte // Missing first continuation byte
CHECK(encode("\xDE") == u8"\\xDE"); CHECK(encode("\xDE") == "\\xDE");
CHECK(encode("\xDF") == u8"\\xDF"); CHECK(encode("\xDF") == "\\xDF");
CHECK(encode("\xE0") == u8"\\xE0"); CHECK(encode("\xE0") == "\\xE0");
CHECK(encode("\xEF") == u8"\\xEF"); CHECK(encode("\xEF") == "\\xEF");
CHECK(encode("\xF0") == u8"\\xF0"); CHECK(encode("\xF0") == "\\xF0");
CHECK(encode("\xF4") == u8"\\xF4"); CHECK(encode("\xF4") == "\\xF4");
// Missing second continuation byte // Missing second continuation byte
CHECK(encode("\xE0\x80") == u8"\\xE0\\x80"); CHECK(encode("\xE0\x80") == "\\xE0\\x80");
CHECK(encode("\xE0\xBF") == u8"\\xE0\\xBF"); CHECK(encode("\xE0\xBF") == "\\xE0\\xBF");
CHECK(encode("\xE1\x80") == u8"\\xE1\\x80"); CHECK(encode("\xE1\x80") == "\\xE1\\x80");
CHECK(encode("\xF0\x80") == u8"\\xF0\\x80"); CHECK(encode("\xF0\x80") == "\\xF0\\x80");
CHECK(encode("\xF4\x80") == u8"\\xF4\\x80"); CHECK(encode("\xF4\x80") == "\\xF4\\x80");
// Missing third continuation byte // Missing third continuation byte
CHECK(encode("\xF0\x80\x80") == u8"\\xF0\\x80\\x80"); CHECK(encode("\xF0\x80\x80") == "\\xF0\\x80\\x80");
CHECK(encode("\xF4\x80\x80") == u8"\\xF4\\x80\\x80"); CHECK(encode("\xF4\x80\x80") == "\\xF4\\x80\\x80");
} }
} }
#undef ESC
} }
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "reporters/catch_reporter_teamcity.hpp" #include "reporters/catch_reporter_teamcity.hpp"
#include "reporters/catch_reporter_tap.hpp" #include "reporters/catch_reporter_tap.hpp"
#include "reporters/catch_reporter_automake.hpp" #include "reporters/catch_reporter_automake.hpp"
#include "reporters/catch_reporter_sonarqube.hpp"
// Some example tag aliases // Some example tag aliases
......
...@@ -58,9 +58,11 @@ struct AutoTestReg { ...@@ -58,9 +58,11 @@ struct AutoTestReg {
REGISTER_TEST_CASE( manuallyRegisteredTestFunction, "ManuallyRegistered" ); REGISTER_TEST_CASE( manuallyRegisteredTestFunction, "ManuallyRegistered" );
} }
}; };
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION
CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
static AutoTestReg autoTestReg; static AutoTestReg autoTestReg;
CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION
template<typename T> template<typename T>
struct Foo { struct Foo {
......
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
// We need 2 types with non-trivial copies/moves // We need 2 types with non-trivial copies/moves
struct MyType1 { struct MyType1 {
MyType1() = default; MyType1() = default;
MyType1(MyType1 const&) { throw 1; } [[noreturn]] MyType1(MyType1 const&) { throw 1; }
MyType1& operator=(MyType1 const&) { throw 3; } MyType1& operator=(MyType1 const&) { throw 3; }
}; };
struct MyType2 { struct MyType2 {
MyType2() = default; MyType2() = default;
MyType2(MyType2 const&) { throw 2; } [[noreturn]] MyType2(MyType2 const&) { throw 2; }
MyType2& operator=(MyType2 const&) { throw 4; } MyType2& operator=(MyType2 const&) { throw 4; }
}; };
......
...@@ -390,12 +390,6 @@ TEST_CASE("Commas in various macros are allowed") { ...@@ -390,12 +390,6 @@ TEST_CASE("Commas in various macros are allowed") {
} }
} }
TEST_CASE( "null deref", "[.][failing][!nonportable]" ) {
CHECK( false );
int *x = NULL;
*x = 1;
}
TEST_CASE( "non-copyable objects", "[.][failing]" ) { TEST_CASE( "non-copyable objects", "[.][failing]" ) {
// Thanks to Agustin Bergé (@k-ballo on the cpplang Slack) for raising this // Thanks to Agustin Bergé (@k-ballo on the cpplang Slack) for raising this
std::type_info const& ti = typeid(int); std::type_info const& ti = typeid(int);
......
...@@ -29,6 +29,7 @@ filelocParser = re.compile(r''' ...@@ -29,6 +29,7 @@ filelocParser = re.compile(r'''
lineNumberParser = re.compile(r' line="[0-9]*"') lineNumberParser = re.compile(r' line="[0-9]*"')
hexParser = re.compile(r'\b(0[xX][0-9a-fA-F]+)\b') hexParser = re.compile(r'\b(0[xX][0-9a-fA-F]+)\b')
durationsParser = re.compile(r' time="[0-9]*\.[0-9]*"') durationsParser = re.compile(r' time="[0-9]*\.[0-9]*"')
sonarqubeDurationParser = re.compile(r' duration="[0-9]+"')
timestampsParser = re.compile(r'\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}Z') timestampsParser = re.compile(r'\d{4}-\d{2}-\d{2}T\d{2}\:\d{2}\:\d{2}Z')
versionParser = re.compile(r'Catch v[0-9]+\.[0-9]+\.[0-9]+(-develop\.[0-9]+)?') versionParser = re.compile(r'Catch v[0-9]+\.[0-9]+\.[0-9]+(-develop\.[0-9]+)?')
nullParser = re.compile(r'\b(__null|nullptr)\b') nullParser = re.compile(r'\b(__null|nullptr)\b')
...@@ -138,6 +139,7 @@ def filterLine(line, isCompact): ...@@ -138,6 +139,7 @@ def filterLine(line, isCompact):
# strip durations and timestamps # strip durations and timestamps
line = durationsParser.sub(' time="{duration}"', line) line = durationsParser.sub(' time="{duration}"', line)
line = sonarqubeDurationParser.sub(' duration="{duration}"', line)
line = timestampsParser.sub('{iso8601-timestamp}', line) line = timestampsParser.sub('{iso8601-timestamp}', line)
line = specialCaseParser.sub('file:\g<1>', line) line = specialCaseParser.sub('file:\g<1>', line)
line = errnoParser.sub('errno', line) line = errnoParser.sub('errno', line)
...@@ -204,6 +206,8 @@ approve("junit.sw", ["~[!nonportable]~[!benchmark]~[approvals]", "-s", "-w", "No ...@@ -204,6 +206,8 @@ approve("junit.sw", ["~[!nonportable]~[!benchmark]~[approvals]", "-s", "-w", "No
approve("xml.sw", ["~[!nonportable]~[!benchmark]~[approvals]", "-s", "-w", "NoAssertions", "-r", "xml", "--order", "lex", "--rng-seed", "1"]) approve("xml.sw", ["~[!nonportable]~[!benchmark]~[approvals]", "-s", "-w", "NoAssertions", "-r", "xml", "--order", "lex", "--rng-seed", "1"])
# compact reporter, include passes, warn about No Assertions # compact reporter, include passes, warn about No Assertions
approve('compact.sw', ['~[!nonportable]~[!benchmark]~[approvals]', '-s', '-w', 'NoAssertions', '-r', 'compact', '--order', 'lex', "--rng-seed", "1"]) approve('compact.sw', ['~[!nonportable]~[!benchmark]~[approvals]', '-s', '-w', 'NoAssertions', '-r', 'compact', '--order', 'lex', "--rng-seed", "1"])
# sonarqube reporter, include passes, warn about No Assertions
approve("sonarqube.sw", ["~[!nonportable]~[!benchmark]~[approvals]", "-s", "-w", "NoAssertions", "-r", "sonarqube", "--order", "lex", "--rng-seed", "1"])
if overallResult != 0: if overallResult != 0:
print("If these differences are expected, run approve.py to approve new baselines.") print("If these differences are expected, run approve.py to approve new baselines.")
......
...@@ -156,7 +156,7 @@ def performUpdates(version): ...@@ -156,7 +156,7 @@ def performUpdates(version):
# We probably should have some kind of convention to select which reporters need to be copied automagically, # We probably should have some kind of convention to select which reporters need to be copied automagically,
# but this works for now # but this works for now
import shutil import shutil
for rep in ('automake', 'tap', 'teamcity'): for rep in ('automake', 'tap', 'teamcity', 'sonarqube'):
sourceFile = os.path.join(catchPath, 'include/reporters/catch_reporter_{}.hpp'.format(rep)) sourceFile = os.path.join(catchPath, 'include/reporters/catch_reporter_{}.hpp'.format(rep))
destFile = os.path.join(catchPath, 'single_include', 'catch2', 'catch_reporter_{}.hpp'.format(rep)) destFile = os.path.join(catchPath, 'single_include', 'catch2', 'catch_reporter_{}.hpp'.format(rep))
shutil.copyfile(sourceFile, destFile) shutil.copyfile(sourceFile, destFile)
......
...@@ -122,7 +122,7 @@ function get_abseil_cpp() ...@@ -122,7 +122,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.10.2" GIT_TAG="v2.11.0"
DEST="deps/catch" DEST="deps/catch"
get_dep "${GIT_REPO}" "${GIT_TAG}" "${DEST}" get_dep "${GIT_REPO}" "${GIT_TAG}" "${DEST}"
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论