Provide means to obtain current test case name and current section name
- Dominant language
- C++
- Stars
- 21.5k
- Forks
- 3.5k
- Avg merge
- 3d 16h
- Merged PRs (30d)
- 2
Description
**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 (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 @jgm-radez suggested (and @isidore supported) the following approach to obtain the current section's hierarchy of names:
```cpp
virtual std::vector getCurrentSectionNames() const {
std::vector retval;
for(std::vector::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();`
Contributor guide
Research direction
Start by reviewing the deprecated Catch::getResultCapture().getCurrentTestName() path and the proposed RunContext implementation using active section trackers. Trace how current test and section names are represented, then define stable access for the test name and section name, with hierarchy support if feasible. Done means the requested names are available without relying on deprecated APIs and are covered by appropriate tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- testing-qa
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100