unit_test_parameters.ipp 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. // (C) Copyright Gennadiy Rozental 2001.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/test for the library home page.
  6. //
  7. // File : $RCSfile$
  8. //
  9. // Version : $Revision$
  10. //
  11. // Description : simple implementation for Unit Test Framework parameter
  12. // handling routines. May be rewritten in future to use some kind of
  13. // command-line arguments parsing facility and environment variable handling
  14. // facility
  15. // ***************************************************************************
  16. #ifndef BOOST_TEST_UNIT_TEST_PARAMETERS_IPP_012205GER
  17. #define BOOST_TEST_UNIT_TEST_PARAMETERS_IPP_012205GER
  18. // Boost.Test
  19. #include <boost/test/unit_test_parameters.hpp>
  20. #include <boost/test/utils/basic_cstring/basic_cstring.hpp>
  21. #include <boost/test/utils/basic_cstring/compare.hpp>
  22. #include <boost/test/utils/basic_cstring/io.hpp>
  23. #include <boost/test/utils/iterator/token_iterator.hpp>
  24. #include <boost/test/debug.hpp>
  25. #include <boost/test/framework.hpp>
  26. #include <boost/test/detail/log_level.hpp>
  27. #include <boost/test/detail/throw_exception.hpp>
  28. // Boost.Runtime.Param
  29. #include <boost/test/utils/runtime/parameter.hpp>
  30. #include <boost/test/utils/runtime/argument.hpp>
  31. #include <boost/test/utils/runtime/finalize.hpp>
  32. #include <boost/test/utils/runtime/cla/parser.hpp>
  33. #include <boost/test/utils/runtime/env/fetch.hpp>
  34. // Boost
  35. #include <boost/config.hpp>
  36. #include <boost/test/detail/suppress_warnings.hpp>
  37. #include <boost/test/detail/enable_warnings.hpp>
  38. #include <boost/cstdlib.hpp>
  39. // STL
  40. #include <cstdlib>
  41. #include <iostream>
  42. #include <fstream>
  43. #include <boost/test/detail/suppress_warnings.hpp>
  44. //____________________________________________________________________________//
  45. # ifdef BOOST_NO_STDC_NAMESPACE
  46. namespace std { using ::getenv; using ::strncmp; using ::strcmp; }
  47. # endif
  48. namespace boost {
  49. namespace unit_test {
  50. namespace rt = boost::runtime;
  51. // ************************************************************************** //
  52. // ************** runtime_config ************** //
  53. // ************************************************************************** //
  54. namespace runtime_config {
  55. // UTF parameters
  56. std::string btrt_auto_start_dbg = "auto_start_dbg";
  57. std::string btrt_break_exec_path = "break_exec_path";
  58. std::string btrt_build_info = "build_info";
  59. std::string btrt_catch_sys_errors = "catch_system_errors";
  60. std::string btrt_color_output = "color_output";
  61. std::string btrt_detect_fp_except = "detect_fp_exceptions";
  62. std::string btrt_detect_mem_leaks = "detect_memory_leaks";
  63. std::string btrt_list_content = "list_content";
  64. std::string btrt_list_labels = "list_labels";
  65. std::string btrt_log_format = "log_format";
  66. std::string btrt_log_level = "log_level";
  67. std::string btrt_log_sink = "log_sink";
  68. std::string btrt_combined_logger = "logger";
  69. std::string btrt_output_format = "output_format";
  70. std::string btrt_random_seed = "random";
  71. std::string btrt_report_format = "report_format";
  72. std::string btrt_report_level = "report_level";
  73. std::string btrt_report_mem_leaks = "report_memory_leaks_to";
  74. std::string btrt_report_sink = "report_sink";
  75. std::string btrt_result_code = "result_code";
  76. std::string btrt_run_filters = "run_test";
  77. std::string btrt_save_test_pattern = "save_pattern";
  78. std::string btrt_show_progress = "show_progress";
  79. std::string btrt_use_alt_stack = "use_alt_stack";
  80. std::string btrt_wait_for_debugger = "wait_for_debugger";
  81. std::string btrt_help = "help";
  82. std::string btrt_usage = "usage";
  83. std::string btrt_version = "version";
  84. //____________________________________________________________________________//
  85. namespace {
  86. void
  87. register_parameters( rt::parameters_store& store )
  88. {
  89. rt::option auto_start_dbg( btrt_auto_start_dbg, (
  90. rt::description = "Automatically attaches debugger in case of system level failure (signal).",
  91. rt::env_var = "BOOST_TEST_AUTO_START_DBG",
  92. rt::help = "Specifies whether Boost.Test should attempt "
  93. "to attach a debugger when fatal system error occurs. At the moment this feature "
  94. "is only available on a few selected platforms: Win32 and *nix. There is a "
  95. "default debugger configured for these platforms. You can manually configure "
  96. "different debugger. For more details on how to configure the debugger see the "
  97. "Boost.Test debug API, specifically the function boost::debug::set_debugger."
  98. ));
  99. auto_start_dbg.add_cla_id( "--", btrt_auto_start_dbg, "=" );
  100. auto_start_dbg.add_cla_id( "-", "d", " " );
  101. store.add( auto_start_dbg );
  102. ///////////////////////////////////////////////
  103. rt::parameter<std::string> break_exec_path( btrt_break_exec_path, (
  104. rt::description = "For the exception safety testing allows to break at specific execution path.",
  105. rt::env_var = "BOOST_TEST_BREAK_EXEC_PATH"
  106. #ifndef BOOST_NO_CXX11_LAMBDAS
  107. ,
  108. rt::callback = [](rt::cstring) {
  109. BOOST_TEST_SETUP_ASSERT( false, "parameter break_exec_path is disabled in this release" );
  110. }
  111. #endif
  112. ));
  113. break_exec_path.add_cla_id( "--", btrt_break_exec_path, "=" );
  114. store.add( break_exec_path );
  115. ///////////////////////////////////////////////
  116. rt::option build_info( btrt_build_info, (
  117. rt::description = "Displays library build information.",
  118. rt::env_var = "BOOST_TEST_BUILD_INFO",
  119. rt::help = "Displays library build information, including: platform, "
  120. "compiler, STL version and Boost version."
  121. ));
  122. build_info.add_cla_id( "--", btrt_build_info, "=" );
  123. build_info.add_cla_id( "-", "i", " " );
  124. store.add( build_info );
  125. ///////////////////////////////////////////////
  126. rt::option catch_sys_errors( btrt_catch_sys_errors, (
  127. rt::description = "Allows to switch between catching and ignoring system errors (signals).",
  128. rt::env_var = "BOOST_TEST_CATCH_SYSTEM_ERRORS",
  129. rt::default_value =
  130. #ifdef BOOST_TEST_DEFAULTS_TO_CORE_DUMP
  131. false,
  132. #else
  133. true,
  134. #endif
  135. rt::help = "If option " + btrt_catch_sys_errors + " has value 'no' the frameworks does not attempt to catch "
  136. "asynchronous system failure events (signals on *NIX platforms or structured exceptions on Windows). "
  137. " Default value is "
  138. #ifdef BOOST_TEST_DEFAULTS_TO_CORE_DUMP
  139. "no."
  140. #else
  141. "true."
  142. #endif
  143. ));
  144. catch_sys_errors.add_cla_id( "--", btrt_catch_sys_errors, "=", true );
  145. catch_sys_errors.add_cla_id( "-", "s", " " );
  146. store.add( catch_sys_errors );
  147. ///////////////////////////////////////////////
  148. rt::option color_output( btrt_color_output, (
  149. rt::description = "Enables color output of the framework log and report messages.",
  150. rt::env_var = "BOOST_TEST_COLOR_OUTPUT",
  151. rt::default_value = true,
  152. rt::help = "Produces color output for logs, reports and help. "
  153. "Defaults to true. "
  154. ));
  155. color_output.add_cla_id( "--", btrt_color_output, "=", true );
  156. color_output.add_cla_id( "-", "x", " " );
  157. store.add( color_output );
  158. ///////////////////////////////////////////////
  159. rt::option detect_fp_except( btrt_detect_fp_except, (
  160. rt::description = "Enables/disables floating point exceptions traps.",
  161. rt::env_var = "BOOST_TEST_DETECT_FP_EXCEPTIONS",
  162. rt::help = "Enables/disables hardware traps for the floating "
  163. "point exceptions (if supported on your platfrom)."
  164. ));
  165. detect_fp_except.add_cla_id( "--", btrt_detect_fp_except, "=", true );
  166. store.add( detect_fp_except );
  167. ///////////////////////////////////////////////
  168. rt::parameter<unsigned long> detect_mem_leaks( btrt_detect_mem_leaks, (
  169. rt::description = "Turns on/off memory leaks detection (optionally breaking on specified alloc order number).",
  170. rt::env_var = "BOOST_TEST_DETECT_MEMORY_LEAK",
  171. rt::default_value = 1L,
  172. rt::optional_value = 1L,
  173. rt::value_hint = "<alloc order number>",
  174. rt::help = "Enables/disables memory leaks detection. "
  175. "This parameter has optional long integer value. The default value is 1, which "
  176. "enables the memory leak detection. The value 0 disables memory leak detection. "
  177. "Any value N greater than 1 is treated as leak allocation number and tells the "
  178. "framework to setup runtime breakpoint at Nth heap allocation. If value is "
  179. "omitted the default value is assumed."
  180. ));
  181. detect_mem_leaks.add_cla_id( "--", btrt_detect_mem_leaks, "=" );
  182. store.add( detect_mem_leaks );
  183. ///////////////////////////////////////////////
  184. rt::enum_parameter<unit_test::output_format> list_content( btrt_list_content, (
  185. rt::description = "Lists the content of test tree - names of all test suites and test cases.",
  186. rt::env_var = "BOOST_TEST_LIST_CONTENT",
  187. rt::default_value = OF_INVALID,
  188. rt::optional_value = OF_CLF,
  189. rt::enum_values<unit_test::output_format>::value =
  190. #if defined(BOOST_TEST_CLA_NEW_API)
  191. {
  192. { "HRF", OF_CLF },
  193. { "DOT", OF_DOT }
  194. },
  195. #else
  196. rt::enum_values_list<unit_test::output_format>()
  197. ( "HRF", OF_CLF )
  198. ( "DOT", OF_DOT )
  199. ,
  200. #endif
  201. rt::help = "Lists the test suites and cases "
  202. "of the test module instead of executing the test cases. The format of the "
  203. "desired output can be passed to the command. Currently the "
  204. "framework supports two formats: human readable format (HRF) and dot graph "
  205. "format (DOT). If value is omitted HRF value is assumed."
  206. ));
  207. list_content.add_cla_id( "--", btrt_list_content, "=" );
  208. store.add( list_content );
  209. ///////////////////////////////////////////////
  210. rt::option list_labels( btrt_list_labels, (
  211. rt::description = "Lists all available labels.",
  212. rt::env_var = "BOOST_TEST_LIST_LABELS",
  213. rt::help = "Option " + btrt_list_labels + " instructs the framework to list all the the labels "
  214. "defined in the test module instead of executing the test cases."
  215. ));
  216. list_labels.add_cla_id( "--", btrt_list_labels, "=" );
  217. store.add( list_labels );
  218. ///////////////////////////////////////////////
  219. rt::enum_parameter<unit_test::output_format> log_format( btrt_log_format, (
  220. rt::description = "Specifies log format.",
  221. rt::env_var = "BOOST_TEST_LOG_FORMAT",
  222. rt::default_value = OF_CLF,
  223. rt::enum_values<unit_test::output_format>::value =
  224. #if defined(BOOST_TEST_CLA_NEW_API)
  225. {
  226. { "HRF", OF_CLF },
  227. { "CLF", OF_CLF },
  228. { "XML", OF_XML },
  229. { "JUNIT", OF_JUNIT },
  230. },
  231. #else
  232. rt::enum_values_list<unit_test::output_format>()
  233. ( "HRF", OF_CLF )
  234. ( "CLF", OF_CLF )
  235. ( "XML", OF_XML )
  236. ( "JUNIT", OF_JUNIT )
  237. ,
  238. #endif
  239. rt::help = "Set the frameowrk's log format to one "
  240. "of the formats supplied by the framework. The only acceptable values for this "
  241. "parameter are the names of the output formats supplied by the framework. By "
  242. "default the framework uses human readable format (HRF) for testing log. This "
  243. "format is similar to compiler error format. Alternatively you can specify XML "
  244. "or JUNIT as log format, which are easier to process by testing automation tools."
  245. ));
  246. log_format.add_cla_id( "--", btrt_log_format, "=" );
  247. log_format.add_cla_id( "-", "f", " " );
  248. store.add( log_format );
  249. ///////////////////////////////////////////////
  250. rt::enum_parameter<unit_test::log_level> log_level( btrt_log_level, (
  251. rt::description = "Specifies the logging level of the test execution.",
  252. rt::env_var = "BOOST_TEST_LOG_LEVEL",
  253. rt::default_value = log_all_errors,
  254. rt::enum_values<unit_test::log_level>::value =
  255. #if defined(BOOST_TEST_CLA_NEW_API)
  256. {
  257. { "all" , log_successful_tests },
  258. { "success" , log_successful_tests },
  259. { "test_suite" , log_test_units },
  260. { "unit_scope" , log_test_units },
  261. { "message" , log_messages },
  262. { "warning" , log_warnings },
  263. { "error" , log_all_errors },
  264. { "cpp_exception" , log_cpp_exception_errors },
  265. { "system_error" , log_system_errors },
  266. { "fatal_error" , log_fatal_errors },
  267. { "nothing" , log_nothing }
  268. },
  269. #else
  270. rt::enum_values_list<unit_test::log_level>()
  271. ( "all" , log_successful_tests )
  272. ( "success" , log_successful_tests )
  273. ( "test_suite" , log_test_units )
  274. ( "unit_scope" , log_test_units )
  275. ( "message" , log_messages )
  276. ( "warning" , log_warnings )
  277. ( "error" , log_all_errors )
  278. ( "cpp_exception" , log_cpp_exception_errors )
  279. ( "system_error" , log_system_errors )
  280. ( "fatal_error" , log_fatal_errors )
  281. ( "nothing" , log_nothing )
  282. ,
  283. #endif
  284. rt::help = "Set the framework's log level. "
  285. "The log level defines the verbosity of the testing logs produced by a test "
  286. "module. The verbosity ranges from a complete log, when all assertions "
  287. "(both successful and failing) are reported, all notifications about "
  288. "test units start and finish are included, to an empty log when nothing "
  289. "is reported to a testing log stream."
  290. ));
  291. log_level.add_cla_id( "--", btrt_log_level, "=" );
  292. log_level.add_cla_id( "-", "l", " " );
  293. store.add( log_level );
  294. ///////////////////////////////////////////////
  295. rt::parameter<std::string> log_sink( btrt_log_sink, (
  296. rt::description = "Specifies log sink: stdout (default), stderr or file name.",
  297. rt::env_var = "BOOST_TEST_LOG_SINK",
  298. rt::value_hint = "<stderr|stdout|file name>",
  299. rt::help = "Sets the log sink - the location "
  300. "where Boost.Test writes the logs of the test execution. It allows to easily redirect the "
  301. "test logs to file or standard streams. By default testing log is "
  302. "directed to standard output."
  303. ));
  304. log_sink.add_cla_id( "--", btrt_log_sink, "=" );
  305. log_sink.add_cla_id( "-", "k", " " );
  306. store.add( log_sink );
  307. ///////////////////////////////////////////////
  308. rt::enum_parameter<unit_test::output_format> output_format( btrt_output_format, (
  309. rt::description = "Specifies output format (both log and report).",
  310. rt::env_var = "BOOST_TEST_OUTPUT_FORMAT",
  311. rt::enum_values<unit_test::output_format>::value =
  312. #if defined(BOOST_TEST_CLA_NEW_API)
  313. {
  314. { "HRF", OF_CLF },
  315. { "CLF", OF_CLF },
  316. { "XML", OF_XML }
  317. },
  318. #else
  319. rt::enum_values_list<unit_test::output_format>()
  320. ( "HRF", OF_CLF )
  321. ( "CLF", OF_CLF )
  322. ( "XML", OF_XML )
  323. ,
  324. #endif
  325. rt::help = "Combines an effect of " + btrt_report_format +
  326. " and " + btrt_log_format + " parameters. If this parameter is specified, "
  327. "it overrides the value of other two parameters. This parameter does not "
  328. "have a default value. The only acceptable values are string names of "
  329. "output formats: HRF - human readable format and XML - XML formats for "
  330. "automation tools processing."
  331. ));
  332. output_format.add_cla_id( "--", btrt_output_format, "=" );
  333. output_format.add_cla_id( "-", "o", " " );
  334. store.add( output_format );
  335. /////////////////////////////////////////////// combined logger option
  336. rt::parameter<std::string,rt::REPEATABLE_PARAM> combined_logger( btrt_combined_logger, (
  337. rt::description = "Specifies log level and sink for one or several log format",
  338. rt::env_var = "BOOST_TEST_LOGGER",
  339. rt::value_hint = "log_format,log_level,log_sink[:log_format,log_level,log_sink]",
  340. rt::help = "Specify one or more logging definition, which include the logger type, level and sink. "
  341. "The log format, level and sink follow the same format as for the argument '--" + btrt_log_format +
  342. "', '--" + btrt_log_level + "' and '--" + btrt_log_sink + "' respetively. "
  343. "This command can take several logging definition separated by a ':', or be repeated "
  344. "on the command line."
  345. ));
  346. combined_logger.add_cla_id( "--", btrt_combined_logger, "=" );
  347. store.add( combined_logger );
  348. ///////////////////////////////////////////////
  349. rt::parameter<unsigned> random_seed( btrt_random_seed, (
  350. rt::description = "Allows to switch between sequential and random order of test units execution."
  351. " Optionally allows to specify concrete seed for random number generator.",
  352. rt::env_var = "BOOST_TEST_RANDOM",
  353. rt::default_value = 0U,
  354. rt::optional_value = 1U,
  355. rt::value_hint = "<seed>",
  356. rt::help = "Instructs the framework to execute the "
  357. "test cases in random order. This parameter accepts an optional unsigned "
  358. "integer argument. If parameter is specified without the argument value testing "
  359. "order is randomized based on current time. Alternatively you can specify "
  360. "any positive value greater than 1 and it will be used as random seed for "
  361. "the run. "
  362. "By default, the test cases are executed in an "
  363. "order defined by their declaration and the optional dependencies among the test units."
  364. ));
  365. random_seed.add_cla_id( "--", btrt_random_seed, "=" );
  366. store.add( random_seed );
  367. ///////////////////////////////////////////////
  368. rt::enum_parameter<unit_test::output_format> report_format( btrt_report_format, (
  369. rt::description = "Specifies the test report format.",
  370. rt::env_var = "BOOST_TEST_REPORT_FORMAT",
  371. rt::default_value = OF_CLF,
  372. rt::enum_values<unit_test::output_format>::value =
  373. #if defined(BOOST_TEST_CLA_NEW_API)
  374. {
  375. { "HRF", OF_CLF },
  376. { "CLF", OF_CLF },
  377. { "XML", OF_XML }
  378. },
  379. #else
  380. rt::enum_values_list<unit_test::output_format>()
  381. ( "HRF", OF_CLF )
  382. ( "CLF", OF_CLF )
  383. ( "XML", OF_XML )
  384. ,
  385. #endif
  386. rt::help = "Set the framework's report format "
  387. "to one of the formats supplied by the framework. The only acceptable values "
  388. "for this parameter are the names of the output formats. By default the framework "
  389. "uses human readable format (HRF) for results reporting. Alternatively you can "
  390. "specify XML as report format. This format is easier to process by testing "
  391. "automation tools."
  392. ));
  393. report_format.add_cla_id( "--", btrt_report_format, "=" );
  394. report_format.add_cla_id( "-", "m", " " );
  395. store.add( report_format );
  396. ///////////////////////////////////////////////
  397. rt::enum_parameter<unit_test::report_level> report_level( btrt_report_level, (
  398. rt::description = "Specifies test report level.",
  399. rt::env_var = "BOOST_TEST_REPORT_LEVEL",
  400. rt::default_value = CONFIRMATION_REPORT,
  401. rt::enum_values<unit_test::report_level>::value =
  402. #if defined(BOOST_TEST_CLA_NEW_API)
  403. {
  404. { "confirm", CONFIRMATION_REPORT },
  405. { "short", SHORT_REPORT },
  406. { "detailed", DETAILED_REPORT },
  407. { "no", NO_REPORT }
  408. },
  409. #else
  410. rt::enum_values_list<unit_test::report_level>()
  411. ( "confirm", CONFIRMATION_REPORT )
  412. ( "short", SHORT_REPORT )
  413. ( "detailed", DETAILED_REPORT )
  414. ( "no", NO_REPORT )
  415. ,
  416. #endif
  417. rt::help = "Set the verbosity level of the "
  418. "result report generated by the testing framework. Use value 'no' to "
  419. "disable the results report completely."
  420. ));
  421. report_level.add_cla_id( "--", btrt_report_level, "=" );
  422. report_level.add_cla_id( "-", "r", " " );
  423. store.add( report_level );
  424. ///////////////////////////////////////////////
  425. rt::parameter<std::string> report_mem_leaks( btrt_report_mem_leaks, (
  426. rt::description = "File where to report memory leaks to.",
  427. rt::env_var = "BOOST_TEST_REPORT_MEMORY_LEAKS_TO",
  428. rt::default_value = std::string(),
  429. rt::value_hint = "<file name>",
  430. rt::help = "Parameter " + btrt_report_mem_leaks + " allows to specify a file where to report "
  431. "memory leaks to. The parameter does not have default value. If it is not specified, "
  432. "memory leaks (if any) are reported to the standard error stream."
  433. ));
  434. report_mem_leaks.add_cla_id( "--", btrt_report_mem_leaks, "=" );
  435. store.add( report_mem_leaks );
  436. ///////////////////////////////////////////////
  437. rt::parameter<std::string> report_sink( btrt_report_sink, (
  438. rt::description = "Specifies report sink: stderr(default), stdout or file name.",
  439. rt::env_var = "BOOST_TEST_REPORT_SINK",
  440. rt::value_hint = "<stderr|stdout|file name>",
  441. rt::help = "Sets the result report sink - "
  442. "the location where the framework writes the result report to. "
  443. "The sink may be a a file or a standard "
  444. "stream. The default is 'stderr': the "
  445. "standard error stream."
  446. ));
  447. report_sink.add_cla_id( "--", btrt_report_sink, "=" );
  448. report_sink.add_cla_id( "-", "e", " " );
  449. store.add( report_sink );
  450. ///////////////////////////////////////////////
  451. rt::option result_code( btrt_result_code, (
  452. rt::description = "Disables test modules's result code generation.",
  453. rt::env_var = "BOOST_TEST_RESULT_CODE",
  454. rt::default_value = true,
  455. rt::help = "The 'no' argument value for the parameter " + btrt_result_code + " instructs the "
  456. "framework to always return zero result code. This can be used for test programs "
  457. "executed within IDE. By default this parameter has value 'yes'."
  458. ));
  459. result_code.add_cla_id( "--", btrt_result_code, "=", true );
  460. result_code.add_cla_id( "-", "c", " " );
  461. store.add( result_code );
  462. ///////////////////////////////////////////////
  463. rt::parameter<std::string,rt::REPEATABLE_PARAM> tests_to_run( btrt_run_filters, (
  464. rt::description = "Filters which tests to execute.",
  465. rt::env_var = "BOOST_TEST_RUN_FILTERS",
  466. rt::value_hint = "<test unit filter>",
  467. rt::help = "Filters which test units to execute. "
  468. "The framework supports both 'selection filters', which allow to select "
  469. "which test units to enable from the set of available test units, and 'disabler "
  470. "filters', which allow to disable some test units. Boost.test also supports "
  471. "enabling/disabling test units at compile time. These settings identify the default "
  472. "set of test units to run. Parameter " + btrt_run_filters + " is used to change this default. "
  473. "This parameter is repeatable, so you can specify more than one filter if necessary."
  474. ));
  475. tests_to_run.add_cla_id( "--", btrt_run_filters, "=" );
  476. tests_to_run.add_cla_id( "-", "t", " " );
  477. store.add( tests_to_run );
  478. ///////////////////////////////////////////////
  479. rt::option save_test_pattern( btrt_save_test_pattern, (
  480. rt::description = "Allows to switch between saving or matching test pattern file.",
  481. rt::env_var = "BOOST_TEST_SAVE_PATTERN",
  482. rt::help = "Parameter " + btrt_save_test_pattern + " facilitates switching mode of operation for "
  483. "testing output streams.\n\nThis parameter serves no particular purpose within the "
  484. "framework itself. It can be used by test modules relying on output_test_stream to "
  485. "implement testing logic. Default mode is 'match' (false)."
  486. ));
  487. save_test_pattern.add_cla_id( "--", btrt_save_test_pattern, "=" );
  488. store.add( save_test_pattern );
  489. ///////////////////////////////////////////////
  490. rt::option show_progress( btrt_show_progress, (
  491. rt::description = "Turns on progress display.",
  492. rt::env_var = "BOOST_TEST_SHOW_PROGRESS",
  493. rt::help = "Instructs the framework to display the progress of the tests. "
  494. "This feature is turned off by default."
  495. ));
  496. show_progress.add_cla_id( "--", btrt_show_progress, "=" );
  497. show_progress.add_cla_id( "-", "p", " " );
  498. store.add( show_progress );
  499. ///////////////////////////////////////////////
  500. rt::option use_alt_stack( btrt_use_alt_stack, (
  501. rt::description = "Turns on/off usage of an alternative stack for signal handling.",
  502. rt::env_var = "BOOST_TEST_USE_ALT_STACK",
  503. rt::default_value = true,
  504. rt::help = "Instructs the framework to use an alternative "
  505. "stack for operating system's signals handling (on platforms where this is supported). "
  506. "The feature is enabled by default, but can be disabled using this command line switch."
  507. ));
  508. use_alt_stack.add_cla_id( "--", btrt_use_alt_stack, "=", true );
  509. store.add( use_alt_stack );
  510. ///////////////////////////////////////////////
  511. rt::option wait_for_debugger( btrt_wait_for_debugger, (
  512. rt::description = "Forces test module to wait for button to be pressed before starting test run.",
  513. rt::env_var = "BOOST_TEST_WAIT_FOR_DEBUGGER",
  514. rt::help = "Instructs the framework to pause before starting "
  515. "test units execution, so that you can attach a debugger to the test module process. "
  516. "This feature is turned off by default."
  517. ));
  518. wait_for_debugger.add_cla_id( "--", btrt_wait_for_debugger, "=" );
  519. wait_for_debugger.add_cla_id( "-", "w", " " );
  520. store.add( wait_for_debugger );
  521. ///////////////////////////////////////////////
  522. rt::parameter<std::string> help( btrt_help, (
  523. rt::description = "Help for framework parameters.",
  524. rt::optional_value = std::string(),
  525. rt::value_hint = "<parameter name>",
  526. rt::help = "Displays help on the framework's parameters. "
  527. "The parameter accepts an optional argument value. If present, an argument value is "
  528. "interpreted as a parameter name (name guessing works as well, so for example "
  529. "'--help=rand' displays help on the parameter 'random'). If the parameter name is unknown "
  530. "or ambiguous error is reported. If argument value is absent, a summary of all "
  531. "framework's parameter is displayed."
  532. ));
  533. help.add_cla_id( "--", btrt_help, "=" );
  534. store.add( help );
  535. ///////////////////////////////////////////////
  536. rt::option usage( btrt_usage, (
  537. rt::description = "Short message explaining usage of Boost.Test parameters."
  538. ));
  539. usage.add_cla_id( "-", "?", " " );
  540. store.add( usage );
  541. ///////////////////////////////////////////////
  542. rt::option version( btrt_version, (
  543. rt::description = "Prints Boost.Test version and exits."
  544. ));
  545. version.add_cla_id( "--", btrt_version, " " );
  546. store.add( version );
  547. }
  548. static rt::arguments_store s_arguments_store;
  549. static rt::parameters_store s_parameters_store;
  550. //____________________________________________________________________________//
  551. } // local namespace
  552. void
  553. init( int& argc, char** argv )
  554. {
  555. shared_ptr<rt::cla::parser> parser;
  556. BOOST_TEST_I_TRY {
  557. // Initialize parameters list
  558. if( s_parameters_store.is_empty() )
  559. register_parameters( s_parameters_store );
  560. // Clear up arguments store just in case (of multiple init invocations)
  561. s_arguments_store.clear();
  562. // Parse CLA they take precedence over environment
  563. parser.reset( new rt::cla::parser( s_parameters_store, (rt::end_of_params = "--", rt::negation_prefix = "no_") ) );
  564. argc = parser->parse( argc, argv, s_arguments_store );
  565. // Try to fetch missing arguments from environment
  566. rt::env::fetch_absent( s_parameters_store, s_arguments_store );
  567. // Set arguments to default values if defined and perform all the validations
  568. rt::finalize_arguments( s_parameters_store, s_arguments_store );
  569. // check if colorized output is enabled
  570. bool use_color = true;
  571. if( s_arguments_store.has(btrt_color_output ) ) {
  572. use_color = runtime_config::get<bool>(runtime_config::btrt_color_output);
  573. }
  574. // Report help if requested
  575. if( runtime_config::get<bool>( btrt_version ) ) {
  576. parser->version( std::cerr );
  577. BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_success ) );
  578. }
  579. else if( runtime_config::get<bool>( btrt_usage ) ) {
  580. parser->usage( std::cerr, runtime::cstring(), use_color );
  581. BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_success ) );
  582. }
  583. else if( s_arguments_store.has( btrt_help ) ) {
  584. parser->help(std::cerr,
  585. s_parameters_store,
  586. runtime_config::get<std::string>( btrt_help ),
  587. use_color );
  588. BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_success ) );
  589. }
  590. // A bit of business logic: output_format takes precedence over log/report formats
  591. if( s_arguments_store.has( btrt_output_format ) ) {
  592. unit_test::output_format of = s_arguments_store.get<unit_test::output_format>( btrt_output_format );
  593. s_arguments_store.set( btrt_report_format, of );
  594. s_arguments_store.set( btrt_log_format, of );
  595. }
  596. }
  597. BOOST_TEST_I_CATCH( rt::init_error, ex ) {
  598. BOOST_TEST_SETUP_ASSERT( false, ex.msg );
  599. }
  600. BOOST_TEST_I_CATCH( rt::ambiguous_param, ex ) {
  601. std::cerr << ex.msg << "\n Did you mean one of these?\n";
  602. BOOST_TEST_FOREACH( rt::cstring, name, ex.m_amb_candidates )
  603. std::cerr << " " << name << "\n";
  604. BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_exception_failure ) );
  605. }
  606. BOOST_TEST_I_CATCH( rt::unrecognized_param, ex ) {
  607. std::cerr << ex.msg << "\n";
  608. if( !ex.m_typo_candidates.empty() ) {
  609. std::cerr << " Did you mean one of these?\n";
  610. BOOST_TEST_FOREACH( rt::cstring, name, ex.m_typo_candidates )
  611. std::cerr << " " << name << "\n";
  612. }
  613. else if( parser ) {
  614. std::cerr << "\n";
  615. parser->usage( std::cerr );
  616. }
  617. BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_exception_failure ) );
  618. }
  619. BOOST_TEST_I_CATCH( rt::input_error, ex ) {
  620. std::cerr << ex.msg << "\n\n";
  621. if( parser )
  622. parser->usage( std::cerr, ex.param_name );
  623. BOOST_TEST_I_THROW( framework::nothing_to_test( boost::exit_exception_failure ) );
  624. }
  625. }
  626. //____________________________________________________________________________//
  627. rt::arguments_store const&
  628. argument_store()
  629. {
  630. return s_arguments_store;
  631. }
  632. //____________________________________________________________________________//
  633. bool
  634. save_pattern()
  635. {
  636. return runtime_config::get<bool>( btrt_save_test_pattern );
  637. }
  638. //____________________________________________________________________________//
  639. } // namespace runtime_config
  640. } // namespace unit_test
  641. } // namespace boost
  642. #include <boost/test/detail/enable_warnings.hpp>
  643. #endif // BOOST_TEST_UNIT_TEST_PARAMETERS_IPP_012205GER