2323#include " library.h"
2424#include " options.h"
2525#include " redirect.h"
26+ #include " timer.h"
2627
2728#include < algorithm>
2829#include < cstdio>
@@ -88,6 +89,7 @@ TestFixture::TestFixture(const char * const _name)
8889 : classname(_name)
8990{}
9091
92+ TestFixture::~TestFixture () = default ;
9193
9294bool TestFixture::prepareTest (const char testname[])
9395{
@@ -106,19 +108,25 @@ bool TestFixture::prepareTest(const char testname[])
106108 // Tests will be executed - prepare them
107109 mTestname = testname;
108110 ++countTests;
111+ std::string fullTestName = classname + " ::" + mTestname ;
109112 if (quiet_tests) {
110113 std::putchar (' .' ); // Use putchar to write through redirection of std::cout/cerr
111114 std::fflush (stdout);
112115 } else {
113- std::cout << classname << " :: " << mTestname << std::endl;
116+ std::cout << fullTestName << std::endl;
114117 }
118+ if (timer_results)
119+ mTimer .reset (new Timer (fullTestName, ShowTime::TOP5_SUMMARY, timer_results));
115120 return !dry_run;
116121}
117122
118123void TestFixture::teardownTest ()
119124{
120125 teardownTestInternal ();
121126
127+ if (mTimer )
128+ mTimer ->stop ();
129+
122130 {
123131 const std::string s = errout_str ();
124132 if (!s.empty ())
@@ -385,6 +393,7 @@ void TestFixture::processOptions(const options& args)
385393 dry_run = args.dry_run ();
386394 exclude_tests = args.exclude_tests ();
387395 exename = args.exe ();
396+ timer_results = args.timer_results ();
388397}
389398
390399std::size_t TestFixture::runTests (const options& args)
@@ -410,7 +419,15 @@ std::size_t TestFixture::runTests(const options& args)
410419 tests = it->second ;
411420 }
412421
413- TestFixture* fixture = test->create ();
422+ TestFixture* fixture;
423+ const auto f = [&](){
424+ fixture = test->create ();
425+ };
426+ // TODO: Timer::run() needs proper handling if no results should be collected
427+ if (args.timer_results ())
428+ Timer::run (test->classname + " - create" , ShowTime::TOP5_SUMMARY, args.timer_results (), f);
429+ else
430+ f ();
414431 fixture->processOptions (args);
415432 fixture->run (tests);
416433 }
0 commit comments