-
Notifications
You must be signed in to change notification settings - Fork 10
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
Draft: Feat/catch2 compat #169
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,25 +2,42 @@ | |||||||||||
|
||||||||||||
#include "snitch/snitch_console.hpp" | ||||||||||||
#include "snitch/snitch_registry.hpp" | ||||||||||||
#include "snitch/snitch_test_data.hpp" | ||||||||||||
|
||||||||||||
#if SNITCH_WITH_EXCEPTIONS | ||||||||||||
# include <exception> | ||||||||||||
#endif | ||||||||||||
#if SNITCH_WITH_TIMINGS | ||||||||||||
# include <chrono> | ||||||||||||
#endif | ||||||||||||
|
||||||||||||
namespace snitch::impl { | ||||||||||||
#if SNITCH_WITH_TIMINGS | ||||||||||||
using fsec = std::chrono::duration<float>; | ||||||||||||
using snitch_clock = std::chrono::steady_clock; | ||||||||||||
#endif | ||||||||||||
|
||||||||||||
section_entry_checker::~section_entry_checker() { | ||||||||||||
if (entered) { | ||||||||||||
#if SNITCH_WITH_EXCEPTIONS | ||||||||||||
if (std::uncaught_exceptions() > 0) { | ||||||||||||
// We are unwinding the stack because an exception has been thrown; | ||||||||||||
// avoid touching the section state since we will want to report where | ||||||||||||
// the exception was thrown. | ||||||||||||
state.reg.report_callback( | ||||||||||||
state.reg, event::section_ended{ | ||||||||||||
state.sections.current_section.back().id, | ||||||||||||
state.sections.current_section.back().location, true}); | ||||||||||||
Comment on lines
+27
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See comment in the approval tests; I think this is done too soon. When an exception is in flight, it has not been reported yet, but we now close the section immediately. This results in all unhandled exceptions being reported at the root of the test case, rather than inside the section from which it originated. I believe this particular case (close the section when unwinding an exception) can be handled in the registry instead, to solve this problem. That would be here: snitch/src/snitch_registry.cpp Lines 554 to 558 in d663212
Also, is this particular path currently missing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. |
||||||||||||
return; | ||||||||||||
} | ||||||||||||
#endif | ||||||||||||
|
||||||||||||
pop_location(state); | ||||||||||||
|
||||||||||||
asserts = state.asserts - asserts; | ||||||||||||
failures = state.failures - failures; | ||||||||||||
allowed_failures = state.allowed_failures - allowed_failures; | ||||||||||||
Comment on lines
+37
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This gives two different meanings to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, we could instead store the actual number of assertions (etc) that were recorded, and make the registry propagate the counts to all open sections in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This also might be necessary since I am noticing in my tests that Catch2 counts these things cumulatively for nested sections but with this strategy snitch does not. given SECTION("Section1") {
CHECK(true);
SECTION("Section1.1") {
CHECK(false);
}
} this code outputs
Catch2:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we are counting the actual count for each section, then that needs to happen in the registry too? I don't see a way to do it in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep; I've implemented this so the registry does the propagation of assert counts to all currently open sections. |
||||||||||||
|
||||||||||||
if (state.sections.depth == state.sections.levels.size()) { | ||||||||||||
// We just entered this section, and there was no child section in it. | ||||||||||||
// This is a leaf; flag that a leaf has been executed so that no other leaf | ||||||||||||
|
@@ -29,6 +46,19 @@ section_entry_checker::~section_entry_checker() { | |||||||||||
// that we don't know about yet. Popping will be done when we exit from the parent, | ||||||||||||
// since then we will know if there is any sibling. | ||||||||||||
state.sections.leaf_executed = true; | ||||||||||||
#if SNITCH_WITH_TIMINGS | ||||||||||||
const auto end_time = snitch_clock::now().time_since_epoch(); | ||||||||||||
const auto duration = | ||||||||||||
std::chrono::duration_cast<fsec>(end_time - snitch_clock::duration{start_time}); | ||||||||||||
state.reg.report_callback( | ||||||||||||
state.reg, event::section_ended{ | ||||||||||||
data.id, data.location, false, asserts, failures, allowed_failures, | ||||||||||||
duration.count()}); | ||||||||||||
#else | ||||||||||||
state.reg.report_callback( | ||||||||||||
state.reg, | ||||||||||||
event::section_ended{data.id, data.location, asserts, failures, allowed_failures}); | ||||||||||||
#endif | ||||||||||||
} else { | ||||||||||||
// Check if there is any child section left to execute, at any depth below this one. | ||||||||||||
bool no_child_section_left = true; | ||||||||||||
|
@@ -42,6 +72,10 @@ section_entry_checker::~section_entry_checker() { | |||||||||||
|
||||||||||||
if (no_child_section_left) { | ||||||||||||
// No more children, we can pop this level and never go back. | ||||||||||||
state.reg.report_callback( | ||||||||||||
state.reg, event::section_ended{ | ||||||||||||
state.sections.current_section.back().id, | ||||||||||||
state.sections.current_section.back().location}); | ||||||||||||
state.sections.levels.pop_back(); | ||||||||||||
} | ||||||||||||
} | ||||||||||||
|
@@ -66,8 +100,13 @@ section_entry_checker::operator bool() { | |||||||||||
|
||||||||||||
state.sections.levels.push_back({}); | ||||||||||||
} | ||||||||||||
|
||||||||||||
#if SNITCH_WITH_TIMINGS | ||||||||||||
start_time = snitch_clock::now().time_since_epoch().count(); | ||||||||||||
#endif | ||||||||||||
++state.sections.depth; | ||||||||||||
asserts = state.asserts; | ||||||||||||
failures = state.failures; | ||||||||||||
allowed_failures = state.allowed_failures; | ||||||||||||
|
||||||||||||
auto& level = state.sections.levels[state.sections.depth - 1]; | ||||||||||||
|
||||||||||||
|
@@ -89,6 +128,10 @@ section_entry_checker::operator bool() { | |||||||||||
(level.current_section_id == level.previous_section_id && | ||||||||||||
state.sections.depth < state.sections.levels.size())) { | ||||||||||||
|
||||||||||||
// First time entering this section, emit the section start event | ||||||||||||
if (level.current_section_id == level.previous_section_id + 1) { | ||||||||||||
state.reg.report_callback(state.reg, event::section_started{data.id, data.location}); | ||||||||||||
} | ||||||||||||
level.previous_section_id = level.current_section_id; | ||||||||||||
state.sections.current_section.push_back(data); | ||||||||||||
push_location( | ||||||||||||
|
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.
TeamCity uses the following:
##teamcity[blockOpened name='...' description='...']
##teamcity[blockClosed name='...']
Then we can probably remove the ad-hoc printing of sections in
print_assertion()
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.
In the
print_assertion()
is see where it iterates over the sections, but I don't see how it outputs the test you show here. I don't see and "blockOpened" or "blockCosed"?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.
Got it :)