-
-
Notifications
You must be signed in to change notification settings - Fork 649
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
Can logging (INFO) be used in helper class outside of TEST_CASE? #169
Comments
I just noticed that I wonder if the inability to use |
the Have a look at the examples - Doesn't it work if you log the iteration of the loop over the container? |
I think my problem is that the I'm trying to achieve something that can be called like |
Here is some code which you can use to emulate what you need: struct MetaInfoBool {
bool result;
doctest::String meta;
operator bool() const { return result; }
};
std::ostream& operator<<(std::ostream& stream, const MetaInfoBool& meta) {
return stream << meta.meta;
}
template <typename T>
struct VecComparator {
const std::vector<T>& lhs;
VecComparator(const std::vector<T>& other)
: lhs(other) {}
MetaInfoBool compare(const std::vector<T>& rhs) const {
if(lhs.size() != rhs.size()) {
return {false, doctest::String("V1[] (length: ") + doctest::toString(lhs.size()) + ") == V2[] (length: " +
doctest::toString(rhs.size()) + ")"};
}
for(size_t i = 0; i < lhs.size(); ++i)
if(lhs[i] != rhs[i])
return {false, doctest::String("V1[") + doctest::toString(i) + "] (value: " + doctest::toString(lhs[i]) +
") == V2[" + doctest::toString(i) + "] (value: " +
doctest::toString(rhs[i]) + ")"};
return {true, "V1[] == V2[]"};
}
}; and use like this: TEST_CASE("single assert for entire vector") {
vector<int> v1 = {1, 2, 3, 4, 5, 6, 7, 8, 9};
vector<int> v2 = {1, 2, 3, 4, 0, 0, 0, 0, 0};
vector<int> v3 = {1, 2, 3, 4};
CHECK(VecComparator<int>(v1).compare(v2));
CHECK(VecComparator<int>(v1).compare(v3));
} with the following output:
and
In the future the framework will support matchers - there will be a few classes for comparing collections (perhaps with the option to use a predicate) available out of the box and users will also be able to write their own matchers. You can plug a |
Thanks for the feedback. I'll give that a go. |
I have a simple helper class that I use in a similar way to
doctest::approx
except that it allows me to check that all values in a container match. When values from the containers do not match, I want to capture the array index where the failure occurred.Unfortunately the
INFO()
macro seems to be ignored if it is not directly nested in aTEST_CASE()
block. Even callingINFO
from a lambda which is defined within aTEST_CASE
has no effect.Is there a way to capture values for the currently executing test case from helper code which exists outside the scope of the
TEST_CASE
block?The text was updated successfully, but these errors were encountered: