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