Skip to content

Commit 2608a1e

Browse files
authored
Reuse bsoncxx::v1 out-of-line definitions of Catch::StringMaker<T>::convert() (#1500)
1 parent 7b559e1 commit 2608a1e

File tree

12 files changed

+238
-91
lines changed

12 files changed

+238
-91
lines changed

src/bsoncxx/test/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,13 @@ set(bsoncxx_test_sources_v_noabi
5050

5151
set(bsoncxx_test_sources_v1
5252
v1/array/value.cpp
53+
v1/array/view_string_maker.cpp
5354
v1/array/view.cpp
5455
v1/decimal128.cpp
5556
v1/document/value.cpp
57+
v1/document/view_string_maker.cpp
5658
v1/document/view.cpp
59+
v1/element/view_string_maker.cpp
5760
v1/element/view.cpp
5861
v1/exception.cpp
5962
v1/oid.cpp

src/bsoncxx/test/v1/array/view.cpp

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@
2323

2424
#include <cstddef>
2525
#include <cstdint>
26-
#include <cstring>
27-
#include <string>
28-
#include <system_error>
2926

3027
#include <bsoncxx/test/stringify.hh>
3128
#include <bsoncxx/test/system_error.hh>
3229

30+
#include <catch2/catch_test_macros.hpp>
3331
#include <catch2/matchers/catch_matchers_string.hpp>
3432

3533
namespace {
@@ -353,33 +351,3 @@ TEST_CASE("StringMaker", "[bsoncxx][test][v1][array][view]") {
353351
}
354352

355353
} // namespace
356-
357-
std::string Catch::StringMaker<bsoncxx::v1::array::view>::convert(bsoncxx::v1::array::view const& value) try {
358-
if (!value) {
359-
return "invalid";
360-
}
361-
362-
auto const end = value.end();
363-
auto iter = value.begin();
364-
365-
if (iter == end) {
366-
return "[]";
367-
}
368-
369-
std::string res;
370-
res += '[';
371-
res += bsoncxx::test::stringify(iter->type_view());
372-
for (++iter; iter != end; ++iter) {
373-
res += ", ";
374-
res += bsoncxx::test::stringify(iter->type_view());
375-
}
376-
res += ']';
377-
return res;
378-
} catch (bsoncxx::v1::exception const& ex) {
379-
WARN("exception during stringification: " << ex.what());
380-
if (ex.code() == code::invalid_data) {
381-
return "invalid";
382-
} else {
383-
throw;
384-
}
385-
}

src/bsoncxx/test/v1/array/view.hh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818

1919
//
2020

21+
#include <bsoncxx/test/v1/document/view.hh> // IWYU pragma: keep: StringMaker<bsoncxx::v1::document::view>
22+
#include <bsoncxx/test/v1/element/view.hh> // IWYU pragma: keep: StringMaker<bsoncxx::v1::element::view>
23+
2124
#include <string>
2225

2326
#include <bsoncxx/private/export.hh>
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2009-present MongoDB, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <bsoncxx/test/v1/array/view.hh>
16+
17+
//
18+
19+
#include <bsoncxx/test/v1/exception.hh>
20+
#include <bsoncxx/test/v1/types/view.hh> // IWYU pragma: keep: Catch::StringMaker<bsoncxx::v1::types::view>
21+
22+
#include <string>
23+
24+
#include <bsoncxx/test/stringify.hh>
25+
26+
#include <catch2/catch_test_macros.hpp>
27+
28+
std::string Catch::StringMaker<bsoncxx::v1::array::view>::convert(bsoncxx::v1::array::view const& value) try {
29+
if (!value) {
30+
return "invalid";
31+
}
32+
33+
auto const end = value.end();
34+
auto iter = value.begin();
35+
36+
if (iter == end) {
37+
return "[]";
38+
}
39+
40+
std::string res;
41+
res += '[';
42+
res += bsoncxx::test::stringify(iter->type_view());
43+
for (++iter; iter != end; ++iter) {
44+
res += ", ";
45+
res += bsoncxx::test::stringify(iter->type_view());
46+
}
47+
res += ']';
48+
return res;
49+
} catch (bsoncxx::v1::exception const& ex) {
50+
WARN("exception during stringification: " << ex.what());
51+
if (ex.code() == bsoncxx::v1::document::view::errc::invalid_data) {
52+
return "invalid";
53+
} else {
54+
throw;
55+
}
56+
}

src/bsoncxx/test/v1/document/view.cpp

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -427,33 +427,3 @@ TEST_CASE("StringMaker", "[bsoncxx][test][v1][document][view]") {
427427
}
428428

429429
} // namespace
430-
431-
std::string Catch::StringMaker<bsoncxx::v1::document::view>::convert(bsoncxx::v1::document::view const& value) try {
432-
if (!value) {
433-
return "invalid";
434-
}
435-
436-
auto const end = value.end();
437-
auto iter = value.begin();
438-
439-
if (iter == end) {
440-
return "{}";
441-
}
442-
443-
std::string res;
444-
res += '{';
445-
res += bsoncxx::test::stringify(*iter);
446-
for (++iter; iter != end; ++iter) {
447-
res += ", ";
448-
res += bsoncxx::test::stringify(*iter);
449-
}
450-
res += '}';
451-
return res;
452-
} catch (bsoncxx::v1::exception const& ex) {
453-
WARN("exception during stringification: " << ex.what());
454-
if (ex.code() == code::invalid_data) {
455-
return "invalid";
456-
} else {
457-
throw;
458-
}
459-
}

src/bsoncxx/test/v1/document/view.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
//
2020

21-
#include <bsoncxx/test/v1/element/view.hh> // StringMaker<bsoncxx::v1::element::view>
21+
#include <bsoncxx/test/v1/element/view.hh> // IWYU pragma: keep: StringMaker<T>
2222

2323
#include <string>
2424

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright 2009-present MongoDB, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <bsoncxx/test/v1/document/view.hh>
16+
17+
//
18+
19+
#include <bsoncxx/test/v1/exception.hh>
20+
#include <bsoncxx/test/v1/types/view.hh> // IWYU pragma: keep: Catch::StringMaker<bsoncxx::v1::types::view>
21+
22+
#include <string>
23+
24+
#include <bsoncxx/test/stringify.hh>
25+
26+
#include <catch2/catch_test_macros.hpp>
27+
28+
std::string Catch::StringMaker<bsoncxx::v1::document::view>::convert(bsoncxx::v1::document::view const& value) try {
29+
if (!value) {
30+
return "invalid";
31+
}
32+
33+
auto const end = value.end();
34+
auto iter = value.begin();
35+
36+
if (iter == end) {
37+
return "{}";
38+
}
39+
40+
std::string res;
41+
res += '{';
42+
res += bsoncxx::test::stringify(*iter);
43+
for (++iter; iter != end; ++iter) {
44+
res += ", ";
45+
res += bsoncxx::test::stringify(*iter);
46+
}
47+
res += '}';
48+
return res;
49+
} catch (bsoncxx::v1::exception const& ex) {
50+
WARN("exception during stringification: " << ex.what());
51+
if (ex.code() == bsoncxx::v1::document::view::errc::invalid_data) {
52+
return "invalid";
53+
} else {
54+
throw;
55+
}
56+
}

src/bsoncxx/test/v1/element/view.cpp

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -289,21 +289,3 @@ TEST_CASE("StringMaker", "[bsoncxx][test][v1][element][view]") {
289289
}
290290

291291
} // namespace
292-
293-
std::string Catch::StringMaker<bsoncxx::v1::element::view>::convert(bsoncxx::v1::element::view const& value) try {
294-
if (!value) {
295-
return "invalid";
296-
}
297-
298-
std::string res;
299-
res += bsoncxx::test::stringify(value.key());
300-
res += ": ";
301-
res += bsoncxx::test::stringify(value.type_view());
302-
return res;
303-
} catch (bsoncxx::v1::exception const& ex) {
304-
if (ex.code() == code::invalid_view || ex.code() == code::invalid_data) {
305-
return "invalid";
306-
} else {
307-
throw;
308-
}
309-
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright 2009-present MongoDB, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <bsoncxx/test/v1/element/view.hh>
16+
17+
//
18+
19+
#include <bsoncxx/test/v1/exception.hh>
20+
#include <bsoncxx/test/v1/types/view.hh> // IWYU pragma: keep: Catch::StringMaker<bsoncxx::v1::types::view>
21+
22+
#include <string>
23+
24+
#include <bsoncxx/test/stringify.hh>
25+
26+
std::string Catch::StringMaker<bsoncxx::v1::element::view>::convert(bsoncxx::v1::element::view const& value) try {
27+
if (!value) {
28+
return "invalid";
29+
}
30+
31+
std::string res;
32+
res += bsoncxx::test::stringify(value.key());
33+
res += ": ";
34+
res += bsoncxx::test::stringify(value.type_view());
35+
return res;
36+
} catch (bsoncxx::v1::exception const& ex) {
37+
using code = bsoncxx::v1::element::view::errc;
38+
39+
if (ex.code() == code::invalid_view || ex.code() == code::invalid_data) {
40+
return "invalid";
41+
} else {
42+
throw;
43+
}
44+
}

src/bsoncxx/test/v1/types/view.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
#include <bsoncxx/test/v1/decimal128.hh> // StringMaker<bsoncxx::v1::decimal128>
2323
#include <bsoncxx/test/v1/document/view.hh> // StringMaker<bsoncxx::v1::document::view>
2424
#include <bsoncxx/test/v1/oid.hh> // StringMaker<bsoncxx::v1::oid>
25-
#include <bsoncxx/test/v1/stdx/string_view.hh> // StringMaker<bsoncxx::v1::stdx::string_view>
25+
#include <bsoncxx/test/v1/stdx/string_view.hh>
26+
#include <bsoncxx/test/v1/types/id.hh> // StringMaker<bsoncxx::v1::types::id>
2627

2728
#include <chrono>
2829
#include <cstdint>

0 commit comments

Comments
 (0)