]> git.tdb.fi Git - libs/test.git/blob - source/runner.cpp
Initialize variables
[libs/test.git] / source / runner.cpp
1 #include <msp/core/getopt.h>
2 #include <msp/io/print.h>
3 #include "runner.h"
4 #include "test.h"
5
6 using namespace std;
7
8 namespace Msp {
9 namespace Test {
10
11 Runner::Runner(int argc, char **argv):
12         verbose(false),
13         show_list(false)
14 {
15         GetOpt getopt;
16         getopt.add_option('v', "verbose", verbose,   GetOpt::NO_ARG).set_help("Show what is being done");
17         getopt.add_option('l', "list",    show_list, GetOpt::NO_ARG).set_help("Print a list of available test cases");
18         getopt(argc, argv);
19
20         const vector<string> &args = getopt.get_args();
21         tests.assign(args.begin(), args.end());
22 }
23
24 int Runner::main()
25 {
26         if(show_list)
27         {
28                 const list<Test::Factory *> &factories = Test::get_factories();
29                 for(list<Test::Factory *>::const_iterator i=factories.begin(); i!=factories.end(); ++i)
30                         IO::print("%s\n", (*i)->get_name());
31         }
32         else if(tests.empty())
33                 Test::run_all(verbose);
34         else
35         {
36                 for(list<string>::const_iterator i=tests.begin(); i!=tests.end(); ++i)
37                         Test::run_single(*i, verbose);
38         }
39
40         return 0;
41 }
42
43 } // namespace Test
44 } // namespace Msp