William A. Kennington III | 9a70f4e | 2021-05-01 17:16:57 -0700 | [diff] [blame] | 1 | #include <stdplus/exception.hpp> |
| 2 | |
Patrick Williams | d1984dd | 2023-05-10 16:12:44 -0500 | [diff] [blame] | 3 | #include <gtest/gtest.h> |
| 4 | |
William A. Kennington III | 9a70f4e | 2021-05-01 17:16:57 -0700 | [diff] [blame] | 5 | namespace stdplus |
| 6 | { |
| 7 | namespace exception |
| 8 | { |
| 9 | |
| 10 | TEST(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 III | eff9ab2 | 2021-06-10 01:48:14 -0700 | [diff] [blame] | 23 | TEST(Exception, IgnoreQuiet) |
| 24 | { |
| 25 | ignoreQuiet([] {})(); |
| 26 | ignoreQuiet([]() mutable { throw std::runtime_error("Boom"); })(); |
| 27 | } |
| 28 | |
William A. Kennington III | 9a70f4e | 2021-05-01 17:16:57 -0700 | [diff] [blame] | 29 | } // namespace exception |
| 30 | } // namespace stdplus |