]> git.proxmox.com Git - ceph.git/blame - ceph/src/Beast/extras/beast/unit_test/main.cpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / Beast / extras / beast / unit_test / main.cpp
CommitLineData
7c673cae
FG
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 <beast/unit_test/amount.hpp>
9#include <beast/unit_test/dstream.hpp>
10#include <beast/unit_test/global_suites.hpp>
11#include <beast/unit_test/match.hpp>
12#include <beast/unit_test/reporter.hpp>
13#include <beast/unit_test/suite.hpp>
14#include <boost/program_options.hpp>
15#include <cstdlib>
16#include <iostream>
17#include <vector>
18
19#ifdef _MSC_VER
20# ifndef WIN32_LEAN_AND_MEAN // VC_EXTRALEAN
21# define WIN32_LEAN_AND_MEAN
22# include <windows.h>
23# undef WIN32_LEAN_AND_MEAN
24# else
25# include <windows.h>
26# endif
27#endif
28
29namespace beast {
30namespace unit_test {
31
32static
33std::string
34prefix(suite_info const& s)
35{
36 if(s.manual())
37 return "|M| ";
38 return " ";
39}
40
41static
42void
43print(std::ostream& os, suite_list const& c)
44{
45 std::size_t manual = 0;
46 for(auto const& s : c)
47 {
48 os << prefix(s) << s.full_name() << '\n';
49 if(s.manual())
50 ++manual;
51 }
52 os <<
53 amount(c.size(), "suite") << " total, " <<
54 amount(manual, "manual suite") <<
55 '\n'
56 ;
57}
58
59// Print the list of suites
60// Used with the --print command line option
61static
62void
63print(std::ostream& os)
64{
65 os << "------------------------------------------\n";
66 print(os, global_suites());
67 os << "------------------------------------------" <<
68 std::endl;
69}
70
71} // unit_test
72} // beast
73
74// Simple main used to produce stand
75// alone executables that run unit tests.
76int main(int ac, char const* av[])
77{
78 using namespace std;
79 using namespace beast::unit_test;
80
81#ifdef _MSC_VER
82 {
83 int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
84 flags |= _CRTDBG_LEAK_CHECK_DF;
85 _CrtSetDbgFlag(flags);
86 }
87#endif
88
89 namespace po = boost::program_options;
90 po::options_description desc("Options");
91 desc.add_options()
92 ("help,h", "Produce a help message")
93 ("print,p", "Print the list of available test suites")
94 ("suites,s", po::value<string>(), "suites to run")
95 ;
96
97 po::positional_options_description p;
98 po::variables_map vm;
99 po::store(po::parse_command_line(ac, av, desc), vm);
100 po::notify(vm);
101
102 dstream log{std::cerr};
103 std::unitbuf(log);
104
105 if(vm.count("help"))
106 {
107 log << desc << std::endl;
108 }
109 else if(vm.count("print"))
110 {
111 print(log);
112 }
113 else
114 {
115 std::string suites;
116 if(vm.count("suites") > 0)
117 suites = vm["suites"].as<string>();
118 reporter r(log);
119 bool failed;
120 if(! suites.empty())
121 failed = r.run_each_if(global_suites(),
122 match_auto(suites));
123 else
124 failed = r.run_each(global_suites());
125 if(failed)
126 return EXIT_FAILURE;
127 return EXIT_SUCCESS;
128 }
129}