Provide means to obtain current test case name and current section name
Description
I propose the following changes:
- Add a feature to get the current test case's name
- Add a feature to get the current section's name
- Optionally: Add a feature to get the current section's hierarchy of names
These changes are useful if additional data for testing is loaded from or written to a filesystem. Directories and filenames could depend on the current section and thereby reduce duplication.
Additional context
In the past sometimes requests for these features were made but none ever reached a stable upstream (or non-deprecated) state. Especially the issue https://github.com/catchorg/Catch2/issues/510 (by @mlogan) contained a request for such features. However, it was resolved since workarounds were available.
Feature to get the current section's hierarchy of names
In the issue https://github.com/catchorg/Catch2/issues/510 @jgm-radez suggested (and @isidore supported) the following approach to obtain the current section's hierarchy of names:
virtual std::vector<std::string> getCurrentSectionNames() const {
std::vector<std::string> retval;
for(std::vector<ITracker*>::const_iterator iter=m_activeSections.begin(); iter!=m_activeSections.end(); ++iter)
retval.push_back((*iter)->nameAndLocation().name);
return retval;
}
(Assumption: implemented in RunContext)
Feature to get the current test case's name
This feature is currently available in Catch2 but it was marked as deprecated in commit 57c346a by @philsquared and I could not find a reason for it. Why was this done?
Catch::getResultCapture().getCurrentTestName();
I came here to create this exact issue. I am chaining very deep SECTIONS for testing cascading reads/writes for a compression driver and I sometimes get a rare failure out of a few hundred million assertions and it's tough to nail down the exact SECTION chain to produce the bug.
Would love a simple Breadcrumb trail sort of mechanism to iterate section names or just get them as a long string.
Is there any update as of today on this issue or is it just stale ?