7 #ifndef IGLOO_TESTRUNNER_H 8 #define IGLOO_TESTRUNNER_H 10 #include <igloo/core/testresult.h> 11 #include <igloo/core/testresults.h> 12 #include <igloo/core/testlisteners/minimalprogresstestlistener.h> 13 #include <igloo/external/choices/choices.h> 22 typedef std::list<BaseContextRunner*> ContextRunners;
24 static int RunAllTests(
int argc = 0,
const char *argv[] = 0)
26 choices::options opt = choices::parse_cmd(argc, argv);
28 if(c::has_option(
"version", opt))
30 std::cout << IGLOO_VERSION << std::endl;
34 if(c::has_option(
"help", opt))
36 std::cout <<
"Usage: <igloo-executable> [--version] [--output=color|vs|xunit]" << std::endl;
37 std::cout <<
"Options:" << std::endl;
38 std::cout <<
" --version:\tPrint version of igloo and exit." << std::endl;
39 std::cout <<
" --output:\tFormat output of test results." << std::endl;
40 std::cout <<
"\t\t--output=color:\tColored output" << std::endl;
41 std::cout <<
"\t\t--output=vs:\tVisual studio friendly output." << std::endl;
42 std::cout <<
"\t\t--output=xunit:\tXUnit formatted output." << std::endl;
43 std::cout <<
"\t\t--output=default:\tDefault output format." << std::endl;
47 std::auto_ptr<TestResultsOutput> output;
48 if(c::has_option(
"output", opt))
50 std::string val = c::option_value(
"output", opt);
55 else if(val ==
"color")
59 else if(val ==
"xunit")
63 else if(val ==
"default")
69 std::cerr <<
"Unknown output: " << c::option_value(
"output", opt) << std::endl;
82 runner.AddListener(&progressOutput);
94 return runner->IsContextMarkedAsOnly();
97 int Run(
const ContextRunners& runners)
101 listenerAggregator_.TestRunStarting();
103 bool only_has_been_found = std::find_if(runners.begin(), runners.end(), is_only) != runners.end();
105 for (ContextRunners::const_iterator it = runners.begin(); it != runners.end(); it++)
108 if(!only_has_been_found || contextRunner->IsContextMarkedAsOnly()) {
109 if(!contextRunner->IsMarkedAsSkip()) {
110 contextRunner->Run(results, listenerAggregator_);
115 listenerAggregator_.TestRunEnded(results);
117 output_.PrintResult(results);
118 return results.NumberOfFailedTests();
123 int numberOfFailedTests = Run(RegisteredRunners());
125 return numberOfFailedTests;
129 template <
typename ContextRunnerType>
130 static void RegisterContext(
const std::string& name,
const char* fileName,
int lineNumber)
132 if(!ContextIsRegistered(name, fileName, lineNumber))
134 ContextRunnerType* contextRunner = 0;
139 contextRunner =
new ContextRunnerType(name, fileName, lineNumber);
140 TestRunner::RegisteredRunners().push_back(contextRunner);
144 contextRunner->InstantiateContext();
148 delete contextRunner;
156 listenerAggregator_.AddListener(listener);
160 static void CleanUpRunners()
162 while(!RegisteredRunners().empty())
164 delete RegisteredRunners().front();
165 RegisteredRunners().pop_front();
169 static bool ContextIsRegistered(
const std::string& name,
const char* fileName,
int lineNumber)
171 for (ContextRunners::const_iterator it = RegisteredRunners().begin(); it != RegisteredRunners().end(); ++it)
173 if((*it)->ContextName() == name &&
174 (*it)->FileName() == fileName &&
175 (*it)->LineNumber() == lineNumber)
184 static TestRunner::ContextRunners& RegisteredRunners()
186 static TestRunner::ContextRunners contextRunners;
187 return contextRunners;
196 #endif // IGLOO_TESTRUNNER_H Definition: testresultsoutput.h:12
Definition: testlistener.h:14
Definition: testlisteneraggregator.h:11
Definition: minimalprogresstestlistener.h:12
Definition: contextrunner.h:13
Definition: visualstudiooutput.h:12
Definition: xunitoutput.h:15
Definition: defaulttestresultsoutput.h:12
Definition: testrunner.h:19
Definition: coloredconsoletestresultsoutput.h:13
Definition: testresults.h:12