Comments (2)
Note: this should hopefully be somewhat coherent, but I've been staring at the code for a few hours and it's late, so sorry if it isnt 😄
The problem
When the section is acquired the second time, we have already ctx.completedCycle()
, so we don't call tryOpen()
. But since the section isComplete()
, close()
is still called, leading to the crash, because we go past the root tracker.
So, the minimal solution is to not enter the section if ctx.completedCycle()
. But after the "section" finished for the first time, it NeedsAnotherRun
(because it has more subsections), and therefore isOpen()
is true. And it generally cannot be false for NeedsAnotherRun
, because we can enter such a section if !ctx.completedCycle()
(TODO: really?).
So, could we just check ctx.completedCycle()
in isOpen()
? Well, no. Because all currently opened sections (with more following children) would suddenly become not opened.
The solution
So, we cannot hack it, we have to do it properly. The goal is to track if a section was already encountered during the current cycle and if so, it's an error.
I think the most robust solution is to remember the serial number of the cycle in each Tracker
and in SectionTracker::acquire
, if we find that the requested section's last recorded cycle is the current cycle, that's the error. (Side note: we don't have to worry about overflow, one-digit binary counter would be enough for this)
Extension of the solution
Alternatively, instead of erroring out, we can say "ok, let's make this a new section and make it work". That would mean that the section tracker tracks also "generation" in addition to name and location.
What about generators
I think it could work the same - if we encounter a generator a second time in the same cycle, we just say it's a different generator. Although I have not studied how generators are implemented yet - even understanding how sections work took me a few hours.
Why it might not be a good idea after all
The problem comes with reporting - how do we distinguish between the two identical sections? We don't. Hence, I think we should force the user to insert (dynamic) sections to make the sections unique.
How to report the error
Catch should probably just throw an exception. But could the malicious user just catch(...){}
it? Probably yes. Am I getting overly paranoid? Definitely.
from catch2.
Another potentially interesting test case with generators:
TEST_CASE("foo") {
std::cout << "new run\n";
for (int i = 0; i < 3; ++i) {
SECTION("section") {
int n = GENERATE(1, 2);
std::cout << n << "\n";
}
}
}
Edit: probably not interesting after all - it's the SECTION that will make it or break it. And generators directly in a loop are handled correctly now.
from catch2.
Related Issues (20)
- Erroneous `cstd` include HOT 1
- Doc: How are generic range matchers used? HOT 1
- Disabling signals is broken in V3
- Compiler problem with operator and include catch_all.hpp HOT 9
- Catch2 junit reporter suddenly writes empty file
- one test fails for 2.5.1 release building with gcc 11/10 on i686-linux HOT 3
- Running a windows GUI application does not allow me to run Catch2 tests! HOT 2
- Security scan issues for v3.5.1 HOT 3
- Calling run multiple times while filenamesAsTags is set changes behaviour of program. HOT 2
- error: size of array ‘altStackMem’ is not an integral constant-expression HOT 1
- riscv: build failure due to Werror=cast-align HOT 2
- Generator results into a fatal error in 2.13.9 (newest not tested)
- Supplying own command line options by following the documentation results in UB (?) HOT 1
- `--benchmark-samples` does not seem to work as expected HOT 4
- I place a benchmark inside a TEST_CASE() and I don't see the results HOT 2
- Wunused-variable in (DYNAMIC_)SECTION when CATCH_CONFIG_EXPERIMENTAL_STATIC_ANALYSIS_SUPPORT is enabled HOT 1
- tsan reports data race on multithread std::cout HOT 3
- XML Reporter doesn't output stderr / stdin when there is a segfault HOT 3
- unnecessary double promotion generate warning.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from catch2.