X24-ListenerStdoutCaptureInMultireporter.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // Copyright Catch2 Authors
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // https://www.boost.org/LICENSE_1_0.txt)
  5. // SPDX-License-Identifier: BSL-1.0
  6. /**\file
  7. * Registers custom listener that does not ask for captured stdout/err
  8. *
  9. * Running the binary with this listener, and asking for multiple _capturing_
  10. * reporters (one would be sufficient, but that would also mean depending on
  11. * implementation details inside Catch2's handling of listeners), we check that
  12. * nothing is written to stdout, because listeners should not be considered in
  13. * whether the stdout should be passed-through or not.
  14. */
  15. #include <catch2/catch_test_macros.hpp>
  16. #include <catch2/reporters/catch_reporter_event_listener.hpp>
  17. #include <catch2/reporters/catch_reporter_registrars.hpp>
  18. #include <iostream>
  19. namespace {
  20. class NonCapturingListener : public Catch::EventListenerBase {
  21. public:
  22. NonCapturingListener( Catch::IConfig const* config ):
  23. EventListenerBase( config ) {
  24. m_preferences.shouldRedirectStdOut = false;
  25. std::cerr << "X24 - NonCapturingListener initialized.\n";
  26. }
  27. };
  28. }
  29. CATCH_REGISTER_LISTENER( NonCapturingListener )
  30. TEST_CASE( "Writes to stdout" ) {
  31. std::cout << "X24 - FooBarBaz\n";
  32. }