-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to add support for comparing std::vector to std::initializer_list #640
Comments
Can't you just do: CHECK( std::vector< char >() == std::vector< char >{ 0 } ); |
Sure, but that would add overhead (in terms of code to read) that I would like to eliminate.
just reads nicer. |
Unfortunately, there's no other way. C++11 just doesn't allow an initializer list on the right-hand-side of ...without metaprogramming. You could create a function and then call it like: CHECK( a == mkv(0x1, 0x2) ); Working on an implementation right now... |
template <typename... Args>
std::vector<typename std::common_type<Args...>::type> mkv(Args&&... args) {
return {args...};
} You can technically name it whatever you want. |
Nice, thank you. What would be the usual ways to add support for custom type comparison operators? Does the In case I test with larger amounts of data, it could be handy if the comparison makes a diff between the two data sets and reports the difference instead of the content of both sets. |
This is rather old issue, but here we go:
|
I missed this one the first time around, sorry.
But also:
How does that sound? |
That sounds perfect! What do you think about having a diff in output of the error case, in case that the containers becomes larger? |
Has there been any progress? I have a lot of Google Test unit tests that I'd like to migrate to Catch2. But I got blocked on the very first test suite, which heavily relies on Google Test's |
std::vector<int> values{ 1, 2, 3 };
REQUIRE_THAT(values, Catch::Equals<int>({1, 2, 3})); |
Thank you! I didn't realize I needed to specify the generic type. |
Hello,
I would like to have support for expressions, like this in Catch:
Could some of you give me some advice, how to add comparison of containers with std::initializer_list? (beside using CHECK_THAT and a custom matcher).
As comparison of
std::vector< T >
with otherstd::vector< char >()
works, I was looking for tests to find out how this works. Are there any unit tests in Catch?cheers,
Torsten
The text was updated successfully, but these errors were encountered: