Sha256: 01c60f14d853432f4b03978e56b8a79ddb6c27d619bcf4b4e30ebb0069fa7e50

Contents?: true

Size: 1.16 KB

Versions: 2

Compression:

Stored size: 1.16 KB

Contents

#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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
tree-sitter-0.1.0 ext/tree-sitter/tree-sitter/externals/bandit/bandit/assertion_frameworks/matchers/ThrowException.h
tree-sitter-0.0.1 ext/tree-sitter/tree-sitter/externals/bandit/bandit/assertion_frameworks/matchers/ThrowException.h