Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-19 09:25:00

0001 //
0002 // Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 //
0007 // Official repository: https://github.com/boostorg/beast
0008 //
0009 
0010 #include <boost/beast/_experimental/unit_test/amount.hpp>
0011 #include <boost/beast/_experimental/unit_test/dstream.hpp>
0012 #include <boost/beast/_experimental/unit_test/global_suites.hpp>
0013 #include <boost/beast/_experimental/unit_test/match.hpp>
0014 #include <boost/beast/_experimental/unit_test/reporter.hpp>
0015 #include <boost/beast/_experimental/unit_test/suite.hpp>
0016 #include <boost/config.hpp>
0017 #include <cstdlib>
0018 #include <iostream>
0019 #include <vector>
0020 
0021 #ifdef BOOST_MSVC
0022 # ifndef WIN32_LEAN_AND_MEAN // VC_EXTRALEAN
0023 #  define WIN32_LEAN_AND_MEAN
0024 #  include <windows.h>
0025 #  undef WIN32_LEAN_AND_MEAN
0026 # else
0027 #  include <windows.h>
0028 # endif
0029 #endif
0030 
0031 // Simple main used to produce stand
0032 // alone executables that run unit tests.
0033 int main(int ac, char const* av[])
0034 {
0035     using namespace std;
0036     using namespace boost::beast::unit_test;
0037 
0038     dstream log(std::cerr);
0039     std::unitbuf(log);
0040 
0041 #ifdef BOOST_MSVC
0042     {
0043         int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
0044         flags |= _CRTDBG_LEAK_CHECK_DF;
0045         _CrtSetDbgFlag(flags);
0046     }
0047 #endif
0048 
0049     if(ac == 2)
0050     {
0051         std::string const s{av[1]};
0052         if(s == "-h" || s == "--help")
0053         {
0054             log <<
0055                 "Usage:\n"
0056                 "  " << av[0] << ": { <suite-name>... }" <<
0057                 std::endl;
0058             return EXIT_SUCCESS;
0059         }
0060     }
0061 
0062     reporter r(log);
0063     bool failed;
0064     if(ac > 1)
0065     {
0066         std::vector<selector> v;
0067         v.reserve(ac - 1);
0068         for(int i = 1; i < ac; ++i)
0069             v.emplace_back(selector::automatch, av[i]);
0070         auto pred =
0071             [&v](suite_info const& si) mutable
0072             {
0073                 for(auto& p : v)
0074                     if(p(si))
0075                         return true;
0076                 return false;
0077             };
0078         failed = r.run_each_if(global_suites(), pred);
0079     }
0080     else
0081     {
0082         failed = r.run_each(global_suites());
0083     }
0084     if(failed)
0085         return EXIT_FAILURE;
0086     return EXIT_SUCCESS;
0087 }