Skip to content

CXX-2745 refactor test directory structure by ABI namespace #1403

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

eramongodb
Copy link
Collaborator

@eramongodb eramongodb commented May 13, 2025

Related to CXX-2745. Precursor changes to CXX-3233.

Refactors the test directory structure and components to support the introduction of v1 test components by better distinguishing tests by ABI namespace. Additionally applies precursor changes to improve the state of undesirable transitive include dependencies due to headers such as <bsoncxx/test/catch.hh>.

As a drive-by improvement, Catch2 is updated to the latest release (v3.8.1). This addresses some Catch2-internal compiler warnings as well as a bug which may affect v1 tests on Windows due to use of StringMaker<std::chrono::time_point<Clock>> for v1::types::b_date stringification (as part of CXX-3233).


The test directory components are refactored to mirror the structure of the library components which they test (with an exception for the v_noabi directory which is flattened):

src/bsoncxx/
├── lib/bsoncxx/
│   ├── private/
│   │   ├── make_unique.hh
│   │   └── ...
│   ├── v1/
│   │   ├── document/
│   │   │   ├── view.cpp
│   │   │   └── ...
│   │   └── ...
│   └── v_noabi/bsoncxx/
│       ├── document/
│       │   ├── view.cpp
│       │   └── ...
│       └── ...
└── test/
    ├── private/
    │   ├── make_unique.test.cpp
    │   └── ...
    ├── v1/
    │   ├── document/
    │   │   ├── view.cpp
    │   │   └── ...
    │   └── ...
    └── v_noabi/
        ├── document/
        │   ├── view.cpp
        │   └── ...
        └── ...

Test-specific components reside outside of ABI directories to avoid associating them with library components, e.g. <bsoncxx/test/catch.hh>, <mongocxx/test/spec/util.hh>, etc.


Catch stringification (used in decomposition of assertion expressions) is improved with the introduction of StringMaker<std::error_condition> and the extraction Catch::StringMaker<T> specializations out of <bsoncxx/test/catch.hh> into individual test headers. This is part of a greater effort to avoid "include funnel" test headers such as <bsoncxx/test/catch.hh> and <bsoncxx/test/v_noabi/to_string.hh> by using individual component-based "test headers" (e.g. <bsoncxx/test/v1/stdx/string_view.hh for <bsoncxx/v1/stdx/string_view.hpp>) to reduce transitive include dependencies and improve test (re)compilation efficiency while continuing to support Catch stringification. This will be explored in greater detail by CXX-3233.

@eramongodb eramongodb requested a review from kevinAlbs May 13, 2025 21:59
@eramongodb eramongodb self-assigned this May 13, 2025
@eramongodb eramongodb requested a review from a team as a code owner May 13, 2025 21:59
@eramongodb eramongodb changed the title test: upgrade Catch2 from 3.7.0 to 3.8.1 CXX-2745 refactor test directory structure by ABI namespace May 13, 2025
@eramongodb
Copy link
Collaborator Author

Addressed Evergreen task failures:

  • Fixed missing or misplaced source files were missing or misplaced in refactored mongocxx test sources lists.
  • Catch2 3.8.0 requires CMake 3.16 or newer. Similar to our C++14 requirement, this is not expected to be a problem given ENABLE_TESTS is OFF by default since C++ Driver 3.11.0. However, two subtle issues were causing CMake configuration errors during CMake version compatibility checks due to this new requirement:
    • Use of CMAKE_DISABLE_FIND_PACKAGE_<PackageName> exposed(?) deficient guards for the ENABLE_TESTS cache variable (OFF by default) during FetchContent configuration given the C Driver also uses the same cache variable (ON by default). CMP0126 might be related, but the root cause of this error is still unclear. CMake docs for CMAKE_DISABLE_FIND_PACKAGE_<PackageName> however do state the following:

      Note that this variable can lead to inconsistent results within the project.

      Therefore, the changelog entry deliberately mentions that this fix only applies when CMAKE_REQUIRE_FIND_PACKAGE_<PackageName> is set.

    • Use of add_subdirectory(mongoc) before add_subdirectory(mongo-cxx-driver) in the add_subdirectory test initializes ENABLE_TESTS=ON. Therefore, ENABLE_TESTS (and ENABLE_EXAMPLES) are explicitly set to OFF within the CMake config to avoid defining unnecessary targets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant