From 843e0f7bb0d1ad5c53f4ccbe8075afd5b2c3562a Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Wed, 28 Dec 2022 17:49:01 +0200 Subject: [PATCH] Add boost::core::detail::lwt_unattended() --- include/boost/core/detail/lwt_unattended.hpp | 45 ++++++++++++++++++++ include/boost/core/lightweight_test.hpp | 37 +++++++--------- 2 files changed, 61 insertions(+), 21 deletions(-) create mode 100644 include/boost/core/detail/lwt_unattended.hpp diff --git a/include/boost/core/detail/lwt_unattended.hpp b/include/boost/core/detail/lwt_unattended.hpp new file mode 100644 index 0000000..68cba62 --- /dev/null +++ b/include/boost/core/detail/lwt_unattended.hpp @@ -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 +#if defined(_MSC_VER) && defined(_CPPLIB_VER) && defined(_DEBUG) +# include +#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 diff --git a/include/boost/core/lightweight_test.hpp b/include/boost/core/lightweight_test.hpp index 37d713d..83f20bc 100644 --- a/include/boost/core/lightweight_test.hpp +++ b/include/boost/core/lightweight_test.hpp @@ -22,6 +22,7 @@ // http://www.boost.org/LICENSE_1_0.txt // +#include #include #include #include @@ -33,10 +34,6 @@ #include #include -#if defined(_MSC_VER) && defined(_CPPLIB_VER) && defined(_DEBUG) -# include -#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_; };