Add boost::core::detail::lwt_unattended()

This commit is contained in:
Peter Dimov 2022-12-28 17:49:01 +02:00
parent ddc6cc25a9
commit 843e0f7bb0
2 changed files with 61 additions and 21 deletions

View File

@ -0,0 +1,45 @@
#ifndef BOOST_CORE_DETAIL_LWT_UNATTENDED_HPP_INCLUDED
#define BOOST_CORE_DETAIL_LWT_UNATTENDED_HPP_INCLUDED
// Copyright 2014, 2022 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <cstdlib>
#if defined(_MSC_VER) && defined(_CPPLIB_VER) && defined(_DEBUG)
# include <crtdbg.h>
#endif
namespace boost
{
namespace core
{
namespace detail
{
// Setup unattended mode by disabling interactive popups on
// assertion failures
inline void lwt_unattended()
{
#if defined(_MSC_VER) && (_MSC_VER > 1310)
// disable message boxes on assert(), abort()
::_set_abort_behavior( 0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT );
#endif
#if defined(_MSC_VER) && defined(_CPPLIB_VER) && defined(_DEBUG)
// disable message boxes on iterator debugging violations
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR );
#endif
}
} // namespace detail
} // namespace core
} // namespace boost
#endif // #ifndef BOOST_CORE_DETAIL_LWT_UNATTENDED_HPP_INCLUDED

View File

@ -22,6 +22,7 @@
// http://www.boost.org/LICENSE_1_0.txt
//
#include <boost/core/detail/lwt_unattended.hpp>
#include <boost/current_function.hpp>
#include <boost/config.hpp>
#include <exception>
@ -33,10 +34,6 @@
#include <cstddef>
#include <cctype>
#if defined(_MSC_VER) && defined(_CPPLIB_VER) && defined(_DEBUG)
# include <crtdbg.h>
#endif
// IDE's like Visual Studio perform better if output goes to std::cout or
// some other stream, so allow user to configure output stream:
#ifndef BOOST_LIGHTWEIGHT_TEST_OSTREAM
@ -49,38 +46,36 @@ namespace boost
namespace detail
{
class test_result {
class test_result
{
public:
test_result()
: report_(false)
, errors_(0) {
#if defined(_MSC_VER) && (_MSC_VER > 1310)
// disable message boxes on assert(), abort()
::_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
#endif
#if defined(_MSC_VER) && defined(_CPPLIB_VER) && defined(_DEBUG)
// disable message boxes on iterator debugging violations
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR );
#endif
test_result(): report_( false ), errors_( 0 )
{
core::detail::lwt_unattended();
}
~test_result() {
if (!report_) {
~test_result()
{
if( !report_ )
{
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "main() should return report_errors()" << std::endl;
std::abort();
}
}
int& errors() {
int& errors()
{
return errors_;
}
void done() {
void done()
{
report_ = true;
}
private:
bool report_;
int errors_;
};