update boost
This commit is contained in:
@@ -193,6 +193,10 @@ public:
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~suite() = default;
|
||||
suite(suite const&) = delete;
|
||||
suite& operator=(suite const&) = delete;
|
||||
|
||||
/** Invokes the test using the specified runner.
|
||||
|
||||
Data members are set up here instead of the constructor as a
|
||||
@@ -635,6 +639,31 @@ run(runner& r)
|
||||
(::boost::beast::unit_test::suite::this_suite()->fail((reason), __FILE__, __LINE__), false))
|
||||
#endif
|
||||
|
||||
/** Ensure an exception is thrown
|
||||
*/
|
||||
#define BEAST_THROWS( EXPR, EXCEP ) \
|
||||
try { \
|
||||
EXPR; \
|
||||
BEAST_FAIL(); \
|
||||
} \
|
||||
catch(EXCEP const&) { \
|
||||
BEAST_PASS(); \
|
||||
} \
|
||||
catch(...) { \
|
||||
BEAST_FAIL(); \
|
||||
}
|
||||
|
||||
/** Ensure an exception is not thrown
|
||||
*/
|
||||
#define BEAST_NO_THROW( EXPR ) \
|
||||
try { \
|
||||
EXPR; \
|
||||
BEAST_PASS(); \
|
||||
} \
|
||||
catch(...) { \
|
||||
BEAST_FAIL(); \
|
||||
}
|
||||
|
||||
} // unit_test
|
||||
} // beast
|
||||
} // boost
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include <boost/beast/_experimental/unit_test/suite_info.hpp>
|
||||
#include <boost/beast/_experimental/unit_test/detail/const_container.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/type_index.hpp>
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <typeindex>
|
||||
#include <set>
|
||||
#include <unordered_set>
|
||||
@@ -28,7 +30,9 @@ class suite_list
|
||||
private:
|
||||
#ifndef NDEBUG
|
||||
std::unordered_set<std::string> names_;
|
||||
std::unordered_set<std::type_index> classes_;
|
||||
|
||||
using type_index = boost::typeindex::type_index;
|
||||
std::unordered_set<type_index, boost::hash<type_index>> classes_;
|
||||
#endif
|
||||
|
||||
public:
|
||||
@@ -65,7 +69,7 @@ suite_list::insert(
|
||||
|
||||
{
|
||||
auto const result(classes_.insert(
|
||||
std::type_index(typeid(Suite))));
|
||||
boost::typeindex::type_id<Suite>()));
|
||||
BOOST_ASSERT(result.second); // Duplicate type
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
//
|
||||
// Copyright (c) 2016-2019 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)
|
||||
//
|
||||
// Official repository: https://github.com/boostorg/beast
|
||||
//
|
||||
|
||||
#ifndef BOOST_BEAST_UNIT_TEST_THREAD_HPP
|
||||
#define BOOST_BEAST_UNIT_TEST_THREAD_HPP
|
||||
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
#include <functional>
|
||||
#include <thread>
|
||||
#include <utility>
|
||||
|
||||
namespace boost {
|
||||
namespace beast {
|
||||
namespace unit_test {
|
||||
|
||||
/** Replacement for std::thread that handles exceptions in unit tests. */
|
||||
class thread
|
||||
{
|
||||
private:
|
||||
suite* s_ = nullptr;
|
||||
std::thread t_;
|
||||
|
||||
public:
|
||||
using id = std::thread::id;
|
||||
using native_handle_type = std::thread::native_handle_type;
|
||||
|
||||
thread() = default;
|
||||
thread(thread const&) = delete;
|
||||
thread& operator=(thread const&) = delete;
|
||||
|
||||
thread(thread&& other)
|
||||
: s_(other.s_)
|
||||
, t_(std::move(other.t_))
|
||||
{
|
||||
}
|
||||
|
||||
thread& operator=(thread&& other)
|
||||
{
|
||||
s_ = other.s_;
|
||||
t_ = std::move(other.t_);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template<class F, class... Args>
|
||||
explicit
|
||||
thread(suite& s, F&& f, Args&&... args)
|
||||
: s_(&s)
|
||||
{
|
||||
std::function<void(void)> b =
|
||||
std::bind(std::forward<F>(f),
|
||||
std::forward<Args>(args)...);
|
||||
t_ = std::thread(&thread::run, this,
|
||||
std::move(b));
|
||||
}
|
||||
|
||||
bool
|
||||
joinable() const
|
||||
{
|
||||
return t_.joinable();
|
||||
}
|
||||
|
||||
std::thread::id
|
||||
get_id() const
|
||||
{
|
||||
return t_.get_id();
|
||||
}
|
||||
|
||||
static
|
||||
unsigned
|
||||
hardware_concurrency() noexcept
|
||||
{
|
||||
return std::thread::hardware_concurrency();
|
||||
}
|
||||
|
||||
void
|
||||
join()
|
||||
{
|
||||
t_.join();
|
||||
s_->propagate_abort();
|
||||
}
|
||||
|
||||
void
|
||||
detach()
|
||||
{
|
||||
t_.detach();
|
||||
}
|
||||
|
||||
void
|
||||
swap(thread& other)
|
||||
{
|
||||
std::swap(s_, other.s_);
|
||||
std::swap(t_, other.t_);
|
||||
}
|
||||
|
||||
private:
|
||||
void
|
||||
run(std::function <void(void)> f)
|
||||
{
|
||||
try
|
||||
{
|
||||
f();
|
||||
}
|
||||
catch(suite::abort_exception const&)
|
||||
{
|
||||
}
|
||||
catch(std::exception const& e)
|
||||
{
|
||||
s_->fail("unhandled exception: " +
|
||||
std::string(e.what()));
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
s_->fail("unhandled exception");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // unit_test
|
||||
} // beast
|
||||
} // boost
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user