blob: a0d2e545741fb4ec26051c3dbd1818792d843012 [file] [log] [blame]
William A. Kennington III9a70f4e2021-05-01 17:16:57 -07001#include <stdplus/exception.hpp>
2
Patrick Williamsd1984dd2023-05-10 16:12:44 -05003#include <gtest/gtest.h>
4
William A. Kennington III9a70f4e2021-05-01 17:16:57 -07005namespace stdplus
6{
7namespace exception
8{
9
10TEST(Exception, IgnoreNoError)
11{
12 ignore([] {})();
13 ignore([]() mutable { throw std::runtime_error("Boom"); })();
14 EXPECT_EQ(int(), ignore([]() -> int { throw 1; })());
15 auto x = std::make_unique<int>(1);
16 auto y = std::make_unique<int>(2);
17 auto z = std::make_unique<int>(3);
18 EXPECT_EQ(3, ignore([x = std::move(x)](auto&& v) { return *v + *x; })(y));
19 EXPECT_EQ(5, ignore([z = std::move(z)](auto v) { return *v + *z; })(
20 std::move(y)));
21}
22
William A. Kennington IIIeff9ab22021-06-10 01:48:14 -070023TEST(Exception, IgnoreQuiet)
24{
25 ignoreQuiet([] {})();
26 ignoreQuiet([]() mutable { throw std::runtime_error("Boom"); })();
27}
28
William A. Kennington III9a70f4e2021-05-01 17:16:57 -070029} // namespace exception
30} // namespace stdplus