cmoon::test::assert_throws


Defined in module <cmoon.test>


template<class Exception, class F, class... Args>
void assert_throws(F&& callable, std::string_view message, Args&&... args, const std::source_location& location = std::source_location::current());


(1)


template<class Exception, class F, class... Args>
void assert_throws(F&& callable, Args&&... args, const std::source_location& location = std::source_location::current());


(2)

Throws an assert_exception if an exception of type Exception is not thrown.

Parameters

callable - Function to call with args...
args - Arguments to be forwarded to the given function
message - Extra information to be added to the error message
location - Information about where in the file this assertion was ran

Return value

(none)

Example



import <stdexcept>;

import cmoon.test;

void will_throw(int)
{
    throw std::runtime_error{"Exception thrown!"};
}

class example_test : public cmoon::test::test_case
{
    public:
        example_test()
            : cmoon::test::test_case{"example test"} {}

        void operator()() override
        {
            cmoon::test::assert_throws<std::runtime_error>(will_throw, 5);
        }
};