Files
bitcoin/src/test/util_check_tests.cpp
furszy d9c6769d03 test: refactor, decouple HasReason from test framework machinery
Avoid providing the entire unit test framework dependency to tests that only
require access to the HasReason utility class.

E.g. reverselock_tests.cpp, sync_tests.cpp, util_check_tests.cpp, util_string_tests.cpp,
and script_parse_tests.cpp only require access to HasReason and nothing else.
2026-02-26 11:28:55 -03:00

34 lines
1.0 KiB
C++

// Copyright (c) The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <util/check.h>
#include <boost/test/unit_test.hpp>
#include <test/util/common.h>
BOOST_AUTO_TEST_SUITE(util_check_tests)
BOOST_AUTO_TEST_CASE(check_pass)
{
Assume(true);
Assert(true);
CHECK_NONFATAL(true);
}
BOOST_AUTO_TEST_CASE(check_fail)
{
// Disable aborts for easier testing here
test_only_CheckFailuresAreExceptionsNotAborts mock_checks{};
if constexpr (G_ABORT_ON_FAILED_ASSUME) {
BOOST_CHECK_EXCEPTION(Assume(false), NonFatalCheckError, HasReason{"Internal bug detected: false"});
} else {
BOOST_CHECK_NO_THROW(Assume(false));
}
BOOST_CHECK_EXCEPTION(Assert(false), NonFatalCheckError, HasReason{"Internal bug detected: false"});
BOOST_CHECK_EXCEPTION(CHECK_NONFATAL(false), NonFatalCheckError, HasReason{"Internal bug detected: false"});
}
BOOST_AUTO_TEST_SUITE_END()