Skip to content
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

Use GTest; resolves #34 #90

Merged
merged 5 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
*.cbor
*.json
*.fb
*.flexbuf
*.msgpack
*.toml
*.xml
Expand Down
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ option(REFLECTCPP_YAML "Enable YAML support" OFF)
option(REFLECTCPP_BUILD_TESTS "Build tests" OFF)

set(REFLECTCPP_USE_VCPKG_DEFAULT OFF)
if (REFLECTCPP_BSON OR REFLECTCPP_CBOR OR REFLECTCPP_FLEXBUFFERS OR REFLECTCPP_MSGPACK OR REFLECTCPP_XML OR REFLECTCPP_TOML OR REFLECTCPP_YAML)
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)
# enable vcpkg per default if require features other than JSON
set(REFLECTCPP_USE_VCPKG_DEFAULT ON)
endif()
Expand Down Expand Up @@ -85,10 +85,14 @@ endif ()
target_compile_options(reflectcpp PRIVATE -Wall)

if (REFLECTCPP_BUILD_TESTS)
if (MSVC)
set(REFLECT_CPP_GTEST_LIB "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/gtest${CMAKE_STATIC_LIBRARY_SUFFIX}")
else ()
set(REFLECT_CPP_GTEST_LIB "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/lib/libgtest${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif ()
add_subdirectory(tests)
endif ()


include(GNUInstallDirs)
include(CMakePackageConfigHelpers)

Expand Down
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,17 @@ vcpkg is a great, but very ambitious and complex project (just like C++ is a gre

## Compiling and running the tests

reflect-cpp uses vcpkg for dependency management, including
gtest, which is required for the tests.

```bash
# bootstrap vcpkg if you haven't done so already
git submodule update --init
./vcpkg/bootstrap-vcpkg.sh # Linux, macOS
./vcpkg/bootstrap-vcpkg.bat # Windows
# You may be prompted to install additional dependencies.
```

### JSON only

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

```bash
# bootstrap vcpkg if you haven't done so already
git submodule update --init
./vcpkg/bootstrap-vcpkg.sh # Linux, macOS
./vcpkg/bootstrap-vcpkg.bat # Windows
# You may be prompted to install additional dependencies.

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
cmake --build build -j 4 # gcc, clang
cmake --build build --config Release -j 4 # MSVC
Expand Down
16 changes: 13 additions & 3 deletions tests/bson/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
project(reflect-cpp-bson-tests)

file(GLOB_RECURSE SOURCES "*.cpp")
file(GLOB_RECURSE SOURCES CONFIGURE_DEPENDS "*.cpp")

add_executable(reflect-cpp-bson-tests ${SOURCES})
add_executable(
reflect-cpp-bson-tests
${SOURCES}
"${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/src/gtest_main.cc"
)

target_include_directories(reflect-cpp-bson-tests SYSTEM PRIVATE "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/include")
target_link_libraries(reflect-cpp-bson-tests PRIVATE reflectcpp)

target_link_libraries(
reflect-cpp-bson-tests
PRIVATE
reflectcpp
"${REFLECT_CPP_GTEST_LIB}"
)
8 changes: 2 additions & 6 deletions tests/bson/test_array.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_array.hpp"

#include <array>
#include <iostream>
#include <memory>
Expand All @@ -8,7 +6,7 @@
#include <string>

// Make sure things still compile when
// rfl.hpp is included after rfl/bson.hpp.
// rfl.hpp is included after rfl/cbor.hpp.
#include <rfl.hpp>

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

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(bson, test_array) {
auto bart = Person{.first_name = "Bart"};

auto lisa = Person{.first_name = "Lisa"};
Expand Down
4 changes: 0 additions & 4 deletions tests/bson/test_array.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/bson/test_box.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_box.hpp"

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand Down Expand Up @@ -29,9 +27,7 @@ struct DecisionTree {
rfl::Field<"leafOrNode", LeafOrNode> leaf_or_node;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(bson, test_box) {
auto leaf1 = DecisionTree::Leaf{.value = 3.0};

auto leaf2 = DecisionTree::Leaf{.value = 5.0};
Expand Down
4 changes: 0 additions & 4 deletions tests/bson/test_box.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/bson/test_custom_class1.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_custom_class1.hpp"

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand Down Expand Up @@ -31,9 +29,7 @@ struct Person {
PersonImpl impl;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(bson, test_custom_class1) {
const auto bart = Person("Bart");

write_and_read(bart);
Expand Down
4 changes: 0 additions & 4 deletions tests/bson/test_custom_class1.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/bson/test_custom_class3.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_custom_class3.hpp"

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand Down Expand Up @@ -56,9 +54,7 @@ struct Parser<ReaderType, WriterType, test_custom_class3::Person>

namespace test_custom_class3 {

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(bson, test_custom_class3) {
const auto bart = Person("Bart", "Simpson", 10);

write_and_read(bart);
Expand Down
4 changes: 0 additions & 4 deletions tests/bson/test_custom_class3.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/bson/test_custom_class4.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_custom_class4.hpp"

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand Down Expand Up @@ -57,9 +55,7 @@ struct Parser<ReaderType, WriterType, test_custom_class4::Person>

namespace test_custom_class4 {

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(bson, test_custom_class4) {
const auto bart = test_custom_class4::Person(
"Bart", rfl::make_box<std::string>("Simpson"), 10);

Expand Down
4 changes: 0 additions & 4 deletions tests/bson/test_custom_class4.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/bson/test_default_values.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_default_values.hpp"

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand All @@ -17,9 +15,7 @@ struct Person {
std::vector<Person> children;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(bson, test_default_values) {
const auto bart = Person{.first_name = "Bart"};
const auto lisa = Person{.first_name = "Lisa"};
const auto maggie = Person{.first_name = "Maggie"};
Expand Down
4 changes: 0 additions & 4 deletions tests/bson/test_default_values.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/bson/test_deque.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_deque.hpp"

#include <iostream>
#include <rfl.hpp>
#include <source_location>
Expand All @@ -16,9 +14,7 @@ struct Person {
std::unique_ptr<std::deque<Person>> children;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(bson, test_default_values) {
auto children = std::make_unique<std::deque<Person>>();
children->emplace_back(Person{.first_name = "Bart"});
children->emplace_back(Person{.first_name = "Lisa"});
Expand Down
4 changes: 0 additions & 4 deletions tests/bson/test_deque.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/bson/test_enum.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_enum.hpp"

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand All @@ -18,9 +16,7 @@ struct Circle {
Color color;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(bson, test_enum) {
const auto circle = Circle{.radius = 2.0, .color = Color::green};

write_and_read(circle);
Expand Down
4 changes: 0 additions & 4 deletions tests/bson/test_enum.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/bson/test_field_variant.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_field_variant.hpp"

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand Down Expand Up @@ -28,9 +26,7 @@ using Shapes = rfl::Variant<rfl::Field<"circle", Circle>,
rfl::Field<"rectangle", Rectangle>,
rfl::Field<"square", rfl::Box<Square>>>;

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(bson, test_field_variant) {
const Shapes r =
rfl::make_field<"rectangle">(Rectangle{.height = 10, .width = 5});

Expand Down
4 changes: 0 additions & 4 deletions tests/bson/test_field_variant.hpp

This file was deleted.

5 changes: 1 addition & 4 deletions tests/bson/test_flag_enum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <string>
#include <vector>

#include "test_enum.hpp"
#include "write_and_read.hpp"

namespace test_flag_enum {
Expand All @@ -27,9 +26,7 @@ struct Circle {
Color color;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(bson, test_flag_enum) {
const auto circle =
Circle{.radius = 2.0, .color = Color::blue | Color::orange};

Expand Down
4 changes: 0 additions & 4 deletions tests/bson/test_flag_enum.hpp

This file was deleted.

5 changes: 1 addition & 4 deletions tests/bson/test_flag_enum_with_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <string>
#include <vector>

#include "test_enum.hpp"
#include "write_and_read.hpp"

namespace test_flag_enum_with_int {
Expand All @@ -27,9 +26,7 @@ struct Circle {
Color color;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(bson, test_flag_enum_with_int) {
const auto circle = Circle{.radius = 2.0, .color = static_cast<Color>(10000)};

write_and_read(circle);
Expand Down
4 changes: 0 additions & 4 deletions tests/bson/test_flag_enum_with_int.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/bson/test_flatten.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_flatten.hpp"

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand All @@ -23,9 +21,7 @@ struct Employee {
rfl::Field<"salary", float> salary;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(bson, test_flatten) {
const auto employee = Employee{
.person = Person{.first_name = "Homer",
.last_name = rfl::make_box<std::string>("Simpson"),
Expand Down
4 changes: 0 additions & 4 deletions tests/bson/test_flatten.hpp

This file was deleted.

6 changes: 1 addition & 5 deletions tests/bson/test_flatten_anonymous.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "test_flatten_anonymous.hpp"

#include <cassert>
#include <iostream>
#include <rfl.hpp>
Expand All @@ -23,9 +21,7 @@ struct Employee {
float salary;
};

void test() {
std::cout << std::source_location::current().function_name() << std::endl;

TEST(bson, test_flatten_anonymous) {
const auto employee = Employee{
.person = Person{.first_name = "Homer",
.last_name = rfl::make_box<std::string>("Simpson"),
Expand Down
4 changes: 0 additions & 4 deletions tests/bson/test_flatten_anonymous.hpp

This file was deleted.

Loading
Loading