Adds --gtest_print_test for printing the elapsed time of tests.
This commit is contained in:
@@ -70,6 +70,7 @@ GTEST_DECLARE_string(color);
|
||||
GTEST_DECLARE_string(filter);
|
||||
GTEST_DECLARE_bool(list_tests);
|
||||
GTEST_DECLARE_string(output);
|
||||
GTEST_DECLARE_bool(print_time);
|
||||
GTEST_DECLARE_int32(repeat);
|
||||
GTEST_DECLARE_int32(stack_trace_depth);
|
||||
GTEST_DECLARE_bool(show_internal_stack_frames);
|
||||
@@ -79,10 +80,11 @@ namespace internal {
|
||||
// Names of the flags (needed for parsing Google Test flags).
|
||||
const char kBreakOnFailureFlag[] = "break_on_failure";
|
||||
const char kCatchExceptionsFlag[] = "catch_exceptions";
|
||||
const char kColorFlag[] = "color";
|
||||
const char kFilterFlag[] = "filter";
|
||||
const char kListTestsFlag[] = "list_tests";
|
||||
const char kOutputFlag[] = "output";
|
||||
const char kColorFlag[] = "color";
|
||||
const char kPrintTimeFlag[] = "print_time";
|
||||
const char kRepeatFlag[] = "repeat";
|
||||
|
||||
// This class saves the values of all Google Test flags in its c'tor, and
|
||||
@@ -99,6 +101,7 @@ class GTestFlagSaver {
|
||||
internal_run_death_test_ = GTEST_FLAG(internal_run_death_test);
|
||||
list_tests_ = GTEST_FLAG(list_tests);
|
||||
output_ = GTEST_FLAG(output);
|
||||
print_time_ = GTEST_FLAG(print_time);
|
||||
repeat_ = GTEST_FLAG(repeat);
|
||||
}
|
||||
|
||||
@@ -112,6 +115,7 @@ class GTestFlagSaver {
|
||||
GTEST_FLAG(internal_run_death_test) = internal_run_death_test_;
|
||||
GTEST_FLAG(list_tests) = list_tests_;
|
||||
GTEST_FLAG(output) = output_;
|
||||
GTEST_FLAG(print_time) = print_time_;
|
||||
GTEST_FLAG(repeat) = repeat_;
|
||||
}
|
||||
private:
|
||||
@@ -124,6 +128,7 @@ class GTestFlagSaver {
|
||||
String internal_run_death_test_;
|
||||
bool list_tests_;
|
||||
String output_;
|
||||
bool print_time_;
|
||||
bool pretty_;
|
||||
internal::Int32 repeat_;
|
||||
} GTEST_ATTRIBUTE_UNUSED;
|
||||
|
||||
36
src/gtest.cc
36
src/gtest.cc
@@ -169,6 +169,12 @@ GTEST_DEFINE_string(
|
||||
"executable's name and, if necessary, made unique by adding "
|
||||
"digits.");
|
||||
|
||||
GTEST_DEFINE_bool(
|
||||
print_time,
|
||||
internal::BoolFromGTestEnv("print_time", false),
|
||||
"True iff " GTEST_NAME
|
||||
" should display elapsed time in text output.");
|
||||
|
||||
GTEST_DEFINE_int32(
|
||||
repeat,
|
||||
internal::Int32FromGTestEnv("repeat", 1),
|
||||
@@ -2303,6 +2309,7 @@ class PrettyUnitTestResultPrinter : public UnitTestEventListenerInterface {
|
||||
virtual void OnUnitTestStart(const UnitTest * unit_test);
|
||||
virtual void OnGlobalSetUpStart(const UnitTest*);
|
||||
virtual void OnTestCaseStart(const TestCase * test_case);
|
||||
virtual void OnTestCaseEnd(const TestCase * test_case);
|
||||
virtual void OnTestStart(const TestInfo * test_info);
|
||||
virtual void OnNewTestPartResult(const TestPartResult * result);
|
||||
virtual void OnTestEnd(const TestInfo * test_info);
|
||||
@@ -2349,6 +2356,20 @@ void PrettyUnitTestResultPrinter::OnTestCaseStart(
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void PrettyUnitTestResultPrinter::OnTestCaseEnd(
|
||||
const TestCase * test_case) {
|
||||
if (!GTEST_FLAG(print_time)) return;
|
||||
|
||||
test_case_name_ = test_case->name();
|
||||
const internal::String counts =
|
||||
FormatCountableNoun(test_case->test_to_run_count(), "test", "tests");
|
||||
ColoredPrintf(COLOR_GREEN, "[----------] ");
|
||||
printf("%s from %s (%s ms total)\n\n",
|
||||
counts.c_str(), test_case_name_.c_str(),
|
||||
internal::StreamableToString(test_case->elapsed_time()).c_str());
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
void PrettyUnitTestResultPrinter::OnTestStart(const TestInfo * test_info) {
|
||||
ColoredPrintf(COLOR_GREEN, "[ RUN ] ");
|
||||
PrintTestName(test_case_name_.c_str(), test_info->name());
|
||||
@@ -2363,7 +2384,12 @@ void PrettyUnitTestResultPrinter::OnTestEnd(const TestInfo * test_info) {
|
||||
ColoredPrintf(COLOR_RED, "[ FAILED ] ");
|
||||
}
|
||||
PrintTestName(test_case_name_.c_str(), test_info->name());
|
||||
printf("\n");
|
||||
if (GTEST_FLAG(print_time)) {
|
||||
printf(" (%s ms)\n", internal::StreamableToString(
|
||||
test_info->result()->elapsed_time()).c_str());
|
||||
} else {
|
||||
printf("\n");
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
@@ -2420,9 +2446,14 @@ void PrettyUnitTestResultPrinter::OnUnitTestEnd(
|
||||
const internal::UnitTestImpl* const impl = unit_test->impl();
|
||||
|
||||
ColoredPrintf(COLOR_GREEN, "[==========] ");
|
||||
printf("%s from %s ran.\n",
|
||||
printf("%s from %s ran.",
|
||||
FormatTestCount(impl->test_to_run_count()).c_str(),
|
||||
FormatTestCaseCount(impl->test_case_to_run_count()).c_str());
|
||||
if (GTEST_FLAG(print_time)) {
|
||||
printf(" (%s ms total)",
|
||||
internal::StreamableToString(impl->elapsed_time()).c_str());
|
||||
}
|
||||
printf("\n");
|
||||
ColoredPrintf(COLOR_GREEN, "[ PASSED ] ");
|
||||
printf("%s.\n", FormatTestCount(impl->successful_test_count()).c_str());
|
||||
|
||||
@@ -3505,6 +3536,7 @@ void InitGoogleTestImpl(int* argc, CharType** argv) {
|
||||
>EST_FLAG(internal_run_death_test)) ||
|
||||
ParseBoolFlag(arg, kListTestsFlag, >EST_FLAG(list_tests)) ||
|
||||
ParseStringFlag(arg, kOutputFlag, >EST_FLAG(output)) ||
|
||||
ParseBoolFlag(arg, kPrintTimeFlag, >EST_FLAG(print_time)) ||
|
||||
ParseInt32Flag(arg, kRepeatFlag, >EST_FLAG(repeat))
|
||||
) {
|
||||
// Yes. Shift the remainder of the argv list left by one. Note
|
||||
|
||||
Reference in New Issue
Block a user