testRunner.cc
Go to the documentation of this file.
1 /*
2  Generic test runner for CppUnit based tests. No modifications needed
3 
4  \author Lukas Nellen
5 
6  \ingroup testing
7 */
8 
9 #include <iostream>
10 #include <boost/program_options.hpp>
11 #include <fwk/CommandLineOptions.h>
12 #include <cppunit/extensions/HelperMacros.h>
13 #include <cppunit/ui/text/TestRunner.h>
14 #ifdef _GNU_SOURCE
15 #include <fenv.h>
16 #endif
17 
18 using namespace std;
19 using namespace CppUnit;
20 namespace po = boost::program_options;
21 
22 
23 int
24 main(int argc, char* argv[])
25 {
26  int fpException;
27  po::options_description desc("Usage:");
28  desc.add_options()
29  ("help,h",
30  "write this message")
31  ("fpexception,x",
32  po::value<int>(&fpException),
33  "Unmask specific floating-point exceptions for debugging: "
34  "1=invalid-sqrt(-1), 4=div-by-0, 8=overflow.")
35  ("log-db-queries",
36  po::value<int>(),
37  "switch on logging of all SQL queries")
38  ;
39 
40  po::variables_map vm;
41  try {
42  po::store(po::parse_command_line(argc, argv, desc), vm);
43  po::notify(vm);
44  } catch (po::error& er) {
45  cerr << "Command line error : " << er.what() << '\n'
46  << desc << endl;
47  return EXIT_FAILURE;
48  }
49 
50  if (vm.count("help")) {
51  cerr << desc << endl;
52  return EXIT_FAILURE;
53  }
54 
55 #ifdef _GNU_SOURCE
56  if (vm.count("fpexception"))
57  feenableexcept(fpException);
58 #else
59  if (vm.count("fpexception"))
60  cerr << "floating-point exceptions will not be enabled on this architecture..." << endl;
61 #endif
62 
63  fwk::CommandLineOptions::GetInstance().SetVariablesMap(vm);
64 
65  TextUi::TestRunner runner;
66  TestFactoryRegistry& registry =
67  TestFactoryRegistry::getRegistry();
68 
69  runner.addTest(registry.makeTest());
70 
71  const bool ok = runner.run("", false);
72  return !ok;
73 }
74 
75 
76 // Configure (x)emacs for this file ...
77 // Local Variables:
78 // mode: c++
79 // compile-command: "make -C .. -k testTesting && ../testTesting"
80 // End:
bool ok(bool okay)
Definition: testlib.cc:89
int main(int argc, char *argv[])
Definition: DBSync.cc:58

, generated on Tue Sep 26 2023.