approvals / ApprovalTests.cpp

Native ApprovalTests for C++ on Linux, Mac and Windows
https://approvaltestscpp.readthedocs.io/en/latest/
Apache License 2.0
312 stars 51 forks source link

`verifyAll` won't compile with some c++20 ranges view. #174

Open bogado opened 3 years ago

bogado commented 3 years ago

The function verifyAll assumes that the Container has an associated type name value_type. This is not true for all views. The issue show up on "approvalTests.hpp:1656" for version 10.8.0.

 [&](typename Container::value_type e, std::ostream& s) {
claremacrae commented 3 years ago

Thank you for reporting this.

Do you have any suggestions as to how to fix this, please? And how serious of a problem is this for you?

claremacrae commented 3 years ago

Sorry - closed in error - and re-opened.

bogado commented 3 years ago

To fix this I think that using std::iterator_traits would suffice. For example :

https://godbolt.org/z/8cG6b1x3Y

This would be friendly to older version of C++ and also be more portable. Depending on how you introduce the fix it might even work with old style sized arrays int[10] for instance.

claremacrae commented 3 years ago

Hi Victor (I assume!)

Thanks for reporting this, and for the Godbolt link.

It's probably going to be a little while until we get to this, so as a suggestion in the meantime, if you haven't done it already, we'd suggest a workaround of writing something:

void verifyAllInRange(...)
{
    // convert range to a vector or similar
    Approvals::verifyAll(vector...) 
}
claremacrae commented 2 years ago

Putting it on hold until either we move our tests to C++20 - or we have a CI build that builds on 20...

We can keep an eye on compiler support: https://en.cppreference.com/w/cpp/compiler_support