Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/src/Progmasoft/Runner/Execution.hpp
blob: 04bae953a8a648415bd90e4ed9b9b8b9d7172c12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) 2026 Progmasoft.
// SPDX-License-Identifier: MPL-2.0 WITH AdditionRef-Progmasoft-Exception-2.0
#pragma once

#include <functional>
#include <memory>
#include <string>

#include "Catalog.hpp"
#include "Json.hpp"
#include "Options.hpp"

namespace Catch
{
    struct ConfigData;
} // namespace Catch

namespace Progmasoft::Catch3::Runner
{
    /// The Catch2 configuration a process that runs tests uses for
    /// `options`.
    [[nodiscard]] Catch::ConfigData
    ToConfigData(const Options &options, const std::string &programName);

    /// Receives the events of the tests a `TestExecutor` runs, as the JSON
    /// messages a worker sends; see `Protocol.hpp`.
    using EventSink = std::function<void(const JsonValue &)>;

    /// Runs tests of this binary in this process with Catch2's engine: the
    /// sections, generators, assertions and listeners are Catch2's.
    ///
    /// One executor lives for the whole process, because Catch2 allows one
    /// run context per process; listeners see one test run, from the first
    /// test to the destruction of the executor.
    class TestExecutor final
    {
    public:
        TestExecutor(const Options &options,
                     const Catalog &catalog,
                     const std::string &programName,
                     EventSink sink);
        TestExecutor(const TestExecutor &) = delete;
        TestExecutor &
        operator=(const TestExecutor &) = delete;
        ~TestExecutor();

        /// Runs one test. `temporaryDirectory` becomes TMPDIR, TMP and TEMP
        /// while it runs; empty leaves them alone.
        void
        Run(std::size_t index,
            std::size_t attempt,
            const std::string &temporaryDirectory);

        /// The executor's Catch2 configuration and run context.
        struct State;

    private:
        std::unique_ptr<State> state_;
    };

    /// Serves a runner over the standard streams until it says to stop.
    [[nodiscard]] int
    RunWorker(const Options &options, const std::string &programName);
} // namespace Progmasoft::Catch3::Runner