X26-ReporterPreferencesForPassingAssertionsIsRespected.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. * Test that reporter is not passed passing assertions when it
  8. * doesn't ask for it.
  9. */
  10. #include <catch2/catch_test_macros.hpp>
  11. #include <catch2/reporters/catch_reporter_streaming_base.hpp>
  12. #include <catch2/reporters/catch_reporter_registrars.hpp>
  13. #include <iostream>
  14. #include <utility>
  15. namespace {
  16. class TestReporter : public Catch::StreamingReporterBase {
  17. public:
  18. TestReporter(Catch::ReporterConfig&& _config):
  19. StreamingReporterBase(std::move(_config)) {
  20. m_preferences.shouldReportAllAssertions = false;
  21. std::cout << "X26 - TestReporter constructed\n";
  22. }
  23. static std::string getDescription() {
  24. return "X26 - test reporter that opts out of passing assertions";
  25. }
  26. void
  27. assertionEnded( Catch::AssertionStats const& ) override {
  28. std::cerr << "X26 - assertionEnded\n";
  29. }
  30. ~TestReporter() override;
  31. };
  32. TestReporter::~TestReporter() = default;
  33. }
  34. CATCH_REGISTER_REPORTER("test-reporter", TestReporter)
  35. TEST_CASE( "Test with only passing assertions" ) {
  36. REQUIRE( 1 == 1 );
  37. REQUIRE( 2 == 2 );
  38. }