aboutsummaryrefslogtreecommitdiff
path: root/src/test/util_tests.cpp
diff options
context:
space:
mode:
authorAnthony Towns <aj@erisian.com.au>2022-03-26 12:41:28 +1000
committerAnthony Towns <aj@erisian.com.au>2022-03-30 23:09:13 +1000
commit2ef47ba6c57a12840499a13908ab61aefca6cb55 (patch)
tree8fa4af2c41a838756e8dffa5d3587c0ef414faf5 /src/test/util_tests.cpp
parent7c9fe25c16d48b53a61fa2f6ff77eaf8820cb1f6 (diff)
downloadbitcoin-2ef47ba6c57a12840499a13908ab61aefca6cb55.tar.xz
util/check: stop using lambda for Assert/Assume
Diffstat (limited to 'src/test/util_tests.cpp')
-rw-r--r--src/test/util_tests.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp
index 1881573e7a..b5d8411e1d 100644
--- a/src/test/util_tests.cpp
+++ b/src/test/util_tests.cpp
@@ -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)