master_test_suite.qbk 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. [/
  2. / Copyright (c) 2019 Raffi Enficiaud
  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:master_test_suite Master test suite]
  8. As defined in introduction section the master test suite is the *root* node of the test tree. Each test module built
  9. with the __UTF__ always has the (unique) master test suite defined. The __UTF__ maintain the master test suite instance
  10. internally. All other test units are registered as direct or indirect children of the master test suite.
  11. ``
  12. namespace boost {
  13. namespace unit_test {
  14. class master_test_suite_t : public test_suite
  15. {
  16. /// implementation details
  17. public:
  18. int argc;
  19. char** argv;
  20. };
  21. } // namespace unit_test
  22. } // namespace boost
  23. ``
  24. To access single instance of the master test suite use the following interface:
  25. ``
  26. namespace boost {
  27. namespace unit_test {
  28. namespace framework {
  29. master_test_suite_t& master_test_suite();
  30. } // namespace framework
  31. } // namespace unit_test
  32. } // namespace boost
  33. ``
  34. [h4 Command line arguments access interface]
  35. Master test suite implemented as an extension to the regular test suite, since it maintains references to the
  36. command line arguments passed to the test module. To access the command line arguments use
  37. ``
  38. boost::unit_test::framework::master_test_suite().argc
  39. boost::unit_test::framework::master_test_suite().argv
  40. ``
  41. In below example references to the command line arguments are accessible either as an initialization function
  42. parameters or as members of the master test suite. Both references point to the same values. A test module that
  43. uses the alternative initialization function specification can only access command line arguments through the
  44. master test suite.
  45. Returning to the free function example, let's modify initialization function to check for absence of any
  46. test module arguments.
  47. [bt_example example13..Command line access in initialization function..run]
  48. [#ref_BOOST_TEST_MODULE][h4 Naming the ['Master test suite]]
  49. The master test suite is created with default name ['Master Test Suite]. There are two methods two
  50. reset the name to a different value: using the macro __BOOST_TEST_MODULE__
  51. and from within the test module initialization function. Former is used for test modules that don't have the
  52. manually implemented initialization function. Following examples illustrate these methods.
  53. [bt_example example14..Naming master test suite using the macro __BOOST_TEST_MODULE__..run]
  54. If the macro __BOOST_TEST_MODULE__ is defined, the test module initialization
  55. function is [*automatically generated] and the
  56. macro value becomes the name of the master test suite. The name may include spaces.
  57. [bt_example example15..Naming master test suite explicitly in the test module initialization function..run]
  58. Without the __BOOST_TEST_MAIN__ and the __BOOST_TEST_MODULE__ flags defined, the test module initialization
  59. function has to be manually implemented. The master test suite name can be reset at any point within this function.
  60. [endsect] [/ master test suite]