Comments (6)
Interestingly enough, Optional()
can be used.
enum class Error { boom };
std::expected<int, Error> something = 1;
EXPECT_THAT(something, testing::Optional(testing::Gt(0)));
std::expected<int, Error> something = std::unexpected(Error::boom);
EXPECT_EQ(something, std::unexpected(Error::boom));
from googletest.
Interestingly enough,
Optional()
can be used.enum class Error { boom }; std::expected<int, Error> something = 1; EXPECT_THAT(something, testing::Optional(testing::Gt(0))); std::expected<int, Error> something = std::unexpected(Error::boom); EXPECT_EQ(something, std::unexpected(Error::boom));
Thats weird, still believe there should be a dedicated macro
from googletest.
Thats weird, still believe there should be a dedicated macro
I agree, the Optional thing is a hacky workaround for now but I would want something like EXPECT_THAT(something, testing::Expected(some_val))
where DescribeNegationTo
would indicate that either there was a failure (and describe the error object, if possible) or that it succeeded with an unexpected value.
For a more fluent approach, maybe there could be matchers like EXPECT_THAT(something, succeedsWith(successValMatcher))
or EXPECT_THAT(something, failsWith(errorValMatcher))
Similar to how the existing matchers for Optional
and Variant
are quite general (ie not bound to the std::
classes), I think it should be reasonable to write this matcher with sufficient generality to work with std::expected
and other popular value-or-error types. See e.g., https://ned14.github.io/outcome/tutorial/advanced/interop/value-or-error/
We can assume
value()
error()
has_value()
and public typedefs value_type
and error_type
. I don't think we need to do any ADL free function stuff like with variant.
This should work with std::expected
, TartanLlama tl::expected
, Boost.Outcome outcome::result
, Boost.System system::result
etc
from googletest.
The matcher for absl::StatusOr
will be released by the abseil-cpp project. Someone is working on it now, but it will take a while.
C++23 and std::expected is not supported yet. We do not want it implemented until C++23 is officially supported.
from googletest.
In case it gets approved, assign it to me
from googletest.
For a more fluent approach, maybe there could be matchers like
EXPECT_THAT(something, succeedsWith(successValMatcher))
orEXPECT_THAT(something, failsWith(errorValMatcher))
I like this.
It's a little bit weird cuz absl version std::expected
is StatusOr
, there should be matcher name that will be understood by both library users.
Having it testing::Expected
makes it a bit harder to read because of the EXPECTED_X
macros.
from googletest.
Related Issues (20)
- [Bug]: CMake error (set_target_properties) HOT 1
- [FR]: Add z/OS platform for death test support HOT 2
- [Bug]: Undefined symbol to `testing::internal::PrintTo` for `std::u8string` HOT 1
- [Bug]: MSVC ElementsAreArray compilation errors
- [FR]: Add NOLINT to quiet clang-tidy on EXPECT_CALL
- [Bug]: ASAN heap-buffer-overflow in ParseGoogleTestFlagsOnlyImpl() in gtest.cc HOT 1
- [FR]: Loosen restrictions on what types are considered containers for matchers
- [Bug]: std::length_error from cmake function "generate_testname_guards()" HOT 1
- [Bug]: Undefined reference building on Windows
- [Bug]: Skipped tests' messages are displayed in brief mode
- [Bug]: Cannot mock recursive lambda with deducing this parameter
- [Bug]: Unordered container matchers ignore result descriptions
- MSVC `SEH exception with code 0xc0000005` when using `SUCCEED` HOT 1
- Cannot link gtest HOT 1
- [FR]: ExpectationSet(std::initializer_list<Expectation>) HOT 1
- [Bug]: Mutex deadlock when expecting a function call HOT 1
- [Bug]: Google Test Executables don't respect additional help flags mentioned in the documentation
- [Bug]: No details about why GetTempFileName fails
- [Bug]: MSVC - Assertion macro SUCCEED() leeds to a memory leak. HOT 3
- [Bug]: GCC-12: Compiler warning with C++20 mode in testing::internal::CanonicalizeForStdLibVersioning HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from googletest.