From 7f7c6f9aff062359e2ef6a9b2731fe6976055752 Mon Sep 17 00:00:00 2001 From: Jez Higgins Date: Tue, 12 Jan 2010 09:42:08 +0000 Subject: [PATCH] added option to log to file in addition to console --- tests/CppUnit/TestRunner.cpp | 36 ++++++++++++++++++++++++++---------- tests/CppUnit/TestRunner.hpp | 1 + 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/tests/CppUnit/TestRunner.cpp b/tests/CppUnit/TestRunner.cpp index 4bf0d1b4..5fc55fa5 100644 --- a/tests/CppUnit/TestRunner.cpp +++ b/tests/CppUnit/TestRunner.cpp @@ -3,6 +3,7 @@ #include "textui/TableTestResult.hpp" #include "textui/XmlTestResult.hpp" #include +#include ////////////////////////////////////////// /* @@ -26,29 +27,36 @@ typedef pair mapping; typedef vector > mappings; template -bool run(const string& name, Test *test, bool verbose) +bool run(const string& name, Test *test, bool verbose, const string& logpath) { if(verbose) cout << "Running " << name << endl; result_type result(name, verbose); test->run (&result); cout << result; + if(!logpath.empty()) + { + std::string filename = logpath + "/" + name + ".log"; + std::ofstream of(filename.c_str()); + of << result; + of.close(); + } // if ... return result.wasSuccessful(); } // run -bool textrun(const string& name, Test *test, bool verbose) +bool textrun(const string& name, Test *test, bool verbose, const string& logpath) { - return run(name, test, verbose); + return run(name, test, verbose, logpath); } // textrun -bool tablerun(const string& name, Test *test, bool verbose) +bool tablerun(const string& name, Test *test, bool verbose, const string& logpath) { - return run(name, test, verbose); + return run(name, test, verbose, logpath); } // tablerun -bool xmlrun(const string& name, Test *test, bool verbose) +bool xmlrun(const string& name, Test *test, bool verbose, const string& logpath) { - return run(name, test, verbose); + return run(name, test, verbose, logpath); } // xmlrun @@ -58,7 +66,7 @@ void printBanner () cout << "Usage: driver [-v] [-table] [ -wait ] testName, where name is the name of a test case class" << endl; } // printBanner -typedef bool (*runFn)(const string& name, Test *test, bool verbose); +typedef bool (*runFn)(const string& name, Test *test, bool verbose, const string& logpath); bool TestRunner::run(int ac, const char **av) { @@ -98,6 +106,14 @@ bool TestRunner::run(int ac, const char **av) continue; } + if(string(av[i]) == "-log") + { + logpath_ = av[++i]; + cout << "logpath=" < > m_mappings; + std::string logpath_; public: TestRunner() : m_wait(false), verbose_(false) {}