19 #include "eckit/exception/Exceptions.h"
20 #include "eckit/filesystem/PathName.h"
21 #include "eckit/log/Timer.h"
22 #include "eckit/utils/StringTools.h"
30 using namespace eckit;
39 mars_sms_label_(false),
42 if (getenv(
"MARS_SMS_LABEL"))
45 label_ = getenv(
"MARS_SMS_LABEL");
53 ASSERT(getenv(
"odc_TEST_DATA_PATH") &&
"odc_TEST_DATA_PATH must be set");
55 stringstream totalRunningTime;
56 unique_ptr<Timer> allTestsTimer(
new Timer(
"Total", totalRunningTime));
57 unique_ptr<TestCases> tests;
71 readConfig(
"/tmp/Dropbox/work/odc/src/odb/TestRunnerApplication.cfg");
72 readConfig(
"/tmp/Dropbox/work/odc/src/tools/TestRunnerApplication.cfg");
77 ASSERT(
"Suite does not exist" &&
suites_.find(suiteName) !=
suites_.end());
78 vector<string>& suite =
suites_[suiteName];
82 tests->insert(tests->end(), tsts->begin(), tsts->end());
86 allTestsTimer.reset();
88 ofstream xmlf(
"testresults.xml");
89 xmlf <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << endl;
90 xmlf <<
"<testsuite name=\"unittests\" time=\"" << StringTools::split(
" ", totalRunningTime.str())[1] <<
"\">" << endl;
92 xmlf <<
"</testsuite>" << endl;
94 size_t nTests = tests->size();
95 for (
size_t i = 0;
i < nTests; ++
i)
99 Log::info() << endl <<
"+- Phew, made it! All " << nTests <<
" tests passed successfully. " << endl << endl;
101 Log::info() << totalRunningTime.str() << endl;
105 Log::error() << endl <<
"+- Summary: " <<
failed_.size() <<
" test(s) failed." << endl;
106 for (vector<FailedTest>::iterator it =
failed_.begin(); it !=
failed_.end(); ++it) {
107 const string&
name = it->first;
108 const string& what = it->second;
114 ss <<
" " <<
failed_.size() <<
" test(s) failed";
115 throw eckit::SeriousBug(ss.str());
121 for (TestCases::const_iterator it = tests.begin(); it != tests.end(); ++it)
123 bool exceptionThrown =
false;
128 Log::info() <<
"+- Running " <<
name <<
" ..." << endl;
131 stringstream runningTime;
132 unique_ptr<Timer> timer(
new Timer(
name, runningTime));
136 }
catch (std::exception &e) {
137 Log::warning() <<
"+- FAILED" << endl;
138 exceptionThrown =
true;
139 what += string(e.what()) +
'\n';
141 Log::warning() <<
"+- FAILED: unknown exception!" << endl;
142 exceptionThrown =
true;
143 what += string(
"Uknown exception") +
'\n';
147 }
catch (std::exception &e) {
148 Log::warning() <<
"+- Exception thrown from tearDown." << endl;
149 exceptionThrown =
true;
150 what += string(
"[In tearDown:]") + string(e.what()) +
'\n';
152 Log::warning() <<
"+- FAILED: unknown exception!" << endl;
153 exceptionThrown =
true;
154 what += string(
"Uknown exception") +
'\n';
157 if (exceptionThrown) {
159 xml_ <<
"<testcase classname=\"test\" name=\"" <<
name <<
"\">" << endl;
160 xml_ <<
" <failure type=\"exception\"><![CDATA[" << what <<
"]]></failure>" << endl;
161 xml_ <<
"</testcase>" << endl;
166 Log::info() <<
"+- Passed." << endl << endl;
167 xml_ <<
"<testcase classname=\"test\" name=\"" <<
name
168 <<
"\" time=\"" << StringTools::split(
" ", runningTime.str())[1] <<
"\"/>" << endl;
175 Log::debug() <<
"TestRunner::readConfig: reading file '" << fileName <<
"'" << endl;
179 for (
size_t i = 0;
i < lines.size(); ++
i)
181 vector<string> words = StringTools::split(
":", lines[
i]);
182 if (words.size() == 0)
184 ASSERT(
"Each line of config file should be like: '<suite_name> : TestPattern1 TestPattern2 ...'" && words.size() == 2);
186 suites_[words[0]] = StringTools::split(
" \t", words[1]);
187 Log::debug() <<
"TestRunner::readConfig(\"" << fileName <<
"\"): "
189 <<
suites_[words[0]].size() <<
" entries." << endl;
197 string cmd =
"smslabel ";