Files
boost_beast/test/extras/include/boost/beast/unit_test/main.cpp
T

88 lines
2.1 KiB
C++
Raw Normal View History

2016-05-07 17:06:46 -04:00
//
2017-07-24 09:42:36 -07:00
// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
2016-05-07 17:06:46 -04:00
//
// 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 13:40:34 -07:00
// Official repository: https://github.com/boostorg/beast
//
2017-07-20 08:01:46 -07:00
2017-07-20 13:40:34 -07:00
#include <boost/beast/unit_test/amount.hpp>
#include <boost/beast/unit_test/dstream.hpp>
#include <boost/beast/unit_test/global_suites.hpp>
#include <boost/beast/unit_test/match.hpp>
#include <boost/beast/unit_test/reporter.hpp>
#include <boost/beast/unit_test/suite.hpp>
2017-07-07 17:47:24 -07:00
#include <boost/config.hpp>
2016-05-10 07:09:57 -04:00
#include <cstdlib>
#include <iostream>
#include <vector>
2017-07-20 08:01:46 -07:00
2017-07-07 17:47:24 -07:00
#ifdef BOOST_MSVC
2017-07-20 08:01:46 -07:00
# 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
// 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;
2017-07-20 13:40:34 -07:00
using namespace boost::beast::unit_test;
2017-07-20 08:01:46 -07:00
2017-07-26 12:10:35 -07:00
dstream log(std::cerr);
std::unitbuf(log);
2017-07-07 17:47:24 -07:00
#if BOOST_MSVC
2017-07-20 08:01:46 -07:00
{
2016-08-29 10:43:56 -04:00
int flags = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
2017-07-20 08:01:46 -07:00
flags |= _CRTDBG_LEAK_CHECK_DF;
2016-08-29 10:43:56 -04:00
_CrtSetDbgFlag(flags);
2017-07-20 08:01:46 -07:00
}
#endif
2017-07-26 12:10:35 -07:00
if(ac == 2)
2017-07-20 08:01:46 -07:00
{
2017-07-26 12:10:35 -07:00
std::string const s{av[1]};
if(s == "-h" || s == "--help")
{
log <<
"Usage:\n"
" " << av[0] << ": { <suite-name>... }" <<
std::endl;
return EXIT_SUCCESS;
}
}
2017-07-26 12:10:35 -07:00
reporter r(log);
bool failed;
if(ac > 1)
{
2017-07-26 12:10:35 -07:00
std::vector<selector> v;
v.reserve(ac - 1);
for(int i = 1; i < ac; ++i)
v.emplace_back(selector::automatch, av[i]);
auto pred =
[&v](suite_info const& si) mutable
{
for(auto& p : v)
if(p(si))
return true;
return false;
};
failed = r.run_each_if(global_suites(), pred);
}
else
{
2017-07-26 12:10:35 -07:00
failed = r.run_each(global_suites());
2017-07-20 08:01:46 -07:00
}
2017-07-26 12:10:35 -07:00
if(failed)
return EXIT_FAILURE;
return EXIT_SUCCESS;
2017-07-20 08:01:46 -07:00
}