1 /* Unit testing for outcomes
2 (C) 2013-2019 Niall Douglas <http://www.nedproductions.biz/> (6 commits)
5 Boost Software License - Version 1.0 - August 17th, 2003
7 Permission is hereby granted, free of charge, to any person or organization
8 obtaining a copy of the software and accompanying documentation covered by
9 this license (the "Software") to use, reproduce, display, distribute,
10 execute, and transmit the Software, and to prepare derivative works of the
11 Software, and to permit third-parties to whom the Software is furnished to
12 do so, all subject to the following:
14 The copyright notices in the Software and this entire statement, including
15 the above license grant, this restriction and the following disclaimer,
16 must be included in all copies of the Software, in whole or in part, and
17 all derivative works of the Software, unless such copies or derivative
18 works are solely in the form of machine-executable object code generated by
19 a source language processor.
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
24 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
25 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
26 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
30 #include <boost/outcome/outcome.hpp>
31 #include <boost/test/unit_test.hpp>
32 #include <boost/test/unit_test_monitor.hpp>
34 BOOST_OUTCOME_AUTO_TEST_CASE(issues_0061_result, "result<T1, E1> does not compare to incompatible result<T2, E2>")
36 using namespace BOOST_OUTCOME_V2_NAMESPACE;
39 const char *_v{nullptr};
41 constexpr udt1(const char *v) noexcept : _v(v) {} // NOLINT
42 udt1(udt1 &&o) = delete;
43 udt1(const udt1 &) = delete;
44 udt1 &operator=(udt1 &&o) = delete;
45 udt1 &operator=(const udt1 &) = delete;
47 constexpr const char *operator*() const noexcept { return _v; }
51 const char *_v{nullptr};
53 constexpr explicit udt2(const char *v) noexcept : _v(v) {}
54 udt2(udt2 &&o) = delete;
55 udt2(const udt2 &) = delete;
56 udt2 &operator=(udt2 &&o) = delete;
57 udt2 &operator=(const udt2 &) = delete;
59 constexpr const char *operator*() const noexcept { return _v; }
60 bool operator==(const udt1 &o) const noexcept { return _v == *o; }
61 bool operator!=(const udt1 &o) const noexcept { return _v != *o; }
63 using result1 = result<int, udt1>;
64 using result2 = result<int, udt2>;
68 BOOST_CHECK(b == a); // udt2 will compare to udt1
69 BOOST_CHECK(!(b != a)); // udt2 will compare to udt1
71 result<void> c = success();
72 result<void> d = success();
74 BOOST_CHECK(!(c != d));
76 BOOST_CHECK(a == success());
77 BOOST_CHECK(success() == a);
78 BOOST_CHECK(b != failure("foo"));
79 BOOST_CHECK(failure("foo") != b);
82 BOOST_OUTCOME_AUTO_TEST_CASE(issues_0061_outcome, "outcome<T1, E1, P1> does not compare to incompatible outcome<T2, E2, P2>")
84 using namespace BOOST_OUTCOME_V2_NAMESPACE;
87 const char *_v{nullptr};
89 constexpr udt1(const char *v) noexcept : _v(v) {} // NOLINT
90 udt1(udt1 &&o) = delete;
91 udt1(const udt1 &) = delete;
92 udt1 &operator=(udt1 &&o) = delete;
93 udt1 &operator=(const udt1 &) = delete;
95 constexpr const char *operator*() const noexcept { return _v; }
99 const char *_v{nullptr};
101 constexpr explicit udt2(const char *v) noexcept : _v(v) {}
102 udt2(udt2 &&o) = delete;
103 udt2(const udt2 &) = delete;
104 udt2 &operator=(udt2 &&o) = delete;
105 udt2 &operator=(const udt2 &) = delete;
107 constexpr const char *operator*() const noexcept { return _v; }
108 bool operator==(const udt1 &o) const noexcept { return _v == *o; }
109 bool operator!=(const udt1 &o) const noexcept { return _v != *o; }
111 using outcome1 = outcome<int, udt1>;
112 using outcome2 = outcome<int, udt2>;
114 outcome1 a(5), _a(6);
116 BOOST_CHECK(b == a); // udt2 will compare to udt1
117 BOOST_CHECK(!(b != a)); // udt2 will compare to udt1
119 outcome<void> c = success();
120 outcome<void> d = success();
122 BOOST_CHECK(!(c != d));
124 BOOST_CHECK(a == success());
125 BOOST_CHECK(success() == a);
126 BOOST_CHECK(b != failure("foo"));
127 BOOST_CHECK(failure("foo") != b);