Skip to content

Commit f183933

Browse files
authored
CXX-3094 Upgrade Catch2 from v2 to v3 (#1200)
* clang-format: separate system and third-party headers from driver headers * Remove obsolete MONGO_CXX_DRIVER_COMPILING compile definition * Do not build or run tests on VS 2015 distros * Upgrade to Catch2 v3 via FetchCatch2.cmake * Format catch_helpers.hh * Conditionally pass SYSTEM to FetchContent_Declare * Disable tests in RPM snapshot builds * Address -Wextra-semi* warnings * Update Catch2 license in THIRD-PARTY-NOTICES to match v3.7.0
1 parent aa0b94c commit f183933

File tree

117 files changed

+560
-18296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+560
-18296
lines changed

.clang-format

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ Cpp11BracedListStyle: true
1010
DerivePointerAlignment: false
1111
IncludeBlocks: Regroup
1212
IncludeCategories:
13-
- Regex: 'prelude\.(hpp|hh)' # preludes
14-
Priority: 4
13+
- Regex: '".*"' # relative headers
14+
Priority: 10
15+
- Regex: '(bsoncxx|mongocxx)/config(/private)?/prelude\.(hpp|hh)' # v_noabi preludes
16+
Priority: 50
17+
- Regex: '(bsoncxx|mongocxx)/test/.*' # test headers
18+
Priority: 60
1519
- Regex: '<[[:alnum:]_.]+>' # system headers
16-
Priority: 1
17-
- Regex: '.*(-|\/)fwd\.(hpp|hh)' # forwarding headers
18-
Priority: 2
19-
- Regex: '.*' # driver headers
20-
Priority: 3
20+
Priority: 20
21+
- Regex: '(bsoncxx|mongocxx)/.*(-|\/)fwd\.(hpp|hh)' # all driver forwarding headers
22+
Priority: 30
23+
- Regex: '(bsoncxx|mongocxx)/.*' # all remaining (normal) driver headers
24+
Priority: 40
25+
- Regex: '.*' # all other headers (third party)
26+
Priority: 90
2127
IndentWidth: 4
2228
MaxEmptyLinesToKeep: 1
2329
NamespaceIndentation: None

.evergreen/build_snapshot_rpm.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ sudo mock -r ${config} --use-bootstrap-image --isolation=simple --copyout "/tmp/
105105
sudo mock -r ${config} --use-bootstrap-image --isolation=simple --cwd "/tmp/${build_dir}" --chroot -- /bin/sh -c "(
106106
[ -d build ] || mkdir build ;
107107
cd build ;
108-
/usr/bin/cmake -DCMAKE_BUILD_TYPE=Release -DBSONCXX_POLY_USE_BOOST=1 -DENABLE_UNINSTALL=OFF .. ;
108+
/usr/bin/cmake -DCMAKE_BUILD_TYPE=Release -DBSONCXX_POLY_USE_BOOST=1 -DENABLE_UNINSTALL=OFF -DENABLE_TESTS=OFF .. ;
109109
make -j 8 dist
110110
)"
111111

.evergreen/test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ PATH="${working_dir:?}/build/src/mongocxx/test/${build_type:?}:${PATH:-}"
6060
PATH="${working_dir:?}/build/src/bsoncxx/test/${build_type:?}:${PATH:-}"
6161
PATH="${working_dir:?}/build/src/mongocxx/${build_type:?}:${PATH:-}"
6262
PATH="${working_dir:?}/build/src/bsoncxx/${build_type:?}:${PATH:-}"
63+
PATH="${working_dir:?}/build/_deps/ep_catch2-build/src/${build_type:?}:${PATH:-}"
6364
PATH="${mongoc_dir:?}/bin:${PATH:-}"
6465
PATH="${working_dir:?}/build/install/bin:${PATH:-}"
6566

.mci.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,8 @@ tasks:
10011001
- func: "setup"
10021002
- func: "fetch_c_driver_source"
10031003
- func: "compile"
1004+
vars:
1005+
ENABLE_TESTS: OFF
10041006
- command: shell.exec
10051007
type: test
10061008
params:
@@ -1015,6 +1017,8 @@ tasks:
10151017
- func: "setup"
10161018
- func: "fetch_c_driver_source"
10171019
- func: "compile"
1020+
vars:
1021+
ENABLE_TESTS: OFF
10181022
- command: shell.exec
10191023
type: test
10201024
params:
@@ -2156,10 +2160,7 @@ buildvariants:
21562160
run_on:
21572161
- windows-64-vs2015-compile
21582162
tasks:
2159-
- name: compile_and_test_with_shared_libs
2160-
- name: compile_and_test_with_shared_libs_extra_alignment
2161-
- name: compile_and_test_with_static_libs
2162-
- name: compile_and_test_with_static_libs_extra_alignment
2163+
- name: compile_without_tests
21632164
- name: uninstall_check_windows
21642165

21652166
- name: windows-2k8-debug
@@ -2172,9 +2173,8 @@ buildvariants:
21722173
run_on:
21732174
- windows-64-vs2015-compile
21742175
tasks:
2175-
# The debug shared lib is tested in the "integration tests" matrix
2176-
- name: compile_and_test_with_static_libs
2177-
- name: compile_and_test_with_static_libs_extra_alignment
2176+
- name: compile_without_tests
2177+
- name: uninstall_check_windows
21782178

21792179
- name: windows-msvc2015-debug
21802180
display_name: "Windows (VS 2015) Debug (MongoDB 4.2)"
@@ -2186,8 +2186,8 @@ buildvariants:
21862186
run_on:
21872187
- windows-64-vs2015-compile
21882188
tasks:
2189-
- name: compile_with_shared_libs
2190-
- name: compile_and_test_auth_with_shared_libs
2189+
- name: compile_without_tests
2190+
- name: uninstall_check_windows
21912191

21922192
- name: packaging
21932193
display_name: Linux Distro Packaging

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ Changes prior to 3.9.0 are documented as [release notes on GitHub](https://githu
1111

1212
### Changed
1313

14-
- `FetchContent_MakeAvailable()` is used to populate dependencies instead of `FetchContent_Populate()` for the Mongo C Driver (when not provided by `CMAKE_PREFIX_PATH`) and mnmlstc/core (when automatically selected or `BSONCXX_POLY_USE_MNMLSTC=ON`).
14+
- `FetchContent_MakeAvailable()` is used to populate dependencies instead of `FetchContent_Populate()` for the Mongo C Driver (when not provided by `CMAKE_PREFIX_PATH`) and mnmlstc/core (when automatically selected or when `BSONCXX_POLY_USE_MNMLSTC=ON`).
1515
- Note: `FetchContent_Populate()` is still used for mnmlstc/core for CMake versions prior to 3.18 to avoid `add_subdirectory()` behavior.
16+
- Test suite now uses Catch2 v3 via FetchContent instead of the bundled Catch2 v2 standalone header.
17+
- C++14 or newer is now required to build tests when enabled with `ENABLE_TESTS=ON`.
1618

1719
### Deprecated
1820

THIRD-PARTY-NOTICES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ https://github.com/mongodb/mongo-cxx-driver.
1515
---------------------------------------
1616
[Note: Catch is used only for testing.]
1717

18-
Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
18+
Copyright Catch2 Authors
1919

2020
Distributed under the Boost Software License, Version 1.0.
2121
See http://www.boost.org/LICENSE_1_0.txt

cmake/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ add_subdirectory(make_dist)
1616

1717
set(cmake_MODULES
1818
BsoncxxUtil.cmake
19+
FetchCatch2.cmake
1920
FetchMnmlstcCore.cmake
2021
FetchMongoC.cmake
2122
MacroGuardTest.cmake

cmake/FetchCatch2.cmake

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Use FetchContent to obtain Catch2.
2+
3+
include(FetchContent)
4+
5+
message(STATUS "Downloading Catch2...")
6+
7+
function(fetch_catch2)
8+
set(fetch_args "")
9+
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.25.0")
10+
set(fetch_args "SYSTEM")
11+
endif()
12+
13+
FetchContent_Declare(
14+
EP_Catch2
15+
16+
GIT_REPOSITORY https://github.com/catchorg/Catch2
17+
GIT_TAG v3.7.0
18+
GIT_SHALLOW TRUE
19+
LOG_DOWNLOAD ON
20+
21+
${fetch_args}
22+
23+
FETCHCONTENT_UPDATES_DISCONNECTED ON
24+
)
25+
26+
FetchContent_GetProperties(EP_Catch2)
27+
28+
if(NOT ep_catch2_POPULATED)
29+
# Avoid Catch2 compile warnings from being treated as errors.
30+
string(REPLACE " -Werror" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
31+
string(REPLACE " -Werror" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
32+
33+
FetchContent_MakeAvailable(EP_Catch2)
34+
35+
# Avoid building unnecessary targets. Use FetchContent_Declare(EXCLUDE_FROM_ALL) in CMake 3.28 and newer.
36+
set_property(DIRECTORY "${ep_catch2_SOURCE_DIR}" PROPERTY EXCLUDE_FROM_ALL ON)
37+
38+
# Catch2 config vars.
39+
set_property(CACHE CATCH_INSTALL_DOCS PROPERTY VALUE OFF)
40+
set_property(CACHE CATCH_INSTALL_EXTRAS PROPERTY VALUE OFF)
41+
endif()
42+
endfunction()
43+
44+
fetch_catch2()
45+
46+
message (STATUS "Downloading Catch2... done.")

cmake/FetchMnmlstcCore.cmake

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ set(core-subbuild "${CMAKE_CURRENT_BINARY_DIR}/_deps/core-subbuild")
77
set(core-build "${CMAKE_CURRENT_BINARY_DIR}/_deps/core-build")
88
set(core-install "${CMAKE_CURRENT_BINARY_DIR}/_deps/core-install")
99

10+
set(fetch_args "")
11+
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.25.0")
12+
set(fetch_args "SYSTEM")
13+
endif()
14+
1015
# Also update etc/purls.txt.
1116
FetchContent_Declare(
1217
EP_mnmlstc_core
@@ -22,6 +27,8 @@ FetchContent_Declare(
2227
GIT_SHALLOW TRUE
2328
LOG_DOWNLOAD ON
2429

30+
${fetch_args}
31+
2532
FETCHCONTENT_UPDATES_DISCONNECTED ON
2633
)
2734
FetchContent_GetProperties(EP_mnmlstc_core)
@@ -33,7 +40,7 @@ if(core_FOUND AND "$CACHE{INTERNAL_MONGOC_MNMLSTC_CORE_FOUND}")
3340
else()
3441
if(NOT ep_mnmlstc_core_POPULATED)
3542
message(STATUS "Downloading mnmlstc/core...")
36-
if("${CMAKE_VERSION}" VERSION_LESS "3.18.0")
43+
if(CMAKE_VERSION VERSION_LESS "3.18.0")
3744
# SOURCE_SUBDIR is not yet supported.
3845
FetchContent_Populate(EP_mnmlstc_core)
3946
else()

cmake/FetchMongoC.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@ include(FetchContent)
44

55
message(STATUS "Download and configure C driver version ${LIBMONGOC_DOWNLOAD_VERSION} ... begin")
66

7+
set(fetch_args "")
8+
if (CMAKE_VERSION VERSION_GREATER_EQUAL "3.25.0")
9+
set(fetch_args "SYSTEM")
10+
endif()
11+
712
# Declare mongo-c-driver as a dependency
813
FetchContent_Declare(
914
mongo-c-driver
1015
GIT_REPOSITORY https://github.com/mongodb/mongo-c-driver.git
1116
GIT_TAG ${LIBMONGOC_DOWNLOAD_VERSION}
17+
18+
${fetch_args}
1219
)
1320

1421
FetchContent_GetProperties(mongo-c-driver)

src/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
add_definitions(-DMONGO_CXX_DRIVER_COMPILING)
1615
add_subdirectory(bsoncxx)
1716
add_subdirectory(mongocxx)
1817

1918
set_local_dist(src_DIST_local
2019
CMakeLists.txt
21-
third_party/catch/main.cpp
22-
third_party/catch/include/catch.hpp
23-
third_party/catch/include/helpers.hpp
2420
)
2521

2622
set(src_DIST

src/bsoncxx/include/bsoncxx/v_noabi/bsoncxx/builder/list.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class document : public list {
160160
///
161161
/// Creates an empty document.
162162
///
163-
document() : list({}, false, false){};
163+
document() : list({}, false, false) {}
164164

165165
///
166166
/// Creates a BSON document.
@@ -184,7 +184,7 @@ class array : public list {
184184
///
185185
/// Creates an empty array.
186186
///
187-
array() : list({}, false, true){};
187+
array() : list({}, false, true) {}
188188

189189
///
190190
/// Creates a BSON array.

src/bsoncxx/test/CMakeLists.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
include(FetchCatch2)
16+
1517
if(NOT BUILD_TESTING)
1618
set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL TRUE)
1719
endif()
@@ -46,25 +48,28 @@ add_executable(test_bson
4648

4749
# Common target properties for test executables.
4850
add_library(bsoncxx_test_properties INTERFACE)
51+
52+
target_link_libraries(bsoncxx_test_properties INTERFACE Catch2::Catch2)
53+
target_compile_features(bsoncxx_test_properties INTERFACE cxx_std_14)
54+
4955
target_link_libraries(bsoncxx_test_properties INTERFACE bsoncxx_testing ${libbson_target})
5056
target_include_directories(bsoncxx_test_properties INTERFACE
5157

5258
# Allow `#include <bson/bson.h>`
5359
${libbson_include_directories}
5460

55-
# Allow `#include <bsoncxx/test/...>` and `#include <third_party/...>`.
61+
# Allow `#include <bsoncxx/test/...>`.
5662
${CMAKE_CURRENT_SOURCE_DIR}/../..
5763
)
5864
target_compile_definitions(bsoncxx_test_properties INTERFACE ${libbson_definitions})
5965
add_library(bsoncxx::test_properties ALIAS bsoncxx_test_properties)
6066

6167
# Avoid redundant recompilation of catch/main.cpp.
62-
add_library(bsoncxx_test_properties_with_main STATIC EXCLUDE_FROM_ALL ${THIRD_PARTY_SOURCE_DIR}/catch/main.cpp)
63-
target_link_libraries(bsoncxx_test_properties_with_main PUBLIC bsoncxx::test_properties)
68+
add_library(bsoncxx_test_properties_with_main INTERFACE)
69+
target_link_libraries(bsoncxx_test_properties_with_main INTERFACE bsoncxx::test_properties Catch2::Catch2WithMain)
6470
add_library(bsoncxx::test_properties_with_main ALIAS bsoncxx_test_properties_with_main)
6571

66-
set_property(TARGET test_bson APPEND PROPERTY LINK_LIBRARIES bsoncxx::test_properties_with_main)
67-
72+
target_link_libraries (test_bson PRIVATE bsoncxx::test_properties_with_main)
6873
add_test(NAME bson COMMAND test_bson)
6974

7075
# Generate test to ensure macro guards behave properly.

src/bsoncxx/test/array.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414

1515
#include <bsoncxx/array/view.hpp>
1616
#include <bsoncxx/builder/basic/array.hpp>
17-
#include <bsoncxx/test/catch.hh>
1817
#include <bsoncxx/types.hpp>
1918
#include <bsoncxx/types/bson_value/make_value.hpp>
2019

20+
#include <bsoncxx/test/catch.hh>
21+
2122
namespace {
2223

2324
using namespace bsoncxx;

src/bsoncxx/test/bson_b_date.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
#include <chrono>
1616

17-
#include <bsoncxx/test/catch.hh>
1817
#include <bsoncxx/types.hpp>
1918

19+
#include <bsoncxx/test/catch.hh>
20+
2021
namespace {
2122
TEST_CASE("time_point is converted to b_date and back", "[bsoncxx::types::b_date]") {
2223
using bsoncxx::types::b_date;

src/bsoncxx/test/bson_builder.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@
2424
#include <bsoncxx/json.hpp>
2525
#include <bsoncxx/private/libbson.hh>
2626
#include <bsoncxx/string/to_string.hpp>
27-
#include <bsoncxx/test/catch.hh>
2827
#include <bsoncxx/types.hpp>
2928
#include <bsoncxx/types/bson_value/view.hpp>
3029

30+
#include <bsoncxx/test/catch.hh>
31+
32+
#include <catch2/catch_case_sensitive.hpp>
33+
#include <catch2/matchers/catch_matchers_string.hpp>
34+
3135
namespace {
3236

3337
using namespace bsoncxx;
@@ -1711,12 +1715,12 @@ TEST_CASE("list builder with explicit type deduction", "[bsoncxx::builder::list]
17111715

17121716
SECTION("document") {
17131717
builder::list b;
1714-
auto kvp_regex =
1715-
Catch::Matches("(.*)must be list of key-value pairs(.*)", Catch::CaseSensitive::No);
1718+
auto kvp_regex = Catch::Matchers::Matches("(.*)must be list of key-value pairs(.*)",
1719+
Catch::CaseSensitive::No);
17161720
REQUIRE_THROWS_WITH((b = builder::document{"foo", 1, 2}), kvp_regex);
17171721

1718-
auto type_regex =
1719-
Catch::Matches("(.*)must be string type(.*)int32(.*)", Catch::CaseSensitive::No);
1722+
auto type_regex = Catch::Matchers::Matches("(.*)must be string type(.*)int32(.*)",
1723+
Catch::CaseSensitive::No);
17201724
REQUIRE_THROWS_WITH((b = builder::document{"foo", 1, 2, 4}), type_regex);
17211725
}
17221726
}

src/bsoncxx/test/bson_get_values.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <bsoncxx/builder/basic/array.hpp>
1818
#include <bsoncxx/builder/basic/document.hpp>
1919
#include <bsoncxx/builder/basic/sub_array.hpp>
20+
2021
#include <bsoncxx/test/catch.hh>
2122

2223
namespace {

src/bsoncxx/test/bson_serialization.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@
1717
#include <bsoncxx/builder/basic/document.hpp>
1818
#include <bsoncxx/document/value.hpp>
1919
#include <bsoncxx/string/to_string.hpp>
20-
#include <bsoncxx/test/catch.hh>
2120
#include <bsoncxx/types/bson_value/view.hpp>
2221

22+
#include <bsoncxx/test/catch.hh>
23+
2324
namespace {
2425
using namespace bsoncxx;
2526

0 commit comments

Comments
 (0)