recorder.hpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // Official repository: https://github.com/boostorg/beast
  8. //
  9. #ifndef BOOST_BEAST_UNIT_TEST_RECORDER_HPP
  10. #define BOOST_BEAST_UNIT_TEST_RECORDER_HPP
  11. #include <boost/beast/_experimental/unit_test/results.hpp>
  12. #include <boost/beast/_experimental/unit_test/runner.hpp>
  13. namespace boost {
  14. namespace beast {
  15. namespace unit_test {
  16. /** A test runner that stores the results. */
  17. class recorder : public runner
  18. {
  19. results m_results;
  20. suite_results m_suite;
  21. case_results m_case;
  22. public:
  23. recorder() = default;
  24. /** Returns a report with the results of all completed suites. */
  25. results const&
  26. report() const
  27. {
  28. return m_results;
  29. }
  30. private:
  31. virtual
  32. void
  33. on_suite_begin(suite_info const& info) override
  34. {
  35. m_suite = suite_results(info.full_name());
  36. }
  37. virtual
  38. void
  39. on_suite_end() override
  40. {
  41. m_results.insert(std::move(m_suite));
  42. }
  43. virtual
  44. void
  45. on_case_begin(std::string const& name) override
  46. {
  47. m_case = case_results(name);
  48. }
  49. virtual
  50. void
  51. on_case_end() override
  52. {
  53. if(m_case.tests.size() > 0)
  54. m_suite.insert(std::move(m_case));
  55. }
  56. virtual
  57. void
  58. on_pass() override
  59. {
  60. m_case.tests.pass();
  61. }
  62. virtual
  63. void
  64. on_fail(std::string const& reason) override
  65. {
  66. m_case.tests.fail(reason);
  67. }
  68. virtual
  69. void
  70. on_log(std::string const& s) override
  71. {
  72. m_case.log.insert(s);
  73. }
  74. };
  75. } // unit_test
  76. } // beast
  77. } // boost
  78. #endif