Reuse bsoncxx::v1 out-of-line definitions of Catch::StringMaker<T>::convert() #1500
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Related to CXX-3237. #1430 added
Catch::StringMaker<T>specializations forbsoncxx::v1entities so that Catch's expression decomposition feature can translate BSON documents and elements into readable strings on assertion failures (or--successoutput) without requiring an "include all" test header containing all specializations (compilation performance). However, there are three specializations which contain out-of-line definitions of theconvert()function:v1::array::view,v1::document::view, andv1::element::view. These definitions are not available for use by themongocxx_mockedtest library, asbsoncxx_testingis not compiled with test sources; it is merely a bsoncxx library compiled with theBSONCXX_TESTINGpreprocessor macro defined to control test-only symbol exports. It is not aware of Catch2, nor should it be. Consequently, when e.g.bsoncxx/test/v1/document/view.hhis included by mongocxx test sources, despite the class template specialization being visible, theconvert()member function definition is not, leading to the one defined by Catch2's partial template specializations for ranges or similar (tbh I am not entirely sure why this is not a hard linker error).To address this issue, the out-of-line definitions are isolated into
*_string_maker.cppimplementation files. These files are then included as additional source files for individual mongocxx test executables via${mongocxx_test_bsoncxx}(a variable is used instead of an object library to avoid reserving new names in the CMake global target namespace; still hoping for cmake/cmake#22687 to be addressed someday...). The newmongocxx/test/bsoncxx.cppfile validates that the correctCatch::StringMaker<T>definitions are used when stringifyingbsoncxx::v1entities (v1::document::view->v1::element::view->v1::types::view->v1::array::view). The test headers are also given additional transitive includes to ensure theCatch::StringMaker<T>specializations are consistently visible prior to use (which also correspond to publically documented transitive includes).