mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
util/check: stop using lambda for Assert/Assume
This commit is contained in:
@@ -78,6 +78,31 @@ BOOST_AUTO_TEST_CASE(util_datadir)
|
||||
BOOST_CHECK_EQUAL(dd_norm, args.GetDataDirBase());
|
||||
}
|
||||
|
||||
namespace {
|
||||
class NoCopyOrMove
|
||||
{
|
||||
public:
|
||||
int i;
|
||||
explicit NoCopyOrMove(int i) : i{i} { }
|
||||
|
||||
NoCopyOrMove() = delete;
|
||||
NoCopyOrMove(const NoCopyOrMove&) = delete;
|
||||
NoCopyOrMove(NoCopyOrMove&&) = delete;
|
||||
NoCopyOrMove& operator=(const NoCopyOrMove&) = delete;
|
||||
NoCopyOrMove& operator=(NoCopyOrMove&&) = delete;
|
||||
|
||||
operator bool() const { return i != 0; }
|
||||
|
||||
int get_ip1() { return i + 1; }
|
||||
bool test()
|
||||
{
|
||||
// Check that Assume can be used within a lambda and still call methods
|
||||
[&]() { Assume(get_ip1()); }();
|
||||
return Assume(get_ip1() != 5);
|
||||
}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_check)
|
||||
{
|
||||
// Check that Assert can forward
|
||||
@@ -89,6 +114,14 @@ BOOST_AUTO_TEST_CASE(util_check)
|
||||
// Check that Assume can be used as unary expression
|
||||
const bool result{Assume(two == 2)};
|
||||
Assert(result);
|
||||
|
||||
// Check that Assert doesn't require copy/move
|
||||
NoCopyOrMove x{9};
|
||||
Assert(x).i += 3;
|
||||
Assert(x).test();
|
||||
|
||||
// Check nested Asserts
|
||||
BOOST_CHECK_EQUAL(Assert((Assert(x).test() ? 3 : 0)), 3);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(util_criticalsection)
|
||||
|
||||
Reference in New Issue
Block a user