exception: Add wrapper to ignore lambda failures
Change-Id: I2bd720775b233a29083ac5b572bdec1671f6c634
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/exception.cpp b/test/exception.cpp
new file mode 100644
index 0000000..6b4a26f
--- /dev/null
+++ b/test/exception.cpp
@@ -0,0 +1,23 @@
+#include <gtest/gtest.h>
+#include <stdplus/exception.hpp>
+
+namespace stdplus
+{
+namespace exception
+{
+
+TEST(Exception, IgnoreNoError)
+{
+ ignore([] {})();
+ ignore([]() mutable { throw std::runtime_error("Boom"); })();
+ EXPECT_EQ(int(), ignore([]() -> int { throw 1; })());
+ auto x = std::make_unique<int>(1);
+ auto y = std::make_unique<int>(2);
+ auto z = std::make_unique<int>(3);
+ EXPECT_EQ(3, ignore([x = std::move(x)](auto&& v) { return *v + *x; })(y));
+ EXPECT_EQ(5, ignore([z = std::move(z)](auto v) { return *v + *z; })(
+ std::move(y)));
+}
+
+} // namespace exception
+} // namespace stdplus
diff --git a/test/meson.build b/test/meson.build
index df694b6..cd89f27 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -21,6 +21,7 @@
endif
gtests = [
+ 'exception',
'handle/copyable',
'handle/managed',
'util/cexec',