X29-CustomArgumentsForReporters.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 custom options are properly passed down to the reporter.
  8. *
  9. * We print out the arguments sorted by key, to have a stable expected
  10. * output.
  11. */
  12. #include <catch2/catch_test_macros.hpp>
  13. #include <catch2/reporters/catch_reporter_streaming_base.hpp>
  14. #include <catch2/reporters/catch_reporter_registrars.hpp>
  15. #include <algorithm>
  16. #include <iostream>
  17. #include <string>
  18. #include <utility>
  19. #include <vector>
  20. class TestReporter : public Catch::StreamingReporterBase {
  21. public:
  22. TestReporter( Catch::ReporterConfig&& _config ):
  23. StreamingReporterBase( std::move(_config) ) {
  24. std::cout << "X29 - TestReporter constructed\n";
  25. }
  26. static std::string getDescription() {
  27. return "X29 test reporter";
  28. }
  29. void testRunStarting( Catch::TestRunInfo const& ) override {
  30. std::vector<std::pair<std::string, std::string>> options;
  31. for ( auto const& kv : m_customOptions ) {
  32. options.push_back( kv );
  33. }
  34. std::sort( options.begin(), options.end() );
  35. bool first = true;
  36. for ( auto const& kv : options ) {
  37. if ( !first ) { std::cout << "::"; }
  38. std::cout << kv.first << "=" << kv.second;
  39. first = false;
  40. }
  41. std::cout << '\n';
  42. }
  43. ~TestReporter() override;
  44. };
  45. TestReporter::~TestReporter() = default;
  46. CATCH_REGISTER_REPORTER( "test-reporter", TestReporter )
  47. TEST_CASE( "Just a test case to run things" ) {}