From 73f71937dccf40f5b41de44cf9f65b399cf73faa Mon Sep 17 00:00:00 2001 From: Marcin Niesluchowski Date: Thu, 16 Oct 2014 14:17:36 +0200 Subject: [PATCH] Add --no-verbose option to HTML collector With --no-verbose param fail/ignore reason is not displayed Change-Id: I790d24f2db8b707df20f88e0df08ec20cf5eab03 --- .../dpl/test/test_results_collector_commons.h | 3 ++ .../include/dpl/test/test_results_collector_html.h | 9 ++-- .../src/test_results_collector_commons.cpp | 18 +++++++ .../src/test_results_collector_console.cpp | 13 +---- src/framework/src/test_results_collector_html.cpp | 57 +++++++++------------- 5 files changed, 50 insertions(+), 50 deletions(-) diff --git a/src/framework/include/dpl/test/test_results_collector_commons.h b/src/framework/include/dpl/test/test_results_collector_commons.h index 606f8c3..8fc98c1 100644 --- a/src/framework/include/dpl/test/test_results_collector_commons.h +++ b/src/framework/include/dpl/test/test_results_collector_commons.h @@ -41,11 +41,14 @@ namespace Test { "[%s%s%s] %s[elapsed: %0.3fms, expected < %0.3fms]%s\n", BOLD_GREEN_BEGIN, \ " OK ", BOLD_GREEN_END, BOLD_RED_BEGIN, elapsed, max, BOLD_RED_END +extern const std::string COLLECTOR_NO_VERBOSE_HELP; + // Get duration as a fraction of millisecond (max precision is 1 microsecond) double get_milliseconds (const std::chrono::system_clock::duration& performanceTime); std::string CollectorFileHelp(const std::string &defaultFilename); bool ParseCollectorFileArg(const std::string &arg, std::string &filename); +bool ParseCollectorNoVerboseArg(const std::string &arg, bool &verbosity); } // namespace Test } // namespace DPL diff --git a/src/framework/include/dpl/test/test_results_collector_html.h b/src/framework/include/dpl/test/test_results_collector_html.h index 90d635e..6d8eafc 100644 --- a/src/framework/include/dpl/test/test_results_collector_html.h +++ b/src/framework/include/dpl/test/test_results_collector_html.h @@ -56,12 +56,8 @@ private: = std::chrono::microseconds::zero()); virtual void Finish(); - void PrintfErrorMessage(const char* type, - const std::string& message, - bool verbosity); - void PrintfIgnoredMessage(const char* type, - const std::string& message, - bool verbosity); + void PrintfErrorMessage(const char* type, const std::string& message); + void PrintfIgnoredMessage(const char* type, const std::string& message); void PrintStats(const std::string& name, const Statistic& stats); std::string m_filename; @@ -69,6 +65,7 @@ private: Statistic m_stats; std::string m_currentGroup; std::map m_groupsStats; + bool m_verbosity; }; } // namespace Test diff --git a/src/framework/src/test_results_collector_commons.cpp b/src/framework/src/test_results_collector_commons.cpp index 701fd36..013bde2 100644 --- a/src/framework/src/test_results_collector_commons.cpp +++ b/src/framework/src/test_results_collector_commons.cpp @@ -27,6 +27,16 @@ namespace DPL { namespace Test { +namespace { + +const std::string NO_VERBOSE_ARG = "--no-verbose"; + +} // namespace + +const std::string COLLECTOR_NO_VERBOSE_HELP = + NO_VERBOSE_ARG + " - turns off verbosity\n" + + std::string(NO_VERBOSE_ARG.size(), ' ') + " verbosity turned on by default\n"; + double get_milliseconds (const std::chrono::system_clock::duration& performanceTime) { return (static_cast(std::chrono::duration_cast @@ -49,6 +59,14 @@ bool ParseCollectorFileArg(const std::string &arg, std::string &filename) return false; } +bool ParseCollectorNoVerboseArg(const std::string &arg, bool &verbosity) +{ + if (arg != NO_VERBOSE_ARG) + return false; + verbosity=false; + return true; +} + } // namespace Test } // namespace DPL diff --git a/src/framework/src/test_results_collector_console.cpp b/src/framework/src/test_results_collector_console.cpp index d60afa5..9ad0c04 100644 --- a/src/framework/src/test_results_collector_console.cpp +++ b/src/framework/src/test_results_collector_console.cpp @@ -32,11 +32,6 @@ namespace DPL { namespace Test { -namespace { - -const std::string NO_VERBOSE_ARG = "--no-verbose"; - -} ConsoleCollector::ConsoleCollector() : m_verbosity(true) @@ -50,16 +45,12 @@ TestResultsCollectorBase* ConsoleCollector::Constructor() bool ConsoleCollector::ParseCollectorSpecificArg(const std::string& arg) { - if (arg != NO_VERBOSE_ARG) - return false; - m_verbosity=false; - return true; + return ParseCollectorNoVerboseArg(arg, m_verbosity); } std::string ConsoleCollector::CollectorSpecificHelp() const { - return NO_VERBOSE_ARG + " - turns off verbosity\n" + - std::string(NO_VERBOSE_ARG.size(), ' ') + " verbosity turned on by default\n"; + return COLLECTOR_NO_VERBOSE_HELP; } void ConsoleCollector::CollectCurrentTestGroupName(const std::string& name) diff --git a/src/framework/src/test_results_collector_html.cpp b/src/framework/src/test_results_collector_html.cpp index 0ca0475..ee76c49 100644 --- a/src/framework/src/test_results_collector_html.cpp +++ b/src/framework/src/test_results_collector_html.cpp @@ -39,7 +39,8 @@ const char *DEFAULT_HTML_FILE_NAME = "index.html"; } HtmlCollector::HtmlCollector() - : m_filename(DEFAULT_HTML_FILE_NAME) + : m_filename(DEFAULT_HTML_FILE_NAME), + m_verbosity(true) { } @@ -66,7 +67,7 @@ bool HtmlCollector::Configure() std::string HtmlCollector::CollectorSpecificHelp() const { - return CollectorFileHelp(DEFAULT_HTML_FILE_NAME); + return CollectorFileHelp(DEFAULT_HTML_FILE_NAME) + COLLECTOR_NO_VERBOSE_HELP; } void HtmlCollector::Start() @@ -101,7 +102,7 @@ void HtmlCollector::Finish() bool HtmlCollector::ParseCollectorSpecificArg(const std::string& arg) { - return ParseCollectorFileArg(arg, m_filename); + return ParseCollectorFileArg(arg, m_filename) || ParseCollectorNoVerboseArg(arg, m_verbosity); } void HtmlCollector::CollectResult(const std::string& id, @@ -137,10 +138,10 @@ void HtmlCollector::CollectResult(const std::string& id, fprintf(m_fp.Get(), GREEN_RESULT_OK); break; case FailStatus::FAILED: - PrintfErrorMessage(" FAILED ", reason, true); + PrintfErrorMessage(" FAILED ", reason); break; case FailStatus::IGNORED: - PrintfIgnoredMessage("Ignored ", reason, true); + PrintfIgnoredMessage("Ignored ", reason); break; default: Assert(false && "Bad status"); @@ -149,51 +150,41 @@ void HtmlCollector::CollectResult(const std::string& id, m_stats.AddTest(status); } -void HtmlCollector::PrintfErrorMessage(const char* type, - const std::string& message, - bool verbosity) +void HtmlCollector::PrintfErrorMessage(const char* type, const std::string& message) { using namespace DPL::Colors::Html; - if (verbosity) { + fprintf(m_fp.Get(), + "[%s%s%s]", + BOLD_RED_BEGIN, + type, + BOLD_RED_END); + if (m_verbosity) { fprintf(m_fp.Get(), - "[%s%s%s] %s%s%s\n", - BOLD_RED_BEGIN, - type, - BOLD_RED_END, + " %s%s%s", BOLD_YELLOW_BEGIN, message.c_str(), BOLD_YELLOW_END); - } else { - fprintf(m_fp.Get(), - "[%s%s%s]\n", - BOLD_RED_BEGIN, - type, - BOLD_RED_END); } + fprintf(m_fp.Get(), "\n"); } -void HtmlCollector::PrintfIgnoredMessage(const char* type, - const std::string& message, - bool verbosity) +void HtmlCollector::PrintfIgnoredMessage(const char* type, const std::string& message) { using namespace DPL::Colors::Html; - if (verbosity) { + fprintf(m_fp.Get(), + "[%s%s%s]", + CYAN_BEGIN, + type, + CYAN_END); + if (m_verbosity) { fprintf(m_fp.Get(), - "[%s%s%s] %s%s%s\n", - CYAN_BEGIN, - type, - CYAN_END, + " %s%s%s", BOLD_GOLD_BEGIN, message.c_str(), BOLD_GOLD_END); - } else { - fprintf(m_fp.Get(), - "[%s%s%s]\n", - CYAN_BEGIN, - type, - CYAN_END); } + fprintf(m_fp.Get(), "\n"); } void HtmlCollector::PrintStats(const std::string& name, const Statistic& stats) -- 2.7.4