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