catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Add nice error messages for unsupported && and ||
- Commit
b3faceede2f2d165b0794d94a470656de38a6b23- Author
- BiCapitalization ·
- Committer
- Martin Hořeňovský
- Parents
e7fce90b493b
Changes
include/internal/catch_decomposer.h | 15 +++++++++++++++ include/internal/catch_meta.hpp | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/include/internal/catch_decomposer.h b/include/internal/catch_decomposer.h index 618a2509..ad69f772 100644 --- a/include/internal/catch_decomposer.h +++ b/include/internal/catch_decomposer.h @@ -10,6 +10,7 @@ #include "catch_tostring.h" #include "catch_stringref.h" +#include "catch_meta.hpp" #include <iosfwd> @@ -143,6 +144,20 @@ namespace Catch { return { static_cast<bool>(m_lhs <= rhs), m_lhs, "<=", rhs }; } + template<typename RhsT> + auto operator && ( RhsT const& ) -> BinaryExpr<LhsT, RhsT const&> const { + static_assert(always_false<RhsT>::value, + "operator&& is not supported inside assertions, " + "wrap the expression inside parentheses, or decompose it"); + } + + template<typename RhsT> + auto operator || ( RhsT const& ) -> BinaryExpr<LhsT, RhsT const&> const { + static_assert(always_false<RhsT>::value, + "operator|| is not supported inside assertions, " + "wrap the expression inside parentheses, or decompose it"); + } + auto makeUnaryExpr() const -> UnaryExpr<LhsT> { return UnaryExpr<LhsT>{ m_lhs }; } diff --git a/include/internal/catch_meta.hpp b/include/internal/catch_meta.hpp index 43ba30fb..e69c4955 100644 --- a/include/internal/catch_meta.hpp +++ b/include/internal/catch_meta.hpp @@ -9,6 +9,8 @@ #ifndef TWOBLUECUBES_CATCH_META_HPP_INCLUDED #define TWOBLUECUBES_CATCH_META_HPP_INCLUDED +#include <type_traits> + template< typename... > struct TypeList{}; @@ -73,4 +75,7 @@ struct combine }; }; +template<typename T> +struct always_false : std::false_type {}; + #endif // TWOBLUECUBES_CATCH_META_HPP_INCLUDED