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

summaryrefslogtreecommitdiffhomepage
path: root/tests/ExtraTests/X25-ListenerCanAskForCapturedStdout.cpp
blob: 67c7d0b1fd7da3bda1f8b0ccbbba5c2e5d813d0e (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

//              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

/**\file
 * Registers custom listener that asks for captured stdout/err
 *
 * Running the binary with this listener, and asking for multiple _noncapturing_
 * reporters (one would be sufficient, but that would also mean depending on
 * implementation details inside Catch2's handling of listeners), we check that
 * the listener gets redirected stdout, even though the reporters didn't ask for
 * it.
 */

#include <Progmasoft/Catch3/TestMacros.hpp>
#include <Progmasoft/Catch3/Reporters/EventListener.hpp>
#include <Progmasoft/Catch3/Reporters/Registrars.hpp>

#include <iostream>

namespace {
	class CapturingListener : public Catch::EventListenerBase {
    public:
        CapturingListener( Catch::IConfig const* config ):
            EventListenerBase( config ) {
            m_preferences.shouldRedirectStdOut = true;
            std::cerr << "CapturingListener initialized\n";
		}

		void
        testCaseEnded( Catch::TestCaseStats const& testCaseStats ) override {
            if ( testCaseStats.stdOut.empty() ) {
                std::cerr << "X25 - ERROR: empty stdout\n";
            }
        }
	};
}

CATCH_REGISTER_LISTENER( CapturingListener )

TEST_CASE( "Writes to stdout" ) {
	std::cout << "X25 - FooBarBaz\n";
}