|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r75030 - in trunk/boost/test: . impl
From: gennadiy.rozental_at_[hidden]
Date: 2011-10-18 04:42:01
Author: rogeeff
Date: 2011-10-18 04:41:56 EDT (Tue, 18 Oct 2011)
New Revision: 75030
URL: http://svn.boost.org/trac/boost/changeset/75030
Log:
added an ability to redirect leaks report into a file
also enabled use of No/Yes/T/N as parameter value
Fixes #3182
Text files modified:
trunk/boost/test/debug.hpp | 2
trunk/boost/test/impl/debug.ipp | 11 +++++++-
trunk/boost/test/impl/framework.ipp | 2
trunk/boost/test/impl/unit_test_parameters.ipp | 48 +++++++++++++++++++++++++++++++++++++--
trunk/boost/test/unit_test_parameters.hpp | 29 ++++++++++++-----------
5 files changed, 71 insertions(+), 21 deletions(-)
Modified: trunk/boost/test/debug.hpp
==============================================================================
--- trunk/boost/test/debug.hpp (original)
+++ trunk/boost/test/debug.hpp 2011-10-18 04:41:56 EDT (Tue, 18 Oct 2011)
@@ -84,7 +84,7 @@
// ************** switch on/off detect memory leaks feature ************** //
// ************************************************************************** //
-void BOOST_TEST_DECL detect_memory_leaks( bool on_off );
+void BOOST_TEST_DECL detect_memory_leaks( bool on_off, unit_test::const_string report_file = unit_test::const_string() );
// ************************************************************************** //
// ************** cause program to break execution in ************** //
Modified: trunk/boost/test/impl/debug.ipp
==============================================================================
--- trunk/boost/test/impl/debug.ipp (original)
+++ trunk/boost/test/impl/debug.ipp 2011-10-18 04:41:56 EDT (Tue, 18 Oct 2011)
@@ -921,7 +921,7 @@
// ************************************************************************** //
void
-detect_memory_leaks( bool on_off )
+detect_memory_leaks( bool on_off, unit_test::const_string report_file )
{
unit_test::ut_detail::ignore_unused_variable_warning( on_off );
@@ -933,7 +933,14 @@
else {
flags |= _CRTDBG_LEAK_CHECK_DF;
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);
+
+ if( report_file.is_empty() )
+ _CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDOUT);
+ else {
+ HANDLE hreport_f = ::CreateFileA( report_file.begin(),
+ GENERIC_WRITE, FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+ _CrtSetReportFile(_CRT_WARN, hreport_f );
+ }
}
_CrtSetDbgFlag ( flags );
Modified: trunk/boost/test/impl/framework.ipp
==============================================================================
--- trunk/boost/test/impl/framework.ipp (original)
+++ trunk/boost/test/impl/framework.ipp 2011-10-18 04:41:56 EDT (Tue, 18 Oct 2011)
@@ -664,7 +664,7 @@
register_observer( progress_monitor );
if( runtime_config::detect_memory_leaks() > 0 ) {
- debug::detect_memory_leaks( true );
+ debug::detect_memory_leaks( true, runtime_config::memory_leaks_report_file() );
debug::break_memory_alloc( runtime_config::detect_memory_leaks() );
}
Modified: trunk/boost/test/impl/unit_test_parameters.ipp
==============================================================================
--- trunk/boost/test/impl/unit_test_parameters.ipp (original)
+++ trunk/boost/test/impl/unit_test_parameters.ipp 2011-10-18 04:41:56 EDT (Tue, 18 Oct 2011)
@@ -285,8 +285,8 @@
<< cla::named_parameter<bool>( DETECT_FP_EXCEPT )
- (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional,
cla::description = "Allows to switch between catching and ignoring floating point exceptions")
- << cla::named_parameter<long>( DETECT_MEM_LEAKS )
- - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional,
+ << cla::named_parameter<std::string>( DETECT_MEM_LEAKS )
+ - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional,cla::optional_value,
cla::description = "Allows to switch between catching and ignoring memory leaks")
<< cla::dual_name_parameter<unit_test::output_format>( LOG_FORMAT + "|f" )
- (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,
@@ -552,7 +552,49 @@
long
detect_memory_leaks()
{
- return retrieve_parameter( DETECT_MEM_LEAKS, s_cla_parser, static_cast<long>(1) );
+ static int s_value = -1;
+
+ if( s_value >= 0 )
+ return s_value;
+
+ std::string value = retrieve_parameter( DETECT_MEM_LEAKS, s_cla_parser, s_empty );
+
+ optional<bool> bool_val;
+ if( runtime::interpret_argument_value_impl<bool>::_( value, bool_val ) )
+ s_value = *bool_val ? 1L : 0L;
+ else {
+ try {
+ // if representable as long - this is leak number
+ s_value = boost::lexical_cast<long>( value );
+ }
+ catch( boost::bad_lexical_cast const& ) {
+ // value is leak report file and detection is enabled
+ s_value = 1L;
+ }
+ }
+
+ return s_value;
+}
+
+//____________________________________________________________________________//
+
+const_string
+memory_leaks_report_file()
+{
+ if( detect_memory_leaks() != 1 )
+ return const_string();
+
+ static std::string s_value;
+
+ if( s_value.empty() ) {
+ s_value = retrieve_parameter<std::string>( DETECT_MEM_LEAKS, s_cla_parser );
+
+ optional<bool> bool_val;
+ if( runtime::interpret_argument_value_impl<bool>::_( s_value, bool_val ) )
+ s_value.clear();
+ }
+
+ return s_value;
}
//____________________________________________________________________________//
Modified: trunk/boost/test/unit_test_parameters.hpp
==============================================================================
--- trunk/boost/test/unit_test_parameters.hpp (original)
+++ trunk/boost/test/unit_test_parameters.hpp 2011-10-18 04:41:56 EDT (Tue, 18 Oct 2011)
@@ -36,27 +36,28 @@
BOOST_TEST_DECL void init( int& argc, char** argv );
-BOOST_TEST_DECL unit_test::log_level log_level();
-BOOST_TEST_DECL bool no_result_code();
-BOOST_TEST_DECL unit_test::report_level report_level();
-BOOST_TEST_DECL std::list<std::string> const& test_to_run();
+BOOST_TEST_DECL bool auto_start_dbg();
BOOST_TEST_DECL const_string break_exec_path();
-BOOST_TEST_DECL bool save_pattern();
-BOOST_TEST_DECL bool show_build_info();
-BOOST_TEST_DECL bool list_content();
-BOOST_TEST_DECL bool show_progress();
BOOST_TEST_DECL bool catch_sys_errors();
BOOST_TEST_DECL bool color_output();
-BOOST_TEST_DECL bool auto_start_dbg();
-BOOST_TEST_DECL bool wait_for_debugger();
-BOOST_TEST_DECL bool use_alt_stack();
BOOST_TEST_DECL bool detect_fp_exceptions();
-BOOST_TEST_DECL output_format report_format();
+BOOST_TEST_DECL long detect_memory_leaks();
+BOOST_TEST_DECL bool list_content();
BOOST_TEST_DECL output_format log_format();
-BOOST_TEST_DECL std::ostream* report_sink();
+BOOST_TEST_DECL unit_test::log_level log_level();
BOOST_TEST_DECL std::ostream* log_sink();
-BOOST_TEST_DECL long detect_memory_leaks();
+BOOST_TEST_DECL const_string memory_leaks_report_file();
+BOOST_TEST_DECL bool no_result_code();
BOOST_TEST_DECL int random_seed();
+BOOST_TEST_DECL output_format report_format();
+BOOST_TEST_DECL unit_test::report_level report_level();
+BOOST_TEST_DECL std::ostream* report_sink();
+BOOST_TEST_DECL bool save_pattern();
+BOOST_TEST_DECL bool show_build_info();
+BOOST_TEST_DECL bool show_progress();
+BOOST_TEST_DECL std::list<std::string> const& test_to_run();
+BOOST_TEST_DECL bool use_alt_stack();
+BOOST_TEST_DECL bool wait_for_debugger();
} // namespace runtime_config
} // namespace unit_test
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk