util_check_tests.cpp raw

   1  // Copyright (c) The Bitcoin Core developers
   2  // Distributed under the MIT software license, see the accompanying
   3  // file COPYING or http://www.opensource.org/licenses/mit-license.php.
   4  
   5  #include <util/check.h>
   6  
   7  #include <boost/test/unit_test.hpp>
   8  #include <test/util/common.h>
   9  
  10  BOOST_AUTO_TEST_SUITE(util_check_tests)
  11  
  12  BOOST_AUTO_TEST_CASE(check_pass)
  13  {
  14      Assume(true);
  15      Assert(true);
  16      CHECK_NONFATAL(true);
  17  }
  18  
  19  BOOST_AUTO_TEST_CASE(check_fail)
  20  {
  21      // Disable aborts for easier testing here
  22      test_only_CheckFailuresAreExceptionsNotAborts mock_checks{};
  23  
  24      if constexpr (G_ABORT_ON_FAILED_ASSUME) {
  25          BOOST_CHECK_EXCEPTION(Assume(false), NonFatalCheckError, HasReason{"Internal bug detected: false"});
  26      } else {
  27          BOOST_CHECK_NO_THROW(Assume(false));
  28      }
  29      BOOST_CHECK_EXCEPTION(Assert(false), NonFatalCheckError, HasReason{"Internal bug detected: false"});
  30      BOOST_CHECK_EXCEPTION(CHECK_NONFATAL(false), NonFatalCheckError, HasReason{"Internal bug detected: false"});
  31  }
  32  
  33  BOOST_AUTO_TEST_SUITE_END()
  34