summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorshiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925>2008-07-25 04:06:16 (GMT)
committershiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925>2008-07-25 04:06:16 (GMT)
commit15cbe5f70adaade1a8a11afc37601fc6606e7e0d (patch)
treea0987a8e162b6f65ca8e1be924abee44379a80b1 /src
parentdbc56bf84bfa3fe27146b56f468a736941892dcc (diff)
downloadgoogletest-15cbe5f70adaade1a8a11afc37601fc6606e7e0d.zip
googletest-15cbe5f70adaade1a8a11afc37601fc6606e7e0d.tar.gz
googletest-15cbe5f70adaade1a8a11afc37601fc6606e7e0d.tar.bz2
Adds --gtest_print_test for printing the elapsed time of tests.
Diffstat (limited to 'src')
-rw-r--r--src/gtest-internal-inl.h7
-rw-r--r--src/gtest.cc36
2 files changed, 40 insertions, 3 deletions
diff --git a/src/gtest-internal-inl.h b/src/gtest-internal-inl.h
index 2a7d71c..5546a77 100644
--- a/src/gtest-internal-inl.h
+++ b/src/gtest-internal-inl.h
@@ -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;
diff --git a/src/gtest.cc b/src/gtest.cc
index 57ff15a..5e4c588 100644
--- a/src/gtest.cc
+++ b/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) {
&GTEST_FLAG(internal_run_death_test)) ||
ParseBoolFlag(arg, kListTestsFlag, &GTEST_FLAG(list_tests)) ||
ParseStringFlag(arg, kOutputFlag, &GTEST_FLAG(output)) ||
+ ParseBoolFlag(arg, kPrintTimeFlag, &GTEST_FLAG(print_time)) ||
ParseInt32Flag(arg, kRepeatFlag, &GTEST_FLAG(repeat))
) {
// Yes. Shift the remainder of the argv list left by one. Note