diff options
| author | Martin Hořeňovský | 2020-02-14 10:32:30 +0100 |
|---|---|---|
| committer | Martin Hořeňovský | 2020-02-14 16:15:47 +0100 |
| commit | db1a0465dc39e8aed36852984c14072192750b1d (patch) | |
| tree | 33871677f9b2e5177472bcee92a9f107643ed74e /src/catch2 | |
| parent | b2a6523d85ec5f4614acdd3176c2f8ed7a669f7b (diff) | |
| download | catch3-db1a0465dc39e8aed36852984c14072192750b1d.tar.gz | |
Outline GeneratorException from generators header
Diffstat (limited to 'src/catch2')
| -rw-r--r-- | src/catch2/catch_approx.h | 6 | ||||
| -rw-r--r-- | src/catch2/catch_generator_exception.cpp | 14 | ||||
| -rw-r--r-- | src/catch2/catch_generator_exception.hpp | 29 | ||||
| -rw-r--r-- | src/catch2/catch_generators.cpp | 15 | ||||
| -rw-r--r-- | src/catch2/catch_generators.hpp | 17 | ||||
| -rw-r--r-- | src/catch2/catch_generators_generic.hpp | 4 | ||||
| -rw-r--r-- | src/catch2/catch_generators_specific.hpp | 2 | ||||
| -rw-r--r-- | src/catch2/catch_output_redirect.cpp | 1 | ||||
| -rw-r--r-- | src/catch2/catch_test_case_tracker.cpp | 1 |
9 files changed, 64 insertions, 25 deletions
diff --git a/src/catch2/catch_approx.h b/src/catch2/catch_approx.h index 9dc9f292..4f3a6958 100644 --- a/src/catch2/catch_approx.h +++ b/src/catch2/catch_approx.h @@ -17,11 +17,9 @@ namespace Catch { class Approx { private: bool equalityComparisonImpl(double other) const; - // Validates the new margin (margin >= 0) - // out-of-line to avoid including stdexcept in the header + //! Sets and validates the new margin (margin >= 0) void setMargin(double margin); - // Validates the new epsilon (0 < epsilon < 1) - // out-of-line to avoid including stdexcept in the header + //! Sets and validates the new epsilon (0 < epsilon < 1) void setEpsilon(double epsilon); public: diff --git a/src/catch2/catch_generator_exception.cpp b/src/catch2/catch_generator_exception.cpp new file mode 100644 index 00000000..9ec5d55b --- /dev/null +++ b/src/catch2/catch_generator_exception.cpp @@ -0,0 +1,14 @@ +/* + * 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) + */ + +#include <catch2/catch_generator_exception.hpp> + +namespace Catch { + + const char* GeneratorException::what() const noexcept { + return m_msg; + } + +} // end namespace Catch diff --git a/src/catch2/catch_generator_exception.hpp b/src/catch2/catch_generator_exception.hpp new file mode 100644 index 00000000..ff84c4d8 --- /dev/null +++ b/src/catch2/catch_generator_exception.hpp @@ -0,0 +1,29 @@ +/* + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ + +#ifndef TWOBLUECUBES_CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED + +#include <exception> + +namespace Catch { + + // Exception type to be thrown when a Generator runs into an error, + // e.g. it cannot initialize the first return value based on + // runtime information + class GeneratorException : public std::exception { + const char* const m_msg = ""; + + public: + GeneratorException(const char* msg): + m_msg(msg) + {} + + const char* what() const noexcept override final; + }; + +} // end namespace Catch + +#endif // TWOBLUECUBES_CATCH_GENERATOR_EXCEPTION_HPP_INCLUDED diff --git a/src/catch2/catch_generators.cpp b/src/catch2/catch_generators.cpp index 0cf55a8d..48d98b92 100644 --- a/src/catch2/catch_generators.cpp +++ b/src/catch2/catch_generators.cpp @@ -6,7 +6,8 @@ */ #include <catch2/catch_generators.hpp> -#include <catch2/catch_random_number_generator.h> +#include <catch2/catch_enforce.h> +#include <catch2/catch_generator_exception.hpp> #include <catch2/catch_interfaces_capture.h> #include <limits> @@ -16,12 +17,16 @@ namespace Catch { IGeneratorTracker::~IGeneratorTracker() {} -const char* GeneratorException::what() const noexcept { - return m_msg; -} - namespace Generators { +namespace Detail { + + [[noreturn]] + void throw_generator_exception(char const* msg) { + Catch::throw_exception(GeneratorException{ msg }); + } +} // end namespace Detail + GeneratorUntypedBase::~GeneratorUntypedBase() {} auto acquireGeneratorTracker( SourceLineInfo const& lineInfo ) -> IGeneratorTracker& { diff --git a/src/catch2/catch_generators.hpp b/src/catch2/catch_generators.hpp index 86f02006..d49ae2e2 100644 --- a/src/catch2/catch_generators.hpp +++ b/src/catch2/catch_generators.hpp @@ -9,29 +9,24 @@ #include <catch2/catch_interfaces_generatortracker.h> #include <catch2/catch_common.h> -#include <catch2/catch_enforce.h> #include <memory> #include <vector> #include <cassert> #include <tuple> #include <utility> -#include <exception> namespace Catch { -class GeneratorException : public std::exception { - const char* const m_msg = ""; +namespace Generators { -public: - GeneratorException(const char* msg): - m_msg(msg) - {} +namespace Detail { - const char* what() const noexcept override final; -}; + //! Throws GeneratorException with the provided message + [[noreturn]] + void throw_generator_exception(char const * msg); -namespace Generators { +} // end namespace detail template<typename T> struct IGenerator : GeneratorUntypedBase { diff --git a/src/catch2/catch_generators_generic.hpp b/src/catch2/catch_generators_generic.hpp index 5a8708dc..954150b9 100644 --- a/src/catch2/catch_generators_generic.hpp +++ b/src/catch2/catch_generators_generic.hpp @@ -65,7 +65,7 @@ namespace Generators { // filter. In that case we throw an exception. auto has_initial_value = next(); if (!has_initial_value) { - Catch::throw_exception(GeneratorException("No valid value found in filtered generator")); + Detail::throw_generator_exception("No valid value found in filtered generator"); } } } @@ -202,7 +202,7 @@ namespace Generators { m_chunk.push_back(m_generator.get()); for (size_t i = 1; i < m_chunk_size; ++i) { if (!m_generator.next()) { - Catch::throw_exception(GeneratorException("Not enough values to initialize the first chunk")); + Detail::throw_generator_exception("Not enough values to initialize the first chunk"); } m_chunk.push_back(m_generator.get()); } diff --git a/src/catch2/catch_generators_specific.hpp b/src/catch2/catch_generators_specific.hpp index b4ca536c..f61a2be2 100644 --- a/src/catch2/catch_generators_specific.hpp +++ b/src/catch2/catch_generators_specific.hpp @@ -140,7 +140,7 @@ public: template <typename InputIterator, typename InputSentinel> IteratorGenerator(InputIterator first, InputSentinel last):m_elems(first, last) { if (m_elems.empty()) { - Catch::throw_exception(GeneratorException("IteratorGenerator received no valid values")); + Detail::throw_generator_exception("IteratorGenerator received no valid values"); } } diff --git a/src/catch2/catch_output_redirect.cpp b/src/catch2/catch_output_redirect.cpp index 10ecfe22..5ff7abd0 100644 --- a/src/catch2/catch_output_redirect.cpp +++ b/src/catch2/catch_output_redirect.cpp @@ -12,7 +12,6 @@ #include <cstring> #include <fstream> #include <sstream> -#include <stdexcept> #if defined(CATCH_CONFIG_NEW_CAPTURE) #if defined(_MSC_VER) diff --git a/src/catch2/catch_test_case_tracker.cpp b/src/catch2/catch_test_case_tracker.cpp index 1781a8db..51aa56ff 100644 --- a/src/catch2/catch_test_case_tracker.cpp +++ b/src/catch2/catch_test_case_tracker.cpp @@ -12,7 +12,6 @@ #include <algorithm> #include <cassert> -#include <stdexcept> #include <memory> #include <sstream> |