diff options
author | Manoj Srivastava <srivasta@debian.org> | 2016-01-27 12:43:59 -0800 |
---|---|---|
committer | Manoj Srivastava <srivasta@debian.org> | 2016-01-27 12:50:09 -0800 |
commit | 76fce162659078323fcd5e54b3195dae371faca2 (patch) | |
tree | c1d93d415b96238aae3c54eb83cb0815af2e4bca /vendor/bandit/bandit/assertion_frameworks/matchers/ThrowException.h | |
parent | b4456969cd02d75c599a5b86b225c0774697e85d (diff) | |
parent | 4aa1a39402c3908e9e8b6eb3fd4e2183d5e5c52e (diff) |
Merge branch 'development' into upstream
Signed-off-by: Manoj Srivastava <srivasta@debian.org>
# Conflicts:
# src/.gitignore
# src/maid-x11.c
# src/quest.pkg
Diffstat (limited to 'vendor/bandit/bandit/assertion_frameworks/matchers/ThrowException.h')
-rw-r--r-- | vendor/bandit/bandit/assertion_frameworks/matchers/ThrowException.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/vendor/bandit/bandit/assertion_frameworks/matchers/ThrowException.h b/vendor/bandit/bandit/assertion_frameworks/matchers/ThrowException.h new file mode 100644 index 00000000..cd8bfc34 --- /dev/null +++ b/vendor/bandit/bandit/assertion_frameworks/matchers/ThrowException.h @@ -0,0 +1,60 @@ +#ifndef BANDIT_THROWEXCEPTION_H +#define BANDIT_THROWEXCEPTION_H + +#include "Matcher.h" + +namespace bandit { namespace Matchers { + + template <typename T> + class ThrowException : public Matcher + { + public: + ThrowException() : Matcher(), _allow_subclasses(false) {} + explicit ThrowException(bool allow_subclasses) : Matcher(), _allow_subclasses(allow_subclasses) {} + + template <typename U = std::exception> + ThrowException<U> operator()() const + { + return ThrowException<U>(); + } + + ThrowException& or_subclass() + { + _allow_subclasses = true; + return *this; + } + + template <typename U> + bool matches(const U& block) const + { + try + { + block(); + } + catch(const T& e) + { + return true; + } + catch(...) // Wrong exception + { + _exception = std::current_exception(); + } + + return false; + } + + protected: + std::string failure_message_end() const + { + return std::string("throw an exception"); + } + + private: + bool _allow_subclasses; + mutable std::exception_ptr _exception; + }; + + static const ThrowException<std::exception> throw_exception; +}} + +#endif // BANDIT_THROWEXCEPTION_H |