PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/mordor/test/stdoutlistener.cpp

http://github.com/mozy/mordor
C++ | 84 lines | 71 code | 12 blank | 1 comment | 10 complexity | 0792e2e20a7ffca14e3cee5932d1679a MD5 | raw file
Possible License(s): BSD-3-Clause
  1. // Copyright (c) 2009 - Mozy, Inc.
  2. #include "mordor/predef.h"
  3. #include "mordor/config.h"
  4. #include "stdoutlistener.h"
  5. #include <iostream>
  6. #include <boost/exception/all.hpp>
  7. using namespace Mordor;
  8. using namespace Mordor::Test;
  9. static ConfigVar<bool>::ptr g_include_startime =
  10. Config::lookup<bool>("mordor.test.outputstarttime", true, "Print start time in test output");
  11. StdoutListener::StdoutListener()
  12. : m_tests(0),
  13. m_success(0),
  14. m_skip(0)
  15. {}
  16. void
  17. StdoutListener::testStarted(const std::string &suite, const std::string &test)
  18. {
  19. if (test != "<invariant>")
  20. ++m_tests;
  21. std::cout << "Running ";
  22. if( g_include_startime->val() )
  23. std::cout << "(" << time(NULL) << ") ";
  24. std::cout << suite << "::" << test << ": ";
  25. std::cout.flush();
  26. }
  27. void
  28. StdoutListener::testComplete(const std::string &suite, const std::string &test)
  29. {
  30. if (test != "<invariant>")
  31. ++m_success;
  32. std::cout << "OK" << std::endl;
  33. }
  34. void
  35. StdoutListener::testSkipped(const std::string &suite, const std::string &test)
  36. {
  37. if (test != "<invariant>") {
  38. ++m_skip;
  39. --m_tests;
  40. }
  41. std::cout << "skipped" << std::endl;
  42. }
  43. void
  44. StdoutListener::testAsserted(const std::string &suite, const std::string &test,
  45. const Assertion &assertion)
  46. {
  47. std::cerr << "Assertion: "
  48. << boost::current_exception_diagnostic_information() << std::endl;
  49. m_failures.push_back(std::make_pair(suite, test));
  50. }
  51. void
  52. StdoutListener::testException(const std::string &suite, const std::string &test)
  53. {
  54. std::cerr << "Unexpected exception: "
  55. << boost::current_exception_diagnostic_information() << std::endl;
  56. m_failures.push_back(std::make_pair(suite, test));
  57. }
  58. void
  59. StdoutListener::testsComplete()
  60. {
  61. std::cout << "Tests complete. " << m_success << "/" << m_tests
  62. << " passed, " << m_skip << " skipped." << std::endl;
  63. if (!m_failures.empty()) {
  64. std::cout << "Failures:" << std::endl;
  65. for (std::vector<std::pair<std::string, std::string> >::iterator
  66. it = m_failures.begin();
  67. it != m_failures.end();
  68. ++it)
  69. std::cout << '\t' << it->first << "::" << it->second
  70. << std::endl;
  71. }
  72. }