<commit_before>#include <exception>
#include <functional>
#include <list>
#include <ccspec/core/example.h>
#include <ccspec/core/example_group.h>
#include <ccspec/core/hooks.h>
#include <ccspec/core/reporter.h>
#include <ccspec/core/unexpected_throw.h>
#include <ccspec/support/exception.h>

namespace ccspec {
namespace core {

using std::current_exception;
using std::make_exception_ptr;
using std::exception;
using std::exception_ptr;
using std::function;
using std::list;
using std::string;
using ccspec::core::UnexpectedThrow;

// Public methods.

// This function enables chaining of around hooks. Callers call this function
// inside each around hook (lambda function), then this function calls the next
// around hook in the chain.
//
// Since this function is nullary, in order to remember the state of which
// around hook to execute next, the around hooks need to be stored in a member
// variable `around_hooks_`. This also implies that `around_hooks_` must be
// mutated in this function in order to transition to the next state.
void Example::run() const {
    if (reporter_ == nullptr ||
        before_each_hooks_ == nullptr ||
        after_each_hooks_ == nullptr) {
        // The required pointers should have been initialized by the overloaded
        // run function before this function is called.
        return;
    }

    if (around_hooks_.empty()) {
        ExecutionResult execution_result;
        auto handleFailure = [&](exception_ptr e) {
            execution_result.set_exception(e);
            reporter_->exampleFailed(execution_result);
        };

        for (auto hook : *before_each_hooks_)
            hook();
        try {
            spec_();
            reporter_->examplePassed(execution_result);
        } catch (const ccspec::support::Exception& e) {
            // The exception can only be a Mismatch as no other CCSpec
            // exceptions should be thrown inside the spec of an example.
            handleFailure(current_exception());
        } catch (const exception& e) {
            handleFailure(make_exception_ptr(UnexpectedThrow(e)));
        }
        for (auto hook : *after_each_hooks_)
            hook();
    } else {
        AroundHook around_hook = around_hooks_.front();<commit_msg>Fail examples if before each hooks fail<commit_after>#include <exception>
#include <functional>
#include <list>
#include <ccspec/core/example.h>
#include <ccspec/core/example_group.h>
#include <ccspec/core/hooks.h>
#include <ccspec/core/reporter.h>
#include <ccspec/core/unexpected_throw.h>
#include <ccspec/support/exception.h>

namespace ccspec {
namespace core {

using std::current_exception;
using std::make_exception_ptr;
using std::exception;
using std::exception_ptr;
using std::function;
using std::list;
using std::string;
using ccspec::core::UnexpectedThrow;

// Public methods.

// This function enables chaining of around hooks. Callers call this function
// inside each around hook (lambda function), then this function calls the next
// around hook in the chain.
//
// Since this function is nullary, in order to remember the state of which
// around hook to execute next, the around hooks need to be stored in a member
// variable `around_hooks_`. This also implies that `around_hooks_` must be
// mutated in this function in order to transition to the next state.
void Example::run() const {
    if (reporter_ == nullptr ||
        before_each_hooks_ == nullptr ||
        after_each_hooks_ == nullptr) {
        // The required pointers should have been initialized by the overloaded
        // run function before this function is called.
        return;
    }

    if (around_hooks_.empty()) {
        ExecutionResult execution_result;
        auto handleFailure = [&](exception_ptr e) {
            execution_result.set_exception(e);
            reporter_->exampleFailed(execution_result);
        };

        try {
            for (auto hook : *before_each_hooks_)
                hook();
            spec_();
            reporter_->examplePassed(execution_result);
        } catch (const ccspec::support::Exception& e) {
            // The exception can only be a Mismatch as no other CCSpec
            // exceptions should be thrown inside the spec code.
            handleFailure(current_exception());
        } catch (const exception& e) {
            handleFailure(make_exception_ptr(UnexpectedThrow(e)));
        }
        for (auto hook : *after_each_hooks_)
            hook();
    } else {
        AroundHook around_hook = around_hooks_.front();
{'fraction_non_alphanumeric': 0.09715168911459483, 'fraction_numerical': 0.0, 'mean_word_length': 3.012400354295837, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7444771', 'n_tokens_mistral': 1218, 'n_tokens_neox': 1218, 'n_words': 409}