Files
boost_beast/extras/beast/unit_test/main.cpp
T

129 lines
2.9 KiB
C++
Raw Normal View History

2016-05-07 17:06:46 -04:00
//
// Copyright (c) 2013-2016 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
2017-07-20 08:01:46 -07:00
2016-05-06 19:14:17 -04:00
#include <beast/unit_test/amount.hpp>
2016-05-10 07:09:57 -04:00
#include <beast/unit_test/dstream.hpp>
2016-05-06 19:14:17 -04:00
#include <beast/unit_test/global_suites.hpp>
#include <beast/unit_test/match.hpp>
#include <beast/unit_test/reporter.hpp>
#include <beast/unit_test/suite.hpp>
#include <boost/program_options.hpp>
2016-05-10 07:09:57 -04:00
#include <cstdlib>
#include <iostream>
#include <vector>
2017-07-20 08:01:46 -07:00
#ifdef _MSC_VER
# ifndef WIN32_LEAN_AND_MEAN // VC_EXTRALEAN
# define WIN32_LEAN_AND_MEAN
# include <windows.h>
2017-07-20 08:01:46 -07:00
# undef WIN32_LEAN_AND_MEAN
# else
# include <windows.h>
2017-07-20 08:01:46 -07:00
# endif
#endif
namespace beast {
namespace unit_test {
2016-05-10 07:09:57 -04:00
static
std::string
prefix(suite_info const& s)
{
2016-08-26 08:01:44 -04:00
if(s.manual())
return "|M| ";
return " ";
}
2016-05-10 07:09:57 -04:00
static
void
2016-05-10 07:09:57 -04:00
print(std::ostream& os, suite_list const& c)
{
std::size_t manual = 0;
for(auto const& s : c)
{
2016-05-10 07:09:57 -04:00
os << prefix (s) << s.full_name() << '\n';
if(s.manual())
++manual;
}
2016-05-10 07:09:57 -04:00
os <<
amount(c.size(), "suite") << " total, " <<
2016-05-10 07:09:57 -04:00
amount(manual, "manual suite") <<
'\n'
;
}
2016-05-10 07:09:57 -04:00
// Print the list of suites
// Used with the --print command line option
static
void
2016-05-10 07:09:57 -04:00
print(std::ostream& os)
{
2016-05-10 07:09:57 -04:00
os << "------------------------------------------\n";
print(os, global_suites());
os << "------------------------------------------" <<
std::endl;
}
} // unit_test
} // beast
2017-07-20 08:01:46 -07:00
// Simple main used to produce stand
// alone executables that run unit tests.
int main(int ac, char const* av[])
2017-07-20 08:01:46 -07:00
{
using namespace std;
2016-05-06 19:14:17 -04:00
using namespace beast::unit_test;
2017-07-20 08:01:46 -07:00
#ifdef _MSC_VER
{
int flags = _CrtSetDbgFlag (_CRTDBG_REPORT_FLAG);
flags |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetDbgFlag (flags);
}
#endif
namespace po = boost::program_options;
po::options_description desc("Options");
desc.add_options()
("help,h", "Produce a help message")
("print,r", "Print the list of available test suites")
("suites,s", po::value<string>(), "suites to run")
;
po::positional_options_description p;
po::variables_map vm;
po::store(po::parse_command_line(ac, av, desc), vm);
po::notify(vm);
2016-05-10 07:09:57 -04:00
dstream log;
if(vm.count("help"))
2017-07-20 08:01:46 -07:00
{
2016-05-10 07:09:57 -04:00
log << desc << std::endl;
}
else if(vm.count("print"))
{
print(log);
}
else
{
std::string suites;
if(vm.count("suites") > 0)
suites = vm["suites"].as<string>();
reporter r(log);
bool failed;
if(! suites.empty())
failed = r.run_each_if(global_suites(),
match_auto(suites));
else
failed = r.run_each(global_suites());
2016-08-26 08:01:44 -04:00
if(failed)
2017-07-20 08:01:46 -07:00
return EXIT_FAILURE;
return EXIT_SUCCESS;
}
}