2 / Copyright (c) 2003 Boost.Test contributors
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)
8 [section:shared_lib_customizations Shared-library variant customizations]
10 [caution Macro __BOOST_TEST_DYN_LINK__ (which instructs the compiler/linker to dynamically link against a shared
11 library variant) may be implicitly defined when macro `BOOST_ALL_DYN_LINK` is defined.]
13 [caution In order to be able to run a test built with the dynamic variant, the operating system should be able
14 to find the dynamic library of the __UTF__. This means, for example on Linux and MacOSX respectively, setting the environment
15 variable `LD_LIBRARY_PATH` or `DYLD_LIBRARY_PATH` properly prior to the execution of the test module.]
17 [section:entry_point Customizing the module's entry point]
19 In this variant, in one of the source files, you now have to define your custom entry point, and invoke the default
20 [link boost_test.adv_scenarios.test_module_runner_overview test runner] `unit_test_main` manually with the default
21 [link boost_test.adv_scenarios.test_module_init_overview initialization function] `init_unit_test` as argument.
22 You need to define __BOOST_TEST_NO_MAIN__ (its value is irrelevant) in the main file:
25 [[In *exactly one* file][In all other files]]
26 [[```#define BOOST_TEST_MODULE test module name
27 #define BOOST_TEST_DYN_LINK
28 #define BOOST_TEST_NO_MAIN
29 #include <boost/test/unit_test.hpp>
32 int main(int argc, char* argv[], char* envp[])
34 return boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
37 [```#define BOOST_TEST_DYN_LINK
38 #include <boost/test/unit_test.hpp>
50 [endsect] [/section:entry_point]
52 [section:init_func Customizing the module's initialization function]
54 In the shared-library variant, it is impossible to customize the initialization function without
55 [link boost_test.adv_scenarios.shared_lib_customizations.entry_point customizing the entry point]. We have
56 to customize both. In one of the source files, you now have to define your custom entry point and
57 [link boost_test.adv_scenarios.test_module_init_overview initialization function] `init_unit_test`; next invoke
58 the default [link boost_test.adv_scenarios.test_module_runner_overview test runner] `unit_test_main` manually
59 with `init_unit_test` as argument. You ['do not] define __BOOST_TEST_MODULE__ in the main file:
62 [[In *exactly one* file][In all other files]]
63 [[```#define BOOST_TEST_DYN_LINK
64 #include <boost/test/unit_test.hpp>
66 // initialization function:
73 int main(int argc, char* argv[])
75 return boost::unit_test::unit_test_main( &init_unit_test, argc, argv );
78 [```#define BOOST_TEST_DYN_LINK
79 #include <boost/test/unit_test.hpp>
95 For reporting errors that may occur during the initialization,
97 * either you return `false` (valid only for the new API only, see __BOOST_TEST_ALTERNATIVE_INIT_API__)
98 * or you raise an exception such as `std::runtime_error` or [classref boost::unit_test::framework::setup_error]
100 An error reported in this function aborts the execution of the test module.
102 [endsect] [/section:init_func]
104 [endsect] [/section:shared_lib_customizations]