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

Add more mock tests #587

Merged
merged 17 commits into from
May 24, 2024
Merged
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ RequiresExpressionIndentation: OuterScope
FixNamespaceComments: true
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<(snitch|nanobench).*>'
- Regex: '^<(catch|nanobench).*>'
Priority: 1
SortPriority: 1
- Regex: '^<rpp/.*/fwd.hpp>'
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/analyzers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
path: |
~/.conan2
/Users/runner/.conan2/
key: deps-ci-ubuntu-clang-Release-${{ hashFiles('conanfile.py') }}
key: deps-ci-ubuntu-clang-Release-${{ hashFiles('**/conanfile.py') }}
restore-keys: deps-ci-ubuntu-clang-Release

- name: conan detect profile
Expand Down Expand Up @@ -131,7 +131,7 @@ jobs:
path: |
~/.conan2
/Users/runner/.conan2/
key: deps-ci-ubuntu-clang-Release-${{ hashFiles('conanfile.py') }}
key: deps-ci-ubuntu-clang-Release-${{ hashFiles('**/conanfile.py') }}
restore-keys: deps-ci-ubuntu-clang-Release

- name: conan detect profile
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
path: |
~/.conan2
/Users/runner/.conan2/
key: deps-${{ matrix.config.name }}-${{ matrix.build_type.config }}-${{ hashFiles('conanfile.py') }}
key: deps-${{ matrix.config.name }}-${{ matrix.build_type.config }}-${{ hashFiles('**/conanfile.py') }}
restore-keys: deps-${{ matrix.config.name }}-${{ matrix.build_type.config }}

- name: conan detect profile
Expand Down Expand Up @@ -110,7 +110,7 @@ jobs:
path: |
~/.conan2
/Users/runner/.conan2/
key: deps-ci-ubuntu-clang-Release-${{ hashFiles('conanfile.py') }}
key: deps-ci-ubuntu-clang-Release-${{ hashFiles('**/conanfile.py') }}
restore-keys: deps-ci-ubuntu-clang-Release

- name: conan detect profile
Expand Down Expand Up @@ -187,7 +187,7 @@ jobs:
path: |
~/.conan2
/Users/runner/.conan2/
key: deps-${{ matrix.config.name }}-${{ matrix.build_type.config }}-${{ hashFiles('conanfile.py') }}
key: deps-${{ matrix.config.name }}-${{ matrix.build_type.config }}-${{ hashFiles('**/conanfile.py') }}
restore-keys: deps-${{ matrix.config.name }}-${{ matrix.build_type.config }}

- name: conan detect profile
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ if (RPP_BUILD_TESTS OR RPP_BUILD_BENCHMARKS)

macro(add_test_with_coverage TARGET)
if (RPP_USE_LLVM_COV)
add_test(NAME ${TARGET} COMMAND ${CMAKE_COMMAND} -E env LLVM_PROFILE_FILE=${RPP_TEST_RESULTS_DIR}/${TARGET}.profraw $<TARGET_FILE:${TARGET}> -v full)
add_test(NAME ${TARGET} COMMAND ${CMAKE_COMMAND} -E env LLVM_PROFILE_FILE=${RPP_TEST_RESULTS_DIR}/${TARGET}.profraw $<TARGET_FILE:${TARGET}> -v high)
else()
add_test(NAME ${TARGET} COMMAND $<TARGET_FILE:${TARGET}> -v full)
add_test(NAME ${TARGET} COMMAND $<TARGET_FILE:${TARGET}> -v high)
endif()
endmacro()
endif()
Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
"cacheVariables": {
"CMAKE_PROJECT_TOP_LEVEL_INCLUDES": "cmake/conan_provider.cmake",
"CONAN_ARGS": "",
"CONAN_INSTALL_ARGS": "--build=missing;-s=compiler.cppstd=20;-c=tools.system.package_manager:mode=install;-c=tools.system.package_manager:sudo=True"
"CONAN_INSTALL_ARGS": "--build=missing;-s:a compiler.cppstd=20;-c tools.system.package_manager:mode=install;-c tools.system.package_manager:sudo=True"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ DEALINGS IN THE SOFTWARE.
# Credits:
ReactivePlusPlus library uses:
- [PVS-Studio](https://pvs-studio.com/pvs-studio/?utm_source=website&utm_medium=github&utm_campaign=open_source) - static analyzer for C, C++, C#, and Java code.
- [snitch](https://github.com/cschreib/snitch) for unit testing only, fetched automatically in case of `RPP_BUILD_TESTS` enabled
- [catch](https://github.com/catchorg/Catch2) for unit testing only, fetched automatically in case of `RPP_BUILD_TESTS` enabled
- [trompeloeil](https://github.com/rollbear/trompeloeil) for mocking in unit testing only, fetched automatically in case of `RPP_BUILD_TESTS` enabled
- [nanobench](https://github.com/martinus/nanobench) for benchmarking only, fetched automatically in case of `RPP_BUILD_BENCHMARKS` enabled
- [RxCpp](https://github.com/ReactiveX/RxCpp) only for comparison of performance between RPP and RxCpp in CI benchmarks. Used as cmake dependency under option
Expand Down
5 changes: 3 additions & 2 deletions cmake/dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ if (RPP_BUILD_RXCPP AND RPP_BUILD_BENCHMARKS)
rpp_fetch_library(rxcpp https://github.com/ReactiveX/RxCpp.git origin/main)
endif()

# ===================== Snitch ===================
# ===================== Tests ===================
if (RPP_BUILD_TESTS)
rpp_fetch_library(snitch https://github.com/cschreib/snitch.git main)
rpp_fetch_library(Catch2 https://github.com/catchorg/Catch2.git v3.6.0)
target_compile_features(Catch2::Catch2WithMain INTERFACE cxx_std_20)
rpp_fetch_library(trompeloeil https://github.com/rollbear/trompeloeil.git main)
endif()

Expand Down
3 changes: 2 additions & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class RppConan(ConanFile):
name = "rpp"
settings = "os", "compiler", "build_type", "arch"
generators = "CMakeDeps", "CMakeToolchain"
extension_properties = {"compatibility_cppstd": False}

options = {
"with_grpc" : [False, True],
Expand All @@ -23,7 +24,7 @@ class RppConan(ConanFile):
def requirements(self):
if self.options.with_tests:
self.requires("trompeloeil/47")
self.requires("snitch/1.2.3")
self.requires("catch2/3.6.0")

if self.options.with_benchmarks:
self.requires("nanobench/4.3.11")
Expand Down
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ sonar.cfamily.llvm-cov.reportPath=build/test_results/coverage.txt
sonar.coverage.exclusions=src/tests/**/*
sonar.cpd.exclusions=src/tests/**/*
sonar.issue.ignore.allfile=a1
sonar.issue.ignore.allfile.a1.fileRegexp=#include.*snitch
sonar.issue.ignore.allfile.a1.fileRegexp=#include.*catch
5 changes: 4 additions & 1 deletion src/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ macro(add_test_target target_name module files)
set(TARGET ${target_name})

add_executable(${TARGET} ${files})
target_link_libraries(${TARGET} PRIVATE snitch::snitch trompeloeil::trompeloeil rpp_tests_utils ${module})
target_link_libraries(${TARGET} PRIVATE Catch2::Catch2WithMain trompeloeil::trompeloeil rpp_tests_utils ${module})
target_compile_definitions(${TARGET} PRIVATE "CATCH_CONFIG_FAST_COMPILE")
set_target_properties(${TARGET} PROPERTIES FOLDER Tests/Suites/${module})

add_test_with_coverage(${TARGET})
Expand All @@ -23,6 +24,8 @@ macro(add_test_target target_name module files)
rpp_add_qt_support_to_executable(${TARGET})
endif()

target_compile_features(${TARGET} PRIVATE cxx_std_20)

if(MSVC)
target_compile_options(${TARGET} PRIVATE /W4 /WX /wd4702)
else()
Expand Down
27 changes: 14 additions & 13 deletions src/tests/rpp/test_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
// Project home: https://github.com/victimsnino/ReactivePlusPlus
//

#include <snitch/snitch.hpp>
#include <catch2/catch_template_test_macros.hpp>
#include <catch2/catch_test_macros.hpp>

#include <rpp/observables/dynamic_observable.hpp>
#include <rpp/operators/buffer.hpp>
Expand All @@ -29,43 +30,43 @@ TEST_CASE("buffer bundles items")
auto obs = rpp::source::just(1, 2, 3);
SECTION("buffer(0) - shall see -{1}-{2}-{3}-|")
{
REQUIRE_CALL(*mock, on_next(std::vector{1})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next(std::vector{2})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next(std::vector{3})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{1})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{2})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{3})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_completed()).IN_SEQUENCE(s);

obs | rpp::ops::buffer(0) | rpp::ops::subscribe(mock);
}
SECTION("buffer(1) - shall see -{1}-{2}-{3}-|")
{
REQUIRE_CALL(*mock, on_next(std::vector{1})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next(std::vector{2})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next(std::vector{3})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{1})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{2})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{3})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_completed()).IN_SEQUENCE(s);

obs | rpp::ops::buffer(1)
| rpp::ops::subscribe(mock);
}
SECTION("buffer(2) - shall see -{1,2}-{3}|")
{
REQUIRE_CALL(*mock, on_next(std::vector{1, 2})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next(std::vector{3})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{1, 2})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{3})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_completed()).IN_SEQUENCE(s);

obs | rpp::ops::buffer(2)
| rpp::ops::subscribe(mock);
}
SECTION("buffer(3) - shall see -{1,2,3}-|")
{
REQUIRE_CALL(*mock, on_next(std::vector{1, 2, 3})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{1, 2, 3})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_completed()).IN_SEQUENCE(s);

obs | rpp::ops::buffer(3)
| rpp::ops::subscribe(mock);
}
SECTION("buffer(4) - shall see -{1,2,3}-|")
{
REQUIRE_CALL(*mock, on_next(std::vector{1, 2, 3})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{1, 2, 3})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_completed()).IN_SEQUENCE(s);

obs | rpp::ops::buffer(4)
Expand All @@ -81,15 +82,15 @@ TEST_CASE("buffer bundles items")
| rpp::ops::merge();
SECTION("buffer(0) - shall see -{1}-x, which means error event is through")
{
REQUIRE_CALL(*mock, on_next(std::vector{1})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{1})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_error(trompeloeil::_)).IN_SEQUENCE(s);

obs | rpp::ops::buffer(0)
| rpp::ops::subscribe(mock);
}
SECTION("buffer(1) - shall see -{1}-x, which means error event is through")
{
REQUIRE_CALL(*mock, on_next(std::vector{1})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_next_rvalue(std::vector{1})).IN_SEQUENCE(s);
REQUIRE_CALL(*mock, on_error(trompeloeil::_)).IN_SEQUENCE(s);

obs | rpp::ops::buffer(1)
Expand Down
Loading
Loading