kaycxx-test
C++ unit test framework
Loading...
Searching...
No Matches
assert_not_throw

Asserts that a function does not throw, or does not throw a specific exception/message combination.

The one-argument form fails on any thrown exception. The typed forms only fail when the thrown exception type and message match the unexpected condition; other exceptions are intentionally allowed by those overloads.

#include <regex>
#include <stdexcept>
#include <kaycxx/test.hpp>
using namespace kaycxx::test;
int main() {
assert_not_throw([] {
auto value = 40 + 2;
(void)value;
});
assert_not_throw<std::runtime_error>(
[] { throw std::runtime_error{"Temporary failure"}; },
"Fatal failure"
);
assert_not_throw<std::runtime_error>(
[] { throw std::runtime_error{"Warning 17"}; },
std::regex{"Fatal [0-9]+"}
);
}
Unit test framework functions and types.
Definition test.hpp:15
Includes the complete public test API.

Use the typed overloads when one specific error must not happen, but unrelated errors are not part of this assertion.