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