diff --git a/.github/workflows/code-cov.yml b/.github/workflows/code-cov.yml index 06d7ddc..6d4031d 100644 --- a/.github/workflows/code-cov.yml +++ b/.github/workflows/code-cov.yml @@ -1,51 +1,55 @@ name: CodeCov -on: [pull_request] +on: + push: + branches: + - main + pull_request: jobs: - ubuntu-bionic-llvm-code-cov: - runs-on: ubuntu-18.04 + ubuntu-code-cov: + runs-on: ubuntu-latest env: - CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON -DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON' + CMAKE_FLAGS: "-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON -DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON" strategy: matrix: - build-type: ['Debug'] - clang-version: ['8'] + build-type: ["Debug"] + compiler-version: ["latest"] + container: silkeh/clang:${{ matrix.compiler-version }} steps: - - name: ccache - uses: hendrikmuhs/ccache-action@v1 - - name: C++ Setting - run: | - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - - sudo add-apt-repository -y "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-${{matrix.clang-version}} main" - sudo apt-get update - sudo apt-get install -yq clang-${{matrix.clang-version}} libc++-dev libc++abi-dev libstdc++-${{matrix.clang-version}}-dev build-essential cmake - sudo apt-get install -yq libllvm${{matrix.clang-version}} llvm-${{matrix.clang-version}} llvm-${{matrix.clang-version}}-dev llvm-${{matrix.clang-version}}-runtime - - name: Compiler Setting - run: | - echo "CC=clang-${{matrix.clang-version}}" >> $GITHUB_ENV - echo "CXX=clang++-${{matrix.clang-version}}" >> $GITHUB_ENV - - name: Clone Repository - uses: actions/checkout@master - with: - submodules: true - - name: CMake build - run: | - cmake -Bbuild -DCMAKE_BUILD_TYPE=${{matrix.build-type}} ${{env.CMAKE_FLAGS}} . - cd build - cmake --build . --config ${{matrix.build-type}} - - name: Generate Coverage Report - run: | - cd build/${{matrix.build-type}} - ./unittest - llvm-profdata-${{matrix.clang-version}} merge -sparse default.profraw -o default.profdata - llvm-cov-${{matrix.clang-version}} export ./unittest --instr-profile default.profdata -format=lcov >> lcov.info - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v2 - with: - directory: ./build/${{matrix.build-type}} - files: lcov.info - flags: unittest - fail_ci_if_error: true - verbose: true + - name: Get latest CMake + uses: lukka/get-cmake@v3.27.7 + + - name: Install git on container + run: apt update && apt install -y git + - name: Clone Repository + uses: actions/checkout@v3 + with: + submodules: true + + - name: CMake build + run: | + cmake -Bbuild -DCMAKE_BUILD_TYPE=${{matrix.build-type}} ${{env.CMAKE_FLAGS}} . + cmake --build ./build --config ${{matrix.build-type}} + + - name: Run Test Script + working-directory: build/${{matrix.build-type}} + run: | + ./unittest + llvm-profdata merge -sparse default.profraw -o default.profdata + llvm-cov export ./unittest --instr-profile default.profdata -format=lcov >> coverage.info + cp coverage.info ../../ + + - name: Prepare Codecov + run: | + apt-get install -y lcov + lcov --remove coverage.info '/usr/*' --output-file coverage.info --rc lcov_branch_coverage=1 + lcov --remove coverage.info '**/tests/*' --output-file coverage.info --rc lcov_branch_coverage=1 + lcov --remove coverage.info '**/.cppm/*' --output-file coverage.info --rc lcov_branch_coverage=1 + lcov --list coverage.info --rc lcov_branch_coverage=1 + - name: Codecov + uses: codecov/codecov-action@v3.1.1 + with: + files: coverage.info + fail_ci_if_error: true + verbose: true diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index eeaeecf..4747d6a 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -1,75 +1,59 @@ name: Linux -on: [pull_request] +on: + push: + branches: + - main + pull_request: jobs: - ubuntu-bionic-gcc: - runs-on: ubuntu-18.04 + ubuntu-gcc: + runs-on: ubuntu-latest env: - CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON -DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON' + CMAKE_FLAGS: "-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON -DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON" strategy: matrix: - build-type: ['Release', 'Debug'] - gcc-version: ['11'] + build-type: ["Release", "Debug"] + gcc-version: ["11", "12", "latest"] + container: gcc:${{ matrix.gcc-version }} steps: - - name: ccache - uses: hendrikmuhs/ccache-action@v1 - - name: C++ Setting - run: | - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - sudo apt-get update - sudo apt-get install -yq g++-${{matrix.gcc-version}} gcc-${{matrix.gcc-version}} libc++-dev libc++abi-dev build-essential libstdc++-${{matrix.gcc-version}}-dev cmake - - name: Compiler Setting - run: | - echo "CC=gcc-${{matrix.gcc-version}}" >> $GITHUB_ENV - echo "CXX=g++-${{matrix.gcc-version}}" >> $GITHUB_ENV - - name: Clone Repository - uses: actions/checkout@master - with: - submodules: true - - name: CMake build - run: | - cmake -Bbuild -DCMAKE_BUILD_TYPE=${{matrix.build-type}} ${{env.CMAKE_FLAGS}} . - cd build - cmake --build . --config ${{matrix.build-type}} - - name: Run Test Script - run: | - cd build - ctest . + - name: Get latest CMake and ninja + uses: lukka/get-cmake@v3.27.7 + - name: Install git on container + run: apt update && apt install -y git + - uses: actions/checkout@v3 + with: + submodules: true + - name: CMake build + run: | + cmake -Bbuild -DCMAKE_BUILD_TYPE=${{matrix.build-type}} ${{env.CMAKE_FLAGS}} . + cmake --build ./build --config ${{matrix.build-type}} + - name: Run Test Script + working-directory: build + run: ctest -C ${{matrix.build-type}} --output-on-failure - ubuntu-bionic-llvm: - runs-on: ubuntu-18.04 + ubuntu-llvm: + runs-on: ubuntu-latest env: - CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON -DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON' + CMAKE_FLAGS: "-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON -DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON" strategy: matrix: - build-type: ['Release', 'Debug'] - clang-version: ['8'] + build-type: ["Release", "Debug"] + clang-version: ["8", "9", "10", "11", "12", "13", "latest"] #"14", "15-bullseye", "latest"] + container: silkeh/clang:${{ matrix.clang-version }} steps: - - name: ccache - uses: hendrikmuhs/ccache-action@v1 - - name: C++ Setting - run: | - sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add - - sudo add-apt-repository -y "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-${{matrix.clang-version}} main" - sudo apt-get update - sudo apt-get install -yq clang-${{matrix.clang-version}} libc++-dev libc++abi-dev libstdc++-${{matrix.clang-version}}-dev build-essential cmake - - name: Compiler Setting - run: | - echo "CC=clang-${{matrix.clang-version}}" >> $GITHUB_ENV - echo "CXX=clang++-${{matrix.clang-version}}" >> $GITHUB_ENV - - name: Clone Repository - uses: actions/checkout@master - with: - submodules: true - - name: CMake build - run: | - cmake -Bbuild -DCMAKE_BUILD_TYPE=${{matrix.build-type}} ${{env.CMAKE_FLAGS}} . - cd build - cmake --build . --config ${{matrix.build-type}} - - name: Run Test Script - run: | - cd build - ctest . - + - name: Get latest CMake + uses: lukka/get-cmake@v3.27.7 + - name: Install git on container + run: apt update && apt install -y git + - name: Clone Repository + uses: actions/checkout@v3 + with: + submodules: true + - name: CMake build + run: | + cmake -Bbuild -DCMAKE_BUILD_TYPE=${{matrix.build-type}} ${{env.CMAKE_FLAGS}} . + cmake --build ./build --config ${{matrix.build-type}} + - name: Run Test Script + working-directory: build + run: ctest -C ${{matrix.build-type}} --output-on-failure diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index ba2766a..21a8c1e 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -1,36 +1,39 @@ name: MacOS -on: [pull_request] +on: + push: + branches: + - main + pull_request: jobs: macos-clang: runs-on: macos-latest env: - CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON -DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON' + CMAKE_FLAGS: "-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON -DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON" strategy: matrix: - build-type: ['Release', 'Debug'] + build-type: ["Release", "Debug"] steps: - - name: ccache - uses: hendrikmuhs/ccache-action@v1 - - name: Clone Repository - uses: actions/checkout@master - with: - submodules: true - - name: C++ Setting - run: | - brew install llvm cmake - - name: Compiler Setting - run: | - echo "CC=/usr/local/opt/llvm/bin/clang" >> $GITHUB_ENV - echo "CXX=/usr/local/opt/llvm/bin/clang++" >> $GITHUB_ENV - - name: CMake build - run: | - cmake -Bbuild -DCMAKE_BUILD_TYPE=${{matrix.build-type}} ${{env.CMAKE_FLAGS}} . - cd build - cmake --build . --config ${{matrix.build-type}} - - name: Run Test Script - run: | - cd build - ctest . - + - name: ccache + uses: hendrikmuhs/ccache-action@v1 + - name: Clone Repository + uses: actions/checkout@master + with: + submodules: true + - name: C++ Setting + run: | + brew install llvm cmake + - name: Compiler Setting + run: | + echo "CC=/usr/local/opt/llvm/bin/clang" >> $GITHUB_ENV + echo "CXX=/usr/local/opt/llvm/bin/clang++" >> $GITHUB_ENV + - name: CMake build + run: | + cmake -Bbuild -DCMAKE_BUILD_TYPE=${{matrix.build-type}} ${{env.CMAKE_FLAGS}} . + cd build + cmake --build . --config ${{matrix.build-type}} + - name: Run Test Script + run: | + cd build + ctest . diff --git a/.github/workflows/window.yml b/.github/workflows/window.yml index 536e618..0bffb85 100644 --- a/.github/workflows/window.yml +++ b/.github/workflows/window.yml @@ -1,26 +1,30 @@ name: Windows -on: [pull_request] +on: + push: + branches: + - main + pull_request: jobs: windows-msvc: runs-on: windows-2019 env: - CMAKE_FLAGS: '-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON -DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON' + CMAKE_FLAGS: "-DSERDEPP_USE_NLOHMANN_JSON=ON -DSERDEPP_USE_TOML11=ON -DSERDEPP_USE_YAML-CPP=ON -DSERDEPP_BUILD_EXAMPLES=ON -DSERDEPP_USE_RAPIDJSON=ON -DSERDEPP_USE_FMT=ON -DSERDEPP_BUILD_TESTING=ON -DSERDEPP_USE_CATCH2=ON" strategy: matrix: - build-type: ['Release', 'Debug'] + build-type: ["Release", "Debug"] steps: - - name: Clone Repository - uses: actions/checkout@master - with: - submodules: true - - name: CMake build - run: | - cmake -Bbuild -DCMAKE_BUILD_TYPE=${{matrix.build-type}} ${{env.CMAKE_FLAGS}}. - cd build - cmake --build . --config ${{matrix.build-type}} - - name: Run Test Script - run: | - cd build - ctest . + - name: Clone Repository + uses: actions/checkout@master + with: + submodules: true + - name: CMake build + run: | + cmake -Bbuild -DCMAKE_BUILD_TYPE=${{matrix.build-type}} ${{env.CMAKE_FLAGS}}. + cd build + cmake --build . --config ${{matrix.build-type}} + - name: Run Test Script + run: | + cd build + ctest . diff --git a/CMakeLists.txt b/CMakeLists.txt index 98d9944..d2e53ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,15 +9,15 @@ cppm_setting() cppm_cxx_standard(17) cppm_compiler_option( DEBUG - CLANG "-fprofile-instr-generate -fcoverage-mapping" + CLANG "-fprofile-instr-generate -fcoverage-mapping --coverage" ) find_cppkg(benchmark 1.5.2 MODULE benchmark::benchmark TYPE lib OPTIONAL OFF) find_cppkg(RapidJSON 1.1.1 MODULE rapidjson TYPE lib OPTIONAL OFF) find_cppkg(nlohmann_json 3.10.5 MODULE nlohmann_json::nlohmann_json TYPE lib OPTIONAL OFF) -find_cppkg(Catch2 2.9.1 MODULE Catch2::Catch2 TYPE lib OPTIONAL OFF) +find_cppkg(Catch2 3.5.0 MODULE Catch2::Catch2WithMain TYPE lib OPTIONAL OFF) find_cppkg(toml11 3.7.0 MODULE toml11::toml11 TYPE lib OPTIONAL OFF) -find_cppkg(yaml-cpp 0.7.0 MODULE yaml-cpp TYPE lib OPTIONAL OFF) +find_cppkg(yaml-cpp 0.6.3 MODULE yaml-cpp TYPE lib OPTIONAL OFF) find_cppkg(fmt 8.0.1 MODULE fmt::fmt-header-only TYPE lib OPTIONAL OFF) find_cppkg(magic_enum 0.7.3 MODULE magic_enum::magic_enum TYPE lib) find_cppkg(nameof 0.10.0 MODULE nameof::nameof TYPE lib) @@ -93,8 +93,8 @@ if(SERDEPP_BUILD_TESTING) cppm_target_define(unittest BINARY SOURCES + tests/serializer.cpp tests/rapid_json.cpp - tests/catch_main.cpp tests/yaml_cpp.cpp tests/toml11.cpp tests/reflection.cpp diff --git a/cppm.toml b/cppm.toml index c47716b..70ff3c4 100644 --- a/cppm.toml +++ b/cppm.toml @@ -8,7 +8,7 @@ # include=["cmake/Lua.cmake"] [profile.dev.compiler] - clang = "-fprofile-instr-generate -fcoverage-mapping" + clang = "-fprofile-instr-generate -fcoverage-mapping --coverage" [lib] name = "serdepp" @@ -93,12 +93,12 @@ source = ["tests/.*"] nameof = { version="0.10.0", link="public"} magic_enum = { version= "0.7.3", link="public"} fmt = {version="8.0.1", link="public", optional=true} - yaml-cpp = { version="0.7.0", link="public", optional=true} + yaml-cpp = { version="0.6.3", link="public", optional=true} toml11 = { version="3.7.0", link="public", optional=true} nlohmann_json = { version="3.10.5", link="public", optional=true} RapidJSON = { version="1.1.1", link="public", optional=true} benchmark = { version="1.5.2", optional=true} - Catch2 = {version="2.9.1", optional=true} + Catch2 = {version="3.5.0", optional=true} #pybind11 = "2.9.0" #hiredis = "git" #"redis++" = "1.3.2" diff --git a/examples/reflection.cpp b/examples/reflection.cpp index 7749c89..a753ff3 100644 --- a/examples/reflection.cpp +++ b/examples/reflection.cpp @@ -29,8 +29,8 @@ int main(int argc, char* argv[]) { member_b_info = 3.14; auto member_d_info = info.member_info<3>(a); - std::string_view member_d_name = member_d_info.name(); - std::vector& member_d = member_d_info.value(); + [[maybe_unused]] std::string_view member_d_name = member_d_info.name(); + [[maybe_unused]] std::vector& member_d = member_d_info.value(); auto names = info.member_names(); for(auto& name : names.members()) { diff --git a/include/serdepp/serializer.hpp b/include/serdepp/serializer.hpp index 2e984af..22e0e3f 100644 --- a/include/serdepp/serializer.hpp +++ b/include/serdepp/serializer.hpp @@ -42,42 +42,39 @@ namespace serde throw serde::unimplemented_error("serde_adaptor<" + std::string(nameof::nameof_short_type()) +">::is_null(adaptor, key)"); - return adaptor.contains(key); + return false; } inline constexpr static size_t size(Adaptor& adaptor) { throw serde::unimplemented_error("serde_adaptor<" + std::string(nameof::nameof_short_type()) +">::size(adaptor, key)"); - return adaptor.size(); + return 0; } inline constexpr static bool is_struct(Adaptor& adaptor) { throw serde::unimplemented_error("serde_adaptor<" + std::string(nameof::nameof_short_type()) +">::is_struct(adaptor, key)"); - return true; + return false; } - inline constexpr static Adaptor parse_file(Adaptor& adaptor) { + inline constexpr static Adaptor parse_file(const std::string& path) { throw serde::unimplemented_error("serde_adaptor<" + std::string(nameof::nameof_short_type()) +">::parse_file(adaptor, key)"); - return true; + return Adaptor{}; } }; template struct serde_adaptor { - static void from(S& s, std::string_view key, T& data){} - static void into(S& s, std::string_view key, const T& data){} + static void from(S& s, std::string_view key, T& data); + static void into(S &s, std::string_view key, const T &data); }; namespace detail { - struct dummy_adaptor{ - bool contains(std::string_view key) { return true; } - size_t size() { return 1; } - }; + struct dummy_adaptor{}; }; template <> struct serde_adaptor_helper diff --git a/tests/catch_main.cpp b/tests/catch_main.cpp deleted file mode 100644 index b955482..0000000 --- a/tests/catch_main.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#define CATCH_CONFIG_MAIN - -#include - -TEST_CASE("1: test (pass)", "[multi-file:1]") { - REQUIRE(1==1); -} diff --git a/tests/nlohmann_json.cpp b/tests/nlohmann_json.cpp index 5d6d722..b78f01a 100644 --- a/tests/nlohmann_json.cpp +++ b/tests/nlohmann_json.cpp @@ -1,9 +1,7 @@ - -#include #include "test_struct.hpp" +#include #include - nlohmann::json json_v = R"({ "str" : "hello", "i": 10, @@ -16,8 +14,6 @@ nlohmann::json json_v = R"({ using namespace serde; TEST_CASE("2: nlohmann json struct (pass)", "[multi-file:2]") { - REQUIRE(json_v.dump() == serialize(deserialize(json_v)).dump()); + REQUIRE(json_v.dump() == + serialize(deserialize(json_v)).dump()); } - - - diff --git a/tests/rapid_json.cpp b/tests/rapid_json.cpp index 0998101..187b4a8 100644 --- a/tests/rapid_json.cpp +++ b/tests/rapid_json.cpp @@ -1,20 +1,20 @@ -#include #include "test_struct.hpp" +#include #include -std::string str(rapidjson::Document& doc) { - using namespace rapidjson; - StringBuffer buffer; - Writer writer(buffer); - doc.Accept(writer); - return buffer.GetString(); +std::string str(rapidjson::Document &doc) { + using namespace rapidjson; + StringBuffer buffer; + Writer writer(buffer); + doc.Accept(writer); + return buffer.GetString(); }; using namespace serde; TEST_CASE("5: toml11 struct (pass)", "[multi-file:5]") { - rapidjson::Document json_v; - json_v.Parse(R"({ + rapidjson::Document json_v; + json_v.Parse(R"({ "str" : "hello", "i": 10, "vec": [ "one", "two", "three"], @@ -22,7 +22,8 @@ TEST_CASE("5: toml11 struct (pass)", "[multi-file:5]") { "sm": { "one" : "tone", "two" : "ttwo"}, "sub" : { "str": "hello" } })"); - rapidjson::Document json_c = serialize(deserialize(json_v)); + rapidjson::Document json_c = + serialize(deserialize(json_v)); - REQUIRE(str(json_v) == str(json_c)); + REQUIRE(str(json_v) == str(json_c)); } diff --git a/tests/reflection.cpp b/tests/reflection.cpp index f8caee8..08fcfa7 100644 --- a/tests/reflection.cpp +++ b/tests/reflection.cpp @@ -1,18 +1,17 @@ -#include #include "test_struct.hpp" +#include #include using namespace serde; TEST_CASE("3: reflection struct (pass)", "[multi-file:3]") { - REQUIRE(std::is_same_v, - std::tuple, - std::optional, - std::optional, - std::map, - nested>>); + REQUIRE(std::is_same_v< + to_tuple_t, + std::tuple, + std::optional, std::optional, + std::map, nested>>); + REQUIRE(serde::type_info.size == 7); + REQUIRE(serde::tuple_size_v == 7); + REQUIRE(std::is_same_v>>); } - - diff --git a/tests/serializer.cpp b/tests/serializer.cpp new file mode 100644 index 0000000..ac5c31a --- /dev/null +++ b/tests/serializer.cpp @@ -0,0 +1,17 @@ +#include "serdepp/exception.hpp" +#include "serdepp/serializer.hpp" +#include "test_struct.hpp" +#include +#include + +struct unknown_adapter {}; + +TEST_CASE("5: unknown adapter with exception (pass)", "[multi-file:5]") { + auto adapter = unknown_adapter{}; + using helper_t = serde::derive_serde_adaptor_helper; + REQUIRE_THROWS_AS(helper_t::is_null(adapter, "hello"), serde::unimplemented_error); + REQUIRE_THROWS_AS(helper_t::size(adapter), serde::unimplemented_error); + REQUIRE_THROWS_AS(helper_t::is_struct(adapter), serde::unimplemented_error); + REQUIRE_THROWS_AS(helper_t::parse_file(std::string("path")), serde::unimplemented_error); +} + diff --git a/tests/test_struct.hpp b/tests/test_struct.hpp index 6945b1a..762c6e0 100644 --- a/tests/test_struct.hpp +++ b/tests/test_struct.hpp @@ -1,25 +1,25 @@ -#include - #pragma once #ifndef __CATCH_TEST_STRUCT_HPP__ #define __CATCH_TEST_STRUCT_HPP__ +#include + struct nested { - DERIVE_SERDE(nested, _SF_(str)) - std::string str; + DERIVE_SERDE(nested, _SF_(str)) + std::string str; }; struct test { - DERIVE_SERDE(test, _SF_(str)_SF_(i)_SF_(vec)_SF_(opt)_SF_(none_opt)_SF_(sm)_SF_(sub)) - std::string str; - int i; - std::vector vec; - std::optional none_opt; - std::optional opt; - std::map sm; - nested sub; + DERIVE_SERDE(test, _SF_(str) _SF_(i) _SF_(vec) _SF_(opt) _SF_(none_opt) + _SF_(sm) _SF_(sub)) + std::string str; + int i; + std::vector vec; + std::optional none_opt; + std::optional opt; + std::map sm; + nested sub; }; #endif - diff --git a/tests/toml11.cpp b/tests/toml11.cpp index acc0f9a..0827f05 100644 --- a/tests/toml11.cpp +++ b/tests/toml11.cpp @@ -1,5 +1,5 @@ -#include #include "test_struct.hpp" +#include #include using namespace serde; @@ -21,5 +21,5 @@ str = "hello" )"_toml; TEST_CASE("4: toml11 struct (pass)", "[multi-file:4]") { - REQUIRE(toml_vl == serialize(deserialize(toml_vl))); + REQUIRE(toml_vl == serialize(deserialize(toml_vl))); } diff --git a/tests/yaml_cpp.cpp b/tests/yaml_cpp.cpp index 3772205..cf76dbd 100644 --- a/tests/yaml_cpp.cpp +++ b/tests/yaml_cpp.cpp @@ -1,8 +1,7 @@ -#include #include "test_struct.hpp" +#include #include - YAML::Node yaml_v = YAML::Load(R"( str: hello i: 10 @@ -21,10 +20,10 @@ opt: hello using namespace serde; TEST_CASE("5: yaml-cpp struct (pass)", "[multi-file:5]") { - std::ostringstream origin; - origin << yaml_v; - std::ostringstream convert; - convert << serialize(deserialize(yaml_v)); + std::ostringstream origin; + origin << yaml_v; + std::ostringstream convert; + convert << serialize(deserialize(yaml_v)); - REQUIRE(origin.str() == convert.str()); + REQUIRE(origin.str() == convert.str()); } diff --git a/thirdparty/Catch2/3.5.0/Catch2.cmake.in b/thirdparty/Catch2/3.5.0/Catch2.cmake.in new file mode 100644 index 0000000..0da910d --- /dev/null +++ b/thirdparty/Catch2/3.5.0/Catch2.cmake.in @@ -0,0 +1,8 @@ +# Cppkg Base Dependency Downloader +cmake_minimum_required(VERSION 3.6) +project(Catch2-3.5.0-install) + +set(CPPM_VERSION ${CPPM_VERSION}) +include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) +download_package(Catch2 3.5.0 URL https://github.com/catchorg/Catch2/archive/refs/tags/v3.5.0.tar.gz TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DCATCH_BUILD_TESTING=OFF) + diff --git a/thirdparty/Catch2/3.5.0/cppkg.toml b/thirdparty/Catch2/3.5.0/cppkg.toml new file mode 100644 index 0000000..31530f9 --- /dev/null +++ b/thirdparty/Catch2/3.5.0/cppkg.toml @@ -0,0 +1,6 @@ +[Catch2] +version = "3.5.0" +description = "modern, C++-native, header-only, test framework for unit-tests" +module = "Catch2::Catch2" +url="https://github.com/catchorg/Catch2/archive/refs/tags/v3.5.0.tar.gz" +flags="-DCATCH_BUILD_TESTING=OFF" \ No newline at end of file diff --git a/thirdparty/yaml-cpp/0.7.0/yaml-cpp.cmake.in b/thirdparty/yaml-cpp/0.7.0/yaml-cpp.cmake.in index 35946fd..27eeb4b 100644 --- a/thirdparty/yaml-cpp/0.7.0/yaml-cpp.cmake.in +++ b/thirdparty/yaml-cpp/0.7.0/yaml-cpp.cmake.in @@ -1,8 +1,8 @@ # Cppkg Base Dependency Downloader cmake_minimum_required(VERSION 3.6) -project(yaml-cpp-0.6.3-install) +project(yaml-cpp-0.7.0-install) set(CPPM_VERSION ${CPPM_VERSION}) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/cppm_loader.cmake) -download_package(yaml-cpp 0.6.3 URL https://github.com/jbeder/yaml-cpp/archive/yaml-cpp-0.6.3.tar.gz TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DYAML_CPP_BUILD_TESTS=OFF) +download_package(yaml-cpp 0.7.0 URL https://github.com/jbeder/yaml-cpp/archive/refs/tags/yaml-cpp-0.7.0.zip TYPE lib CMAKE_ARGS ${CMAKE_ARGS} -DYAML_CPP_BUILD_TESTS=OFF)