Catch2 icon indicating copy to clipboard operation
Catch2 copied to clipboard

Provide means to obtain current test case name and current section name

Open sparkles43 opened this issue 1 year ago • 3 comments

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();

sparkles43 avatar Apr 17 '24 12:04 sparkles43

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.

acidtonic avatar Apr 19 '24 19:04 acidtonic

Is there any update as of today on this issue or is it just stale ?

greg-is-kub avatar Aug 20 '24 12:08 greg-is-kub