Skip to content

Commit 325d163

Browse files
Use GTest; resolves #34 (#90)
1 parent bf1c9be commit 325d163

682 files changed

Lines changed: 1126 additions & 4802 deletions

File tree

Some content is hidden

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

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
*.cbor
4646
*.json
4747
*.fb
48+
*.flexbuf
4849
*.msgpack
4950
*.toml
5051
*.xml

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ option(REFLECTCPP_YAML "Enable YAML support" OFF)
1212
option(REFLECTCPP_BUILD_TESTS "Build tests" OFF)
1313

1414
set(REFLECTCPP_USE_VCPKG_DEFAULT OFF)
15-
if (REFLECTCPP_BSON OR REFLECTCPP_CBOR OR REFLECTCPP_FLEXBUFFERS OR REFLECTCPP_MSGPACK OR REFLECTCPP_XML OR REFLECTCPP_TOML OR REFLECTCPP_YAML)
15+
if (REFLECTCPP_BUILD_TESTS OR REFLECTCPP_BSON OR REFLECTCPP_CBOR OR REFLECTCPP_FLEXBUFFERS OR REFLECTCPP_MSGPACK OR REFLECTCPP_XML OR REFLECTCPP_TOML OR REFLECTCPP_YAML)
1616
# enable vcpkg per default if require features other than JSON
1717
set(REFLECTCPP_USE_VCPKG_DEFAULT ON)
1818
endif()
@@ -85,10 +85,14 @@ endif ()
8585
target_compile_options(reflectcpp PRIVATE -Wall)
8686

8787
if (REFLECTCPP_BUILD_TESTS)
88+
if (MSVC)
89+
set(REFLECT_CPP_GTEST_LIB "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/gtest${CMAKE_STATIC_LIBRARY_SUFFIX}")
90+
else ()
91+
set(REFLECT_CPP_GTEST_LIB "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libgtest${CMAKE_STATIC_LIBRARY_SUFFIX}")
92+
endif ()
8893
add_subdirectory(tests)
8994
endif ()
9095

91-
9296
include(GNUInstallDirs)
9397
include(CMakePackageConfigHelpers)
9498

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,17 @@ vcpkg is a great, but very ambitious and complex project (just like C++ is a gre
530530

531531
## Compiling and running the tests
532532

533+
reflect-cpp uses vcpkg for dependency management, including
534+
gtest, which is required for the tests.
535+
536+
```bash
537+
# bootstrap vcpkg if you haven't done so already
538+
git submodule update --init
539+
./vcpkg/bootstrap-vcpkg.sh # Linux, macOS
540+
./vcpkg/bootstrap-vcpkg.bat # Windows
541+
# You may be prompted to install additional dependencies.
542+
```
543+
533544
### JSON only
534545

535546
To compile the tests, do the following:
@@ -551,12 +562,6 @@ To run the tests, do the following:
551562
To compile the tests with serialization formats other than JSON, do the following:
552563

553564
```bash
554-
# bootstrap vcpkg if you haven't done so already
555-
git submodule update --init
556-
./vcpkg/bootstrap-vcpkg.sh # Linux, macOS
557-
./vcpkg/bootstrap-vcpkg.bat # Windows
558-
# You may be prompted to install additional dependencies.
559-
560565
cmake -S . -B build -DREFLECTCPP_BUILD_TESTS=ON -DREFLECTCPP_BSON=ON -DREFLECTCPP_CBOR=ON -DREFLECTCPP_FLEXBUFFERS=ON -DREFLECTCPP_MSGPACK=ON -DREFLECTCPP_XML=ON -DREFLECTCPP_TOML=ON -DREFLECTCPP_YAML=ON -DCMAKE_BUILD_TYPE=Release
561566
cmake --build build -j 4 # gcc, clang
562567
cmake --build build --config Release -j 4 # MSVC

tests/bson/CMakeLists.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
project(reflect-cpp-bson-tests)
22

3-
file(GLOB_RECURSE SOURCES "*.cpp")
3+
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp")
44

5-
add_executable(reflect-cpp-bson-tests ${SOURCES})
5+
add_executable(
6+
reflect-cpp-bson-tests
7+
${SOURCES}
8+
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/src/gtest_main.cc"
9+
)
610

711
target_include_directories(reflect-cpp-bson-tests SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")
8-
target_link_libraries(reflect-cpp-bson-tests PRIVATE reflectcpp)
12+
13+
target_link_libraries(
14+
reflect-cpp-bson-tests
15+
PRIVATE
16+
reflectcpp
17+
"${REFLECT_CPP_GTEST_LIB}"
18+
)

tests/bson/test_array.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include "test_array.hpp"
2-
31
#include <array>
42
#include <iostream>
53
#include <memory>
@@ -8,7 +6,7 @@
86
#include <string>
97

108
// Make sure things still compile when
11-
// rfl.hpp is included after rfl/bson.hpp.
9+
// rfl.hpp is included after rfl/cbor.hpp.
1210
#include <rfl.hpp>
1311

1412
#include "write_and_read.hpp"
@@ -21,9 +19,7 @@ struct Person {
2119
std::unique_ptr<std::array<Person, 3>> children = nullptr;
2220
};
2321

24-
void test() {
25-
std::cout << std::source_location::current().function_name() << std::endl;
26-
22+
TEST(bson, test_array) {
2723
auto bart = Person{.first_name = "Bart"};
2824

2925
auto lisa = Person{.first_name = "Lisa"};

tests/bson/test_array.hpp

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/bson/test_box.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include "test_box.hpp"
2-
31
#include <cassert>
42
#include <iostream>
53
#include <rfl.hpp>
@@ -29,9 +27,7 @@ struct DecisionTree {
2927
rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node;
3028
};
3129

32-
void test() {
33-
std::cout << std::source_location::current().function_name() << std::endl;
34-
30+
TEST(bson, test_box) {
3531
auto leaf1 = DecisionTree::Leaf{.value = 3.0};
3632

3733
auto leaf2 = DecisionTree::Leaf{.value = 5.0};

tests/bson/test_box.hpp

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/bson/test_custom_class1.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#include "test_custom_class1.hpp"
2-
31
#include <cassert>
42
#include <iostream>
53
#include <rfl.hpp>
@@ -31,9 +29,7 @@ struct Person {
3129
PersonImpl impl;
3230
};
3331

34-
void test() {
35-
std::cout << std::source_location::current().function_name() << std::endl;
36-
32+
TEST(bson, test_custom_class1) {
3733
const auto bart = Person("Bart");
3834

3935
write_and_read(bart);

tests/bson/test_custom_class1.hpp

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)