-
Notifications
You must be signed in to change notification settings - Fork 8
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
[TEST] Refactor api tests #169
Conversation
Codecov Report
@@ Coverage Diff @@
## master #169 +/- ##
=======================================
Coverage 96.48% 96.48%
=======================================
Files 19 19
Lines 797 797
=======================================
Hits 769 769
Misses 28 28
Continue to review full report at Codecov.
|
dcddf14
to
541a3a5
Compare
Signed-off-by: Lydia Buntrock <lydia.buntrock@fu-berlin.de>
541a3a5
to
baf10c8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There might be subtle problem with gVerbose = true
. By default it is initialized to false
. Depending on the unit test order, it might be set to true by a previous unittest.
So it is necessary to reset it to false.
I think this could be a great use case of the use of a scope guard (Idea taken from here https://stackoverflow.com/questions/28729545/abusing-c11-unique-ptr-to-execute-code-upon-leaving-the-scope):
By implementing a scope guard function:
template<class F> auto scope_guard(F&& f) {
return std::unique_ptr<void, std::decay<F>::type>{(void*)1, std::forward<F>(f)};
}
You can now protect your code by writting:
TEST(...) {
auto verboseGuard = scope_guard([]{gVerbose = false; });
gVerbose = true;
....
}
Or you define even a help construct for that:
template<class F> auto scope_guard(F&& f) {
return std::unique_ptr<void, std::decay<F>::type>{(void*)1, std::forward<F>(f)};
}
auto guard_verbose (bool verbose) {
auto lastState = gVerbose;
gVerbose = verbose;
return scope_guard([=]{gVerbose = lastState; });
}
This would allow you to write:
TEST(...) {
auto verboseGuard = verbose_guard(true); // will reset back to the original state, after leaving this scope
....
}
Signed-off-by: Lydia Buntrock <lydia.buntrock@fu-berlin.de>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me :-)
Signed-off-by: Lydia Buntrock <lydia.buntrock@fu-berlin.de>
2fddab2
to
cbd49fa
Compare
test/api/api_test.hpp
Outdated
// Uses a unique_ptr to implement a scope_guard for guarding the gVerbose state | ||
auto verbose_guard(bool verbose) | ||
{ | ||
// Lambda is being executed when the scope of the unique_ptr is being left |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Lambda is being executed when the scope of the unique_ptr is being left | |
// Lambda is executed when the scope of the unique_ptr ends |
} | ||
|
||
// This is a helper function for debugging, it prints junctions for comparing | ||
void print_compare_junction_vectors(std::vector<Junction> const & junctions_expected_res, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include <vector>
is missing
@@ -426,178 +446,182 @@ TEST(junction_detection, analyze_sa_tag) | |||
1000, // default partition_max_distance | |||
0.5}; // default hierarchical_clustering_cutoff | |||
|
|||
std::vector<Junction> junctions_res{}; | |||
{ // Example 1 | |||
seqan3::debug_stream << "----------------------------------First Example:----------------------------------\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is printed on each test execution – is this intended (even if print_compare_junction_vectors
is just a comment)? The same below for the second example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, because it splits the different examples. I think a few prints give a little more clarity, as there are other printouts while executing the single tests.
Signed-off-by: Lydia Buntrock <lydia.buntrock@fu-berlin.de>
cbd49fa
to
9a7e65d
Compare
Some refactoring for #168 .