1//
2// Copyright (c) 2016-2019 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// Official repository: https://github.com/boostorg/beast
8//
9
10#include <boost/beast/_experimental/unit_test/amount.hpp>
11#include <boost/beast/_experimental/unit_test/dstream.hpp>
12#include <boost/beast/_experimental/unit_test/global_suites.hpp>
13#include <boost/beast/_experimental/unit_test/match.hpp>
14#include <boost/beast/_experimental/unit_test/reporter.hpp>
15#include <boost/beast/_experimental/unit_test/suite.hpp>
16#include <boost/config.hpp>
17#include <cstdlib>
18#include <iostream>
19#include <vector>
20
21#ifdef BOOST_MSVC
22# ifndef WIN32_LEAN_AND_MEAN // VC_EXTRALEAN
23# define WIN32_LEAN_AND_MEAN
24# include <windows.h>
25# undef WIN32_LEAN_AND_MEAN
26# else
27# include <windows.h>
28# endif
29#endif
30
31// Simple main used to produce stand
32// alone executables that run unit tests.
33int main(int ac, char const* av[])
34{
35 using namespace std;
36 using namespace boost::beast::unit_test;
37
38 dstream log(std::cerr);
39 std::unitbuf(base&: log);
40
41#ifdef BOOST_MSVC
42 {
43 int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
44 flags |= _CRTDBG_LEAK_CHECK_DF;
45 _CrtSetDbgFlag(flags);
46 }
47#endif
48
49 if(ac == 2)
50 {
51 std::string const s{av[1]};
52 if(s == "-h" || s == "--help")
53 {
54 log <<
55 "Usage:\n"
56 " " << av[0] << ": { <suite-name>... }" <<
57 std::endl;
58 return EXIT_SUCCESS;
59 }
60 }
61
62 reporter r(log);
63 bool failed;
64 if(ac > 1)
65 {
66 std::vector<selector> v;
67 v.reserve(n: ac - 1);
68 for(int i = 1; i < ac; ++i)
69 v.emplace_back(args: selector::automatch, args&: av[i]);
70 auto pred =
71 [&v](suite_info const& si) mutable
72 {
73 for(auto& p : v)
74 if(p(si))
75 return true;
76 return false;
77 };
78 failed = r.run_each_if(c: global_suites(), pred);
79 }
80 else
81 {
82 failed = r.run_each(c: global_suites());
83 }
84 if(failed)
85 return EXIT_FAILURE;
86 return EXIT_SUCCESS;
87}
88

source code of boost/libs/beast/include/boost/beast/_experimental/unit_test/main.ipp