catch_reporter_bases.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Created by Phil on 27/11/2013.
  3. * Copyright 2013 Two Blue Cubes Ltd. All rights reserved.
  4. *
  5. * Distributed under the Boost Software License, Version 1.0. (See accompanying
  6. * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  7. */
  8. #include "../internal/catch_interfaces_reporter.h"
  9. #include "../internal/catch_errno_guard.h"
  10. #include "catch_reporter_bases.hpp"
  11. #include <cstring>
  12. #include <cfloat>
  13. #include <cstdio>
  14. #include <cassert>
  15. #include <memory>
  16. namespace Catch {
  17. void prepareExpandedExpression(AssertionResult& result) {
  18. result.getExpandedExpression();
  19. }
  20. // Because formatting using c++ streams is stateful, drop down to C is required
  21. // Alternatively we could use stringstream, but its performance is... not good.
  22. std::string getFormattedDuration( double duration ) {
  23. // Max exponent + 1 is required to represent the whole part
  24. // + 1 for decimal point
  25. // + 3 for the 3 decimal places
  26. // + 1 for null terminator
  27. const std::size_t maxDoubleSize = DBL_MAX_10_EXP + 1 + 1 + 3 + 1;
  28. char buffer[maxDoubleSize];
  29. // Save previous errno, to prevent sprintf from overwriting it
  30. ErrnoGuard guard;
  31. #ifdef _MSC_VER
  32. sprintf_s(buffer, "%.3f", duration);
  33. #else
  34. std::sprintf(buffer, "%.3f", duration);
  35. #endif
  36. return std::string(buffer);
  37. }
  38. bool shouldShowDuration( IConfig const& config, double duration ) {
  39. if ( config.showDurations() == ShowDurations::Always ) {
  40. return true;
  41. }
  42. if ( config.showDurations() == ShowDurations::Never ) {
  43. return false;
  44. }
  45. const double min = config.minDuration();
  46. return min >= 0 && duration >= min;
  47. }
  48. std::string serializeFilters( std::vector<std::string> const& container ) {
  49. ReusableStringStream oss;
  50. bool first = true;
  51. for (auto&& filter : container)
  52. {
  53. if (!first)
  54. oss << ' ';
  55. else
  56. first = false;
  57. oss << filter;
  58. }
  59. return oss.str();
  60. }
  61. TestEventListenerBase::TestEventListenerBase(ReporterConfig const & _config)
  62. :StreamingReporterBase(_config) {}
  63. std::set<Verbosity> TestEventListenerBase::getSupportedVerbosities() {
  64. return { Verbosity::Quiet, Verbosity::Normal, Verbosity::High };
  65. }
  66. void TestEventListenerBase::assertionStarting(AssertionInfo const &) {}
  67. bool TestEventListenerBase::assertionEnded(AssertionStats const &) {
  68. return false;
  69. }
  70. } // end namespace Catch