boost_test_universal_macro.qbk 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. [/
  2. / Copyright (c) 2015 Boost.Test contributors
  3. /
  4. / Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. / file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. /]
  7. [section:boost_test_universal_macro BOOST_TEST: universal and general purpose assertions]
  8. The __UTF__ provides an almost unique interface to a great range of test-case scenarios, through the __BOOST_TEST__
  9. macro. The general form of `BOOST_TEST` is the following:
  10. BOOST_TEST(statement);
  11. BOOST_TEST_<level>(statement, optional_modifiers)
  12. An example of use might be the following:
  13. [bt_example boost_test_macro_overview..BOOST_TEST overview..run-fail]
  14. The major features of this tool are:
  15. * a great flexibility for `statement` which may be almost anything: full expression composed by several operations are supported
  16. and handled,
  17. * an extended reporting capability in case of failure: not only `BOOST_TEST` reports the location of the failure and a copy of `statement` itself,
  18. but also the values of the operands that permits a rapid identification of the issues related to the failed assertion,
  19. * the possibility to control better the behavior or the reports of the checks, in particular:
  20. * floating point comparison: the tolerance may be provided, either using the `BOOST_TEST`
  21. directly with `optional_modifiers`, or with /decorators/ (see [link boost_test.testing_tools.extended_comparison.floating_point here]
  22. for more details),
  23. * container/collection comparisons: different operations for comparison are provided out of the box for comparing collection of
  24. elements (default, per-element, lexicographic), with extended diagnostic on failures (covered in
  25. [link boost_test.testing_tools.extended_comparison.collections this] section),
  26. * string comparison: C-strings operands are automatically detected and the comparisons are performed as if `std::string` objects
  27. were used,
  28. * optional failure message,
  29. * bitwise comparison, providing extended diagnostic in case of failure
  30. [warning To get all the functionalities of `BOOST_TEST` family of assertions, a C++11 capable compiler is required, especially
  31. supporting the `auto` and `decltype` keywords and the variadic macros. The documentation focuses on these set of compilers.
  32. For compilers not supporting all the features of `BOOST_TEST`, the macro `BOOST_TEST_MACRO_LIMITED_SUPPORT`.]
  33. [#boost_test_statement_overloads][h3 Complex statements]
  34. `BOOST_TEST` provides an enhanced reporting capability: additional details of the failing operands and operations are provided in the log,
  35. as shown on the example below:
  36. [bt_example boost_test_macro3..BOOST_TEST enhanced reporting..run-fail]
  37. `BOOST_TEST` parses the `statement` and constructs an expression out of it. `statement` may be a complex expressions
  38. containing almost any of the overloadable operators in C++:
  39. [table
  40. [[Class of operation][operators]]
  41. [[binary comparisons][`==`, `!=`, `<`, `>`, `<=`, `>=`]]
  42. [[arithmetic compositions][`+`, `-`, `*`, `/`, `%`]]
  43. [[bitwise compositions][`|`, `&`, `^`, `<<`, `>>`]]
  44. [[assignments][`=`, `+=`, `-=`, `*=`, `/=`, `%=`, `<<=`, `>>=`, `&=`, `^=`, `|=`]]
  45. ]
  46. `statement` is evaluated and cast to `bool`, as if it would appear as argument to an `if` statement: this is the result of the assertion
  47. [h3 Uniform reporting]
  48. This tool is provided in three variants corresponding to the corresponding
  49. [link boost_test.testing_tools.tools_assertion_severity_level severity levels]. These three levels of assertions are
  50. reported into the test log and output, as described in details in the section. The granularity of the
  51. report depends on the current [link boost_test.utf_reference.rt_param_reference.log_level log level] and
  52. [link boost_test.utf_reference.rt_param_reference.report_level report level].
  53. [#boost_test_statement_limitations][h3 Limitations & workaround]
  54. There are a few constructions that are however unsupported, but adding an extra bracket usually solves that:
  55. * statements containing ternary conditions: those statement should be surrounded by parenthesis as they cannot be overloaded
  56. * statements containing commas: those statements will be intercepted by the preprocessor
  57. * compound statements containing any logical composition `||`, `&&`. Those are disabled intentionally and should be surrounded
  58. by parenthesis
  59. BOOST_TEST((true || false));
  60. The full details are given in [link boost_test.testing_tools.internal_details this section].
  61. [bt_example boost_test_macro_workaround..BOOST_TEST limitation and workaround..run]
  62. [endsect] [/ boost_test_universal_macro]