blob: 48e562e155a197e262808da8123dfb59568b62d8 [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));
Patrick Williamsd8e0af52024-08-16 15:21:12 -040019 EXPECT_EQ(5, ignore([z = std::move(z)](auto v) {
20 return *v + *z;
21 })(std::move(y)));
William A. Kennington III9a70f4e2021-05-01 17:16:57 -070022}
23
William A. Kennington IIIeff9ab22021-06-10 01:48:14 -070024TEST(Exception, IgnoreQuiet)
25{
26 ignoreQuiet([] {})();
27 ignoreQuiet([]() mutable { throw std::runtime_error("Boom"); })();
28}
29
William A. Kennington III9a70f4e2021-05-01 17:16:57 -070030} // namespace exception
31} // namespace stdplus