From 601eab03436bac4ce48bc121df43b2a937bf56e6 Mon Sep 17 00:00:00 2001 From: Gennadiy Rozental Date: Fri, 16 Sep 2011 03:22:37 +0000 Subject: [PATCH] made "run" argument multiplicable facilitated CLA parser reuse for multiple parsing sessions (mostly for internal unit testing) introduced list_context CLA [SVN r74401] --- .../test/detail/unit_test_parameters.hpp | 42 +++-- .../boost/test/impl/unit_test_parameters.ipp | 175 ++++++++++-------- 2 files changed, 118 insertions(+), 99 deletions(-) diff --git a/include/boost/test/detail/unit_test_parameters.hpp b/include/boost/test/detail/unit_test_parameters.hpp index 4b30e3a3..6608a065 100644 --- a/include/boost/test/detail/unit_test_parameters.hpp +++ b/include/boost/test/detail/unit_test_parameters.hpp @@ -22,6 +22,7 @@ // STL #include +#include //____________________________________________________________________________// @@ -35,27 +36,28 @@ namespace unit_test { namespace runtime_config { -BOOST_TEST_DECL void init( int& argc, char** argv ); +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 const_string test_to_run(); -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 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 use_alt_stack(); -BOOST_TEST_DECL bool detect_fp_exceptions(); -BOOST_TEST_DECL output_format report_format(); -BOOST_TEST_DECL output_format log_format(); -BOOST_TEST_DECL std::ostream* report_sink(); -BOOST_TEST_DECL std::ostream* log_sink(); -BOOST_TEST_DECL long detect_memory_leaks(); -BOOST_TEST_DECL int random_seed(); +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 const& test_to_run(); +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 use_alt_stack(); +BOOST_TEST_DECL bool detect_fp_exceptions(); +BOOST_TEST_DECL output_format report_format(); +BOOST_TEST_DECL output_format log_format(); +BOOST_TEST_DECL std::ostream* report_sink(); +BOOST_TEST_DECL std::ostream* log_sink(); +BOOST_TEST_DECL long detect_memory_leaks(); +BOOST_TEST_DECL int random_seed(); } // namespace runtime_config diff --git a/include/boost/test/impl/unit_test_parameters.ipp b/include/boost/test/impl/unit_test_parameters.ipp index c8518cbb..88996e49 100644 --- a/include/boost/test/impl/unit_test_parameters.ipp +++ b/include/boost/test/impl/unit_test_parameters.ipp @@ -19,6 +19,7 @@ #define BOOST_TEST_UNIT_TEST_PARAMETERS_IPP_012205GER // Boost.Test +#define MAX_MAP_SIZE 25 #include #include #include @@ -34,14 +35,12 @@ namespace rt = boost::runtime; namespace cla = rt::cla; - #ifndef UNDER_CE #include namespace env = rt::env; #endif - // Boost #include #include @@ -161,6 +160,7 @@ std::string CATCH_SYS_ERRORS = "catch_system_errors"; std::string COLOR_OUTPUT = "color_output"; std::string DETECT_FP_EXCEPT = "detect_fp_exceptions"; std::string DETECT_MEM_LEAKS = "detect_memory_leaks"; +std::string LIST_CONTENT = "list_content"; std::string LOG_FORMAT = "log_format"; std::string LOG_LEVEL = "log_level"; std::string LOG_SINK = "log_sink"; @@ -183,6 +183,7 @@ fixed_mapping parameter_2_env_var( COLOR_OUTPUT , "BOOST_TEST_COLOR_OUTPUT", DETECT_FP_EXCEPT , "BOOST_TEST_DETECT_FP_EXCEPTIONS", DETECT_MEM_LEAKS , "BOOST_TEST_DETECT_MEMORY_LEAK", + LIST_CONTENT , "BOOST_TEST_LIST_CONTENT", LOG_FORMAT , "BOOST_TEST_LOG_FORMAT", LOG_LEVEL , "BOOST_TEST_LOG_LEVEL", LOG_SINK , "BOOST_TEST_LOG_SINK", @@ -203,11 +204,13 @@ fixed_mapping parameter_2_env_var( //____________________________________________________________________________// // storage for the CLAs -cla::parser s_cla_parser; -std::string s_empty; +cla::parser s_cla_parser; +std::string s_empty; -output_format s_report_format; -output_format s_log_format; +output_format s_report_format; +output_format s_log_format; + +std::list s_test_to_run; //____________________________________________________________________________// @@ -250,73 +253,79 @@ init( int& argc, char** argv ) using namespace cla; try { - s_cla_parser - cla::ignore_mismatch - << cla::dual_name_parameter( AUTO_START_DBG + "|d" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Automatically starts debugger if system level error (signal) occurs") - << cla::named_parameter( BREAK_EXEC_PATH ) - - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional, - cla::description = "For the exception safety testing allows to break at specific execution path") - << cla::dual_name_parameter( BUILD_INFO + "|i" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Shows library build information" ) - << cla::dual_name_parameter( CATCH_SYS_ERRORS + "|s" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Allows to switch between catching and ignoring system errors (signals)") - << cla::dual_name_parameter( COLOR_OUTPUT + "|x" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Allows to switch between catching and ignoring system errors (signals)") - << cla::named_parameter( 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( DETECT_MEM_LEAKS ) - - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional, - cla::description = "Allows to switch between catching and ignoring memory leaks") - << cla::dual_name_parameter( LOG_FORMAT + "|f" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Specifies log format") - << cla::dual_name_parameter( LOG_LEVEL + "|l" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Specifies log level") - << cla::dual_name_parameter( LOG_SINK + "|k" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Specifies log sink:stdout(default),stderr or file name") - << cla::dual_name_parameter( OUTPUT_FORMAT + "|o" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Specifies output format (both log and report)") - << cla::dual_name_parameter( RANDOM_SEED + "|a" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,cla::optional_value, - cla::description = "Allows to switch between sequential and random order of test units execution.\n" - "Optionally allows to specify concrete seed for random number generator") - << cla::dual_name_parameter( REPORT_FORMAT + "|m" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Specifies report format") - << cla::dual_name_parameter(REPORT_LEVEL + "|r") - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Specifies report level") - << cla::dual_name_parameter( REPORT_SINK + "|e" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Specifies report sink:stderr(default),stdout or file name") - << cla::dual_name_parameter( RESULT_CODE + "|c" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Allows to disable test modules's result code generation") - << cla::dual_name_parameter( TESTS_TO_RUN + "|t" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Allows to filter which test units to run") - << cla::named_parameter( SAVE_TEST_PATTERN ) - - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional, - cla::description = "Allows to switch between saving and matching against test pattern file") - << cla::dual_name_parameter( SHOW_PROGRESS + "|p" ) - - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, - cla::description = "Turns on progress display") - << cla::named_parameter( USE_ALT_STACK ) - - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional, - cla::description = "Turns on/off usage of an alternative stack for signal handling") + if( s_cla_parser.num_params() != 0 ) + s_cla_parser.reset(); + else + s_cla_parser - cla::ignore_mismatch + << cla::dual_name_parameter( AUTO_START_DBG + "|d" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, + cla::description = "Automatically starts debugger if system level error (signal) occurs") + << cla::named_parameter( BREAK_EXEC_PATH ) + - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional, + cla::description = "For the exception safety testing allows to break at specific execution path") + << cla::dual_name_parameter( BUILD_INFO + "|i" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, + cla::description = "Shows library build information" ) + << cla::dual_name_parameter( CATCH_SYS_ERRORS + "|s" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, + cla::description = "Allows to switch between catching and ignoring system errors (signals)") + << cla::dual_name_parameter( COLOR_OUTPUT + "|x" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, + cla::description = "Allows to switch between catching and ignoring system errors (signals)") + << cla::named_parameter( 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( DETECT_MEM_LEAKS ) + - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional, + cla::description = "Allows to switch between catching and ignoring memory leaks") + << cla::dual_name_parameter( LOG_FORMAT + "|f" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, + cla::description = "Specifies log format") + << cla::dual_name_parameter( LOG_LEVEL + "|l" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, + cla::description = "Specifies log level") + << cla::dual_name_parameter( LOG_SINK + "|k" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, + cla::description = "Specifies log sink:stdout(default),stderr or file name") + << cla::dual_name_parameter( OUTPUT_FORMAT + "|o" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, + cla::description = "Specifies output format (both log and report)") + << cla::dual_name_parameter( RANDOM_SEED + "|a" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,cla::optional_value, + cla::description = "Allows to switch between sequential and random order of test units execution.\n" + "Optionally allows to specify concrete seed for random number generator") + << cla::dual_name_parameter( REPORT_FORMAT + "|m" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, + cla::description = "Specifies report format") + << cla::dual_name_parameter(REPORT_LEVEL + "|r") + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, + cla::description = "Specifies report level") + << cla::dual_name_parameter( REPORT_SINK + "|e" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, + cla::description = "Specifies report sink:stderr(default),stdout or file name") + << cla::dual_name_parameter( RESULT_CODE + "|c" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, + cla::description = "Allows to disable test modules's result code generation") + << cla::dual_name_parameter( TESTS_TO_RUN + "|t" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,cla::multiplicable, + cla::description = "Allows to filter which test units to run") + << cla::named_parameter( SAVE_TEST_PATTERN ) + - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional, + cla::description = "Allows to switch between saving and matching against test pattern file") + << cla::dual_name_parameter( SHOW_PROGRESS + "|p" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional, + cla::description = "Turns on progress display") + << cla::dual_name_parameter( LIST_CONTENT + "|j" ) + - (cla::prefix = "--|-",cla::separator = "=| ",cla::guess_name,cla::optional,cla::optional_value, + cla::description = "Lists the content of test tree - names of all test suites and test cases") + << cla::named_parameter( USE_ALT_STACK ) + - (cla::prefix = "--",cla::separator = "=",cla::guess_name,cla::optional, + cla::description = "Turns on/off usage of an alternative stack for signal handling") - << cla::dual_name_parameter( "help|?" ) - - (cla::prefix = "--|-",cla::separator = "=",cla::guess_name,cla::optional, - cla::description = "this help message") - ; + << cla::dual_name_parameter( "help|?" ) + - (cla::prefix = "--|-",cla::separator = "=",cla::guess_name,cla::optional, + cla::description = "this help message") + ; s_cla_parser.parse( argc, argv ); @@ -332,6 +341,8 @@ init( int& argc, char** argv ) if( of != unit_test::INV_OF ) s_report_format = s_log_format = of; + + s_test_to_run = retrieve_parameter >( TESTS_TO_RUN, s_cla_parser ); } catch( rt::logic_error const& ex ) { std::ostringstream err; @@ -369,11 +380,9 @@ report_level() //____________________________________________________________________________// -const_string +std::list const& test_to_run() { - static std::string s_test_to_run = retrieve_parameter( TESTS_TO_RUN, s_cla_parser, s_empty ); - return s_test_to_run; } @@ -413,6 +422,14 @@ show_build_info() //____________________________________________________________________________// +bool +list_content() +{ + return retrieve_parameter( LIST_CONTENT, s_cla_parser, false ); +} + +//____________________________________________________________________________// + bool catch_sys_errors() { @@ -488,8 +505,8 @@ report_sink() if( sink_name == "stdout" ) return &std::cout; - static std::ofstream log_file( sink_name.c_str() ); - return &log_file; + static std::ofstream report_file( sink_name.c_str() ); + return &report_file; } //____________________________________________________________________________// @@ -505,8 +522,8 @@ log_sink() if( sink_name == "stderr" ) return &std::cerr; - static std::ofstream report_file( sink_name.c_str() ); - return &report_file; + static std::ofstream log_file( sink_name.c_str() ); + return &log_file; } //____________________________________________________________________________//