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

summaryrefslogtreecommitdiffhomepage
path: root/src/Progmasoft/Catch3/Session.hpp
blob: b6bd75ac77286e0bc37cfa45ca943a79719b8f98 (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
65
66

//              Copyright Catch2 Authors
// Distributed under the Boost Software License, Version 1.0.
//   (See accompanying file LICENSE.txt or copy at
//        https://www.boost.org/LICENSE_1_0.txt)

// SPDX-License-Identifier: BSL-1.0
#pragma once

#include <Progmasoft/Catch3/Internal/NonCopyable.hpp>
#include <Progmasoft/Catch3/Internal/ConfigWchar.hpp>

#include <string>
#include <vector>

namespace Catch {

    constexpr int UnspecifiedErrorExitCode = 1;
    constexpr int NoTestsRunExitCode = 2;
    constexpr int UnmatchedTestSpecExitCode = 3;
    constexpr int AllTestsSkippedExitCode = 4;
    constexpr int InvalidTestSpecExitCode = 5;
    constexpr int TestFailureExitCode = 42;

    /**
     * The entry point of a test binary with its own `main`.
     *
     * It hands the command line to the Catch3 runner, which runs the tests
     * in worker processes started from the same binary. Code in `main`
     * before and after `run` therefore also runs in every worker: global
     * set-up belongs there, or in a listener.
     */
    class Session : Detail::NonCopyable {
    public:

        Session();
        ~Session();

        //! Prints the options of the Catch3 runner.
        void showHelp() const;

        //! Keeps the command line for a later `run()`. It is checked by
        //! `run()`, which reports a mistake and returns 1.
        int applyCommandLine( int argc, char const * const * argv );
    #if defined(CATCH_CONFIG_WCHAR) && defined(_WIN32) && defined(UNICODE)
        int applyCommandLine( int argc, wchar_t const * const * argv );
    #endif

        template<typename CharT>
        int run(int argc, CharT const * const argv[]) {
            int returnCode = applyCommandLine(argc, argv);
            if (returnCode == 0)
                returnCode = run();
            return returnCode;
        }

        //! Runs the tests the command line selects and returns the exit
        //! code: 0, or one of the constants above.
        int run();

    private:
        std::vector<std::string> m_arguments;
    };

} // end namespace Catch