tut logo

tut_main.hpp Source File


tut_main.hpp
1 #ifndef TUT_MAIN_H
2 #define TUT_MAIN_H
3 
4 #include <tut/tut.hpp>
5 #include <tut/tut_console_reporter.hpp>
6 #include <tut/tut_cppunit_reporter.hpp>
7 #include <iostream>
8 #include <cstring>
9 
10 namespace tut
11 {
12 
54 inline bool tut_main(int argc, const char * const * const argv, std::ostream &os = std::cerr)
55 {
56  std::stringstream usage;
57  usage << "Usage: " << argv[0] << " [group] [testcase]" << std::endl;
58  groupnames gr = runner.get().list_groups();
59  usage << "Available test groups:" << std::endl;
60  for(groupnames::const_iterator i = gr.begin(); i != gr.end(); ++i)
61  {
62  usage << " " << *i << std::endl;
63  }
64 
65  if(argc>1)
66  {
67  if(std::string(argv[1]) == "-h" ||
68  std::string(argv[1]) == "--help" ||
69  std::string(argv[1]) == "/?" ||
70  argc > 3)
71  {
72  os << usage.rdbuf();
73  return false;
74  }
75  }
76 
77  // Check command line options.
78  switch(argc)
79  {
80  case 1:
81  runner.get().run_tests();
82  break;
83 
84  case 2:
85  runner.get().run_tests(argv[1]);
86  break;
87 
88  case 3:
89  {
90  char *end;
91  int t = strtol(argv[2], &end, 10);
92  if(end != argv[2] + strlen(argv[2]))
93  {
94  throw no_such_test("`" + std::string(argv[2]) + "` should be a number");
95  }
96 
97  test_result tr;
98  if(!runner.get().run_test(argv[1], t, tr) || tr.result == test_result::dummy)
99  {
100  throw no_such_test("No testcase `" + std::string(argv[2]) + "` in group `" + argv[1] + "`");
101  }
102  }
103  break;
104  }
105 
106  return true;
107 } // tut_main()
108 
109 }
110 
111 #endif
Definition: tut_exception.hpp:68
bool run_test(const std::string &group_name, int n, test_result &tr) const
Definition: tut_runner.hpp:268
bool tut_main(int argc, const char *const *const argv, std::ostream &os=std::cerr)
Definition: tut_main.hpp:54
std::vector< std::string > groupnames
Definition: tut_runner.hpp:107
void run_tests() const
Definition: tut_runner.hpp:222
const groupnames list_groups() const
Definition: tut_runner.hpp:209
Definition: tut_result.hpp:69

All Rights Reserved. Generated on Wed Dec 18 2013 11:19:52 for TUT by doxygen 1.8.5