Function acquire

Synopsis

#include <include/internal/catch_run_context.cpp>

static GeneratorTracker & acquire(TrackerContext &ctx, TestCaseTracking::NameAndLocation const &nameAndLocation)

Description

No description yet.

Source

Lines 24-58 in include/internal/catch_run_context.cpp.

static GeneratorTracker& acquire( TrackerContext& ctx, TestCaseTracking::NameAndLocation const& nameAndLocation ) {
    std::shared_ptr<GeneratorTracker> tracker;
    ITracker& currentTracker = ctx.currentTracker();
    // Under specific circumstances, the generator we want
    // to acquire is also the current tracker. If this is
    // the case, we have to avoid looking through current
    // tracker's children, and instead return the current
    // tracker.
    // A case where this check is important is e.g.
    //     for (int i = 0; i < 5; ++i) {
    //         int n = GENERATE(1, 2);
    //     }
    //
    // without it, the code above creates 5 nested generators.
    if (currentTracker.nameAndLocation() == nameAndLocation) {
        auto thisTracker = currentTracker.parent().findChild(nameAndLocation);
        assert(thisTracker);
        assert(thisTracker->isGeneratorTracker());
        tracker = std::static_pointer_cast<GeneratorTracker>(thisTracker);
    } else if ( TestCaseTracking::ITrackerPtr childTracker = currentTracker.findChild( nameAndLocation ) ) {
        assert( childTracker );
        assert( childTracker->isGeneratorTracker() );
        tracker = std::static_pointer_cast<GeneratorTracker>( childTracker );
    } else {
        tracker = std::make_shared<GeneratorTracker>( nameAndLocation, ctx, &currentTracker );
        currentTracker.addChild( tracker );
    }
    if( !tracker->isComplete() ) {
        tracker->open();
    }
    return *tracker;
}





Add Discussion as Guest

Log in