rippled
main.cpp
1 //
2 // Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 
8 #include <ripple/beast/unit_test/amount.hpp>
9 #include <ripple/beast/unit_test/dstream.hpp>
10 #include <ripple/beast/unit_test/global_suites.hpp>
11 #include <ripple/beast/unit_test/match.hpp>
12 #include <ripple/beast/unit_test/reporter.hpp>
13 #include <ripple/beast/unit_test/suite.hpp>
14 #include <boost/config.hpp>
15 #include <boost/program_options.hpp>
16 #include <cstdlib>
17 #include <iostream>
18 #include <vector>
19 
20 #ifdef BOOST_MSVC
21 #ifndef WIN32_LEAN_AND_MEAN // VC_EXTRALEAN
22 #define WIN32_LEAN_AND_MEAN
23 #include <windows.h>
24 #undef WIN32_LEAN_AND_MEAN
25 #else
26 #include <windows.h>
27 #endif
28 #endif
29 
30 namespace beast {
31 namespace unit_test {
32 
33 static std::string
34 prefix(suite_info const& s)
35 {
36  if (s.manual())
37  return "|M| ";
38  return " ";
39 }
40 
41 static void
42 print(std::ostream& os, suite_list const& c)
43 {
44  std::size_t manual = 0;
45  for (auto const& s : c)
46  {
47  os << prefix(s) << s.full_name() << '\n';
48  if (s.manual())
49  ++manual;
50  }
51  os << amount(c.size(), "suite") << " total, "
52  << amount(manual, "manual suite") << '\n';
53 }
54 
55 // Print the list of suites
56 // Used with the --print command line option
57 static void
59 {
60  os << "------------------------------------------\n";
61  print(os, global_suites());
62  os << "------------------------------------------" << std::endl;
63 }
64 
65 } // namespace unit_test
66 } // namespace beast
67 
68 // Simple main used to produce stand
69 // alone executables that run unit tests.
70 int
71 main(int ac, char const* av[])
72 {
73  using namespace std;
74  using namespace beast::unit_test;
75 
76  namespace po = boost::program_options;
77  po::options_description desc("Options");
78  desc.add_options()("help,h", "Produce a help message")(
79  "print,p", "Print the list of available test suites")(
80  "suites,s", po::value<string>(), "suites to run");
81 
82  po::positional_options_description p;
83  po::variables_map vm;
84  po::store(po::parse_command_line(ac, av, desc), vm);
85  po::notify(vm);
86 
87  dstream log(std::cerr);
89 
90  if (vm.count("help"))
91  {
92  log << desc << std::endl;
93  }
94  else if (vm.count("print"))
95  {
96  print(log);
97  }
98  else
99  {
100  std::string suites;
101  if (vm.count("suites") > 0)
102  suites = vm["suites"].as<string>();
103  reporter r(log);
104  bool failed;
105  if (!suites.empty())
106  failed = r.run_each_if(global_suites(), match_auto(suites));
107  else
108  failed = r.run_each(global_suites());
109  if (failed)
110  return EXIT_FAILURE;
111  return EXIT_SUCCESS;
112  }
113 }
std::string
STL class.
std::unitbuf
T unitbuf(T... args)
vector
beast::unit_test
Definition: main.cpp:31
std::cerr
iostream
std::log
T log(T... args)
std::ostream
STL class.
beast::unit_test::print
static void print(std::ostream &os, suite_list const &c)
Definition: main.cpp:42
beast::unit_test::prefix
static std::string prefix(suite_info const &s)
Definition: main.cpp:34
cstdlib
std::endl
T endl(T... args)
std
STL namespace.
std::string::empty
T empty(T... args)
std::size_t
beast
Definition: base_uint.h:641