catch_main.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef CATCH_MAIN
  2. #define CATCH_MAIN
  3. #define CATCH_CONFIG_EXTERNAL_INTERFACES
  4. #define CATCH_CONFIG_MAIN
  5. #define CATCH_CONFIG_DEFAULT_REPORTER "verboseconsole"
  6. #include <catch2/catch.hpp>
  7. namespace Catch {
  8. struct VerboseConsoleReporter : public ConsoleReporter {
  9. double duration = 0.;
  10. using ConsoleReporter::ConsoleReporter;
  11. void testCaseStarting(TestCaseInfo const& _testInfo) override
  12. {
  13. Colour::use(Colour::Cyan);
  14. stream << "Testing ";
  15. Colour::use(Colour::None);
  16. stream << _testInfo.name << std::endl;
  17. ConsoleReporter::testCaseStarting(_testInfo);
  18. }
  19. void sectionStarting(const SectionInfo &_sectionInfo) override
  20. {
  21. if (_sectionInfo.name != currentTestCaseInfo->name)
  22. stream << _sectionInfo.name << std::endl;
  23. ConsoleReporter::sectionStarting(_sectionInfo);
  24. }
  25. void sectionEnded(const SectionStats &_sectionStats) override {
  26. duration += _sectionStats.durationInSeconds;
  27. ConsoleReporter::sectionEnded(_sectionStats);
  28. }
  29. void testCaseEnded(TestCaseStats const& stats) override
  30. {
  31. if (stats.totals.assertions.allOk()) {
  32. Colour::use(Colour::BrightGreen);
  33. stream << "Passed";
  34. Colour::use(Colour::None);
  35. stream << " in " << duration << " [seconds]\n" << std::endl;
  36. }
  37. duration = 0.;
  38. ConsoleReporter::testCaseEnded(stats);
  39. }
  40. };
  41. CATCH_REGISTER_REPORTER( "verboseconsole", VerboseConsoleReporter )
  42. } // namespace Catch
  43. #endif // CATCH_MAIN