]> git.tdb.fi Git - libs/test.git/blob - source/runner.cpp
Initial commit
[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 {
13         GetOpt getopt;
14         getopt.add_option('v', "verbose", verbose,   GetOpt::NO_ARG).set_help("Show what is being done");
15         getopt.add_option('l', "list",    show_list, GetOpt::NO_ARG).set_help("Print a list of available test cases");
16         getopt(argc, argv);
17
18         const vector<string> &args = getopt.get_args();
19         tests.assign(args.begin(), args.end());
20 }
21
22 int Runner::main()
23 {
24         if(show_list)
25         {
26                 const list<Test::Factory *> &factories = Test::get_factories();
27                 for(list<Test::Factory *>::const_iterator i=factories.begin(); i!=factories.end(); ++i)
28                         IO::print("%s\n", (*i)->get_name());
29         }
30         else if(tests.empty())
31                 Test::run_all(verbose);
32         else
33         {
34                 for(list<string>::const_iterator i=tests.begin(); i!=tests.end(); ++i)
35                         Test::run_single(*i, verbose);
36         }
37
38         return 0;
39 }
40
41 } // namespace Test
42 } // namespace Msp